Incomplete port to 22w16b
Signed-off-by: Username404 <w.iron.zombie@gmail.com>
This commit is contained in:
parent
0a2175c2e1
commit
3d5b6133e5
|
@ -2,9 +2,11 @@ package fr.username404.snowygui
|
||||||
|
|
||||||
import fr.username404.snowygui.config.Configuration
|
import fr.username404.snowygui.config.Configuration
|
||||||
import fr.username404.snowygui.gui.feature.ButtonImpl
|
import fr.username404.snowygui.gui.feature.ButtonImpl
|
||||||
|
import fr.username404.snowygui.gui.feature.ButtonImpl.Companion.initButtons
|
||||||
import fr.username404.snowygui.gui.feature.ButtonInfo
|
import fr.username404.snowygui.gui.feature.ButtonInfo
|
||||||
import fr.username404.snowygui.misc.AddKeyMaps
|
import fr.username404.snowygui.misc.AddKeyMaps
|
||||||
import net.minecraft.network.chat.TranslatableComponent
|
import net.minecraft.network.chat.Component
|
||||||
|
import net.minecraft.network.chat.Component.translatable
|
||||||
import org.apache.logging.log4j.LogManager
|
import org.apache.logging.log4j.LogManager
|
||||||
import org.apache.logging.log4j.Logger
|
import org.apache.logging.log4j.Logger
|
||||||
import java.lang.reflect.Modifier
|
import java.lang.reflect.Modifier
|
||||||
|
@ -16,7 +18,7 @@ abstract class Snowy {
|
||||||
abstract val annotatedButtons: Set<Class<out ButtonImpl>>
|
abstract val annotatedButtons: Set<Class<out ButtonImpl>>
|
||||||
companion object {
|
companion object {
|
||||||
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
|
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
|
||||||
object MissingComponent: TranslatableComponent(null) { override fun getString(): String = "MISSING_COMPONENT" }
|
val MissingComponent: Component = translatable("MISSING_COMPONENT")
|
||||||
@Suppress("JVM_STATIC_ON_CONST_OR_JVM_FIELD") // See KT-39868
|
@Suppress("JVM_STATIC_ON_CONST_OR_JVM_FIELD") // See KT-39868
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
protected const val FeaturePackage: String = "fr.username404.snowygui.gui.feature"
|
protected const val FeaturePackage: String = "fr.username404.snowygui.gui.feature"
|
||||||
|
|
|
@ -13,16 +13,16 @@ import fr.username404.snowygui.gui.feature.Keystrokes
|
||||||
import fr.username404.snowygui.gui.feature.Zoom
|
import fr.username404.snowygui.gui.feature.Zoom
|
||||||
import net.minecraft.client.gui.screens.Screen
|
import net.minecraft.client.gui.screens.Screen
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
import net.minecraft.network.chat.TranslatableComponent
|
import net.minecraft.network.chat.Component.translatable
|
||||||
import java.util.Optional
|
import java.util.Optional
|
||||||
|
|
||||||
private const val confPrefix: String = "screen.snowy.config"
|
private const val confPrefix: String = "screen.snowy.config"
|
||||||
private val translationComponent = TranslatableComponent(confPrefix)
|
private val translationComponent = translatable(confPrefix)
|
||||||
|
|
||||||
var configScreenParent: Screen? = null
|
var configScreenParent: Screen? = null
|
||||||
|
|
||||||
private fun supplyComponent(string: String?): Optional<Component> = string?.run {
|
private fun supplyComponent(string: String?): Optional<Component> = string?.run {
|
||||||
Optional.of(TranslatableComponent(string))
|
Optional.of(translatable(string))
|
||||||
} ?: Optional.empty()
|
} ?: Optional.empty()
|
||||||
|
|
||||||
val SnowyConfigScreen: Screen = object: Screen(translationComponent) {
|
val SnowyConfigScreen: Screen = object: Screen(translationComponent) {
|
||||||
|
@ -47,20 +47,20 @@ val SnowyConfigScreen: Screen = object: Screen(translationComponent) {
|
||||||
.setShouldListSmoothScroll(true)
|
.setShouldListSmoothScroll(true)
|
||||||
.setTitle(translationComponent).apply {
|
.setTitle(translationComponent).apply {
|
||||||
with(entryBuilder()) {
|
with(entryBuilder()) {
|
||||||
getOrCreateCategory(TranslatableComponent("$confPrefix.general")).addEntry(startSubCategory(TranslatableComponent("$confPrefix.behavior")).apply {
|
getOrCreateCategory(translatable("$confPrefix.general")).addEntry(startSubCategory(translatable("$confPrefix.behavior")).apply {
|
||||||
addAll(
|
addAll(
|
||||||
setOf(
|
setOf(
|
||||||
startBooleanToggle(TranslatableComponent("$confPrefix.behavior.sortalphabetically"), sortAlphabetically)
|
startBooleanToggle(translatable("$confPrefix.behavior.sortalphabetically"), sortAlphabetically)
|
||||||
.setDefaultValue(true).requireRestart()
|
.setDefaultValue(true).requireRestart()
|
||||||
.setSaveConsumer { sortAlphabetically = it }.build(),
|
.setSaveConsumer { sortAlphabetically = it }.build(),
|
||||||
startDoubleField(TranslatableComponent("$confPrefix.behavior.zoom.factor"), Zoom.zoomFactor).setSaveConsumer {
|
startDoubleField(translatable("$confPrefix.behavior.zoom.factor"), Zoom.zoomFactor).setSaveConsumer {
|
||||||
Zoom.zoomFactor = it
|
Zoom.zoomFactor = it
|
||||||
}.setMin(1.1).build(),
|
}.setMin(1.1).build(),
|
||||||
startBooleanToggle(TranslatableComponent("$confPrefix.behavior.zoom.smoothcamera"), Zoom.smoothCameraOnZoom).setSaveConsumer {
|
startBooleanToggle(translatable("$confPrefix.behavior.zoom.smoothcamera"), Zoom.smoothCameraOnZoom).setSaveConsumer {
|
||||||
Zoom.smoothCameraOnZoom = it
|
Zoom.smoothCameraOnZoom = it
|
||||||
Zoom.execAction()
|
Zoom.execAction()
|
||||||
}.build(),
|
}.build(),
|
||||||
startEnumSelector(TranslatableComponent("$confPrefix.behavior.keystrokes.position"), Keystrokes.Position::class.java, Keystrokes.Position.values().find {
|
startEnumSelector(translatable("$confPrefix.behavior.keystrokes.position"), Keystrokes.Position::class.java, Keystrokes.Position.values().find {
|
||||||
it.value == Keystrokes.currentPosition
|
it.value == Keystrokes.currentPosition
|
||||||
}).setSaveConsumer {
|
}).setSaveConsumer {
|
||||||
Keystrokes.currentPosition = it.value
|
Keystrokes.currentPosition = it.value
|
||||||
|
@ -68,7 +68,7 @@ val SnowyConfigScreen: Screen = object: Screen(translationComponent) {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}.build())
|
}.build())
|
||||||
.addEntry(startSubCategory(TranslatableComponent("$confPrefix.colors")).also { builder ->
|
.addEntry(startSubCategory(translatable("$confPrefix.colors")).also { builder ->
|
||||||
builder.addAll(
|
builder.addAll(
|
||||||
ClickGui.clickBoxes.map { box ->
|
ClickGui.clickBoxes.map { box ->
|
||||||
startColorField(box.name, box.color).setSaveConsumer {
|
startColorField(box.name, box.color).setSaveConsumer {
|
||||||
|
@ -77,7 +77,7 @@ val SnowyConfigScreen: Screen = object: Screen(translationComponent) {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}.build()).addEntry(startStrList(
|
}.build()).addEntry(startStrList(
|
||||||
TranslatableComponent(Category.MACROS.translationKey),
|
Category.MACROS.box.name,
|
||||||
macrosButtons.getTitleCommand()
|
macrosButtons.getTitleCommand()
|
||||||
).setInsertInFront(false).setDefaultValue(Configuration.foundMacros.getTitleCommand()).setErrorSupplier { list ->
|
).setInsertInFront(false).setDefaultValue(Configuration.foundMacros.getTitleCommand()).setErrorSupplier { list ->
|
||||||
supplyComponent(if (list.size > buttonsMax) "$confPrefix.general.macros.toomuchbuttons" else null)
|
supplyComponent(if (list.size > buttonsMax) "$confPrefix.general.macros.toomuchbuttons" else null)
|
||||||
|
@ -93,7 +93,7 @@ val SnowyConfigScreen: Screen = object: Screen(translationComponent) {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}.setTooltip(TranslatableComponent("$confPrefix.general.macros.tooltip")).setSaveConsumer { it.forEach { string ->
|
}.setTooltip(translatable("$confPrefix.general.macros.tooltip")).setSaveConsumer { it.forEach { string ->
|
||||||
with(string.split(":")) {
|
with(string.split(":")) {
|
||||||
if (size == 2) Macro(title = component1().trimStart(), command = component2().trim()).let { newMacro ->
|
if (size == 2) Macro(title = component1().trimStart(), command = component2().trim()).let { newMacro ->
|
||||||
macrosButtons.removeIf { existingMacro ->
|
macrosButtons.removeIf { existingMacro ->
|
||||||
|
|
|
@ -29,6 +29,8 @@ import kotlinx.serialization.ExperimentalSerializationApi
|
||||||
import kotlinx.serialization.decodeFromString
|
import kotlinx.serialization.decodeFromString
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
import net.minecraft.network.chat.MutableComponent
|
||||||
|
import net.minecraft.network.chat.contents.TranslatableContents
|
||||||
import org.jetbrains.annotations.ApiStatus
|
import org.jetbrains.annotations.ApiStatus
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
import kotlin.reflect.full.isSuperclassOf
|
import kotlin.reflect.full.isSuperclassOf
|
||||||
|
@ -46,9 +48,9 @@ object Configuration {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"box_colors" to mapOf<String, Int>(*ClickGui.clickBoxes.filter { box ->
|
"box_colors" to mapOf<String, Int>(*ClickGui.clickBoxes.filter { box ->
|
||||||
(box.name.key != MissingComponent.key) && Category.fromBox(box)?.categoryColor != box.color
|
((box.name.contents as TranslatableContents).key != (MissingComponent.contents as TranslatableContents).key) && Category.fromBox(box)?.categoryColor != box.color
|
||||||
}.map {
|
}.map {
|
||||||
it.name.key to it.color
|
(it.name as TranslatableContents).key to it.color
|
||||||
}.toTypedArray()),
|
}.toTypedArray()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,9 @@ package fr.username404.snowygui.gui
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack
|
import com.mojang.blaze3d.vertex.PoseStack
|
||||||
import net.minecraft.client.gui.screens.Screen
|
import net.minecraft.client.gui.screens.Screen
|
||||||
import net.minecraft.network.chat.TranslatableComponent
|
import net.minecraft.network.chat.Component.translatable
|
||||||
|
|
||||||
abstract class SnowyScreen(translatableString: String = "screen.snowy.gui", private val willPauseScreen: Boolean = false): Screen(TranslatableComponent(translatableString)) {
|
abstract class SnowyScreen(translatableString: String = "screen.snowy.gui", private val willPauseScreen: Boolean = false): Screen(translatable(translatableString)) {
|
||||||
abstract val components: MutableCollection<Element>
|
abstract val components: MutableCollection<Element>
|
||||||
override fun render(poseStack: PoseStack?, i: Int, j: Int, f: Float) {
|
override fun render(poseStack: PoseStack?, i: Int, j: Int, f: Float) {
|
||||||
if (poseStack != null) {
|
if (poseStack != null) {
|
||||||
|
|
|
@ -19,7 +19,7 @@ import kotlinx.coroutines.CoroutineStart
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import net.minecraft.client.Minecraft
|
import net.minecraft.client.Minecraft
|
||||||
import net.minecraft.network.chat.TranslatableComponent
|
import net.minecraft.network.chat.Component
|
||||||
import org.jetbrains.annotations.ApiStatus
|
import org.jetbrains.annotations.ApiStatus
|
||||||
import java.util.TreeSet
|
import java.util.TreeSet
|
||||||
import kotlin.collections.LinkedHashSet
|
import kotlin.collections.LinkedHashSet
|
||||||
|
@ -28,9 +28,9 @@ import kotlin.collections.LinkedHashSet
|
||||||
class ClickBox(
|
class ClickBox(
|
||||||
x: Double, y: Double,
|
x: Double, y: Double,
|
||||||
override var color: Int = Colors.BLUE.hexValue,
|
override var color: Int = Colors.BLUE.hexValue,
|
||||||
val name: TranslatableComponent = MissingComponent
|
val name: Component = MissingComponent
|
||||||
): ColoredElement(x, y, 80, 10, color, 0.5F) {
|
): ColoredElement(x, y, 80, 10, color, 0.5F) {
|
||||||
fun isCategory(c: Category): Boolean = (name.key == c.translationKey)
|
fun isCategory(c: Category): Boolean = (name.string == c.box.name.string)
|
||||||
val buttons: MutableSet<ButtonImpl> =
|
val buttons: MutableSet<ButtonImpl> =
|
||||||
if (sortAlphabetically)
|
if (sortAlphabetically)
|
||||||
TreeSet(compareBy(String.CASE_INSENSITIVE_ORDER) { it.title })
|
TreeSet(compareBy(String.CASE_INSENSITIVE_ORDER) { it.title })
|
||||||
|
@ -126,7 +126,7 @@ class ClickBox(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
init {
|
init {
|
||||||
savedColors?.get(name.key)?.let {
|
savedColors?.get(name.string)?.let {
|
||||||
this.color = it
|
this.color = it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,8 @@ package fr.username404.snowygui.gui.feature
|
||||||
|
|
||||||
import fr.username404.snowygui.ClickGui
|
import fr.username404.snowygui.ClickGui
|
||||||
import fr.username404.snowygui.gui.elements.ClickBox
|
import fr.username404.snowygui.gui.elements.ClickBox
|
||||||
import net.minecraft.network.chat.TranslatableComponent
|
import net.minecraft.network.chat.Component.translatable
|
||||||
|
import net.minecraft.network.chat.contents.TranslatableContents
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should be used on classes/objects extending [ButtonImpl]
|
* Should be used on classes/objects extending [ButtonImpl]
|
||||||
|
@ -22,7 +23,7 @@ annotation class ButtonInfo(
|
||||||
TOGGLE,
|
TOGGLE,
|
||||||
CLICK
|
CLICK
|
||||||
}
|
}
|
||||||
enum class Category(val translationKey: String, val categoryColor: Int, val shouldHide: Boolean = false) {
|
enum class Category(translationKey: String, val categoryColor: Int, val shouldHide: Boolean = false) {
|
||||||
MISC("snowy.clickbox.misc", Colors.BLUE),
|
MISC("snowy.clickbox.misc", Colors.BLUE),
|
||||||
HUD("snowy.clickbox.hud", Colors.DARK_PURPLE),
|
HUD("snowy.clickbox.hud", Colors.DARK_PURPLE),
|
||||||
MACROS("snowy.clickbox.macros", Colors.GREEN);
|
MACROS("snowy.clickbox.macros", Colors.GREEN);
|
||||||
|
@ -35,14 +36,14 @@ annotation class ButtonInfo(
|
||||||
x = 4.0 + (ordinal - ClickGui.clickBoxes.count { category ->
|
x = 4.0 + (ordinal - ClickGui.clickBoxes.count { category ->
|
||||||
category.hidden
|
category.hidden
|
||||||
}) * 86, y = 4.0,
|
}) * 86, y = 4.0,
|
||||||
name = TranslatableComponent(translationKey),
|
name = translatable(translationKey),
|
||||||
color = categoryColor
|
color = categoryColor
|
||||||
); private set
|
); private set
|
||||||
private fun addBox() = ClickGui.components.add(box.apply { if (shouldHide) hidden = true })
|
private fun addBox() = ClickGui.components.add(box.apply { if (shouldHide) hidden = true })
|
||||||
constructor(
|
constructor(
|
||||||
translationKey: String, categoryColor: Colors, condition: Boolean = false
|
translationKey: String, categoryColor: Colors, condition: Boolean = false
|
||||||
): this(translationKey, categoryColor.hexValue, condition)
|
): this(translationKey, categoryColor.hexValue, condition)
|
||||||
constructor(categoryBox: ClickBox): this(translationKey = categoryBox.name.key, categoryColor = categoryBox.color) {
|
constructor(categoryBox: ClickBox): this(translationKey = (categoryBox.name.contents as TranslatableContents).key, categoryColor = categoryBox.color) {
|
||||||
with(ClickGui.components) {
|
with(ClickGui.components) {
|
||||||
remove(this@Category.box)
|
remove(this@Category.box)
|
||||||
this@Category.box = categoryBox
|
this@Category.box = categoryBox
|
||||||
|
|
|
@ -8,10 +8,13 @@ object GammaBoost: ButtonImpl() {
|
||||||
private var oldGamma = 0.0
|
private var oldGamma = 0.0
|
||||||
override fun execAction() {
|
override fun execAction() {
|
||||||
with(Minecraft.getInstance().options) {
|
with(Minecraft.getInstance().options) {
|
||||||
gamma = if (toggled) {
|
val gamma = gamma().get();
|
||||||
|
gamma().set(
|
||||||
|
if (toggled) {
|
||||||
if (gamma < boost) oldGamma = gamma
|
if (gamma < boost) oldGamma = gamma
|
||||||
boost
|
boost
|
||||||
} else oldGamma
|
} else oldGamma
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue