Changeset 36 for trunk


Ignore:
Timestamp:
Oct 13, 2019, 5:14:50 PM (5 years ago)
Author:
chronos
Message:
  • Fixed: Missing UFormHistory files.
  • Added: Allow to disable moves history recording.
Location:
trunk
Files:
3 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.lfm

    r31 r36  
    3737        Action = Core.AComputer
    3838      end
    39       object MenuItem5: TMenuItem
     39      object MenuItemMovesHistory: TMenuItem
    4040        Action = Core.AHistory
    4141      end
  • trunk/Forms/UFormMain.pas

    r35 r36  
    1919    MenuItem3: TMenuItem;
    2020    MenuItem4: TMenuItem;
    21     MenuItem5: TMenuItem;
     21    MenuItemMovesHistory: TMenuItem;
    2222    MenuItemTools: TMenuItem;
    2323    MenuItemNew: TMenuItem;
     
    8888  Core.PersistentForm1.Load(Self);
    8989  UpdateInterface;
     90  if Core.Game.Board.GetEmptyTilesCount > Core.Game.Board.Size.X * Core.Game.Board.Size.Y - 2 then
     91    Core.Game.New;
    9092end;
    9193
     
    108110  ToolsVisible: Boolean;
    109111begin
     112  MenuItemMovesHistory.Visible := Core.Game.RecordHistory;
    110113  ToolsVisible := False;
    111114  for I := 0 to MenuItemTools.Count - 1 do
  • trunk/Forms/UFormNew.lfm

    r31 r36  
    11object FormNew: TFormNew
    22  Left = 703
    3   Height = 212
    4   Top = 748
    5   Width = 487
     3  Height = 266
     4  Top = 694
     5  Width = 501
    66  Caption = 'New game'
    7   ClientHeight = 212
    8   ClientWidth = 487
     7  ClientHeight = 266
     8  ClientWidth = 501
    99  DesignTimePPI = 144
    1010  OnClose = FormClose
     
    4545    Left = 120
    4646    Height = 38
    47     Top = 158
     47    Top = 212
    4848    Width = 113
    4949    Anchors = [akLeft, akBottom]
     
    5555    Left = 280
    5656    Height = 38
    57     Top = 158
     57    Top = 212
    5858    Width = 113
    5959    Anchors = [akLeft, akBottom]
     
    7070    TabOrder = 3
    7171  end
     72  object CheckBoxRecordHistory: TCheckBox
     73    Left = 16
     74    Height = 30
     75    Top = 88
     76    Width = 210
     77    Caption = 'Record moves history'
     78    TabOrder = 4
     79  end
    7280end
  • trunk/Forms/UFormNew.lrj

    r28 r36  
    44{"hash":77089212,"name":"tformnew.buttoncancel.caption","sourcebytes":[67,97,110,99,101,108],"value":"Cancel"},
    55{"hash":1339,"name":"tformnew.buttonok.caption","sourcebytes":[79,75],"value":"OK"},
    6 {"hash":260260820,"name":"tformnew.checkboxundoenabled.caption","sourcebytes":[85,110,100,111,32,101,110,97,98,108,101,100],"value":"Undo enabled"}
     6{"hash":260260820,"name":"tformnew.checkboxundoenabled.caption","sourcebytes":[85,110,100,111,32,101,110,97,98,108,101,100],"value":"Undo enabled"},
     7{"hash":146862089,"name":"tformnew.checkboxrecordhistory.caption","sourcebytes":[82,101,99,111,114,100,32,109,111,118,101,115,32,104,105,115,116,111,114,121],"value":"Record moves history"}
    78]}
  • trunk/Forms/UFormNew.pas

    r31 r36  
    1616    ButtonCancel: TButton;
    1717    ButtonOk: TButton;
     18    CheckBoxRecordHistory: TCheckBox;
    1819    CheckBoxUndoEnabled: TCheckBox;
    1920    ComboBoxSize: TComboBox;
     
    6061  ComboBoxSize.ItemIndex := Game.Board.Size.X - 2;
    6162  CheckBoxUndoEnabled.Checked := Game.UndoEnabled;
     63  CheckBoxRecordHistory.Checked := Game.RecordHistory;
    6264end;
    6365
     
    6668  Game.Board.Size := Point(2 + ComboBoxSize.ItemIndex, 2 + ComboBoxSize.ItemIndex);
    6769  Game.UndoEnabled := CheckBoxUndoEnabled.Checked;
     70  Game.RecordHistory := CheckBoxRecordHistory.Checked;
    6871end;
    6972
  • trunk/Forms/UFormSettings.pas

    r15 r36  
    6262    Core.Translator1.Language := TLanguage(ComboBoxLanguage.Items.Objects[ComboBoxLanguage.ItemIndex]);
    6363  end;
    64   Close;
     64  ModalResult := mrOk;
    6565end;
    6666
  • trunk/Game2048.lpi

    r31 r36  
    173173        <RangeChecks Value="True"/>
    174174        <OverflowChecks Value="True"/>
    175         <StackChecks Value="True"/>
    176175      </Checks>
    177176      <VerifyObjMethodCallValidity Value="True"/>
  • trunk/Languages/Game2048.cs.po

    r32 r36  
    126126msgstr "Nová hra"
    127127
     128#: tformnew.checkboxrecordhistory.caption
     129msgctxt "tformnew.checkboxrecordhistory.caption"
     130msgid "Record moves history"
     131msgstr "Zaznamenávat historii pohybů"
     132
    128133#: tformnew.checkboxundoenabled.caption
    129134msgid "Undo enabled"
  • trunk/Languages/Game2048.po

    r32 r36  
    116116msgstr ""
    117117
     118#: tformnew.checkboxrecordhistory.caption
     119msgctxt "tformnew.checkboxrecordhistory.caption"
     120msgid "Record moves history"
     121msgstr ""
     122
    118123#: tformnew.checkboxundoenabled.caption
    119124msgid "Undo enabled"
  • trunk/Packages/Common/URegistry.pas

    r7 r36  
    133133begin
    134134  {$IFDEF Linux}
    135   CloseKey;
     135  //CloseKey;
    136136  {$ENDIF}
    137137  Result := inherited OpenKey(Key, CanCreate);
  • trunk/UCore.pas

    r33 r36  
    8888  FormSettings := TFormSettings.Create(nil);
    8989  try
    90     FormSettings.ShowModal;
     90    if FormSettings.ShowModal = mrOk then begin
     91      FormMain.UpdateInterface;
     92      UpdateInterface;
     93    end;
    9194  finally
    9295    FreeAndNil(FormSettings);
     
    153156      FormNew.Save(Core.Game);
    154157      Game.New;
     158      UpdateInterface;
     159      FormMain.UpdateInterface;
    155160    end;
    156161  finally
     
    184189begin
    185190  AUndo.Enabled := Game.CanUndo;
     191  AHistory.Enabled := Game.RecordHistory;
    186192  {$IFDEF DEBUG}
    187193  AComputer.Enabled := True;
  • trunk/UGame.pas

    r35 r36  
    6161    InitialTilesPos: array of TPoint;
    6262    procedure GetStep(GameStep: TGame; Step: Integer);
     63    procedure Clear;
    6364    constructor Create;
    6465    destructor Destroy; override;
     
    9697    FOnGameOver: TNotifyEvent;
    9798    FOnWin: TNotifyEvent;
     99    FRecordHistory: Boolean;
    98100    FRunning: Boolean;
    99101    FScore: Integer;
     
    101103    FBoardUndo: TBoard;
    102104    function GetTileColor(Value: Integer): TColor;
     105    procedure SetRecordHistory(AValue: Boolean);
    103106    procedure SetScore(AValue: Integer);
    104107    procedure DoChange;
     
    138141    property OnGameOver: TNotifyEvent read FOnGameOver write FOnGameOver;
    139142    property Moving: Boolean read FMoving;
     143    property RecordHistory: Boolean read FRecordHistory write SetRecordHistory;
    140144  end;
    141145
     
    173177var
    174178  I: Integer;
    175   C: Integer;
    176   HistoryMove: THistoryMove;
    177179begin
    178180  with Reg do begin
    179181    CurrentContext := RegContext;
    180     C := ReadIntegerWithDefault('Count', 0);
    181     for I := 0 to C - 1 do begin
    182       HistoryMove := THistoryMove.Create;
    183       Add(HistoryMove);
    184       HistoryMove.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '/' + IntToStr(I)));
     182    Count := ReadIntegerWithDefault('Count', 0);
     183    for I := 0 to Count - 1 do begin
     184      Items[I] := THistoryMove.Create;
     185      THistoryMove(Items[I]).LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '/' + IntToStr(I)));
    185186    end;
    186187  end;
     
    229230      else raise Exception.Create('Tile should be empty');
    230231  end;
     232end;
     233
     234procedure THistory.Clear;
     235begin
     236  Moves.Clear;
     237  SetLength(InitialTilesPos, 0);
    231238end;
    232239
     
    475482    Result := EmptyTiles[Random(EmptyTiles.Count)];
    476483    Result.Value := NewValue;
     484    if RecordHistory then begin
     485      SetLength(History.InitialTilesPos, Length(History.InitialTilesPos) + 1);
     486      History.InitialTilesPos[Length(History.InitialTilesPos) - 1] := Result.Index;
     487    end;
    477488  end;
    478489  EmptyTiles.Free;
     
    512523var
    513524  I: Integer;
    514   NewTile: TTile;
    515525begin
    516526  FCanUndo := False;
     
    518528  Score := 0;
    519529  Running := True;
    520   with History do begin
    521     Moves.Clear;
    522 
    523     SetLength(InitialTilesPos, 0);
    524     for I := 0 to 1 do begin
    525       NewTile := FillRandomTile(0);
    526       SetLength(InitialTilesPos, Length(InitialTilesPos) + 1);
    527       InitialTilesPos[Length(InitialTilesPos) - 1] := NewTile.Index;
    528     end;
    529   end;
     530  History.Clear;
     531  for I := 0 to 1 do
     532    FillRandomTile(0);
    530533  DoChange;
    531534end;
     
    860863
    861864    NewTile := FillRandomTile;
    862     HistoryMove := THistoryMove.Create;
    863     HistoryMove.Direction := Direction;
    864     HistoryMove.NewItemPos := NewTile.Index;
    865     HistoryMove.NewItemValue := NewTile.Value;
    866     History.Moves.Add(HistoryMove);
     865    if RecordHistory then begin
     866      HistoryMove := THistoryMove.Create;
     867      HistoryMove.Direction := Direction;
     868      HistoryMove.NewItemPos := NewTile.Index;
     869      HistoryMove.NewItemValue := NewTile.Value;
     870      History.Moves.Add(HistoryMove);
     871    end;
    867872
    868873    if not CanMove and (Board.GetEmptyTilesCount = 0) then
     
    902907    WriteBool('CanUndo', FCanUndo);
    903908    WriteBool('UndoEnabled', UndoEnabled);
     909    WriteBool('RecordHistory', RecordHistory);
    904910    FBoardUndo.SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\BoardUndo'));
    905911    Board.SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\Board'));
     
    924930    FCanUndo := ReadBoolWithDefault('CanUndo', False);
    925931    UndoEnabled := ReadBoolWithDefault('UndoEnabled', True);
     932    RecordHistory := ReadBoolWithDefault('RecordHistory', False);
    926933    FBoardUndo.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\BoardUndo'));
    927934    Board.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\Board'));
     
    970977end;
    971978
     979procedure TGame.SetRecordHistory(AValue: Boolean);
     980begin
     981  if FRecordHistory = AValue then Exit;
     982  FRecordHistory := AValue;
     983  if not FRecordHistory then History.Clear;
     984end;
     985
    972986procedure TGame.SetScore(AValue: Integer);
    973987begin
Note: See TracChangeset for help on using the changeset viewer.