Changeset 192 for trunk/Start.pas


Ignore:
Timestamp:
May 7, 2020, 12:30:04 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Code cleanup.
  • Modified: Simplified initialization of brain pictures.
  • Modified: Use GetAiDir function for AI subdirectory.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Start.pas

    r190 r192  
    154154    procedure LoadConfig;
    155155    procedure SaveConfig;
     156    procedure LoadAiBrainsPictures;
    156157  end;
    157158
     
    433434  r0, r1: HRgn;
    434435  Location: TPoint;
     436  PlayerSlot: TPlayerSlot;
    435437  AIBrains: TBrains;
    436   PlayerSlot: TPlayerSlot;
    437438begin
    438439  PlayerSlots := TPlayerSlots.Create;
     
    528529    CustomizeBtn.ButtonIndex := 2;
    529530
    530   Brains[0].Picture := TBitmap.Create;
    531   Brains[0].Picture.SetSize(64, 64);
    532   BitBltCanvas(Brains[0].Picture.Canvas, 0, 0, 64, 64,
    533     GrExt[HGrSystem2].Data.Canvas, 1, 111);
    534   Brains[1].Picture := TBitmap.Create;
    535   Brains[1].Picture.SetSize(64, 64);
    536   BitBltCanvas(Brains[1].Picture.Canvas, 0, 0, 64, 64,
    537     GrExt[HGrSystem2].Data.Canvas, 66, 111);
    538   Brains[2].Picture := TBitmap.Create;
    539   Brains[2].Picture.SetSize(64, 64);
    540   BitBltCanvas(Brains[2].Picture.Canvas, 0, 0, 64, 64,
    541     GrExt[HGrSystem2].Data.Canvas, 131, 111);
    542   Brains[3].Picture := TBitmap.Create;
    543   Brains[3].Picture.SetSize(64, 64);
    544   BitBltCanvas(Brains[3].Picture.Canvas, 0, 0, 64, 64,
    545     GrExt[HGrSystem2].Data.Canvas, 131, 46);
    546 
    547   AIBrains := TBrains.Create(False);
    548   Brains.GetByKind(btAI, AIBrains);
    549   for i := 0 to AIBrains.Count - 1 do
    550   with AIBrains[I] do
    551   begin
    552     AIBrains[i].Picture := TBitmap.Create;
    553     if not LoadGraphicFile(AIBrains[i].Picture, HomeDir + 'AI' + DirectorySeparator +
    554       FileName + DirectorySeparator + FileName + '.png', gfNoError) then begin
    555       AIBrains[i].Picture.SetSize(64, 64);
    556       with AIBrains[i].Picture.Canvas do begin
    557         Brush.Color := $904830;
    558         FillRect(Rect(0, 0, 64, 64));
    559         Font.Assign(UniFont[ftTiny]);
    560         Font.Style := [];
    561         Font.Color := $5FDBFF;
    562         Textout(32 - TextWidth(FileName) div 2,
    563           32 - TextHeight(FileName) div 2, FileName);
    564       end;
    565     end;
    566   end;
    567   AIBrains.Free;
     531  BitBltBitmap(BrainNoTerm.Picture, 0, 0, 64, 64, GrExt[HGrSystem2].Data, 1, 111);
     532  BitBltBitmap(BrainSuperVirtual.Picture, 0, 0, 64, 64, GrExt[HGrSystem2].Data, 66, 111);
     533  BitBltBitmap(BrainTerm.Picture, 0, 0, 64, 64, GrExt[HGrSystem2].Data, 131, 111);
     534  BitBltBitmap(BrainRandom.Picture, 0, 0, 64, 64, GrExt[HGrSystem2].Data, 131, 46);
     535  LoadAiBrainsPictures;
    568536
    569537  EmptyPicture := TBitmap.Create;
     
    712680end;
    713681
     682procedure TStartDlg.LoadAiBrainsPictures;
     683var
     684  AIBrains: TBrains;
     685  I: Integer;
     686begin
     687  AIBrains := TBrains.Create(False);
     688  Brains.GetByKind(btAI, AIBrains);
     689  for i := 0 to AIBrains.Count - 1 do
     690  with AIBrains[I] do begin
     691    if not LoadGraphicFile(AIBrains[i].Picture, GetAiDir + DirectorySeparator +
     692      FileName + DirectorySeparator + FileName + '.png', gfNoError) then begin
     693      with AIBrains[i].Picture.Canvas do begin
     694        Brush.Color := $904830;
     695        FillRect(Rect(0, 0, 64, 64));
     696        Font.Assign(UniFont[ftTiny]);
     697        Font.Style := [];
     698        Font.Color := $5FDBFF;
     699        Textout(32 - TextWidth(FileName) div 2,
     700          32 - TextHeight(FileName) div 2, FileName);
     701      end;
     702    end;
     703  end;
     704  AIBrains.Free;
     705end;
     706
    714707procedure TStartDlg.DrawAction(y, IconIndex: integer; HeaderItem, TextItem: string);
    715708begin
     
    828821  if Page = pgMain then
    829822  begin
    830     if SelectedAction >= maNone then // mark selected action
     823    if SelectedAction <> maNone then // mark selected action
    831824      for i := 0 to (ClientWidth - 2 * ActionSideBorder) div wBuffer + 1 do
    832825      begin
     
    852845      if MainAction in ActionsOffered then
    853846        case MainAction of
    854           maConfig:
    855             DrawAction(y, 25, 'ACTIONHEADER_CONFIG', 'ACTION_CONFIG');
    856           maManual:
    857             DrawAction(y, 19, 'ACTIONHEADER_MANUAL', 'ACTION_MANUAL');
    858           maCredits:
    859             DrawAction(y, 22, 'ACTIONHEADER_CREDITS', 'ACTION_CREDITS');
    860           maAIDev:
    861             DrawAction(y, 24, 'ACTIONHEADER_AIDEV', 'ACTION_AIDEV');
     847          maConfig: DrawAction(y, 25, 'ACTIONHEADER_CONFIG', 'ACTION_CONFIG');
     848          maManual: DrawAction(y, 19, 'ACTIONHEADER_MANUAL', 'ACTION_MANUAL');
     849          maCredits: DrawAction(y, 22, 'ACTIONHEADER_CREDITS', 'ACTION_CREDITS');
     850          maAIDev: DrawAction(y, 24, 'ACTIONHEADER_AIDEV', 'ACTION_AIDEV');
    862851          maWeb:
    863852            begin
     
    10951084
    10961085procedure TStartDlg.FormShow(Sender: TObject);
    1097 var
    1098   x, y: integer;
    1099   PicturePixel: TPixelPointer;
    11001086begin
    11011087  SetMainTextureByAge(-1);
    11021088  List.Font.Color := MainTexture.clMark;
    11031089
    1104   Fill(EmptyPicture.Canvas, 0, 0, 64, 64, (wMaintexture - 64) div 2,
    1105     (hMaintexture - 64) div 2);
    1106   // darken texture for empty slot
    1107   EmptyPicture.BeginUpdate;
    1108   PicturePixel.Init(EmptyPicture);
    1109   for y := 0 to 63 do begin
    1110     for x := 0 to 64 - 1 do begin
    1111       PicturePixel.Pixel^.B := Max(PicturePixel.Pixel^.B - 28, 0);
    1112       PicturePixel.Pixel^.G := Max(PicturePixel.Pixel^.G - 28, 0);
    1113       PicturePixel.Pixel^.R := Max(PicturePixel.Pixel^.R - 28, 0);
    1114       PicturePixel.NextPixel;
    1115     end;
    1116     PicturePixel.NextLine;
    1117   end;
    1118   EmptyPicture.EndUpdate;
     1090  Fill(EmptyPicture.Canvas, Bounds(0, 0, 64, 64),
     1091    Point((wMaintexture - 64) div 2, (hMaintexture - 64) div 2));
     1092
     1093  DarkenImage(EmptyPicture, 28);
    11191094
    11201095  Difficulty[0] := Diff0;
Note: See TracChangeset for help on using the changeset viewer.