Changeset 156 for trunk


Ignore:
Timestamp:
Nov 10, 2018, 8:00:53 PM (6 years ago)
Author:
chronos
Message:
  • Modified: Improved wonders dialog code readability.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LocalPlayer/Wonders.pas

    r155 r156  
    55
    66uses
    7   ScreenTools, BaseWin, Protocol,
    8   LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms, ButtonB;
     7  ScreenTools, BaseWin, Protocol, LCLIntf, LCLType, SysUtils, Classes, Graphics,
     8  Controls, Forms, ButtonB;
    99
    1010type
     
    2121      Shift: TShiftState; X, Y: Integer);
    2222  private
    23     xm, ym, Selection: Integer;
     23    Selection: Integer;
     24    Center: TPoint;
    2425    procedure DarkIcon(i: Integer);
    2526    procedure Glow(i, GlowColor: Integer);
     
    3334  WondersDlg: TWondersDlg;
    3435
     36
    3537implementation
    3638
     
    4143
    4244const
    43   RingPosition: array [0 .. 20, 0 .. 1] of Integer = ((-80, -32), // Pyramids
    44     (80, -32), // Zeus
    45     (0, -64), // Gardens
    46     (0, 0), // Colossus
    47     (0, 64), // Lighthouse
    48     (-80, 32), // GrLibrary
    49     (-90, 114), // Oracle
    50     (80, 32), // Sun
    51     (90, -114), // Leo
    52     (-180, 0), // Magellan
    53     (90, 114), // Mich
    54     (0, 0), // {11;}
    55     (180, 0), // Newton
    56     (-90, -114), // Bach
    57     (0, 0), // {14;}
    58     (-160, -64), // Liberty
    59     (0, 128), // Eiffel
    60     (160, -64), // Hoover
    61     (-160, 64), // Shinkansen
    62     (0, -128), // Manhattan
    63     (160, 64)); // Mir
     45  RingPosition: array [0 .. 20] of TPoint = (
     46    (X: -80; Y: -32), // Pyramids
     47    (X: 80; Y: -32), // Zeus
     48    (X: 0; Y: -64), // Gardens
     49    (X: 0; Y: 0), // Colossus
     50    (X: 0; Y: 64), // Lighthouse
     51    (X: -80; Y: 32), // GrLibrary
     52    (X: -90; Y: 114), // Oracle
     53    (X: 80; Y: 32), // Sun
     54    (X: 90; Y: -114), // Leo
     55    (X: -180; Y: 0), // Magellan
     56    (X: 90; Y: 114), // Mich
     57    (X: 0; Y: 0), // {11;}
     58    (X: 180; Y: 0), // Newton
     59    (X: -90; Y: -114), // Bach
     60    (X: 0; Y: 0), // {14;}
     61    (X: -160; Y: -64), // Liberty
     62    (X: 0; Y: 128), // Eiffel
     63    (X: 160; Y: -64), // Hoover
     64    (X: -160; Y: 64), // Shinkansen
     65    (X: 0; Y: -128), // Manhattan
     66    (X: 160; Y: 64) // Mir
     67  );
    6468
    6569procedure TWondersDlg.FormCreate(Sender: TObject);
     
    6771  Canvas.Font.Assign(UniFont[ftNormal]);
    6872  Canvas.Brush.Style := bsClear;
    69   InitButtons();
     73  InitButtons;
    7074end;
    7175
     
    114118        for i := 0 to 1 do
    115119          for ch := 0 to 2 do begin
    116             Line[0].SetXY(xm + X, ym + Y);
    117             Line[1].SetXY(xm + X, ym - 1 - Y);
     120            Line[0].SetXY(Center.X + X, Center.Y + Y);
     121            Line[1].SetXY(Center.X + X, Center.Y - 1 - Y);
    118122            c := Line[i].Pixel^.Planes[ch] - darken;
    119123            if c < 0 then Line[i].Pixel^.Planes[ch] := 0
    120124              else Line[i].Pixel^.Planes[ch] := c;
    121             Line[0].SetXY(xm - 1 - X, ym + Y);
    122             Line[1].SetXY(xm - 1 - X, ym - 1 - Y);
     125            Line[0].SetXY(Center.X - 1 - X, Center.Y + Y);
     126            Line[1].SetXY(Center.X - 1 - X, Center.Y - 1 - Y);
    123127            c := Line[i].Pixel^.Planes[ch] - darken;
    124128            if c < 0 then Line[i].Pixel^.Planes[ch] := 0
     
    136140begin
    137141  Offscreen.BeginUpdate;
    138   x0Dst := ClientWidth div 2 - xSizeBig div 2 + RingPosition[i, 0];
    139   y0Dst := ClientHeight div 2 - ySizeBig div 2 + RingPosition[i, 1];
     142  x0Dst := ClientWidth div 2 - xSizeBig div 2 + RingPosition[i].X;
     143  y0Dst := ClientHeight div 2 - ySizeBig div 2 + RingPosition[i].Y;
    140144  x0Src := (i mod 7) * xSizeBig;
    141145  y0Src := (i div 7 + SystemIconLines) * ySizeBig;
     
    162166procedure TWondersDlg.Glow(i, GlowColor: Integer);
    163167begin
    164   GlowFrame(Offscreen, ClientWidth div 2 - xSizeBig div 2 + RingPosition[i,
    165     0], ClientHeight div 2 - ySizeBig div 2 + RingPosition[i, 1], xSizeBig,
    166     ySizeBig, GlowColor);
     168  GlowFrame(Offscreen,
     169    ClientWidth div 2 - xSizeBig div 2 + RingPosition[i].X,
     170    ClientHeight div 2 - ySizeBig div 2 + RingPosition[i].Y,
     171    xSizeBig, ySizeBig, GlowColor);
    167172end;
    168173
    169174procedure TWondersDlg.OffscreenPaint;
    170175var
    171   i: Integer;
    172   HaveWonder: boolean;
    173   s: string;
    174 begin
    175   if (OffscreenUser <> nil) and (OffscreenUser <> self) then
     176  I: Integer;
     177  HaveWonder: Boolean;
     178  S: string;
     179begin
     180  if (OffscreenUser <> nil) and (OffscreenUser <> Self) then
    176181    OffscreenUser.Update;
    177182  // complete working with old owner to prevent rebound
    178   OffscreenUser := self;
     183  OffscreenUser := Self;
    179184
    180185  Fill(Offscreen.Canvas, 3, 3, ClientWidth - 6, ClientHeight - 6,
     
    193198
    194199  Offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
    195   s := Phrases.Lookup('TITLE_WONDERS');
     200  S := Phrases.Lookup('TITLE_WONDERS');
    196201  RisedTextOut(Offscreen.Canvas,
    197     (ClientWidth - BiColorTextWidth(Offscreen.Canvas, s)) div 2 - 1, 7, s);
     202    (ClientWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2 - 1, 7, S);
    198203  Offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
    199204
    200   xm := ClientWidth div 2;
    201   ym := ClientHeight div 2;
     205  Center := Point(ClientWidth div 2, ClientHeight div 2);
    202206
    203207  PaintBackgroundShape;
    204208
    205   for i := 0 to 20 do
    206     if Imp[i].Preq <> preNA then
     209  for I := 0 to 20 do
     210    if Imp[I].Preq <> preNA then
    207211    begin
    208       case MyRO.Wonder[i].CityID of
     212      case MyRO.Wonder[I].CityID of
    209213        - 1: // not built yet
    210214          begin
    211             Fill(Offscreen.Canvas, xm - xSizeBig div 2 + RingPosition[i, 0] - 3,
    212               ym - ySizeBig div 2 + RingPosition[i, 1] - 3, xSizeBig + 6,
     215            Fill(Offscreen.Canvas, Center.X - xSizeBig div 2 + RingPosition[I].X - 3,
     216              Center.Y - ySizeBig div 2 + RingPosition[I].Y - 3, xSizeBig + 6,
    213217              ySizeBig + 6, (wMaintexture - ClientWidth) div 2,
    214218              (hMaintexture - ClientHeight) div 2);
    215             DarkIcon(i);
     219            DarkIcon(I);
    216220          end;
    217221        -2: // destroyed
    218222          begin
    219             Glow(i, $000000);
     223            Glow(I, $000000);
    220224          end;
    221225      else
    222226        begin
    223           if MyRO.Wonder[i].EffectiveOwner >= 0 then
    224             Glow(i, Tribe[MyRO.Wonder[i].EffectiveOwner].Color)
     227          if MyRO.Wonder[I].EffectiveOwner >= 0 then
     228            Glow(I, Tribe[MyRO.Wonder[I].EffectiveOwner].Color)
    225229          else
    226             Glow(i, $000000);
    227         end
    228       end
    229     end;
    230 
    231   HaveWonder := false;
    232   for i := 0 to 20 do
    233     if Imp[i].Preq <> preNA then
     230            Glow(I, $000000);
     231        end;
     232      end;
     233    end;
     234
     235  HaveWonder := False;
     236  for I := 0 to 20 do
     237    if Imp[I].Preq <> preNA then
    234238    begin
    235       case MyRO.Wonder[i].CityID of
     239      case MyRO.Wonder[I].CityID of
    236240        - 1: // not built yet
    237241          begin
    238             Fill(Offscreen.Canvas, xm - xSizeBig div 2 + RingPosition[i, 0] - 3,
    239               ym - ySizeBig div 2 + RingPosition[i, 1] - 3, xSizeBig + 6,
     242            Fill(Offscreen.Canvas, Center.X - xSizeBig div 2 + RingPosition[I].X - 3,
     243              Center.Y - ySizeBig div 2 + RingPosition[I].Y - 3, xSizeBig + 6,
    240244              ySizeBig + 6, (wMaintexture - ClientWidth) div 2,
    241245              (hMaintexture - ClientHeight) div 2);
    242             DarkIcon(i);
     246            DarkIcon(I);
    243247          end;
    244248        -2: // destroyed
    245249          begin
    246             HaveWonder := true;
    247             BitBlt(Offscreen.Canvas.Handle, xm - xSizeBig div 2 + RingPosition
    248               [i, 0], ym - ySizeBig div 2 + RingPosition[i, 1], xSizeBig,
     250            HaveWonder := True;
     251            BitBlt(Offscreen.Canvas.Handle,
     252              Center.X - xSizeBig div 2 + RingPosition[I].X,
     253              Center.Y - ySizeBig div 2 + RingPosition[I].Y, xSizeBig,
    249254              ySizeBig, BigImp.Canvas.Handle, 0, (SystemIconLines + 3) *
    250255              ySizeBig, SRCCOPY);
     
    252257      else
    253258        begin
    254           HaveWonder := true;
    255           BitBlt(Offscreen.Canvas.Handle, xm - xSizeBig div 2 + RingPosition[i,
    256             0], ym - ySizeBig div 2 + RingPosition[i, 1], xSizeBig, ySizeBig,
    257             BigImp.Canvas.Handle, (i mod 7) * xSizeBig,
    258             (i div 7 + SystemIconLines) * ySizeBig, SRCCOPY);
    259         end
    260       end
     259          HaveWonder := True;
     260          BitBlt(Offscreen.Canvas.Handle,
     261            Center.X - xSizeBig div 2 + RingPosition[I].X,
     262            Center.Y - ySizeBig div 2 + RingPosition[I].Y, xSizeBig, ySizeBig,
     263            BigImp.Canvas.Handle, (I mod 7) * xSizeBig,
     264            (I div 7 + SystemIconLines) * ySizeBig, SRCCOPY);
     265        end;
     266      end;
    261267    end;
    262268
    263269  if not HaveWonder then
    264270  begin
    265     s := Phrases.Lookup('NOWONDER');
    266     RisedTextOut(Offscreen.Canvas, xm - BiColorTextWidth(Offscreen.Canvas, s)
    267       div 2, ym - Offscreen.Canvas.TextHeight(s) div 2, s);
     271    S := Phrases.Lookup('NOWONDER');
     272    RisedTextOut(Offscreen.Canvas,
     273      Center.X - BiColorTextWidth(Offscreen.Canvas, S) div 2,
     274      Center.Y - Offscreen.Canvas.TextHeight(S) div 2, S);
    268275  end;
    269276
     
    273280procedure TWondersDlg.CloseBtnClick(Sender: TObject);
    274281begin
    275   Close
     282  Close;
    276283end;
    277284
     
    279286  X, Y: Integer);
    280287var
    281   i, OldSelection: Integer;
    282   s: string;
     288  I, OldSelection: Integer;
     289  S: string;
    283290begin
    284291  OldSelection := Selection;
    285292  Selection := -1;
    286   for i := 0 to 20 do
    287     if (Imp[i].Preq <> preNA) and (X >= xm - xSizeBig div 2 + RingPosition[i, 0]
    288       ) and (X < xm + xSizeBig div 2 + RingPosition[i, 0]) and
    289       (Y >= ym - ySizeBig div 2 + RingPosition[i, 1]) and
    290       (Y < ym + ySizeBig div 2 + RingPosition[i, 1]) then
     293  for I := 0 to 20 do
     294    if (Imp[I].Preq <> preNA) and
     295      (X >= Center.X - xSizeBig div 2 + RingPosition[I].X) and
     296      (X < Center.X + xSizeBig div 2 + RingPosition[I].X) and
     297      (Y >= Center.Y - ySizeBig div 2 + RingPosition[I].Y) and
     298      (Y < Center.Y + ySizeBig div 2 + RingPosition[I].Y) then
    291299    begin
    292       Selection := i;
    293       break
     300      Selection := I;
     301      Break;
    294302    end;
    295303  if Selection <> OldSelection then
     
    301309      if MyRO.Wonder[Selection].CityID = -1 then
    302310      begin // not built yet
    303         { s:=Phrases.Lookup('IMPROVEMENTS',Selection);
     311        { S:=Phrases.Lookup('IMPROVEMENTS',Selection);
    304312          Canvas.Font.Color:=$000000;
    305313          Canvas.TextOut(
    306           (ClientWidth-BiColorTextWidth(Canvas,s)) div 2+1,
    307           ClientHeight-3-36+1, s);
     314          (ClientWidth-BiColorTextWidth(Canvas,S)) div 2+1,
     315          ClientHeight-3-36+1, S);
    308316          Canvas.Font.Color:=MainTexture.clBevelLight;
    309317          Canvas.TextOut(
    310           (ClientWidth-BiColorTextWidth(Canvas,s)) div 2,
    311           ClientHeight-3-36, s); }
     318          (ClientWidth-BiColorTextWidth(Canvas,S)) div 2,
     319          ClientHeight-3-36, S); }
    312320      end
    313321      else
    314322      begin
    315         s := Phrases.Lookup('IMPROVEMENTS', Selection);
     323        S := Phrases.Lookup('IMPROVEMENTS', Selection);
    316324        if MyRO.Wonder[Selection].CityID <> -2 then
    317           s := Format(Phrases.Lookup('WONDEROF'),
    318             [s, CityName(MyRO.Wonder[Selection].CityID)]);
     325          S := Format(Phrases.Lookup('WONDEROF'),
     326            [S, CityName(MyRO.Wonder[Selection].CityID)]);
    319327        LoweredTextOut(Canvas, -1, MainTexture,
    320           (ClientWidth - BiColorTextWidth(Canvas, s)) div 2,
    321           ClientHeight - 3 - 36 - 10, s);
     328          (ClientWidth - BiColorTextWidth(Canvas, S)) div 2,
     329          ClientHeight - 3 - 36 - 10, S);
    322330        if MyRO.Wonder[Selection].CityID = -2 then
    323           s := Phrases.Lookup('DESTROYED')
     331          S := Phrases.Lookup('DESTROYED')
    324332        else if MyRO.Wonder[Selection].EffectiveOwner < 0 then
    325           s := Phrases.Lookup('EXPIRED')
     333          S := Phrases.Lookup('EXPIRED')
    326334        else
    327           s := Tribe[MyRO.Wonder[Selection].EffectiveOwner]
    328             .TPhrase('WONDEROWNER');
     335          S := Tribe[MyRO.Wonder[Selection].EffectiveOwner].TPhrase('WONDEROWNER');
    329336        LoweredTextOut(Canvas, -1, MainTexture,
    330           (ClientWidth - BiColorTextWidth(Canvas, s)) div 2,
    331           ClientHeight - 3 - 36 + 10, s);
    332       end
    333     end;
    334   end
     337          (ClientWidth - BiColorTextWidth(Canvas, S)) div 2,
     338          ClientHeight - 3 - 36 + 10, S);
     339      end;
     340    end;
     341  end;
    335342end;
    336343
Note: See TracChangeset for help on using the changeset viewer.