Changeset 189 for trunk/Start.pas


Ignore:
Timestamp:
May 7, 2020, 12:46:55 AM (5 years ago)
Author:
chronos
Message:
  • Added: New Global unit with global constants.
  • Modified: Multiple occurence of string constants used for subdirectories replaced by functions.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Start.pas

    r188 r189  
    153153      invalidateTab0: boolean = false); overload;
    154154    procedure LoadConfig;
     155    procedure SaveConfig;
    155156  end;
    156157
     
    162163
    163164uses
    164   Directories, Direct, ScreenTools, Inp, Back, Locale, PixelPointer;
     165  Global, Directories, Direct, ScreenTools, Inp, Back, Locale, PixelPointer;
    165166
    166167{$R *.lfm}
    167168
    168169const
    169   CevoExt = '.cevo';
    170   CevoMapExt = '.cevo map';
    171170  // predefined world size
    172171  // attention: lx*ly+1 must be prime!
     
    467466  DirectDlg.Top := (Screen.Height - DirectDlg.Height) div 2;
    468467
    469   if FullScreen then
    470   begin
     468  if FullScreen then begin
    471469    Location := Point((Screen.Width - 800) * 3 div 8,
    472470      Screen.Height - Height - (Screen.Height - 600) div 3);
     
    484482    SetWindowRgn(Handle, r0, False);
    485483    DeleteObject(r0); // causes crash with Windows 95
    486   end
    487   else
    488   begin
     484  end else begin
    489485    Left := (Screen.Width - Width) div 2;
    490486    Top := (Screen.Height - Height) div 2;
     
    599595procedure TStartDlg.FormDestroy(Sender: TObject);
    600596begin
     597  SaveConfig;
    601598  FreeAndNil(FormerGames);
    602599  FreeAndNil(Maps);
     
    622619      DeleteObject(r1);
    623620    end;
    624   if not invalidateTab0 then
    625   begin
     621  if not invalidateTab0 then begin
    626622    r1 := CreateRectRgn(0, 0, 6 + 36, 3 + 38); // tab 0 icon
    627623    CombineRgn(r0, r0, r1, RGN_DIFF);
     
    652648        WriteInteger('Diff' + IntToStr(I), 2);
    653649    end;
    654     WriteInteger('MultiControl', 0);
    655650
    656651    OpenKey(AppRegistryKey, True);
     652    if ValueExists('Gamma') then Gamma := ReadInteger('Gamma')
     653      else Gamma := 100;
     654    if Gamma <> 100 then InitGammaLookupTable;
     655    if ValueExists('Locale') then LocaleCode := ReadString('Locale')
     656      else LocaleCode := '';
    657657    if ValueExists('WorldSize') then WorldSize := Reg.ReadInteger('WorldSize')
    658658      else WorldSize := DefaultWorldSize;
     
    680680    if ValueExists('ResolutionFreq') then
    681681      ResolutionFreq := ReadInteger('ResolutionFreq');
     682    if ValueExists('MultiControl') then
     683      MultiControl := ReadInteger('MultiControl')
     684      else MultiControl := 0;
    682685    {$IFDEF WINDOWS}
    683686    if ScreenMode = 2 then
     
    685688        ResolutionFreq);
    686689    {$ENDIF}
     690  finally
     691    Free;
     692  end;
     693end;
     694
     695procedure TStartDlg.SaveConfig;
     696var
     697  Reg: TRegistry;
     698begin
     699  Reg := TRegistry.Create;
     700  with Reg do try
     701    OpenKey(AppRegistryKey, True);
     702    WriteInteger('WorldSize', WorldSize);
     703    WriteInteger('LandMass', StartLandMass);
     704    WriteString('Locale', LocaleCode);
     705    WriteInteger('Gamma', Gamma);
     706    if FullScreen then WriteInteger('ScreenMode', 1)
     707      else WriteInteger('ScreenMode', 0);
     708    WriteInteger('MultiControl', MultiControl);
    687709  finally
    688710    Free;
     
    11631185          end;
    11641186
    1165           // save settings and AI assignment
     1187          // Save settings and AI assignment
    11661188          if Page = pgStartRandom then begin
    1167             WriteInteger('WorldSize', WorldSize);
    1168             WriteInteger('LandMass', StartLandMass);
    1169 
     1189            SaveConfig;
    11701190            OpenKey(AppRegistryKey + '\AI', True);
    11711191            if AutoDiff < 0 then
     
    11771197                WriteInteger('Diff' + IntToStr(I), Difficulty[I]);
    11781198              end;
    1179             WriteInteger('MultiControl', MultiControl);
    11801199          end;
    11811200
     
    12371256        MapFileName := Format(Phrases.Lookup('MAP'), [MapCount]) + CevoMapExt;
    12381257        EditMap(MapFileName, WorldSizes[WorldSize].X, WorldSizes[WorldSize].Y, StartLandMass);
    1239       end
    1240   end
     1258      end;
     1259  end;
    12411260end;
    12421261
     
    15051524                      PlayersBrain[p1] := Brains[j];
    15061525              end;
    1507               MultiControl := Reg.ReadInteger('MultiControl');
    15081526            finally
    15091527              Free;
     
    16551673        OpenDocument(pchar(HomeDir + 'AI Template' + DirectorySeparator + 'AI development manual.html'));
    16561674      maWeb:
    1657         OpenURL('http://c-evo.org')
     1675        OpenURL(CevoHomepage);
    16581676    end;
    16591677  end
Note: See TracChangeset for help on using the changeset viewer.