source: tags/1.3.8/LocalPlayer/Enhance.pas

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