Compare commits

..

3 Commits

Author SHA1 Message Date
630afa2e53
Set default strings for macros in ConfigScreen
Signed-off-by: Username404-59 <w.iron.zombie@gmail.com>
2026-02-22 03:24:27 +01:00
d8b37fc4ab
Fix a crash on launch when macros exist on neoforge
Signed-off-by: Username404-59 <w.iron.zombie@gmail.com>
2026-02-22 03:14:34 +01:00
2341dafe1b
Fix FontUtil.drawScaled
Signed-off-by: Username404-59 <w.iron.zombie@gmail.com>
2026-02-22 01:44:14 +01:00
6 changed files with 22 additions and 17 deletions

View File

@ -1,6 +1,6 @@
package fr.username404.snowygui
import fr.username404.snowygui.config.Configuration
import fr.username404.snowygui.config.LazyConfiguration
import fr.username404.snowygui.gui.feature.ButtonImpl
import fr.username404.snowygui.gui.feature.ButtonInfo
import fr.username404.snowygui.misc.AddKeyMaps
@ -13,7 +13,7 @@ import java.lang.reflect.Modifier
abstract class Snowy {
protected fun Class<*>.isValidForButtonCollection(): Boolean =
!Modifier.isAbstract(modifiers) && declaredAnnotations.any { it is ButtonInfo && !it.ignored }
private val displayInitMessage: Boolean by Configuration
private val displayInitMessage: Lazy<Boolean> by LazyConfiguration
abstract val annotatedButtons: Lazy<Set<Class<out ButtonImpl>>>
companion object {
val MissingComponent: Component = translatable("MISSING_COMPONENT")
@ -36,7 +36,7 @@ abstract class Snowy {
}
}
fun atInit() {
if (displayInitMessage) logs.info("Init point of SnowyGUI hit.")
if (displayInitMessage.value) logs.info("Init point of SnowyGUI hit.")
eventsInit()
}
}

View File

@ -5,6 +5,7 @@ import fr.username404.snowygui.gui.elements.ClickBox
import fr.username404.snowygui.gui.elements.ClickBox.Companion.sortAlphabetically
import fr.username404.snowygui.gui.feature.*
import fr.username404.snowygui.utils.FontUtil
import me.shedaniel.clothconfig2.gui.entries.StringListListEntry
import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.gui.screens.Screen
import net.minecraft.network.chat.Component
@ -74,7 +75,9 @@ val SnowyConfigScreen: Screen = object: Screen(translationComponent) {
}.build()).addEntry(startStrList(
Category.MACROS.box.name,
macrosButtons.getTitleCommand()
).setInsertInFront(false).setDefaultValue(Configuration.foundMacros.getTitleCommand()).setCellErrorSupplier { cell ->
).setCreateNewInstance {
entry -> StringListListEntry.StringListCell("ExampleMacro: say hello", entry)
}.setInsertInFront(false).setDefaultValue(Configuration.foundMacros.getTitleCommand()).setCellErrorSupplier { cell ->
with(cell.split(":")) {
supplyComponent(
when {

View File

@ -175,3 +175,9 @@ object Configuration {
operator fun <T> setValue(ref: Any?, property: KProperty<*>, value: T) = @Suppress("DEPRECATION_ERROR")
ModifiableValues.setValue(ref, property, value)
}
object LazyConfiguration {
inline operator fun <reified T: Any> getValue(ref: Any?, property: KProperty<*>): Lazy<T> = lazy {
Configuration.getValue<T>(ref, property);
}
}

View File

@ -4,18 +4,17 @@ import net.minecraft.client.Minecraft
import fr.username404.snowygui.gui.feature.Colors
import net.minecraft.client.gui.GuiGraphics
import net.minecraft.util.ARGB
import org.joml.Matrix3x2f
object FontUtil {
fun drawScaled(guiGraphics: GuiGraphics, text: String, x: Double, y: Double, scaleFactor: Float, color: Colors = Colors.BLACK) {
val stack = guiGraphics.pose()
stack.scale(scaleFactor, scaleFactor, Matrix3x2f())
stack.scale(scaleFactor, scaleFactor)
guiGraphics.drawString(
Minecraft.getInstance().font, text,
x.toInt(), y.toInt(),
(x / scaleFactor).toInt(), (y / scaleFactor).toInt(),
ARGB.opaque(color.hexValue), false
)
val factorToOriginal = 1F / scaleFactor
stack.scale(factorToOriginal, factorToOriginal, Matrix3x2f())
stack.scale(factorToOriginal, factorToOriginal)
}
}

View File

@ -1,5 +1,6 @@
package fr.username404.snowygui.forge
import fr.username404.snowygui.ClickGui
import fr.username404.snowygui.Snowy
import fr.username404.snowygui.config.SnowyConfigScreen
import fr.username404.snowygui.config.configScreenParent
@ -15,7 +16,11 @@ import net.neoforged.neoforgespi.language.ModFileScanData
@Mod("snowygui")
@Suppress("UNUSED_PARAMETER")
class ForgeInit(container: ModContainer): Snowy() {
private fun initSetup(event: FMLClientSetupEvent) = atInit()
private fun initSetup(event: FMLClientSetupEvent) {
atInit()
ClickGui.tick()
ButtonImpl.initButtons()
}
override val annotatedButtons = lazy { // Forge-specific reflection
ModList.get()
.allScanData

View File

@ -1,18 +1,10 @@
package fr.username404.snowygui.forge
import fr.username404.snowygui.ClickGui
import fr.username404.snowygui.gui.feature.ButtonImpl
import fr.username404.snowygui.misc.AddKeyMaps
import net.neoforged.bus.api.SubscribeEvent
import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent
object MiscModBusHandlers {
@SubscribeEvent
fun handleClickGuiInit(event: RegisterMenuScreensEvent) {
ClickGui.tick()
ButtonImpl.initButtons()
}
@SubscribeEvent
fun handleKeys(event: RegisterKeyMappingsEvent) {
AddKeyMaps.list.forEach {