Changeset 465 for branches/highdpi/NoTerm.pas
- Timestamp:
- Nov 30, 2023, 10:16:14 PM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/NoTerm.pas
r378 r465 18 18 procedure FormPaint(Sender: TObject); 19 19 procedure FormCreate(Sender: TObject); 20 procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);20 procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); 21 21 public 22 procedure Client(Command, Player: integer; var Data);22 procedure Client(Command, Player: Integer; var Data); 23 23 private 24 24 Me: Integer; … … 43 43 procedure NewStat; 44 44 procedure EndPlaying; 45 procedure ShowActive( p: integer; Active: boolean);45 procedure ShowActive(P: Integer; Active: Boolean); 46 46 procedure ShowYear; 47 47 end; … … 50 50 NoTermDlg: TNoTermDlg; 51 51 52 procedure Client(Command, Player: integer; var Data); stdcall; 52 procedure Client(Command, Player: Integer; var Data); stdcall; 53 53 54 54 55 implementation 55 56 56 57 uses 57 GameServer, log;58 GameServer, Log; 58 59 59 60 {$R *.lfm} … … 68 69 dxBrain = 128; 69 70 dyBrain = 128; 70 xBrain: array [0 .. nPlOffered - 1] of integer = (x0Brain, x0Brain,71 xBrain: array [0 .. nPlOffered - 1] of Integer = (x0Brain, x0Brain, 71 72 x0Brain + dxBrain, x0Brain + dxBrain, x0Brain + dxBrain, x0Brain, 72 73 x0Brain - dxBrain, x0Brain - dxBrain, x0Brain - dxBrain); 73 yBrain: array [0 .. nPlOffered - 1] of integer = (y0Brain, y0Brain - dyBrain,74 yBrain: array [0 .. nPlOffered - 1] of Integer = (y0Brain, y0Brain - dyBrain, 74 75 y0Brain - dyBrain, y0Brain, y0Brain + dyBrain, y0Brain + dyBrain, 75 76 y0Brain + dyBrain, y0Brain, y0Brain - dyBrain); 76 xActive: array [0 .. nPlOffered - 1] of integer = (0, 0, 36, 51, 36, 0,77 xActive: array [0 .. nPlOffered - 1] of Integer = (0, 0, 36, 51, 36, 0, 77 78 -36, -51, -36); 78 yActive: array [0 .. nPlOffered - 1] of integer = (0, -51, -36, 0, 36, 51,79 yActive: array [0 .. nPlOffered - 1] of Integer = (0, -51, -36, 0, 36, 51, 79 80 36, 0, -36); 80 81 81 82 var 82 FormsCreated: boolean;83 FormsCreated: Boolean; 83 84 84 85 procedure TNoTermDlg.FormCreate(Sender: TObject); … … 107 108 procedure TNoTermDlg.EndPlaying; 108 109 var 109 EndCommand: integer;110 EndCommand: Integer; 110 111 begin 111 112 NewStat; 112 if G.RO[ me].Turn > 0 then113 if G.RO[Me].Turn > 0 then 113 114 with MessgDlg do 114 115 begin … … 123 124 else 124 125 EndCommand := sResign; 125 Server(EndCommand, me, 0, nil^)126 end; 127 128 procedure TNoTermDlg.ShowActive( p: integer; Active: boolean);129 begin 130 if p< nPlOffered then131 Sprite(Canvas, HGrSystem, x0Brain + 28 + xActive[ p],132 y0Brain + 28 + yActive[ p], 8, 8, 81 + 9 * Byte(Active), 16);126 Server(EndCommand, Me, 0, nil^); 127 end; 128 129 procedure TNoTermDlg.ShowActive(P: Integer; Active: Boolean); 130 begin 131 if P < nPlOffered then 132 Sprite(Canvas, HGrSystem, x0Brain + 28 + xActive[P], 133 y0Brain + 28 + yActive[P], 8, 8, 81 + 9 * Byte(Active), 16); 133 134 end; 134 135 … … 137 138 Fill(State.Canvas, 0, 0, 192, 20, 64, 287 + 138); 138 139 RisedTextOut(State.Canvas, 0, 0, Format(Phrases.Lookup('AIT_ROUND'), [Round]) 139 + ' ' + TurnToString(G.RO[ me].Turn));140 DpiBit Canvas(Canvas, 64, 287 + 138, 192, 20, State.Canvas, 0, 0);141 end; 142 143 procedure TNoTermDlg.Client(Command, Player: integer; var Data);144 var 145 i, x, y, p: integer;146 ActiveDuration: extended;147 ShipComplete: boolean;148 r: TRect;140 + ' ' + TurnToString(G.RO[Me].Turn)); 141 DpiBitBltCanvas(Canvas, 64, 287 + 138, 192, 20, State.Canvas, 0, 0); 142 end; 143 144 procedure TNoTermDlg.Client(Command, Player: Integer; var Data); 145 var 146 I, X, Y, P: Integer; 147 ActiveDuration: Extended; 148 ShipComplete: Boolean; 149 R: TRect; 149 150 nowt: TDateTime; 150 151 begin 151 152 case Command of 152 153 cDebugMessage: 153 LogDlg.Add(Player, G.RO[0].Turn, pchar(@Data));154 LogDlg.Add(Player, G.RO[0].Turn, PChar(@Data)); 154 155 155 156 cInitModule: … … 159 160 Shade := TDpiBitmap.Create; 160 161 Shade.SetSize(64, 64); 161 for x:= 0 to 63 do162 for y:= 0 to 63 do163 if Odd( x + y) then164 Shade.Canvas.Pixels[ x, y] := $FFFFFF162 for X := 0 to 63 do 163 for Y := 0 to 63 do 164 if Odd(X + Y) then 165 Shade.Canvas.Pixels[X, Y] := $FFFFFF 165 166 else 166 Shade.Canvas.Pixels[ x, y] := $000000;167 Shade.Canvas.Pixels[X, Y] := $000000; 167 168 State := TDpiBitmap.Create; 168 169 State.SetSize(192, 20); … … 180 181 cNewGame, cLoadGame: 181 182 begin 182 inc(Round);183 Inc(Round); 183 184 if Mode = rmRunning then 184 185 begin … … 189 190 Show; 190 191 G := TNewGameData(Data); 191 LogDlg.mSlot.Visible := false;192 LogDlg.mSlot.Visible := False; 192 193 LogDlg.Host := nil; 193 ToldAlive := G.RO[ me].Alive;194 ToldAlive := G.RO[Me].Alive; 194 195 Active := -1; 195 196 FillChar(DisallowShowActive, SizeOf(DisallowShowActive), 0); // false … … 212 213 cTurn, cResume, cContinue: 213 214 begin 214 me := Player;215 Me := Player; 215 216 if Active >= 0 then 216 217 begin 217 ShowActive(Active, false);218 ShowActive(Active, False); 218 219 Active := -1; 219 220 end; // should not happen … … 227 228 TurnTime := SecondOf(nowt - LastNewTurn); 228 229 LastNewTurn := nowt; 229 if (G.RO[ me].Alive <> ToldAlive) then230 begin 231 for p:= 1 to nPlOffered - 1 do232 if 1 shl p and (G.RO[me].Alive xor ToldAlive) <> 0 then230 if (G.RO[Me].Alive <> ToldAlive) then 231 begin 232 for P := 1 to nPlOffered - 1 do 233 if 1 shl P and (G.RO[Me].Alive xor ToldAlive) <> 0 then 233 234 begin 234 r := Rect(xBrain[p], yBrain[p] - 16, xBrain[p] + 64,235 yBrain[ p] - 16 + 64);236 InvalidateRect(Handle, @ r, false);235 R := Rect(xBrain[P], yBrain[P] - 16, xBrain[P] + 64, 236 yBrain[P] - 16 + 64); 237 InvalidateRect(Handle, @R, False); 237 238 end; 238 ToldAlive := G.RO[ me].Alive;239 ToldAlive := G.RO[Me].Alive; 239 240 end; 240 241 DpiApplication.ProcessMessages; 241 242 if Mode = rmQuit then 242 243 EndPlaying 243 else if G.RO[ me].Happened and phGameEnd <> 0 then244 else if G.RO[Me].Happened and phGameEnd <> 0 then 244 245 begin // game ended, update statistics 245 for p:= 1 to nPlOffered - 1 do246 if Assigned(PlayersBrain[ p]) then247 if 1 shl p and G.RO[me].Alive = 0 then248 inc(ExtStat[p]) // extinct249 else if G.RO[ me].Alive = 1 shl pthen250 inc(AloneStat[p]) // only player alive246 for P := 1 to nPlOffered - 1 do 247 if Assigned(PlayersBrain[P]) then 248 if 1 shl P and G.RO[Me].Alive = 0 then 249 Inc(ExtStat[P]) // extinct 250 else if G.RO[Me].Alive = 1 shl P then 251 Inc(AloneStat[P]) // only player alive 251 252 else 252 253 begin // alive but not alone -- check colony ship 253 ShipComplete := true;254 for i:= 0 to nShipPart - 1 do255 if G.RO[ me].Ship[p].Parts[i] < ShipNeed[i] then256 ShipComplete := false;254 ShipComplete := True; 255 for I := 0 to nShipPart - 1 do 256 if G.RO[Me].Ship[P].Parts[I] < ShipNeed[I] then 257 ShipComplete := False; 257 258 if ShipComplete then 258 inc(WinStat[p]);259 Inc(WinStat[P]); 259 260 end; 260 261 if Mode = rmRunning then 261 Server(sNextRound, me, 0, nil^);262 Server(sNextRound, Me, 0, nil^); 262 263 end 263 264 else if Mode = rmRunning then 264 Server(sTurn, me, 0, nil^);265 Server(sTurn, Me, 0, nil^); 265 266 if Mode = rmStop then 266 267 begin … … 279 280 TotalStatTime := TotalStatTime + ActiveDuration; 280 281 if not DisallowShowActive[Active] then 281 ShowActive(Active, false);282 ShowActive(Active, False); 282 283 DisallowShowActive[Active] := (ActiveDuration < TurnTime * 0.25) and 283 284 (ActiveDuration < ShowActiveThreshold); … … 285 286 LastShowTurnChange := nowt; 286 287 287 Active := integer(Data);288 Active := Integer(Data); 288 289 if (Active >= 0) and not DisallowShowActive[Active] then 289 ShowActive(Active, true);290 ShowActive(Active, True); 290 291 end; 291 292 end; … … 301 302 GoBtn.ButtonIndex := 23; 302 303 GoBtn.Update; 303 Server(sTurn, me, 0, nil^);304 Server(sTurn, Me, 0, nil^); 304 305 end; 305 306 end; … … 313 314 procedure TNoTermDlg.FormPaint(Sender: TObject); 314 315 var 315 i, TimeShare: integer;316 I, TimeShare: Integer; 316 317 begin 317 318 Fill(Canvas, 3, 3, ClientWidth - 6, ClientHeight - 6, 0, 0); … … 329 330 7, Caption); 330 331 Canvas.Font.Assign(UniFont[ftSmall]); 331 for i:= 1 to nPlOffered - 1 do332 if Assigned(PlayersBrain[ i]) then332 for I := 1 to nPlOffered - 1 do 333 if Assigned(PlayersBrain[I]) then 333 334 begin 334 Frame(Canvas, xBrain[ i] - 24, yBrain[i] - 8 - 16, xBrain[i] - 24 + 111,335 yBrain[ i] - 8 - 16 + 111, MainTexture.ColorBevelShade,335 Frame(Canvas, xBrain[I] - 24, yBrain[I] - 8 - 16, xBrain[I] - 24 + 111, 336 yBrain[I] - 8 - 16 + 111, MainTexture.ColorBevelShade, 336 337 MainTexture.ColorBevelShade); 337 FrameImage(Canvas, PlayersBrain[ i].Picture, xBrain[i],338 yBrain[ i] - 16, 64, 64, 0, 0);339 if 1 shl i and G.RO[me].Alive = 0 then340 DpiBit Canvas(Canvas, xBrain[i], yBrain[i] - 16, 64, 64,338 FrameImage(Canvas, PlayersBrain[I].Picture, xBrain[I], 339 yBrain[I] - 16, 64, 64, 0, 0); 340 if 1 shl I and G.RO[Me].Alive = 0 then 341 DpiBitBltCanvas(Canvas, xBrain[I], yBrain[I] - 16, 64, 64, 341 342 Shade.Canvas, 0, 0, SRCAND); 342 Sprite(Canvas, HGrSystem, xBrain[ i] + 30 - 14, yBrain[i] + 53, 14,343 Sprite(Canvas, HGrSystem, xBrain[I] + 30 - 14, yBrain[I] + 53, 14, 343 344 14, 1, 316); 344 RisedTextOut(Canvas, xBrain[ i] + 30 - 16 - BiColorTextWidth(Canvas,345 IntToStr(WinStat[ i])), yBrain[i] + 51, IntToStr(WinStat[i]));346 Sprite(Canvas, HGrSystem, xBrain[ i] + 34, yBrain[i] + 53, 14, 14,345 RisedTextOut(Canvas, xBrain[I] + 30 - 16 - BiColorTextWidth(Canvas, 346 IntToStr(WinStat[I])), yBrain[I] + 51, IntToStr(WinStat[I])); 347 Sprite(Canvas, HGrSystem, xBrain[I] + 34, yBrain[I] + 53, 14, 14, 347 348 1 + 15, 316); 348 RisedTextOut(Canvas, xBrain[ i] + 34 + 16, yBrain[i] + 51,349 IntToStr(AloneStat[ i]));350 Sprite(Canvas, HGrSystem, xBrain[ i] + 30 - 14, yBrain[i] + 53 + 16, 14,349 RisedTextOut(Canvas, xBrain[I] + 34 + 16, yBrain[I] + 51, 350 IntToStr(AloneStat[I])); 351 Sprite(Canvas, HGrSystem, xBrain[I] + 30 - 14, yBrain[I] + 53 + 16, 14, 351 352 14, 1 + 30, 316); 352 RisedTextOut(Canvas, xBrain[ i] + 30 - 16 - BiColorTextWidth(Canvas,353 IntToStr(ExtStat[ i])), yBrain[i] + 51 + 16, IntToStr(ExtStat[i]));354 Sprite(Canvas, HGrSystem, xBrain[ i] + 34, yBrain[i] + 53 + 16, 14, 14,353 RisedTextOut(Canvas, xBrain[I] + 30 - 16 - BiColorTextWidth(Canvas, 354 IntToStr(ExtStat[I])), yBrain[I] + 51 + 16, IntToStr(ExtStat[I])); 355 Sprite(Canvas, HGrSystem, xBrain[I] + 34, yBrain[I] + 53 + 16, 14, 14, 355 356 1 + 45, 316); 356 357 if TotalStatTime > 0 then 357 358 begin 358 TimeShare := trunc(TimeStat[ i] / TotalStatTime * 100 + 0.5);359 RisedTextOut(Canvas, xBrain[ i] + 34 + 16, yBrain[i] + 51 + 16,359 TimeShare := trunc(TimeStat[I] / TotalStatTime * 100 + 0.5); 360 RisedTextOut(Canvas, xBrain[I] + 34 + 16, yBrain[I] + 51 + 16, 360 361 IntToStr(TimeShare) + '%'); 361 362 end; 362 ShowActive( i, i= Active);363 ShowActive(I, I = Active); 363 364 end; 364 365 Sprite(Canvas, HGrSystem2, x0Brain + 32 - 20, y0Brain + 32 - 20, 40, … … 370 371 end; 371 372 372 procedure Client(Command, Player: integer; var Data);373 procedure Client(Command, Player: Integer; var Data); 373 374 begin 374 375 if not FormsCreated then 375 376 begin 376 FormsCreated := true;377 FormsCreated := True; 377 378 DpiApplication.CreateForm(TNoTermDlg, NoTermDlg); 378 379 end; … … 380 381 end; 381 382 382 procedure TNoTermDlg.FormKeyDown(Sender: TObject; var Key: word;383 procedure TNoTermDlg.FormKeyDown(Sender: TObject; var Key: Word; 383 384 Shift: TShiftState); 384 385 begin
Note:
See TracChangeset
for help on using the changeset viewer.