Ignore:
Timestamp:
Nov 30, 2023, 10:16:14 PM (5 months ago)
Author:
chronos
Message:
  • Modified: Updated high dpi branch from trunk.
  • Modified: Use generics.collections instead of fgl.
  • Modified: Compile with Delphi syntax.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/highdpi/NoTerm.pas

    r378 r465  
    1818    procedure FormPaint(Sender: TObject);
    1919    procedure FormCreate(Sender: TObject);
    20     procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
     20    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    2121  public
    22     procedure Client(Command, Player: integer; var Data);
     22    procedure Client(Command, Player: Integer; var Data);
    2323  private
    2424    Me: Integer;
     
    4343    procedure NewStat;
    4444    procedure EndPlaying;
    45     procedure ShowActive(p: integer; Active: boolean);
     45    procedure ShowActive(P: Integer; Active: Boolean);
    4646    procedure ShowYear;
    4747  end;
     
    5050  NoTermDlg: TNoTermDlg;
    5151
    52 procedure Client(Command, Player: integer; var Data); stdcall;
     52procedure Client(Command, Player: Integer; var Data); stdcall;
     53
    5354
    5455implementation
    5556
    5657uses
    57   GameServer, log;
     58  GameServer, Log;
    5859
    5960{$R *.lfm}
     
    6869  dxBrain = 128;
    6970  dyBrain = 128;
    70   xBrain: array [0 .. nPlOffered - 1] of integer = (x0Brain, x0Brain,
     71  xBrain: array [0 .. nPlOffered - 1] of Integer = (x0Brain, x0Brain,
    7172    x0Brain + dxBrain, x0Brain + dxBrain, x0Brain + dxBrain, x0Brain,
    7273    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,
    7475    y0Brain - dyBrain, y0Brain, y0Brain + dyBrain, y0Brain + dyBrain,
    7576    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,
    7778    -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,
    7980    36, 0, -36);
    8081
    8182var
    82   FormsCreated: boolean;
     83  FormsCreated: Boolean;
    8384
    8485procedure TNoTermDlg.FormCreate(Sender: TObject);
     
    107108procedure TNoTermDlg.EndPlaying;
    108109var
    109   EndCommand: integer;
     110  EndCommand: Integer;
    110111begin
    111112  NewStat;
    112   if G.RO[me].Turn > 0 then
     113  if G.RO[Me].Turn > 0 then
    113114    with MessgDlg do
    114115    begin
     
    123124  else
    124125    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 then
    131     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^);
     127end;
     128
     129procedure TNoTermDlg.ShowActive(P: Integer; Active: Boolean);
     130begin
     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);
    133134end;
    134135
     
    137138  Fill(State.Canvas, 0, 0, 192, 20, 64, 287 + 138);
    138139  RisedTextOut(State.Canvas, 0, 0, Format(Phrases.Lookup('AIT_ROUND'), [Round])
    139     + ' ' + TurnToString(G.RO[me].Turn));
    140   DpiBitCanvas(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);
     142end;
     143
     144procedure TNoTermDlg.Client(Command, Player: Integer; var Data);
     145var
     146  I, X, Y, P: Integer;
     147  ActiveDuration: Extended;
     148  ShipComplete: Boolean;
     149  R: TRect;
    149150  nowt: TDateTime;
    150151begin
    151152  case Command of
    152153    cDebugMessage:
    153       LogDlg.Add(Player, G.RO[0].Turn, pchar(@Data));
     154      LogDlg.Add(Player, G.RO[0].Turn, PChar(@Data));
    154155
    155156    cInitModule:
     
    159160        Shade := TDpiBitmap.Create;
    160161        Shade.SetSize(64, 64);
    161         for x := 0 to 63 do
    162           for y := 0 to 63 do
    163             if Odd(x + y) then
    164               Shade.Canvas.Pixels[x, y] := $FFFFFF
     162        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
    165166            else
    166               Shade.Canvas.Pixels[x, y] := $000000;
     167              Shade.Canvas.Pixels[X, Y] := $000000;
    167168        State := TDpiBitmap.Create;
    168169        State.SetSize(192, 20);
     
    180181    cNewGame, cLoadGame:
    181182      begin
    182         inc(Round);
     183        Inc(Round);
    183184        if Mode = rmRunning then
    184185        begin
     
    189190          Show;
    190191        G := TNewGameData(Data);
    191         LogDlg.mSlot.Visible := false;
     192        LogDlg.mSlot.Visible := False;
    192193        LogDlg.Host := nil;
    193         ToldAlive := G.RO[me].Alive;
     194        ToldAlive := G.RO[Me].Alive;
    194195        Active := -1;
    195196        FillChar(DisallowShowActive, SizeOf(DisallowShowActive), 0); // false
     
    212213    cTurn, cResume, cContinue:
    213214      begin
    214         me := Player;
     215        Me := Player;
    215216        if Active >= 0 then
    216217        begin
    217           ShowActive(Active, false);
     218          ShowActive(Active, False);
    218219          Active := -1;
    219220        end; // should not happen
     
    227228        TurnTime := SecondOf(nowt - LastNewTurn);
    228229        LastNewTurn := nowt;
    229         if (G.RO[me].Alive <> ToldAlive) then
    230         begin
    231           for p := 1 to nPlOffered - 1 do
    232             if 1 shl p and (G.RO[me].Alive xor ToldAlive) <> 0 then
     230        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
    233234            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);
    237238            end;
    238           ToldAlive := G.RO[me].Alive;
     239          ToldAlive := G.RO[Me].Alive;
    239240        end;
    240241        DpiApplication.ProcessMessages;
    241242        if Mode = rmQuit then
    242243          EndPlaying
    243         else if G.RO[me].Happened and phGameEnd <> 0 then
     244        else if G.RO[Me].Happened and phGameEnd <> 0 then
    244245        begin // game ended, update statistics
    245           for p := 1 to nPlOffered - 1 do
    246             if Assigned(PlayersBrain[p]) then
    247               if 1 shl p and G.RO[me].Alive = 0 then
    248                 inc(ExtStat[p]) // extinct
    249               else if G.RO[me].Alive = 1 shl p then
    250                 inc(AloneStat[p]) // only player alive
     246          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
    251252              else
    252253              begin // alive but not alone -- check colony ship
    253                 ShipComplete := true;
    254                 for i := 0 to nShipPart - 1 do
    255                   if G.RO[me].Ship[p].Parts[i] < ShipNeed[i] then
    256                     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;
    257258                if ShipComplete then
    258                   inc(WinStat[p]);
     259                  Inc(WinStat[P]);
    259260              end;
    260261          if Mode = rmRunning then
    261             Server(sNextRound, me, 0, nil^);
     262            Server(sNextRound, Me, 0, nil^);
    262263        end
    263264        else if Mode = rmRunning then
    264           Server(sTurn, me, 0, nil^);
     265          Server(sTurn, Me, 0, nil^);
    265266        if Mode = rmStop then
    266267        begin
     
    279280          TotalStatTime := TotalStatTime + ActiveDuration;
    280281          if not DisallowShowActive[Active] then
    281             ShowActive(Active, false);
     282            ShowActive(Active, False);
    282283          DisallowShowActive[Active] := (ActiveDuration < TurnTime * 0.25) and
    283284            (ActiveDuration < ShowActiveThreshold);
     
    285286        LastShowTurnChange := nowt;
    286287
    287         Active := integer(Data);
     288        Active := Integer(Data);
    288289        if (Active >= 0) and not DisallowShowActive[Active] then
    289           ShowActive(Active, true);
     290          ShowActive(Active, True);
    290291      end;
    291292  end;
     
    301302    GoBtn.ButtonIndex := 23;
    302303    GoBtn.Update;
    303     Server(sTurn, me, 0, nil^);
     304    Server(sTurn, Me, 0, nil^);
    304305  end;
    305306end;
     
    313314procedure TNoTermDlg.FormPaint(Sender: TObject);
    314315var
    315   i, TimeShare: integer;
     316  I, TimeShare: Integer;
    316317begin
    317318  Fill(Canvas, 3, 3, ClientWidth - 6, ClientHeight - 6, 0, 0);
     
    329330    7, Caption);
    330331  Canvas.Font.Assign(UniFont[ftSmall]);
    331   for i := 1 to nPlOffered - 1 do
    332     if Assigned(PlayersBrain[i]) then
     332  for I := 1 to nPlOffered - 1 do
     333    if Assigned(PlayersBrain[I]) then
    333334    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,
    336337        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 then
    340         DpiBitCanvas(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,
    341342          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,
    343344        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,
    347348        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,
    351352        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,
    355356        1 + 45, 316);
    356357      if TotalStatTime > 0 then
    357358      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,
    360361          IntToStr(TimeShare) + '%');
    361362      end;
    362       ShowActive(i, i = Active);
     363      ShowActive(I, I = Active);
    363364    end;
    364365  Sprite(Canvas, HGrSystem2, x0Brain + 32 - 20, y0Brain + 32 - 20, 40,
     
    370371end;
    371372
    372 procedure Client(Command, Player: integer; var Data);
     373procedure Client(Command, Player: Integer; var Data);
    373374begin
    374375  if not FormsCreated then
    375376  begin
    376     FormsCreated := true;
     377    FormsCreated := True;
    377378    DpiApplication.CreateForm(TNoTermDlg, NoTermDlg);
    378379  end;
     
    380381end;
    381382
    382 procedure TNoTermDlg.FormKeyDown(Sender: TObject; var Key: word;
     383procedure TNoTermDlg.FormKeyDown(Sender: TObject; var Key: Word;
    383384  Shift: TShiftState);
    384385begin
Note: See TracChangeset for help on using the changeset viewer.