aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/util')
-rw-r--r--src/main/kotlin/util/MoulConfigUtils.kt13
-rw-r--r--src/main/kotlin/util/StringUtil.kt9
-rw-r--r--src/main/kotlin/util/customgui/CustomGui.kt12
3 files changed, 34 insertions, 0 deletions
diff --git a/src/main/kotlin/util/MoulConfigUtils.kt b/src/main/kotlin/util/MoulConfigUtils.kt
index 2e52092..62bf3dd 100644
--- a/src/main/kotlin/util/MoulConfigUtils.kt
+++ b/src/main/kotlin/util/MoulConfigUtils.kt
@@ -7,6 +7,7 @@ import io.github.notenoughupdates.moulconfig.gui.GuiComponent
import io.github.notenoughupdates.moulconfig.gui.GuiComponentWrapper
import io.github.notenoughupdates.moulconfig.gui.GuiContext
import io.github.notenoughupdates.moulconfig.gui.GuiImmediateContext
+import io.github.notenoughupdates.moulconfig.gui.KeyboardEvent
import io.github.notenoughupdates.moulconfig.gui.MouseEvent
import io.github.notenoughupdates.moulconfig.observer.GetSetter
import io.github.notenoughupdates.moulconfig.platform.ModernRenderContext
@@ -247,6 +248,18 @@ object MoulConfigUtils {
}
}
+ fun typeMCComponentInPlace(
+ component: GuiComponent,
+ x: Int,
+ y: Int,
+ w: Int,
+ h: Int,
+ keyboardEvent: KeyboardEvent
+ ): Boolean {
+ val immContext = createInPlaceFullContext(null, IMinecraft.instance.mouseX, IMinecraft.instance.mouseY)
+ return component.keyboardEvent(keyboardEvent, immContext.translated(x, y, w, h))
+ }
+
fun clickMCComponentInPlace(
component: GuiComponent,
x: Int,
diff --git a/src/main/kotlin/util/StringUtil.kt b/src/main/kotlin/util/StringUtil.kt
index f080d5a..68e161a 100644
--- a/src/main/kotlin/util/StringUtil.kt
+++ b/src/main/kotlin/util/StringUtil.kt
@@ -10,4 +10,13 @@ object StringUtil {
}
fun Iterable<String>.unwords() = joinToString(" ")
+ fun nextLexicographicStringOfSameLength(string: String): String {
+ val next = StringBuilder(string)
+ while (next.lastOrNull() == Character.MAX_VALUE) next.setLength(next.length - 1)
+ if (next.isEmpty()) return "" // There is no upper bound. Fall back to the empty string
+ val lastIdx = next.indices.last
+ next[lastIdx] = (next[lastIdx] + 1)
+ return next.toString()
+ }
+
}
diff --git a/src/main/kotlin/util/customgui/CustomGui.kt b/src/main/kotlin/util/customgui/CustomGui.kt
index 5224448..35c60ac 100644
--- a/src/main/kotlin/util/customgui/CustomGui.kt
+++ b/src/main/kotlin/util/customgui/CustomGui.kt
@@ -76,4 +76,16 @@ abstract class CustomGui {
open fun mouseDragged(mouseX: Double, mouseY: Double, button: Int, deltaX: Double, deltaY: Double): Boolean {
return false
}
+
+ open fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
+ return false
+ }
+
+ open fun charTyped(chr: Char, modifiers: Int): Boolean {
+ return false
+ }
+
+ open fun keyReleased(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
+ return false
+ }
}