From 720b2754dfa89c4068504c7e2520764ddfb3a886 Mon Sep 17 00:00:00 2001 From: ohlidalp Date: Sat, 25 Jan 2025 16:17:44 +0100 Subject: [PATCH] :scroll: example_actor_engineDiag.as: added focused editing mode. // Attributes can be edited realtime (on every keystroke) or using the [Focus] button. // Focused editing means all other inputs are disabled and [Apply/Reset] buttons must be used. ^ This hint was added to the help box. --- resources/scripts/example_actor_engineDiag.as | 71 ++++++++++++++++--- 1 file changed, 61 insertions(+), 10 deletions(-) diff --git a/resources/scripts/example_actor_engineDiag.as b/resources/scripts/example_actor_engineDiag.as index 1a09aa89d0..6258f1ceb6 100644 --- a/resources/scripts/example_actor_engineDiag.as +++ b/resources/scripts/example_actor_engineDiag.as @@ -102,27 +102,78 @@ void plotFloatBuf(array@ buf, float rangeMin, float rangeMax) float val = buf[buf.length()-1]; ImGui::Text(formatFloat(val, "", 0, 3)); } - + +// Attributes can be edited realtime (on every keystroke) or using the [Focus] button. +// Focused editing means all other inputs are disabled and [Apply/Reset] buttons must be used. +ActorSimAttr gFocusedEditingAttr = ACTORSIMATTR_NONE; +float gFocusedEditingValue = 0.f; +float cfgAttrInputboxWidth = 125.f; +color cfgAttrUnfocusedBgColor = color(0.14, 0.14, 0.14, 1.0); void drawAttrInputRow(BeamClass@ actor, ActorSimAttr attr, string label) -{ +{ + ImGui::PushID(label); ImGui::TextDisabled(label); - ImGui::NextColumn(); - float val = actor.getSimAttribute(attr); - if (ImGui::InputFloat("##"+label, val)) - { - actor.setSimAttribute(attr, val); + ImGui::NextColumn(); + if (gFocusedEditingAttr == ACTORSIMATTR_NONE) + { + // Focused editing inactive - draw [Focus] button + float val = actor.getSimAttribute(attr); + ImGui::SetNextItemWidth(cfgAttrInputboxWidth); + if (ImGui::InputFloat("", val)) + { + actor.setSimAttribute(attr, val); + } + ImGui::SameLine(); + if (ImGui::SmallButton("Focus")) + { + gFocusedEditingAttr = attr; + gFocusedEditingValue = val; + } + } + else if (gFocusedEditingAttr == attr) + { + // This attr is focused - draw [Apply/Reset] buttons + ImGui::SetNextItemWidth(cfgAttrInputboxWidth); + ImGui::InputFloat("##"+label, gFocusedEditingValue); + ImGui::SameLine(); + if (ImGui::Button("Apply")) + { + actor.setSimAttribute(attr, gFocusedEditingValue); + gFocusedEditingAttr = ACTORSIMATTR_NONE; + gFocusedEditingValue = 0.f; + } + ImGui::SameLine(); + if (ImGui::SmallButton("Reset")) + { + gFocusedEditingAttr = ACTORSIMATTR_NONE; + gFocusedEditingValue = 0.f; + } + } + else + { + // Some other attr is focused - just draw a label padded to size of inputbox. + string valStr = "" + actor.getSimAttribute(attr); + ImGui::PushStyleColor(ImGuiCol_FrameBg, cfgAttrUnfocusedBgColor); + ImGui::BeginChildFrame(uint(attr), vector2(cfgAttrInputboxWidth, ImGui::GetTextLineHeight()) + 3 * 2); + ImGui::Text(valStr); + ImGui::EndChildFrame(); // Must be called either way - inconsistent with other End*** funcs. + ImGui::PopStyleColor(); // FrameBg } - ImGui::NextColumn(); + ImGui::NextColumn(); + ImGui::PopID(); // label } void drawAttributesCommonHelp() { - if (ImGui::CollapsingHeader("How to read attributes:")) + if (ImGui::CollapsingHeader("How to read and edit attributes:")) { ImGui::TextDisabled("Each value is displayed twice (for debugging) from different sources:"); ImGui::TextDisabled("1. the 'get***' value is what EngineClass object reports via `get***()` functions."); ImGui::TextDisabled("2. the UPPERCASE value is what ActorClass object reports via `getSimAttribute()` function."); - ImGui::TextDisabled("There are exceptions, a few values have multiple EngineClass getters or lack Attribute handle"); + ImGui::TextDisabled("There are exceptions, a few values have multiple EngineClass getters or lack Attribute handle"); + ImGui::Dummy(vector2(10,10)); + ImGui::TextDisabled("Attributes can be edited realtime (on every keystroke) or using the [Focus] button."); + ImGui::TextDisabled("Focused editing means all other inputs are disabled and [Apply/Reset] buttons must be used."); ImGui::Separator(); ImGui::Separator(); }