source: tags/1.3.1/LocalPlayer/Wonders.pas

Last change on this file was 442, checked in by chronos, 2 years ago
  • Modified: Code cleanup.
File size: 11.9 KB
Line 
1{$INCLUDE Switches.inc}
2unit Wonders;
3
4interface
5
6uses
7 ScreenTools, BaseWin, Protocol, LCLIntf, LCLType, SysUtils, Classes, Graphics,
8 Controls, Forms, ButtonB;
9
10type
11
12 { TWondersDlg }
13
14 TWondersDlg = class(TBufferedDrawDlg)
15 CloseBtn: TButtonB;
16 procedure FormCreate(Sender: TObject);
17 procedure CloseBtnClick(Sender: TObject);
18 procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
19 procedure FormShow(Sender: TObject);
20 procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
21 Shift: TShiftState; X, Y: Integer);
22 private
23 Selection: Integer;
24 Center: TPoint;
25 procedure DarkIcon(i: Integer);
26 procedure Glow(i, GlowColor: Integer);
27 procedure PaintBackgroundShape;
28 public
29 procedure OffscreenPaint; override;
30 procedure ShowNewContent(NewMode: TWindowMode);
31 end;
32
33var
34 WondersDlg: TWondersDlg;
35
36
37implementation
38
39uses
40 Term, ClientTools, Help, Tribes, UPixelPointer;
41
42{$R *.lfm}
43
44const
45 RingPosition: array [0 .. 20] of TPoint = (
46 (X: -80; Y: -32), // Pyramids
47 (X: 80; Y: -32), // Zeus
48 (X: 0; Y: -64), // Gardens
49 (X: 0; Y: 0), // Colossus
50 (X: 0; Y: 64), // Lighthouse
51 (X: -80; Y: 32), // GrLibrary
52 (X: -90; Y: 114), // Oracle
53 (X: 80; Y: 32), // Sun
54 (X: 90; Y: -114), // Leo
55 (X: -180; Y: 0), // Magellan
56 (X: 90; Y: 114), // Mich
57 (X: 0; Y: 0), // {11;}
58 (X: 180; Y: 0), // Newton
59 (X: -90; Y: -114), // Bach
60 (X: 0; Y: 0), // {14;}
61 (X: -160; Y: -64), // Liberty
62 (X: 0; Y: 128), // Eiffel
63 (X: 160; Y: -64), // Hoover
64 (X: -160; Y: 64), // Shinkansen
65 (X: 0; Y: -128), // Manhattan
66 (X: 160; Y: 64) // Mir
67 );
68
69procedure TWondersDlg.FormCreate(Sender: TObject);
70begin
71 Canvas.Font.Assign(UniFont[ftNormal]);
72 Canvas.Brush.Style := bsClear;
73 InitButtons;
74end;
75
76procedure TWondersDlg.FormShow(Sender: TObject);
77begin
78 Caption := Phrases.Lookup('TITLE_WONDERS');
79 Selection := -1;
80 OffscreenPaint;
81end;
82
83procedure TWondersDlg.ShowNewContent(NewMode: TWindowMode);
84begin
85 inherited ShowNewContent(NewMode);
86end;
87
88procedure TWondersDlg.PaintBackgroundShape;
89const
90 Darken = 24;
91 // space=pi/120;
92 amax0 = 15734; // 1 shl 16*tan(pi/12-space);
93 amin1 = 19413; // 1 shl 16*tan(pi/12+space);
94 amax1 = 62191; // 1 shl 16*tan(pi/4-space);
95 amin2 = 69061; // 1 shl 16*tan(pi/4+space);
96 amax2 = 221246; // 1 shl 16*tan(5*pi/12-space);
97 amin3 = 272977; // 1 shl 16*tan(5*pi/12+space);
98var
99 X: Integer;
100 Y: Integer;
101 ax: Integer;
102 R: Integer;
103 C: Integer;
104 Ch: Integer;
105 Line: array [0..3] of TPixelPointer;
106 Width: Integer;
107 Height: Integer;
108begin
109 Width := ScaleToNative(180);
110 Height := ScaleToNative(128);
111 Offscreen.BeginUpdate;
112 Line[0] := PixelPointer(Offscreen, ScaleToNative(Center.X), ScaleToNative(Center.Y));
113 Line[1] := PixelPointer(Offscreen, ScaleToNative(Center.X), ScaleToNative(Center.Y) - 1);
114 Line[2] := PixelPointer(Offscreen, ScaleToNative(Center.X) - 1, ScaleToNative(Center.Y));
115 Line[3] := PixelPointer(Offscreen, ScaleToNative(Center.X) - 1, ScaleToNative(Center.Y) - 1);
116 for Y := 0 to Height - 1 do begin
117 for X := 0 to Width - 1 do begin
118 r := X * X * ((Height div 4) * (Height div 4)) + Y * Y * ((Width div 4) * (Width div 4));
119 ax := ((1 shl 16 div (Height div 4)) * (Width div 4)) * Y;
120 if (r < ScaleToNative(8) * Height * Width * Width) and
121 ((r >= (Height div 4) * (Height div 2) * (Width div 2) * (Width div 2)) and (ax < amax2 * X) and
122 ((ax < amax0 * X) or (ax > amin2 * X)) or (ax > amin1 * X) and
123 ((ax < amax1 * X) or (ax > amin3 * X))) then begin
124 for ch := 0 to 2 do begin
125 c := Line[0].Pixel^.Planes[ch] - Darken;
126 if c < 0 then Line[0].Pixel^.Planes[ch] := 0
127 else Line[0].Pixel^.Planes[ch] := c;
128 c := Line[1].Pixel^.Planes[ch] - Darken;
129 if c < 0 then Line[1].Pixel^.Planes[ch] := 0
130 else Line[1].Pixel^.Planes[ch] := c;
131 c := Line[2].Pixel^.Planes[ch] - Darken;
132 if c < 0 then Line[2].Pixel^.Planes[ch] := 0
133 else Line[2].Pixel^.Planes[ch] := c;
134 c := Line[3].Pixel^.Planes[ch] - Darken;
135 if c < 0 then Line[3].Pixel^.Planes[ch] := 0
136 else Line[3].Pixel^.Planes[ch] := c;
137 end;
138 end;
139 Line[0].NextPixel;
140 Line[1].NextPixel;
141 Line[2].PreviousPixel;
142 Line[3].PreviousPixel;
143 end;
144 Line[0].NextLine;
145 Line[1].PreviousLine;
146 Line[2].NextLine;
147 Line[3].PreviousLine;
148 end;
149 Offscreen.EndUpdate;
150end;
151
152procedure TWondersDlg.DarkIcon(i: Integer);
153var
154 X, Y, ch, x0Dst, y0Dst, x0Src, y0Src, darken, c: Integer;
155 Src, Dst: TPixelPointer;
156begin
157 Offscreen.BeginUpdate;
158 x0Dst := ClientWidth div 2 - xSizeBig div 2 + RingPosition[i].X;
159 y0Dst := ClientHeight div 2 - ySizeBig div 2 + RingPosition[i].Y;
160 x0Src := (i mod 7) * xSizeBig;
161 y0Src := (i div 7 + SystemIconLines) * ySizeBig;
162 Src := PixelPointer(BigImp, ScaleToNative(x0Src), ScaleToNative(y0Src));
163 Dst := PixelPointer(Offscreen, ScaleToNative(x0Dst), ScaleToNative(y0Dst));
164 for Y := 0 to ScaleToNative(ySizeBig) - 1 do begin
165 for X := 0 to ScaleToNative(xSizeBig) - 1 do begin
166 Darken := ((255 - Src.Pixel^.B) * 3 + (255 - Src.Pixel^.G) *
167 15 + (255 - Src.Pixel^.R) * 9) div 128;
168 for ch := 0 to 2 do begin
169 c := Dst.Pixel^.Planes[ch] - Darken;
170 if c < 0 then Dst.Pixel^.Planes[ch] := 0
171 else Dst.Pixel^.Planes[ch] := c;
172 end;
173 Src.NextPixel;
174 Dst.NextPixel;
175 end;
176 Src.NextLine;
177 Dst.NextLine;
178 end;
179 Offscreen.EndUpdate;
180end;
181
182procedure TWondersDlg.Glow(i, GlowColor: Integer);
183begin
184 GlowFrame(Offscreen,
185 ClientWidth div 2 - xSizeBig div 2 + RingPosition[i].X,
186 ClientHeight div 2 - ySizeBig div 2 + RingPosition[i].Y,
187 xSizeBig, ySizeBig, GlowColor);
188end;
189
190procedure TWondersDlg.OffscreenPaint;
191var
192 I: Integer;
193 HaveWonder: Boolean;
194 S: string;
195begin
196 if (OffscreenUser <> nil) and (OffscreenUser <> Self) then
197 OffscreenUser.Update;
198 // complete working with old owner to prevent rebound
199 OffscreenUser := Self;
200
201 Fill(Offscreen.Canvas, 3, 3, ClientWidth - 6, ClientHeight - 6,
202 (Maintexture.Width - ClientWidth) div 2, (Maintexture.Height - ClientHeight) div 2);
203 Frame(Offscreen.Canvas, 0, 0, ClientWidth - 1, ClientHeight - 1, 0, 0);
204 Frame(Offscreen.Canvas, 1, 1, ClientWidth - 2, ClientHeight - 2,
205 MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
206 Frame(Offscreen.Canvas, 2, 2, ClientWidth - 3, ClientHeight - 3,
207 MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
208 Corner(Offscreen.Canvas, 1, 1, 0, MainTexture);
209 Corner(Offscreen.Canvas, ClientWidth - 9, 1, 1, MainTexture);
210 Corner(Offscreen.Canvas, 1, ClientHeight - 9, 2, MainTexture);
211 Corner(Offscreen.Canvas, ClientWidth - 9, ClientHeight - 9, 3, MainTexture);
212
213 BtnFrame(Offscreen.Canvas, CloseBtn.BoundsRect, MainTexture);
214
215 Offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
216 S := Phrases.Lookup('TITLE_WONDERS');
217 RisedTextOut(Offscreen.Canvas,
218 (ClientWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2 - 1, 7, S);
219 Offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
220
221 Center := Point(ClientWidth div 2, ClientHeight div 2);
222
223 PaintBackgroundShape;
224
225 // Draw all bitmaps first
226 HaveWonder := False;
227 for I := 0 to 20 do begin
228 if Imp[I].Preq <> preNA then begin
229 case MyRO.Wonder[I].CityID of
230 WonderNotBuiltYet: begin
231 Fill(Offscreen.Canvas, Center.X - xSizeBig div 2 + RingPosition[I].X - 3,
232 Center.Y - ySizeBig div 2 + RingPosition[I].Y - 3, xSizeBig + 6,
233 ySizeBig + 6, (Maintexture.Width - ClientWidth) div 2,
234 (Maintexture.Height - ClientHeight) div 2);
235 end;
236 WonderDestroyed: begin
237 HaveWonder := True;
238 BitBltCanvas(Offscreen.Canvas,
239 Center.X - xSizeBig div 2 + RingPosition[I].X,
240 Center.Y - ySizeBig div 2 + RingPosition[I].Y, xSizeBig,
241 ySizeBig, BigImp.Canvas, 0, (SystemIconLines + 3) *
242 ySizeBig);
243 end;
244 else begin
245 HaveWonder := True;
246 BitBltCanvas(Offscreen.Canvas,
247 Center.X - xSizeBig div 2 + RingPosition[I].X,
248 Center.Y - ySizeBig div 2 + RingPosition[I].Y, xSizeBig, ySizeBig,
249 BigImp.Canvas, (I mod 7) * xSizeBig,
250 (I div 7 + SystemIconLines) * ySizeBig);
251 end;
252 end;
253 end;
254 end;
255
256 // Do direct pixel postprocessing separately to avoid bitmap copying in memory
257 Offscreen.Canvas.FillRect(0, 0, 0, 0);
258 Offscreen.BeginUpdate;
259 for I := 0 to 20 do begin
260 if Imp[I].Preq <> preNA then begin
261 case MyRO.Wonder[I].CityID of
262 WonderNotBuiltYet: DarkIcon(I);
263 WonderDestroyed: Glow(I, $000000);
264 else begin
265 if MyRO.Wonder[I].EffectiveOwner >= 0 then
266 Glow(I, Tribe[MyRO.Wonder[I].EffectiveOwner].Color)
267 else Glow(I, $000000);
268 end;
269 end;
270 end;
271 end;
272 Offscreen.EndUpdate;
273
274 if not HaveWonder then
275 begin
276 S := Phrases.Lookup('NOWONDER');
277 RisedTextOut(Offscreen.Canvas,
278 Center.X - BiColorTextWidth(Offscreen.Canvas, S) div 2,
279 Center.Y - Offscreen.Canvas.TextHeight(S) div 2, S);
280 end;
281
282 MarkUsedOffscreen(ClientWidth, ClientHeight);
283end;
284
285procedure TWondersDlg.CloseBtnClick(Sender: TObject);
286begin
287 Close;
288end;
289
290procedure TWondersDlg.FormMouseMove(Sender: TObject; Shift: TShiftState;
291 X, Y: Integer);
292var
293 I, OldSelection: Integer;
294 S: string;
295begin
296 OldSelection := Selection;
297 Selection := -1;
298 for I := 0 to 20 do
299 if (Imp[I].Preq <> preNA) and
300 (X >= Center.X - xSizeBig div 2 + RingPosition[I].X) and
301 (X < Center.X + xSizeBig div 2 + RingPosition[I].X) and
302 (Y >= Center.Y - ySizeBig div 2 + RingPosition[I].Y) and
303 (Y < Center.Y + ySizeBig div 2 + RingPosition[I].Y) then
304 begin
305 Selection := I;
306 Break;
307 end;
308 if Selection <> OldSelection then
309 begin
310 Fill(Canvas, 9, ClientHeight - 3 - 46, ClientWidth - 18, 44,
311 (Maintexture.Width - ClientWidth) div 2, (Maintexture.Height - ClientHeight) div 2);
312 if Selection >= 0 then
313 begin
314 if MyRO.Wonder[Selection].CityID = WonderNotBuiltYet then
315 begin // not built yet
316 { S:=Phrases.Lookup('IMPROVEMENTS',Selection);
317 Canvas.Font.Color:=$000000;
318 Canvas.TextOut(
319 (ClientWidth-BiColorTextWidth(Canvas,S)) div 2+1,
320 ClientHeight-3-36+1, S);
321 Canvas.Font.Color:=MainTexture.ColorBevelLight;
322 Canvas.TextOut(
323 (ClientWidth-BiColorTextWidth(Canvas,S)) div 2,
324 ClientHeight-3-36, S); }
325 end
326 else
327 begin
328 S := Phrases.Lookup('IMPROVEMENTS', Selection);
329 if MyRO.Wonder[Selection].CityID <> WonderDestroyed then
330 S := Format(Phrases.Lookup('WONDEROF'),
331 [S, CityName(MyRO.Wonder[Selection].CityID)]);
332 LoweredTextOut(Canvas, -1, MainTexture,
333 (ClientWidth - BiColorTextWidth(Canvas, S)) div 2,
334 ClientHeight - 3 - 36 - 10, S);
335 if MyRO.Wonder[Selection].CityID = WonderDestroyed then
336 S := Phrases.Lookup('DESTROYED')
337 else if MyRO.Wonder[Selection].EffectiveOwner < 0 then
338 S := Phrases.Lookup('EXPIRED')
339 else
340 S := Tribe[MyRO.Wonder[Selection].EffectiveOwner].TPhrase('WONDEROWNER');
341 LoweredTextOut(Canvas, -1, MainTexture,
342 (ClientWidth - BiColorTextWidth(Canvas, S)) div 2,
343 ClientHeight - 3 - 36 + 10, S);
344 end;
345 end;
346 end;
347end;
348
349procedure TWondersDlg.FormMouseDown(Sender: TObject; Button: TMouseButton;
350 Shift: TShiftState; X, Y: Integer);
351begin
352 if Selection >= 0 then
353 HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkImp, Selection);
354end;
355
356end.
Note: See TracBrowser for help on using the repository browser.