| 1 | {$INCLUDE Switches.inc}
|
|---|
| 2 | unit Wonders;
|
|---|
| 3 |
|
|---|
| 4 | interface
|
|---|
| 5 |
|
|---|
| 6 | uses
|
|---|
| 7 | ScreenTools, BaseWin, Protocol, LCLIntf, LCLType, SysUtils, Classes, Graphics,
|
|---|
| 8 | Controls, Forms, ButtonB;
|
|---|
| 9 |
|
|---|
| 10 | type
|
|---|
| 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 |
|
|---|
| 33 | var
|
|---|
| 34 | WondersDlg: TWondersDlg;
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 | implementation
|
|---|
| 38 |
|
|---|
| 39 | uses
|
|---|
| 40 | Term, ClientTools, Help, Tribes, UPixelPointer;
|
|---|
| 41 |
|
|---|
| 42 | {$R *.lfm}
|
|---|
| 43 |
|
|---|
| 44 | const
|
|---|
| 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 |
|
|---|
| 69 | procedure TWondersDlg.FormCreate(Sender: TObject);
|
|---|
| 70 | begin
|
|---|
| 71 | Canvas.Font.Assign(UniFont[ftNormal]);
|
|---|
| 72 | Canvas.Brush.Style := bsClear;
|
|---|
| 73 | InitButtons;
|
|---|
| 74 | end;
|
|---|
| 75 |
|
|---|
| 76 | procedure TWondersDlg.FormShow(Sender: TObject);
|
|---|
| 77 | begin
|
|---|
| 78 | Selection := -1;
|
|---|
| 79 | OffscreenPaint;
|
|---|
| 80 | end;
|
|---|
| 81 |
|
|---|
| 82 | procedure TWondersDlg.ShowNewContent(NewMode: Integer);
|
|---|
| 83 | begin
|
|---|
| 84 | inherited ShowNewContent(NewMode);
|
|---|
| 85 | end;
|
|---|
| 86 |
|
|---|
| 87 | procedure TWondersDlg.PaintBackgroundShape;
|
|---|
| 88 | const
|
|---|
| 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);
|
|---|
| 97 | var
|
|---|
| 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 | begin
|
|---|
| 107 | Offscreen.BeginUpdate;
|
|---|
| 108 | Line[0] := PixelPointer(Offscreen, Center.X, Center.Y);
|
|---|
| 109 | Line[1] := PixelPointer(Offscreen, Center.X, Center.Y - 1);
|
|---|
| 110 | Line[2] := PixelPointer(Offscreen, Center.X - 1, Center.Y);
|
|---|
| 111 | Line[3] := PixelPointer(Offscreen, Center.X - 1, Center.Y - 1);
|
|---|
| 112 | for Y := 0 to 127 do begin
|
|---|
| 113 | for X := 0 to 179 do begin
|
|---|
| 114 | r := X * X * (32 * 32) + Y * Y * (45 * 45);
|
|---|
| 115 | ax := ((1 shl 16 div 32) * 45) * Y;
|
|---|
| 116 | if (r < 8 * 128 * 180 * 180) and
|
|---|
| 117 | ((r >= 32 * 64 * 90 * 90) and (ax < amax2 * X) and
|
|---|
| 118 | ((ax < amax0 * X) or (ax > amin2 * X)) or (ax > amin1 * X) and
|
|---|
| 119 | ((ax < amax1 * X) or (ax > amin3 * X))) then begin
|
|---|
| 120 | for ch := 0 to 2 do begin
|
|---|
| 121 | c := Line[0].Pixel^.Planes[ch] - Darken;
|
|---|
| 122 | if c < 0 then Line[0].Pixel^.Planes[ch] := 0
|
|---|
| 123 | else Line[0].Pixel^.Planes[ch] := c;
|
|---|
| 124 | c := Line[1].Pixel^.Planes[ch] - Darken;
|
|---|
| 125 | if c < 0 then Line[1].Pixel^.Planes[ch] := 0
|
|---|
| 126 | else Line[1].Pixel^.Planes[ch] := c;
|
|---|
| 127 | c := Line[2].Pixel^.Planes[ch] - Darken;
|
|---|
| 128 | if c < 0 then Line[2].Pixel^.Planes[ch] := 0
|
|---|
| 129 | else Line[2].Pixel^.Planes[ch] := c;
|
|---|
| 130 | c := Line[3].Pixel^.Planes[ch] - Darken;
|
|---|
| 131 | if c < 0 then Line[3].Pixel^.Planes[ch] := 0
|
|---|
| 132 | else Line[3].Pixel^.Planes[ch] := c;
|
|---|
| 133 | end;
|
|---|
| 134 | end;
|
|---|
| 135 | Line[0].NextPixel;
|
|---|
| 136 | Line[1].NextPixel;
|
|---|
| 137 | Line[2].PreviousPixel;
|
|---|
| 138 | Line[3].PreviousPixel;
|
|---|
| 139 | end;
|
|---|
| 140 | Line[0].NextLine;
|
|---|
| 141 | Line[1].PreviousLine;
|
|---|
| 142 | Line[2].NextLine;
|
|---|
| 143 | Line[3].PreviousLine;
|
|---|
| 144 | end;
|
|---|
| 145 | Offscreen.EndUpdate;
|
|---|
| 146 | end;
|
|---|
| 147 |
|
|---|
| 148 | procedure TWondersDlg.DarkIcon(i: Integer);
|
|---|
| 149 | var
|
|---|
| 150 | X, Y, ch, x0Dst, y0Dst, x0Src, y0Src, darken, c: Integer;
|
|---|
| 151 | Src, Dst: TPixelPointer;
|
|---|
| 152 | begin
|
|---|
| 153 | Offscreen.BeginUpdate;
|
|---|
| 154 | x0Dst := ClientWidth div 2 - xSizeBig div 2 + RingPosition[i].X;
|
|---|
| 155 | y0Dst := ClientHeight div 2 - ySizeBig div 2 + RingPosition[i].Y;
|
|---|
| 156 | x0Src := (i mod 7) * xSizeBig;
|
|---|
| 157 | y0Src := (i div 7 + SystemIconLines) * ySizeBig;
|
|---|
| 158 | Src := PixelPointer(BigImp, x0Src, y0Src);
|
|---|
| 159 | Dst := PixelPointer(Offscreen, x0Dst, y0Dst);
|
|---|
| 160 | for Y := 0 to ySizeBig - 1 do begin
|
|---|
| 161 | for X := 0 to xSizeBig - 1 do begin
|
|---|
| 162 | Darken := ((255 - Src.Pixel^.B) * 3 + (255 - Src.Pixel^.G) *
|
|---|
| 163 | 15 + (255 - Src.Pixel^.R) * 9) div 128;
|
|---|
| 164 | for ch := 0 to 2 do begin
|
|---|
| 165 | c := Dst.Pixel^.Planes[ch] - Darken;
|
|---|
| 166 | if c < 0 then Dst.Pixel^.Planes[ch] := 0
|
|---|
| 167 | else Dst.Pixel^.Planes[ch] := c;
|
|---|
| 168 | end;
|
|---|
| 169 | Src.NextPixel;
|
|---|
| 170 | Dst.NextPixel;
|
|---|
| 171 | end;
|
|---|
| 172 | Src.NextLine;
|
|---|
| 173 | Dst.NextLine;
|
|---|
| 174 | end;
|
|---|
| 175 | Offscreen.EndUpdate;
|
|---|
| 176 | end;
|
|---|
| 177 |
|
|---|
| 178 | procedure TWondersDlg.Glow(i, GlowColor: Integer);
|
|---|
| 179 | begin
|
|---|
| 180 | GlowFrame(Offscreen,
|
|---|
| 181 | ClientWidth div 2 - xSizeBig div 2 + RingPosition[i].X,
|
|---|
| 182 | ClientHeight div 2 - ySizeBig div 2 + RingPosition[i].Y,
|
|---|
| 183 | xSizeBig, ySizeBig, GlowColor);
|
|---|
| 184 | end;
|
|---|
| 185 |
|
|---|
| 186 | procedure TWondersDlg.OffscreenPaint;
|
|---|
| 187 | var
|
|---|
| 188 | I: Integer;
|
|---|
| 189 | HaveWonder: Boolean;
|
|---|
| 190 | S: string;
|
|---|
| 191 | begin
|
|---|
| 192 | if (OffscreenUser <> nil) and (OffscreenUser <> Self) then
|
|---|
| 193 | OffscreenUser.Update;
|
|---|
| 194 | // complete working with old owner to prevent rebound
|
|---|
| 195 | OffscreenUser := Self;
|
|---|
| 196 |
|
|---|
| 197 | Fill(Offscreen.Canvas, 3, 3, ClientWidth - 6, ClientHeight - 6,
|
|---|
| 198 | (wMaintexture - ClientWidth) div 2, (hMaintexture - ClientHeight) div 2);
|
|---|
| 199 | Frame(Offscreen.Canvas, 0, 0, ClientWidth - 1, ClientHeight - 1, 0, 0);
|
|---|
| 200 | Frame(Offscreen.Canvas, 1, 1, ClientWidth - 2, ClientHeight - 2,
|
|---|
| 201 | MainTexture.clBevelLight, MainTexture.clBevelShade);
|
|---|
| 202 | Frame(Offscreen.Canvas, 2, 2, ClientWidth - 3, ClientHeight - 3,
|
|---|
| 203 | MainTexture.clBevelLight, MainTexture.clBevelShade);
|
|---|
| 204 | Corner(Offscreen.Canvas, 1, 1, 0, MainTexture);
|
|---|
| 205 | Corner(Offscreen.Canvas, ClientWidth - 9, 1, 1, MainTexture);
|
|---|
| 206 | Corner(Offscreen.Canvas, 1, ClientHeight - 9, 2, MainTexture);
|
|---|
| 207 | Corner(Offscreen.Canvas, ClientWidth - 9, ClientHeight - 9, 3, MainTexture);
|
|---|
| 208 |
|
|---|
| 209 | BtnFrame(Offscreen.Canvas, CloseBtn.BoundsRect, MainTexture);
|
|---|
| 210 |
|
|---|
| 211 | Offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
|
|---|
| 212 | S := Phrases.Lookup('TITLE_WONDERS');
|
|---|
| 213 | RisedTextOut(Offscreen.Canvas,
|
|---|
| 214 | (ClientWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2 - 1, 7, S);
|
|---|
| 215 | Offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
|
|---|
| 216 |
|
|---|
| 217 | Center := Point(ClientWidth div 2, ClientHeight div 2);
|
|---|
| 218 |
|
|---|
| 219 | PaintBackgroundShape;
|
|---|
| 220 |
|
|---|
| 221 | for I := 0 to 20 do
|
|---|
| 222 | if Imp[I].Preq <> preNA then
|
|---|
| 223 | begin
|
|---|
| 224 | case MyRO.Wonder[I].CityID of
|
|---|
| 225 | - 1: // not built yet
|
|---|
| 226 | begin
|
|---|
| 227 | Fill(Offscreen.Canvas, Center.X - xSizeBig div 2 + RingPosition[I].X - 3,
|
|---|
| 228 | Center.Y - ySizeBig div 2 + RingPosition[I].Y - 3, xSizeBig + 6,
|
|---|
| 229 | ySizeBig + 6, (wMaintexture - ClientWidth) div 2,
|
|---|
| 230 | (hMaintexture - ClientHeight) div 2);
|
|---|
| 231 | //DarkIcon(I);
|
|---|
| 232 | end;
|
|---|
| 233 | -2: // destroyed
|
|---|
| 234 | begin
|
|---|
| 235 | Glow(I, $000000);
|
|---|
| 236 | end;
|
|---|
| 237 | else
|
|---|
| 238 | begin
|
|---|
| 239 | if MyRO.Wonder[I].EffectiveOwner >= 0 then
|
|---|
| 240 | Glow(I, Tribe[MyRO.Wonder[I].EffectiveOwner].Color)
|
|---|
| 241 | else
|
|---|
| 242 | Glow(I, $000000);
|
|---|
| 243 | end;
|
|---|
| 244 | end;
|
|---|
| 245 | end;
|
|---|
| 246 |
|
|---|
| 247 | HaveWonder := False;
|
|---|
| 248 | for I := 0 to 20 do
|
|---|
| 249 | if Imp[I].Preq <> preNA then
|
|---|
| 250 | begin
|
|---|
| 251 | case MyRO.Wonder[I].CityID of
|
|---|
| 252 | -1: // not built yet
|
|---|
| 253 | begin
|
|---|
| 254 | Fill(Offscreen.Canvas, Center.X - xSizeBig div 2 + RingPosition[I].X - 3,
|
|---|
| 255 | Center.Y - ySizeBig div 2 + RingPosition[I].Y - 3, xSizeBig + 6,
|
|---|
| 256 | ySizeBig + 6, (wMaintexture - ClientWidth) div 2,
|
|---|
| 257 | (hMaintexture - ClientHeight) div 2);
|
|---|
| 258 | DarkIcon(I);
|
|---|
| 259 | end;
|
|---|
| 260 | -2: // destroyed
|
|---|
| 261 | begin
|
|---|
| 262 | HaveWonder := True;
|
|---|
| 263 | BitBltCanvas(Offscreen.Canvas,
|
|---|
| 264 | Center.X - xSizeBig div 2 + RingPosition[I].X,
|
|---|
| 265 | Center.Y - ySizeBig div 2 + RingPosition[I].Y, xSizeBig,
|
|---|
| 266 | ySizeBig, BigImp.Canvas, 0, (SystemIconLines + 3) *
|
|---|
| 267 | ySizeBig);
|
|---|
| 268 | end;
|
|---|
| 269 | else
|
|---|
| 270 | begin
|
|---|
| 271 | HaveWonder := True;
|
|---|
| 272 | BitBltCanvas(Offscreen.Canvas,
|
|---|
| 273 | Center.X - xSizeBig div 2 + RingPosition[I].X,
|
|---|
| 274 | Center.Y - ySizeBig div 2 + RingPosition[I].Y, xSizeBig, ySizeBig,
|
|---|
| 275 | BigImp.Canvas, (I mod 7) * xSizeBig,
|
|---|
| 276 | (I div 7 + SystemIconLines) * ySizeBig);
|
|---|
| 277 | end;
|
|---|
| 278 | end;
|
|---|
| 279 | end;
|
|---|
| 280 |
|
|---|
| 281 | if not HaveWonder then
|
|---|
| 282 | begin
|
|---|
| 283 | S := Phrases.Lookup('NOWONDER');
|
|---|
| 284 | RisedTextOut(Offscreen.Canvas,
|
|---|
| 285 | Center.X - BiColorTextWidth(Offscreen.Canvas, S) div 2,
|
|---|
| 286 | Center.Y - Offscreen.Canvas.TextHeight(S) div 2, S);
|
|---|
| 287 | end;
|
|---|
| 288 |
|
|---|
| 289 | MarkUsedOffscreen(ClientWidth, ClientHeight);
|
|---|
| 290 | end; { OffscreenPaint }
|
|---|
| 291 |
|
|---|
| 292 | procedure TWondersDlg.CloseBtnClick(Sender: TObject);
|
|---|
| 293 | begin
|
|---|
| 294 | Close;
|
|---|
| 295 | end;
|
|---|
| 296 |
|
|---|
| 297 | procedure TWondersDlg.FormMouseMove(Sender: TObject; Shift: TShiftState;
|
|---|
| 298 | X, Y: Integer);
|
|---|
| 299 | var
|
|---|
| 300 | I, OldSelection: Integer;
|
|---|
| 301 | S: string;
|
|---|
| 302 | begin
|
|---|
| 303 | OldSelection := Selection;
|
|---|
| 304 | Selection := -1;
|
|---|
| 305 | for I := 0 to 20 do
|
|---|
| 306 | if (Imp[I].Preq <> preNA) and
|
|---|
| 307 | (X >= Center.X - xSizeBig div 2 + RingPosition[I].X) and
|
|---|
| 308 | (X < Center.X + xSizeBig div 2 + RingPosition[I].X) and
|
|---|
| 309 | (Y >= Center.Y - ySizeBig div 2 + RingPosition[I].Y) and
|
|---|
| 310 | (Y < Center.Y + ySizeBig div 2 + RingPosition[I].Y) then
|
|---|
| 311 | begin
|
|---|
| 312 | Selection := I;
|
|---|
| 313 | Break;
|
|---|
| 314 | end;
|
|---|
| 315 | if Selection <> OldSelection then
|
|---|
| 316 | begin
|
|---|
| 317 | Fill(Canvas, 9, ClientHeight - 3 - 46, ClientWidth - 18, 44,
|
|---|
| 318 | (wMaintexture - ClientWidth) div 2, (hMaintexture - ClientHeight) div 2);
|
|---|
| 319 | if Selection >= 0 then
|
|---|
| 320 | begin
|
|---|
| 321 | if MyRO.Wonder[Selection].CityID = -1 then
|
|---|
| 322 | begin // not built yet
|
|---|
| 323 | { S:=Phrases.Lookup('IMPROVEMENTS',Selection);
|
|---|
| 324 | Canvas.Font.Color:=$000000;
|
|---|
| 325 | Canvas.TextOut(
|
|---|
| 326 | (ClientWidth-BiColorTextWidth(Canvas,S)) div 2+1,
|
|---|
| 327 | ClientHeight-3-36+1, S);
|
|---|
| 328 | Canvas.Font.Color:=MainTexture.clBevelLight;
|
|---|
| 329 | Canvas.TextOut(
|
|---|
| 330 | (ClientWidth-BiColorTextWidth(Canvas,S)) div 2,
|
|---|
| 331 | ClientHeight-3-36, S); }
|
|---|
| 332 | end
|
|---|
| 333 | else
|
|---|
| 334 | begin
|
|---|
| 335 | S := Phrases.Lookup('IMPROVEMENTS', Selection);
|
|---|
| 336 | if MyRO.Wonder[Selection].CityID <> -2 then
|
|---|
| 337 | S := Format(Phrases.Lookup('WONDEROF'),
|
|---|
| 338 | [S, CityName(MyRO.Wonder[Selection].CityID)]);
|
|---|
| 339 | LoweredTextOut(Canvas, -1, MainTexture,
|
|---|
| 340 | (ClientWidth - BiColorTextWidth(Canvas, S)) div 2,
|
|---|
| 341 | ClientHeight - 3 - 36 - 10, S);
|
|---|
| 342 | if MyRO.Wonder[Selection].CityID = -2 then
|
|---|
| 343 | S := Phrases.Lookup('DESTROYED')
|
|---|
| 344 | else if MyRO.Wonder[Selection].EffectiveOwner < 0 then
|
|---|
| 345 | S := Phrases.Lookup('EXPIRED')
|
|---|
| 346 | else
|
|---|
| 347 | S := Tribe[MyRO.Wonder[Selection].EffectiveOwner].TPhrase('WONDEROWNER');
|
|---|
| 348 | LoweredTextOut(Canvas, -1, MainTexture,
|
|---|
| 349 | (ClientWidth - BiColorTextWidth(Canvas, S)) div 2,
|
|---|
| 350 | ClientHeight - 3 - 36 + 10, S);
|
|---|
| 351 | end;
|
|---|
| 352 | end;
|
|---|
| 353 | end;
|
|---|
| 354 | end;
|
|---|
| 355 |
|
|---|
| 356 | procedure TWondersDlg.FormMouseDown(Sender: TObject; Button: TMouseButton;
|
|---|
| 357 | Shift: TShiftState; X, Y: Integer);
|
|---|
| 358 | begin
|
|---|
| 359 | if Selection >= 0 then
|
|---|
| 360 | HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkImp, Selection);
|
|---|
| 361 | end;
|
|---|
| 362 |
|
|---|
| 363 | end.
|
|---|