generated from nea89o/Forge1.8.9Template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a8f551
commit 056a46c
Showing
18 changed files
with
338 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/kotlin/dev/dediamondpro/resourcify/config/Config.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package dev.dediamondpro.resourcify.config | ||
|
||
import dev.dediamondpro.resourcify.services.modrinth.ModrinthService | ||
import dev.dediamondpro.resourcify.util.fromJson | ||
import dev.dediamondpro.resourcify.util.toJson | ||
import java.io.File | ||
|
||
class Config { | ||
var defaultService: String = ModrinthService.getName() | ||
var adsEnabled: Boolean = true | ||
|
||
companion object { | ||
private val configFile = File("./config/resourcify.json") | ||
val instance: Config = load() | ||
|
||
private fun load(): Config { | ||
return try { | ||
configFile.readText().fromJson() | ||
} catch (e: Exception) { | ||
Config() | ||
} | ||
} | ||
|
||
fun save() { | ||
configFile.outputStream().bufferedWriter().use { | ||
it.write(instance.toJson()) | ||
} | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/kotlin/dev/dediamondpro/resourcify/config/ForgeGuiFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package dev.dediamondpro.resourcify.config | ||
|
||
//#if FORGE == 1 && MC <= 11202 | ||
|
||
import net.minecraft.client.Minecraft | ||
import net.minecraft.client.gui.GuiScreen | ||
import net.minecraftforge.fml.client.IModGuiFactory | ||
|
||
class ForgeGuiFactory : IModGuiFactory { | ||
override fun initialize(minecraft: Minecraft?) { | ||
} | ||
|
||
//#if MC==10809 | ||
override fun mainConfigGuiClass(): Class<out GuiScreen> { | ||
return SettingsPage::class.java | ||
} | ||
|
||
override fun getHandlerFor(runtimeOptionCategoryElement: IModGuiFactory.RuntimeOptionCategoryElement?): IModGuiFactory.RuntimeOptionGuiHandler? { | ||
return null | ||
} | ||
//#else | ||
//$$ override fun createConfigGui(guiScreen: GuiScreen?): GuiScreen { | ||
//$$ return SettingsPage() | ||
//$$ } | ||
//$$ | ||
//$$ override fun hasConfigGui(): Boolean = true | ||
//#endif | ||
|
||
override fun runtimeGuiCategories(): MutableSet<IModGuiFactory.RuntimeOptionCategoryElement>? { | ||
return null | ||
} | ||
} | ||
|
||
//#endif |
127 changes: 127 additions & 0 deletions
127
src/main/kotlin/dev/dediamondpro/resourcify/config/SettingsPage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package dev.dediamondpro.resourcify.config | ||
|
||
import dev.dediamondpro.resourcify.constraints.ChildLocationSizeConstraint | ||
import dev.dediamondpro.resourcify.elements.DropDown | ||
import dev.dediamondpro.resourcify.gui.PaginatedScreen | ||
import dev.dediamondpro.resourcify.services.ServiceRegistry | ||
import dev.dediamondpro.resourcify.util.localize | ||
import gg.essential.elementa.components.UIBlock | ||
import gg.essential.elementa.components.UIContainer | ||
import gg.essential.elementa.components.UIText | ||
import gg.essential.elementa.components.UIWrappedText | ||
import gg.essential.elementa.constraints.CenterConstraint | ||
import gg.essential.elementa.constraints.ChildBasedMaxSizeConstraint | ||
import gg.essential.elementa.constraints.SiblingConstraint | ||
import gg.essential.elementa.constraints.animation.Animations | ||
import gg.essential.elementa.dsl.* | ||
import gg.essential.elementa.effects.OutlineEffect | ||
import net.minecraft.client.gui.GuiScreen | ||
import java.awt.Color | ||
|
||
class SettingsPage() : PaginatedScreen(adaptScale = false) { | ||
|
||
//#if FORGE && MC <= 11202 | ||
constructor(lastPage: GuiScreen) : this() | ||
//#endif | ||
|
||
init { | ||
val mainBox = UIContainer().constrain { | ||
x = CenterConstraint() | ||
width = min(692.pixels(), basicWidthConstraint { window.getWidth() - 8 }) | ||
height = 100.percent() | ||
} childOf window | ||
UIText("resourcify.config.title".localize()).constrain { | ||
x = CenterConstraint() | ||
y = 8.pixels() | ||
textScale = 2.pixels() | ||
} childOf mainBox | ||
|
||
// Source | ||
val sourceBox = UIBlock(Color(0, 0, 0, 100)).constrain { | ||
x = 0.pixels() | ||
y = SiblingConstraint(padding = 4f) | ||
width = 100.percent() | ||
height = ChildBasedMaxSizeConstraint() + 4.pixels() | ||
} childOf mainBox | ||
val sourceDescriptionBox = UIContainer().constrain { | ||
x = 4.pixels() | ||
y = 4.pixels() | ||
width = 100.percent() - 168.pixels() | ||
height = ChildLocationSizeConstraint() | ||
} childOf sourceBox | ||
UIWrappedText("resourcify.config.source.title".localize()).constrain { | ||
width = 100.percent() | ||
} childOf sourceDescriptionBox | ||
UIWrappedText("resourcify.config.source.description".localize()).constrain { | ||
y = SiblingConstraint(padding = 4f) | ||
width = 100.percent() | ||
color = Color.LIGHT_GRAY.toConstraint() | ||
} childOf sourceDescriptionBox | ||
DropDown( | ||
ServiceRegistry.getServices().map { it.getName() }, | ||
true, mutableListOf(Config.instance.defaultService) | ||
).constrain { | ||
x = 4.pixels(true) | ||
y = CenterConstraint() | ||
width = 160.pixels() | ||
}.onSelectionUpdate { | ||
Config.instance.defaultService = it.first() | ||
Config.save() | ||
} childOf sourceBox | ||
|
||
// Ads | ||
val adsBox = UIBlock(Color(0, 0, 0, 100)).constrain { | ||
x = 0.pixels() | ||
y = SiblingConstraint(padding = 4f) | ||
width = 100.percent() | ||
height = ChildBasedMaxSizeConstraint() + 4.pixels() | ||
} childOf mainBox | ||
val adsDescriptionBox = UIContainer().constrain { | ||
x = 4.pixels() | ||
y = 4.pixels() | ||
width = 100.percent() - 168.pixels() | ||
height = ChildLocationSizeConstraint() | ||
} childOf adsBox | ||
UIWrappedText("resourcify.config.ads.title".localize()).constrain { | ||
width = 100.percent() | ||
} childOf adsDescriptionBox | ||
UIWrappedText("resourcify.config.ads.description".localize()).constrain { | ||
y = SiblingConstraint(padding = 4f) | ||
width = 100.percent() | ||
color = Color.LIGHT_GRAY.toConstraint() | ||
} childOf adsDescriptionBox | ||
val checkBox = UIContainer().constrain { | ||
x = 4.pixels(alignOpposite = true) | ||
y = CenterConstraint() | ||
width = 14.pixels() | ||
height = 14.pixels() | ||
} childOf adsBox effect OutlineEffect(Color.LIGHT_GRAY, 1f) | ||
val check = UIBlock(Color(192, 192, 192, if (Config.instance.adsEnabled) 255 else 0)).constrain { | ||
x = 2.pixels() | ||
y = 2.pixels() | ||
width = 10.pixels() | ||
height = 10.pixels() | ||
}.animateBeforeHide { | ||
setColorAnimation( | ||
Animations.IN_OUT_QUAD, | ||
0.15f, | ||
Color(192, 192, 192, 0).toConstraint(), | ||
0f | ||
) | ||
}.animateAfterUnhide { | ||
setColorAnimation( | ||
Animations.IN_OUT_QUAD, | ||
0.15f, | ||
Color(192, 192, 192, 255).toConstraint(), | ||
0f | ||
) | ||
} childOf checkBox | ||
if (!Config.instance.adsEnabled) check.hide(true) | ||
checkBox.onMouseClick { | ||
val adsEnabled = !Config.instance.adsEnabled | ||
Config.instance.adsEnabled = adsEnabled | ||
Config.save() | ||
if (adsEnabled) check.unhide() else check.hide() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.