hibiscus/src/main/kotlin/codes/som/hibiscus/gui/ModuleControlsUI.kt

84 lines
2.9 KiB
Kotlin

package codes.som.hibiscus.gui
import codes.som.hibiscus.HibiscusMod
import codes.som.hibiscus.api.feature.Feature
import codes.som.hibiscus.api.feature.FeatureCategory
import imgui.ImGui
import imgui.flag.ImGuiCol
import imgui.flag.ImGuiCond.Once
import imgui.flag.ImGuiWindowFlags
import imgui.flag.ImGuiWindowFlags.AlwaysVerticalScrollbar
import imgui.type.ImBoolean
object ModuleControlsUI {
private val moduleValueWindows = mutableMapOf<Feature, ImBoolean>()
private fun categoryPanel(category: FeatureCategory, initialX: Float, initialY: Float) {
ImGui.setNextWindowPos(initialX, initialY, Once)
ImGui.setNextWindowCollapsed(true, Once)
ImGui.setNextWindowSize(300f, 0f, Once)
ImGui.begin(category.humanName, AlwaysVerticalScrollbar)
for (feature in HibiscusMod.features.getAllFeatures().filter { it.category == category }) {
featureControls(feature)
}
ImGui.end()
}
private fun featureControls(feature: Feature) {
if (feature.values.exist()) {
ImGui.columns(2, "Features Columns", false)
ImGui.setColumnWidth(0, ImGui.getWindowContentRegionMaxX() - ImGui.getWindowContentRegionMinX() - 24)
}
if (feature.enabled) {
ImGui.pushStyleColor(ImGuiCol.Button, 0.819f, 0.619f, 1.000f, 0.8f)
ImGui.pushStyleColor(ImGuiCol.ButtonHovered, 0.819f, 0.619f, 1.000f, 0.95f)
ImGui.pushStyleColor(ImGuiCol.ButtonActive, 0.819f, 0.619f, 1.000f, 1f)
} else {
ImGui.pushStyleColor(ImGuiCol.Button, 0.63f, 0.47f, 0.83f, 0.14f)
ImGui.pushStyleColor(ImGuiCol.ButtonHovered, 0.352f, 0.196f, 0.454f, 0.86f)
ImGui.pushStyleColor(ImGuiCol.ButtonActive, 0.352f, 0.196f, 0.454f, 1f)
}
if (ImGui.button(feature.name, -1f, 0f)) {
feature.enabled = !feature.enabled
}
ImGui.popStyleColor()
ImGui.popStyleColor()
ImGui.popStyleColor()
if (feature.values.exist()) {
val showValueWindow = moduleValueWindows.getOrPut(feature) { ImBoolean(false) }
ImGui.nextColumn()
if (ImGui.radioButton("##${feature.name} values", showValueWindow.get())) {
showValueWindow.set(!showValueWindow.get())
}
ImGui.nextColumn()
if (showValueWindow.get()) {
if (ImGui.begin("${feature.name}##Feature Controls", showValueWindow, ImGuiWindowFlags.NoCollapse)) {
for (value in feature.values)
value.drawUIControl()
}
ImGui.end()
}
}
}
fun render(delta: Float) {
for ((index, category) in FeatureCategory.values().withIndex()) {
categoryPanel(
category,
ImGui.getMainViewport().posX + 10f,
ImGui.getMainViewport().posY + 10f + index * 20f
)
}
}
}