Skip to content

Commit e2e434f

Browse files
committed
Single settings window
1 parent 498b5af commit e2e434f

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/ModuleButton.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,26 @@ class ModuleButton(val module: Module, owner: WindowComponent<*>) : ListButton(o
1212
override val active get() = module.isEnabled
1313
private val gui = owner.owner
1414

15-
private val settingsWindow = SettingsWindow(this, gui)
16-
1715
override fun performClickAction(e: GuiEvent.MouseClick) {
1816
when (e.button) {
1917
Mouse.Button.Left -> if (hovered) module.toggle()
2018
Mouse.Button.Right -> {
21-
gui.scheduleAction {
22-
gui.windows.addChild(settingsWindow.apply {
23-
position = e.mouse
24-
})
19+
gui.apply {
20+
windows.children.forEach { child ->
21+
if (child is SettingsWindow && child.button == this@ModuleButton) {
22+
gui.scheduleAction {
23+
gui.windows.removeChild(child)
24+
}
25+
}
26+
}
27+
28+
scheduleAction {
29+
windows.addChild(SettingsWindow(this@ModuleButton, this).apply {
30+
position = e.mouse
31+
})
32+
}
2533
}
34+
2635
}
2736
}
2837
}

common/src/main/kotlin/com/lambda/gui/impl/clickgui/windows/SettingsWindow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import com.lambda.gui.impl.clickgui.AbstractClickGui
77
import com.lambda.gui.impl.clickgui.buttons.ModuleButton
88

99
class SettingsWindow(
10-
button: ModuleButton,
10+
val button: ModuleButton,
1111
owner: AbstractClickGui
1212
) : ListWindow<ListButton>(owner) {
1313
private val module = button.module

0 commit comments

Comments
 (0)