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