1 | {$INCLUDE Switches.inc}
|
---|
2 | unit Enhance;
|
---|
3 |
|
---|
4 | interface
|
---|
5 |
|
---|
6 | uses
|
---|
7 | ScreenTools, BaseWin, Protocol, ClientTools, Term, LCLIntf, LCLType,
|
---|
8 |
|
---|
9 | SysUtils, Classes, Graphics, Controls, Forms,
|
---|
10 | ButtonB, ButtonC, Menus;
|
---|
11 |
|
---|
12 | type
|
---|
13 |
|
---|
14 | { TEnhanceDlg }
|
---|
15 |
|
---|
16 | TEnhanceDlg = class(TFramedDlg)
|
---|
17 | MenuItem1: TMenuItem;
|
---|
18 | ToggleBtn: TButtonB;
|
---|
19 | CloseBtn: TButtonB;
|
---|
20 | job1: TButtonC;
|
---|
21 | job2: TButtonC;
|
---|
22 | job4: TButtonC;
|
---|
23 | job5: TButtonC;
|
---|
24 | job7: TButtonC;
|
---|
25 | job3: TButtonC;
|
---|
26 | job6: TButtonC;
|
---|
27 | job9: TButtonC;
|
---|
28 | Popup: TPopupMenu;
|
---|
29 | procedure FormCreate(Sender: TObject);
|
---|
30 | procedure FormPaint(Sender: TObject);
|
---|
31 | procedure FormShow(Sender: TObject);
|
---|
32 | procedure CloseBtnClick(Sender: TObject);
|
---|
33 | procedure ToggleBtnClick(Sender: TObject);
|
---|
34 | procedure TerrClick(Sender: TObject);
|
---|
35 | procedure JobClick(Sender: TObject);
|
---|
36 | procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
---|
37 | public
|
---|
38 | procedure ShowNewContent(NewMode: integer; TerrType: integer = -1);
|
---|
39 | protected
|
---|
40 | Page: integer;
|
---|
41 | procedure OffscreenPaint; override;
|
---|
42 | end;
|
---|
43 |
|
---|
44 | var
|
---|
45 | EnhanceDlg: TEnhanceDlg;
|
---|
46 |
|
---|
47 | implementation
|
---|
48 |
|
---|
49 | uses Help;
|
---|
50 |
|
---|
51 | {$R *.lfm}
|
---|
52 |
|
---|
53 | procedure TEnhanceDlg.FormCreate(Sender: TObject);
|
---|
54 | var
|
---|
55 | TerrType: integer;
|
---|
56 | m: TMenuItem;
|
---|
57 | begin
|
---|
58 | inherited;
|
---|
59 | CaptionRight := CloseBtn.Left;
|
---|
60 | CaptionLeft := ToggleBtn.Left + ToggleBtn.Width;
|
---|
61 | InitButtons();
|
---|
62 | HelpContext := 'MACRO';
|
---|
63 | Caption := Phrases.Lookup('TITLE_ENHANCE');
|
---|
64 | ToggleBtn.Hint := Phrases.Lookup('BTN_SELECT');
|
---|
65 |
|
---|
66 | for TerrType := fGrass to fMountains do
|
---|
67 | if TerrType <> fJungle then
|
---|
68 | begin
|
---|
69 | m := TMenuItem.Create(Popup);
|
---|
70 | m.RadioItem := true;
|
---|
71 | if TerrType = fGrass then
|
---|
72 | m.Caption := Format(Phrases.Lookup('TWOTERRAINS'),
|
---|
73 | [Phrases.Lookup('TERRAIN', fGrass), Phrases.Lookup('TERRAIN',
|
---|
74 | fGrass + 12)])
|
---|
75 | else if TerrType = fForest then
|
---|
76 | m.Caption := Format(Phrases.Lookup('TWOTERRAINS'),
|
---|
77 | [Phrases.Lookup('TERRAIN', fForest), Phrases.Lookup('TERRAIN',
|
---|
78 | fJungle)])
|
---|
79 | else
|
---|
80 | m.Caption := Phrases.Lookup('TERRAIN', TerrType);
|
---|
81 | m.Tag := TerrType;
|
---|
82 | m.OnClick := TerrClick;
|
---|
83 | Popup.Items.Add(m);
|
---|
84 | end;
|
---|
85 | end;
|
---|
86 |
|
---|
87 | procedure TEnhanceDlg.FormPaint(Sender: TObject);
|
---|
88 | var
|
---|
89 | i: integer;
|
---|
90 | begin
|
---|
91 | inherited;
|
---|
92 | BtnFrame(Canvas, Rect(job1.Left, job1.Top, job7.Left + job7.Width,
|
---|
93 | job1.Top + job1.Height), MainTexture);
|
---|
94 | BtnFrame(Canvas, Rect(job3.Left, job3.Top, job9.Left + job9.Width,
|
---|
95 | job3.Top + job3.Height), MainTexture);
|
---|
96 | for i := 0 to ControlCount - 1 do
|
---|
97 | if Controls[i] is TButtonC then
|
---|
98 | BitBltCanvas(Canvas, Controls[i].Left + 2, Controls[i].Top - 11, 8, 8,
|
---|
99 | HGrSystem.Data.Canvas, 121 + Controls[i].Tag mod 7 * 9,
|
---|
100 | 1 + Controls[i].Tag div 7 * 9);
|
---|
101 | end;
|
---|
102 |
|
---|
103 | procedure TEnhanceDlg.FormShow(Sender: TObject);
|
---|
104 | begin
|
---|
105 | OffscreenPaint;
|
---|
106 | end;
|
---|
107 |
|
---|
108 | procedure TEnhanceDlg.ShowNewContent(NewMode, TerrType: integer);
|
---|
109 | begin
|
---|
110 | if (TerrType < fGrass) or (TerrType > fMountains) then
|
---|
111 | Page := fGrass
|
---|
112 | else
|
---|
113 | Page := TerrType;
|
---|
114 | inherited ShowNewContent(NewMode);
|
---|
115 | end;
|
---|
116 |
|
---|
117 | procedure TEnhanceDlg.OffscreenPaint;
|
---|
118 | var
|
---|
119 | i, stage, TerrType, TileImp, x, EndStage, Cost, LastJob: integer;
|
---|
120 | s: string;
|
---|
121 | Done: Set of jNone .. jTrans;
|
---|
122 | TypeChanged: boolean;
|
---|
123 | begin
|
---|
124 | OffscreenUser := self;
|
---|
125 | offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
|
---|
126 | FillOffscreen(0, 0, InnerWidth, InnerHeight);
|
---|
127 |
|
---|
128 | EndStage := 0;
|
---|
129 | while (EndStage < 5) and (MyData.EnhancementJobs[Page, EndStage] <> jNone) do
|
---|
130 | inc(EndStage);
|
---|
131 | x := InnerWidth div 2 - xxt - (xxt + 3) * EndStage;
|
---|
132 |
|
---|
133 | TerrType := Page;
|
---|
134 | TileImp := 0;
|
---|
135 | Done := [];
|
---|
136 | Cost := 0;
|
---|
137 | for stage := 0 to EndStage do
|
---|
138 | begin
|
---|
139 | if stage > 0 then
|
---|
140 | begin
|
---|
141 | Sprite(offscreen, HGrSystem, x - 10, 66, 14, 14, 80, 1);
|
---|
142 | case MyData.EnhancementJobs[Page, stage - 1] of
|
---|
143 | jRoad:
|
---|
144 | begin
|
---|
145 | inc(Cost, Terrain[TerrType].MoveCost * RoadWork);
|
---|
146 | TileImp := TileImp or fRoad;
|
---|
147 | end;
|
---|
148 | jRR:
|
---|
149 | begin
|
---|
150 | inc(Cost, Terrain[TerrType].MoveCost * RRWork);
|
---|
151 | TileImp := TileImp or fRR;
|
---|
152 | end;
|
---|
153 | jIrr:
|
---|
154 | begin
|
---|
155 | inc(Cost, Terrain[TerrType].IrrClearWork);
|
---|
156 | TileImp := TileImp and not fTerImp or tiIrrigation;
|
---|
157 | end;
|
---|
158 | jFarm:
|
---|
159 | begin
|
---|
160 | inc(Cost, Terrain[TerrType].IrrClearWork * FarmWork);
|
---|
161 | TileImp := TileImp and not fTerImp or tiFarm;
|
---|
162 | end;
|
---|
163 | jMine:
|
---|
164 | begin
|
---|
165 | inc(Cost, Terrain[TerrType].MineAfforestWork);
|
---|
166 | TileImp := TileImp and not fTerImp or tiMine;
|
---|
167 | end;
|
---|
168 | jClear:
|
---|
169 | begin
|
---|
170 | inc(Cost, Terrain[TerrType].IrrClearWork);
|
---|
171 | TerrType := Terrain[TerrType].ClearTerrain;
|
---|
172 | end;
|
---|
173 | jAfforest:
|
---|
174 | begin
|
---|
175 | inc(Cost, Terrain[TerrType].MineAfforestWork);
|
---|
176 | TerrType := Terrain[TerrType].AfforestTerrain;
|
---|
177 | end;
|
---|
178 | jTrans:
|
---|
179 | begin
|
---|
180 | inc(Cost, Terrain[TerrType].TransWork);
|
---|
181 | TerrType := Terrain[TerrType].TransTerrain;
|
---|
182 | end;
|
---|
183 | end;
|
---|
184 | include(Done, MyData.EnhancementJobs[Page, stage - 1]);
|
---|
185 | end;
|
---|
186 |
|
---|
187 | if TerrType < fForest then
|
---|
188 | Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
|
---|
189 | 1 + TerrType * (xxt * 2 + 1), 1 + yyt)
|
---|
190 | else
|
---|
191 | begin
|
---|
192 | Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
|
---|
193 | 1 + 2 * (xxt * 2 + 1), 1 + yyt + 2 * (yyt * 3 + 1));
|
---|
194 | Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
|
---|
195 | 1 + 7 * (xxt * 2 + 1), 1 + yyt + 2 * (2 + TerrType - fForest) *
|
---|
196 | (yyt * 3 + 1));
|
---|
197 | end;
|
---|
198 | if TileImp and fTerImp = tiFarm then
|
---|
199 | Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
|
---|
200 | 1 + (xxt * 2 + 1), 1 + yyt + 12 * (yyt * 3 + 1))
|
---|
201 | else if TileImp and fTerImp = tiIrrigation then
|
---|
202 | Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2, 1,
|
---|
203 | 1 + yyt + 12 * (yyt * 3 + 1));
|
---|
204 | if TileImp and fRR <> 0 then
|
---|
205 | begin
|
---|
206 | Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
|
---|
207 | 1 + 6 * (xxt * 2 + 1), 1 + yyt + 10 * (yyt * 3 + 1));
|
---|
208 | Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
|
---|
209 | 1 + 2 * (xxt * 2 + 1), 1 + yyt + 10 * (yyt * 3 + 1));
|
---|
210 | end
|
---|
211 | else if TileImp and fRoad <> 0 then
|
---|
212 | begin
|
---|
213 | Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
|
---|
214 | 1 + 6 * (xxt * 2 + 1), 1 + yyt + 9 * (yyt * 3 + 1));
|
---|
215 | Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
|
---|
216 | 1 + 2 * (xxt * 2 + 1), 1 + yyt + 9 * (yyt * 3 + 1));
|
---|
217 | end;
|
---|
218 | if TileImp and fTerImp = tiMine then
|
---|
219 | Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
|
---|
220 | 1 + 2 * (xxt * 2 + 1), 1 + yyt + 12 * (yyt * 3 + 1));
|
---|
221 | inc(x, xxt * 2 + 6)
|
---|
222 | end;
|
---|
223 |
|
---|
224 | for i := 0 to Popup.Items.Count - 1 do
|
---|
225 | if Popup.Items[i].Tag = Page then
|
---|
226 | s := Popup.Items[i].Caption;
|
---|
227 | if Cost > 0 then
|
---|
228 | s := Format(Phrases.Lookup('ENHANCE'), [s, MovementToString(Cost)]);
|
---|
229 | LoweredTextOut(offscreen.Canvas, -1, MainTexture,
|
---|
230 | (InnerWidth - BiColorTextWidth(offscreen.Canvas, s)) div 2, 12, s);
|
---|
231 |
|
---|
232 | if EndStage > 0 then
|
---|
233 | LastJob := MyData.EnhancementJobs[Page, EndStage - 1]
|
---|
234 | else
|
---|
235 | LastJob := jNone;
|
---|
236 | if jRoad in Done then
|
---|
237 | job1.ButtonIndex := 3
|
---|
238 | else
|
---|
239 | job1.ButtonIndex := 2;
|
---|
240 | if jRR in Done then
|
---|
241 | job2.ButtonIndex := 3
|
---|
242 | else
|
---|
243 | job2.ButtonIndex := 2;
|
---|
244 | if jIrr in Done then
|
---|
245 | job4.ButtonIndex := 3
|
---|
246 | else
|
---|
247 | job4.ButtonIndex := 2;
|
---|
248 | if jFarm in Done then
|
---|
249 | job5.ButtonIndex := 3
|
---|
250 | else
|
---|
251 | job5.ButtonIndex := 2;
|
---|
252 | if jMine in Done then
|
---|
253 | job7.ButtonIndex := 3
|
---|
254 | else
|
---|
255 | job7.ButtonIndex := 2;
|
---|
256 | if LastJob = jClear then
|
---|
257 | job3.ButtonIndex := 3
|
---|
258 | else
|
---|
259 | job3.ButtonIndex := 2;
|
---|
260 | if LastJob = jAfforest then
|
---|
261 | job6.ButtonIndex := 3
|
---|
262 | else
|
---|
263 | job6.ButtonIndex := 2;
|
---|
264 | if LastJob = jTrans then
|
---|
265 | job9.ButtonIndex := 3
|
---|
266 | else
|
---|
267 | job9.ButtonIndex := 2;
|
---|
268 |
|
---|
269 | TypeChanged := LastJob in [jClear, jAfforest, jTrans];
|
---|
270 | job1.Visible := (jRoad in Done) or not TypeChanged;
|
---|
271 | job2.Visible := (jRR in Done) or not TypeChanged;
|
---|
272 | job4.Visible := (jIrr in Done) or not TypeChanged and
|
---|
273 | (Terrain[TerrType].IrrEff > 0);
|
---|
274 | job5.Visible := (jFarm in Done) or not TypeChanged and
|
---|
275 | (Terrain[TerrType].IrrEff > 0);
|
---|
276 | job7.Visible := (jMine in Done) or not TypeChanged and
|
---|
277 | (Terrain[TerrType].MineEff > 0);
|
---|
278 | job3.Visible := not TypeChanged and (Terrain[TerrType].ClearTerrain >= 0) and
|
---|
279 | ((TerrType <> fDesert) or (MyRO.Wonder[woGardens].EffectiveOwner = me)) or
|
---|
280 | (LastJob = jClear);
|
---|
281 | job6.Visible := not TypeChanged and (Terrain[TerrType].AfforestTerrain >= 0)
|
---|
282 | or (LastJob = jAfforest);
|
---|
283 | job9.Visible := not TypeChanged and (Terrain[TerrType].TransTerrain >= 0) or
|
---|
284 | (LastJob = jTrans);
|
---|
285 |
|
---|
286 | MarkUsedOffscreen(InnerWidth, InnerHeight);
|
---|
287 | end; { OffscreenPaint }
|
---|
288 |
|
---|
289 | procedure TEnhanceDlg.CloseBtnClick(Sender: TObject);
|
---|
290 | begin
|
---|
291 | Close
|
---|
292 | end;
|
---|
293 |
|
---|
294 | procedure TEnhanceDlg.ToggleBtnClick(Sender: TObject);
|
---|
295 | var
|
---|
296 | i: integer;
|
---|
297 | begin
|
---|
298 | for i := 0 to Popup.Items.Count - 1 do
|
---|
299 | Popup.Items[i].Checked := Popup.Items[i].Tag = Page;
|
---|
300 | Popup.Popup(Left + ToggleBtn.Left, Top + ToggleBtn.Top + ToggleBtn.Height);
|
---|
301 | end;
|
---|
302 |
|
---|
303 | procedure TEnhanceDlg.TerrClick(Sender: TObject);
|
---|
304 | begin
|
---|
305 | Page := TComponent(Sender).Tag;
|
---|
306 | SmartUpdateContent
|
---|
307 | end;
|
---|
308 |
|
---|
309 | procedure TEnhanceDlg.JobClick(Sender: TObject);
|
---|
310 | var
|
---|
311 | stage, NewJob: integer;
|
---|
312 | Done: Set of jNone .. jTrans;
|
---|
313 |
|
---|
314 | procedure RemoveJob(j: integer);
|
---|
315 | begin // remove job
|
---|
316 | stage := 0;
|
---|
317 | while (stage < 5) and (MyData.EnhancementJobs[Page, stage] <> jNone) do
|
---|
318 | begin
|
---|
319 | if (MyData.EnhancementJobs[Page, stage] = j) or (j = jRoad) and
|
---|
320 | (MyData.EnhancementJobs[Page, stage] = jRR) or (j = jIrr) and
|
---|
321 | (MyData.EnhancementJobs[Page, stage] = jFarm) then
|
---|
322 | begin
|
---|
323 | if stage < 4 then
|
---|
324 | move(MyData.EnhancementJobs[Page, stage + 1],
|
---|
325 | MyData.EnhancementJobs[Page, stage], 4 - stage);
|
---|
326 | MyData.EnhancementJobs[Page, 4] := jNone
|
---|
327 | end
|
---|
328 | else
|
---|
329 | inc(stage);
|
---|
330 | end;
|
---|
331 | end;
|
---|
332 |
|
---|
333 | begin
|
---|
334 | NewJob := TButtonC(Sender).Tag;
|
---|
335 | Done := [];
|
---|
336 | stage := 0;
|
---|
337 | while (stage < 5) and (MyData.EnhancementJobs[Page, stage] <> jNone) do
|
---|
338 | begin
|
---|
339 | include(Done, MyData.EnhancementJobs[Page, stage]);
|
---|
340 | inc(stage);
|
---|
341 | end;
|
---|
342 | if NewJob in Done then
|
---|
343 | RemoveJob(NewJob)
|
---|
344 | else
|
---|
345 | begin // add job
|
---|
346 | if NewJob in [jMine, jAfforest] then
|
---|
347 | RemoveJob(jIrr);
|
---|
348 | if NewJob in [jIrr, jFarm, jTrans] then
|
---|
349 | RemoveJob(jMine);
|
---|
350 | if (NewJob = jRR) and not(jRoad in Done) then
|
---|
351 | begin
|
---|
352 | MyData.EnhancementJobs[Page, stage] := jRoad;
|
---|
353 | inc(stage)
|
---|
354 | end;
|
---|
355 | if (NewJob = jFarm) and not(jIrr in Done) then
|
---|
356 | begin
|
---|
357 | MyData.EnhancementJobs[Page, stage] := jIrr;
|
---|
358 | inc(stage)
|
---|
359 | end;
|
---|
360 | MyData.EnhancementJobs[Page, stage] := NewJob
|
---|
361 | end;
|
---|
362 | SmartUpdateContent
|
---|
363 | end;
|
---|
364 |
|
---|
365 | procedure TEnhanceDlg.FormKeyDown(Sender: TObject; var Key: Word;
|
---|
366 | Shift: TShiftState);
|
---|
367 | begin
|
---|
368 | if Key = VK_F1 then
|
---|
369 | HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkText,
|
---|
370 | HelpDlg.TextIndex('MACRO'))
|
---|
371 | end;
|
---|
372 |
|
---|
373 | end.
|
---|