From 9106e19c3eb6a84fb10de2abfa1556ac67fa3313 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Thu, 17 Sep 2026 19:58:10 -0400 Subject: Add edit mode, tweak UI Signed-off-by: Andrew Opalach --- Plugin.cs | 179 ++++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 138 insertions(+), 41 deletions(-) (limited to 'Plugin.cs') diff --git a/Plugin.cs b/Plugin.cs index 97a46ee..7da60f9 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -204,9 +204,13 @@ namespace WorldTuningTool } private const float defaultParamWidth = 0.21f; + private const float fadeAlphaFactor = 0.7f; + private const float disableAlphaFactor = 0.6f; private static bool ignoreMinMax = false; + private static bool editMode = false; + private const StageExt globalStage = StageExt.Global; private static StageExt currentStage => (StageExt)Area.CurrentStage; private static List? maybeGetStageOverrides(Config config) @@ -932,7 +936,7 @@ namespace WorldTuningTool public void DrawReferenceValue(string name, Vector4 v4, int i1) { - ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.7f); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * fadeAlphaFactor); switch (Type) { case ParameterType.BOOL: @@ -1388,19 +1392,22 @@ namespace WorldTuningTool } } - public void Draw(bool forSet, List? currentOverrides, List? stageOverrides, List? globalOverrides, bool superseded, float width) + public bool Draw(bool forSet, List? currentOverrides, List? stageOverrides, List? globalOverrides, bool superseded, float width) { Assert(!superseded == isSet); if (superseded) { - ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.5f); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * disableAlphaFactor); } - if (currentOverrides == null) + ImGuiComboFlags comboFlags = ImGuiComboFlags.HeightLarge; + bool disableCombo = currentOverrides == null || !editMode; + if (disableCombo) { ImGui.PushItemFlag(ImGuiItemFlags.Disabled, true); + comboFlags |= ImGuiComboFlags.NoArrowButton; } ImGui.PushItemWidth(width * 0.475f); - bool beginCombo = ImGui.BeginCombo("##Parameters", (Param != null) ? Param.Name : "", ImGuiComboFlags.HeightLarge); + bool beginCombo = ImGui.BeginCombo("##Parameters", (Param != null) ? Param.Name : "", comboFlags); if (superseded) { ImGui.PopStyleVar(); @@ -1481,16 +1488,17 @@ namespace WorldTuningTool ImGui.EndCombo(); } ImGui.PopItemWidth(); - if (currentOverrides == null) + if (disableCombo) { ImGui.PopItemFlag(); } + bool hasStatus = false; if (Param != null) { ImGui.SameLine(); if (superseded) { - ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.5f); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * disableAlphaFactor); } if (Param.DrawValue(ref valueV, ref valueInt, width, false)) { @@ -1523,11 +1531,12 @@ namespace WorldTuningTool { ImGui.SameLine(); Param.DrawReferenceValue("Saved", sValueV, sValueInt); + hasStatus = true; } if (Param.PendingUpdate()) { ImGui.SameLine(); - ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.7f); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * fadeAlphaFactor); ImGui.Text("(Pending)"); ImGui.PopStyleVar(); if (ImGui.BeginItemTooltip()) @@ -1535,6 +1544,7 @@ namespace WorldTuningTool ImGui.Text("The type this parameter belongs to has no current object."); ImGui.EndTooltip(); } + hasStatus = true; } else if (valueDiffers) { @@ -1546,8 +1556,10 @@ namespace WorldTuningTool byLine = Param.SetByLine(config, stageOverrides, globalOverrides, forSet, false); } Param.DrawReferenceValue((byLine == "") ? "Current" : byLine, v4, i1); + hasStatus = true; } } + return hasStatus; } } @@ -3505,6 +3517,46 @@ namespace WorldTuningTool HandleAreaChange(stage); } + private static bool drawListButtons(ref bool requestRemove, ref bool requestUp, ref bool requestDown) + { + requestRemove = ImGui.Button("X"); + ImGui.SameLine(); + requestUp = ImGui.Button("▲"); + ImGui.SameLine(); + requestDown = ImGui.Button("▼"); + ImGui.SameLine(); + return requestRemove || requestUp || requestDown; + } + + private static void prepareStatusBox(ref Vector2 cursorPos, ref float boxHeight, ref float boxWidth) + { + cursorPos = ImGui.GetCursorPos(); + boxHeight = ImGui.GetFrameHeight(); + boxWidth = boxHeight / 3.0f; + ImGui.SetCursorPos(cursorPos + new Vector2(boxWidth + 2.0f, 0.0f)); + } + + private static void drawStatusBox(bool superseded, bool hasStatus, Vector2 cursorPos, float boxHeight, float boxWidth) + { + Vector2 windowPos = ImGui.GetWindowPos(); + windowPos += cursorPos - new Vector2(ImGui.GetScrollX(), ImGui.GetScrollY()); + Vector4 boxColor; + if (superseded) + { + boxColor = ImGui.GetStyle().Colors[(int)ImGuiCol.Separator]; + } + else if (hasStatus) + { + boxColor = ImGui.GetStyle().Colors[(int)ImGuiCol.PlotHistogram]; + } + else + { + boxColor = ImGui.GetStyle().Colors[(int)ImGuiCol.Button]; + } + ImDrawListPtr drawList = ImGui.GetWindowDrawList(); + drawList.AddRectFilled(windowPos, windowPos + new Vector2(boxWidth, boxHeight), (uint)ColorVectorToInt(boxColor)); + } + public void OnImGuiRender() { float width = ImGui.GetWindowWidth(); @@ -3532,7 +3584,7 @@ namespace WorldTuningTool if (errorStage) { ImGui.PushItemFlag(ImGuiItemFlags.Disabled, true); - ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.5f); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * disableAlphaFactor); } if (ImGui.Button("Current")) { @@ -3551,15 +3603,30 @@ namespace WorldTuningTool bool selectedOrderChanged = false; List selectedOverrides = config.Overrides[selectedStage]; - if (ImGui.Button("Add override")) + if (!editMode) + { + if (ImGui.Button("Edit")) + { + editMode = true; + } + } + else { - Override ov = new Override(); - if (selectedStage == currentStage || selectedStage == globalStage) + if (ImGui.Button("< Edit")) { - ov.Set(); // Empty override never superseded. + editMode = false; + } + ImGui.SameLine(); + if (ImGui.Button("Add override")) + { + Override ov = new Override(); + if (selectedStage == currentStage || selectedStage == globalStage) + { + ov.Set(); // Empty override never superseded. + } + selectedOverrides.Add(ov); + selectedOrderChanged = true; } - selectedOverrides.Add(ov); - selectedOrderChanged = true; } List? stageOverrides = maybeGetStageOverrides(config); List? globalOverrides = null; @@ -3601,18 +3668,26 @@ namespace WorldTuningTool ImGui.PushID(i); Override ovS = selectedOverrides[i]; bool superseded = selectedOverrideSuperseded(config, globalOverrides, stageOverrides, ovS.Param); - bool requestRemove = ImGui.Button("X"); - ImGui.SameLine(); - bool requestUp = ImGui.Button("▲"); - ImGui.SameLine(); - bool requestDown = ImGui.Button("▼"); - ImGui.SameLine(); - selectedOrderChanged |= requestRemove || requestUp || requestDown; + bool requestRemove = false, requestUp = false, requestDown = false; + Vector2 cursorPos = default; + float boxHeight = 0.0f, boxWidth = 0.0f; + if (editMode) + { + selectedOrderChanged |= drawListButtons(ref requestRemove, ref requestUp, ref requestDown); + } + else + { + prepareStatusBox(ref cursorPos, ref boxHeight, ref boxWidth); + } if (requestDown && i < selectedOverrides.Count - 1) { (selectedOverrides[i], selectedOverrides[i + 1]) = (selectedOverrides[i + 1], selectedOverrides[i]); } - ovS.Draw(false, selectedOverrides, stageOverrides, globalOverrides, superseded, width); + bool hasStatus = ovS.Draw(false, selectedOverrides, stageOverrides, globalOverrides, superseded, width); + if (!editMode) + { + drawStatusBox(superseded, hasStatus, cursorPos, boxHeight, boxWidth); + } if (requestUp && i > 0) { (selectedOverrides[i], selectedOverrides[i - 1]) = (selectedOverrides[i - 1], selectedOverrides[i]); @@ -3632,7 +3707,6 @@ namespace WorldTuningTool selectedOverrides.RemoveAt(i); i--; } - ImGui.PopID(); } if (ImGui.Button("Save")) @@ -3661,7 +3735,7 @@ namespace WorldTuningTool if ((configState & SelectedNotSaved) == SelectedNotSaved) { ImGui.SameLine(); - ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.5f); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * fadeAlphaFactor); ImGui.Text("(Not Saved)"); ImGui.PopStyleVar(); } @@ -3691,7 +3765,7 @@ namespace WorldTuningTool if (renamingSet) { ImGui.PushItemFlag(ImGuiItemFlags.Disabled, true); - ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.5f); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * disableAlphaFactor); } if (ImGui.BeginCombo("##Set", selectedSet)) { @@ -3732,7 +3806,7 @@ namespace WorldTuningTool if (typedSetName == "") { ImGui.PushItemFlag(ImGuiItemFlags.Disabled, true); - ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.5f); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * disableAlphaFactor); } if (ImGui.Button("Save")) { @@ -3767,30 +3841,53 @@ namespace WorldTuningTool bool setOrderChanged = false; List setOverrides = config.Sets[selectedSet]; - if (ImGui.Button("Add override")) + if (!editMode) { - Override ov = new Override(); - ov.Set(); // Empty override never superseded. - setOverrides.Add(ov); - setOrderChanged = true; + if (ImGui.Button("Edit")) + { + editMode = true; + } + } + else + { + if (ImGui.Button("< Edit")) + { + editMode = false; + } + ImGui.SameLine(); + if (ImGui.Button("Add override")) + { + Override ov = new Override(); + ov.Set(); // Empty override never superseded. + setOverrides.Add(ov); + setOrderChanged = true; + } } for (int i = 0; i < setOverrides.Count; i++) { ImGui.PushID(i); Override ovP = setOverrides[i]; bool superseded = ovP.Param != null && overridesContainsParam(externalOverrides.Values, ovP.Param); - bool requestRemove = ImGui.Button("X"); - ImGui.SameLine(); - bool requestUp = ImGui.Button("▲"); - ImGui.SameLine(); - bool requestDown = ImGui.Button("▼"); - ImGui.SameLine(); - setOrderChanged |= requestRemove || requestUp || requestDown; + bool requestRemove = false, requestUp = false, requestDown = false; + Vector2 cursorPos = default; + float boxHeight = 0.0f, boxWidth = 0.0f; + if (editMode) + { + setOrderChanged |= drawListButtons(ref requestRemove, ref requestUp, ref requestDown); + } + else + { + prepareStatusBox(ref cursorPos, ref boxHeight, ref boxWidth); + } if (requestDown && i < setOverrides.Count - 1) { (setOverrides[i], setOverrides[i + 1]) = (setOverrides[i + 1], setOverrides[i]); } - ovP.Draw(true, setOverrides, stageOverrides, globalOverrides, superseded, width); + bool hasStatus = ovP.Draw(true, setOverrides, stageOverrides, globalOverrides, superseded, width); + if (!editMode) + { + drawStatusBox(superseded, hasStatus, cursorPos, boxHeight, boxWidth); + } if (requestUp && i > 0) { (setOverrides[i], setOverrides[i - 1]) = (setOverrides[i - 1], setOverrides[i]); @@ -3837,7 +3934,7 @@ namespace WorldTuningTool if ((configState & SetNotSaved) == SetNotSaved) { ImGui.SameLine(); - ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.5f); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * fadeAlphaFactor); ImGui.Text("(Not Saved)"); ImGui.PopStyleVar(); } -- cgit v1.2.3-101-g0448