4 using Vintagestory.API.Client;
5 using Vintagestory.API.Common;
6 using Vintagestory.API.Datastructures;
10 public class AutomapGUIDialog : GuiDialog
12 public const string _automapControlPanelKey = "automapControlPanelKey";
13 private const string _statusTextKey = @"txtStatus";
15 private ILogger Logger;
17 private long dashTickHandle;
19 public override string ToggleKeyCombinationCode {
22 return _automapControlPanelKey;
26 private uint totalShards, voidShards, changesThisTick;
27 private RunState lastState;
30 public AutomapGUIDialog(ICoreClientAPI capi,AutomapSystem ams) : base(capi)
35 capi.Event.RegisterEventBusListener(AutomapStatusMsg, 1.0D, AutomapSystem.AutomapStatusEventKey);
39 //Event for GUI status display
41 private void SetupDialog( )
43 ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog.WithAlignment(EnumDialogArea.CenterMiddle);
45 ElementBounds textBounds = ElementBounds.Fixed(0, 40, 500, 300);
47 ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding);
48 bgBounds.BothSizing = ElementSizing.FitToChildren;
49 bgBounds.WithChildren(textBounds);
51 ElementBounds toggleBounds = textBounds.CopyOffsetedSibling(3, 64, 5, 2);
52 toggleBounds.fixedHeight = 24;
53 toggleBounds.fixedWidth = 64;
55 ElementBounds txtStatusBounds = textBounds.CopyOffsetedSibling(0, 26, 2, 4);
56 txtStatusBounds.fixedHeight = 16;
57 txtStatusBounds.percentWidth = 1;
60 this.SingleComposer = capi.Gui.CreateCompo("automapControlPanel", dialogBounds)
61 .AddShadedDialogBG(bgBounds)
62 .AddDialogTitleBar("Automap Controls", OnTitleBarCloseClicked)
63 .AddStaticText("Configure Automap settings:", CairoFont.WhiteDetailText( ), textBounds)
64 .AddToggleButton("Run", CairoFont.ButtonText( ), RunToggle, toggleBounds, "btnRun")
65 .AddDynamicText("Idle.", CairoFont.WhiteSmallText( ).WithFontSize(12), EnumTextOrientation.Left, txtStatusBounds, _statusTextKey)
68 //Controls for ALL Block & Entity Designators (Enable/Disable)
69 //_automapSystem.BlockID_Designators
70 //_automapSystem.Entity_Designators
72 //Message verbosity? Speed?
74 //A Button to add POI - notes manually (when AM running)
78 private void OnTitleBarCloseClicked( )
84 /// Toggle Automap from/to RUN state
86 /// <returns>The toggle.</returns>
87 /// <param name="toggle">Run.</param>
88 internal void RunToggle(bool toggle)
90 Logger.VerboseDebug("Dialog Changed; [ Automap Enabled: {0} ]", toggle);
91 var statusText = this.SingleComposer.GetDynamicText(_statusTextKey);
92 statusText.SetNewText($"State: {(toggle? "Run": "Halt" )}, Total: {totalShards}, Nulls: {voidShards} " );
97 dashTickHandle = capi.Event.RegisterGameTickListener(UpdateDashDisplay, 6001);
98 cmd = new CommandData(toggle ? RunState.Run : RunState.Stop, new bool[ ] { true, true, true, true, true });
101 capi.Event.UnregisterGameTickListener(dashTickHandle);
102 cmd = new CommandData(toggle ? RunState.Run : RunState.Stop);
105 capi.Event.PushEvent(AutomapSystem.AutomapCommandEventKey, cmd);
109 private void AutomapStatusMsg(string eventName, ref EnumHandling handling, IAttribute data)
111 Logger.VerboseDebug("MsgBus RX: AutomapStatusMsg");
112 StatusData realData = data as StatusData;
113 totalShards = realData.TotalUpdates;
114 voidShards = realData.VoidChunks;
115 changesThisTick = realData.Delta;
116 lastState = realData.CurrentState;
119 private void UpdateDashDisplay(float delay )
121 var statusText = this.SingleComposer.GetDynamicText(_statusTextKey);
122 statusText.SetNewText($"State: {lastState}, Total: {totalShards}, Delta: {changesThisTick} Nulls: {voidShards} ");