OSDN Git Service

indentation
[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         {
18             get
19             {
20                 return _automapControlPanelKey;
21             }
22         }
23
24         public AutomapGUIDialog(ICoreClientAPI capi, AutomapSystem ams) : base(capi)
25         {
26             _automapSystem = ams;
27             Logger = capi.Logger;
28             SetupDialog();
29         }
30
31         private void SetupDialog()
32         {
33             ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog.WithAlignment(EnumDialogArea.CenterMiddle);
34
35             ElementBounds textBounds = ElementBounds.Fixed(0, 40, 500, 300);
36
37             ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding);
38             bgBounds.BothSizing = ElementSizing.FitToChildren;
39             bgBounds.WithChildren(textBounds);
40
41             ElementBounds toggleBounds = textBounds.CopyOffsetedSibling(3, 5, 5, 2);
42             toggleBounds.fixedHeight = 18;
43             toggleBounds.fixedWidth = 50;
44
45             ElementBounds txtStatusBounds = textBounds.CopyOffsetedSibling(0, 20, 2, 4);
46             txtStatusBounds.fixedHeight = 16;
47             txtStatusBounds.percentWidth = 1;
48
49
50             this.SingleComposer = capi.Gui.CreateCompo("automapControlPanel", dialogBounds)
51                 .AddShadedDialogBG(bgBounds)
52                 .AddDialogTitleBar("Automap Controls", OnTitleBarCloseClicked)
53                 .AddStaticText("Configure Automap settings:", CairoFont.WhiteDetailText(), textBounds)
54                 .AddToggleButton("Run", CairoFont.ButtonText(), RunToggle, toggleBounds, "btnRun")
55                 .AddStaticText("Idle.", CairoFont.WhiteSmallText().WithFontSize(12), txtStatusBounds, "txtStatus")
56                 .Compose();
57         }
58
59         private void OnTitleBarCloseClicked()
60         {
61             TryClose();
62         }
63
64         /// <summary>
65         /// Toggle Automap from/to RUN state
66         /// </summary>
67         /// <returns>The toggle.</returns>
68         /// <param name="t1">T1.</param>
69         internal void RunToggle(bool toggle)
70         {
71             _automapSystem.Enabled = toggle;
72             Logger.VerboseDebug("Dialog Changed; [ Automap Enabled: {0} ]", toggle);
73             var statusText = this.SingleComposer.GetStaticText("txtStatus");
74             statusText.SetValue($"Running: {this._automapSystem.Enabled}, Total: {this._automapSystem.updatedChunksTotal}, Nulls: {this._automapSystem.nullChunkCount} ");
75
76         }
77     }
78 }
79