Changeset 130


Ignore:
Timestamp:
May 1, 2023, 4:02:31 PM (20 months ago)
Author:
chronos
Message:
  • Added: Allow to save/load game in multiple slots.
Location:
trunk
Files:
3 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.lfm

    r125 r130  
    1515  OnKeyUp = FormKeyUp
    1616  OnShow = FormShow
    17   LCLVersion = '2.2.4.0'
     17  LCLVersion = '2.2.6.0'
    1818  object PaintBox1: TPaintBox
    1919    Left = 0
  • trunk/Languages/TransLines.cs.po

    r128 r130  
    233233msgstr "Tvary"
    234234
     235#: uengine.sslot
     236msgid "Slot"
     237msgstr "Pozice"
     238
    235239#: uengine.sstationnotdefined
    236240msgid "Station have to be defined"
  • trunk/Languages/TransLines.de.po

    r128 r130  
    237237msgstr ""
    238238
     239#: uengine.sslot
     240msgid "Slot"
     241msgstr ""
     242
    239243#: uengine.sstationnotdefined
    240244msgid "Station have to be defined"
  • trunk/Languages/TransLines.fr.po

    r128 r130  
    238238msgstr ""
    239239
     240#: uengine.sslot
     241msgid "Slot"
     242msgstr ""
     243
    240244#: uengine.sstationnotdefined
    241245msgid "Station have to be defined"
  • trunk/Languages/TransLines.pot

    r128 r130  
    223223msgstr ""
    224224
     225#: uengine.sslot
     226msgid "Slot"
     227msgstr ""
     228
    225229#: uengine.sstationnotdefined
    226230msgid "Station have to be defined"
  • trunk/TransLines.lpi

    r128 r130  
    3131          <SearchPaths>
    3232            <IncludeFiles Value="$(ProjOutDir)"/>
    33             <OtherUnitFiles Value="Forms"/>
     33            <OtherUnitFiles Value="Forms;Scenes"/>
    3434            <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)-$(BuildMode)"/>
    3535          </SearchPaths>
     
    8989      </Item2>
    9090    </RequiredPackages>
    91     <Units Count="17">
     91    <Units Count="19">
    9292      <Unit0>
    9393        <Filename Value="TransLines.lpr"/>
     
    173173        <IsPartOfProject Value="True"/>
    174174      </Unit16>
     175      <Unit17>
     176        <Filename Value="UScene.pas"/>
     177        <IsPartOfProject Value="True"/>
     178      </Unit17>
     179      <Unit18>
     180        <Filename Value="Scenes/USceneGameSlots.pas"/>
     181        <IsPartOfProject Value="True"/>
     182      </Unit18>
    175183    </Units>
    176184  </ProjectOptions>
     
    182190    <SearchPaths>
    183191      <IncludeFiles Value="$(ProjOutDir)"/>
    184       <OtherUnitFiles Value="Forms"/>
     192      <OtherUnitFiles Value="Forms;Scenes"/>
    185193      <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)-$(BuildMode)"/>
    186194    </SearchPaths>
  • trunk/TransLines.lpr

    r128 r130  
    1010  Forms, SysUtils, UFormMain, UFormImages, UFormTestCase, UFormTest, Common,
    1111  UMenu, UControls, UMetroPassenger, UColors, UView, URiver, UCity, UCore,
    12   UTestCases, UItems;
     12  UTestCases, UItems, UScene, USceneGameSlots;
    1313
    1414{$R *.res}
  • trunk/UCity.pas

    r110 r130  
    2828
    2929  TCities = class(TObjectList<TCity>)
     30    function SearchBySysName(SysName: string): TCity;
    3031    function AddNew(SysName, Name: string; Population: Integer): TCity;
    3132    procedure LoadFromRegistry(Context: TRegistryContext);
     
    8182{ TCities }
    8283
     84function TCities.SearchBySysName(SysName: string): TCity;
     85var
     86  I: Integer;
     87begin
     88  I := 0;
     89  while (I < Count) and (Items[I].SysName <> SysName) do Inc(I);
     90  if I < Count then Result := Items[I]
     91    else Result := nil;
     92end;
     93
    8394function TCities.AddNew(SysName, Name: string; Population: Integer): TCity;
    8495begin
  • trunk/UEngine.pas

    r129 r130  
    1010  URegistry, UMetaCanvas, Generics.Collections, Generics.Defaults, UMenu,
    1111  UControls, UMetroPassenger, UColors, UView, URiver, UTrack, UCity, UGeometric,
    12   UTranslator, DOM, XMLRead, XMLWrite, UXMLUtils, UItems;
     12  UTranslator, DOM, XMLRead, XMLWrite, UXMLUtils, UItems, FileUtil;
    1313
    1414type
     
    227227    MenuGame: TMenu;
    228228    MenuCustomGame: TMenu;
     229    MenuGameSlots: TMenu;
    229230    LastState: TGameState;
    230231    TimePerSecond: TDateTime;
     
    237238    GrabbedTrainDirection: Integer;
    238239    LastGrabbedTrain: TMetroTrain;
    239     SavedGameFileName: string;
    240240    function GetMetroLineThickness: Integer;
    241241    function GetServedDaysCount: Integer;
     
    286286    procedure MenuItemGameLoad(Sender: TObject);
    287287    procedure MenuItemGameSave(Sender: TObject);
     288    procedure MenuItemGameSlotLoad(Sender: TObject);
     289    procedure MenuItemGameSlotSave(Sender: TObject);
    288290    procedure MenuItemBack(Sender: TObject);
    289291    procedure ButtonPlay(Sender: TObject);
     
    304306    function GetImprovementBitmap(Improvement: TMetroImprovement): TBitmap;
    305307    procedure EvaluateImprovement(Improvement: TMetroImprovement);
     308    procedure ReloadGameSlots(Save: Boolean);
     309    function GetGameSlotFileName(Index: Integer): string;
    306310  public
    307311    // Test
     
    465469  SVisualStyle = 'Visual style';
    466470  SStationStyle = 'Station style';
     471  SSlot = 'Slot';
    467472
    468473  // Cities
     
    22872292procedure TEngine.MenuItemGameLoad(Sender: TObject);
    22882293begin
    2289   LoadFromFile(SavedGameFileName);
     2294  ReloadGameSlots(False);
     2295  Menu := MenuGameSlots;
     2296end;
     2297
     2298procedure TEngine.MenuItemGameSave(Sender: TObject);
     2299begin
     2300  ReloadGameSlots(True);
     2301  Menu := MenuGameSlots;
     2302end;
     2303
     2304procedure TEngine.MenuItemGameSlotLoad(Sender: TObject);
     2305begin
     2306  LoadFromFile(GetGameSlotFileName(Integer(TMenuItemButton(Sender).Ref)));
    22902307  State := gsRunning;
    22912308end;
    22922309
    2293 procedure TEngine.MenuItemGameSave(Sender: TObject);
    2294 begin
    2295   SaveToFile(SavedGameFileName);
     2310procedure TEngine.MenuItemGameSlotSave(Sender: TObject);
     2311begin
     2312  SaveToFile(GetGameSlotFileName(Integer(TMenuItemButton(Sender).Ref)));
    22962313  State := LastState;
    22972314end;
     
    24262443    miTerminal: Inc(AvailableTerminals);
    24272444  end;
     2445end;
     2446
     2447procedure TEngine.ReloadGameSlots(Save: Boolean);
     2448var
     2449  I: Integer;
     2450  Action: TNotifyEvent;
     2451  FileName: string;
     2452  FileDateTime: TDateTime;
     2453  ControlName: string;
     2454const
     2455  GameSlotCount = 6;
     2456begin
     2457  with MenuGameSlots, Items do begin
     2458    Clear;
     2459    Parent := Menu;
     2460    if Save then Action := MenuItemGameSlotSave
     2461      else Action := MenuItemGameSlotLoad;
     2462    for I := 0 to GameSlotCount - 1 do begin
     2463      FileName := GetGameSlotFileName(Integer(I));
     2464      ControlName := SSlot + ' ' + IntToStr(I);
     2465      if FileExists(FileName) then begin
     2466        FileAge(FileName, FileDateTime);
     2467        ControlName := ControlName + ' (' + DateTimeToStr(FileDateTime) + ')';
     2468      end;
     2469      with AddButton(ControlName, Action) do begin
     2470        Ref := TObject(I);
     2471        Enabled := FileExists(FileName) or Save;
     2472        TextSize := 40;
     2473        TextColor := Colors.MenuItemText;
     2474        TextDisabledColor := Colors.MenuItemDisabledText;
     2475        BackgroundColor := Colors.MenuItemBackground;
     2476        BackgroundSelectedColor := Colors.MenuItemBackgroundSelected;
     2477      end;
     2478    end;
     2479    with AddButton(SExit, MenuItemBack) do begin
     2480      TextSize := 40;
     2481      TextColor := Colors.MenuItemText;
     2482      TextDisabledColor := Colors.MenuItemDisabledText;
     2483      BackgroundColor := Colors.MenuItemBackground;
     2484      BackgroundSelectedColor := Colors.MenuItemBackgroundSelected;
     2485    end;
     2486    OnExit := MenuItemBack;
     2487  end;
     2488end;
     2489
     2490function TEngine.GetGameSlotFileName(Index: Integer): string;
     2491begin
     2492  Result := GetAppConfigDir(False) + 'Saved game ' + IntToStr(Index) + TransLinesExt;
    24282493end;
    24292494
     
    24702535    end;
    24712536    with AddButton(SLoad, MenuItemGameLoad) do begin
    2472       Enabled := FileExists(SavedGameFileName);
    24732537      TextSize := 40;
    24742538      TextColor := Colors.MenuItemText;
     
    25272591    end;
    25282592    with AddButton(SLoad, MenuItemGameLoad) do begin
    2529       Enabled := FileExists(SavedGameFileName);
    25302593      TextSize := 40;
    25312594      TextColor := Colors.MenuItemText;
     
    39574020  FTime := ReadDateTime(Node, 'Time', 0);
    39584021  FLastTime := FTime;
     4022  City := Cities.SearchBySysName(ReadString(Node, 'CityName', ''));
    39594023
    39604024  NewNode := Node.FindNode(DOMString(TView.GetClassSysName));
     
    40074071  WriteInteger(Node, 'State', Integer(State));
    40084072  WriteDateTime(Node, 'Time', FTime);
     4073  if Assigned(City) then WriteString(Node, 'CityName', City.SysName);
    40094074
    40104075  NewNode := Node.OwnerDocument.CreateElement(DOMString(TView.GetClassSysName));
     
    40784143begin
    40794144  inherited;
    4080   SavedGameFileName := GetAppConfigDir(False) + 'LastGameState' + TransLinesExt;
    40814145  MovableTracks := True;
    40824146  Colors := TColors.Create;
     
    40954159  MenuGame := TMenu.Create;
    40964160  MenuCustomGame := TMenu.Create;
     4161  MenuGameSlots := TMenu.Create;
    40974162  Menu := MenuMain;
    40984163  InitMenus;
     
    41594224  FreeAndNil(MenuCareer);
    41604225  FreeAndNil(MenuGame);
     4226  FreeAndNil(MenuGameSlots);
    41614227  FreeAndNil(Cities);
    41624228  FreeAndNil(ButtonBack);
  • trunk/UMenu.pas

    r100 r130  
    7575    procedure MouseUp(Button: TMouseButton; Position: TPoint);
    7676    procedure Paint(Canvas: TCanvas; CanvasSize: TPoint);
    77     constructor Create;
     77    constructor Create; virtual;
    7878    destructor Destroy; override;
    7979    property OnExit: TNotifyEvent read FOnExit write FOnExit;
     
    286286end;
    287287
    288 
    289288end.
    290289
Note: See TracChangeset for help on using the changeset viewer.