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/LocalPlayer/Draft.pas

    r361 r465  
    55
    66uses
    7   UDpiControls, Protocol, ClientTools, Term, ScreenTools, BaseWin,
    8 
    9   LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms, ExtCtrls,
    10   ButtonA,
    11   ButtonB, Area;
     7  UDpiControls, Protocol, ClientTools, ScreenTools, BaseWin, LCLIntf, LCLType, SysUtils,
     8  Classes, Graphics, Controls, Forms, ExtCtrls, ButtonA, ButtonB, Area;
    129
    1310type
     
    2320    procedure CloseBtnClick(Sender: TObject);
    2421    procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    25       Shift: TShiftState; x, y: integer);
     22      Shift: TShiftState; X, Y: Integer);
    2623    procedure OKBtnClick(Sender: TObject);
    2724    procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
    28       Shift: TShiftState; x, y: integer);
     25      Shift: TShiftState; X, Y: Integer);
    2926  public
    30     procedure ShowNewContent(NewMode: integer);
     27    procedure ShowNewContent(NewMode: TWindowMode);
    3128  protected
    3229    procedure OffscreenPaint; override;
    3330  private
    3431    Domain, MaxLines, Lines, Cut, yDomain, yFeature, yWeight, yTotal, yView,
    35       IncCap, DecCap: integer;
    36     code: array [0 .. nFeature - 1] of integer;
     32      IncCap, DecCap: Integer;
     33    Code: array [0 .. nFeature - 1] of Integer;
    3734    Template, Back: TDpiBitmap;
    38     function IsFeatureInList(d, i: integer): boolean;
    39     procedure SetDomain(d: integer);
    40   end;
    41 
    42 var
    43   DraftDlg: TDraftDlg;
     35    function IsFeatureInList(D, I: Integer): Boolean;
     36    procedure SetDomain(D: Integer);
     37  end;
     38
    4439
    4540implementation
    4641
    47 uses Help, Tribes, Directories;
     42uses
     43  Term, Help, Tribes, Directories;
    4844
    4945{$R *.lfm}
     
    109105procedure TDraftDlg.OffscreenPaint;
    110106
    111   function DomainAvailable(d: integer): boolean;
    112   begin
    113     result := (upgrade[d, 0].Preq = preNone) or
    114       (MyRO.Tech[upgrade[d, 0].Preq] >= tsApplicable);
     107  function DomainAvailable(D: Integer): Boolean;
     108  begin
     109    Result := (upgrade[D, 0].Preq = preNone) or
     110      (MyRO.Tech[upgrade[D, 0].Preq] >= tsApplicable);
    115111  end;
    116112
    117113  procedure PaintTotalBars;
    118114  var
    119     i, y, dx, num, w: integer;
    120     s: string;
    121   begin
    122     with offscreen.Canvas do
     115    I, Y, dx, num, W: Integer;
     116    S: string;
     117  begin
     118    with Offscreen.Canvas do
    123119    begin
    124120      // strength bar
    125       y := yTotal;
    126       DarkGradient(offscreen.Canvas, xTotal - 6, y + 1, 184, 2);
    127       DarkGradient(offscreen.Canvas, xTotal2 + 172, y + 1, 95, 2);
    128       RisedTextOut(offscreen.Canvas, xTotal - 2, y,
     121      Y := yTotal;
     122      DarkGradient(Offscreen.Canvas, xTotal - 6, Y + 1, 184, 2);
     123      DarkGradient(Offscreen.Canvas, xTotal2 + 172, Y + 1, 95, 2);
     124      RisedTextOut(Offscreen.Canvas, xTotal - 2, Y,
    129125        Phrases.Lookup('UNITSTRENGTH'));
    130       RisedTextOut(offscreen.Canvas, xTotal + 112 + 30, y,
     126      RisedTextOut(Offscreen.Canvas, xTotal + 112 + 30, Y,
    131127        'x' + IntToStr(MyRO.DevModel.MStrength));
    132       RisedTextOut(offscreen.Canvas, xTotal2 + 148 + 30, y, '=');
    133       s := IntToStr(MyRO.DevModel.Attack) + '/' +
     128      RisedTextOut(Offscreen.Canvas, xTotal2 + 148 + 30, Y, '=');
     129      S := IntToStr(MyRO.DevModel.Attack) + '/' +
    134130        IntToStr(MyRO.DevModel.Defense);
    135       RisedTextOut(offscreen.Canvas, xTotal2 + 170 + 64 + 30 -
    136         BiColorTextWidth(offscreen.Canvas, s), y, s);
     131      RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 -
     132        BiColorTextWidth(Offscreen.Canvas, S), Y, S);
    137133
    138134      // transport bar
    139135      if MyRO.DevModel.MTrans > 0 then
    140136      begin
    141         y := yTotal + 19;
    142         DarkGradient(offscreen.Canvas, xTotal - 6, y + 1, 184, 1);
    143         DarkGradient(offscreen.Canvas, xTotal2 + 172, y + 1, 95, 1);
    144         RisedTextOut(offscreen.Canvas, xTotal - 2, y,
     137        Y := yTotal + 19;
     138        DarkGradient(Offscreen.Canvas, xTotal - 6, Y + 1, 184, 1);
     139        DarkGradient(Offscreen.Canvas, xTotal2 + 172, Y + 1, 95, 1);
     140        RisedTextOut(Offscreen.Canvas, xTotal - 2, Y,
    145141          Phrases.Lookup('UNITTRANSPORT'));
    146         RisedTextOut(offscreen.Canvas, xTotal + 112 + 30, y,
     142        RisedTextOut(Offscreen.Canvas, xTotal + 112 + 30, Y,
    147143          'x' + IntToStr(MyRO.DevModel.MTrans));
    148         RisedTextOut(offscreen.Canvas, xTotal2 + 148 + 30, y, '=');
     144        RisedTextOut(Offscreen.Canvas, xTotal2 + 148 + 30, Y, '=');
    149145
    150146        Font.Color := $000000;
    151147        dx := -237 - 30;
    152         for i := mcFirstNonCap - 1 downto 3 do
    153           if i in [mcSeaTrans, mcCarrier, mcAirTrans] then
     148        for I := mcFirstNonCap - 1 downto 3 do
     149          if I in [mcSeaTrans, mcCarrier, mcAirTrans] then
    154150          begin
    155             num := MyRO.DevModel.Cap[i] * MyRO.DevModel.MTrans;
     151            num := MyRO.DevModel.Cap[I] * MyRO.DevModel.MTrans;
    156152            if num > 0 then
    157153            begin
    158               inc(dx, 15);
     154              Inc(dx, 15);
    159155              Brush.Color := $C0C0C0;
    160               FrameRect(Rect(xTotal2 - 3 - dx, y + 2,
    161                 xTotal2 + 11 - dx, y + 16));
     156              FrameRect(Rect(xTotal2 - 3 - dx, Y + 2,
     157                xTotal2 + 11 - dx, Y + 16));
    162158              Brush.Style := bsClear;
    163               Sprite(offscreen, HGrSystem, xTotal2 - 1 - dx, y + 4, 10, 10,
    164                 66 + i mod 11 * 11, 137 + i div 11 * 11);
     159              Sprite(Offscreen, HGrSystem, xTotal2 - 1 - dx, Y + 4, 10, 10,
     160                66 + I mod 11 * 11, 137 + I div 11 * 11);
    165161              if num > 1 then
    166162              begin
    167                 s := IntToStr(num);
    168                 w := TextWidth(s);
    169                 inc(dx, w + 1);
     163                S := IntToStr(num);
     164                W := TextWidth(S);
     165                Inc(dx, W + 1);
    170166                Brush.Color := $FFFFFF;
    171                 FillRect(Rect(xTotal2 - 3 - dx, y + 2,
    172                   xTotal2 + w - 1 - dx, y + 16));
     167                FillRect(Rect(xTotal2 - 3 - dx, Y + 2,
     168                  xTotal2 + W - 1 - dx, Y + 16));
    173169                Brush.Style := bsClear;
    174                 Textout(xTotal2 - 3 - dx + 1, y, s);
     170                Textout(xTotal2 - 3 - dx + 1, Y, S);
    175171              end;
    176172            end;
    177           end
     173          end;
    178174      end;
    179175
    180176      // speed bar
    181       y := yTotal + 38;
    182       LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2, y,
     177      Y := yTotal + 38;
     178      LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, Y,
    183179        Phrases.Lookup('UNITSPEED'));
    184       DLine(offscreen.Canvas, xTotal - 2, xTotal + 174, y + 16,
     180      DLine(Offscreen.Canvas, xTotal - 2, xTotal + 174, Y + 16,
    185181        MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    186       DLine(offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, y + 16,
     182      DLine(Offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, Y + 16,
    187183        MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    188       s := MovementToString(MyRO.DevModel.Speed);
    189       RisedTextOut(offscreen.Canvas, xTotal2 + 170 + 64 + 30 -
    190         TextWidth(s), y, s);
     184      S := MovementToString(MyRO.DevModel.Speed);
     185      RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 -
     186        TextWidth(S), Y, S);
    191187
    192188      // cost bar
    193       y := yTotal + 57;
    194       LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2, y,
     189      Y := yTotal + 57;
     190      LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, Y,
    195191        Phrases.Lookup('UNITCOST'));
    196       LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal + 112 + 30, y,
     192      LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal + 112 + 30, Y,
    197193        'x' + IntToStr(MyRO.DevModel.MCost));
    198       LoweredTextOut(offscreen.Canvas, -1, MainTexture,
    199         xTotal2 + 148 + 30, y, '=');
    200       DLine(offscreen.Canvas, xTotal - 2, xTotal + 174, y + 16,
     194      LoweredTextOut(Offscreen.Canvas, -1, MainTexture,
     195        xTotal2 + 148 + 30, Y, '=');
     196      DLine(Offscreen.Canvas, xTotal - 2, xTotal + 174, Y + 16,
    201197        MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    202       DLine(offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, y + 16,
     198      DLine(Offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, Y + 16,
    203199        MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    204       s := IntToStr(MyRO.DevModel.Cost);
    205       RisedTextOut(offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 -
    206         TextWidth(s), y, s);
    207       Sprite(offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, y + 4, 10,
     200      S := IntToStr(MyRO.DevModel.Cost);
     201      RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 -
     202        TextWidth(S), Y, S);
     203      Sprite(Offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, Y + 4, 10,
    208204        10, 88, 115);
    209205
    210       if G.Difficulty[me] <> 2 then
     206      if G.Difficulty[Me] <> 2 then
    211207      begin // corrected cost bar
    212         y := yTotal + 76;
    213         LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2, y,
    214           Phrases.Lookup('COSTDIFF' + char(48 + G.Difficulty[me])));
    215         LoweredTextOut(offscreen.Canvas, -1, MainTexture,
    216           xTotal2 + 148 + 30, y, '=');
    217         DLine(offscreen.Canvas, xTotal - 2, xTotal + 174, y + 16,
     208        Y := yTotal + 76;
     209        LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, Y,
     210          Phrases.Lookup('COSTDIFF' + char(48 + G.Difficulty[Me])));
     211        LoweredTextOut(Offscreen.Canvas, -1, MainTexture,
     212          xTotal2 + 148 + 30, Y, '=');
     213        DLine(Offscreen.Canvas, xTotal - 2, xTotal + 174, Y + 16,
    218214          MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    219         DLine(offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, y + 16,
     215        DLine(Offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, Y + 16,
    220216          MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    221         s := IntToStr(MyRO.DevModel.Cost * BuildCostMod
    222           [G.Difficulty[me]] div 12);
    223         RisedTextOut(offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 -
    224           TextWidth(s), y, s);
    225         Sprite(offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, y + 4, 10,
     217        S := IntToStr(MyRO.DevModel.Cost * BuildCostMod
     218          [G.Difficulty[Me]] div 12);
     219        RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 -
     220          TextWidth(S), Y, S);
     221        Sprite(Offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, Y + 4, 10,
    226222          10, 88, 115);
    227223      end;
     
    230226
    231227var
    232   i, j, x, d, n, TextColor, CapWeight, DomainCount: integer;
     228  I, J, X, D, N, TextColor, CapWeight, DomainCount: Integer;
    233229begin
    234230  inherited;
     
    239235  // assemble background from 2 texture tiles
    240236  begin
    241     DpiBitCanvas(Back.Canvas, 0, 0, ClientWidth, 64,
     237    DpiBitBltCanvas(Back.Canvas, 0, 0, ClientWidth, 64,
    242238      MainTexture.Image.Canvas, (MainTexture.Width - ClientWidth) div 2,
    243239      MainTexture.Height - 64);
    244     DpiBitCanvas(Back.Canvas, 0, 64, ClientWidth, ClientHeight - 64,
     240    DpiBitBltCanvas(Back.Canvas, 0, 64, ClientWidth, ClientHeight - 64,
    245241      MainTexture.Image.Canvas, (MainTexture.Width - ClientWidth) div 2,
    246242      0);
    247243  end
    248244  else
    249     DpiBitCanvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight,
     245    DpiBitBltCanvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight,
    250246      MainTexture.Image.Canvas, (MainTexture.Width - ClientWidth) div 2,
    251247      (MainTexture.Height - ClientHeight) div 2);
     
    254250    Template.Height - 64 - Cut);
    255251
    256   DpiBitCanvas(offscreen.Canvas, 0, 0, ClientWidth, ClientHeight,
     252  DpiBitBltCanvas(Offscreen.Canvas, 0, 0, ClientWidth, ClientHeight,
    257253    Back.Canvas, 0, 0);
    258254
    259   offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
    260   RisedTextOut(offscreen.Canvas, 10, 7, Caption);
    261   offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     255  Offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
     256  RisedTextOut(Offscreen.Canvas, 10, 7, Caption);
     257  Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    262258
    263259  with MyRO.DevModel do
    264260  begin
    265261    DomainCount := 0;
    266     for d := 0 to nDomains - 1 do
    267       if DomainAvailable(d) then
    268         inc(DomainCount);
     262    for D := 0 to nDomains - 1 do
     263      if DomainAvailable(D) then
     264        Inc(DomainCount);
    269265    if DomainCount > 1 then
    270266    begin
    271       for d := 0 to nDomains - 1 do
    272         if DomainAvailable(d) then
     267      for D := 0 to nDomains - 1 do
     268        if DomainAvailable(D) then
    273269        begin
    274           x := xDomain + d * DomainPitch;
    275           if d = Domain then
    276             ImageOp_BCC(offscreen, Templates.Data, x, yDomain, 142, 246 + 37 * d, 36,
     270          X := xDomain + D * DomainPitch;
     271          if D = Domain then
     272            ImageOp_BCC(Offscreen, Templates.Data, X, yDomain, 142, 246 + 37 * D, 36,
    277273              36, 0, $00C0FF)
    278274          else
    279             ImageOp_BCC(offscreen, Templates.Data, x, yDomain, 142, 246 + 37 * d, 36,
     275            ImageOp_BCC(Offscreen, Templates.Data, X, yDomain, 142, 246 + 37 * D, 36,
    280276              36, 0, $606060);
    281277        end;
    282       Frame(offscreen.Canvas, xDomain - 11, yDomain - 3,
     278      Frame(Offscreen.Canvas, xDomain - 11, yDomain - 3,
    283279        xDomain + 2 * DomainPitch + 46, yDomain + 38, $B0B0B0, $FFFFFF);
    284       RFrame(offscreen.Canvas, xDomain - 12, yDomain - 4,
     280      RFrame(Offscreen.Canvas, xDomain - 12, yDomain - 4,
    285281        xDomain + 2 * DomainPitch + 47, yDomain + 39, $FFFFFF, $B0B0B0);
    286282    end;
     
    295291
    296292    // display weight
    297     with offscreen.Canvas do
    298     begin
    299       for i := 0 to MaxWeight - 1 do
    300         if i < Weight then
    301           ImageOp_BCC(offscreen, Templates.Data, Point(xWeight + 20 * i, yWeight),
     293    with Offscreen.Canvas do
     294    begin
     295      for I := 0 to MaxWeight - 1 do
     296        if I < Weight then
     297          ImageOp_BCC(Offscreen, Templates.Data, Point(xWeight + 20 * I, yWeight),
    302298            WeightOn.BoundsRect, 0, $949494)
    303299        else
    304           ImageOp_BCC(offscreen, Templates.Data, Point(xWeight + 20 * i, yWeight),
     300          ImageOp_BCC(Offscreen, Templates.Data, Point(xWeight + 20 * I, yWeight),
    305301            WeightOff.BoundsRect, 0, $949494);
    306302    end;
    307303
    308     with offscreen.Canvas do
    309       for i := 0 to Lines - 1 do
     304    with Offscreen.Canvas do
     305      for I := 0 to Lines - 1 do
    310306      begin
    311         if not(code[i] in AutoFeature) then
     307        if not(Code[I] in AutoFeature) then
    312308        begin
    313309          // paint +/- butttons
    314           if code[i] < mcFirstNonCap then
     310          if Code[I] < mcFirstNonCap then
    315311          begin
    316             Dump(offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch *
    317               i, 12, 12, 169, 172);
    318             Dump(offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
    319               i, 12, 12, 169, 159);
    320             RFrame(offscreen.Canvas, xFeature - (21 + 1),
    321               yFeature + 2 + LinePitch * i - 1, xFeature - (21 - 24),
    322               yFeature + 2 + LinePitch * i + 12, MainTexture.ColorBevelShade,
     312            Dump(Offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch *
     313              I, 12, 12, 169, 172);
     314            Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
     315              I, 12, 12, 169, 159);
     316            RFrame(Offscreen.Canvas, xFeature - (21 + 1),
     317              yFeature + 2 + LinePitch * I - 1, xFeature - (21 - 24),
     318              yFeature + 2 + LinePitch * I + 12, MainTexture.ColorBevelShade,
    323319              MainTexture.ColorBevelLight);
    324320          end
    325321          else
    326322          begin
    327             Dump(offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
    328               i, 12, 12, 169, 185 + 13 * MyRO.DevModel.Cap[code[i]]);
    329             RFrame(offscreen.Canvas, xFeature - (9 + 1),
    330               yFeature + 2 + LinePitch * i - 1, xFeature - (21 - 24),
    331               yFeature + 2 + LinePitch * i + 12, MainTexture.ColorBevelShade,
     323            Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
     324              I, 12, 12, 169, 185 + 13 * MyRO.DevModel.Cap[Code[I]]);
     325            RFrame(Offscreen.Canvas, xFeature - (9 + 1),
     326              yFeature + 2 + LinePitch * I - 1, xFeature - (21 - 24),
     327              yFeature + 2 + LinePitch * I + 12, MainTexture.ColorBevelShade,
    332328              MainTexture.ColorBevelLight);
    333329          end;
    334330
    335331          // paint cost
    336           LightGradient(offscreen.Canvas, xFeature + 34,
    337             yFeature + LinePitch * i, 50, HGrSystem.Data.Canvas.Pixels
     332          LightGradient(Offscreen.Canvas, xFeature + 34,
     333            yFeature + LinePitch * I, 50, HGrSystem.Data.Canvas.Pixels
    338334            [187, 137]);
    339           if (Domain = dGround) and (code[i] = mcDefense) then
     335          if (Domain = dGround) and (Code[I] = mcDefense) then
    340336            CapWeight := 2
    341337          else
    342             CapWeight := Feature[code[i]].Weight;
    343           n := CapWeight + Feature[code[i]].Cost;
    344           d := 6;
    345           while (n - 1) * d * 2 > 48 - 10 do
    346             dec(d);
    347           for j := 0 to n - 1 do
    348             if j < CapWeight then
    349               Sprite(offscreen, HGrSystem, xFeature + 54 + (j * 2 + 1 - n) * d,
    350                 yFeature + 2 + LinePitch * i + 1, 10, 10, 88, 126)
     338            CapWeight := Feature[Code[I]].Weight;
     339          N := CapWeight + Feature[Code[I]].Cost;
     340          D := 6;
     341          while (N - 1) * D * 2 > 48 - 10 do
     342            Dec(D);
     343          for J := 0 to N - 1 do
     344            if J < CapWeight then
     345              Sprite(Offscreen, HGrSystem, xFeature + 54 + (J * 2 + 1 - N) * D,
     346                yFeature + 2 + LinePitch * I + 1, 10, 10, 88, 126)
    351347            else
    352               Sprite(offscreen, HGrSystem, xFeature + 54 + (j * 2 + 1 - n) * d,
    353                 yFeature + 2 + LinePitch * i + 1, 10, 10, 88, 115);
     348              Sprite(Offscreen, HGrSystem, xFeature + 54 + (J * 2 + 1 - N) * D,
     349                yFeature + 2 + LinePitch * I + 1, 10, 10, 88, 115);
    354350        end; // if not (code[i] in AutoFeature)
    355         DarkGradient(offscreen.Canvas, xFeature + 17,
    356           yFeature + LinePitch * i, 16, 1);
    357         ScreenTools.Frame(offscreen.Canvas, xFeature + 18, yFeature + 1 + LinePitch * i,
    358           xFeature + 20 - 2 + 13, yFeature + 2 + 1 - 2 + 13 + LinePitch * i,
     351        DarkGradient(Offscreen.Canvas, xFeature + 17,
     352          yFeature + LinePitch * I, 16, 1);
     353        ScreenTools.Frame(Offscreen.Canvas, xFeature + 18, yFeature + 1 + LinePitch * I,
     354          xFeature + 20 - 2 + 13, yFeature + 2 + 1 - 2 + 13 + LinePitch * I,
    359355          $C0C0C0, $C0C0C0);
    360         Sprite(offscreen, HGrSystem, xFeature + 20, yFeature + 2 + 1 + LinePitch
    361           * i, 10, 10, 66 + code[i] mod 11 * 11, 137 + code[i] div 11 * 11);
    362 
    363         if MyRO.DevModel.Cap[code[i]] > 0 then
     356        Sprite(Offscreen, HGrSystem, xFeature + 20, yFeature + 2 + 1 + LinePitch
     357          * I, 10, 10, 66 + Code[I] mod 11 * 11, 137 + Code[I] div 11 * 11);
     358
     359        if MyRO.DevModel.Cap[Code[I]] > 0 then
    364360          TextColor := MainTexture.ColorLitText
    365361        else
    366362          TextColor := -1;
    367363
    368         if code[i] < mcFirstNonCap then
    369           LoweredTextOut(offscreen.Canvas, TextColor, MainTexture, xFeature + 7,
    370             yFeature + LinePitch * i - 1, IntToStr(MyRO.DevModel.Cap[code[i]]));
    371         LoweredTextOut(offscreen.Canvas, TextColor, MainTexture, xFeature + 88,
    372           yFeature + LinePitch * i - 1, Phrases.Lookup('FEATURES', code[i]));
     364        if Code[I] < mcFirstNonCap then
     365          LoweredTextOut(Offscreen.Canvas, TextColor, MainTexture, xFeature + 7,
     366            yFeature + LinePitch * I - 1, IntToStr(MyRO.DevModel.Cap[Code[I]]));
     367        LoweredTextOut(Offscreen.Canvas, TextColor, MainTexture, xFeature + 88,
     368          yFeature + LinePitch * I - 1, Phrases.Lookup('FEATURES', Code[I]));
    373369      end;
    374370  end;
    375371
    376372  // free features
    377   j := 0;
    378   for i := 0 to nFeature - 1 do
    379     if (i in AutoFeature) and (1 shl Domain and Feature[i].Domains <> 0) and
    380       (Feature[i].Preq <> preNA) and
    381       ((Feature[i].Preq = preSun) and (MyRO.Wonder[woSun].EffectiveOwner = me)
    382       or (Feature[i].Preq >= 0) and (MyRO.Tech[Feature[i].Preq] >= tsApplicable)
    383       ) and not((Feature[i].Preq = adSteamEngine) and
     373  J := 0;
     374  for I := 0 to nFeature - 1 do
     375    if (I in AutoFeature) and (1 shl Domain and Feature[I].Domains <> 0) and
     376      (Feature[I].Preq <> preNA) and
     377      ((Feature[I].Preq = preSun) and (MyRO.Wonder[woSun].EffectiveOwner = Me)
     378      or (Feature[I].Preq >= 0) and (MyRO.Tech[Feature[I].Preq] >= tsApplicable)
     379      ) and not((Feature[I].Preq = adSteamEngine) and
    384380      (MyRO.Tech[adNuclearPower] >= tsApplicable)) then
    385381    begin
    386       DarkGradient(offscreen.Canvas, xWeight + 4, yWeight + 32 + LinePitch
    387         * j, 16, 1);
    388       Frame(offscreen.Canvas, xWeight + 5, yWeight + 33 + LinePitch * j,
    389         xWeight + 18, yWeight + 47 + LinePitch * j, $C0C0C0, $C0C0C0);
    390       Sprite(offscreen, HGrSystem, xWeight + 7, yWeight + 36 + LinePitch * j,
    391         10, 10, 66 + i mod 11 * 11, 137 + i div 11 * 11);
    392       LoweredTextOut(offscreen.Canvas, -1, MainTexture, xWeight + 26,
    393         yWeight + 31 + LinePitch * j, Phrases.Lookup('FEATURES', i));
    394       inc(j);
    395     end;
    396 
    397   with Tribe[me].ModelPicture[MyRO.nModel] do
    398   begin
    399     FrameImage(offscreen.Canvas, BigImp, xView + 4, yView + 4, xSizeBig,
     382      DarkGradient(Offscreen.Canvas, xWeight + 4, yWeight + 32 + LinePitch
     383        * J, 16, 1);
     384      Frame(Offscreen.Canvas, xWeight + 5, yWeight + 33 + LinePitch * J,
     385        xWeight + 18, yWeight + 47 + LinePitch * J, $C0C0C0, $C0C0C0);
     386      Sprite(Offscreen, HGrSystem, xWeight + 7, yWeight + 36 + LinePitch * J,
     387        10, 10, 66 + I mod 11 * 11, 137 + I div 11 * 11);
     388      LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xWeight + 26,
     389        yWeight + 31 + LinePitch * J, Phrases.Lookup('FEATURES', I));
     390      Inc(J);
     391    end;
     392
     393  with Tribe[Me].ModelPicture[MyRO.nModel] do
     394  begin
     395    FrameImage(Offscreen.Canvas, BigImp, xView + 4, yView + 4, xSizeBig,
    400396      ySizeBig, 0, 0);
    401     Sprite(offscreen, HGr, xView, yView, 64, 44, pix mod 10 * 65 + 1,
     397    Sprite(Offscreen, HGr, xView, yView, 64, 44, pix mod 10 * 65 + 1,
    402398      pix div 10 * 49 + 1);
    403399  end;
    404400  MarkUsedOffscreen(ClientWidth, ClientHeight);
    405 end; { MainPaint }
    406 
    407 procedure TDraftDlg.SetDomain(d: integer);
    408 
    409   function Prio(fix: integer): integer;
     401end;
     402
     403procedure TDraftDlg.SetDomain(D: Integer);
     404
     405  function Prio(fix: Integer): Integer;
    410406  var
    411     FeaturePreq: integer;
     407    FeaturePreq: Integer;
    412408  begin
    413409    FeaturePreq := Feature[fix].Preq;
    414     assert(FeaturePreq <> preNA);
     410    Assert(FeaturePreq <> preNA);
    415411    if fix < mcFirstNonCap then
    416       result := 10000 + fix
     412      Result := 10000 + fix
    417413    else if FeaturePreq = preNone then
    418       result := 20000
     414      Result := 20000
    419415    else if FeaturePreq < 0 then
    420       result := 40000
     416      Result := 40000
    421417    else
    422       result := 30000 + AdvValue[FeaturePreq];
     418      Result := 30000 + AdvValue[FeaturePreq];
    423419    if not(fix in AutoFeature) then
    424       inc(result, 90000);
     420      Inc(Result, 90000);
    425421  end;
    426422
    427423var
    428   i, j, x: integer;
    429 begin
    430   Domain := d;
     424  I, J, X: Integer;
     425begin
     426  Domain := D;
    431427  Lines := 0;
    432   for i := 0 to nFeature - 1 do
    433     if IsFeatureInList(Domain, i) then
    434     begin
    435       code[Lines] := i;
    436       inc(Lines)
     428  for I := 0 to nFeature - 1 do
     429    if IsFeatureInList(Domain, I) then
     430    begin
     431      Code[Lines] := I;
     432      Inc(Lines);
    437433    end;
    438434  yFeature := yFeature0 + (MaxLines - Lines) * LinePitch div 2;
    439435
    440436  // sort features
    441   for i := 0 to Lines - 2 do
    442     for j := i + 1 to Lines - 1 do
    443       if Prio(code[i]) > Prio(code[j]) then
     437  for I := 0 to Lines - 2 do
     438    for J := I + 1 to Lines - 1 do
     439      if Prio(Code[I]) > Prio(Code[J]) then
    444440      begin // exchange
    445         x := code[i];
    446         code[i] := code[j];
    447         code[j] := x
     441        X := Code[I];
     442        Code[I] := Code[J];
     443        Code[J] := X;
    448444      end;
    449445end;
    450446
    451 function TDraftDlg.IsFeatureInList(d, i: integer): boolean;
    452 begin
    453   result := not(i in AutoFeature) and (1 shl d and Feature[i].Domains <> 0) and
    454     (Feature[i].Preq <> preNA) and
    455     ((Feature[i].Preq = preNone) or (Feature[i].Preq = preSun) and
    456     (MyRO.Wonder[woSun].EffectiveOwner = me) or (Feature[i].Preq >= 0) and
    457     (MyRO.Tech[Feature[i].Preq] >= tsApplicable));
     447function TDraftDlg.IsFeatureInList(D, I: Integer): Boolean;
     448begin
     449  Result := not(I in AutoFeature) and (1 shl D and Feature[I].Domains <> 0) and
     450    (Feature[I].Preq <> preNA) and
     451    ((Feature[I].Preq = preNone) or (Feature[I].Preq = preSun) and
     452    (MyRO.Wonder[woSun].EffectiveOwner = Me) or (Feature[I].Preq >= 0) and
     453    (MyRO.Tech[Feature[I].Preq] >= tsApplicable));
    458454end;
    459455
    460456procedure TDraftDlg.FormShow(Sender: TObject);
    461457var
    462   count, d, i: integer;
     458  count, D, I: Integer;
    463459begin
    464460  Domain := dGround;
    465461  while (Domain < dAir) and (upgrade[Domain, 0].Preq <> preNone) and
    466462    (MyRO.Tech[upgrade[Domain, 0].Preq] < tsApplicable) do
    467     inc(Domain);
     463    Inc(Domain);
    468464
    469465  // count max number of features in any domain
    470466  MaxLines := 0;
    471   for d := 0 to nDomains - 1 do
    472     if (upgrade[d, 0].Preq = preNone) or
    473       (MyRO.Tech[upgrade[d, 0].Preq] >= tsApplicable) then
     467  for D := 0 to nDomains - 1 do
     468    if (upgrade[D, 0].Preq = preNone) or
     469      (MyRO.Tech[upgrade[D, 0].Preq] >= tsApplicable) then
    474470    begin
    475471      count := 0;
    476       for i := 0 to nFeature - 1 do
    477         if IsFeatureInList(d, i) then
    478           inc(count);
     472      for I := 0 to nFeature - 1 do
     473        if IsFeatureInList(D, I) then
     474          Inc(count);
    479475      if count > MaxLines then
    480476        MaxLines := count;
     
    494490
    495491  SetDomain(Domain);
    496   Server(sCreateDevModel, me, Domain, nil^);
     492  Server(sCreateDevModel, Me, Domain, nil^);
    497493  MyModel[MyRO.nModel] := MyRO.DevModel;
    498   InitMyModel(MyRO.nModel, false);
     494  InitMyModel(MyRO.nModel, False);
    499495  OffscreenPaint;
    500496  IncCap := -1;
     
    502498end;
    503499
    504 procedure TDraftDlg.ShowNewContent(NewMode: integer);
     500procedure TDraftDlg.ShowNewContent(NewMode: TWindowMode);
    505501begin
    506502  inherited ShowNewContent(NewMode);
     
    508504
    509505procedure TDraftDlg.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    510   Shift: TShiftState; x, y: integer);
     506  Shift: TShiftState; X, Y: Integer);
    511507var
    512   i, d: integer;
     508  I, D: Integer;
    513509begin
    514510  if Button = mbLeft then
    515511  begin
    516     for d := 0 to nDomains - 1 do
    517       if (d <> Domain) and ((upgrade[d, 0].Preq = preNone) or
    518         (MyRO.Tech[upgrade[d, 0].Preq] >= tsApplicable)) and
    519         (x >= xDomain + d * DomainPitch) and
    520         (x < xDomain + d * DomainPitch + 36) and (y >= yDomain) and
    521         (y < yDomain + 36) then
     512    for D := 0 to nDomains - 1 do
     513      if (D <> Domain) and ((upgrade[D, 0].Preq = preNone) or
     514        (MyRO.Tech[upgrade[D, 0].Preq] >= tsApplicable)) and
     515        (X >= xDomain + D * DomainPitch) and
     516        (X < xDomain + D * DomainPitch + 36) and (Y >= yDomain) and
     517        (Y < yDomain + 36) then
    522518      begin
    523         SetDomain(d);
    524         Server(sCreateDevModel, me, Domain, nil^);
     519        SetDomain(D);
     520        Server(sCreateDevModel, Me, Domain, nil^);
    525521        MyModel[MyRO.nModel] := MyRO.DevModel;
    526         InitMyModel(MyRO.nModel, false);
     522        InitMyModel(MyRO.nModel, False);
    527523        SmartUpdateContent;
    528524      end;
    529525
    530     if (y >= yFeature) and (y < yFeature + LinePitch * Lines) then
    531     begin
    532       i := (y - yFeature) div LinePitch;
    533       if (x >= xFeature - 21) and (x < ClientWidth) and (ssShift in Shift) then
    534         HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkFeature, code[i])
    535       else if not(code[i] in AutoFeature) then
     526    if (Y >= yFeature) and (Y < yFeature + LinePitch * Lines) then
     527    begin
     528      I := (Y - yFeature) div LinePitch;
     529      if (X >= xFeature - 21) and (X < ClientWidth) and (ssShift in Shift) then
     530        MainScreen.HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkFeature, Code[I])
     531      else if not(Code[I] in AutoFeature) then
    536532      begin
    537         if (code[i] < mcFirstNonCap) and (x >= xFeature - 21) and
    538           (x < xFeature - 21 + 12) then
     533        if (Code[I] < mcFirstNonCap) and (X >= xFeature - 21) and
     534          (X < xFeature - 21 + 12) then
    539535        begin
    540           IncCap := code[i];
    541           Dump(offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch *
    542             i, 12, 12, 182, 172);
     536          IncCap := Code[I];
     537          Dump(Offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch *
     538            I, 12, 12, 182, 172);
    543539          SmartInvalidate;
    544540        end
    545         else if (x >= xFeature - 9) and (x < xFeature - 9 + 12) then
     541        else if (X >= xFeature - 9) and (X < xFeature - 9 + 12) then
    546542        begin
    547           DecCap := code[i];
    548           if code[i] < mcFirstNonCap then
    549             Dump(offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
    550               i, 12, 12, 182, 159)
     543          DecCap := Code[I];
     544          if Code[I] < mcFirstNonCap then
     545            Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
     546              I, 12, 12, 182, 159)
    551547          else
    552             Dump(offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
    553               i, 12, 12, 182, 185 + 13 * MyRO.DevModel.Cap[code[i]]);
     548            Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
     549              I, 12, 12, 182, 185 + 13 * MyRO.DevModel.Cap[Code[I]]);
    554550          SmartInvalidate;
    555551        end;
    556       end
    557     end
    558   end
     552      end;
     553    end;
     554  end;
    559555end;
    560556
    561557procedure TDraftDlg.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
    562   Shift: TShiftState; x, y: integer);
     558  Shift: TShiftState; X, Y: Integer);
    563559var
    564   NewValue: integer;
     560  NewValue: Integer;
    565561begin
    566562  if IncCap >= 0 then
    567563  begin
    568564    NewValue := MyRO.DevModel.Cap[IncCap] + 1;
    569     Server(sSetDevModelCap + NewValue shl 4, me, IncCap, nil^);
     565    Server(sSetDevModelCap + NewValue shl 4, Me, IncCap, nil^);
    570566    MyModel[MyRO.nModel] := MyRO.DevModel;
    571     InitMyModel(MyRO.nModel, false);
     567    InitMyModel(MyRO.nModel, False);
    572568    SmartUpdateContent;
    573569    IncCap := -1;
     
    580576      if DecCap >= mcFirstNonCap then
    581577        NewValue := -NewValue;
    582       Server(sSetDevModelCap + NewValue shl 4, me, DecCap, nil^);
     578      Server(sSetDevModelCap + NewValue shl 4, Me, DecCap, nil^);
    583579      MyModel[MyRO.nModel] := MyRO.DevModel;
    584       InitMyModel(MyRO.nModel, false);
     580      InitMyModel(MyRO.nModel, False);
    585581    end;
    586582    SmartUpdateContent;
Note: See TracChangeset for help on using the changeset viewer.