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";
14 private const string _noteTextKey = @"edtNote";
16 private ILogger Logger;
18 private long dashTickHandle;
20 public override string ToggleKeyCombinationCode {
23 return _automapControlPanelKey;
27 private uint totalShards, voidShards, changesThisTick;
28 private RunState lastState;
31 public AutomapGUIDialog(ICoreClientAPI capi,AutomapSystem ams) : base(capi)
36 capi.Event.RegisterEventBusListener(AutomapStatusMsg, 1.0D, AutomapSystem.AutomapStatusEventKey);
40 //Event for GUI status display
42 private void SetupDialog( )
44 ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog.WithAlignment(EnumDialogArea.CenterMiddle);
46 ElementBounds textBounds = ElementBounds.Fixed(0, 40, 500, 300);
48 ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding);
49 bgBounds.BothSizing = ElementSizing.FitToChildren;
50 bgBounds.WithChildren(textBounds);
52 ElementBounds toggleBounds = textBounds.CopyOffsetedSibling(0, 72, 5, 2);
53 toggleBounds.fixedHeight = 24;
54 toggleBounds.fixedWidth = 64;
56 ElementBounds txtStatusBounds = textBounds.CopyOffsetedSibling(0, 26, 2, 4);
57 txtStatusBounds.fixedHeight = 16;
58 txtStatusBounds.percentWidth = 1;
60 ElementBounds btnNoteArea = textBounds.CopyOffsetedSibling(0, 42, 2, 5);
61 btnNoteArea.fixedHeight = 24;
62 btnNoteArea.fixedWidth = 20;
64 ElementBounds txtNoteArea = btnNoteArea.CopyOffsetedSibling(64, 0, 1, 6);
65 txtNoteArea.fixedHeight = 24;
66 txtNoteArea.fixedWidth = 256;
69 this.SingleComposer = capi.Gui.CreateCompo("automapControlPanel", dialogBounds)
70 .AddShadedDialogBG(bgBounds)
71 .AddDialogTitleBar("Automap Controls", OnTitleBarCloseClicked)
72 .AddStaticText("Configure Automap settings:", CairoFont.WhiteDetailText( ), textBounds)
73 .AddToggleButton("Run", CairoFont.ButtonText( ), RunToggle, toggleBounds, "btnRun")
74 .AddDynamicText("Idle.", CairoFont.WhiteSmallText( ).WithFontSize(12), EnumTextOrientation.Left, txtStatusBounds, _statusTextKey)
75 .AddTextInput(txtNoteArea,null,CairoFont.WhiteMediumText().WithFontSize(16),_noteTextKey)
76 .AddButton("Note:",CreateNote,btnNoteArea,CairoFont.ButtonText())
79 //Controls for ALL Block & Entity Designators (Enable/Disable)
80 //_automapSystem.BlockID_Designators
81 //_automapSystem.Entity_Designators
83 //Message verbosity? Speed?
85 //A Button to add POI - notes manually (when AM running)
89 private void OnTitleBarCloseClicked( )
95 /// Toggle Automap from/to RUN state
97 /// <returns>The toggle.</returns>
98 /// <param name="toggle">Run.</param>
99 internal void RunToggle(bool toggle)
101 Logger.VerboseDebug("Dialog Changed; [ Automap Enabled: {0} ]", toggle);
102 var statusText = this.SingleComposer.GetDynamicText(_statusTextKey);
103 statusText.SetNewText($"State: {(toggle? "Run": "Halt" )}, Total: {totalShards}, Nulls: {voidShards} " );
108 dashTickHandle = capi.Event.RegisterGameTickListener(UpdateDashDisplay, 6001);
109 cmd = new CommandData(toggle ? RunState.Run : RunState.Stop, new bool[ ] { true, true, true, true, true });
112 capi.Event.UnregisterGameTickListener(dashTickHandle);
113 cmd = new CommandData(toggle ? RunState.Run : RunState.Stop);
116 capi.Event.PushEvent(AutomapSystem.AutomapCommandEventKey, cmd);
119 private bool CreateNote( )
121 var noteCmd = new CommandData(RunState.Notation);
122 var txtNote = this.SingleComposer.GetTextInput(_noteTextKey);
123 if (!String.IsNullOrWhiteSpace(txtNote.GetText( ))) {
124 noteCmd.Notation = txtNote.GetText( );
125 txtNote.SetValue(string.Empty);
127 capi.Event.PushEvent(AutomapSystem.AutomapCommandEventKey, noteCmd);
132 private void AutomapStatusMsg(string eventName, ref EnumHandling handling, IAttribute data)
134 Logger.VerboseDebug("MsgBus RX: AutomapStatusMsg");
135 StatusData realData = data as StatusData;
136 totalShards = realData.TotalUpdates;
137 voidShards = realData.VoidChunks;
138 changesThisTick = realData.Delta;
139 lastState = realData.CurrentState;
142 private void UpdateDashDisplay(float delay )
144 var statusText = this.SingleComposer.GetDynamicText(_statusTextKey);
145 statusText.SetNewText($"State: {lastState}, Total: {totalShards}, Delta: {changesThisTick} Nulls: {voidShards} ");