Changeset 127 for trunk


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.
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.lfm

    r125 r127  
    152152        Action = Core.AGameLoad
    153153      end
     154      object MenuItemLoadRecent: TMenuItem
     155        Caption = 'Load recent'
     156      end
    154157      object MenuItem15: TMenuItem
    155158        Action = Core.AGameSave
  • trunk/Forms/UFormMain.lrt

    r111 r127  
    11TFORMMAIN.CAPTION=xTactics
    22TFORMMAIN.MENUITEM1.CAPTION=Game
     3TFORMMAIN.MENUITEMLOADRECENT.CAPTION=Load recent
    34TFORMMAIN.MENUITEM5.CAPTION=-
    45TFORMMAIN.MENUITEM10.CAPTION=View
  • trunk/Forms/UFormMain.pas

    r125 r127  
    4242    MenuItem22: TMenuItem;
    4343    MenuItem23: TMenuItem;
     44    MenuItemLoadRecent: TMenuItem;
    4445    MenuItem3: TMenuItem;
    4546    MenuItem4: TMenuItem;
  • trunk/Languages/xtactics.cs.po

    r125 r127  
    99"MIME-Version: 1.0\n"
    1010"Content-Transfer-Encoding: 8bit\n"
    11 "X-Generator: Poedit 1.8.9\n"
     11"X-Generator: Poedit 2.0.1\n"
    1212"Language: cs\n"
    1313
     
    175175msgstr "Nástroje"
    176176
     177#: tformmain.menuitemloadrecent.caption
     178msgid "Load recent"
     179msgstr "Načíst nedávné"
     180
    177181#: tformmove.buttoncancel.caption
    178182msgctxt "tformmove.buttoncancel.caption"
  • trunk/Languages/xtactics.po

    r115 r127  
    164164msgstr ""
    165165
     166#: tformmain.menuitemloadrecent.caption
     167msgid "Load recent"
     168msgstr ""
     169
    166170#: tformmove.buttoncancel.caption
    167171msgctxt "tformmove.buttoncancel.caption"
  • trunk/UCore.lfm

    r124 r127  
    99  object ActionList1: TActionList
    1010    Images = ImageListSmall
    11     left = 112
    12     top = 80
     11    left = 72
     12    top = 32
    1313    object AGameNew: TAction
    1414      Caption = 'New'
     
    469469    POFilesFolder = 'Languages'
    470470    OnTranslate = CoolTranslator1Translate
    471     left = 214
    472     top = 252
     471    left = 73
     472    top = 232
    473473  end
    474474  object ImageListLarge: TImageList
     
    20212021    RootName = 'CONFIG'
    20222022    ReadOnly = False
    2023     left = 209
    2024     top = 360
     2023    left = 73
     2024    top = 296
    20252025  end
    20262026  object OpenDialog1: TOpenDialog
     
    20492049    RegistryRoot = rrKeyCurrentUser
    20502050    License = 'CC0'
    2051     left = 112
    2052     top = 155
     2051    left = 73
     2052    top = 96
    20532053  end
    20542054  object PersistentForm: TPersistentForm
     
    20602060  object ScaleDPI1: TScaleDPI
    20612061    AutoDetect = False
    2062     left = 245
    2063     top = 54
     2062    left = 72
     2063    top = 360
     2064  end
     2065  object LastOpenedList1: TLastOpenedList
     2066    MaxCount = 10
     2067    OnChange = LastOpenedList1Change
     2068    left = 73
     2069    top = 160
    20642070  end
    20652071end
  • 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}
  • trunk/UGame.pas

    r126 r127  
    394394    procedure BuildBridges;
    395395    procedure BuildMapAreas;
     396    procedure InitClients;
    396397  public
    397398    Players: TPlayers;
     
    27032704end;
    27042705
     2706procedure TGame.InitClients;
     2707var
     2708  I: Integer;
     2709begin
     2710  Clients.Clear;
     2711  Clients.New('Spectator');
     2712  for I := 0 to Players.Count - 1 do
     2713  with TPlayer(Players[I]) do
     2714  if Mode = pmHuman then begin
     2715    Clients.New(TPlayer(Players[I]).Name);
     2716    TPlayer(Players[I]).Client := TClient(Clients.Last);
     2717  end;
     2718
     2719  for I := 0 to Clients.Count - 1 do
     2720  with TClient(Clients[I]) do begin
     2721    View.Clear;
     2722    View.Zoom := 1;
     2723    if Assigned(ControlPlayer) then View.CenterPlayerCity(ControlPlayer)
     2724      else View.CenterMap;
     2725  end;
     2726end;
     2727
    27052728procedure TGame.SaveConfig(Config: TXmlConfig; Path: string);
    27062729begin
     
    27932816        else CurrentPlayer := nil;
    27942817
     2818      InitClients;
     2819
    27952820      NewNode := FindNode('UnitMoves');
    27962821      if Assigned(NewNode) then
     
    30443069    else CurrentPlayer := nil;
    30453070
    3046   Clients.Clear;
    3047   Clients.New('Spectator');
    3048   for I := 0 to Players.Count - 1 do
    3049   with TPlayer(Players[I]) do
    3050   if Mode = pmHuman then begin
    3051     Clients.New(TPlayer(Players[I]).Name);
    3052     TPlayer(Players[I]).Client := TClient(Clients.Last);
    3053   end;
    3054 
    3055   for I := 0 to Clients.Count - 1 do
    3056   with TClient(Clients[I]) do begin
    3057     View.Clear;
    3058     View.Zoom := 1;
    3059     if Assigned(ControlPlayer) then View.CenterPlayerCity(ControlPlayer)
    3060       else View.CenterMap;
    3061   end;
     3071  InitClients;
    30623072end;
    30633073
Note: See TracChangeset for help on using the changeset viewer.