OSDN Git Service

Pre-PR5: GUI panel update changes...
authormelchior <melchior@users.osdn.me>
Thu, 5 Mar 2020 01:54:35 +0000 (20:54 -0500)
committermelchior <melchior@users.osdn.me>
Thu, 5 Mar 2020 01:54:35 +0000 (20:54 -0500)
Automap/Subsystems/AutomapGUIDialog.cs

index 9fedd85..c1a1f82 100644 (file)
@@ -16,7 +16,7 @@ namespace Automap
                private const string _btnRunKey = @"btnRun";
 
                private ILogger Logger;
-
+               private PersistedConfiguration configuration;
                private long dashTickHandle;
 
                public override string ToggleKeyCombinationCode
@@ -36,11 +36,11 @@ namespace Automap
                        Logger = capi.Logger;
                        SetupDialog();
                        capi.Event.RegisterEventBusListener(AutomapStatusMsg, 1.0D, AutomapSystem.AutomapStatusEventKey);
-
+                       configuration = cfg;
                }
 
                public AutomapGUIDialog(ICoreClientAPI capi) : base(capi)
-               {
+               {                       
                }
 
                //Event for GUI status display
@@ -103,6 +103,20 @@ namespace Automap
                        TryClose();
                }
 
+               public override void OnGuiOpened( )
+               {
+               base.OnGuiOpened( );
+               UpdateDashDisplay(0f);
+               if (dashTickHandle == 0L)  dashTickHandle = capi.Event.RegisterGameTickListener(UpdateDashDisplay, 1000);
+               }
+
+               public override void OnGuiClosed( )
+               {
+               base.OnGuiClosed( );
+
+               if (dashTickHandle != 0L) capi.Event.UnregisterGameTickListener(dashTickHandle);
+               }
+
                /// <summary>
                /// Toggle Automap from/to RUN state
                /// </summary>
@@ -112,20 +126,9 @@ namespace Automap
                {
                        Logger.VerboseDebug("Dialog Changed; [ Automap Enabled: {0} ]", toggle);
                        var statusText = this.SingleComposer.GetDynamicText(_statusTextKey);
-                       statusText.SetNewText($"State: {(toggle ? "Run" : "Halt")}, Total: {totalShards}, Nulls: {voidShards} ");
-
-                       CommandData cmd;
-
-                       if (toggle)
-                       {
-                               dashTickHandle = capi.Event.RegisterGameTickListener(UpdateDashDisplay, 6001);
-                               cmd = new CommandData(toggle ? CommandType.Run : CommandType.Stop);
-                       }
-                       else
-                       {
-                               capi.Event.UnregisterGameTickListener(dashTickHandle);
-                               cmd = new CommandData(toggle ? CommandType.Run : CommandType.Stop);
-                       }
+                       UpdateDashDisplay(0f);
+                                                
+                       CommandData cmd = new CommandData(toggle ? CommandType.Run : CommandType.Stop);
 
                        capi.Event.PushEvent(AutomapSystem.AutomapCommandEventKey, cmd);
                }
@@ -146,7 +149,7 @@ namespace Automap
 
                private void AutostartChange(bool startValue)
                {
-                       
+               configuration.Autostart = startValue;           
                }
 
                private void AutomapStatusMsg(string eventName, ref EnumHandling handling, IAttribute data)
@@ -157,20 +160,20 @@ namespace Automap
                        voidShards = realData.VoidChunks;
                        changesThisTick = realData.Delta;
                        lastState = realData.CurrentState;
-
                }
 
                private void UpdateDashDisplay(float delay)
                {
                        var statusText = this.SingleComposer.GetDynamicText(_statusTextKey);
-                       statusText.SetNewText($"State: {lastState}, Total: {totalShards}, Delta: {changesThisTick} Nulls: {voidShards} ");
 
                        var btnRun = this.SingleComposer.GetToggleButton(_btnRunKey);
 
                        if (lastState == CommandType.Run) {
+                       statusText.SetNewText($"State: {lastState}, Total: {totalShards}, Delta: +{changesThisTick} Nulls: {voidShards} ");
                        btnRun.SetValue(true);
                        }
                        else if (lastState == CommandType.Stop) {
+                       statusText.SetNewText($"State: {lastState}, Total: {totalShards}, Nulls: {voidShards} ");                       
                        btnRun.SetValue(false);
                        }
                }