Skip to content

Commit

Permalink
Merge pull request #492 from Edouard127/gui_refactor_1
Browse files Browse the repository at this point in the history
Added copy/paste in module options
  • Loading branch information
Avanatiker authored May 5, 2023
2 parents 3a98b81 + e43e8ee commit 36b02e5
Showing 1 changed file with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import com.lambda.client.util.graphics.VertexHelper
import com.lambda.client.util.graphics.font.FontRenderAdapter
import com.lambda.client.util.math.Vec2d
import com.lambda.client.util.math.Vec2f
import net.minecraft.client.gui.GuiScreen
import org.lwjgl.input.Keyboard
import kotlin.math.max
import kotlin.math.min

class StringButton(val setting: StringSetting) : BooleanSlider(setting.name, 1.0, setting.description, setting.visibility) {

Expand Down Expand Up @@ -61,18 +63,27 @@ class StringButton(val setting: StringSetting) : BooleanSlider(setting.name, 1.0
override fun onKeyInput(keyCode: Int, keyState: Boolean) {
super.onKeyInput(keyCode, keyState)
val typedChar = Keyboard.getEventCharacter()
if (keyState) {
when (keyCode) {
Keyboard.KEY_RETURN -> {
onStopListening(true)
}
Keyboard.KEY_BACK, Keyboard.KEY_DELETE -> {
componentName = componentName.substring(0, max(componentName.length - 1, 0))
if (!keyState) return

when (keyCode) {
Keyboard.KEY_V, Keyboard.KEY_INSERT -> {
if (!GuiScreen.isCtrlKeyDown() && keyCode == Keyboard.KEY_V) {
componentName += typedChar
} else {
componentName += GuiScreen.getClipboardString().trim()
}
else -> if (typedChar >= ' ') {
}
Keyboard.KEY_C -> {
if (GuiScreen.isCtrlKeyDown()) {
GuiScreen.setClipboardString(componentName)
} else {
componentName += typedChar
}
}
Keyboard.KEY_RETURN -> onStopListening(true)
Keyboard.KEY_BACK -> componentName = componentName.dropLast(1)
Keyboard.KEY_DELETE -> componentName = ""
else -> if (typedChar >= ' ') componentName += typedChar
}
}

Expand Down

0 comments on commit 36b02e5

Please sign in to comment.