Ignore:
Timestamp:
May 19, 2022, 10:39:34 PM (2 years ago)
Author:
chronos
Message:
  • Modified: Use first capital letter in identifiers.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LocalPlayer/CityType.pas

    r442 r447  
    1818    procedure FormShow(Sender: TObject);
    1919    procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    20       Shift: TShiftState; x, y: integer);
     20      Shift: TShiftState; X, Y: Integer);
    2121    procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
    22       Shift: TShiftState; x, y: integer);
     22      Shift: TShiftState; X, Y: Integer);
    2323    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    2424    procedure DeleteBtnClick(Sender: TObject);
     
    2828    procedure OffscreenPaint; override;
    2929  private
    30     nPool, dragiix, ctype: integer;
    31     Pooliix: array [0 .. nImp - 1] of integer;
     30    nPool, dragiix, ctype: Integer;
     31    Pooliix: array [0 .. nImp - 1] of Integer;
    3232    listed: Set of 0 .. nImp;
    33     Changed: boolean;
    34     procedure LoadType(NewType: integer);
     33    Changed: Boolean;
     34    procedure LoadType(NewType: Integer);
    3535    procedure SaveType;
    3636  end;
     
    8282procedure TCityTypeDlg.OffscreenPaint;
    8383var
    84   i, iix: integer;
    85   s: string;
     84  I, iix: Integer;
     85  S: string;
    8686begin
    8787  inherited;
    88   offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     88  Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    8989  FillOffscreen(xList - 7, yList, 42 * nListCol + 14, 32 * nListRow);
    9090  FillOffscreen(xPool - 7, yPool, 42 * nPoolCol + 14, 32 * nPoolRow);
     
    9292    yPool - yList - 32 * nListRow);
    9393
    94   Frame(offscreen.Canvas, 0, yList + 32 * nListRow, InnerWidth - 255,
     94  Frame(Offscreen.Canvas, 0, yList + 32 * nListRow, InnerWidth - 255,
    9595    yPool - 23, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    96   Frame(offscreen.Canvas, InnerWidth - 254, yList + 32 * nListRow,
     96  Frame(Offscreen.Canvas, InnerWidth - 254, yList + 32 * nListRow,
    9797    InnerWidth - 89, yPool - 23, MainTexture.ColorBevelLight,
    9898    MainTexture.ColorBevelShade);
    99   Frame(offscreen.Canvas, InnerWidth - 88, yList + 32 * nListRow,
     99  Frame(Offscreen.Canvas, InnerWidth - 88, yList + 32 * nListRow,
    100100    InnerWidth - 1, yPool - 23, MainTexture.ColorBevelLight,
    101101    MainTexture.ColorBevelShade);
    102   Frame(offscreen.Canvas, 0, yPool - 22, InnerWidth - 1, yPool - 1,
     102  Frame(Offscreen.Canvas, 0, yPool - 22, InnerWidth - 1, yPool - 1,
    103103    MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    104   for i := 0 to nCityType - 1 do
    105   begin
    106     RFrame(offscreen.Canvas, xSwitch + i * 42, ySwitch, xSwitch + 39 + i * 42,
     104  for I := 0 to nCityType - 1 do
     105  begin
     106    RFrame(Offscreen.Canvas, xSwitch + I * 42, ySwitch, xSwitch + 39 + I * 42,
    107107      ySwitch + 23, MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    108     if i = ctype then
    109       Frame(offscreen.Canvas, xSwitch + 1 + i * 42, ySwitch + 1,
    110         xSwitch + 38 + i * 42, ySwitch + 22, MainTexture.ColorBevelShade,
     108    if I = ctype then
     109      Frame(Offscreen.Canvas, xSwitch + 1 + I * 42, ySwitch + 1,
     110        xSwitch + 38 + I * 42, ySwitch + 22, MainTexture.ColorBevelShade,
    111111        MainTexture.ColorBevelLight)
    112112    else
    113       Frame(offscreen.Canvas, xSwitch + 1 + i * 42, ySwitch + 1,
    114         xSwitch + 38 + i * 42, ySwitch + 22, MainTexture.ColorBevelLight,
     113      Frame(Offscreen.Canvas, xSwitch + 1 + I * 42, ySwitch + 1,
     114        xSwitch + 38 + I * 42, ySwitch + 22, MainTexture.ColorBevelLight,
    115115        MainTexture.ColorBevelShade);
    116     BitBltCanvas(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,
     116    BitBltCanvas(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,
    120120    Phrases.Lookup('BUILDORDER'));
    121   RisedTextOut(offscreen.Canvas, 8, ySwitch + 26,
     121  RisedTextOut(Offscreen.Canvas, 8, ySwitch + 26,
    122122    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 do
    129   begin
    130     for i := 1 to nListRow - 1 do
    131       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 do
    134     begin
    135       s := IntToStr(i + 1);
     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 do
     129  begin
     130    for I := 1 to nListRow - 1 do
     131      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 do
     134    begin
     135      S := IntToStr(I + 1);
    136136      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 do
    144   begin
    145     RFrame(offscreen.Canvas, xList + 20 - xSizeSmall div 2 + i mod nListCol *
    146       42, yList + 15 - ySizeSmall div 2 + i div nListCol * 32,
    147       xList + 21 + xSizeSmall div 2 + i mod nListCol * 42,
    148       yList + 16 + ySizeSmall div 2 + i div nListCol * 32,
     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 do
     144  begin
     145    RFrame(Offscreen.Canvas, xList + 20 - xSizeSmall div 2 + I mod nListCol *
     146      42, yList + 15 - ySizeSmall div 2 + I div nListCol * 32,
     147      xList + 21 + xSizeSmall div 2 + I mod nListCol * 42,
     148      yList + 16 + ySizeSmall div 2 + I div nListCol * 32,
    149149      MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    150     BitBltCanvas(offscreen.Canvas, xList + 21 - xSizeSmall div 2 +
    151       i mod nListCol * 42, yList + 16 - ySizeSmall div 2 + i div nListCol * 32,
     150    BitBltCanvas(Offscreen.Canvas, xList + 21 - xSizeSmall div 2 +
     151      I mod nListCol * 42, yList + 16 - ySizeSmall div 2 + I div nListCol * 32,
    152152      xSizeSmall, ySizeSmall, SmallImp.Canvas,
    153       MyData.ImpOrder[ctype, i] mod 7 * xSizeSmall,
    154       (MyData.ImpOrder[ctype, i] + SystemIconLines * 7) div 7 *
     153      MyData.ImpOrder[ctype, I] mod 7 * xSizeSmall,
     154      (MyData.ImpOrder[ctype, I] + SystemIconLines * 7) div 7 *
    155155      ySizeSmall);
    156     inc(i);
     156    Inc(I);
    157157  end;
    158158
     
    165165    begin
    166166      Pooliix[nPool] := iix;
    167       RFrame(offscreen.Canvas, xPool + 20 - xSizeSmall div 2 +
     167      RFrame(Offscreen.Canvas, xPool + 20 - xSizeSmall div 2 +
    168168        nPool mod nPoolCol * 42, yPool + 15 - ySizeSmall div 2 +
    169169        nPool div nPoolCol * 32, xPool + 21 + xSizeSmall div 2 +
     
    171171        nPool div nPoolCol * 32, MainTexture.ColorBevelLight,
    172172        MainTexture.ColorBevelShade);
    173       BitBltCanvas(offscreen.Canvas, xPool + 21 - xSizeSmall div 2 +
     173      BitBltCanvas(Offscreen.Canvas, xPool + 21 - xSizeSmall div 2 +
    174174        nPool mod nPoolCol * 42, yPool + 16 - ySizeSmall div 2 +
    175175        nPool div nPoolCol * 32, xSizeSmall, ySizeSmall, SmallImp.Canvas,
    176176        iix mod 7 * xSizeSmall, (iix + SystemIconLines * 7) div 7 *
    177177        ySizeSmall);
    178       inc(nPool);
     178      Inc(nPool);
    179179    end;
    180180  DeleteBtn.Visible := MyData.ImpOrder[ctype, 0] >= 0;
     
    182182  if dragiix >= 0 then
    183183  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);
     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);
    189189  end;
    190190  MarkUsedOffscreen(InnerWidth, InnerHeight);
    191191end;
    192192
    193 procedure TCityTypeDlg.LoadType(NewType: integer);
    194 var
    195   i: integer;
     193procedure TCityTypeDlg.LoadType(NewType: Integer);
     194var
     195  I: Integer;
    196196begin
    197197  ctype := NewType;
    198198  listed := [];
    199   i := 0;
    200   while MyData.ImpOrder[ctype, i] >= 0 do
    201   begin
    202     include(listed, MyData.ImpOrder[ctype, i]);
    203     inc(i);
    204   end;
    205   Changed := false;
     199  I := 0;
     200  while MyData.ImpOrder[ctype, I] >= 0 do
     201  begin
     202    Include(listed, MyData.ImpOrder[ctype, I]);
     203    Inc(I);
     204  end;
     205  Changed := False;
    206206end;
    207207
    208208procedure TCityTypeDlg.SaveType;
    209209var
    210   cix: integer;
     210  cix: Integer;
    211211begin
    212212  if Changed then
     
    215215      if (MyCity[cix].Loc >= 0) and (MyCity[cix].Status and 7 = ctype + 1) then
    216216        AutoBuild(cix, MyData.ImpOrder[ctype]);
    217     Changed := false;
     217    Changed := False;
    218218  end;
    219219end;
     
    232232
    233233procedure 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) and
    242     (x > xList + 2 + i mod nListCol * 42) and
    243     (y > yList + 5 + i div nListCol * 32) and
    244     (x < xList + 3 + 36 + i mod nListCol * 42) and
    245     (y < yList + 6 + 20 + i div nListCol * 32) then
     234  Shift: TShiftState; X, Y: Integer);
     235var
     236  I: Integer;
     237begin
     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) and
     242    (X > xList + 2 + I mod nListCol * 42) and
     243    (Y > yList + 5 + I div nListCol * 32) and
     244    (X < xList + 3 + 36 + I mod nListCol * 42) and
     245    (Y < yList + 6 + 20 + I div nListCol * 32) then
    246246  begin
    247247    if ssShift in Shift then
    248248      HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkImp,
    249         MyData.ImpOrder[ctype, i])
     249        MyData.ImpOrder[ctype, I])
    250250    else
    251251    begin
    252       dragiix := MyData.ImpOrder[ctype, i];
     252      dragiix := MyData.ImpOrder[ctype, I];
    253253      Screen.Cursor := crImpDrag;
    254254      SmartUpdateContent;
    255255    end;
    256     exit;
    257   end;
    258   i := (x - xPool) div 42 + (y - yPool) div 32 * nPoolCol;
    259   if (i < nPool) and (x > xPool + 2 + i mod nPoolCol * 42) and
    260     (y > yPool + 5 + i div nPoolCol * 32) and
    261     (x < xPool + 3 + 36 + i mod nPoolCol * 42) and
    262     (y < yPool + 6 + 20 + i div nPoolCol * 32) then
     256    Exit;
     257  end;
     258  I := (X - xPool) div 42 + (Y - yPool) div 32 * nPoolCol;
     259  if (I < nPool) and (X > xPool + 2 + I mod nPoolCol * 42) and
     260    (Y > yPool + 5 + I div nPoolCol * 32) and
     261    (X < xPool + 3 + 36 + I mod nPoolCol * 42) and
     262    (Y < yPool + 6 + 20 + I div nPoolCol * 32) then
    263263  begin
    264264    if ssShift in Shift then
    265       HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkImp, Pooliix[i])
     265      HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkImp, Pooliix[I])
    266266    else
    267267    begin
    268       dragiix := Pooliix[i];
     268      dragiix := Pooliix[I];
    269269      Screen.Cursor := crImpDrag;
    270270      SmartUpdateContent;
    271271    end;
    272     exit;
    273   end;
    274   i := (x - xSwitch) div 42;
    275   if (i < nCityType) and (x > xSwitch + 2 + i * 42) and
    276     (x < xSwitch + 3 + 36 + i * 42) and (y >= ySwitch + 2) and (y < ySwitch + 22)
     272    Exit;
     273  end;
     274  I := (X - xSwitch) div 42;
     275  if (I < nCityType) and (X > xSwitch + 2 + I * 42) and
     276    (X < xSwitch + 3 + 36 + I * 42) and (Y >= ySwitch + 2) and (Y < ySwitch + 22)
    277277  then
    278278  begin
    279279    SaveType;
    280     LoadType(i);
     280    LoadType(I);
    281281    SmartUpdateContent;
    282282  end;
     
    284284
    285285procedure TCityTypeDlg.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
    286   Shift: TShiftState; x, y: integer);
    287 
    288   procedure UnList(iix: integer);
     286  Shift: TShiftState; X, Y: Integer);
     287
     288  procedure UnList(iix: Integer);
    289289  var
    290     i: integer;
    291   begin
    292     i := 0;
    293     while (MyData.ImpOrder[ctype, i] >= 0) and
    294       (MyData.ImpOrder[ctype, i] <> iix) do
    295       inc(i);
    296     assert(MyData.ImpOrder[ctype, i] = iix);
    297     move(MyData.ImpOrder[ctype, i + 1], MyData.ImpOrder[ctype, i], nImp - i);
     290    I: Integer;
     291  begin
     292    I := 0;
     293    while (MyData.ImpOrder[ctype, I] >= 0) and
     294      (MyData.ImpOrder[ctype, I] <> iix) do
     295      Inc(I);
     296    Assert(MyData.ImpOrder[ctype, I] = iix);
     297    Move(MyData.ImpOrder[ctype, I + 1], MyData.ImpOrder[ctype, I], nImp - I);
    298298    Exclude(listed, iix);
    299299  end;
    300300
    301301var
    302   i: integer;
    303 begin
    304   x := x - SideFrame;
    305   y := y - WideFrame;
     302  I: Integer;
     303begin
     304  X := X - SideFrame;
     305  Y := Y - WideFrame;
    306306  if dragiix >= 0 then
    307307  begin
    308     if (x >= xList) and (x < xList + nListCol * 42) and (y >= yList) and
    309       (y < yList + nListRow * 32) then
     308    if (X >= xList) and (X < xList + nListCol * 42) and (Y >= yList) and
     309      (Y < yList + nListRow * 32) then
    310310    begin
    311311      if dragiix in listed then
    312312        UnList(dragiix);
    313       i := (x - xList) div 42 + (y - yList) div 32 * nListCol;
    314       while (i > 0) and (MyData.ImpOrder[ctype, i - 1] < 0) do
    315         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;
     313      I := (X - xList) div 42 + (Y - yList) div 32 * nListCol;
     314      while (I > 0) and (MyData.ImpOrder[ctype, I - 1] < 0) do
     315        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;
    321321    end
    322     else if (dragiix in listed) and (x >= xPool) and (x < xPool + nPoolCol * 42)
    323       and (y >= yPool) and (y < yPool + nPoolRow * 32) then
     322    else if (dragiix in listed) and (X >= xPool) and (X < xPool + nPoolCol * 42)
     323      and (Y >= yPool) and (Y < yPool + nPoolRow * 32) then
    324324    begin
    325325      UnList(dragiix);
    326       Changed := true;
     326      Changed := True;
    327327    end;
    328328    dragiix := -1;
     
    340340procedure TCityTypeDlg.DeleteBtnClick(Sender: TObject);
    341341begin
    342   fillchar(MyData.ImpOrder[ctype], sizeof(MyData.ImpOrder[ctype]), Byte(-1));
     342  FillChar(MyData.ImpOrder[ctype], SizeOf(MyData.ImpOrder[ctype]), Byte(-1));
    343343  listed := [];
    344   Changed := true;
     344  Changed := True;
    345345  SmartUpdateContent;
    346346end;
Note: See TracChangeset for help on using the changeset viewer.