예제 #1
0
        public void DrawUI()
        {
            ImGui.PushID(_uniqueUiId);

            ScriptState?scriptState = _ctrl.GetScriptState(_id);
            ScriptDef?  scriptDef   = _ctrl.GetScriptDef(_id);

            string statusText = scriptState != null?Tools.GetScriptStateText(scriptState) : string.Empty;

            ImGui.PushStyleColor(ImGuiCol.Text, new System.Numerics.Vector4(1f, 1f, 0f, 1f));
            bool opened = ImGui.TreeNodeEx(_id, ImGuiTreeNodeFlags.FramePadding);

            ImGui.PopStyleColor();
            if (ImGui.BeginPopupContextItem())
            {
                if (ImGui.MenuItem("Start"))
                {
                    _ctrl.Send(new Net.StartScriptMessage(_ctrl.Name, _id, null));
                }

                if (ImGui.MenuItem("Kill"))
                {
                    _ctrl.Send(new Net.KillScriptMessage(_ctrl.Name, _id));
                }

                ImGui.EndPopup();
            }

            ImGui.SameLine();
            ImGui.SetCursorPosX(ImGui.GetWindowWidth() * 3 / 4.5f);
            if (ImGuiTools.ImgBtn(_txStart))
            {
                _ctrl.Send(new Net.StartScriptMessage(_ctrl.Name, _id, null));
            }
            ImGui.SameLine();
            if (ImGuiTools.ImgBtn(_txKill))
            {
                _ctrl.Send(new Net.KillScriptMessage(_ctrl.Name, _id));
            }

            ImGui.SameLine();
            ImGui.SetCursorPosX(ImGui.GetWindowWidth() / 4.5f * 2f);
            ImGui.TextColored(GetScriptStateColor(statusText), statusText);

            //ImGui.SameLine();
            //ImGui.SetCursorPosX( ImGui.GetWindowWidth()/4f);
            //DrawOptions();

            if (opened)
            {
                //DrawUIBody();

                string jsonString = JsonSerializer.Serialize(scriptDef, new JsonSerializerOptions()
                {
                    WriteIndented = true, IncludeFields = true
                });
                ImGui.TextWrapped(jsonString.Replace("%", "%%"));                 // TextWrapped doesn't like %s etc, percent signs needs to be doubled

                ImGui.TreePop();
            }

            ImGui.PopID();
        }
예제 #2
0
        public void DrawUI()
        {
            ImGui.PushID(_uniqueUiId);

            AppDef?appDef = _appDef ?? _ctrl.GetAppDef(_id);

            AppState?appState = _ctrl.GetAppState(_id);

            PlanState?planState = null;

            if (appState != null && !string.IsNullOrEmpty(appState.PlanName))
            {
                planState = _ctrl.GetPlanState(appState.PlanName);
            }

            string statusText = appState != null?Tools.GetAppStateText(appState, planState, appDef) : string.Empty;

            string?planName = _appDef?.PlanName ?? appState?.PlanName;                  // prefer plan from appdef


            ImGui.PushStyleColor(ImGuiCol.Text, new System.Numerics.Vector4(1.0f, 0f, 1f, 1f));
            bool opened = ImGui.TreeNodeEx($"{_id}##{_id}", ImGuiTreeNodeFlags.FramePadding);

            ImGui.PopStyleColor();
            if (ImGui.BeginPopupContextItem())
            {
                if (ImGui.MenuItem("Start"))
                {
                    _ctrl.Send(new Net.StartAppMessage(_ctrl.Name, _id, planName));
                }

                if (ImGui.MenuItem("Kill"))
                {
                    _ctrl.Send(new Net.KillAppMessage(_ctrl.Name, _id));
                }

                if (ImGui.MenuItem("Restart"))
                {
                    _ctrl.Send(new Net.RestartAppMessage(_ctrl.Name, _id));
                }
                ImGui.EndPopup();
            }
            ImGui.SameLine();
            ImGui.SetCursorPosX(ImGui.GetWindowWidth() * 3 / 4f);
            //if( ImGui.Button("S") )	_ctrl.Send( new Net.StartAppMessage( _id, planName ) );
            if (ImGuiTools.ImgBtn(_txStart))
            {
                _ctrl.Send(new Net.StartAppMessage(_ctrl.Name, _id, planName));
            }
            ImGui.SameLine();
            if (ImGuiTools.ImgBtn(_txKill))
            {
                _ctrl.Send(new Net.KillAppMessage(_ctrl.Name, _id));
            }
            ImGui.SameLine();
            if (ImGuiTools.ImgBtn(_txRestart))
            {
                _ctrl.Send(new Net.RestartAppMessage(_ctrl.Name, _id));
            }

            // enabled checkbox just for apps from a plan
            if (_appDef is not null && _appDef.PlanName is not null)
            {
                ImGui.SameLine();
                bool enabled = !_appDef.Disabled;
                if (ImGui.Checkbox("##enabled", ref enabled))
                {
                    _ctrl.Send(new Net.SetAppEnabledMessage(_ctrl.Name, _appDef.PlanName, _id, enabled));
                }
            }

            ImGui.SameLine();
            ImGui.SetCursorPosX(ImGui.GetWindowWidth() / 4 * 2f);
            ImGui.TextColored(GetAppStateColor(statusText, appDef), statusText);

            //ImGui.SameLine();
            //ImGui.SetCursorPosX( ImGui.GetWindowWidth()/4f);
            //DrawOptions();

            if (opened)
            {
                //DrawUIBody();
                string jsonString = JsonSerializer.Serialize(appDef, new JsonSerializerOptions()
                {
                    WriteIndented = true, IncludeFields = true
                });
                ImGui.TextWrapped(jsonString.Replace("%", "%%"));                 // TextWrapped doesn't like %s etc, percent signs needs to be doubled

                ImGui.TreePop();
            }

            ImGui.PopID();
        }