Changeset 591 for trunk/MiniMap.pas


Ignore:
Timestamp:
Jul 24, 2024, 11:02:31 PM (8 weeks ago)
Author:
chronos
Message:
  • Modified: Draw graphical preview for maps which doesn't have associated image.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MiniMap.pas

    r590 r591  
    2626    procedure LoadFromLogFile(FileName: string; var LastTurn: Integer; DefaultSize: TPoint);
    2727    procedure LoadFromMapFile(FileName: string; var nMapLandTiles, nMapStartPositions: Integer);
     28    procedure PaintMap(Map: TMap);
    2829    procedure PaintRandom(Brightness, StartLandMass: Integer; WorldSize: TPoint);
    2930    procedure PaintFile(SaveMap: TMapArray);
     
    111112procedure TMiniMap.LoadFromMapFile(FileName: string; var nMapLandTiles, nMapStartPositions: Integer);
    112113var
    113   x, y: integer;
    114   MapRow: array [0 .. lxmax - 1] of Cardinal;
     114  X, Y: Integer;
    115115  ImageFileName: string;
    116116  Map: TMap;
    117117  Tile: Cardinal;
     118  PaintMapEnabled: Boolean;
    118119begin
    119120  ImageFileName := Copy(FileName, 1, Length(FileName) - Length(CevoMapExt)) + CevoMapPictureExt;
     
    126127      Bitmap.Height := MaxHeightMapLogo;
    127128    Size := Point(Bitmap.Width div 2, Bitmap.Height);
     129    PaintMapEnabled := False;
    128130  end else begin
    129     Mode := mmNone;
     131    Mode := mmPicture;
    130132    Size := Point(MaxWidthMapLogo, MaxHeightMapLogo);
     133    PaintMapEnabled := True;
    131134  end;
    132135
     
    136139    nMapLandTiles := 0;
    137140    nMapStartPositions := 0;
    138     for y := 0 to Map.Size.Y - 1 do begin
     141    for Y := 0 to Map.Size.Y - 1 do begin
    139142      for X := 0 to Map.Size.X - 1 do begin
    140143        Tile := Map.Tiles[Y * Map.Size.X + X];
     
    148151    if nMapStartPositions > nPl then
    149152      nMapStartPositions := nPl;
     153
     154    if PaintMapEnabled then begin
     155      Size := Map.Size;
     156      PaintMap(Map);
     157    end;
    150158  finally
    151159    FreeAndNil(Map);
     160  end;
     161end;
     162
     163procedure TMiniMap.PaintMap(Map: TMap);
     164var
     165  i, x, y, xm, cm, Tile, OwnColor, EnemyColor: integer;
     166  MiniPixel: TPixelPointer;
     167  PrevMiniPixel: TPixelPointer;
     168  xx, yy: Integer;
     169begin
     170  OwnColor := HGrSystem.Data.Canvas.Pixels[95, 67];
     171  EnemyColor := HGrSystem.Data.Canvas.Pixels[96, 67];
     172  Bitmap.PixelFormat := TPixelFormat.pf24bit;
     173  Bitmap.SetSize(Size.X * 2, Size.Y);
     174  if Mode = mmPicture then begin
     175    Bitmap.BeginUpdate;
     176    MiniPixel := TPixelPointer.Create(Bitmap);
     177    PrevMiniPixel := TPixelPointer.Create(Bitmap);
     178    xx := ScaleToNative(Size.X);
     179    yy := ScaleToNative(Size.Y);
     180    for y := 0 to yy - 1 do begin
     181      for x := 0 to xx - 1 do begin
     182        for i := 0 to 1 do begin
     183          xm := (x * 2 + i + y and 1) mod (xx * 2);
     184          MiniPixel.SetX(xm);
     185          Tile := Map.Tiles[ScaleFromNative(x) + Size.X * ScaleFromNative(y)];
     186          if Tile and fTerrain = fUNKNOWN then
     187            cm := $000000
     188          else if Tile and smCity <> 0 then begin
     189            if Tile and smOwned <> 0 then cm := OwnColor
     190              else cm := EnemyColor;
     191            if y > 0 then begin
     192              // 2x2 city dot covers two lines
     193              PrevMiniPixel.SetX(xm);
     194              if (PByte(PrevMiniPixel.Pixel) >= Bitmap.RawImage.Data) and
     195              (PByte(PrevMiniPixel.Pixel) < (Bitmap.RawImage.Data + yy * PrevMiniPixel.BytesPerLine)) then begin
     196                PrevMiniPixel.PixelB := cm shr 16;
     197                PrevMiniPixel.PixelG:= cm shr 8 and $FF;
     198                PrevMiniPixel.PixelR := cm and $FF;
     199              end;
     200            end;
     201          end
     202          else if (i = 0) and (Tile and smUnit <> 0) then begin
     203            if Tile and smOwned <> 0 then cm := OwnColor
     204              else cm := EnemyColor;
     205          end else
     206            cm := Colors[Tile and fTerrain, i];
     207          if (PByte(MiniPixel.Pixel) >= Bitmap.RawImage.Data) and
     208          (PByte(MiniPixel.Pixel) < (Bitmap.RawImage.Data + yy * MiniPixel.BytesPerLine)) then begin
     209            MiniPixel.PixelB := (cm shr 16) and $ff;
     210            MiniPixel.PixelG := (cm shr 8) and $ff;
     211            MiniPixel.PixelR := (cm shr 0) and $ff;
     212          end;
     213        end;
     214      end;
     215      MiniPixel.NextLine;
     216      if y > 0 then PrevMiniPixel.NextLine;
     217    end;
     218    Bitmap.EndUpdate;
    152219  end;
    153220end;
Note: See TracChangeset for help on using the changeset viewer.