OSDN Git Service

W.I.P. #6: GUI incomplete, injected JSON map state on HTML
[automap/automap.git] / Automap / Subsystems / AutomapGUIDialog.cs
1 using System;
2
3
4 using Vintagestory.API.Client;
5 using Vintagestory.API.Common;
6
7 namespace Automap
8 {
9         public class AutomapGUIDialog : GuiDialog
10         {
11                 public const string _automapControlPanelKey = "automapControlPanelKey";
12
13                 private ILogger Logger;
14                 private AutomapSystem _automapSystem;
15
16                 public override string ToggleKeyCombinationCode {
17                         get
18                         {
19                                 return _automapControlPanelKey;
20                         }
21                 }
22
23                 public AutomapGUIDialog(ICoreClientAPI capi,AutomapSystem ams) : base(capi)
24         {
25                 _automapSystem = ams;
26                 Logger = capi.Logger;
27                 SetupDialog( );
28                 }
29
30                 private void SetupDialog( )
31                 {
32                 ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog.WithAlignment(EnumDialogArea.CenterMiddle);
33                                         
34                 ElementBounds textBounds = ElementBounds.Fixed(0, 40, 500, 300);
35                 
36                 ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding);
37                 bgBounds.BothSizing = ElementSizing.FitToChildren;
38                 bgBounds.WithChildren(textBounds);
39
40                 ElementBounds toggleBounds = textBounds.CopyOffsetedSibling(3, 5, 5, 2);
41                 toggleBounds.fixedHeight = 18;
42                 toggleBounds.fixedWidth = 50;
43
44                 ElementBounds txtStatusBounds = textBounds.CopyOffsetedSibling(0, 20, 2, 4);
45                 txtStatusBounds.fixedHeight = 16;
46                 txtStatusBounds.percentWidth = 1;
47
48
49                 this.SingleComposer = capi.Gui.CreateCompo("automapControlPanel", dialogBounds)
50                         .AddShadedDialogBG(bgBounds)
51                         .AddDialogTitleBar("Automap Controls", OnTitleBarCloseClicked)
52                         .AddStaticText("Configure Automap settings:", CairoFont.WhiteDetailText( ), textBounds)
53                         .AddToggleButton("Run", CairoFont.ButtonText( ), RunToggle, toggleBounds, "btnRun")
54                         .AddStaticText("Idle.", CairoFont.WhiteSmallText( ).WithFontSize(12), txtStatusBounds, "txtStatus")
55                         .Compose( );
56                 }
57
58                 private void OnTitleBarCloseClicked( )
59                 {
60                 TryClose( );
61                 }
62
63                 /// <summary>
64                 /// Toggle Automap from/to RUN state
65                 /// </summary>
66                 /// <returns>The toggle.</returns>
67                 /// <param name="t1">T1.</param>
68                 internal void RunToggle(bool toggle)
69                 {
70                 _automapSystem.Enabled = toggle;
71                 Logger.VerboseDebug("Dialog Changed; [ Automap Enabled: {0} ]", toggle);
72                 var statusText = this.SingleComposer.GetStaticText("txtStatus");
73                 statusText.SetValue($"Running: {this._automapSystem.Enabled}, Total: {this._automapSystem.updatedChunksTotal}, Nulls: {this._automapSystem.nullChunkCount} " );
74
75                 }
76         }
77 }
78