Changeset 6 for trunk/LocalPlayer/Wonders.pas
- Timestamp:
- Jan 7, 2017, 11:32:14 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LocalPlayer/Wonders.pas
r2 r6 1 1 {$INCLUDE switches} 2 3 2 unit Wonders; 4 3 … … 6 5 7 6 uses 8 ScreenTools, BaseWin,Protocol,7 ScreenTools, BaseWin, Protocol, 9 8 10 9 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, … … 16 15 procedure FormCreate(Sender: TObject); 17 16 procedure CloseBtnClick(Sender: TObject); 18 procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, 19 Y: Integer); 17 procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); 20 18 procedure FormShow(Sender: TObject); 21 19 procedure FormMouseDown(Sender: TObject; Button: TMouseButton; … … 24 22 public 25 23 procedure OffscreenPaint; override; 26 procedure ShowNewContent(NewMode: integer);24 procedure ShowNewContent(NewMode: Integer); 27 25 28 26 private 29 xm, ym,Selection: integer;27 xm, ym, Selection: Integer; 30 28 end; 31 29 … … 36 34 37 35 uses 38 Term, ClientTools, Help,Tribes;36 Term, ClientTools, Help, Tribes; 39 37 40 38 {$R *.DFM} 41 39 42 40 const 43 RingPosition: array[0..20,0..1] of integer= 44 ((-80,-32), // Pyramids 45 (80,-32), // Zeus 46 (0,-64), // Gardens 47 (0,0), // Colossus 48 (0,64), // Lighthouse 49 (-80,32), // GrLibrary 50 (-90,114), // Oracle 51 (80,32), // Sun 52 (90,-114), // Leo 53 (-180,0), // Magellan 54 (90,114), // Mich 55 (0,0), //{11;} 56 (180,0), // Newton 57 (-90,-114), // Bach 58 (0,0), //{14;} 59 (-160,-64), // Liberty 60 (0,128), // Eiffel 61 (160,-64), // Hoover 62 (-160,64), // Shinkansen 63 (0,-128), // Manhattan 64 (160,64)); // Mir 65 41 RingPosition: array [0 .. 20, 0 .. 1] of Integer = ((-80, -32), // Pyramids 42 (80, -32), // Zeus 43 (0, -64), // Gardens 44 (0, 0), // Colossus 45 (0, 64), // Lighthouse 46 (-80, 32), // GrLibrary 47 (-90, 114), // Oracle 48 (80, 32), // Sun 49 (90, -114), // Leo 50 (-180, 0), // Magellan 51 (90, 114), // Mich 52 (0, 0), // {11;} 53 (180, 0), // Newton 54 (-90, -114), // Bach 55 (0, 0), // {14;} 56 (-160, -64), // Liberty 57 (0, 128), // Eiffel 58 (160, -64), // Hoover 59 (-160, 64), // Shinkansen 60 (0, -128), // Manhattan 61 (160, 64)); // Mir 66 62 67 63 procedure TWondersDlg.FormCreate(Sender: TObject); 68 64 begin 69 Canvas.Font.Assign(UniFont[ftNormal]);70 Canvas.Brush.Style:=bsClear;71 InitButtons();65 Canvas.Font.Assign(UniFont[ftNormal]); 66 Canvas.Brush.Style := bsClear; 67 InitButtons(); 72 68 end; 73 69 74 70 procedure TWondersDlg.FormShow(Sender: TObject); 75 71 begin 76 Selection:=-1;77 OffscreenPaint;78 end; 79 80 procedure TWondersDlg.ShowNewContent(NewMode: integer);81 begin 82 inherited ShowNewContent(NewMode);72 Selection := -1; 73 OffscreenPaint; 74 end; 75 76 procedure TWondersDlg.ShowNewContent(NewMode: Integer); 77 begin 78 inherited ShowNewContent(NewMode); 83 79 end; 84 80 85 81 procedure TWondersDlg.OffscreenPaint; 86 82 type 87 TLine=array[0..649,0..2] of Byte;88 89 procedure DarkIcon(i: integer);83 TLine = array [0 .. 649, 0 .. 2] of Byte; 84 85 procedure DarkIcon(i: Integer); 90 86 var 91 x,y,ch,x0Dst,y0Dst,x0Src,y0Src,darken,c: integer;92 Src,Dst: ^TLine;93 begin 94 x0Dst:=ClientWidth div 2-xSizeBig div 2+RingPosition[i,0];95 y0Dst:=ClientHeight div 2-ySizeBig div 2+RingPosition[i,1];96 x0Src:=(i mod 7)*xSizeBig;97 y0Src:=(i div 7+SystemIconLines)*ySizeBig;98 for y:=0 to ySizeBig-1 do99 begin 100 Src:=BigImp.ScanLine[y0Src+y];101 Dst:=Offscreen.ScanLine[y0Dst+y];102 for x:=0 to xSizeBig-1 do87 X, Y, ch, x0Dst, y0Dst, x0Src, y0Src, darken, c: Integer; 88 Src, Dst: ^TLine; 89 begin 90 x0Dst := ClientWidth div 2 - xSizeBig div 2 + RingPosition[i, 0]; 91 y0Dst := ClientHeight div 2 - ySizeBig div 2 + RingPosition[i, 1]; 92 x0Src := (i mod 7) * xSizeBig; 93 y0Src := (i div 7 + SystemIconLines) * ySizeBig; 94 for Y := 0 to ySizeBig - 1 do 95 begin 96 Src := BigImp.ScanLine[y0Src + Y]; 97 Dst := Offscreen.ScanLine[y0Dst + Y]; 98 for X := 0 to xSizeBig - 1 do 103 99 begin 104 darken:=((255-Src[x0Src+x][0])*3 105 +(255-Src[x0Src+x][1])*15 106 +(255-Src[x0Src+x][2])*9) div 128; 107 for ch:=0 to 2 do 100 darken := ((255 - Src[x0Src + X][0]) * 3 + (255 - Src[x0Src + X][1]) * 101 15 + (255 - Src[x0Src + X][2]) * 9) div 128; 102 for ch := 0 to 2 do 108 103 begin 109 c:=Dst[x0Dst+x][ch]-darken; 110 if c<0 then Dst[x0Dst+x][ch]:=0 111 else Dst[x0Dst+x][ch]:=c; 104 c := Dst[x0Dst + X][ch] - darken; 105 if c < 0 then 106 Dst[x0Dst + X][ch] := 0 107 else 108 Dst[x0Dst + X][ch] := c; 112 109 end 113 110 end … … 115 112 end; 116 113 117 procedure Glow(i, GlowColor: integer);118 begin 119 GlowFrame(Offscreen, ClientWidth div 2-xSizeBig div 2+RingPosition[i,0],120 ClientHeight div 2-ySizeBig div 2+RingPosition[i,1],121 xSizeBig,ySizeBig, GlowColor);114 procedure Glow(i, GlowColor: Integer); 115 begin 116 GlowFrame(Offscreen, ClientWidth div 2 - xSizeBig div 2 + RingPosition[i, 117 0], ClientHeight div 2 - ySizeBig div 2 + RingPosition[i, 1], xSizeBig, 118 ySizeBig, GlowColor); 122 119 end; 123 120 124 121 const 125 darken=24;126 // space=pi/120;127 amax0=15734; // 1 shl 16*tan(pi/12-space);128 amin1=19413; // 1 shl 16*tan(pi/12+space);129 amax1=62191; // 1 shl 16*tan(pi/4-space);130 amin2=69061; // 1 shl 16*tan(pi/4+space);131 amax2=221246; // 1 shl 16*tan(5*pi/12-space);132 amin3=272977; // 1 shl 16*tan(5*pi/12+space);122 darken = 24; 123 // space=pi/120; 124 amax0 = 15734; // 1 shl 16*tan(pi/12-space); 125 amin1 = 19413; // 1 shl 16*tan(pi/12+space); 126 amax1 = 62191; // 1 shl 16*tan(pi/4-space); 127 amin2 = 69061; // 1 shl 16*tan(pi/4+space); 128 amax2 = 221246; // 1 shl 16*tan(5*pi/12-space); 129 amin3 = 272977; // 1 shl 16*tan(5*pi/12+space); 133 130 var 134 i,x,y,r,ax,ch,c: integer; 135 HaveWonder: boolean; 136 Line: array[0..1] of ^TLine; 137 s: string; 138 begin 139 if (OffscreenUser<>nil) and (OffscreenUser<>self) then OffscreenUser.Update; 131 i, X, Y, r, ax, ch, c: Integer; 132 HaveWonder: boolean; 133 Line: array [0 .. 1] of ^TLine; 134 s: string; 135 begin 136 if (OffscreenUser <> nil) and (OffscreenUser <> self) then 137 OffscreenUser.Update; 140 138 // complete working with old owner to prevent rebound 141 OffscreenUser:=self; 142 143 Fill(Offscreen.Canvas,3,3,ClientWidth-6,ClientHeight-6, 144 (wMaintexture-ClientWidth) div 2,(hMaintexture-ClientHeight) div 2); 145 Frame(Offscreen.Canvas,0,0,ClientWidth-1,ClientHeight-1,0,0); 146 Frame(Offscreen.Canvas,1,1,ClientWidth-2,ClientHeight-2,MainTexture.clBevelLight,MainTexture.clBevelShade); 147 Frame(Offscreen.Canvas,2,2,ClientWidth-3,ClientHeight-3,MainTexture.clBevelLight,MainTexture.clBevelShade); 148 Corner(Offscreen.Canvas,1,1,0,MainTexture); 149 Corner(Offscreen.Canvas,ClientWidth-9,1,1,MainTexture); 150 Corner(Offscreen.Canvas,1,ClientHeight-9,2,MainTexture); 151 Corner(Offscreen.Canvas,ClientWidth-9,ClientHeight-9,3,MainTexture); 152 153 BtnFrame(Offscreen.Canvas,CloseBtn.BoundsRect,MainTexture); 154 155 Offscreen.Canvas.Font.Assign(UniFont[ftCaption]); 156 s:=Phrases.Lookup('TITLE_WONDERS'); 157 RisedTextOut(Offscreen.Canvas,(ClientWidth-BiColorTextWidth(Offscreen.Canvas,s)) div 2-1,7,s); 158 Offscreen.Canvas.Font.Assign(UniFont[ftNormal]); 159 160 xm:=ClientWidth div 2; 161 ym:=ClientHeight div 2; 162 for y:=0 to 127 do 163 begin 164 Line[0]:=Offscreen.Scanline[ym+y]; 165 Line[1]:=Offscreen.Scanline[ym-1-y]; 166 for x:=0 to 179 do 167 begin 168 r:=x*x*(32*32)+y*y*(45*45); 169 ax:=((1 shl 16 div 32)*45)*y; 170 if (r<8*128*180*180) 171 and ((r>=32*64*90*90) and (ax<amax2*x) and ((ax<amax0*x) or (ax>amin2*x)) 172 or (ax>amin1*x) and ((ax<amax1*x) or (ax>amin3*x))) then 173 for i:=0 to 1 do for ch:=0 to 2 do 139 OffscreenUser := self; 140 141 Fill(Offscreen.Canvas, 3, 3, ClientWidth - 6, ClientHeight - 6, 142 (wMaintexture - ClientWidth) div 2, (hMaintexture - ClientHeight) div 2); 143 Frame(Offscreen.Canvas, 0, 0, ClientWidth - 1, ClientHeight - 1, 0, 0); 144 Frame(Offscreen.Canvas, 1, 1, ClientWidth - 2, ClientHeight - 2, 145 MainTexture.clBevelLight, MainTexture.clBevelShade); 146 Frame(Offscreen.Canvas, 2, 2, ClientWidth - 3, ClientHeight - 3, 147 MainTexture.clBevelLight, MainTexture.clBevelShade); 148 Corner(Offscreen.Canvas, 1, 1, 0, MainTexture); 149 Corner(Offscreen.Canvas, ClientWidth - 9, 1, 1, MainTexture); 150 Corner(Offscreen.Canvas, 1, ClientHeight - 9, 2, MainTexture); 151 Corner(Offscreen.Canvas, ClientWidth - 9, ClientHeight - 9, 3, MainTexture); 152 153 BtnFrame(Offscreen.Canvas, CloseBtn.BoundsRect, MainTexture); 154 155 Offscreen.Canvas.Font.Assign(UniFont[ftCaption]); 156 s := Phrases.Lookup('TITLE_WONDERS'); 157 RisedTextOut(Offscreen.Canvas, 158 (ClientWidth - BiColorTextWidth(Offscreen.Canvas, s)) div 2 - 1, 7, s); 159 Offscreen.Canvas.Font.Assign(UniFont[ftNormal]); 160 161 xm := ClientWidth div 2; 162 ym := ClientHeight div 2; 163 for Y := 0 to 127 do 164 begin 165 Line[0] := Offscreen.ScanLine[ym + Y]; 166 Line[1] := Offscreen.ScanLine[ym - 1 - Y]; 167 for X := 0 to 179 do 168 begin 169 r := X * X * (32 * 32) + Y * Y * (45 * 45); 170 ax := ((1 shl 16 div 32) * 45) * Y; 171 if (r < 8 * 128 * 180 * 180) and 172 ((r >= 32 * 64 * 90 * 90) and (ax < amax2 * X) and 173 ((ax < amax0 * X) or (ax > amin2 * X)) or (ax > amin1 * X) and 174 ((ax < amax1 * X) or (ax > amin3 * X))) then 175 for i := 0 to 1 do 176 for ch := 0 to 2 do 174 177 begin 175 c:=Line[i][xm+x][ch]-darken; 176 if c<0 then Line[i][xm+x][ch]:=0 177 else Line[i][xm+x][ch]:=c; 178 c:=Line[i][xm-1-x][ch]-darken; 179 if c<0 then Line[i][xm-1-x][ch]:=0 180 else Line[i][xm-1-x][ch]:=c; 178 c := Line[i][xm + X][ch] - darken; 179 if c < 0 then 180 Line[i][xm + X][ch] := 0 181 else 182 Line[i][xm + X][ch] := c; 183 c := Line[i][xm - 1 - X][ch] - darken; 184 if c < 0 then 185 Line[i][xm - 1 - X][ch] := 0 186 else 187 Line[i][xm - 1 - X][ch] := c; 181 188 end 182 189 end; 183 190 end; 184 191 185 HaveWonder:=false; 186 for i:=0 to 20 do if Imp[i].Preq<>preNA then 187 begin 188 case MyRO.Wonder[i].CityID of 189 -1: // not built yet 192 HaveWonder := false; 193 for i := 0 to 20 do 194 if Imp[i].Preq <> preNA then 195 begin 196 case MyRO.Wonder[i].CityID of 197 - 1: // not built yet 198 begin 199 Fill(Offscreen.Canvas, xm - xSizeBig div 2 + RingPosition[i, 0] - 3, 200 ym - ySizeBig div 2 + RingPosition[i, 1] - 3, xSizeBig + 6, 201 ySizeBig + 6, (wMaintexture - ClientWidth) div 2, 202 (hMaintexture - ClientHeight) div 2); 203 DarkIcon(i); 204 end; 205 -2: // destroyed 206 begin 207 HaveWonder := true; 208 Glow(i, $000000); 209 BitBlt(Offscreen.Canvas.Handle, xm - xSizeBig div 2 + RingPosition 210 [i, 0], ym - ySizeBig div 2 + RingPosition[i, 1], xSizeBig, 211 ySizeBig, BigImp.Canvas.Handle, 0, (SystemIconLines + 3) * 212 ySizeBig, SRCCOPY); 213 end; 214 else 215 begin 216 HaveWonder := true; 217 if MyRO.Wonder[i].EffectiveOwner >= 0 then 218 Glow(i, Tribe[MyRO.Wonder[i].EffectiveOwner].Color) 219 else 220 Glow(i, $000000); 221 BitBlt(Offscreen.Canvas.Handle, xm - xSizeBig div 2 + RingPosition[i, 222 0], ym - ySizeBig div 2 + RingPosition[i, 1], xSizeBig, ySizeBig, 223 BigImp.Canvas.Handle, (i mod 7) * xSizeBig, 224 (i div 7 + SystemIconLines) * ySizeBig, SRCCOPY); 225 end 226 end 227 end; 228 229 if not HaveWonder then 230 begin 231 s := Phrases.Lookup('NOWONDER'); 232 RisedTextOut(Offscreen.Canvas, xm - BiColorTextWidth(Offscreen.Canvas, s) 233 div 2, ym - Offscreen.Canvas.TextHeight(s) div 2, s); 234 end; 235 236 MarkUsedOffscreen(ClientWidth, ClientHeight); 237 end; { OffscreenPaint } 238 239 procedure TWondersDlg.CloseBtnClick(Sender: TObject); 240 begin 241 Close 242 end; 243 244 procedure TWondersDlg.FormMouseMove(Sender: TObject; Shift: TShiftState; 245 X, Y: Integer); 246 var 247 i, OldSelection: Integer; 248 s: string; 249 begin 250 OldSelection := Selection; 251 Selection := -1; 252 for i := 0 to 20 do 253 if (Imp[i].Preq <> preNA) and (X >= xm - xSizeBig div 2 + RingPosition[i, 0] 254 ) and (X < xm + xSizeBig div 2 + RingPosition[i, 0]) and 255 (Y >= ym - ySizeBig div 2 + RingPosition[i, 1]) and 256 (Y < ym + ySizeBig div 2 + RingPosition[i, 1]) then 257 begin 258 Selection := i; 259 break 260 end; 261 if Selection <> OldSelection then 262 begin 263 Fill(Canvas, 9, ClientHeight - 3 - 46, ClientWidth - 18, 44, 264 (wMaintexture - ClientWidth) div 2, (hMaintexture - ClientHeight) div 2); 265 if Selection >= 0 then 266 begin 267 if MyRO.Wonder[Selection].CityID = -1 then 268 begin // not built yet 269 { s:=Phrases.Lookup('IMPROVEMENTS',Selection); 270 Canvas.Font.Color:=$000000; 271 Canvas.TextOut( 272 (ClientWidth-BiColorTextWidth(Canvas,s)) div 2+1, 273 ClientHeight-3-36+1, s); 274 Canvas.Font.Color:=MainTexture.clBevelLight; 275 Canvas.TextOut( 276 (ClientWidth-BiColorTextWidth(Canvas,s)) div 2, 277 ClientHeight-3-36, s); } 278 end 279 else 190 280 begin 191 Fill(Offscreen.Canvas, 192 xm-xSizeBig div 2+RingPosition[i,0]-3, 193 ym-ySizeBig div 2+RingPosition[i,1]-3, 194 xSizeBig+6, ySizeBig+6, 195 (wMaintexture-ClientWidth) div 2,(hMaintexture-ClientHeight) div 2); 196 DarkIcon(i); 197 end; 198 -2: // destroyed 199 begin 200 HaveWonder:=true; 201 Glow(i,$000000); 202 BitBlt(Offscreen.Canvas.Handle, xm-xSizeBig div 2+RingPosition[i,0], 203 ym-ySizeBig div 2+RingPosition[i,1], xSizeBig, ySizeBig, 204 BigImp.Canvas.Handle, 0, (SystemIconLines+3)*ySizeBig, SRCCOPY); 205 end; 206 else 207 begin 208 HaveWonder:=true; 209 if MyRO.Wonder[i].EffectiveOwner>=0 then 210 Glow(i,Tribe[MyRO.Wonder[i].EffectiveOwner].Color) 211 else Glow(i,$000000); 212 BitBlt(Offscreen.Canvas.Handle, xm-xSizeBig div 2+RingPosition[i,0], 213 ym-ySizeBig div 2+RingPosition[i,1], xSizeBig, ySizeBig, 214 BigImp.Canvas.Handle, (i mod 7)*xSizeBig, 215 (i div 7+SystemIconLines)*ySizeBig, SRCCOPY); 216 end 217 end 218 end; 219 220 if not HaveWonder then 221 begin 222 s:=Phrases.Lookup('NOWONDER'); 223 RisedTextout(Offscreen.Canvas,xm-BiColorTextWidth(Offscreen.Canvas,s) div 2, 224 ym-Offscreen.Canvas.TextHeight(s) div 2, s); 225 end; 226 227 MarkUsedOffscreen(ClientWidth,ClientHeight); 228 end; {OffscreenPaint} 229 230 procedure TWondersDlg.CloseBtnClick(Sender: TObject); 231 begin 232 Close 233 end; 234 235 procedure TWondersDlg.FormMouseMove(Sender: TObject; Shift: TShiftState; X, 236 Y: Integer); 237 var 238 i,OldSelection: integer; 239 s: string; 240 begin 241 OldSelection:=Selection; 242 Selection:=-1; 243 for i:=0 to 20 do 244 if (Imp[i].Preq<>preNA) and (x>=xm-xSizeBig div 2+RingPosition[i,0]) 245 and (x<xm+xSizeBig div 2+RingPosition[i,0]) 246 and (y>=ym-ySizeBig div 2+RingPosition[i,1]) 247 and (y<ym+ySizeBig div 2+RingPosition[i,1]) then 248 begin Selection:=i; break end; 249 if Selection<>OldSelection then 250 begin 251 Fill(Canvas,9,ClientHeight-3-46,ClientWidth-18,44, 252 (wMaintexture-ClientWidth) div 2,(hMaintexture-ClientHeight) div 2); 253 if Selection>=0 then 254 begin 255 if MyRO.Wonder[Selection].CityID=-1 then 256 begin // not built yet 257 { s:=Phrases.Lookup('IMPROVEMENTS',Selection); 258 Canvas.Font.Color:=$000000; 259 Canvas.TextOut( 260 (ClientWidth-BiColorTextWidth(Canvas,s)) div 2+1, 261 ClientHeight-3-36+1, s); 262 Canvas.Font.Color:=MainTexture.clBevelLight; 263 Canvas.TextOut( 264 (ClientWidth-BiColorTextWidth(Canvas,s)) div 2, 265 ClientHeight-3-36, s);} 266 end 267 else 268 begin 269 s:=Phrases.Lookup('IMPROVEMENTS',Selection); 270 if MyRO.Wonder[Selection].CityID<>-2 then 271 s:=Format(Phrases.Lookup('WONDEROF'), 272 [s,CityName(MyRO.Wonder[Selection].CityID)]); 273 LoweredTextOut(Canvas, -1, MainTexture, (ClientWidth-BiColorTextWidth(Canvas,s)) div 2, 274 ClientHeight-3-36-10, s); 275 if MyRO.Wonder[Selection].CityID=-2 then 276 s:=Phrases.Lookup('DESTROYED') 277 else if MyRO.Wonder[Selection].EffectiveOwner<0 then 278 s:=Phrases.Lookup('EXPIRED') 279 else s:=Tribe[MyRO.Wonder[Selection].EffectiveOwner].TPhrase('WONDEROWNER'); 280 LoweredTextOut(Canvas, -1, MainTexture, (ClientWidth-BiColorTextWidth(Canvas,s)) div 2, 281 ClientHeight-3-36+10, s); 281 s := Phrases.Lookup('IMPROVEMENTS', Selection); 282 if MyRO.Wonder[Selection].CityID <> -2 then 283 s := Format(Phrases.Lookup('WONDEROF'), 284 [s, CityName(MyRO.Wonder[Selection].CityID)]); 285 LoweredTextOut(Canvas, -1, MainTexture, 286 (ClientWidth - BiColorTextWidth(Canvas, s)) div 2, 287 ClientHeight - 3 - 36 - 10, s); 288 if MyRO.Wonder[Selection].CityID = -2 then 289 s := Phrases.Lookup('DESTROYED') 290 else if MyRO.Wonder[Selection].EffectiveOwner < 0 then 291 s := Phrases.Lookup('EXPIRED') 292 else 293 s := Tribe[MyRO.Wonder[Selection].EffectiveOwner] 294 .TPhrase('WONDEROWNER'); 295 LoweredTextOut(Canvas, -1, MainTexture, 296 (ClientWidth - BiColorTextWidth(Canvas, s)) div 2, 297 ClientHeight - 3 - 36 + 10, s); 282 298 end 283 299 end; … … 288 304 Shift: TShiftState; X, Y: Integer); 289 305 begin 290 if Selection>=0 then291 HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkImp, Selection);306 if Selection >= 0 then 307 HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkImp, Selection); 292 308 end; 293 309 294 310 end. 295
Note:
See TracChangeset
for help on using the changeset viewer.