using System; using Vintagestory.API.Client; using Vintagestory.API.Common; using Vintagestory.API.Datastructures; namespace Automap { public class AutomapGUIDialog : GuiDialog { public const string _automapControlPanelKey = "automapControlPanelKey"; private const string _statusTextKey = @"txtStatus"; private ILogger Logger; private long dashTickHandle; public override string ToggleKeyCombinationCode { get { return _automapControlPanelKey; } } private uint totalShards, voidShards, changesThisTick; private RunState lastState; public AutomapGUIDialog(ICoreClientAPI capi,AutomapSystem ams) : base(capi) { Logger = capi.Logger; SetupDialog( ); capi.Event.RegisterEventBusListener(AutomapStatusMsg, 1.0D, AutomapSystem.AutomapStatusEventKey); } //Event for GUI status display private void SetupDialog( ) { ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog.WithAlignment(EnumDialogArea.CenterMiddle); ElementBounds textBounds = ElementBounds.Fixed(0, 40, 500, 300); ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding); bgBounds.BothSizing = ElementSizing.FitToChildren; bgBounds.WithChildren(textBounds); ElementBounds toggleBounds = textBounds.CopyOffsetedSibling(3, 64, 5, 2); toggleBounds.fixedHeight = 24; toggleBounds.fixedWidth = 64; ElementBounds txtStatusBounds = textBounds.CopyOffsetedSibling(0, 26, 2, 4); txtStatusBounds.fixedHeight = 16; txtStatusBounds.percentWidth = 1; this.SingleComposer = capi.Gui.CreateCompo("automapControlPanel", dialogBounds) .AddShadedDialogBG(bgBounds) .AddDialogTitleBar("Automap Controls", OnTitleBarCloseClicked) .AddStaticText("Configure Automap settings:", CairoFont.WhiteDetailText( ), textBounds) .AddToggleButton("Run", CairoFont.ButtonText( ), RunToggle, toggleBounds, "btnRun") .AddDynamicText("Idle.", CairoFont.WhiteSmallText( ).WithFontSize(12), EnumTextOrientation.Left, txtStatusBounds, _statusTextKey) .Compose( ); //Controls for ALL Block & Entity Designators (Enable/Disable) //_automapSystem.BlockID_Designators //_automapSystem.Entity_Designators //Renderer selection //Message verbosity? Speed? //A Button to add POI - notes manually (when AM running) } private void OnTitleBarCloseClicked( ) { TryClose( ); } /// /// Toggle Automap from/to RUN state /// /// The toggle. /// Run. internal void RunToggle(bool toggle) { Logger.VerboseDebug("Dialog Changed; [ Automap Enabled: {0} ]", toggle); var statusText = this.SingleComposer.GetDynamicText(_statusTextKey); statusText.SetNewText($"State: {(toggle? "Run": "Halt" )}, Total: ?, Nulls: 0 " ); if (toggle) { dashTickHandle = capi.Event.RegisterGameTickListener(UpdateDashDisplay, 6001); } else { capi.Event.UnregisterGameTickListener(dashTickHandle); } CommandData cmd = new CommandData(toggle ? RunState.Run : RunState.Stop); capi.Event.PushEvent(AutomapSystem.AutomapCommandEventKey, cmd); } private void AutomapStatusMsg(string eventName, ref EnumHandling handling, IAttribute data) { Logger.VerboseDebug("MsgBus RX: AutomapStatusMsg"); StatusData realData = data as StatusData; totalShards = realData.TotalUpdates; 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} "); } } }