source: branches/AlphaChannel/LocalPlayer/Wonders.pas

Last change on this file was 245, checked in by chronos, 4 years ago
  • Added: Inactive scaling functions for future HighDPI support.
File size: 12.0 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: Integer);
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 Selection := -1;
79 OffscreenPaint;
80end;
81
82procedure TWondersDlg.ShowNewContent(NewMode: Integer);
83begin
84 inherited ShowNewContent(NewMode);
85end;
86
87procedure TWondersDlg.PaintBackgroundShape;
88const
89 Darken = 24;
90 // space=pi/120;
91 amax0 = 15734; // 1 shl 16*tan(pi/12-space);
92 amin1 = 19413; // 1 shl 16*tan(pi/12+space);
93 amax1 = 62191; // 1 shl 16*tan(pi/4-space);
94 amin2 = 69061; // 1 shl 16*tan(pi/4+space);
95 amax2 = 221246; // 1 shl 16*tan(5*pi/12-space);
96 amin3 = 272977; // 1 shl 16*tan(5*pi/12+space);
97var
98 X: Integer;
99 Y: Integer;
100 ax: Integer;
101 R: Integer;
102 I: 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 (wMaintexture - ClientWidth) div 2, (hMaintexture - 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.clBevelLight, MainTexture.clBevelShade);
206 Frame(Offscreen.Canvas, 2, 2, ClientWidth - 3, ClientHeight - 3,
207 MainTexture.clBevelLight, MainTexture.clBevelShade);
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 for I := 0 to 20 do
226 if Imp[I].Preq <> preNA then
227 begin
228 case MyRO.Wonder[I].CityID of
229 - 1: // not built yet
230 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, (wMaintexture - ClientWidth) div 2,
234 (hMaintexture - ClientHeight) div 2);
235 DarkIcon(I);
236 end;
237 -2: // destroyed
238 begin
239 Glow(I, $000000);
240 end;
241 else
242 begin
243 if MyRO.Wonder[I].EffectiveOwner >= 0 then
244 Glow(I, Tribe[MyRO.Wonder[I].EffectiveOwner].Color)
245 else
246 Glow(I, $000000);
247 end;
248 end;
249 end;
250
251 HaveWonder := False;
252 for I := 0 to 20 do
253 if Imp[I].Preq <> preNA then
254 begin
255 case MyRO.Wonder[I].CityID of
256 -1: // not built yet
257 begin
258 Fill(Offscreen.Canvas, Center.X - xSizeBig div 2 + RingPosition[I].X - 3,
259 Center.Y - ySizeBig div 2 + RingPosition[I].Y - 3, xSizeBig + 6,
260 ySizeBig + 6, (wMaintexture - ClientWidth) div 2,
261 (hMaintexture - ClientHeight) div 2);
262 DarkIcon(I);
263 end;
264 -2: // destroyed
265 begin
266 HaveWonder := True;
267 BitBltCanvas(Offscreen.Canvas,
268 Center.X - xSizeBig div 2 + RingPosition[I].X,
269 Center.Y - ySizeBig div 2 + RingPosition[I].Y, xSizeBig,
270 ySizeBig, BigImp.Canvas, 0, (SystemIconLines + 3) *
271 ySizeBig);
272 end;
273 else
274 begin
275 HaveWonder := True;
276 BitBltCanvas(Offscreen.Canvas,
277 Center.X - xSizeBig div 2 + RingPosition[I].X,
278 Center.Y - ySizeBig div 2 + RingPosition[I].Y, xSizeBig, ySizeBig,
279 BigImp.Canvas, (I mod 7) * xSizeBig,
280 (I div 7 + SystemIconLines) * ySizeBig);
281 end;
282 end;
283 end;
284
285 if not HaveWonder then
286 begin
287 S := Phrases.Lookup('NOWONDER');
288 RisedTextOut(Offscreen.Canvas,
289 Center.X - BiColorTextWidth(Offscreen.Canvas, S) div 2,
290 Center.Y - Offscreen.Canvas.TextHeight(S) div 2, S);
291 end;
292
293 MarkUsedOffscreen(ClientWidth, ClientHeight);
294end; { OffscreenPaint }
295
296procedure TWondersDlg.CloseBtnClick(Sender: TObject);
297begin
298 Close;
299end;
300
301procedure TWondersDlg.FormMouseMove(Sender: TObject; Shift: TShiftState;
302 X, Y: Integer);
303var
304 I, OldSelection: Integer;
305 S: string;
306begin
307 OldSelection := Selection;
308 Selection := -1;
309 for I := 0 to 20 do
310 if (Imp[I].Preq <> preNA) and
311 (X >= Center.X - xSizeBig div 2 + RingPosition[I].X) and
312 (X < Center.X + xSizeBig div 2 + RingPosition[I].X) and
313 (Y >= Center.Y - ySizeBig div 2 + RingPosition[I].Y) and
314 (Y < Center.Y + ySizeBig div 2 + RingPosition[I].Y) then
315 begin
316 Selection := I;
317 Break;
318 end;
319 if Selection <> OldSelection then
320 begin
321 Fill(Canvas, 9, ClientHeight - 3 - 46, ClientWidth - 18, 44,
322 (wMaintexture - ClientWidth) div 2, (hMaintexture - ClientHeight) div 2);
323 if Selection >= 0 then
324 begin
325 if MyRO.Wonder[Selection].CityID = -1 then
326 begin // not built yet
327 { S:=Phrases.Lookup('IMPROVEMENTS',Selection);
328 Canvas.Font.Color:=$000000;
329 Canvas.TextOut(
330 (ClientWidth-BiColorTextWidth(Canvas,S)) div 2+1,
331 ClientHeight-3-36+1, S);
332 Canvas.Font.Color:=MainTexture.clBevelLight;
333 Canvas.TextOut(
334 (ClientWidth-BiColorTextWidth(Canvas,S)) div 2,
335 ClientHeight-3-36, S); }
336 end
337 else
338 begin
339 S := Phrases.Lookup('IMPROVEMENTS', Selection);
340 if MyRO.Wonder[Selection].CityID <> -2 then
341 S := Format(Phrases.Lookup('WONDEROF'),
342 [S, CityName(MyRO.Wonder[Selection].CityID)]);
343 LoweredTextOut(Canvas, -1, MainTexture,
344 (ClientWidth - BiColorTextWidth(Canvas, S)) div 2,
345 ClientHeight - 3 - 36 - 10, S);
346 if MyRO.Wonder[Selection].CityID = -2 then
347 S := Phrases.Lookup('DESTROYED')
348 else if MyRO.Wonder[Selection].EffectiveOwner < 0 then
349 S := Phrases.Lookup('EXPIRED')
350 else
351 S := Tribe[MyRO.Wonder[Selection].EffectiveOwner].TPhrase('WONDEROWNER');
352 LoweredTextOut(Canvas, -1, MainTexture,
353 (ClientWidth - BiColorTextWidth(Canvas, S)) div 2,
354 ClientHeight - 3 - 36 + 10, S);
355 end;
356 end;
357 end;
358end;
359
360procedure TWondersDlg.FormMouseDown(Sender: TObject; Button: TMouseButton;
361 Shift: TShiftState; X, Y: Integer);
362begin
363 if Selection >= 0 then
364 HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkImp, Selection);
365end;
366
367end.
Note: See TracBrowser for help on using the repository browser.