Ignore:
Timestamp:
Mar 25, 2021, 2:09:42 PM (4 years ago)
Author:
chronos
Message:
  • Modified: Use enumeration type for MapOptions and game options.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LocalPlayer/Term.pas

    r326 r327  
    271271    procedure InitModule;
    272272    procedure InitTurn(NewPlayer: integer);
     273    procedure SaveMenuItemsState;
    273274    procedure ScrollBarUpdate(Sender: TObject);
    274275    procedure ArrangeMidPanel;
     
    421422  // lines of system icons in icons.bmp before improvements
    422423
    423   // save options apart from what's defined by SaveOption
    424   soTellAI = 30;
    425   soExtraMask = $40000000;
    426 
    427424  nCityEventPriority = 16;
    428425  CityEventPriority: array [0 .. nCityEventPriority - 1] of integer =
     
    485482  Age: Integer;
    486483  UnFocus: Integer;
    487   OptionChecked: Integer;
    488   MapOptionChecked: Integer;
     484  OptionChecked: TSaveOptions;
     485  MapOptionChecked: TMapOptions;
    489486  nLostArmy: Integer;
    490487  ScienceSum: Integer;
     
    570567  flImmUpdate = $0002;
    571568
    572   nSaveOption = 22;
    573 
    574569var
    575570  Jump: array [0 .. nPl - 1] of integer;
     
    577572  SmallScreen, GameOK, MapValid, skipped, idle: boolean;
    578573
    579   SaveOption: array [0..nSaveOption - 1] of integer;
     574  SaveOption: array of integer;
    580575  MiniColors: array [0..11, 0..1] of TColor;
    581576  MainMap: TIsoMap;
     
    12661261procedure TMainScreen.SetMapOptions;
    12671262begin
    1268   MiniMap.Options := MapOptionChecked;
    1269   IsoEngine.Options := MapOptionChecked;
     1263  MiniMap.MapOptions := MapOptionChecked;
     1264  IsoEngine.MapOptions := MapOptionChecked;
    12701265  if ClientMode = cEditMap then
    1271     IsoEngine.Options := IsoEngine.Options or (1 shl moEditMode);
     1266    IsoEngine.MapOptions := IsoEngine.MapOptions + [moEditMode];
    12721267  if mLocCodes.Checked then
    1273     IsoEngine.Options := IsoEngine.Options or (1 shl moLocCodes);
     1268    IsoEngine.MapOptions := IsoEngine.MapOptions + [moLocCodes];
    12741269end;
    12751270
     
    34583453  BaseWin.CreateOffscreen(Offscreen);
    34593454
    3460    // define which menu settings to save
     3455  // define which menu settings to save
     3456  SetLength(SaveOption, 22);
    34613457  SaveOption[0] := mAlEffectiveMovesOnly.Tag;
    34623458  SaveOption[1] := mEnMoves.Tag;
     
    34903486  for i := 0 to ComponentCount - 1 do
    34913487    if Components[i].Tag and $FF <> 0 then
    3492       if Components[i] is TMenuItem then
    3493       begin
     3488      if Components[i] is TMenuItem then begin
    34943489        TMenuItem(Components[i]).Caption := Phrases.Lookup('CONTROLS',
    34953490          -1 + Components[i].Tag and $FF);
    3496         for j := 0 to nSaveOption - 1 do
     3491        for j := 0 to Length(SaveOption) - 1 do
    34973492          if Components[i].Tag and $FF = SaveOption[j] then
    3498             TMenuItem(Components[i]).Checked := ((1 shl j) and OptionChecked) <> 0;
    3499       end
    3500       else if Components[i] is TButtonBase then
    3501       begin
     3493            TMenuItem(Components[i]).Checked := TSaveOption(j) in OptionChecked;
     3494      end else
     3495      if Components[i] is TButtonBase then begin
    35023496        TButtonBase(Components[i]).Hint := Phrases.Lookup('CONTROLS',
    35033497          -1 + Components[i].Tag and $FF);
     
    35053499          (TButtonC(Components[i]).ButtonIndex <> 1) then
    35063500          TButtonC(Components[i]).ButtonIndex :=
    3507             MapOptionChecked shr (Components[i].Tag shr 8) and 1 + 2
     3501            Integer(MapOptionChecked) shr (Components[i].Tag shr 8) and 1 + 2
    35083502      end;
    35093503
     
    50155009procedure TMainScreen.Timer1Timer(Sender: TObject);
    50165010var
    5017   dx, dy, speed: integer;
     5011  dx, dy, ScrollSpeed: integer;
    50185012begin
    50195013  if idle and (me >= 0) and (GameMode <> cMovie) then
     
    50365030      if Application.Active and not mScrollOff.Checked then
    50375031      begin
    5038         if mScrollFast.Checked then
    5039           speed := 2
    5040         else
    5041           speed := 1;
     5032        if mScrollFast.Checked then ScrollSpeed := 2
     5033          else ScrollSpeed := 1;
    50425034        dx := 0;
    50435035        dy := 0;
    50445036        if Mouse.CursorPos.y < Screen.height - PanelHeight then
    50455037          if Mouse.CursorPos.x = 0 then
    5046             dx := -speed // scroll left
     5038            dx := -ScrollSpeed // scroll left
    50475039          else if Mouse.CursorPos.x = Screen.width - 1 then
    5048             dx := speed; // scroll right
     5040            dx := ScrollSpeed; // scroll right
    50495041        if Mouse.CursorPos.y = 0 then
    5050           dy := -speed // scroll up
     5042          dy := -ScrollSpeed // scroll up
    50515043        else if (Mouse.CursorPos.y = Screen.height - 1) and
    50525044          (Mouse.CursorPos.x >= TerrainBtn.Left + TerrainBtn.width) and
    50535045          (Mouse.CursorPos.x < xRightPanel + 10 - 8) then
    5054           dy := speed; // scroll down
     5046          dy := ScrollSpeed; // scroll down
    50555047        if (dx <> 0) or (dy <> 0) then
    50565048        begin
     
    63826374begin
    63836375  IsoEngine.pDebugMap := p;
    6384   IsoEngine.Options := IsoEngine.Options and not(1 shl moLocCodes);
     6376  IsoEngine.MapOptions := IsoEngine.MapOptions - [moLocCodes];
    63856377  mLocCodes.Checked := false;
    63866378  MapValid := false;
     
    77067698var
    77077699  Reg: TRegistry;
    7708   DefaultOptionChecked: Integer;
    7709 begin
    7710   DefaultOptionChecked := 1 shl 1 + 1 shl 7 + 1 shl 10 + 1 shl 12 + 1 shl 14 +
    7711     1 shl 18 + 1 shl 19;
     7700  DefaultOptionChecked: TSaveOptions;
     7701begin
     7702  DefaultOptionChecked := [soEnMoves, soSlowMoves, soNames, soRepScreens,
     7703    soSoundOn, soScrollOff, soAlSlowMoves];
    77127704  Reg := TRegistry.Create;
    77137705  with Reg do try
     
    77177709    xxt := TileSizes[TileSize].X;
    77187710    yyt := TileSizes[TileSize].Y;
    7719     if ValueExists('OptionChecked') then OptionChecked := ReadInteger('OptionChecked')
     7711    if ValueExists('OptionChecked') then OptionChecked := TSaveOptions(ReadInteger('OptionChecked'))
    77207712      else OptionChecked := DefaultOptionChecked;
    7721     if ValueExists('MapOptionChecked') then MapOptionChecked := ReadInteger('MapOptionChecked')
    7722       else MapOptionChecked := 1 shl moCityNames;
     7713    if ValueExists('MapOptionChecked') then MapOptionChecked := TMapOptions(ReadInteger('MapOptionChecked'))
     7714      else MapOptionChecked := [moCityNames];
    77237715    if ValueExists('CityReport') then CityRepMask := Cardinal(ReadInteger('CityReport'))
    77247716      else CityRepMask := Cardinal(not chPopIncrease and not chNoGrowthWarning and
    77257717          not chCaptured);
    7726     if OptionChecked and (7 shl 16) = 0 then
    7727       OptionChecked := OptionChecked or (1 shl 16);
     7718    if (not (soScrollFast in OptionChecked)) and (not (soScrollSlow in OptionChecked)) and
     7719      (not (soScrollOff in OptionChecked)) then
     7720      OptionChecked := OptionChecked + [soScrollSlow];
    77287721      // old regver with no scrolling
    77297722  finally
     
    77317724  end;
    77327725
    7733   if 1 shl 13 and OptionChecked <> 0 then
     7726  if soSoundOff in OptionChecked then
    77347727    SoundMode := smOff
    7735   else if 1 shl 15 and OptionChecked <> 0 then
     7728  else if soSoundOnAlt in OptionChecked then
    77367729    SoundMode := smOnAlt
    77377730  else
     
    78037796  with TButtonC(Sender) do
    78047797  begin
    7805     MapOptionChecked := MapOptionChecked xor (1 shl (Tag shr 8));
     7798    MapOptionChecked := TMapOptions(Integer(MapOptionChecked) xor (1 shl (Tag shr 8)));
    78067799    SetMapOptions;
    7807     ButtonIndex := MapOptionChecked shr (Tag shr 8) and 1 + 2;
     7800    ButtonIndex := Integer(MapOptionChecked) shr (Tag shr 8) and 1 + 2;
    78087801  end;
    78097802  if Sender = MapBtn0 then
     
    78237816  if TButtonBase(Sender).Down then
    78247817  begin
    7825     MapOptionChecked := MapOptionChecked or (1 shl moGreatWall);
     7818    MapOptionChecked := MapOptionChecked + [moGreatWall];
    78267819    TButtonBase(Sender).Hint := '';
    78277820  end
    78287821  else
    78297822  begin
    7830     MapOptionChecked := MapOptionChecked and not(1 shl moGreatWall);
     7823    MapOptionChecked := MapOptionChecked - [moGreatWall];
    78317824    TButtonBase(Sender).Hint := Phrases.Lookup('CONTROLS',
    78327825      -1 + TButtonBase(Sender).Tag and $FF);
     
    78417834  if TButtonBase(Sender).Down then
    78427835  begin
    7843     MapOptionChecked := MapOptionChecked or (1 shl moBareTerrain);
     7836    MapOptionChecked := MapOptionChecked + [moBareTerrain];
    78447837    TButtonBase(Sender).Hint := '';
    78457838  end
    78467839  else
    78477840  begin
    7848     MapOptionChecked := MapOptionChecked and not(1 shl moBareTerrain);
     7841    MapOptionChecked := MapOptionChecked - [moBareTerrain];
    78497842    TButtonBase(Sender).Hint := Phrases.Lookup('CONTROLS',
    78507843      -1 + TButtonBase(Sender).Tag and $FF);
     
    79737966end;
    79747967
     7968procedure TMainScreen.SaveMenuItemsState;
     7969var
     7970  i, j: integer;
     7971begin
     7972  if soTellAI in OptionChecked then OptionChecked := [soTellAI]
     7973    else OptionChecked := [];
     7974  for i := 0 to ComponentCount - 1 do
     7975    if Components[i] is TMenuItem then
     7976      for j := 0 to Length(SaveOption) - 1 do
     7977        if TMenuItem(Components[i]).Checked and
     7978          (TMenuItem(Components[i]).Tag = SaveOption[j]) then
     7979          OptionChecked := OptionChecked + [TSaveOption(j)];
     7980end;
     7981
    79757982procedure TMainScreen.SaveSettings;
    79767983var
    7977   i, j: integer;
    79787984  Reg: TRegistry;
    79797985begin
    7980   OptionChecked := OptionChecked and soExtraMask;
    7981   for i := 0 to ComponentCount - 1 do
    7982     if Components[i] is TMenuItem then
    7983       for j := 0 to nSaveOption - 1 do
    7984         if TMenuItem(Components[i]).Checked and
    7985           (TMenuItem(Components[i]).Tag = SaveOption[j]) then
    7986           inc(OptionChecked, 1 shl j);
     7986  SaveMenuItemsState;
    79877987
    79887988  Reg := TRegistry.Create;
     
    79917991    OpenKey(AppRegistryKey, true);
    79927992    WriteInteger('TileSize', Integer(TileSize));
    7993     WriteInteger('OptionChecked', OptionChecked);
    7994     WriteInteger('MapOptionChecked', MapOptionChecked);
     7993    WriteInteger('OptionChecked', Integer(OptionChecked));
     7994    WriteInteger('MapOptionChecked', Integer(MapOptionChecked));
    79957995    WriteInteger('CityReport', integer(CityRepMask));
    79967996  finally
Note: See TracChangeset for help on using the changeset viewer.