Changeset 354


Ignore:
Timestamp:
Dec 29, 2024, 1:35:37 PM (3 days ago)
Author:
chronos
Message:
  • Modified: Automatically save running game on application exit and reopen it on next start.
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Core.pas

    r352 r354  
    8383    procedure Delay(Time: Integer);
    8484    procedure GameNewTurnExecute(Sender: TObject);
    85     procedure AutoSave;
    8685    procedure CommandLineParams;
    8786    procedure SelectClient;
     
    8988    procedure FormClientActions;
    9089    procedure LoadGameSystems;
     90    function GetAutoSaveFileName: string;
    9191  public
    9292    Game: TGame;
     
    9898    CellGridVisible: Boolean;
    9999    UnitShapeVisible: Boolean;
    100     AutoSaveEnabled: Boolean;
    101     ReopenLastFile: Boolean;
    102100    FormClients: TFormClients;
    103101    LocalClients: TClients;
     
    105103    GameSystems: TGameSystems;
    106104    FormMain: TFormMain;
     105    procedure AutoSave;
    107106    procedure ReopenGameOnInit;
    108107    procedure LoadConfig;
     
    145144  SRestartGameQuestion = 'Do you want to restart current game?';
    146145  SPlayersNotInitialized = 'Not all players were initialized with start cell. Needed %d, initialized %d. Change map parameters to have more terrain cells.';
    147   SFileDialogFilter = 'xTactics games (.xtg)|*.xtg|All files|*.*';
     146  SFileDialogFilter = 'xTactics games (' + GameFileExt + ')|*' + GameFileExt + '|All files|*.*';
    148147  SMissingServerClientForPlayer = 'Server client for current player not found.';
    149148
     
    188187procedure TCore.GameNewTurnExecute(Sender: TObject);
    189188begin
    190   if AutoSaveEnabled then AutoSave;
     189  AutoSave;
    191190end;
    192191
     
    196195begin
    197196  OldFileName := Game.FileName;
    198   Game.SaveToFile(GetAppConfigDir(False) + 'AutoSave.xtg');
     197  Game.SaveToFile(GetAutoSaveFileName);
    199198  Game.FileName := OldFileName;
    200199end;
     
    210209  DevelMode := XMLConfig1.GetValue('DevelMode', false);
    211210  AnimationSpeed := XMLConfig1.GetValue('AnimationSpeed', 50);
    212   AutoSaveEnabled := XMLConfig1.GetValue('AutoSave', True);
    213   ReopenLastFile := XMLConfig1.GetValue('ReopenLastFile', True);
    214211  Translator1.Language := Translator1.Languages.SearchByCode(String(XMLConfig1.GetValue('Language', '')));
    215212  ScaleDPI1.DPI := Point(XMLConfig1.GetValue('DPIX', 96), XMLConfig1.GetValue('DPIY', 96));
     
    227224  XMLConfig1.SetValue('DevelMode', DevelMode);
    228225  XMLConfig1.SetValue('AnimationSpeed', AnimationSpeed);
    229   XMLConfig1.SetValue('AutoSave', AutoSaveEnabled);
    230   XMLConfig1.SetValue('ReopenLastFile', ReopenLastFile);
    231226  XMLConfig1.SetValue('DPIX', ScaleDPI1.DPI.X);
    232227  XMLConfig1.SetValue('DPIY', ScaleDPI1.DPI.Y);
     
    695690end;
    696691
     692function TCore.GetAutoSaveFileName: string;
     693begin
     694  Result := GetAppConfigDir(False) + 'AutoSave' + GameFileExt;
     695end;
     696
    697697procedure TCore.ReopenGameOnInit;
     698var
     699  OldFileName: string;
    698700begin
    699701  CommandLineParams;
    700   if not GameLoaded and ReopenLastFile and (LastOpenedList1.Items.Count > 0) and
     702  if not GameLoaded and (LastOpenedList1.Items.Count > 0) and
    701703    FileExists(LastOpenedList1.Items[0]) then
    702     LoadGame(LastOpenedList1.Items[0]);
     704    Game.FileName := LastOpenedList1.Items[0];
     705
     706  if not GameLoaded and FileExists(GetAutoSaveFileName) then begin
     707    OldFileName := Game.FileName;
     708    LoadGame(GetAutoSaveFileName);
     709    LastOpenedList1.Items.Delete(0);
     710    Game.FileName := OldFileName;
     711  end;
    703712
    704713  if Game.FileName = '' then begin
  • trunk/Forms/FormMain.pas

    r337 r354  
    251251procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
    252252begin
     253  Core.Core.AutoSave;
    253254  Core.Core.Game.Running := False;
    254255  FormClient.Close;
  • trunk/Forms/FormSettings.lfm

    r325 r354  
    11object FormSettings: TFormSettings
    2   Left = 851
     2  Left = 545
    33  Height = 613
    4   Top = 413
     4  Top = 203
    55  Width = 857
    66  ActiveControl = ButtonOk
     
    1414  OnShow = FormShow
    1515  Position = poMainFormCenter
    16   LCLVersion = '3.4.0.0'
     16  LCLVersion = '3.6.0.0'
    1717  object ButtonOk: TButton
    1818    Left = 735
     
    5151    object TabSheetGeneral: TTabSheet
    5252      Caption = 'General'
    53       ClientHeight = 512
    54       ClientWidth = 831
     53      ClientHeight = 506
     54      ClientWidth = 835
    5555      ParentFont = False
    5656      object Panel1: TPanel
    5757        Left = 0
    58         Height = 512
     58        Height = 506
    5959        Top = 0
    60         Width = 831
     60        Width = 835
    6161        Align = alClient
    6262        BevelOuter = bvNone
    63         ClientHeight = 512
    64         ClientWidth = 831
     63        ClientHeight = 506
     64        ClientWidth = 835
    6565        ParentFont = False
    6666        TabOrder = 0
    6767        object Label1: TLabel
    6868          Left = 20
    69           Height = 26
     69          Height = 28
    7070          Top = 32
    71           Width = 88
     71          Width = 96
    7272          Caption = 'Language:'
    7373          ParentColor = False
     
    7676        object ComboBoxLanguage: TComboBox
    7777          Left = 178
    78           Height = 42
     78          Height = 40
    7979          Top = 24
    8080          Width = 196
     
    8686        object ComboBoxTheme: TComboBox
    8787          Left = 176
    88           Height = 42
     88          Height = 40
    8989          Top = 72
    9090          Width = 196
     
    9696        object Label6: TLabel
    9797          Left = 20
    98           Height = 26
     98          Height = 28
    9999          Top = 80
    100           Width = 63
     100          Width = 69
    101101          Caption = 'Theme:'
    102102          ParentColor = False
     
    105105        object SpinEditAnimSpeed: TSpinEdit
    106106          Left = 232
    107           Height = 43
     107          Height = 38
    108108          Top = 120
    109109          Width = 122
     
    113113        object Label3: TLabel
    114114          Left = 368
    115           Height = 26
     115          Height = 28
    116116          Top = 124
    117           Width = 15
     117          Width = 17
    118118          Caption = '%'
    119119          ParentColor = False
     
    122122        object Label2: TLabel
    123123          Left = 20
    124           Height = 26
     124          Height = 28
    125125          Top = 120
    126           Width = 149
     126          Width = 162
    127127          Caption = 'Animation speed:'
    128128          ParentColor = False
    129129          ParentFont = False
    130         end
    131         object CheckBoxAutoSaveTurn: TCheckBox
    132           Left = 20
    133           Height = 30
    134           Top = 154
    135           Width = 269
    136           Caption = 'Autosave game on each turn'
    137           ParentFont = False
    138           TabOrder = 3
    139         end
    140         object CheckBoxReopenLastFile: TCheckBox
    141           Left = 20
    142           Height = 30
    143           Top = 194
    144           Width = 248
    145           Caption = 'Reopen last game on start'
    146           ParentFont = False
    147           TabOrder = 4
    148130        end
    149131      end
     
    151133    object TabSheetDebug: TTabSheet
    152134      Caption = 'Debug'
    153       ClientHeight = 512
    154       ClientWidth = 831
     135      ClientHeight = 506
     136      ClientWidth = 835
    155137      ParentFont = False
    156138      object Panel2: TPanel
    157139        Left = 0
    158         Height = 512
     140        Height = 506
    159141        Top = 0
    160         Width = 831
     142        Width = 835
    161143        Align = alClient
    162144        BevelOuter = bvNone
    163         ClientHeight = 512
    164         ClientWidth = 831
     145        ClientHeight = 506
     146        ClientWidth = 835
    165147        ParentFont = False
    166148        TabOrder = 0
     
    169151          Height = 24
    170152          Top = 32
    171           Width = 799
     153          Width = 803
    172154          Anchors = [akTop, akLeft, akRight]
    173155          AutoSize = False
     
    179161        object Label4: TLabel
    180162          Left = 14
    181           Height = 26
     163          Height = 28
    182164          Top = 67
    183           Width = 35
     165          Width = 39
    184166          Caption = 'DPI:'
    185167          ParentColor = False
     
    188170        object SpinEditX: TSpinEdit
    189171          Left = 104
    190           Height = 43
     172          Height = 38
    191173          Top = 64
    192174          Width = 96
     
    199181        object Label5: TLabel
    200182          Left = 208
    201           Height = 26
     183          Height = 28
    202184          Top = 67
    203           Width = 10
     185          Width = 11
    204186          Caption = 'x'
    205187          ParentColor = False
     
    208190        object SpinEditY: TSpinEdit
    209191          Left = 232
    210           Height = 43
     192          Height = 38
    211193          Top = 64
    212194          Width = 90
     
    221203          Height = 26
    222204          Top = 136
    223           Width = 803
     205          Width = 807
    224206          Anchors = [akTop, akLeft, akRight]
    225207          AutoSize = False
  • trunk/Forms/FormSettings.lrj

    r317 r354  
    88{"hash":37,"name":"tformsettings.label3.caption","sourcebytes":[37],"value":"%"},
    99{"hash":69745274,"name":"tformsettings.label2.caption","sourcebytes":[65,110,105,109,97,116,105,111,110,32,115,112,101,101,100,58],"value":"Animation speed:"},
    10 {"hash":121383118,"name":"tformsettings.checkboxautosaveturn.caption","sourcebytes":[65,117,116,111,115,97,118,101,32,103,97,109,101,32,111,110,32,101,97,99,104,32,116,117,114,110],"value":"Autosave game on each turn"},
    11 {"hash":47650276,"name":"tformsettings.checkboxreopenlastfile.caption","sourcebytes":[82,101,111,112,101,110,32,108,97,115,116,32,103,97,109,101,32,111,110,32,115,116,97,114,116],"value":"Reopen last game on start"},
    1210{"hash":4897207,"name":"tformsettings.tabsheetdebug.caption","sourcebytes":[68,101,98,117,103],"value":"Debug"},
    1311{"hash":37628553,"name":"tformsettings.checkbox2.caption","sourcebytes":[65,117,116,111,109,97,116,105,99,32,68,80,73],"value":"Automatic DPI"},
  • trunk/Forms/FormSettings.pas

    r318 r354  
    1515    ButtonCancel: TButton;
    1616    CheckBox2: TCheckBox;
    17     CheckBoxAutoSaveTurn: TCheckBox;
    1817    CheckBoxDevelMode: TCheckBox;
    19     CheckBoxReopenLastFile: TCheckBox;
    2018    ComboBoxLanguage: TComboBox;
    2119    ComboBoxTheme: TComboBox;
     
    8583  SpinEditX.Value := Core.Core.ScaleDPI1.DPI.X;
    8684  SpinEditY.Value := Core.Core.ScaleDPI1.DPI.Y;
    87   CheckBoxAutoSaveTurn.Checked := Core.Core.AutoSaveEnabled;
    88   CheckBoxReopenLastFile.Checked := Core.Core.ReopenLastFile;
    8985end;
    9086
     
    9995  Core.Core.ScaleDPI1.AutoDetect := CheckBox2.Checked;
    10096  Core.Core.ScaleDPI1.DPI := Point(SpinEditX.Value, SpinEditY.Value);
    101   Core.Core.AutoSaveEnabled := CheckBoxAutoSaveTurn.Checked;
    102   Core.Core.ReopenLastFile := CheckBoxReopenLastFile.Checked;
    10397end;
    10498
  • trunk/Game.pas

    r344 r354  
    1212  MinPlayerCount = 1;
    1313  MaxPlayerCount = 8;
     14  GameFileExt = '.xtg';
    1415
    1516type
     
    136137  SComputer = 'Computer';
    137138  SWrongFileFormat = 'Wrong file format';
    138   SNewGameFile = 'New game.xtg';
     139  SNewGameFile = 'New game' + GameFileExt;
    139140  SUnsupportedMapType = 'Unsupported map type';
    140141
  • trunk/Languages/xtactics.cs.po

    r340 r354  
    12381238msgstr "Automatické DPI"
    12391239
    1240 #: tformsettings.checkboxautosaveturn.caption
    1241 msgid "Autosave game on each turn"
    1242 msgstr "Uložit hru po každém tahu"
    1243 
    12441240#: tformsettings.checkboxdevelmode.caption
    12451241msgid "Developer mode"
    12461242msgstr "Vývojářský režim"
    1247 
    1248 #: tformsettings.checkboxreopenlastfile.caption
    1249 msgid "Reopen last game on start"
    1250 msgstr "Znovu otevřít poslední hru při startu"
    12511243
    12521244#: tformsettings.label1.caption
  • trunk/Languages/xtactics.pot

    r340 r354  
    12011201msgstr ""
    12021202
    1203 #: tformsettings.checkboxautosaveturn.caption
    1204 msgid "Autosave game on each turn"
    1205 msgstr ""
    1206 
    12071203#: tformsettings.checkboxdevelmode.caption
    12081204msgid "Developer mode"
    1209 msgstr ""
    1210 
    1211 #: tformsettings.checkboxreopenlastfile.caption
    1212 msgid "Reopen last game on start"
    12131205msgstr ""
    12141206
Note: See TracChangeset for help on using the changeset viewer.