OSDN Git Service

Adjusted notes GUI, POI/EOI JSON metadata added
[automap/automap.git] / Automap / Subsystems / AutomapGUIDialog.cs
1 using System;
2
3
4 using Vintagestory.API.Client;
5 using Vintagestory.API.Common;
6 using Vintagestory.API.Datastructures;
7
8 namespace Automap
9 {
10         public class AutomapGUIDialog : GuiDialog
11         {
12                 public const string _automapControlPanelKey = "automapControlPanelKey";
13                 private const string _statusTextKey = @"txtStatus";
14                 private const string _noteTextKey = @"edtNote";
15
16                 private ILogger Logger;
17
18                 private long dashTickHandle;
19
20                 public override string ToggleKeyCombinationCode {
21                         get
22                         {
23                                 return _automapControlPanelKey;
24                         }
25                 }
26
27                 private uint totalShards, voidShards, changesThisTick;
28                 private RunState lastState;
29
30
31                 public AutomapGUIDialog(ICoreClientAPI capi,AutomapSystem ams) : base(capi)
32         {
33
34                 Logger = capi.Logger;
35                 SetupDialog( );
36                 capi.Event.RegisterEventBusListener(AutomapStatusMsg, 1.0D, AutomapSystem.AutomapStatusEventKey);
37                 
38                 }
39
40                 //Event for GUI status display
41
42                 private void SetupDialog( )
43                 {
44                 ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog.WithAlignment(EnumDialogArea.CenterMiddle);
45                                         
46                 ElementBounds textBounds = ElementBounds.Fixed(0, 40, 500, 300);
47                 
48                 ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding);
49                 bgBounds.BothSizing = ElementSizing.FitToChildren;
50                 bgBounds.WithChildren(textBounds);
51
52                 ElementBounds toggleBounds = textBounds.CopyOffsetedSibling(0, 72, 5, 2);
53                 toggleBounds.fixedHeight = 24;
54                 toggleBounds.fixedWidth = 64;
55
56                 ElementBounds txtStatusBounds = textBounds.CopyOffsetedSibling(0, 26, 2, 4);
57                 txtStatusBounds.fixedHeight = 16;
58                 txtStatusBounds.percentWidth = 1;
59
60                 ElementBounds btnNoteArea = textBounds.CopyOffsetedSibling(0, 42, 2, 5);
61                 btnNoteArea.fixedHeight = 24;
62                 btnNoteArea.fixedWidth = 20;
63
64                 ElementBounds txtNoteArea = btnNoteArea.CopyOffsetedSibling(64, 0, 1, 6);
65                 txtNoteArea.fixedHeight = 24;
66                 txtNoteArea.fixedWidth = 256;
67
68
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())
77                         .Compose( );
78
79                         //Controls for ALL Block & Entity Designators (Enable/Disable)
80                         //_automapSystem.BlockID_Designators
81                         //_automapSystem.Entity_Designators
82                         //Renderer selection
83                         //Message verbosity? Speed?
84
85                         //A Button to add POI - notes manually (when AM running)
86
87                 }
88
89                 private void OnTitleBarCloseClicked( )
90                 {
91                 TryClose( );
92                 }
93
94                 /// <summary>
95                 /// Toggle Automap from/to RUN state
96                 /// </summary>
97                 /// <returns>The toggle.</returns>
98                 /// <param name="toggle">Run.</param>
99                 internal void RunToggle(bool toggle)
100                 {
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} " );
104
105                 CommandData cmd;
106
107                 if (toggle) {
108                 dashTickHandle = capi.Event.RegisterGameTickListener(UpdateDashDisplay, 6001);
109                 cmd = new CommandData(toggle ? RunState.Run : RunState.Stop, new bool[ ] { true, true, true, true, true });
110                 }
111                 else {
112                 capi.Event.UnregisterGameTickListener(dashTickHandle);
113                 cmd = new CommandData(toggle ? RunState.Run : RunState.Stop);
114                 }
115                                         
116                 capi.Event.PushEvent(AutomapSystem.AutomapCommandEventKey, cmd);
117                 }
118
119                 private bool CreateNote( )
120                 {
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);
126
127                 capi.Event.PushEvent(AutomapSystem.AutomapCommandEventKey, noteCmd);
128                 }
129                 return false;//???
130                 }
131
132                 private void AutomapStatusMsg(string eventName, ref EnumHandling handling, IAttribute data)
133                 {
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;
140                 }
141
142                 private void UpdateDashDisplay(float delay )
143                 {
144                 var statusText = this.SingleComposer.GetDynamicText(_statusTextKey);
145                 statusText.SetNewText($"State: {lastState}, Total: {totalShards}, Delta: {changesThisTick} Nulls: {voidShards} ");
146
147
148                 }
149
150
151         }
152 }
153