Changeset 465 for branches/highdpi/LocalPlayer/CityType.pas
- Timestamp:
- Nov 30, 2023, 10:16:14 PM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/LocalPlayer/CityType.pas
r361 r465 5 5 6 6 uses 7 UDpiControls, Protocol, ClientTools, Term, ScreenTools, BaseWin, LCLIntf, LCLType, 8 SysUtils, Classes, Graphics, Controls, Forms, 9 ButtonB, ExtCtrls; 7 UDpiControls, Protocol, ClientTools, ScreenTools, BaseWin, LCLIntf, LCLType, 8 SysUtils, Classes, Graphics, Controls, Forms, ButtonB, ExtCtrls; 10 9 11 10 type … … 18 17 procedure FormShow(Sender: TObject); 19 18 procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; 20 Shift: TShiftState; x, y: integer);19 Shift: TShiftState; X, Y: Integer); 21 20 procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton; 22 Shift: TShiftState; x, y: integer);21 Shift: TShiftState; X, Y: Integer); 23 22 procedure FormClose(Sender: TObject; var Action: TCloseAction); 24 23 procedure DeleteBtnClick(Sender: TObject); 25 24 public 26 procedure ShowNewContent(NewMode: integer);25 procedure ShowNewContent(NewMode: TWindowMode); 27 26 protected 28 27 procedure OffscreenPaint; override; 29 28 private 30 nPool, dragiix, ctype: integer;31 Pooliix: array [0 .. nImp - 1] of integer;29 nPool, dragiix, ctype: Integer; 30 Pooliix: array [0 .. nImp - 1] of Integer; 32 31 listed: Set of 0 .. nImp; 33 Changed: boolean;34 procedure LoadType(NewType: integer);32 Changed: Boolean; 33 procedure LoadType(NewType: Integer); 35 34 procedure SaveType; 36 35 end; 37 36 38 var39 CityTypeDlg: TCityTypeDlg;40 37 41 38 implementation 42 39 43 uses Help; 40 uses 41 Help, Term; 44 42 45 43 {$R *.lfm} … … 82 80 procedure TCityTypeDlg.OffscreenPaint; 83 81 var 84 i, iix: integer;85 s: string;82 I, iix: Integer; 83 S: string; 86 84 begin 87 85 inherited; 88 offscreen.Canvas.Font.Assign(UniFont[ftSmall]);86 Offscreen.Canvas.Font.Assign(UniFont[ftSmall]); 89 87 FillOffscreen(xList - 7, yList, 42 * nListCol + 14, 32 * nListRow); 90 88 FillOffscreen(xPool - 7, yPool, 42 * nPoolCol + 14, 32 * nPoolRow); … … 92 90 yPool - yList - 32 * nListRow); 93 91 94 Frame( offscreen.Canvas, 0, yList + 32 * nListRow, InnerWidth - 255,92 Frame(Offscreen.Canvas, 0, yList + 32 * nListRow, InnerWidth - 255, 95 93 yPool - 23, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade); 96 Frame( offscreen.Canvas, InnerWidth - 254, yList + 32 * nListRow,94 Frame(Offscreen.Canvas, InnerWidth - 254, yList + 32 * nListRow, 97 95 InnerWidth - 89, yPool - 23, MainTexture.ColorBevelLight, 98 96 MainTexture.ColorBevelShade); 99 Frame( offscreen.Canvas, InnerWidth - 88, yList + 32 * nListRow,97 Frame(Offscreen.Canvas, InnerWidth - 88, yList + 32 * nListRow, 100 98 InnerWidth - 1, yPool - 23, MainTexture.ColorBevelLight, 101 99 MainTexture.ColorBevelShade); 102 Frame( offscreen.Canvas, 0, yPool - 22, InnerWidth - 1, yPool - 1,100 Frame(Offscreen.Canvas, 0, yPool - 22, InnerWidth - 1, yPool - 1, 103 101 MainTexture.ColorBevelLight, MainTexture.ColorBevelShade); 104 for i:= 0 to nCityType - 1 do105 begin 106 RFrame( offscreen.Canvas, xSwitch + i * 42, ySwitch, xSwitch + 39 + i* 42,102 for I := 0 to nCityType - 1 do 103 begin 104 RFrame(Offscreen.Canvas, xSwitch + I * 42, ySwitch, xSwitch + 39 + I * 42, 107 105 ySwitch + 23, MainTexture.ColorBevelShade, MainTexture.ColorBevelLight); 108 if i= ctype then109 Frame( offscreen.Canvas, xSwitch + 1 + i* 42, ySwitch + 1,110 xSwitch + 38 + i* 42, ySwitch + 22, MainTexture.ColorBevelShade,106 if I = ctype then 107 Frame(Offscreen.Canvas, xSwitch + 1 + I * 42, ySwitch + 1, 108 xSwitch + 38 + I * 42, ySwitch + 22, MainTexture.ColorBevelShade, 111 109 MainTexture.ColorBevelLight) 112 110 else 113 Frame( offscreen.Canvas, xSwitch + 1 + i* 42, ySwitch + 1,114 xSwitch + 38 + i* 42, ySwitch + 22, MainTexture.ColorBevelLight,111 Frame(Offscreen.Canvas, xSwitch + 1 + I * 42, ySwitch + 1, 112 xSwitch + 38 + I * 42, ySwitch + 22, MainTexture.ColorBevelLight, 115 113 MainTexture.ColorBevelShade); 116 DpiBit Canvas(offscreen.Canvas, xSwitch + 2 + i* 42, ySwitch + 2,117 xSizeSmall, ySizeSmall, SmallImp.Canvas, ( i+ 3) * xSizeSmall, 0);118 end; 119 RisedTextOut( offscreen.Canvas, 8, yList + 32 * nListRow + 2,114 DpiBitBltCanvas(Offscreen.Canvas, xSwitch + 2 + I * 42, ySwitch + 2, 115 xSizeSmall, ySizeSmall, SmallImp.Canvas, (I + 3) * xSizeSmall, 0); 116 end; 117 RisedTextOut(Offscreen.Canvas, 8, yList + 32 * nListRow + 2, 120 118 Phrases.Lookup('BUILDORDER')); 121 RisedTextOut( offscreen.Canvas, 8, ySwitch + 26,119 RisedTextOut(Offscreen.Canvas, 8, ySwitch + 26, 122 120 Phrases.Lookup('CITYTYPE', ctype)); 123 s:= Phrases.Lookup('BUILDREST');124 RisedTextOut( offscreen.Canvas,125 (InnerWidth - BiColorTextWidth( offscreen.Canvas, s)) div 2,126 yList + 72 + 32 * nListRow, s);127 128 with offscreen.Canvas do129 begin 130 for i:= 1 to nListRow - 1 do131 DLine( offscreen.Canvas, xList - 5, xList + 4 + 42 * nListCol,132 yList - 1 + 32 * i, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);133 for i:= 0 to nListCol * nListRow - 1 do134 begin 135 s := IntToStr(i+ 1);121 S := Phrases.Lookup('BUILDREST'); 122 RisedTextOut(Offscreen.Canvas, 123 (InnerWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2, 124 yList + 72 + 32 * nListRow, S); 125 126 with Offscreen.Canvas do 127 begin 128 for I := 1 to nListRow - 1 do 129 DLine(Offscreen.Canvas, xList - 5, xList + 4 + 42 * nListCol, 130 yList - 1 + 32 * I, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade); 131 for I := 0 to nListCol * nListRow - 1 do 132 begin 133 S := IntToStr(I + 1); 136 134 Font.Color := MainTexture.ColorTextLight; 137 Textout(xList + 20 + i mod nListCol * 42 - TextWidth(s) div 2,138 yList + 15 + i div nListCol * 32 - TextHeight(s) div 2, s);139 end; 140 end; 141 142 i:= 0;143 while MyData.ImpOrder[ctype, i] >= 0 do144 begin 145 RFrame( offscreen.Canvas, xList + 20 - xSizeSmall div 2 + imod nListCol *146 42, yList + 15 - ySizeSmall div 2 + idiv nListCol * 32,147 xList + 21 + xSizeSmall div 2 + imod nListCol * 42,148 yList + 16 + ySizeSmall div 2 + idiv nListCol * 32,135 Textout(xList + 20 + I mod nListCol * 42 - TextWidth(S) div 2, 136 yList + 15 + I div nListCol * 32 - TextHeight(S) div 2, S); 137 end; 138 end; 139 140 I := 0; 141 while MyData.ImpOrder[ctype, I] >= 0 do 142 begin 143 RFrame(Offscreen.Canvas, xList + 20 - xSizeSmall div 2 + I mod nListCol * 144 42, yList + 15 - ySizeSmall div 2 + I div nListCol * 32, 145 xList + 21 + xSizeSmall div 2 + I mod nListCol * 42, 146 yList + 16 + ySizeSmall div 2 + I div nListCol * 32, 149 147 MainTexture.ColorBevelLight, MainTexture.ColorBevelShade); 150 DpiBit Canvas(offscreen.Canvas, xList + 21 - xSizeSmall div 2 +151 i mod nListCol * 42, yList + 16 - ySizeSmall div 2 + idiv nListCol * 32,148 DpiBitBltCanvas(Offscreen.Canvas, xList + 21 - xSizeSmall div 2 + 149 I mod nListCol * 42, yList + 16 - ySizeSmall div 2 + I div nListCol * 32, 152 150 xSizeSmall, ySizeSmall, SmallImp.Canvas, 153 MyData.ImpOrder[ctype, i] mod 7 * xSizeSmall,154 (MyData.ImpOrder[ctype, i] + SystemIconLines * 7) div 7 *151 MyData.ImpOrder[ctype, I] mod 7 * xSizeSmall, 152 (MyData.ImpOrder[ctype, I] + SystemIconLines * 7) div 7 * 155 153 ySizeSmall); 156 inc(i);154 Inc(I); 157 155 end; 158 156 … … 165 163 begin 166 164 Pooliix[nPool] := iix; 167 RFrame( offscreen.Canvas, xPool + 20 - xSizeSmall div 2 +165 RFrame(Offscreen.Canvas, xPool + 20 - xSizeSmall div 2 + 168 166 nPool mod nPoolCol * 42, yPool + 15 - ySizeSmall div 2 + 169 167 nPool div nPoolCol * 32, xPool + 21 + xSizeSmall div 2 + … … 171 169 nPool div nPoolCol * 32, MainTexture.ColorBevelLight, 172 170 MainTexture.ColorBevelShade); 173 DpiBit Canvas(offscreen.Canvas, xPool + 21 - xSizeSmall div 2 +171 DpiBitBltCanvas(Offscreen.Canvas, xPool + 21 - xSizeSmall div 2 + 174 172 nPool mod nPoolCol * 42, yPool + 16 - ySizeSmall div 2 + 175 173 nPool div nPoolCol * 32, xSizeSmall, ySizeSmall, SmallImp.Canvas, 176 174 iix mod 7 * xSizeSmall, (iix + SystemIconLines * 7) div 7 * 177 175 ySizeSmall); 178 inc(nPool);176 Inc(nPool); 179 177 end; 180 178 DeleteBtn.Visible := MyData.ImpOrder[ctype, 0] >= 0; … … 182 180 if dragiix >= 0 then 183 181 begin 184 ImpImage( offscreen.Canvas, xView + 9, yView + 5, dragiix);185 s:= Phrases.Lookup('IMPROVEMENTS', dragiix);186 RisedTextOut( offscreen.Canvas,187 xView + 36 - BiColorTextWidth( offscreen.Canvas, s) div 2,188 ySwitch + 26, s);182 ImpImage(Offscreen.Canvas, xView + 9, yView + 5, dragiix); 183 S := Phrases.Lookup('IMPROVEMENTS', dragiix); 184 RisedTextOut(Offscreen.Canvas, 185 xView + 36 - BiColorTextWidth(Offscreen.Canvas, S) div 2, 186 ySwitch + 26, S); 189 187 end; 190 188 MarkUsedOffscreen(InnerWidth, InnerHeight); 191 end; { MainPaint }192 193 procedure TCityTypeDlg.LoadType(NewType: integer);194 var 195 i: integer;189 end; 190 191 procedure TCityTypeDlg.LoadType(NewType: Integer); 192 var 193 I: Integer; 196 194 begin 197 195 ctype := NewType; 198 196 listed := []; 199 i:= 0;200 while MyData.ImpOrder[ctype, i] >= 0 do201 begin 202 include(listed, MyData.ImpOrder[ctype, i]);203 inc(i);204 end; 205 Changed := false;197 I := 0; 198 while MyData.ImpOrder[ctype, I] >= 0 do 199 begin 200 Include(listed, MyData.ImpOrder[ctype, I]); 201 Inc(I); 202 end; 203 Changed := False; 206 204 end; 207 205 208 206 procedure TCityTypeDlg.SaveType; 209 207 var 210 cix: integer;208 cix: Integer; 211 209 begin 212 210 if Changed then … … 215 213 if (MyCity[cix].Loc >= 0) and (MyCity[cix].Status and 7 = ctype + 1) then 216 214 AutoBuild(cix, MyData.ImpOrder[ctype]); 217 Changed := false;215 Changed := False; 218 216 end; 219 217 end; … … 226 224 end; 227 225 228 procedure TCityTypeDlg.ShowNewContent(NewMode: integer);226 procedure TCityTypeDlg.ShowNewContent(NewMode: TWindowMode); 229 227 begin 230 228 inherited ShowNewContent(NewMode); … … 232 230 233 231 procedure TCityTypeDlg.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; 234 Shift: TShiftState; x, y: integer);235 var 236 i: integer;237 begin 238 x := x- SideFrame;239 y := y- WideFrame;240 i := (x - xList) div 42 + (y- yList) div 32 * nListCol;241 if ( i < nImp) and (MyData.ImpOrder[ctype, i] >= 0) and242 ( x > xList + 2 + imod nListCol * 42) and243 ( y > yList + 5 + idiv nListCol * 32) and244 ( x < xList + 3 + 36 + imod nListCol * 42) and245 ( y < yList + 6 + 20 + idiv nListCol * 32) then232 Shift: TShiftState; X, Y: Integer); 233 var 234 I: Integer; 235 begin 236 X := X - SideFrame; 237 Y := Y - WideFrame; 238 I := (X - xList) div 42 + (Y - yList) div 32 * nListCol; 239 if (I < nImp) and (MyData.ImpOrder[ctype, I] >= 0) and 240 (X > xList + 2 + I mod nListCol * 42) and 241 (Y > yList + 5 + I div nListCol * 32) and 242 (X < xList + 3 + 36 + I mod nListCol * 42) and 243 (Y < yList + 6 + 20 + I div nListCol * 32) then 246 244 begin 247 245 if ssShift in Shift then 248 HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkImp,249 MyData.ImpOrder[ctype, i])246 MainScreen.HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkImp, 247 MyData.ImpOrder[ctype, I]) 250 248 else 251 249 begin 252 dragiix := MyData.ImpOrder[ctype, i];250 dragiix := MyData.ImpOrder[ctype, I]; 253 251 DpiScreen.Cursor := crImpDrag; 254 252 SmartUpdateContent; 255 253 end; 256 exit;257 end; 258 i := (x - xPool) div 42 + (y- yPool) div 32 * nPoolCol;259 if ( i < nPool) and (x > xPool + 2 + imod nPoolCol * 42) and260 ( y > yPool + 5 + idiv nPoolCol * 32) and261 ( x < xPool + 3 + 36 + imod nPoolCol * 42) and262 ( y < yPool + 6 + 20 + idiv nPoolCol * 32) then254 Exit; 255 end; 256 I := (X - xPool) div 42 + (Y - yPool) div 32 * nPoolCol; 257 if (I < nPool) and (X > xPool + 2 + I mod nPoolCol * 42) and 258 (Y > yPool + 5 + I div nPoolCol * 32) and 259 (X < xPool + 3 + 36 + I mod nPoolCol * 42) and 260 (Y < yPool + 6 + 20 + I div nPoolCol * 32) then 263 261 begin 264 262 if ssShift in Shift then 265 HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkImp, Pooliix[i])263 MainScreen.HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkImp, Pooliix[I]) 266 264 else 267 265 begin 268 dragiix := Pooliix[ i];266 dragiix := Pooliix[I]; 269 267 DpiScreen.Cursor := crImpDrag; 270 268 SmartUpdateContent; 271 269 end; 272 exit;273 end; 274 i := (x- xSwitch) div 42;275 if ( i < nCityType) and (x > xSwitch + 2 + i* 42) and276 ( x < xSwitch + 3 + 36 + i * 42) and (y >= ySwitch + 2) and (y< ySwitch + 22)270 Exit; 271 end; 272 I := (X - xSwitch) div 42; 273 if (I < nCityType) and (X > xSwitch + 2 + I * 42) and 274 (X < xSwitch + 3 + 36 + I * 42) and (Y >= ySwitch + 2) and (Y < ySwitch + 22) 277 275 then 278 276 begin 279 277 SaveType; 280 LoadType( i);278 LoadType(I); 281 279 SmartUpdateContent; 282 280 end; … … 284 282 285 283 procedure TCityTypeDlg.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton; 286 Shift: TShiftState; x, y: integer);287 288 procedure UnList(iix: integer);284 Shift: TShiftState; X, Y: Integer); 285 286 procedure UnList(iix: Integer); 289 287 var 290 i: integer;291 begin 292 i:= 0;293 while (MyData.ImpOrder[ctype, i] >= 0) and294 (MyData.ImpOrder[ctype, i] <> iix) do295 inc(i);296 assert(MyData.ImpOrder[ctype, i] = iix);297 move(MyData.ImpOrder[ctype, i + 1], MyData.ImpOrder[ctype, i], nImp - i);288 I: Integer; 289 begin 290 I := 0; 291 while (MyData.ImpOrder[ctype, I] >= 0) and 292 (MyData.ImpOrder[ctype, I] <> iix) do 293 Inc(I); 294 Assert(MyData.ImpOrder[ctype, I] = iix); 295 Move(MyData.ImpOrder[ctype, I + 1], MyData.ImpOrder[ctype, I], nImp - I); 298 296 Exclude(listed, iix); 299 297 end; 300 298 301 299 var 302 i: integer;303 begin 304 x := x- SideFrame;305 y := y- WideFrame;300 I: Integer; 301 begin 302 X := X - SideFrame; 303 Y := Y - WideFrame; 306 304 if dragiix >= 0 then 307 305 begin 308 if ( x >= xList) and (x < xList + nListCol * 42) and (y>= yList) and309 ( y< yList + nListRow * 32) then306 if (X >= xList) and (X < xList + nListCol * 42) and (Y >= yList) and 307 (Y < yList + nListRow * 32) then 310 308 begin 311 309 if dragiix in listed then 312 310 UnList(dragiix); 313 i := (x - xList) div 42 + (y- yList) div 32 * nListCol;314 while ( i > 0) and (MyData.ImpOrder[ctype, i- 1] < 0) do315 dec(i);316 move(MyData.ImpOrder[ctype, i], MyData.ImpOrder[ctype, i+ 1],317 nImp - i- 1);318 MyData.ImpOrder[ctype, i] := dragiix;319 include(listed, dragiix);320 Changed := true;311 I := (X - xList) div 42 + (Y - yList) div 32 * nListCol; 312 while (I > 0) and (MyData.ImpOrder[ctype, I - 1] < 0) do 313 Dec(I); 314 Move(MyData.ImpOrder[ctype, I], MyData.ImpOrder[ctype, I + 1], 315 nImp - I - 1); 316 MyData.ImpOrder[ctype, I] := dragiix; 317 Include(listed, dragiix); 318 Changed := True; 321 319 end 322 else if (dragiix in listed) and ( x >= xPool) and (x< xPool + nPoolCol * 42)323 and ( y >= yPool) and (y< yPool + nPoolRow * 32) then320 else if (dragiix in listed) and (X >= xPool) and (X < xPool + nPoolCol * 42) 321 and (Y >= yPool) and (Y < yPool + nPoolRow * 32) then 324 322 begin 325 323 UnList(dragiix); 326 Changed := true;324 Changed := True; 327 325 end; 328 326 dragiix := -1; … … 340 338 procedure TCityTypeDlg.DeleteBtnClick(Sender: TObject); 341 339 begin 342 fillchar(MyData.ImpOrder[ctype], sizeof(MyData.ImpOrder[ctype]), Byte(-1));340 FillChar(MyData.ImpOrder[ctype], SizeOf(MyData.ImpOrder[ctype]), Byte(-1)); 343 341 listed := []; 344 Changed := true;342 Changed := True; 345 343 SmartUpdateContent; 346 344 end;
Note:
See TracChangeset
for help on using the changeset viewer.