Changeset 137


Ignore:
Timestamp:
May 6, 2018, 6:17:16 PM (7 years ago)
Author:
chronos
Message:
  • Modified: Moved start screeb configuration loading part to separate method.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Start.pas

    r135 r137  
    4242    procedure FormPaint(Sender: TObject);
    4343    procedure FormShow(Sender: TObject);
     44    procedure FormHide(Sender: TObject);
     45    procedure FormCreate(Sender: TObject);
    4446    procedure FormDestroy(Sender: TObject);
    45     procedure FormCreate(Sender: TObject);
    4647    procedure BrainClick(Sender: TObject);
    4748    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
     
    5758    procedure Up2BtnClick(Sender: TObject);
    5859    procedure Down2BtnClick(Sender: TObject);
    59     procedure FormHide(Sender: TObject);
    6060    procedure QuitBtnClick(Sender: TObject);
    6161    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
     
    9292    ActionsOffered: set of 0 .. nMainActions - 1;
    9393    TurnValid, Tracking: boolean;
     94    DefaultAI: string;
    9495    procedure InitPopup(PopupIndex: integer);
    9596    procedure PaintInfo;
     
    99100    procedure SmartInvalidate(x0, y0, x1, y1: integer;
    100101      invalidateTab0: boolean = false); overload;
     102    procedure LoadConfig;
    101103  end;
    102104
     
    181183procedure TStartDlg.FormCreate(Sender: TObject);
    182184var
    183   x, y, i, ResolutionX, ResolutionY, ResolutionBPP, ResolutionFreq: Integer;
    184   ScreenMode: Integer;
    185   DefaultAI, s: string;
     185  x, y, i: Integer;
    186186  r0, r1: HRgn;
    187   Reg: TRegistry;
    188187  Location: TPoint;
    189188begin
    190   Reg := TRegistry.Create;
    191   with Reg do try
    192     // initialize AI assignment
    193     OpenKey(AppRegistryKey + '\AI', True);
    194     for I := 0 to nPlOffered - 1 do begin
    195       if i = 0 then s := ':StdIntf'
    196         else s := 'StdAI';
    197       if not ValueExists('Control' + IntToStr(i)) then
    198         WriteString('Control' + IntToStr(i), s);
    199       if not ValueExists('Diff' + IntToStr(i)) then
    200         WriteInteger('Diff' + IntToStr(i), 2);
    201     end;
    202     WriteInteger('MultiControl', 0);
    203 
    204     OpenKey(AppRegistryKey, True);
    205     if ValueExists('WorldSize') then WorldSize := Reg.ReadInteger('WorldSize')
    206       else WorldSize := DefaultWorldSize;
    207     if ValueExists('LandMass') then StartLandMass := Reg.ReadInteger('LandMass')
    208       else StartLandMass := DefaultLandMass;
    209     if ValueExists('MaxTurn') then MaxTurn := Reg.ReadInteger('MaxTurn')
    210       else MaxTurn := 800;
    211     if ValueExists('DefaultAI') then DefaultAI := Reg.ReadString('DefaultAI')
    212       else DefaultAI := 'StdAI';
    213     if ValueExists('AutoEnemies') then AutoEnemies := Reg.ReadInteger('AutoEnemies')
    214       else AutoEnemies := 8;
    215     if ValueExists('AutoDiff') then AutoDiff := Reg.ReadInteger('AutoDiff')
    216       else AutoDiff := 1;
    217 
    218     if ValueExists('ScreenMode') then
    219       ScreenMode := ReadInteger('ScreenMode')
    220       else ScreenMode := 1;
    221     FullScreen := ScreenMode > 0;
    222     if ValueExists('ResolutionX') then
    223       ResolutionX := ReadInteger('ResolutionX');
    224     if ValueExists('ResolutionY') then
    225       ResolutionY := ReadInteger('ResolutionY');
    226     if ValueExists('ResolutionBPP') then
    227       ResolutionBPP := ReadInteger('ResolutionBPP');
    228     if ValueExists('ResolutionFreq') then
    229       ResolutionFreq := ReadInteger('ResolutionFreq');
    230     {$IFDEF WINDOWS}
    231     if ScreenMode = 2 then
    232       ChangeResolution(ResolutionX, ResolutionY, ResolutionBPP,
    233         ResolutionFreq);
    234     {$ENDIF}
    235   finally
    236     Free;
    237   end;
     189  LoadConfig;
    238190
    239191  ActionsOffered := [maManual, maCredits, maWeb];
     
    251203    bixDefault := bixFirstAI; // default AI not found, use any
    252204
    253   DirectDlg.left := (screen.width - DirectDlg.width) div 2;
    254   DirectDlg.top := (screen.height - DirectDlg.height) div 2;
     205  DirectDlg.Left := (Screen.Width - DirectDlg.Width) div 2;
     206  DirectDlg.Top := (screen.Height - DirectDlg.Height) div 2;
    255207
    256208  if FullScreen then
    257209  begin
    258     Location := Point(Screen.Width, Screen.Height);
    259     Location := Point((Screen.width - 800) * 3 div 8,
    260       Screen.height - Height - (Screen.height - 600) div 3);
     210    Location := Point((Screen.Width - 800) * 3 div 8,
     211      Screen.Height - Height - (Screen.Height - 600) div 3);
    261212    Left := Location.X;
    262213    Top := Location.Y;
     
    266217    CombineRgn(r0, r0, r1, RGN_DIFF);
    267218    DeleteObject(r1);
    268     r1 := CreateRectRgn(QuitBtn.left, QuitBtn.top, QuitBtn.left + QuitBtn.width,
    269       QuitBtn.top + QuitBtn.height);
     219    r1 := CreateRectRgn(QuitBtn.Left, QuitBtn.Top, QuitBtn.Left + QuitBtn.Width,
     220      QuitBtn.top + QuitBtn.Height);
    270221    CombineRgn(r0, r0, r1, RGN_OR);
    271222    DeleteObject(r1);
    272     SetWindowRgn(Handle, r0, false);
     223    SetWindowRgn(Handle, r0, False);
    273224    DeleteObject(r0); // causes crash with Windows 95
    274225  end
    275226  else
    276227  begin
    277     left := (screen.width - width) div 2;
    278     top := (screen.height - height) div 2;
     228    Left := (Screen.Width - Width) div 2;
     229    Top := (Screen.Height - Height) div 2;
    279230  end;
    280231
     
    417368  InvalidateRgn(Handle, r0, false);
    418369  DeleteObject(r0);
     370end;
     371
     372procedure TStartDlg.LoadConfig;
     373var
     374  Reg: TRegistry;
     375  I: Integer;
     376  S: string;
     377  ResolutionX, ResolutionY, ResolutionBPP, ResolutionFreq: Integer;
     378  ScreenMode: Integer;
     379begin
     380  Reg := TRegistry.Create;
     381  with Reg do try
     382    // Initialize AI assignment
     383    OpenKey(AppRegistryKey + '\AI', True);
     384    for I := 0 to nPlOffered - 1 do begin
     385      if I = 0 then S := ':StdIntf'
     386        else S := 'StdAI';
     387      if not ValueExists('Control' + IntToStr(I)) then
     388        WriteString('Control' + IntToStr(I), S);
     389      if not ValueExists('Diff' + IntToStr(I)) then
     390        WriteInteger('Diff' + IntToStr(I), 2);
     391    end;
     392    WriteInteger('MultiControl', 0);
     393
     394    OpenKey(AppRegistryKey, True);
     395    if ValueExists('WorldSize') then WorldSize := Reg.ReadInteger('WorldSize')
     396      else WorldSize := DefaultWorldSize;
     397    if ValueExists('LandMass') then StartLandMass := Reg.ReadInteger('LandMass')
     398      else StartLandMass := DefaultLandMass;
     399    if ValueExists('MaxTurn') then MaxTurn := Reg.ReadInteger('MaxTurn')
     400      else MaxTurn := 800;
     401    if ValueExists('DefaultAI') then DefaultAI := Reg.ReadString('DefaultAI')
     402      else DefaultAI := 'StdAI';
     403    if ValueExists('AutoEnemies') then AutoEnemies := Reg.ReadInteger('AutoEnemies')
     404      else AutoEnemies := 8;
     405    if ValueExists('AutoDiff') then AutoDiff := Reg.ReadInteger('AutoDiff')
     406      else AutoDiff := 1;
     407
     408    if ValueExists('ScreenMode') then
     409      ScreenMode := ReadInteger('ScreenMode')
     410      else ScreenMode := 1;
     411    FullScreen := ScreenMode > 0;
     412    if ValueExists('ResolutionX') then
     413      ResolutionX := ReadInteger('ResolutionX');
     414    if ValueExists('ResolutionY') then
     415      ResolutionY := ReadInteger('ResolutionY');
     416    if ValueExists('ResolutionBPP') then
     417      ResolutionBPP := ReadInteger('ResolutionBPP');
     418    if ValueExists('ResolutionFreq') then
     419      ResolutionFreq := ReadInteger('ResolutionFreq');
     420    {$IFDEF WINDOWS}
     421    if ScreenMode = 2 then
     422      ChangeResolution(ResolutionX, ResolutionY, ResolutionBPP,
     423        ResolutionFreq);
     424    {$ENDIF}
     425  finally
     426    Free;
     427  end;
    419428end;
    420429
Note: See TracChangeset for help on using the changeset viewer.