Changeset 276 for trunk


Ignore:
Timestamp:
Feb 3, 2019, 11:55:30 PM (6 years ago)
Author:
chronos
Message:
  • Fixed: Load/save game syste name correctly from/to file.
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormGameSystem.lfm

    r275 r276  
    88  ClientWidth = 781
    99  DesignTimePPI = 144
     10  OnClose = FormClose
     11  OnCreate = FormCreate
     12  OnShow = FormShow
    1013  LCLVersion = '1.8.4.0'
    1114  object ButtonSave: TButton
     
    1417    Top = 528
    1518    Width = 113
    16     Anchors = [akTop, akLeft, akBottom]
     19    Anchors = [akLeft, akBottom]
    1720    Caption = 'Save'
    1821    OnClick = ButtonSaveClick
     
    3033  end
    3134  object ButtonCancel: TButton
    32     Left = 472
     35    Left = 504
    3336    Height = 38
    3437    Top = 528
    3538    Width = 113
    36     Anchors = [akLeft]
     39    Anchors = [akRight]
    3740    Caption = 'Cancel'
    3841    ModalResult = 2
     
    4043  end
    4144  object ButtonOk: TButton
    42     Left = 616
     45    Left = 647
    4346    Height = 38
    44     Top = 529
     47    Top = 528
    4548    Width = 113
    46     Anchors = [akLeft, akBottom]
     49    Anchors = [akRight, akBottom]
    4750    Caption = 'OK'
    4851    ModalResult = 1
    4952    TabOrder = 3
     53  end
     54  object PageControl1: TPageControl
     55    Left = 16
     56    Height = 496
     57    Top = 16
     58    Width = 744
     59    ActivePage = TabSheetGeneral
     60    Anchors = [akTop, akLeft, akRight, akBottom]
     61    TabIndex = 0
     62    TabOrder = 4
     63    object TabSheetGeneral: TTabSheet
     64      Caption = 'General'
     65      ClientHeight = 456
     66      ClientWidth = 734
     67      object CheckBoxEmptyCellsNeutral: TCheckBox
     68        Left = 16
     69        Height = 30
     70        Top = 16
     71        Width = 362
     72        Caption = 'Set cells without player units as neutral'
     73        TabOrder = 0
     74      end
     75      object CheckBoxUnitsSplitMerge: TCheckBox
     76        Left = 16
     77        Height = 30
     78        Top = 55
     79        Width = 231
     80        Caption = 'Units can split or merge'
     81        TabOrder = 1
     82      end
     83      object CheckBoxUnitsMoveImmediately: TCheckBox
     84        Left = 16
     85        Height = 30
     86        Top = 95
     87        Width = 234
     88        Caption = 'Units move immediately'
     89        TabOrder = 2
     90      end
     91    end
     92    object TabSheetUnits: TTabSheet
     93      Caption = 'Units'
     94    end
    5095  end
    5196  object OpenDialog1: TOpenDialog
  • trunk/Forms/UFormGameSystem.pas

    r275 r276  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   UGameSystem;
     9  ComCtrls, UGameSystem;
    1010
    1111type
     
    1818    ButtonSave: TButton;
    1919    ButtonLoad: TButton;
     20    CheckBoxEmptyCellsNeutral: TCheckBox;
     21    CheckBoxUnitsMoveImmediately: TCheckBox;
     22    CheckBoxUnitsSplitMerge: TCheckBox;
    2023    OpenDialog1: TOpenDialog;
     24    PageControl1: TPageControl;
    2125    SaveDialog1: TSaveDialog;
     26    TabSheetGeneral: TTabSheet;
     27    TabSheetUnits: TTabSheet;
    2228    procedure ButtonLoadClick(Sender: TObject);
    2329    procedure ButtonSaveClick(Sender: TObject);
     30    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
     31    procedure FormCreate(Sender: TObject);
     32    procedure FormShow(Sender: TObject);
    2433  private
    2534    FGameSystem: TGameSystem;
     
    3847implementation
    3948
     49{$R *.lfm}
     50
     51uses
     52  UCore;
     53
    4054resourcestring
    4155  SFileDialogFilter = 'xTactics game system (.xts)|*.xts|All files|*.*';
    42 
    43 
    44 {$R *.lfm}
    4556
    4657{ TFormGameSystem }
     
    6273  SaveDialog1.InitialDir := ExtractFileDir(GameSystem.FileName);
    6374  SaveDialog1.FileName := ExtractFileName(GameSystem.FileName);
     75  SaveDialog1.DefaultExt := GameSystemExt;
    6476  if SaveDialog1.Execute then begin
    6577    GameSystem.SaveToFile(SaveDialog1.FileName);
    6678  end;
     79end;
     80
     81procedure TFormGameSystem.FormClose(Sender: TObject;
     82  var CloseAction: TCloseAction);
     83begin
     84  Core.PersistentForm.Save(Self);
     85end;
     86
     87procedure TFormGameSystem.FormCreate(Sender: TObject);
     88begin
     89  Core.ThemeManager1.UseTheme(Self);
     90  Core.CoolTranslator1.TranslateComponentRecursive(Self);
     91end;
     92
     93procedure TFormGameSystem.FormShow(Sender: TObject);
     94begin
     95  Core.PersistentForm.Load(Self);
    6796end;
    6897
     
    75104procedure TFormGameSystem.LoadData(GameSystem: TGameSystem);
    76105begin
    77 
     106  Self.GameSystem := GameSystem;
     107  CheckBoxEmptyCellsNeutral.Checked := GameSystem.EmptyCellsNeutral;
     108  CheckBoxUnitsSplitMerge.Checked := GameSystem.UnitsSplitMerge;
     109  CheckBoxUnitsMoveImmediately.Checked := GameSystem.UnitsMoveImmediately;
    78110end;
    79111
    80112procedure TFormGameSystem.SaveData(GameSystem: TGameSystem);
    81113begin
    82 
     114  GameSystem.EmptyCellsNeutral := CheckBoxEmptyCellsNeutral.Checked;
     115  GameSystem.UnitsSplitMerge := CheckBoxUnitsSplitMerge.Checked;
     116  GameSystem.UnitsMoveImmediately := CheckBoxUnitsMoveImmediately.Checked;
    83117end;
    84118
  • trunk/Forms/UFormGameSystems.pas

    r275 r276  
    6767  SRemoveItems = 'Remove items';
    6868  SRemoveItemsQuery = 'Do you want to remove selected items?';
    69 
     69  SNewGameSystem = 'New game system';
    7070
    7171{ TFormGameSystems }
     
    9696  with TGameSystem(ListView1.Selected.Data) do begin
    9797    TempEntry := TGameSystem.Create;
     98    TempEntry.Assign(TGameSystem(ListView1.Selected.Data));
    9899    FormGameSystem := TFormGameSystem.Create(Self);
    99100    try
     
    101102      if FormGameSystem.ShowModal = mrOk then begin
    102103        FormGameSystem.SaveData(TempEntry);
     104        TGameSystem(ListView1.Selected.Data).Assign(TempEntry);
    103105        UpdateList;
    104106        UpdateInterface;
     
    118120  FormGameSystem := TFormGameSystem.Create(Self);
    119121  try
     122    TempEntry.FileName := SNewGameSystem + GameSystemExt;
    120123    FormGameSystem.LoadData(TempEntry);
    121124    if FormGameSystem.ShowModal = mrOk then begin
    122125      FormGameSystem.SaveData(TempEntry);
     126      TGameSystem(ListView1.Selected.Data).Assign(TempEntry);
    123127      UpdateList;
    124128      UpdateInterface;
     
    165169  if Item.Index < ListView1.Items.Count then
    166170  with TGameSystem(GameSystems[Item.Index]) do begin
    167     Item.Caption := Name;
     171    Item.Caption := GetName;
    168172    Item.Data := GameSystems[Item.Index];
    169173  end;
  • trunk/Forms/UFormNew.lfm

    r275 r276  
    2121    Top = 60
    2222    Width = 806
    23     ActivePage = TabSheetMode
     23    ActivePage = TabSheetRules
    2424    Align = alClient
    2525    BorderSpacing.Around = 4
    26     TabIndex = 0
     26    TabIndex = 3
    2727    TabOrder = 0
    2828    OnChange = PageControl1Change
     
    546546      object Panel4: TPanel
    547547        Left = 0
    548         Height = 652
     548        Height = 596
    549549        Top = 0
    550550        Width = 796
    551551        Align = alClient
    552552        BevelOuter = bvNone
    553         ClientHeight = 652
     553        ClientHeight = 596
    554554        ClientWidth = 796
    555555        TabOrder = 0
     
    694694          end
    695695        end
    696         object CheckBoxEmptyCellsNeutral: TCheckBox
    697           Left = 336
    698           Height = 30
    699           Top = 62
    700           Width = 362
    701           Caption = 'Set cells without player units as neutral'
    702           TabOrder = 5
    703         end
    704         object CheckBoxUnitsSplitMerge: TCheckBox
    705           Left = 336
    706           Height = 30
    707           Top = 101
    708           Width = 231
    709           Caption = 'Units can split or merge'
    710           TabOrder = 6
    711         end
    712         object CheckBoxUnitsMoveImmediately: TCheckBox
    713           Left = 336
    714           Height = 30
    715           Top = 141
    716           Width = 234
    717           Caption = 'Units move immediately'
    718           TabOrder = 7
    719         end
    720696      end
    721697    end
  • trunk/Forms/UFormNew.pas

    r275 r276  
    3333    ButtonPlayerModify: TButton;
    3434    ButtonPlayerRemove: TButton;
    35     CheckBoxUnitsSplitMerge: TCheckBox;
    36     CheckBoxEmptyCellsNeutral: TCheckBox;
    3735    CheckBoxBridges: TCheckBox;
    3836    CheckBoxCity: TCheckBox;
     
    4038    CheckBoxFogOfWar: TCheckBox;
    4139    CheckBoxSymetricMap: TCheckBox;
    42     CheckBoxUnitsMoveImmediately: TCheckBox;
    4340    CheckBoxVoid: TCheckBox;
    4441    ComboBoxGameSystem: TComboBox;
     
    192189uses
    193190  UFormPlayer, UFormChat, UCore, UFormServer, UClientGUI, UFormClient,
    194   UFormGameSystems;
     191  UFormGameSystems, UGameSystem;
    195192
    196193resourcestring
     
    367364    SpinEditTurns.Value := StayAliveForDefinedTurns;
    368365    SpinEditSpecialCells.Value := SpecialCaptureCellCount;
    369     CheckBoxEmptyCellsNeutral.Checked := GameSystem.EmptyCellsNeutral;
    370     CheckBoxUnitsSplitMerge.Checked := GameSystem.UnitsSplitMerge;
    371     CheckBoxUnitsMoveImmediately.Checked := GameSystem.UnitsMoveImmediately;
     366    ComboBoxGameSystem.ItemIndex := ComboBoxGameSystem.Items.IndexOf(GameSystemName);
    372367  end;
    373368end;
     
    398393    StayAliveForDefinedTurns := SpinEditTurns.Value;
    399394    SpecialCaptureCellCount := SpinEditSpecialCells.Value;
    400     GameSystem.EmptyCellsNeutral := CheckBoxEmptyCellsNeutral.Checked;
    401     GameSystem.UnitsSplitMerge := CheckBoxUnitsSplitMerge.Checked;
    402     GameSystem.UnitsMoveImmediately := CheckBoxUnitsMoveImmediately.Checked;
     395    GameSystem := TGameSystem(ComboBoxGameSystem.Items.Objects[ComboBoxGameSystem.ItemIndex]);
     396    GameSystemName := GameSystem.GetName;
    403397  end;
    404398end;
     
    424418      ComboBoxGameSystem.Items.Add('');
    425419    for I := 0 to Core.GameSystems.Count - 1 do begin
    426       ComboBoxGameSystem.Items[I] := Core.GameSystems[I].Name;
     420      ComboBoxGameSystem.Items[I] := Core.GameSystems[I].GetName;
    427421      ComboBoxGameSystem.Items.Objects[I] := Core.GameSystems[I];
    428422    end;
     
    558552  Core.PersistentForm.Load(Self);
    559553  Core.ThemeManager1.UseTheme(Self);
    560   ReloadGameSystemsMenu;
    561554  ReloadView;
    562555  //Height := Trunc(1.5 * Height);
     
    773766procedure TFormNew.Load(Server: TServer);
    774767begin
     768  ReloadGameSystemsMenu;
    775769  with Server do begin
    776770    RadioButtonModeLocal.Checked := Mode = smLocal;
  • trunk/Languages/xtactics.cs.po

    r275 r276  
    230230msgstr "Herní systém"
    231231
     232#: tformgamesystem.checkboxemptycellsneutral.caption
     233msgctxt "tformgamesystem.checkboxemptycellsneutral.caption"
     234msgid "Set cells without player units as neutral"
     235msgstr "Nastavit buňky bez jednotek hráče jako neutrální"
     236
     237#: tformgamesystem.checkboxunitsmoveimmediately.caption
     238msgctxt "tformgamesystem.checkboxunitsmoveimmediately.caption"
     239msgid "Units move immediately"
     240msgstr "Okamžitý pohyb jednotek"
     241
     242#: tformgamesystem.checkboxunitssplitmerge.caption
     243msgctxt "tformgamesystem.checkboxunitssplitmerge.caption"
     244msgid "Units can split or merge"
     245msgstr "Dělení nebo slučování jednotek"
     246
     247#: tformgamesystem.tabsheetgeneral.caption
     248msgctxt "tformgamesystem.tabsheetgeneral.caption"
     249msgid "General"
     250msgstr "Obecné"
     251
     252#: tformgamesystem.tabsheetunits.caption
     253msgctxt "tformgamesystem.tabsheetunits.caption"
     254msgid "Units"
     255msgstr "Jednotky"
     256
    232257#: tformgamesystems.aadd.caption
    233258msgctxt "tformgamesystems.aadd.caption"
     
    489514msgstr "Cyklická mapa"
    490515
    491 #: tformnew.checkboxemptycellsneutral.caption
    492 msgid "Set cells without player units as neutral"
    493 msgstr "Nastavit buňky bez jednotek hráče jako neutrální"
    494 
    495516#: tformnew.checkboxfogofwar.caption
    496517msgid "Fog of war"
     
    500521msgid "Symetric map"
    501522msgstr "Symetrická mapa"
    502 
    503 #: tformnew.checkboxunitsmoveimmediately.caption
    504 msgid "Units move immediately"
    505 msgstr "Okamžitý pohyb jednotek"
    506 
    507 #: tformnew.checkboxunitssplitmerge.caption
    508 msgid "Units can split or merge"
    509 msgstr "Dělení nebo slučování jednotek"
    510523
    511524#: tformnew.checkboxvoid.caption
     
    834847
    835848#: tformsettings.tabsheetgeneral.caption
     849msgctxt "tformsettings.tabsheetgeneral.caption"
    836850msgid "General"
    837851msgstr "Obecné"
     
    955969msgid "xTactics game system (.xts)|*.xts|All files|*.*"
    956970msgstr "xTactics herní systém (.xts)|*.xts|Všechny soubory|*.*"
     971
     972#: uformgamesystems.snewgamesystem
     973msgid "New game system"
     974msgstr "Nový herní systém"
    957975
    958976#: uformgamesystems.sremoveitems
  • trunk/Languages/xtactics.po

    r275 r276  
    220220msgstr ""
    221221
     222#: tformgamesystem.checkboxemptycellsneutral.caption
     223msgctxt "tformgamesystem.checkboxemptycellsneutral.caption"
     224msgid "Set cells without player units as neutral"
     225msgstr ""
     226
     227#: tformgamesystem.checkboxunitsmoveimmediately.caption
     228msgctxt "tformgamesystem.checkboxunitsmoveimmediately.caption"
     229msgid "Units move immediately"
     230msgstr ""
     231
     232#: tformgamesystem.checkboxunitssplitmerge.caption
     233msgctxt "tformgamesystem.checkboxunitssplitmerge.caption"
     234msgid "Units can split or merge"
     235msgstr ""
     236
     237#: tformgamesystem.tabsheetgeneral.caption
     238msgctxt "tformgamesystem.tabsheetgeneral.caption"
     239msgid "General"
     240msgstr ""
     241
     242#: tformgamesystem.tabsheetunits.caption
     243msgctxt "tformgamesystem.tabsheetunits.caption"
     244msgid "Units"
     245msgstr ""
     246
    222247#: tformgamesystems.aadd.caption
    223248msgctxt "tformgamesystems.aadd.caption"
     
    476501msgstr ""
    477502
    478 #: tformnew.checkboxemptycellsneutral.caption
    479 msgid "Set cells without player units as neutral"
    480 msgstr ""
    481 
    482503#: tformnew.checkboxfogofwar.caption
    483504msgid "Fog of war"
     
    486507#: tformnew.checkboxsymetricmap.caption
    487508msgid "Symetric map"
    488 msgstr ""
    489 
    490 #: tformnew.checkboxunitsmoveimmediately.caption
    491 msgid "Units move immediately"
    492 msgstr ""
    493 
    494 #: tformnew.checkboxunitssplitmerge.caption
    495 msgid "Units can split or merge"
    496509msgstr ""
    497510
     
    819832
    820833#: tformsettings.tabsheetgeneral.caption
     834msgctxt "tformsettings.tabsheetgeneral.caption"
    821835msgid "General"
    822836msgstr ""
     
    939953#: uformgamesystem.sfiledialogfilter
    940954msgid "xTactics game system (.xts)|*.xts|All files|*.*"
     955msgstr ""
     956
     957#: uformgamesystems.snewgamesystem
     958msgid "New game system"
    941959msgstr ""
    942960
  • trunk/UGame.pas

    r275 r276  
    684684    end;
    685685    if ExtractFileDir(FileName) <> '' then
    686       ForceDirectoriesUTF8(ExtractFileDir(FileName));
     686      ForceDirectories(ExtractFileDir(FileName));
    687687    WriteXMLFile(Doc, FileName);
    688688  finally
  • trunk/UGameSystem.pas

    r275 r276  
    66
    77uses
    8   Classes, SysUtils, fgl, UUnit, DOM, XMLRead, XMLWrite, UXMLUtils, XMLConf;
     8  Classes, SysUtils, fgl, UUnit, DOM, XMLRead, XMLWrite, UXMLUtils, XMLConf,
     9  FileUtil;
    910
    1011type
     
    1415
    1516  TGameSystem = class
    16     Name: string;
     17    FileName: string;
    1718    MaxPlayerCount: Integer;
    1819    UnitKinds: TUnitKinds;
     
    2021    EmptyCellsNeutral: Boolean;
    2122    UnitsMoveImmediately: Boolean;
    22     FileName: string;
    2323    constructor Create;
    2424    destructor Destroy; override;
    2525    procedure Clear;
     26    function GetName: string;
    2627    procedure Assign(Source: TGameSystem);
    2728    procedure LoadFromNode(Node: TDOMNode);
     
    4041  end;
    4142
     43const
     44  GameSystemExt = '.xts';
     45
    4246
    4347implementation
     
    5155begin
    5256  Result := TGameSystem.Create;
    53   Result.Name := Name;
     57  Result.FileName := Name;
    5458  Add(Result);
    5559end;
     
    6064begin
    6165  I := 0;
    62   while (I < Count) and (Items[I].Name <> Name) do Inc(I);
     66  while (I < Count) and (TGameSystem(Items[I]).GetName <> Name) do Inc(I);
    6367  if I < Count then Result := Items[I]
    6468    else Result := nil;
     
    8387end;
    8488
     89function TGameSystem.GetName: string;
     90begin
     91  Result := ExtractFileNameWithoutExt(ExtractFileName(FileName));
     92end;
     93
    8594procedure TGameSystem.Assign(Source: TGameSystem);
    8695begin
    87   Name := Source.Name;
     96  FileName := Source.FileName;
    8897  UnitsMoveImmediately := Source.UnitsMoveImmediately;
    8998  MaxPlayerCount := Source.MaxPlayerCount;
     
    96105  NewNode: TDOMNode;
    97106begin
    98   Name := ReadString(Node, 'Name', '');
    99107  UnitsSplitMerge := ReadBoolean(Node, 'UnitsSplitMerge', False);
    100108  EmptyCellsNeutral := ReadBoolean(Node, 'EmptyCellsNeutral', False);
     
    110118  NewNode: TDOMNode;
    111119begin
    112   WriteString(Node, 'Name', Name);
    113120  WriteBoolean(Node, 'UnitsSplitMerge', UnitsSplitMerge);
    114121  WriteBoolean(Node, 'EmptyCellsNeutral', EmptyCellsNeutral);
     
    129136  Clear;
    130137  with Doc do try
    131     if Doc.DocumentElement.NodeName <> 'XtacticsRules' then
     138    if Doc.DocumentElement.NodeName <> 'XtacticsGameSystem' then
    132139      raise Exception.Create(SWrongFileFormat);
    133140    RootNode := Doc.DocumentElement;
     
    146153  Doc := TXMLDocument.Create;
    147154  with Doc do try
    148     RootNode := CreateElement('XtacticsRules');
     155    RootNode := CreateElement('XtacticsGameSystem');
    149156    AppendChild(RootNode);
    150157    SaveToNode(RootNode);
     
    160167begin
    161168  with Config do begin
    162     Self.Name := string(GetValue(DOMString(Path + '/Name'), DOMString('')));
    163169    UnitsSplitMerge := GetValue(DOMString(Path + '/UnitsSplitMerge'), True);
    164170    EmptyCellsNeutral := GetValue(DOMString(Path + '/EmptyCellsNeutral'), False);
     
    170176begin
    171177  with Config do begin
    172     SetValue(DOMString(Path + '/Name'), DOMString(Self.Name));
    173178    SetValue(DOMString(Path + '/UnitsSplitMerge'), UnitsSplitMerge);
    174179    SetValue(DOMString(Path + '/EmptyCellsNeutral'), EmptyCellsNeutral);
Note: See TracChangeset for help on using the changeset viewer.