Changeset 127 for trunk/UCore.pas


Ignore:
Timestamp:
Jun 17, 2017, 3:14:16 PM (7 years ago)
Author:
chronos
Message:
  • Added: Load recent menu action to load recently opened/saved files.
  • Fixed: Init clients after loading game from file.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r126 r127  
    77uses
    88  Classes, SysUtils, XMLConf, FileUtil, ActnList, Controls, Dialogs, Forms,
    9   UGame, UApplicationInfo, UPersistentForm, UScaleDPI, UCoolTranslator, URegistry,
    10   Registry;
     9  UGame, UApplicationInfo, UPersistentForm, UScaleDPI, UCoolTranslator,
     10  URegistry, ULastOpenedList, Registry, Menus;
    1111
    1212type
     
    3030    ImageListLarge: TImageList;
    3131    ImageListSmall: TImageList;
     32    LastOpenedList1: TLastOpenedList;
    3233    OpenDialog1: TOpenDialog;
    3334    PersistentForm: TPersistentForm;
     
    4849    procedure DataModuleCreate(Sender: TObject);
    4950    procedure DataModuleDestroy(Sender: TObject);
     51    procedure LastOpenedList1Change(Sender: TObject);
    5052  private
    5153    FInitialized: Boolean;
    5254    StoredDimension: TControlDimension;
    5355    RegistryContext: TRegistryContext;
     56    procedure LoadRecentExecute(Sender: TObject);
    5457    procedure StartNewGame;
    5558    procedure DoPlayerChange(Sender: TObject);
     
    6669    procedure ScaleDPI;
    6770    procedure SelectClient;
     71    procedure LoadGame(FileName: string);
    6872  public
    6973    Game: TGame;
    7074    UseSingleView: Boolean;
    7175    DevelMode: Boolean;
    72     LastMapFileName: string;
    7376    AnimationSpeed: Integer;
    7477    AutoSaveEnabled: Boolean;
     
    175178  XMLConfig1.Filename := GetAppConfigDir(False) + 'Config.xml';
    176179
    177   LastMapFileName := XMLConfig1.GetValue('LastMapFileName', '');
     180  LastOpenedList1.LoadFromXMLConfig(XMLConfig1, 'RecentFiles');
    178181  DevelMode := XMLConfig1.GetValue('DevelMode', false);
    179182  AnimationSpeed := XMLConfig1.GetValue('AnimationSpeed', 50);
     
    187190begin
    188191  XMLConfig1.SetValue('Language', CoolTranslator1.Language.Code);
    189   XMLConfig1.SetValue('LastMapFileName', LastMapFileName);
     192  LastOpenedList1.SaveToXMLConfig(XMLConfig1, 'RecentFiles');
    190193  XMLConfig1.SetValue('DevelMode', DevelMode);
    191194  XMLConfig1.SetValue('AnimationSpeed', AnimationSpeed);
     
    203206  if (ParamCount > 0) then begin
    204207    FileName := UTF8Encode(ParamStr(1));
    205     if FileExists(FileName) then begin
    206       Game.LoadFromFile(FileName);
    207       SelectClient;
    208       LastMapFileName := OpenDialog1.FileName;
    209       with Core.CurrentClient do
    210         View.DestRect := Bounds(0, 0, FormMain.PaintBox1.Width, FormMain.PaintBox1.Height);
    211       FormMain.AZoomAll.Execute;
    212       FormMain.Redraw;
    213     end;
     208    if FileExists(FileName) then LoadGame(FileName);
    214209  end;
    215210end;
     
    305300procedure TCore.AGameLoadExecute(Sender: TObject);
    306301begin
    307   if Game.FileName = '' then
    308     OpenDialog1.FileName := LastMapFileName
     302  if (Game.FileName = '') and (LastOpenedList1.Items.Count > 0) then
     303    OpenDialog1.FileName := LastOpenedList1.Items[0]
    309304    else OpenDialog1.FileName := Game.FileName;
    310305  if OpenDialog1.Execute then begin
    311     Game.LoadFromFile(OpenDialog1.FileName);
    312     SelectClient;
    313     LastMapFileName := OpenDialog1.FileName;
    314     with Core.CurrentClient do
    315       View.DestRect := Bounds(0, 0, FormMain.PaintBox1.Width, FormMain.PaintBox1.Height);
    316     FormMain.AZoomAll.Execute;
    317     FormMain.Redraw;
     306    LoadGame(OpenDialog1.FileName);
    318307  end;
    319308end;
     
    337326procedure TCore.AGameSaveExecute(Sender: TObject);
    338327begin
    339   if Game.FileName = '' then
    340     SaveDialog1.FileName := ExtractFileDir(LastMapFileName)
     328  if (Game.FileName = '') and (LastOpenedList1.Items.Count > 0) then
     329    SaveDialog1.FileName := ExtractFileDir(LastOpenedList1.Items[0])
    341330    else SaveDialog1.FileName := Game.FileName;
    342331  if SaveDialog1.Execute then begin
    343332    Game.SaveToFile(SaveDialog1.FileName);
    344     LastMapFileName := SaveDialog1.FileName;
     333    LastOpenedList1.AddItem(SaveDialog1.FileName);
    345334  end;
    346335end;
     
    392381end;
    393382
     383procedure TCore.LastOpenedList1Change(Sender: TObject);
     384begin
     385  LastOpenedList1.LoadToMenuItem(FormMain.MenuItemLoadRecent, LoadRecentExecute);
     386end;
     387
     388procedure TCore.LoadRecentExecute(Sender: TObject);
     389begin
     390  LoadGame((Sender as TMenuItem).Caption);
     391end;
     392
     393procedure TCore.LoadGame(FileName: string);
     394begin
     395  Game.LoadFromFile(FileName);
     396  SelectClient;
     397  LastOpenedList1.AddItem(FileName);
     398  with Core.CurrentClient do
     399    View.DestRect := Bounds(0, 0, FormMain.PaintBox1.Width, FormMain.PaintBox1.Height);
     400  FormMain.AZoomAll.Execute;
     401  FormMain.Redraw;
     402end;
     403
    394404procedure TCore.StartNewGame;
    395405begin
     
    408418
    409419procedure TCore.Init;
    410 var
    411   I: Integer;
    412420begin
    413421  {$IFDEF Linux}
Note: See TracChangeset for help on using the changeset viewer.