Skip to content

Commit f1924cf

Browse files
committed
Keybind setting picker
1 parent 8cb2c81 commit f1924cf

File tree

4 files changed

+45
-21
lines changed

4 files changed

+45
-21
lines changed

common/src/main/kotlin/com/lambda/gui/component/core/TextField.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ class TextField(
4242
val textWidth get() = FontRenderer.getWidth(text, scale)
4343
val textHeight get() = FontRenderer.getHeight(scale)
4444

45+
fun mergeFrom(other: TextField) {
46+
text = other.text
47+
color = other.color
48+
scale = other.scale
49+
shadow = other.shadow
50+
51+
textHAlignment = HAlign.RIGHT
52+
textVAlignment = other.textVAlignment
53+
offsetX = other.offsetX
54+
offsetY = other.offsetY
55+
}
56+
4557
init {
4658
properties.interactionPassthrough = true
4759

common/src/main/kotlin/com/lambda/gui/impl/clickgui/module/SettingLayout.kt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ abstract class SettingLayout <V : Any, T: AbstractSetting<V>> (
4747

4848
override val isShown: Boolean get() = super.isShown && isVisible
4949

50+
51+
5052
init {
5153
isMinimized = true
5254

@@ -65,16 +67,6 @@ abstract class SettingLayout <V : Any, T: AbstractSetting<V>> (
6567
content.destroy()
6668
} else {
6769
backgroundTint(true)
68-
69-
// Minimize other expandable settings when this one gets opened
70-
onWindowExpand {
71-
owner.children
72-
.filterIsInstance<SettingLayout<*, *>>()
73-
.filter { it.expandable }
74-
.forEach {
75-
if (it != this) it.isMinimized = true
76-
}
77-
}
7870
}
7971

8072
titleBar.textField.onUpdate {

common/src/main/kotlin/com/lambda/gui/impl/clickgui/module/settings/KeybindPicker.kt

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,45 @@ import com.lambda.gui.component.HAlign
2222
import com.lambda.gui.component.core.TextField.Companion.textField
2323
import com.lambda.gui.component.core.UIBuilder
2424
import com.lambda.gui.component.layout.Layout
25+
import com.lambda.gui.impl.clickgui.module.ModuleLayout
2526
import com.lambda.gui.impl.clickgui.module.SettingLayout
2627
import com.lambda.util.KeyCode
28+
import com.lambda.util.Mouse
2729
import com.lambda.util.extension.displayValue
2830

2931
class KeybindPicker(
3032
owner: Layout,
3133
setting: KeyBindSetting
3234
) : SettingLayout<KeyCode, KeyBindSetting>(owner, setting) {
35+
private var isListening = false
3336

3437
init {
3538
textField {
36-
text = setting.value.displayValue
37-
textHAlignment = HAlign.RIGHT
39+
onUpdate {
40+
mergeFrom(titleBar.textField)
41+
text = if (isListening) "..." else setting.value.displayValue
42+
textHAlignment = HAlign.RIGHT
43+
}
44+
}
45+
46+
onMouseAction(Mouse.Button.Left) {
47+
isListening = !isListening
48+
}
49+
50+
onKeyPress { key ->
51+
if (!isListening) return@onKeyPress
52+
53+
settingDelegate = key
54+
isListening = false
55+
}
56+
57+
onShow {
58+
isListening = false
59+
}
60+
61+
onTick {
62+
val module = (owner.owner as? ModuleLayout) ?: return@onTick
63+
if (module.isMinimized) isListening = false
3864
}
3965
}
4066

common/src/main/kotlin/com/lambda/gui/impl/clickgui/module/settings/SettingSlider.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,12 @@ abstract class SettingSlider <V : Any, T: AbstractSetting<V>>(
6464

6565
onUpdate {
6666
lastValue = text
67+
mergeFrom(textField)
6768
text = settingValue
68-
if (lastValue != text) changeAnimation = 0.0
69-
70-
offsetX = textField.offsetX
71-
offsetY = textField.offsetY
7269

70+
if (lastValue != text) changeAnimation = 0.0
7371
textHAlignment = HAlign.RIGHT
74-
textVAlignment = textField.textVAlignment
75-
shadow = textField.shadow
76-
color = textField.color
77-
78-
scale = textField.scale * lerp(changeAnimation, 1.1, 1.0)
72+
scale *= lerp(changeAnimation, 1.1, 1.0)
7973
}
8074
}
8175
}

0 commit comments

Comments
 (0)