1 | unit UFormMain;
|
---|
2 |
|
---|
3 | {$mode delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
|
---|
9 | UGame, LCLType, Menus, ActnList, ComCtrls, dateutils, XMLConf, DOM;
|
---|
10 |
|
---|
11 | const
|
---|
12 | ZoomFactor = 1.5;
|
---|
13 | MouseMinDiff = 0.1;
|
---|
14 |
|
---|
15 | type
|
---|
16 |
|
---|
17 | { TFormMain }
|
---|
18 |
|
---|
19 | TFormMain = class(TForm)
|
---|
20 | AToolBarVisible: TAction;
|
---|
21 | AToolBarBigIcons: TAction;
|
---|
22 | ActionList1: TActionList;
|
---|
23 | MainMenu1: TMainMenu;
|
---|
24 | MenuItem1: TMenuItem;
|
---|
25 | MenuItem10: TMenuItem;
|
---|
26 | MenuItem11: TMenuItem;
|
---|
27 | MenuItem12: TMenuItem;
|
---|
28 | MenuItem13: TMenuItem;
|
---|
29 | MenuItem14: TMenuItem;
|
---|
30 | MenuItem15: TMenuItem;
|
---|
31 | MenuItem16: TMenuItem;
|
---|
32 | MenuItem17: TMenuItem;
|
---|
33 | MenuItem18: TMenuItem;
|
---|
34 | MenuItem19: TMenuItem;
|
---|
35 | MenuItem2: TMenuItem;
|
---|
36 | MenuItem20: TMenuItem;
|
---|
37 | MenuItem21: TMenuItem;
|
---|
38 | MenuItem22: TMenuItem;
|
---|
39 | MenuItem23: TMenuItem;
|
---|
40 | MenuItem24: TMenuItem;
|
---|
41 | MenuItem25: TMenuItem;
|
---|
42 | MenuItem26: TMenuItem;
|
---|
43 | MenuItem27: TMenuItem;
|
---|
44 | MenuItem28: TMenuItem;
|
---|
45 | MenuItemLoadRecent: TMenuItem;
|
---|
46 | MenuItem3: TMenuItem;
|
---|
47 | MenuItem4: TMenuItem;
|
---|
48 | MenuItem5: TMenuItem;
|
---|
49 | MenuItem6: TMenuItem;
|
---|
50 | MenuItem7: TMenuItem;
|
---|
51 | MenuItem8: TMenuItem;
|
---|
52 | MenuItem9: TMenuItem;
|
---|
53 | PanelMain: TPanel;
|
---|
54 | PopupMenuToolbar: TPopupMenu;
|
---|
55 | Timer1: TTimer;
|
---|
56 | ToolBar1: TToolBar;
|
---|
57 | ToolButton1: TToolButton;
|
---|
58 | ToolButton11: TToolButton;
|
---|
59 | ToolButton12: TToolButton;
|
---|
60 | ToolButton13: TToolButton;
|
---|
61 | ToolButton2: TToolButton;
|
---|
62 | ToolButton3: TToolButton;
|
---|
63 | ToolButton4: TToolButton;
|
---|
64 | ToolButton5: TToolButton;
|
---|
65 | ToolButton9: TToolButton;
|
---|
66 | procedure AToolBarBigIconsExecute(Sender: TObject);
|
---|
67 | procedure AToolBarVisibleExecute(Sender: TObject);
|
---|
68 | procedure FormShow(Sender: TObject);
|
---|
69 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
70 | procedure FormCreate(Sender: TObject);
|
---|
71 | procedure FormDestroy(Sender: TObject);
|
---|
72 | procedure EraseBackground(DC: HDC); override;
|
---|
73 | procedure Timer1Timer(Sender: TObject);
|
---|
74 | private
|
---|
75 | public
|
---|
76 | procedure LoadConfig(Config: TXmlConfig; Path: string);
|
---|
77 | procedure SaveConfig(Config: TXmlConfig; Path: string);
|
---|
78 | procedure ReloadView;
|
---|
79 | end;
|
---|
80 |
|
---|
81 | var
|
---|
82 | FormMain: TFormMain;
|
---|
83 |
|
---|
84 | implementation
|
---|
85 |
|
---|
86 | uses
|
---|
87 | UCore, UFormClient;
|
---|
88 |
|
---|
89 | resourcestring
|
---|
90 | STurn = 'turn';
|
---|
91 |
|
---|
92 | {$R *.lfm}
|
---|
93 |
|
---|
94 | { TFormMain }
|
---|
95 |
|
---|
96 | procedure TFormMain.EraseBackground(DC: HDC);
|
---|
97 | begin
|
---|
98 | // Do nothing, all background space covered by controls
|
---|
99 | end;
|
---|
100 |
|
---|
101 | procedure TFormMain.Timer1Timer(Sender: TObject);
|
---|
102 | var
|
---|
103 | NewCaption: string;
|
---|
104 | begin
|
---|
105 | NewCaption := 'xTactics';
|
---|
106 | if Assigned(Core.Game.CurrentPlayer) then
|
---|
107 | NewCaption := Core.Game.CurrentPlayer.Name + ' - ' + STurn + ' ' + IntToStr(Core.Game.TurnCounter) + ' - ' + NewCaption;
|
---|
108 | Caption := NewCaption;
|
---|
109 | end;
|
---|
110 |
|
---|
111 | procedure TFormMain.LoadConfig(Config: TXmlConfig; Path: string);
|
---|
112 | begin
|
---|
113 | with Config do begin
|
---|
114 | AToolBarBigIcons.Checked := GetValue(DOMString(Path + '/LargeIcons'), False);
|
---|
115 | AToolBarVisible.Checked := GetValue(DOMString(Path + '/ToolBarVisible'), True);
|
---|
116 | end;
|
---|
117 | end;
|
---|
118 |
|
---|
119 | procedure TFormMain.SaveConfig(Config: TXmlConfig; Path: string);
|
---|
120 | begin
|
---|
121 | with Config do begin
|
---|
122 | SetValue(DOMString(Path + '/LargeIcons'), AToolBarBigIcons.Checked);
|
---|
123 | SetValue(DOMString(Path + '/ToolBarVisible'), AToolBarVisible.Checked);
|
---|
124 | end;
|
---|
125 | end;
|
---|
126 |
|
---|
127 | procedure TFormMain.ReloadView;
|
---|
128 | begin
|
---|
129 | if AToolBarBigIcons.Checked then begin
|
---|
130 | ToolBar1.Images := Core.ImageListLarge;
|
---|
131 | ToolBar1.ButtonWidth := Core.ImageListLarge.Width + 7;
|
---|
132 | ToolBar1.ButtonHeight := Core.ImageListLarge.Height + 6;
|
---|
133 | ToolBar1.Width := Core.ImageListLarge.Width + 10;
|
---|
134 | ToolBar1.Height := Core.ImageListLarge.Height + 10;
|
---|
135 | end else begin
|
---|
136 | ToolBar1.Images := Core.ImageListSmall;
|
---|
137 | ToolBar1.ButtonWidth := Core.ImageListSmall.Width + 7;
|
---|
138 | ToolBar1.ButtonHeight := Core.ImageListSmall.Height + 6;
|
---|
139 | ToolBar1.Width := Core.ImageListSmall.Width + 10;
|
---|
140 | ToolBar1.Height := Core.ImageListSmall.Height + 10;
|
---|
141 | end;
|
---|
142 | ToolBar1.Visible := AToolBarVisible.Checked;
|
---|
143 | end;
|
---|
144 |
|
---|
145 | procedure TFormMain.FormCreate(Sender: TObject);
|
---|
146 | begin
|
---|
147 | FormClient := TFormClient.Create(nil);
|
---|
148 | FormClient.ManualDock(PanelMain, nil, alClient);
|
---|
149 | FormClient.Align := alClient;
|
---|
150 | FormClient.Show;
|
---|
151 | end;
|
---|
152 |
|
---|
153 | procedure TFormMain.AToolBarBigIconsExecute(Sender: TObject);
|
---|
154 | begin
|
---|
155 | AToolBarBigIcons.Checked := not AToolBarBigIcons.Checked;
|
---|
156 | ReloadView;
|
---|
157 | end;
|
---|
158 |
|
---|
159 | procedure TFormMain.AToolBarVisibleExecute(Sender: TObject);
|
---|
160 | begin
|
---|
161 | AToolBarVisible.Checked := not AToolBarVisible.Checked;
|
---|
162 | ReloadView;
|
---|
163 | end;
|
---|
164 |
|
---|
165 | procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
166 | begin
|
---|
167 | Core.Game.Running := False;
|
---|
168 | Core.PersistentForm.Save(Self);
|
---|
169 | SaveConfig(Core.XMLConfig1, 'FormMain');
|
---|
170 | Core.XMLConfig1.Flush;
|
---|
171 | end;
|
---|
172 |
|
---|
173 | procedure TFormMain.FormDestroy(Sender: TObject);
|
---|
174 | begin
|
---|
175 | FormClient.Free;
|
---|
176 | end;
|
---|
177 |
|
---|
178 | procedure TFormMain.FormShow(Sender: TObject);
|
---|
179 | begin
|
---|
180 | Core.Init;
|
---|
181 | LoadConfig(Core.XMLConfig1, 'FormMain');
|
---|
182 | Core.PersistentForm.Load(Self, wsMaximized);
|
---|
183 | ReloadView;
|
---|
184 | end;
|
---|
185 |
|
---|
186 | end.
|
---|
187 |
|
---|