Ignore:
Timestamp:
Apr 24, 2021, 11:41:07 PM (4 years ago)
Author:
chronos
Message:
  • Modified: Merged changes from trunk r377.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/highdpi/Start.pas

    r361 r378  
    77  UDpiControls, GameServer, Messg, ButtonBase, ButtonA, ButtonC, ButtonB, Area, Types,
    88  LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms, StdCtrls,
    9   Menus, Registry,  DrawDlg, fgl, Protocol, UMiniMap;
     9  Menus, Registry,  DrawDlg, fgl, Protocol, UMiniMap, UBrain;
    1010
    1111type
     12
     13  { TPlayerSlot }
     14
    1215  TPlayerSlot = class
    1316    DiffUpBtn: TButtonC;
     
    5457    AutoEnemyDownBtn: TButtonC;
    5558    ReplayBtn: TButtonB;
     59    procedure ListKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
     60    procedure ListKeyPress(Sender: TObject; var Key: char);
    5661    procedure StartBtnClick(Sender: TObject);
    5762    procedure FormPaint(Sender: TObject);
     
    8489    procedure AutoEnemyDownBtnClick(Sender: TObject);
    8590    procedure ReplayBtnClick(Sender: TObject);
    86   public
    87     EmptyPicture: TDpiBitmap;
    88     procedure UpdateFormerGames;
    89     procedure UpdateMaps;
    9091  private
    9192    WorldSize: Integer;
     
    134135    procedure LoadAiBrainsPictures;
    135136    procedure UpdateInterface;
     137    procedure ShowSettings;
     138  public
     139    EmptyPicture: TDpiBitmap;
     140    procedure UpdateFormerGames;
     141    procedure UpdateMaps;
    136142  end;
    137143
     
    356362  I: Integer;
    357363  S: string;
     364  {$IFDEF WINDOWS}
    358365  ResolutionX, ResolutionY, ResolutionBPP, ResolutionFreq: Integer;
     366  {$ENDIF}
    359367  ScreenMode: Integer;
    360368begin
     
    394402    if ValueExists('LastGame') then LastGame := Reg.ReadString('LastGame')
    395403       else LastGame := '';
     404    if ValueExists('NetworkEnabled') then NetworkEnabled := Reg.ReadBool('NetworkEnabled')
     405       else NetworkEnabled := False;
    396406
    397407    if ValueExists('ScreenMode') then
     
    399409      else ScreenMode := 1;
    400410    FullScreen := ScreenMode > 0;
     411    if ValueExists('MultiControl') then
     412      MultiControl := ReadInteger('MultiControl')
     413      else MultiControl := 0;
     414    {$IFDEF WINDOWS}
    401415    if ValueExists('ResolutionX') then
    402416      ResolutionX := ReadInteger('ResolutionX');
     
    407421    if ValueExists('ResolutionFreq') then
    408422      ResolutionFreq := ReadInteger('ResolutionFreq');
    409     if ValueExists('MultiControl') then
    410       MultiControl := ReadInteger('MultiControl')
    411       else MultiControl := 0;
    412     {$IFDEF WINDOWS}
    413423    if ScreenMode = 2 then
    414424      ChangeResolution(ResolutionX, ResolutionY, ResolutionBPP,
     
    436446    WriteInteger('StartTab', Integer(ShowTab));
    437447    WriteString('LastGame', LastGame);
     448    WriteBool('NetworkEnabled', NetworkEnabled);
    438449  finally
    439450    Free;
     
    492503      (DpiScreen.Height - Height) div 2, Width, Height)
    493504  end;
     505end;
     506
     507procedure TStartDlg.ShowSettings;
     508begin
     509  SettingsDlg := TSettingsDlg.Create(nil);
     510  if SettingsDlg.ShowModal = mrOk then begin
     511    LoadAssets;
     512    Invalidate;
     513    UpdateInterface;
     514    Background.UpdateInterface;
     515  end;
     516  FreeAndNil(SettingsDlg);
    494517end;
    495518
     
    750773        yMain + 164 { y0Mini-77 } , Phrases.Lookup('STARTCONTROLS', 16));
    751774      if AutoDiff = 1 then
    752         FrameImage(Canvas, BrainBeginner.Picture, xDefault, yDefault, 64,
     775        FrameImage(Canvas, Brains.GetBeginner.Picture, xDefault, yDefault, 64,
    753776          64, 0, 0, false)
    754777      else
     
    908931    FormerGames.Delete(I);
    909932    if ListIndex[tbNew] = I then
    910       ListIndex[tbNew] := 0
     933      ListIndex[tbNew] := 0;
    911934  end;
    912935end;
     
    968991
    969992          OpenKey(AppRegistryKey, True);
    970           if AutoDiff > 0 then
    971           begin
    972             WriteString('DefaultAI', BrainDefault.FileName);
    973             SlotAvailable := 0; // PlayerSlot will be invalid hereafter
    974             PlayersBrain[0] := BrainTerm;
    975             Difficulty[0] := PlayerAutoDiff[AutoDiff];
    976             for I := 1 to nPl - 1 do
    977               if (Page = pgStartRandom) and (I <= AutoEnemies) or
    978                 (Page = pgStartMap) and (I < nMapStartPositions) then begin
    979                 if AutoDiff = 1 then PlayersBrain[I] := BrainBeginner
    980                   else PlayersBrain[I] := BrainDefault;
    981                 Difficulty[I] := EnemyAutoDiff[AutoDiff];
    982               end  else PlayersBrain[I] := nil;
    983           end else begin
    984             for I := 6 to 8 do
    985               if (PlayersBrain[0].Kind <> btNoTerm) and (MultiControl and (1 shl I) <> 0)
    986               then begin
    987                 PlayersBrain[I + 3] := PlayersBrain[I];
    988                 Difficulty[I + 3] := Difficulty[I];
    989                 PlayersBrain[I + 6] := PlayersBrain[I];
    990                 Difficulty[I + 6] := Difficulty[I];
    991               end else begin
    992                 PlayersBrain[I + 3] := nil;
    993                 PlayersBrain[I + 6] := nil;
    994               end;
     993          if BrainDefault.Kind <> btNetworkClient then begin
     994            if AutoDiff > 0 then begin
     995              WriteString('DefaultAI', BrainDefault.FileName);
     996              SlotAvailable := 0; // PlayerSlot will be invalid hereafter
     997              PlayersBrain[0] := BrainTerm;
     998              Difficulty[0] := PlayerAutoDiff[AutoDiff];
     999              for I := 1 to nPl - 1 do
     1000                if (Page = pgStartRandom) and (I <= AutoEnemies) or
     1001                  (Page = pgStartMap) and (I < nMapStartPositions) then begin
     1002                  if AutoDiff = 1 then PlayersBrain[I] := Brains.GetBeginner
     1003                    else PlayersBrain[I] := BrainDefault;
     1004                  Difficulty[I] := EnemyAutoDiff[AutoDiff];
     1005                end else PlayersBrain[I] := nil;
     1006            end else begin
     1007              for I := 6 to 8 do
     1008                if (PlayersBrain[0].Kind <> btNoTerm) and (MultiControl and (1 shl I) <> 0)
     1009                then begin
     1010                  PlayersBrain[I + 3] := PlayersBrain[I];
     1011                  Difficulty[I + 3] := Difficulty[I];
     1012                  PlayersBrain[I + 6] := PlayersBrain[I];
     1013                  Difficulty[I + 6] := Difficulty[I];
     1014                end else begin
     1015                  PlayersBrain[I + 3] := nil;
     1016                  PlayersBrain[I + 6] := nil;
     1017                end;
     1018            end;
    9951019          end;
    9961020
     
    10271051      end;
    10281052  end;
     1053end;
     1054
     1055procedure TStartDlg.ListKeyPress(Sender: TObject; var Key: char);
     1056begin
     1057  if Key = #13 then StartBtnClick(Sender);
     1058end;
     1059
     1060procedure TStartDlg.ListKeyDown(Sender: TObject; var Key: Word;
     1061  Shift: TShiftState);
     1062const
     1063  DelKey = 46;
     1064begin
     1065  if Key = DelKey then DeleteBtnClick(Sender)
     1066    else FormKeyDown(Sender, Key, Shift);
    10291067end;
    10301068
     
    11621200  AIBrains: TBrains;
    11631201begin
     1202  FixedLines := 0;
    11641203  PlayerPopupIndex := PlayerIndex;
    11651204  EmptyMenu(PopupMenu1.Items);
    11661205  if PlayerPopupIndex < 0 then begin // select default AI
    1167     FixedLines := 0;
     1206    if NetworkEnabled then begin
     1207      OfferBrain(BrainNetworkClient, FixedLines);
     1208      Inc(FixedLines);
     1209    end;
     1210
     1211    MenuItem := TDpiMenuItem.Create(PopupMenu1);
     1212    MenuItem.Caption := '-';
     1213    PopupMenu1.Items.Add(MenuItem);
     1214
     1215    Inc(FixedLines);
    11681216    if Brains.GetKindCount(btAI) >= 2 then begin
    11691217      OfferBrain(BrainRandom, FixedLines);
     
    11771225    FreeAndNil(AIBrains);
    11781226  end else begin
    1179     FixedLines := 0;
    11801227    if PlayerPopupIndex > 0 then begin
    11811228      OfferBrain(nil, FixedLines);
     
    11891236      end;
    11901237    if PlayerPopupIndex > 0 then begin
     1238      if NetworkEnabled then begin
     1239        OfferBrain(BrainNetworkServer, FixedLines);
     1240        Inc(FixedLines);
     1241      end;
     1242
    11911243      MenuItem := TDpiMenuItem.Create(PopupMenu1);
    11921244      MenuItem.Caption := '-';
     
    12671319          begin
    12681320            PlayersBrain[0] := BrainSuperVirtual;
    1269             Difficulty[0] := 0
     1321            Difficulty[0] := 0;
    12701322          end;
    12711323          if PlayersBrain[0].Kind in [btNoTerm, btSuperVirtual] then
     
    14241476    ChangeTab(TStartTab((x - TabOffset) div TabSize));
    14251477  end
    1426   else if Page = pgMain then
    1427   begin
     1478  else if Page = pgMain then begin
    14281479    case SelectedAction of
    1429       maConfig:
    1430         begin
    1431           SettingsDlg := TSettingsDlg.Create(nil);
    1432           if SettingsDlg.ShowModal = mrOk then begin
    1433             LoadAssets;
    1434             Invalidate;
    1435             UpdateInterface;
    1436             Background.UpdateInterface;
    1437           end;
    1438           FreeAndNil(SettingsDlg);
    1439         end;
    1440       maManual:
    1441         DirectHelp(cStartHelp);
    1442       maCredits:
    1443         DirectHelp(cStartCredits);
    1444       maAIDev:
    1445         OpenDocument(HomeDir + AITemplateFileName);
    1446       maWeb:
    1447         OpenURL(CevoHomepage);
     1480      maConfig: ShowSettings;
     1481      maManual: DirectHelp(cStartHelp);
     1482      maCredits: DirectHelp(cStartCredits);
     1483      maAIDev: OpenDocument(HomeDir + AITemplateFileName);
     1484      maWeb: OpenURL(CevoHomepage);
    14481485    end;
    14491486  end
     
    14601497        else
    14611498          PopupMenu1.Popup(left + xBrain[I] + 4, top + yBrain[I] + 4);
    1462       end
     1499      end;
    14631500  end
    14641501  else if (AutoDiff > 1) and ((Page = pgStartRandom) or (Page = pgStartMap)) and
Note: See TracChangeset for help on using the changeset viewer.