101 lines
3.4 KiB
Kotlin
101 lines
3.4 KiB
Kotlin
package codes.som.hibiscus.gui
|
|
|
|
import codes.som.hibiscus.Hibiscus
|
|
import codes.som.hibiscus.api.feature.Feature
|
|
import codes.som.hibiscus.api.feature.FeatureCategory
|
|
import codes.som.hibiscus.features.overlay.Overlay
|
|
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 FeatureControlsUI {
|
|
private val moduleValueWindows = mutableMapOf<Feature, ImBoolean>()
|
|
|
|
private fun drawCategoryPanel(category: FeatureCategory) {
|
|
ImGui.begin(category.humanName, AlwaysVerticalScrollbar)
|
|
|
|
for (feature in Hibiscus.features.getAllFeatures().filter { it.category == category }) {
|
|
drawFeatureControls(feature)
|
|
}
|
|
|
|
ImGui.end()
|
|
}
|
|
|
|
private fun drawFeatureControls(feature: Feature) {
|
|
if (feature.values.exist()) {
|
|
ImGui.columns(2, "Features Columns", false)
|
|
ImGui.setColumnWidth(0, ImGui.getWindowContentRegionMaxX() - ImGui.getWindowContentRegionMinX() - 30)
|
|
}
|
|
|
|
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(3)
|
|
|
|
if (feature.values.exist()) {
|
|
val showValueWindow = moduleValueWindows.getOrPut(feature) { ImBoolean(false) }
|
|
|
|
ImGui.nextColumn()
|
|
if (ImGui.radioButton("##${feature.name} values", showValueWindow.get()))
|
|
showValueWindow.flip()
|
|
ImGui.nextColumn()
|
|
|
|
if (showValueWindow.get()) {
|
|
if (ImGui.begin("${feature.name}##Feature Controls", showValueWindow, ImGuiWindowFlags.NoCollapse)) {
|
|
for (value in feature.values)
|
|
value.drawUIControl()
|
|
}
|
|
ImGui.end()
|
|
}
|
|
}
|
|
}
|
|
|
|
private fun drawOverlaySettings() {
|
|
val overlayFeature = Hibiscus.features.getFeature<Overlay>()
|
|
if (ImGui.begin("${overlayFeature.name}##Feature Controls"))
|
|
for (value in overlayFeature.values)
|
|
value.drawUIControl()
|
|
ImGui.end()
|
|
}
|
|
|
|
fun render(delta: Float) {
|
|
var yOffset = 0f
|
|
|
|
fun pushInitialPanelConfig() {
|
|
val initialX = ImGui.getMainViewport().posX + 10f
|
|
val initialY = ImGui.getMainViewport().posY + 10f + yOffset
|
|
|
|
ImGui.setNextWindowPos(initialX, initialY, Once)
|
|
ImGui.setNextWindowCollapsed(true, Once)
|
|
ImGui.setNextWindowSize(300f, 0f, Once)
|
|
}
|
|
|
|
for (category in FeatureCategory.values()) {
|
|
if (category == FeatureCategory.OVERLAY)
|
|
continue
|
|
|
|
pushInitialPanelConfig()
|
|
drawCategoryPanel(category)
|
|
|
|
yOffset += 30f
|
|
}
|
|
|
|
pushInitialPanelConfig()
|
|
drawOverlaySettings()
|
|
}
|
|
}
|