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/Enhance.pas

    r361 r465  
    55
    66uses
    7   UDpiControls, ScreenTools, BaseWin, Protocol, ClientTools, Term, LCLIntf, LCLType,
    8 
    9   SysUtils, Classes, Graphics, Controls, Forms, IsoEngine,
    10   ButtonB, ButtonC, Menus;
     7  UDpiControls, ScreenTools, BaseWin, Protocol, ClientTools, LCLIntf, LCLType, SysUtils,
     8  Classes, Graphics, Controls, Forms, IsoEngine, ButtonB, ButtonC, Menus;
    119
    1210type
     
    3937    NoMap: TIsoMap;
    4038  public
    41     procedure ShowNewContent(NewMode: integer; TerrType: integer = -1);
     39    procedure ShowNewContent(NewMode: TWindowMode; TerrType: Integer = -1);
    4240  protected
    43     Page: integer;
     41    Page: Integer;
    4442    procedure OffscreenPaint; override;
    4543  end;
    4644
    47 var
    48   EnhanceDlg: TEnhanceDlg;
    49 
    5045
    5146implementation
    5247
    5348uses
    54   Help, UKeyBindings;
     49  Help, KeyBindings, Term;
    5550
    5651{$R *.lfm}
     
    5853procedure TEnhanceDlg.FormCreate(Sender: TObject);
    5954var
    60   TerrType: integer;
    61   m: TDpiMenuItem;
     55  TerrType: Integer;
     56  M: TDpiMenuItem;
    6257begin
    6358  inherited;
     
    7368    if TerrType <> fJungle then
    7469    begin
    75       m := TDpiMenuItem.Create(Popup);
    76       m.RadioItem := true;
     70      M := TDpiMenuItem.Create(Popup);
     71      M.RadioItem := True;
    7772      if TerrType = fGrass then
    78         m.Caption := Format(Phrases.Lookup('TWOTERRAINS'),
     73        M.Caption := Format(Phrases.Lookup('TWOTERRAINS'),
    7974          [Phrases.Lookup('TERRAIN', fGrass), Phrases.Lookup('TERRAIN',
    8075          fGrass + 12)])
    8176      else if TerrType = fForest then
    82         m.Caption := Format(Phrases.Lookup('TWOTERRAINS'),
     77        M.Caption := Format(Phrases.Lookup('TWOTERRAINS'),
    8378          [Phrases.Lookup('TERRAIN', fForest), Phrases.Lookup('TERRAIN',
    8479          fJungle)])
    8580      else
    86         m.Caption := Phrases.Lookup('TERRAIN', TerrType);
    87       m.Tag := TerrType;
    88       m.OnClick := TerrClick;
    89       Popup.Items.Add(m);
     81        M.Caption := Phrases.Lookup('TERRAIN', TerrType);
     82      M.Tag := TerrType;
     83      M.OnClick := TerrClick;
     84      Popup.Items.Add(M);
    9085    end;
    9186end;
     
    9893procedure TEnhanceDlg.FormPaint(Sender: TObject);
    9994var
    100   i: integer;
     95  I: Integer;
    10196begin
    10297  inherited;
     
    105100  BtnFrame(Canvas, Rect(job3.Left, job3.Top, job9.Left + job9.Width,
    106101    job3.Top + job3.Height), MainTexture);
    107   for i := 0 to ControlCount - 1 do
    108     if Controls[i] is TButtonC then
    109       DpiBitCanvas(Canvas, Controls[i].Left + 2, Controls[i].Top - 11, 8, 8,
    110         HGrSystem.Data.Canvas, 121 + Controls[i].Tag mod 7 * 9,
    111         1 + Controls[i].Tag div 7 * 9);
     102  for I := 0 to ControlCount - 1 do
     103    if Controls[I] is TButtonC then
     104      DpiBitBltCanvas(Canvas, Controls[I].Left + 2, Controls[I].Top - 11, 8, 8,
     105        HGrSystem.Data.Canvas, 121 + Controls[I].Tag mod 7 * 9,
     106        1 + Controls[I].Tag div 7 * 9);
    112107end;
    113108
     
    117112end;
    118113
    119 procedure TEnhanceDlg.ShowNewContent(NewMode, TerrType: integer);
     114procedure TEnhanceDlg.ShowNewContent(NewMode: TWindowMode; TerrType: Integer);
    120115begin
    121116  if (TerrType < fGrass) or (TerrType > fMountains) then
     
    128123procedure TEnhanceDlg.OffscreenPaint;
    129124var
    130   i, stage, TerrType, TileImp, x, EndStage, Cost, LastJob: integer;
    131   s: string;
    132   Done: Set of jNone .. jTrans;
    133   TypeChanged: boolean;
     125  I, stage, TerrType, TileImp, X, EndStage, Cost, LastJob: Integer;
     126  S: string;
     127  Done: set of jNone .. jTrans;
     128  TypeChanged: Boolean;
    134129begin
    135130  OffscreenUser := self;
    136   offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     131  Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    137132  FillOffscreen(0, 0, InnerWidth, InnerHeight);
    138133
    139134  EndStage := 0;
    140135  while (EndStage < 5) and (MyData.EnhancementJobs[Page, EndStage] <> jNone) do
    141     inc(EndStage);
     136    Inc(EndStage);
    142137  with NoMap do
    143     x := InnerWidth div 2 - xxt - (xxt + 3) * EndStage;
     138    X := InnerWidth div 2 - xxt - (xxt + 3) * EndStage;
    144139
    145140  TerrType := Page;
     
    151146    if stage > 0 then
    152147    begin
    153       Sprite(offscreen, HGrSystem, x - 10, 66, 14, 14, 80, 1);
     148      Sprite(Offscreen, HGrSystem, X - 10, 66, 14, 14, 80, 1);
    154149      case MyData.EnhancementJobs[Page, stage - 1] of
    155150        jRoad:
    156151          begin
    157             inc(Cost, Terrain[TerrType].MoveCost * RoadWork);
     152            Inc(Cost, Terrain[TerrType].MoveCost * RoadWork);
    158153            TileImp := TileImp or fRoad;
    159154          end;
    160155        jRR:
    161156          begin
    162             inc(Cost, Terrain[TerrType].MoveCost * RRWork);
     157            Inc(Cost, Terrain[TerrType].MoveCost * RRWork);
    163158            TileImp := TileImp or fRR;
    164159          end;
    165160        jIrr:
    166161          begin
    167             inc(Cost, Terrain[TerrType].IrrClearWork);
     162            Inc(Cost, Terrain[TerrType].IrrClearWork);
    168163            TileImp := TileImp and not fTerImp or tiIrrigation;
    169164          end;
    170165        jFarm:
    171166          begin
    172             inc(Cost, Terrain[TerrType].IrrClearWork * FarmWork);
     167            Inc(Cost, Terrain[TerrType].IrrClearWork * FarmWork);
    173168            TileImp := TileImp and not fTerImp or tiFarm;
    174169          end;
    175170        jMine:
    176171          begin
    177             inc(Cost, Terrain[TerrType].MineAfforestWork);
     172            Inc(Cost, Terrain[TerrType].MineAfforestWork);
    178173            TileImp := TileImp and not fTerImp or tiMine;
    179174          end;
    180175        jClear:
    181176          begin
    182             inc(Cost, Terrain[TerrType].IrrClearWork);
     177            Inc(Cost, Terrain[TerrType].IrrClearWork);
    183178            TerrType := Terrain[TerrType].ClearTerrain;
    184179          end;
    185180        jAfforest:
    186181          begin
    187             inc(Cost, Terrain[TerrType].MineAfforestWork);
     182            Inc(Cost, Terrain[TerrType].MineAfforestWork);
    188183            TerrType := Terrain[TerrType].AfforestTerrain;
    189184          end;
    190185        jTrans:
    191186          begin
    192             inc(Cost, Terrain[TerrType].TransWork);
     187            Inc(Cost, Terrain[TerrType].TransWork);
    193188            TerrType := Terrain[TerrType].TransTerrain;
    194189          end;
    195190      end;
    196       include(Done, MyData.EnhancementJobs[Page, stage - 1]);
     191      Include(Done, MyData.EnhancementJobs[Page, stage - 1]);
    197192    end;
    198193
    199194    with NoMap do begin
    200195      if TerrType < fForest then
    201         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     196        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    202197          1 + TerrType * (xxt * 2 + 1), 1 + yyt)
    203198      else
    204199      begin
    205         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     200        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    206201          1 + 2 * (xxt * 2 + 1), 1 + yyt + 2 * (yyt * 3 + 1));
    207         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     202        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    208203          1 + 7 * (xxt * 2 + 1), 1 + yyt + 2 * (2 + TerrType - fForest) *
    209204          (yyt * 3 + 1));
    210205      end;
    211206      if TileImp and fTerImp = tiFarm then
    212         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     207        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    213208          1 + (xxt * 2 + 1), 1 + yyt + 12 * (yyt * 3 + 1))
    214209      else if TileImp and fTerImp = tiIrrigation then
    215         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2, 1,
     210        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 1,
    216211          1 + yyt + 12 * (yyt * 3 + 1));
    217212      if TileImp and fRR <> 0 then
    218213      begin
    219         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     214        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    220215          1 + 6 * (xxt * 2 + 1), 1 + yyt + 10 * (yyt * 3 + 1));
    221         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     216        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    222217          1 + 2 * (xxt * 2 + 1), 1 + yyt + 10 * (yyt * 3 + 1));
    223218      end
    224219      else if TileImp and fRoad <> 0 then
    225220      begin
    226         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     221        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    227222          1 + 6 * (xxt * 2 + 1), 1 + yyt + 9 * (yyt * 3 + 1));
    228         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     223        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    229224          1 + 2 * (xxt * 2 + 1), 1 + yyt + 9 * (yyt * 3 + 1));
    230225      end;
    231226      if TileImp and fTerImp = tiMine then
    232         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     227        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    233228          1 + 2 * (xxt * 2 + 1), 1 + yyt + 12 * (yyt * 3 + 1));
    234       inc(x, xxt * 2 + 6);
    235     end;
    236   end;
    237 
    238   for i := 0 to Popup.Items.Count - 1 do
    239     if Popup.Items[i].Tag = Page then
    240       s := Popup.Items[i].Caption;
     229      Inc(X, xxt * 2 + 6);
     230    end;
     231  end;
     232
     233  for I := 0 to Popup.Items.Count - 1 do
     234    if Popup.Items[I].Tag = Page then
     235      S := Popup.Items[I].Caption;
    241236  if Cost > 0 then
    242     s := Format(Phrases.Lookup('ENHANCE'), [s, MovementToString(Cost)]);
    243   LoweredTextOut(offscreen.Canvas, -1, MainTexture,
    244     (InnerWidth - BiColorTextWidth(offscreen.Canvas, s)) div 2, 12, s);
     237    S := Format(Phrases.Lookup('ENHANCE'), [S, MovementToString(Cost)]);
     238  LoweredTextOut(Offscreen.Canvas, -1, MainTexture,
     239    (InnerWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2, 12, S);
    245240
    246241  if EndStage > 0 then
     
    291286    (Terrain[TerrType].MineEff > 0);
    292287  job3.Visible := not TypeChanged and (Terrain[TerrType].ClearTerrain >= 0) and
    293     ((TerrType <> fDesert) or (MyRO.Wonder[woGardens].EffectiveOwner = me)) or
     288    ((TerrType <> fDesert) or (MyRO.Wonder[woGardens].EffectiveOwner = Me)) or
    294289    (LastJob = jClear);
    295290  job6.Visible := not TypeChanged and (Terrain[TerrType].AfforestTerrain >= 0)
     
    299294
    300295  MarkUsedOffscreen(InnerWidth, InnerHeight);
    301 end; { OffscreenPaint }
     296end;
    302297
    303298procedure TEnhanceDlg.CloseBtnClick(Sender: TObject);
     
    308303procedure TEnhanceDlg.ToggleBtnClick(Sender: TObject);
    309304var
    310   i: integer;
    311 begin
    312   for i := 0 to Popup.Items.Count - 1 do
    313     Popup.Items[i].Checked := Popup.Items[i].Tag = Page;
     305  I: Integer;
     306begin
     307  for I := 0 to Popup.Items.Count - 1 do
     308    Popup.Items[I].Checked := Popup.Items[I].Tag = Page;
    314309  Popup.Popup(Left + ToggleBtn.Left, Top + ToggleBtn.Top + ToggleBtn.Height);
    315310end;
     
    323318procedure TEnhanceDlg.JobClick(Sender: TObject);
    324319var
    325   stage, NewJob: integer;
     320  Stage, NewJob: Integer;
    326321  Done: Set of jNone .. jTrans;
    327322
    328   procedure RemoveJob(j: integer);
     323  procedure RemoveJob(J: Integer);
    329324  begin // remove job
    330     stage := 0;
    331     while (stage < 5) and (MyData.EnhancementJobs[Page, stage] <> jNone) do
    332     begin
    333       if (MyData.EnhancementJobs[Page, stage] = j) or (j = jRoad) and
    334         (MyData.EnhancementJobs[Page, stage] = jRR) or (j = jIrr) and
    335         (MyData.EnhancementJobs[Page, stage] = jFarm) then
     325    Stage := 0;
     326    while (Stage < 5) and (MyData.EnhancementJobs[Page, Stage] <> jNone) do
     327    begin
     328      if (MyData.EnhancementJobs[Page, Stage] = J) or (J = jRoad) and
     329        (MyData.EnhancementJobs[Page, Stage] = jRR) or (J = jIrr) and
     330        (MyData.EnhancementJobs[Page, Stage] = jFarm) then
    336331      begin
    337         if stage < 4 then
    338           move(MyData.EnhancementJobs[Page, stage + 1],
    339             MyData.EnhancementJobs[Page, stage], 4 - stage);
     332        if Stage < 4 then
     333          Move(MyData.EnhancementJobs[Page, Stage + 1],
     334            MyData.EnhancementJobs[Page, Stage], 4 - Stage);
    340335        MyData.EnhancementJobs[Page, 4] := jNone;
    341336      end
    342337      else
    343         inc(stage);
     338        Inc(Stage);
    344339    end;
    345340  end;
     
    348343  NewJob := TButtonC(Sender).Tag;
    349344  Done := [];
    350   stage := 0;
    351   while (stage < 5) and (MyData.EnhancementJobs[Page, stage] <> jNone) do
     345  Stage := 0;
     346  while (Stage < 5) and (MyData.EnhancementJobs[Page, Stage] <> jNone) do
    352347  begin
    353     include(Done, MyData.EnhancementJobs[Page, stage]);
    354     inc(stage);
     348    Include(Done, MyData.EnhancementJobs[Page, Stage]);
     349    Inc(Stage);
    355350  end;
    356351  if NewJob in Done then
     
    364359    if (NewJob = jRR) and not(jRoad in Done) then
    365360    begin
    366       MyData.EnhancementJobs[Page, stage] := jRoad;
    367       inc(stage);
     361      MyData.EnhancementJobs[Page, Stage] := jRoad;
     362      Inc(Stage);
    368363    end;
    369364    if (NewJob = jFarm) and not(jIrr in Done) then
    370365    begin
    371       MyData.EnhancementJobs[Page, stage] := jIrr;
    372       inc(stage);
    373     end;
    374     MyData.EnhancementJobs[Page, stage] := NewJob;
     366      MyData.EnhancementJobs[Page, Stage] := jIrr;
     367      Inc(Stage);
     368    end;
     369    MyData.EnhancementJobs[Page, Stage] := NewJob;
    375370  end;
    376371  SmartUpdateContent;
     
    384379  ShortCut := KeyToShortCut(Key, Shift);
    385380  if BHelp.Test(ShortCut) then
    386     HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkText,
    387       HelpDlg.TextIndex('MACRO'))
     381    MainScreen.HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkText,
     382      MainScreen.HelpDlg.TextIndex('MACRO'))
    388383end;
    389384
Note: See TracChangeset for help on using the changeset viewer.