Ignore:
Timestamp:
Nov 30, 2023, 10:16:14 PM (12 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/LocalPlayer/NatStat.pas

    r361 r465  
    55
    66uses
    7   UDpiControls, Protocol, ClientTools, Term, ScreenTools, BaseWin,
    8 
    9   LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms,
    10   ButtonB, ButtonC, Menus, EOTButton;
     7  UDpiControls, Protocol, ClientTools, ScreenTools, BaseWin, LCLIntf, LCLType, SysUtils,
     8  Classes, Graphics, Controls, Forms, ButtonB, ButtonC, Menus, EOTButton;
    119
    1210type
     
    2725    procedure ToggleBtnClick(Sender: TObject);
    2826    procedure PlayerClick(Sender: TObject);
    29     procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
     27    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    3028    procedure FormDestroy(Sender: TObject);
    3129    procedure ScrollUpBtnClick(Sender: TObject);
    3230    procedure ScrollDownBtnClick(Sender: TObject);
    3331    procedure TellAIBtnClick(Sender: TObject);
    34 
    3532  public
    3633    procedure CheckAge;
    37     procedure ShowNewContent(NewMode: integer; p: integer = -1);
     34    procedure ShowNewContent(NewMode: TWindowMode; P: Integer = -1);
    3835    procedure EcoChange;
    39 
    4036  protected
    4137    procedure OffscreenPaint; override;
    42 
    4338  private
    44     pView, AgePrepared, LinesDown: integer;
    45     SelfReport, CurrentReport: PEnemyReport;
    46     ShowContact, ContactEnabled: boolean;
    47     Back, Template: TDpiBitmap;
     39    pView: Integer;
     40    AgePrepared: Integer;
     41    LinesDown: Integer;
     42    SelfReport: PEnemyReport;
     43    CurrentReport: PEnemyReport;
     44    ShowContact: Boolean;
     45    ContactEnabled: Boolean;
     46    Back: TDpiBitmap;
     47    Template: TDpiBitmap;
    4848    ReportText: TStringList;
    4949    procedure GenerateReportText;
    5050  end;
    5151
    52 var
    53   NatStatDlg: TNatStatDlg;
    5452
    5553implementation
     
    5856
    5957uses
    60   Messg, Tribes, Directories;
     58  Term, Messg, Tribes, Directories;
    6159
    6260const
     
    109107  if MainTexture.Age <> AgePrepared then begin
    110108    AgePrepared := MainTexture.Age;
    111     DpiBitCanvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight,
     109    DpiBitBltCanvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight,
    112110      MainTexture.Image.Canvas, (MainTexture.Width - ClientWidth) div 2,
    113111      (MainTexture.Height - ClientHeight) div 2);
     
    118116procedure TNatStatDlg.FormShow(Sender: TObject);
    119117begin
    120   if pView = me then
     118  if pView = Me then
    121119  begin
    122120    SelfReport.TurnOfCivilReport := MyRO.Turn;
    123121    SelfReport.TurnOfMilReport := MyRO.Turn;
    124     move(MyRO.Treaty, SelfReport.Treaty, SizeOf(SelfReport.Treaty));
     122    Move(MyRO.Treaty, SelfReport.Treaty, SizeOf(SelfReport.Treaty));
    125123    SelfReport.Government := MyRO.Government;
    126124    SelfReport.Money := MyRO.Money;
    127     CurrentReport := pointer(SelfReport);
     125    CurrentReport := Pointer(SelfReport);
    128126  end
    129127  else
    130     CurrentReport := pointer(MyRO.EnemyReport[pView]);
     128    CurrentReport := Pointer(MyRO.EnemyReport[pView]);
    131129  if CurrentReport.TurnOfCivilReport >= 0 then
    132130    GenerateReportText;
    133   ShowContact := (pView <> me) and (not supervising or (me <> 0));
    134   ContactEnabled := ShowContact and not supervising and
     131  ShowContact := (pView <> Me) and (not Supervising or (Me <> 0));
     132  ContactEnabled := ShowContact and not Supervising and
    135133    (1 shl pView and MyRO.Alive <> 0);
    136134  ContactBtn.Visible := ContactEnabled and (MyRO.Happened and phGameEnd = 0) and
     
    150148end;
    151149
    152 procedure TNatStatDlg.ShowNewContent(NewMode, p: integer);
    153 begin
    154   if p < 0 then
     150procedure TNatStatDlg.ShowNewContent(NewMode: TWindowMode; P: Integer);
     151begin
     152  if P < 0 then
    155153    if ClientMode >= scContact then
    156       pView := DipMem[me].pContact
     154      pView := DipMem[Me].pContact
    157155    else
    158156    begin
     
    160158      while (pView < nPl) and ((MyRO.Treaty[pView] < trNone) or
    161159        (1 shl pView and MyRO.Alive = 0)) do
    162         inc(pView);
     160        Inc(pView);
    163161      if pView >= nPl then
    164         pView := me;
     162        pView := Me;
    165163    end
    166164  else
    167     pView := p;
     165    pView := P;
    168166  inherited ShowNewContent(NewMode);
    169167end;
     
    178176  List: ^TChart;
    179177
    180   function StatText(no: integer): string;
     178  function StatText(no: Integer): string;
    181179  var
    182     i: integer;
     180    I: Integer;
    183181  begin
    184182    if (CurrentReport.TurnOfCivilReport >= 0) and
    185       (Server(sGetChart + no shl 4, me, pView, List^) >= rExecuted) then
     183      (Server(sGetChart + no shl 4, Me, pView, List^) >= rExecuted) then
    186184    begin
    187       i := List[CurrentReport.TurnOfCivilReport];
     185      I := List[CurrentReport.TurnOfCivilReport];
    188186      case no of
    189187        stPop:
    190           result := Format(Phrases.Lookup('FRSTATPOP'), [i]);
     188          Result := Format(Phrases.Lookup('FRSTATPOP'), [I]);
    191189        stTerritory:
    192           result := Format(Phrases.Lookup('FRSTATTER'), [i]);
     190          Result := Format(Phrases.Lookup('FRSTATTER'), [I]);
    193191        stScience:
    194           result := Format(Phrases.Lookup('FRSTATTECH'), [i div nAdv]);
     192          Result := Format(Phrases.Lookup('FRSTATTECH'), [I div nAdv]);
    195193        stExplore:
    196           result := Format(Phrases.Lookup('FRSTATEXP'),
    197             [i * 100 div (G.lx * G.ly)]);
     194          Result := Format(Phrases.Lookup('FRSTATEXP'),
     195            [I * 100 div (G.lx * G.ly)]);
    198196      end;
    199     end
     197    end;
    200198  end;
    201199
    202200var
    203   p1, Treaty: integer;
    204   s: string;
    205   HasContact, ExtinctPart: boolean;
     201  p1, Treaty: Integer;
     202  S: string;
     203  HasContact, ExtinctPart: Boolean;
    206204begin
    207205  GetMem(List, 4 * (MyRO.Turn + 2));
     
    212210    (1 shl pView and MyRO.Alive <> 0) then
    213211  begin
    214     s := Format(Phrases.Lookup('FROLDCIVILREP'),
     212    S := Format(Phrases.Lookup('FROLDCIVILREP'),
    215213      [TurnToString(CurrentReport.TurnOfCivilReport)]);
    216     ReportText.Add('C' + s);
     214    ReportText.Add('C' + S);
    217215    ReportText.Add('');
    218216  end;
     
    227225  ReportText.Add('S' + StatText(stScience));
    228226  ReportText.Add('E' + StatText(stExplore));
    229   HasContact := false;
     227  HasContact := False;
    230228  for p1 := 0 to nPl - 1 do
    231     if (p1 <> me) and (CurrentReport.Treaty[p1] > trNoContact) then
    232       HasContact := true;
     229    if (p1 <> Me) and (CurrentReport.Treaty[p1] > trNoContact) then
     230      HasContact := True;
    233231  if HasContact then
    234232  begin
    235233    ReportText.Add('');
    236234    ReportText.Add(' ' + Phrases.Lookup('FRRELATIONS'));
    237     for ExtinctPart := false to true do
     235    for ExtinctPart := False to True do
    238236      for Treaty := trAlliance downto trNone do
    239237        for p1 := 0 to nPl - 1 do
    240           if (p1 <> me) and (CurrentReport.Treaty[p1] = Treaty) and
     238          if (p1 <> Me) and (CurrentReport.Treaty[p1] = Treaty) and
    241239            ((1 shl p1 and MyRO.Alive = 0) = ExtinctPart) then
    242240          begin
    243             s := Tribe[p1].TString(Phrases.Lookup('HAVETREATY', Treaty));
     241            S := Tribe[p1].TString(Phrases.Lookup('HAVETREATY', Treaty));
    244242            if ExtinctPart then
    245               s := '(' + s + ')';
    246             ReportText.Add(char(48 + Treaty) + s);
     243              S := '(' + S + ')';
     244            ReportText.Add(char(48 + Treaty) + S);
    247245          end;
    248246  end;
     
    254252procedure TNatStatDlg.OffscreenPaint;
    255253var
    256   i, y: integer;
    257   s: string;
    258   ps: pchar;
    259   Extinct: boolean;
    260 
     254  I, Y: Integer;
     255  S: string;
     256  ps: PChar;
     257  Extinct: Boolean;
    261258begin
    262259  inherited;
     
    264261  Extinct := 1 shl pView and MyRO.Alive = 0;
    265262
    266   DpiBitCanvas(offscreen.Canvas, 0, 0, ClientWidth, ClientHeight,
     263  DpiBitBltCanvas(Offscreen.Canvas, 0, 0, ClientWidth, ClientHeight,
    267264    Back.Canvas, 0, 0);
    268265
    269   offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
    270   RisedTextout(offscreen.Canvas,
     266  Offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
     267  RisedTextout(Offscreen.Canvas,
    271268    40 { (ClientWidth-BiColorTextWidth(offscreen.canvas,caption)) div 2 } ,
    272269    7, Caption);
    273270
    274   offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
    275 
    276   with offscreen do
     271  Offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
     272
     273  with Offscreen do
    277274  begin
    278275    // show leader picture
     
    280277    if Assigned(Tribe[pView].faceHGr) then
    281278    begin
    282       Dump(offscreen, Tribe[pView].faceHGr, 18, yIcon - 4, 64, 48,
     279      Dump(Offscreen, Tribe[pView].faceHGr, 18, yIcon - 4, 64, 48,
    283280        1 + Tribe[pView].facepix mod 10 * 65,
    284281        1 + Tribe[pView].facepix div 10 * 49);
    285       frame(offscreen.Canvas, 18 - 1, yIcon - 4 - 1, 18 + 64, yIcon - 4 + 48,
     282      Frame(Offscreen.Canvas, 18 - 1, yIcon - 4 - 1, 18 + 64, yIcon - 4 + 48,
    286283        $000000, $000000);
    287284    end;
    288285
    289     if (pView = me) or not Extinct then
     286    if (pView = Me) or not Extinct then
    290287      LoweredTextOut(Canvas, -1, MainTexture, xAttrib, yAttrib,
    291288        Phrases.Lookup('GOVERNMENT', CurrentReport.Government) +
    292289        Phrases.Lookup('FRAND'));
    293     if pView = me then
     290    if pView = Me then
    294291    begin
    295292      LoweredTextOut(Canvas, -1, MainTexture, xAttrib, yAttrib + 19,
     
    305302          Phrases.Lookup('FREXTINCT'));
    306303        LoweredTextOut(Canvas, -1, MainTexture, xAttrib, yAttrib + 28,
    307           TurnToString(CurrentReport.TurnOfCivilReport))
     304          TurnToString(CurrentReport.TurnOfCivilReport));
    308305      end
    309306      else
     
    318315      if MyRO.Treaty[pView] = trNoContact then
    319316      begin
    320         s := Phrases.Lookup('FRNOCONTACT');
     317        S := Phrases.Lookup('FRNOCONTACT');
    321318        LoweredTextOut(Canvas, -1, MainTexture,
    322           (ClientWidth - BiColorTextWidth(Canvas, s)) div 2, yRelation + 9, s)
     319          (ClientWidth - BiColorTextWidth(Canvas, S)) div 2, yRelation + 9, S);
    323320      end
    324321      else if ShowContact then
     
    344341        FrameImage(Canvas, BigImp, xIcon, yIcon, xSizeBig, ySizeBig, 0, 200)
    345342        { else if CurrentReport.Government=gAnarchy then
    346           FrameImage(canvas,BigImp,xIcon,yIcon,xSizeBig,ySizeBig,112,400,
     343          FrameImage(Canvas,BigImp,xIcon,yIcon,xSizeBig,ySizeBig,112,400,
    347344          ContactEnabled and (MyRO.Happened and phGameEnd=0) and (ClientMode<scContact))
    348345          else
    349           FrameImage(canvas,BigImp,xIcon,yIcon,xSizeBig,ySizeBig,
     346          FrameImage(Canvas,BigImp,xIcon,yIcon,xSizeBig,ySizeBig,
    350347          56*(CurrentReport.Government-1),40,
    351348          ContactEnabled and (MyRO.Happened and phGameEnd=0) and (ClientMode<scContact)) };
     
    365362      end;
    366363
    367       y := 0;
    368       for i := 0 to ReportText.Count - 1 do
    369       begin
    370         if (i >= LinesDown) and (i < LinesDown + ReportLines) then
     364      Y := 0;
     365      for I := 0 to ReportText.Count - 1 do
     366      begin
     367        if (I >= LinesDown) and (I < LinesDown + ReportLines) then
    371368        begin
    372           s := ReportText[i];
    373           if s <> '' then
     369          S := ReportText[I];
     370          if S <> '' then
    374371          begin
    375372            // LineType:=s[1];
    376             delete(s, 1, 1);
     373            Delete(S, 1, 1);
    377374            BiColorTextOut(Canvas, Colors.Canvas.Pixels[clkMisc, cliPaperText],
    378               $7F007F, xReport + 8, yReport + LineSpacing * y, s);
     375              $7F007F, xReport + 8, yReport + LineSpacing * Y, S);
    379376          end;
    380           inc(y);
    381         end
     377          Inc(Y);
     378        end;
    382379      end;
    383380    end
    384381    else
    385382    begin
    386       s := Phrases.Lookup('FRNOCIVILREP');
    387       RisedTextout(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s)) div 2,
    388         yReport + hReport div 2 - 10, s);
     383      S := Phrases.Lookup('FRNOCIVILREP');
     384      RisedTextout(Canvas, (ClientWidth - BiColorTextWidth(Canvas, S)) div 2,
     385        yReport + hReport div 2 - 10, S);
    389386    end;
    390387
    391388    if soTellAI in OptionChecked then begin
    392       Server(sGetAIInfo, me, pView, ps);
     389      Server(sGetAIInfo, Me, pView, ps);
    393390      LoweredTextOut(Canvas, -1, MainTexture, 42, 445, ps);
    394391    end else
     
    396393        Phrases2.Lookup('MENU_TELLAI'));
    397394  end;
    398   ContactBtn.SetBack(offscreen.Canvas, ContactBtn.Left, ContactBtn.Top);
     395
     396  ContactBtn.SetBack(Offscreen.Canvas, ContactBtn.Left, ContactBtn.Top);
    399397
    400398  MarkUsedOffscreen(ClientWidth, ClientHeight);
    401 end; { OffscreenPaint }
     399end;
    402400
    403401procedure TNatStatDlg.CloseBtnClick(Sender: TObject);
    404402begin
    405   Close
     403  Close;
    406404end;
    407405
    408406procedure TNatStatDlg.DialogBtnClick(Sender: TObject);
    409407var
    410   ContactResult: integer;
     408  ContactResult: Integer;
    411409begin
    412410  ContactResult := MainScreen.DipCall(scContact + pView shl 4);
     
    416414      SoundMessage(Phrases.Lookup('FRCOLDWAR'), 'MSG_DEFAULT')
    417415    else if MyRO.Government = gAnarchy then
    418       SoundMessage(Tribe[me].TPhrase('FRMYANARCHY'), 'MSG_DEFAULT')
     416      SoundMessage(Tribe[Me].TPhrase('FRMYANARCHY'), 'MSG_DEFAULT')
    419417    else if ContactResult = eAnarchy then
    420418      if MyRO.Treaty[pView] >= trPeace then
    421419      begin
    422420        if MainScreen.ContactRefused(pView, 'FRANARCHY') then
    423           SmartUpdateContent
     421          SmartUpdateContent;
    424422      end
    425423      else
     
    427425  end
    428426  else
    429     Close
     427    Close;
    430428end;
    431429
    432430procedure TNatStatDlg.ToggleBtnClick(Sender: TObject);
    433431var
    434   p1, StartCount: integer;
    435   m: TDpiMenuItem;
    436   ExtinctPart: boolean;
     432  p1, StartCount: Integer;
     433  M: TDpiMenuItem;
     434  ExtinctPart: Boolean;
    437435begin
    438436  EmptyMenu(Popup.Items);
    439437
    440438  // own nation
    441   if G.Difficulty[me] <> 0 then
    442   begin
    443     m := TDpiMenuItem.Create(Popup);
    444     m.RadioItem := true;
    445     m.Caption := Tribe[me].TPhrase('TITLE_NATION');
    446     m.Tag := me;
    447     m.OnClick := PlayerClick;
    448     if me = pView then
    449       m.Checked := true;
    450     Popup.Items.Add(m);
     439  if G.Difficulty[Me] <> 0 then
     440  begin
     441    M := TDpiMenuItem.Create(Popup);
     442    M.RadioItem := True;
     443    M.Caption := Tribe[Me].TPhrase('TITLE_NATION');
     444    M.Tag := Me;
     445    M.OnClick := PlayerClick;
     446    if Me = pView then
     447      M.Checked := True;
     448    Popup.Items.Add(M);
    451449  end;
    452450
    453451  // foreign nations
    454   for ExtinctPart := false to true do
     452  for ExtinctPart := False to True do
    455453  begin
    456454    StartCount := Popup.Items.Count;
     
    460458        (1 shl p1 and MyRO.Alive <> 0) and (MyRO.Treaty[p1] >= trNone) then
    461459      begin
    462         m := TDpiMenuItem.Create(Popup);
    463         m.RadioItem := true;
    464         m.Caption := Tribe[p1].TPhrase('TITLE_NATION');
     460        M := TDpiMenuItem.Create(Popup);
     461        M.RadioItem := True;
     462        M.Caption := Tribe[p1].TPhrase('TITLE_NATION');
    465463        if ExtinctPart then
    466           m.Caption := '(' + m.Caption + ')';
    467         m.Tag := p1;
    468         m.OnClick := PlayerClick;
     464          M.Caption := '(' + M.Caption + ')';
     465        M.Tag := p1;
     466        M.OnClick := PlayerClick;
    469467        if p1 = pView then
    470           m.Checked := true;
    471         Popup.Items.Add(m);
     468          M.Checked := True;
     469        Popup.Items.Add(M);
    472470      end;
    473471    if (StartCount > 0) and (Popup.Items.Count > StartCount) then
    474472    begin // seperator
    475       m := TDpiMenuItem.Create(Popup);
    476       m.Caption := '-';
    477       Popup.Items.Insert(StartCount, m);
     473      M := TDpiMenuItem.Create(Popup);
     474      M.Caption := '-';
     475      Popup.Items.Insert(StartCount, M);
    478476    end;
    479477  end;
     
    482480end;
    483481
    484 procedure TNatStatDlg.FormKeyDown(Sender: TObject; var Key: word;
     482procedure TNatStatDlg.FormKeyDown(Sender: TObject; var Key: Word;
    485483  Shift: TShiftState);
    486484var
    487   i: integer;
     485  I: Integer;
    488486begin
    489487  if Key = VK_F9 then // my key
    490488  begin // toggle nation
    491     i := 0;
     489    I := 0;
    492490    repeat
    493491      pView := (pView + 1) mod nPl;
    494       inc(i);
    495     until (i >= nPl) or (1 shl pView and MyRO.Alive <> 0) and
     492      Inc(I);
     493    until (I >= nPl) or (1 shl pView and MyRO.Alive <> 0) and
    496494      (MyRO.Treaty[pView] >= trNone);
    497     if i >= nPl then
    498       pView := me;
     495    if I >= nPl then
     496      pView := Me;
    499497    Tag := pView;
    500498    PlayerClick(self); // no, this is not nice
    501499  end
    502500  else
    503     inherited
     501    inherited;
    504502end;
    505503
    506504procedure TNatStatDlg.EcoChange;
    507505begin
    508   if Visible and (pView = me) then
     506  if Visible and (pView = Me) then
    509507  begin
    510508    SelfReport.Government := MyRO.Government;
    511509    SelfReport.Money := MyRO.Money;
    512     SmartUpdateContent
    513   end
     510    SmartUpdateContent;
     511  end;
    514512end;
    515513
     
    518516  if LinesDown > 0 then
    519517  begin
    520     dec(LinesDown);
     518    Dec(LinesDown);
    521519    SmartUpdateContent;
    522   end
     520  end;
    523521end;
    524522
     
    527525  if LinesDown + ReportLines < ReportText.Count then
    528526  begin
    529     inc(LinesDown);
     527    Inc(LinesDown);
    530528    SmartUpdateContent;
    531   end
     529  end;
    532530end;
    533531
     
    540538  else
    541539    TellAIBtn.ButtonIndex := 2;
    542   SmartUpdateContent
     540  SmartUpdateContent;
    543541end;
    544542
Note: See TracChangeset for help on using the changeset viewer.