Changeset 77


Ignore:
Timestamp:
Oct 5, 2014, 7:13:38 PM (10 years ago)
Author:
chronos
Message:
  • Added: Auto save game to file option in settings.
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormSettings.lfm

    r68 r77  
    2929  object Label1: TLabel
    3030    Left = 20
    31     Height = 22
     31    Height = 25
    3232    Top = 26
    33     Width = 80
     33    Width = 95
    3434    Caption = 'Language:'
    3535    ParentColor = False
     
    3737  object ComboBoxLanguage: TComboBox
    3838    Left = 178
    39     Height = 34
     39    Height = 37
    4040    Top = 24
    4141    Width = 196
     
    4646  object CheckBoxDevelMode: TCheckBox
    4747    Left = 16
    48     Height = 24
     48    Height = 27
    4949    Top = 80
    50     Width = 157
     50    Width = 176
    5151    Caption = 'Developer mode'
    5252    TabOrder = 3
     
    5454  object SpinEditAnimSpeed: TSpinEdit
    5555    Left = 184
    56     Height = 32
     56    Height = 35
    5757    Top = 120
    5858    Width = 122
     
    6161  object Label2: TLabel
    6262    Left = 19
    63     Height = 22
     63    Height = 25
    6464    Top = 126
    65     Width = 140
     65    Width = 162
    6666    Caption = 'Animation speed:'
    6767    ParentColor = False
     
    6969  object Label3: TLabel
    7070    Left = 311
    71     Height = 22
     71    Height = 25
    7272    Top = 128
    73     Width = 15
     73    Width = 17
    7474    Caption = '%'
    7575    ParentColor = False
    7676  end
     77  object CheckBox1: TCheckBox
     78    Left = 16
     79    Height = 27
     80    Top = 160
     81    Width = 287
     82    Caption = 'Autosave game on each turn'
     83    TabOrder = 5
     84  end
    7785end
  • trunk/Forms/UFormSettings.lrt

    r68 r77  
    66TFORMSETTINGS.LABEL2.CAPTION=Animation speed:
    77TFORMSETTINGS.LABEL3.CAPTION=%
     8TFORMSETTINGS.CHECKBOX1.CAPTION=Autosave game on each turn
  • trunk/Forms/UFormSettings.pas

    r68 r77  
    1616    ButtonOk: TButton;
    1717    ButtonCancel: TButton;
     18    CheckBox1: TCheckBox;
    1819    CheckBoxDevelMode: TCheckBox;
    1920    ComboBoxLanguage: TComboBox;
  • trunk/Languages/xtactics.cs.po

    r76 r77  
    367367msgstr "Nastavení"
    368368
     369#: tformsettings.checkbox1.caption
     370msgid "Autosave game on each turn"
     371msgstr ""
     372
    369373#: tformsettings.checkboxdevelmode.caption
    370374msgid "Developer mode"
     
    537541msgid "Wrong file format"
    538542msgstr "Chybný formát souboru"
     543
  • trunk/Languages/xtactics.po

    r75 r77  
    353353msgstr ""
    354354
     355#: tformsettings.checkbox1.caption
     356msgid "Autosave game on each turn"
     357msgstr ""
     358
    355359#: tformsettings.checkboxdevelmode.caption
    356360msgid "Developer mode"
  • trunk/UCore.pas

    r76 r77  
    4949    procedure DoOnWin(Player: TPlayer);
    5050    procedure Delay(Time: Integer);
     51    procedure GameNewTurnExecute(Sender: TObject);
     52    procedure AutoSave;
    5153  public
    5254    Game: TGame;
     
    5557    LastMapFileName: string;
    5658    AnimationSpeed: Integer;
     59    AutoSaveEnabled: Boolean;
    5760    procedure UpdateActions;
    5861    procedure Init;
     
    129132end;
    130133
     134procedure TCore.GameNewTurnExecute(Sender: TObject);
     135begin
     136  if AutoSaveEnabled then AutoSave;
     137end;
     138
     139procedure TCore.AutoSave;
     140begin
     141  Game.SaveToFile(GetAppConfigDir(False) + 'AutoSave.xtg');
     142  GetUserDir;
     143end;
     144
    131145procedure TCore.UpdateActions;
    132146begin
     
    249263  Game.OnMove := DoOnMove;
    250264  Game.OnWin := DoOnWin;
     265  Game.OnNewTurn := GameNewTurnExecute;
    251266end;
    252267
     
    258273  XMLConfig1.SetValue('DevelMode', DevelMode);
    259274  XMLConfig1.SetValue('AnimationSpeed', AnimationSpeed);
     275  XMLConfig1.SetValue('AutoSave', AutoSaveEnabled);
    260276  FreeAndNil(Game);
    261277end;
     
    269285  DevelMode := XMLConfig1.GetValue('DevelMode', false);
    270286  AnimationSpeed := XMLConfig1.GetValue('AnimationSpeed', 50);
     287  AutoSaveEnabled := XMLConfig1.GetValue('AutoSave', True);
    271288  CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(XMLConfig1.GetValue('Language', ''));
    272289  for I := 0 to Game.Players.Count - 1 do
  • trunk/UGame.pas

    r76 r77  
    2525  TUnitMoves = class;
    2626  TCells = class;
     27  TMap = class;
    2728
    2829  TFloatPoint = record
     
    3839  TCell = class
    3940  private
     41    FMap: TMap;
    4042    FPower: Integer;
    4143    procedure SetPower(AValue: Integer);
     
    4547    Polygon: TPointArray;
    4648    Terrain: TTerrainType;
     49    PlayerId: Integer;
    4750    Player: TPlayer;
    4851    MovesFrom: TUnitMoves;
    4952    MovesTo: TUnitMoves;
     53    NeighborsId: array of Integer;
    5054    Neighbors: TCells;
    5155    Mark: Boolean;
     56    procedure FixRefId;
    5257    procedure LoadFromNode(Node: TDOMNode);
    5358    procedure SaveToNode(Node: TDOMNode);
     
    6065    destructor Destroy; override;
    6166    property Power: Integer read FPower write SetPower;
     67    property Map: TMap read FMap write FMap;
    6268  end;
    6369
     
    6773
    6874  TCells = class(TObjectList)
     75    Map: TMap;
     76    procedure FixRefId;
    6977    function FindById(Id: Integer): TCell;
    7078    procedure LoadFromNode(Node: TDOMNode);
     
    235243    Game: TGame;
    236244    NewPlayerId: Integer;
     245    function FindById(Id: Integer): TPlayer;
    237246    procedure New(Name: string; Color: TColor; Mode: TPlayerMode);
    238247    function GetNewPlayerId: Integer;
     
    285294    FMapType: TMapType;
    286295    FOnMove: TMoveEvent;
     296    FOnNewTurn: TNotifyEvent;
    287297    FOnWin: TWinEvent;
    288298    FRunning: Boolean;
     
    334344    property OnMove: TMoveEvent read FOnMove write FOnMove;
    335345    property OnWin: TWinEvent read FOnWin write FOnWin;
     346    property OnNewTurn: TNotifyEvent read FOnNewTurn write FOnNewTurn;
    336347  end;
    337348
     
    427438{ TCells }
    428439
     440procedure TCells.FixRefId;
     441var
     442  I: Integer;
     443begin
     444  for I := 0 to Count - 1 do
     445  TCell(Items[I]).FixRefId;
     446end;
     447
    429448function TCells.FindById(Id: Integer): TCell;
    430449var
     
    432451begin
    433452  I := 0;
    434   while (I < 0) and (TCell(Items[I]).Id <> Id) do Inc(I);
     453  while (I < Count) and (TCell(Items[I]).Id <> Id) do Inc(I);
    435454  if I < Count then Result := TCell(Items[I])
    436455    else Result := nil;
     
    446465  while Assigned(Node2) and (Node2.NodeName = 'Cell') do begin
    447466    NewCell := TCell.Create;
     467    NewCell.Map := Map;
    448468    NewCell.LoadFromNode(Node2);
    449469    Add(NewCell);
     
    466486
    467487{ TPlayers }
     488
     489function TPlayers.FindById(Id: Integer): TPlayer;
     490var
     491  I: Integer;
     492begin
     493  I := 0;
     494  while (I < Count) and (TPlayer(Items[I]).Id <> Id) do Inc(I);
     495  if I < Count then Result := TPlayer(Items[I])
     496    else Result := nil;
     497end;
    468498
    469499procedure TPlayers.New(Name: string; Color: TColor; Mode: TPlayerMode);
     
    574604  for X := 0 to FSize.X - 1 do begin
    575605    NewCell := TCell.Create;
     606    NewCell.Map := Self;
    576607    NewCell.PosPx := Point(Trunc(Random * FSize.X * DefaultCellSize.X), Trunc(Random * FSize.Y * DefaultCellSize.Y));
    577608    SetLength(NewCell.Polygon, 1);
     
    618649  for X := 0 to FSize.X - 1 do begin
    619650    NewCell := TCell.Create;
     651    NewCell.Map := Self;
    620652    Reverse := Boolean(X mod 2) xor Boolean(Y mod 2);
    621653    if Reverse then Rev := -1
     
    658690  for X := 0 to FSize.X - 1 do begin
    659691    NewCell := TCell.Create;
     692    NewCell.Map := Self;
    660693    NewCell.PosPx := Point(Trunc(X * DefaultCellSize.X * SquareCellMulX),
    661694      Trunc(Y * DefaultCellSize.Y * SquareCellMulY));
     
    960993  for X := 0 to FSize.X - 1 do begin
    961994    NewCell := TCell.Create;
     995    NewCell.Map := Self;
    962996    NewCell.PosPx := Point(X, Y);
    963997    NewCell.Id := GetNewCellId;
     
    9711005  DefaultCellSize := Point(220, 220);
    9721006  Cells := TCells.create;
     1007  Cells.Map := Self;
    9731008  Size := Point(0, 0);
    9741009  Image := TImage.Create(nil);
     
    11451180end;
    11461181
     1182procedure TCell.FixRefId;
     1183var
     1184  I: Integer;
     1185begin
     1186  Player := Map.Game.Players.FindById(PlayerId);
     1187
     1188  Neighbors.Count := Length(NeighborsId);
     1189  for I := 0 to Length(NeighborsId) - 1 do begin
     1190     Neighbors[I] := Map.Cells.FindById(NeighborsId[I]);
     1191  end;
     1192end;
     1193
    11471194procedure TCell.LoadFromNode(Node: TDOMNode);
    11481195var
     
    11561203  PosPx.X := ReadInteger(Node, 'PosX', 0);
    11571204  PosPx.Y := ReadInteger(Node, 'PosY', 0);
    1158   //Player := Map.Game.Players.FindById(ReadInteger(Node, 'Player', 0));
     1205  PlayerId := ReadInteger(Node, 'Player', 0);
     1206
     1207  Node3 := Node.FindNode('Neighbours');
     1208  if Assigned(Node3) then begin
     1209    SetLength(NeighborsId, 0);
     1210    Node2 := Node3.FirstChild;
     1211    while Assigned(Node2) and (Node2.NodeName = 'Neighbour') do begin
     1212      SetLength(NeighborsId, Length(NeighborsId) + 1);
     1213      NeighborsId[High(NeighborsId)] := ReadInteger(Node2, 'Id', 0);
     1214      Node2 := Node2.NextSibling;
     1215    end;
     1216  end;
    11591217
    11601218  Node3 := Node.FindNode('Polygon');
     
    19772035      if Assigned(NewNode) then
    19782036        Moves.LoadFromNode(NewNode);
     2037
     2038      Map.Cells.FixRefId;
    19792039    end;
    19802040  finally
     
    20782138    CurrentPlayer := TPlayer(Players[(Players.IndexOf(CurrentPlayer) + 1) mod Players.Count]);
    20792139  until CurrentPlayer.TotalCells > 0;
    2080   if Players.IndexOf(CurrentPlayer) < Players.IndexOf(PrevPlayer) then Inc(TurnCounter);
     2140  if Players.IndexOf(CurrentPlayer) < Players.IndexOf(PrevPlayer) then begin
     2141    Inc(TurnCounter);
     2142    if Assigned(FOnNewTurn) then
     2143      FOnNewTurn(Self);
     2144  end;
    20812145  CheckWinObjective;
    20822146  // For computers take view from previous human
     
    23642428  for X := 0 to FSize.X - 1 do begin
    23652429    NewCell := TCell.Create;
     2430    NewCell.Map := Self;
    23662431    PX := X;
    23672432    PY := Y;
Note: See TracChangeset for help on using the changeset viewer.