Changeset 326 for trunk/LocalPlayer


Ignore:
Timestamp:
Mar 24, 2021, 12:08:28 AM (4 years ago)
Author:
chronos
Message:
  • Modified: Mini map paint method moved from TMainScreen class to TMiniMap class.
Location:
trunk/LocalPlayer
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LocalPlayer/ClientTools.pas

    r294 r326  
    5959procedure CityOptimizer_AfterRemoveUnit;
    6060procedure CityOptimizer_EndOfTurn;
     61function GetMyCityByLoc(Loc: Integer): PCity;
     62function GetEnemyCityByLoc(Loc: Integer): PCityInfo;
     63function GetMyUnitByLoc(Loc: Integer): PUn;
     64function GetEnemyUnitByLoc(Loc: Integer): PUnitInfo;
    6165
    6266
     
    696700end;
    697701
     702function GetMyCityByLoc(Loc: Integer): PCity;
     703var
     704  I: Integer;
     705begin
     706  I := MyRO.nCity - 1;
     707  while (I >= 0) and (MyCity[I].Loc <> Loc) do Dec(I);
     708  if I >= 0 then Result := @MyCity[I]
     709    else Result := nil;
     710end;
     711
     712function GetEnemyCityByLoc(Loc: Integer): PCityInfo;
     713var
     714  I: Integer;
     715begin
     716  I := MyRO.nEnemyCity - 1;
     717  while (I >= 0) and (MyRo.EnemyCity[I].Loc <> Loc) do Dec(I);
     718  if I >= 0 then Result := @MyRo.EnemyCity[I]
     719    else Result := nil;
     720end;
     721
     722function GetMyUnitByLoc(Loc: Integer): PUn;
     723var
     724  I: Integer;
     725begin
     726  I := MyRO.nUn - 1;
     727  while (I >= 0) and (MyUn[I].Loc <> Loc) do Dec(I);
     728  if I >= 0 then Result := @MyUn[I]
     729    else Result := nil;
     730end;
     731
     732function GetEnemyUnitByLoc(Loc: Integer): PUnitInfo;
     733var
     734  I: Integer;
     735begin
     736  I := MyRO.nEnemyUn - 1;
     737  while (I >= 0) and (MyRO.EnemyUn[I].Loc <> Loc) do Dec(I);
     738  if I >= 0 then Result := @MyRO.EnemyUn[I]
     739    else Result := nil;
     740end;
     741
     742
    698743initialization
    699744
  • trunk/LocalPlayer/IsoEngine.pas

    r325 r326  
    8080var
    8181  NoMap: TIsoMap;
    82   Options: integer;
    83   pDebugMap: integer; // -1 for off
     82  Options: Integer;
     83  pDebugMap: Integer; // -1 for off
    8484
    8585function IsJungle(y: integer): boolean;
     
    8787function ApplyTileSize(ATileSize: TTileSize): boolean;
    8888procedure Done;
    89 procedure Reset;
     89procedure IsoEngineReset;
    9090
    9191implementation
     
    466466end;
    467467
    468 procedure Reset;
     468procedure IsoEngineReset;
    469469begin
    470470  BordersOK := 0;
  • trunk/LocalPlayer/Term.pas

    r325 r326  
    1414  LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, DrawDlg, Types,
    1515  Forms, Menus, ExtCtrls, dateutils, Platform, ButtonB, ButtonC, EOTButton, Area,
    16   UGraphicSet;
     16  UGraphicSet, UMiniMap;
    1717
    1818const
     
    253253    trix: array [0 .. 63] of Integer;
    254254    AILogo: array [0 .. nPl - 1] of TBitmap;
    255     Mini: TBitmap;
     255    MiniMap: TMiniMap;
    256256    Panel: TBitmap;
    257257    TopBar: TBitmap;
     
    274274    procedure ArrangeMidPanel;
    275275    procedure MainOffscreenPaint;
    276     procedure MiniPaint;
     276    procedure MiniMapPaint;
    277277    procedure PaintAll;
    278278    procedure PaintAllMaps;
     
    12661266procedure TMainScreen.SetMapOptions;
    12671267begin
     1268  MiniMap.Options := MapOptionChecked;
    12681269  IsoEngine.Options := MapOptionChecked;
    12691270  if ClientMode = cEditMap then
     
    25862587        GameMode := Command;
    25872588        GrExt.ResetPixUsed;
    2588         IsoEngine.Reset;
     2589        IsoEngineReset;
    25892590        Tribes.Init;
    25902591        GetTribeList;
     
    26392640        CityDlg.Reset;
    26402641
    2641         Mini.SetSize(G.lx * 2, G.ly);
     2642        MiniMap.Size := Point(G.lx, G.ly);
    26422643        for i := 0 to nPl - 1 do
    26432644        begin
     
    28422843          MyData := G.RO[NewPlayer].Data;
    28432844          SetTroopLoc(-1);
    2844           MiniPaint;
     2845          MiniMapPaint;
    28452846          InitAllEnemyModels; // necessary for correct replay
    28462847          if not EndTurn(true) then
     
    35243525  end;
    35253526
    3526   Mini := TBitmap.Create;
    3527   Mini.PixelFormat := pf24bit;
     3527  MiniMap := TMiniMap.Create;
    35283528  Panel := TBitmap.Create;
    35293529  Panel.PixelFormat := pf24bit;
     
    35603560  FreeAndNil(sb);
    35613561  FreeAndNil(TopBar);
    3562   FreeAndNil(Mini);
     3562  FreeAndNil(MiniMap);
    35633563  FreeAndNil(Buffer);
    35643564  FreeAndNil(Panel);
     
    41064106end;
    41074107
    4108 procedure TMainScreen.MiniPaint;
    4109 var
    4110   uix, cix, x, y, Loc, i, hw, xm, cm, cmPolOcean, cmPolNone: integer;
    4111   PrevMiniPixel: TPixelPointer;
    4112   MiniPixel: TPixelPointer;
    4113   TerrainTile: Cardinal;
    4114 begin
    4115   if not Assigned(MyMap) then Exit;
    4116   cmPolOcean := HGrSystem.Data.Canvas.Pixels[101, 67];
    4117   cmPolNone := HGrSystem.Data.Canvas.Pixels[102, 67];
    4118   hw := MapWidth div (xxt * 2);
    4119   with Mini.Canvas do begin
    4120     Brush.Color := $000000;
    4121     FillRect(Rect(0, 0, Mini.width, Mini.height));
    4122   end;
    4123   Mini.BeginUpdate;
    4124   MiniPixel := PixelPointer(Mini);
    4125   PrevMiniPixel := PixelPointer(Mini);
    4126   for y := 0 to ScaleToNative(G.ly) - 1 do begin
    4127     for x := 0 to ScaleToNative(G.lx) - 1 do begin
    4128       Loc := ScaleFromNative(x) + G.lx * ScaleFromNative(y);
    4129       if (MyMap[Loc] and fTerrain) <> fUNKNOWN then begin
    4130         for i := 0 to 1 do begin
    4131           xm := ((x - ScaleToNative(xwMini)) * 2 + i + y and 1 - ScaleToNative(hw) +
    4132             ScaleToNative(G.lx) * 5) mod (ScaleToNative(G.lx) * 2);
    4133           MiniPixel.SetXY(xm, y);
    4134           TerrainTile := MyMap[Loc] and fTerrain;
    4135           if TerrainTile > 11 then TerrainTile := 0;
    4136           cm := MiniColors[TerrainTile, i];
    4137           if ClientMode = cEditMap then
    4138           begin
    4139             if MyMap[Loc] and (fPrefStartPos or fStartPos) <> 0 then
    4140               cm := $FFFFFF;
    4141           end
    4142           else if MyMap[Loc] and fCity <> 0 then
    4143           begin
    4144             cix := MyRO.nCity - 1;
    4145             while (cix >= 0) and (MyCity[cix].Loc <> Loc) do
    4146               dec(cix);
    4147             if cix >= 0 then
    4148               cm := Tribe[me].Color
    4149             else
    4150             begin
    4151               cix := MyRO.nEnemyCity - 1;
    4152               while (cix >= 0) and (MyRO.EnemyCity[cix].Loc <> Loc) do
    4153                 dec(cix);
    4154               if cix >= 0 then
    4155                 cm := Tribe[MyRO.EnemyCity[cix].Owner].Color
    4156             end;
    4157             cm := $808080 or cm shr 1; { increase brightness }
    4158             if y > 0 then begin
    4159               // 2x2 city dot covers two lines
    4160               PrevMiniPixel.SetXY(xm, y - 1);
    4161               PrevMiniPixel.Pixel^.B := cm shr 16;
    4162               PrevMiniPixel.Pixel^.G := cm shr 8 and $FF;
    4163               PrevMiniPixel.Pixel^.R := cm and $FF;
    4164             end;
    4165           end
    4166           else if (i = 0) and (MyMap[Loc] and fUnit <> 0) then
    4167           begin
    4168             uix := MyRO.nUn - 1;
    4169             while (uix >= 0) and (MyUn[uix].Loc <> Loc) do
    4170               dec(uix);
    4171             if uix >= 0 then
    4172               cm := Tribe[me].Color
    4173             else
    4174             begin
    4175               uix := MyRO.nEnemyUn - 1;
    4176               while (uix >= 0) and (MyRO.EnemyUn[uix].Loc <> Loc) do
    4177                 dec(uix);
    4178               if uix >= 0 then
    4179                 cm := Tribe[MyRO.EnemyUn[uix].Owner].Color
    4180             end;
    4181             cm := $808080 or cm shr 1; { increase brightness }
    4182           end
    4183           else if MapOptionChecked and (1 shl moPolitical) <> 0 then
    4184           begin
    4185             if MyMap[Loc] and fTerrain < fGrass then
    4186               cm := cmPolOcean
    4187             else if MyRO.Territory[Loc] < 0 then
    4188               cm := cmPolNone
    4189             else
    4190               cm := Tribe[MyRO.Territory[Loc]].Color;
    4191           end;
    4192           MiniPixel.Pixel^.B := cm shr 16;
    4193           MiniPixel.Pixel^.G := cm shr 8 and $FF;
    4194           MiniPixel.Pixel^.R := cm and $FF;
    4195         end;
    4196       end;
    4197     end;
    4198   end;
    4199   Mini.EndUpdate;
    4200 end;
    4201 
    42024108{$IFDEF LINUX}
    42034109// Can't do scrolling of DC under Linux, then fallback into BitBlt.
     
    43274233end;
    43284234
     4235procedure TMainScreen.MiniMapPaint;
     4236begin
     4237  MiniMap.Paint(MyMap, MapWidth, ClientMode, xxt, xwMini);
     4238end;
     4239
    43294240procedure TMainScreen.PaintAll;
    43304241begin
     
    43324243  xwMini := xw;
    43334244  ywMini := yw;
    4334   MiniPaint;
     4245  MiniMapPaint;
    43354246  PanelPaint;
    43364247end;
     
    43414252  xwMini := xw;
    43424253  ywMini := yw;
    4343   MiniPaint;
     4254  MiniMapPaint;
    43444255  CopyMiniToPanel;
    43454256  RectInvalidate(xMini + 2, TopBarHeight + MapHeight - overlap + yMini + 2,
     
    43514262begin
    43524263  BitBltCanvas(Panel.Canvas, xMini + 2, yMini + 2, G.lx * 2, G.ly,
    4353     Mini.Canvas, 0, 0);
     4264    MiniMap.Bitmap.Canvas, 0, 0);
    43544265  if MarkCityLoc >= 0 then
    43554266    Sprite(Panel, HGrSystem, xMini - 2 + (4 * G.lx + 2 * (MarkCityLoc mod G.lx)
     
    43584269      CityMark2.Height, CityMark2.Left, CityMark2.Top)
    43594270  else if ywmax <= 0 then
    4360     Frame(Panel.Canvas, xMini + 2 + G.lx - MapWidth div (xxt * 2), yMini + 2,
     4271    Frame(Panel.Canvas,
     4272      xMini + 2 + G.lx - MapWidth div (xxt * 2), yMini + 2,
    43614273      xMini + 1 + G.lx + MapWidth div (xxt * 2), yMini + 2 + G.ly - 1,
    43624274      MainTexture.clMark, MainTexture.clMark)
    43634275  else
    4364     Frame(Panel.Canvas, xMini + 2 + G.lx - MapWidth div (xxt * 2),
    4365       yMini + 2 + yw, xMini + 1 + G.lx + MapWidth div (xxt * 2),
    4366       yMini + yw + MapHeight div yyt, MainTexture.clMark, MainTexture.clMark);
     4276    Frame(Panel.Canvas,
     4277      xMini + 2 + G.lx - MapWidth div (xxt * 2), yMini + 2 + yw,
     4278      xMini + 1 + G.lx + MapWidth div (xxt * 2), yMini + yw + MapHeight div yyt,
     4279      MainTexture.clMark, MainTexture.clMark);
    43674280end;
    43684281
     
    50925005  xwMini := xw;
    50935006  ywMini := yw;
    5094   MiniPaint;
     5007  MiniMapPaint;
    50955008  CopyMiniToPanel;
    50965009  RectInvalidate(xMini + 2, TopBarHeight + MapHeight - overlap + yMini + 2,
     
    52985211      BrushLoc := MouseLoc;
    52995212      PaintLoc(MouseLoc, 2);
    5300       MiniPaint;
     5213      MiniMapPaint;
    53015214      BitBltCanvas(Panel.Canvas, xMini + 2, yMini + 2, G.lx * 2, G.ly,
    5302         Mini.Canvas, 0, 0);
     5215        MiniMap.Bitmap.Canvas, 0, 0);
    53035216      if ywmax <= 0 then
    53045217        Frame(Panel.Canvas, xMini + 2 + G.lx - MapWidth div (2 * xxt),
     
    75707483          yw := ywmax;
    75717484      end;
    7572       BitBltCanvas(Buffer.Canvas, 0, 0, G.lx * 2, G.ly, Mini.Canvas, 0, 0);
     7485      BitBltCanvas(Buffer.Canvas, 0, 0, G.lx * 2, G.ly, MiniMap.Bitmap.Canvas, 0, 0);
    75737486      if ywmax <= 0 then
    75747487        Frame(Buffer.Canvas, x - xMini - 2 - MapWidth div (xxt * 2), 0,
     
    76007513    xwMini := xw;
    76017514    ywMini := yw;
    7602     MiniPaint;
     7515    MiniMapPaint;
    76037516    PanelPaint;
    76047517  end;
     
    78817794      end
    78827795      else if Flag = tfAllTechs then
    7883         TellNewModels
     7796        TellNewModels;
    78847797    end;
    78857798  end;
     
    78927805    MapOptionChecked := MapOptionChecked xor (1 shl (Tag shr 8));
    78937806    SetMapOptions;
    7894     ButtonIndex := MapOptionChecked shr (Tag shr 8) and 1 + 2
     7807    ButtonIndex := MapOptionChecked shr (Tag shr 8) and 1 + 2;
    78957808  end;
    78967809  if Sender = MapBtn0 then
    78977810  begin
    7898     MiniPaint;
    7899     PanelPaint
     7811    MiniMapPaint;
     7812    PanelPaint;
    79007813  end // update mini map only
    79017814  else
Note: See TracChangeset for help on using the changeset viewer.