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;
16 private AutomapSystem _automapSystem;
18 private long dashTickHandle;
20 public override string ToggleKeyCombinationCode {
23 return _automapControlPanelKey;
27 private uint totalShards, voidShards, changesThisTick;
29 public AutomapGUIDialog(ICoreClientAPI capi,AutomapSystem ams) : base(capi)
34 capi.Event.RegisterEventBusListener(AutomapStatusMsg, 1.0D, AutomapSystem.automapStatusEventKey);
38 //Event for GUI status display
40 private void SetupDialog( )
42 ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog.WithAlignment(EnumDialogArea.CenterMiddle);
44 ElementBounds textBounds = ElementBounds.Fixed(0, 40, 500, 300);
46 ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding);
47 bgBounds.BothSizing = ElementSizing.FitToChildren;
48 bgBounds.WithChildren(textBounds);
50 ElementBounds toggleBounds = textBounds.CopyOffsetedSibling(3, 26, 5, 2);
51 toggleBounds.fixedHeight = 24;
52 toggleBounds.fixedWidth = 64;
54 ElementBounds txtStatusBounds = textBounds.CopyOffsetedSibling(0, 64, 2, 4);
55 txtStatusBounds.fixedHeight = 16;
56 txtStatusBounds.percentWidth = 1;
59 this.SingleComposer = capi.Gui.CreateCompo("automapControlPanel", dialogBounds)
60 .AddShadedDialogBG(bgBounds)
61 .AddDialogTitleBar("Automap Controls", OnTitleBarCloseClicked)
62 .AddStaticText("Configure Automap settings:", CairoFont.WhiteDetailText( ), textBounds)
63 .AddToggleButton("Run", CairoFont.ButtonText( ), RunToggle, toggleBounds, "btnRun")
64 .AddDynamicText("Idle.", CairoFont.WhiteSmallText( ).WithFontSize(12), EnumTextOrientation.Left, txtStatusBounds, _statusTextKey)
67 //Controls for ALL Block & Entity Designators (Enable/Disable)
68 //_automapSystem.BlockID_Designators
69 //_automapSystem.Entity_Designators
71 //Message verbosity? Speed?
73 //A Button to add POI - notes manually (when AM running)
77 private void OnTitleBarCloseClicked( )
83 /// Toggle Automap from/to RUN state
85 /// <returns>The toggle.</returns>
86 /// <param name="t1">T1.</param>
87 internal void RunToggle(bool toggle)
89 _automapSystem.Enabled = toggle;
90 Logger.VerboseDebug("Dialog Changed; [ Automap Enabled: {0} ]", toggle);
91 var statusText = this.SingleComposer.GetDynamicText(_statusTextKey);
92 statusText.SetNewText($"Running: {this._automapSystem.Enabled}, Total: ?, Nulls: 0 " );
95 dashTickHandle = capi.Event.RegisterGameTickListener(UpdateDashDisplay, 6001);
98 capi.Event.UnregisterGameTickListener(dashTickHandle);
105 private void AutomapStatusMsg(string eventName, ref EnumHandling handling, IAttribute data)
107 Logger.VerboseDebug("MsgBus - AutomapStatusMsg");
108 StatusData realData = data as StatusData;
109 totalShards = realData.TotalUpdates;
110 voidShards = realData.VoidChunks;
111 changesThisTick = realData.Delta;
115 private void UpdateDashDisplay(float delay )
117 var statusText = this.SingleComposer.GetDynamicText(_statusTextKey);
118 statusText.SetNewText($"Running: {this._automapSystem.Enabled}, Total: {totalShards}, Delta: {changesThisTick} Nulls: {voidShards} ");