Ignore:
Timestamp:
Mar 24, 2019, 2:26:29 PM (6 years ago)
Author:
chronos
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormNew.pas

    r282 r287  
    105105    procedure ButtonGameSystemsClick(Sender: TObject);
    106106    procedure ButtonImageBrowseClick(Sender: TObject);
     107    procedure ButtonOkClick(Sender: TObject);
    107108    procedure ButtonRandomizeClick(Sender: TObject);
    108109    procedure CheckBoxBridgesChange(Sender: TObject);
     
    138139    procedure TrackBarSizeXChange(Sender: TObject);
    139140  private
    140     Players: TPlayers;
     141    FServer: TServer;
    141142    ServerList: TServerList;
    142143    GamePreview: TGame;
     
    144145    NewRandSeed: Cardinal;
    145146    FormPlayers: TFormPlayers;
    146     GameSystem: TGameSystem;
    147147    procedure LoadGame(Game: TGame);
    148148    procedure SaveGame(Game: TGame);
     149    procedure Load(Server: TServer);
     150    procedure Save(Server: TServer);
    149151    procedure MapPreviewPaint;
    150152    procedure MapPreviewRedraw;
    151153    procedure ReloadGameSystemsMenu;
     154    procedure SetServer(AValue: TServer);
    152155  public
    153156    procedure Translate;
    154157    procedure ReloadView;
    155158    procedure UpdateInterface;
    156     procedure Load(Server: TServer);
    157     procedure Save(Server: TServer);
     159    property Server: TServer read FServer write SetServer;
    158160  end;
    159161
     
    278280procedure TFormNew.LoadGame(Game: TGame);
    279281begin
    280   FormPlayers.Players.Assign(Game.Players);
    281282  with Game do begin
    282283    CheckBoxSymetricMap.Checked := SymetricMap;
     
    303304    SpinEditTurns.Value := StayAliveForDefinedTurns;
    304305    SpinEditSpecialCells.Value := SpecialCaptureCellCount;
     306    GameSystem := Game.GameSystem;
    305307    ComboBoxGameSystem.ItemIndex := ComboBoxGameSystem.Items.IndexOf(GameSystemName);
     308    if (ComboBoxGameSystem.ItemIndex = -1) and (ComboBoxGameSystem.Items.Count > 0) then
     309      ComboBoxGameSystem.ItemIndex := 0;
    306310  end;
    307311end;
     
    309313procedure TFormNew.SaveGame(Game: TGame);
    310314begin
    311   Game.Players.Assign(FormPlayers.Players);
    312315  with Game do begin
    313316    StoredRandSeed := NewRandSeed;
     
    332335    StayAliveForDefinedTurns := SpinEditTurns.Value;
    333336    SpecialCaptureCellCount := SpinEditSpecialCells.Value;
    334     GameSystem := TGameSystem(ComboBoxGameSystem.Items.Objects[ComboBoxGameSystem.ItemIndex]);
    335     GameSystemName := GameSystem.GetName;
     337    if ComboBoxGameSystem.ItemIndex <> -1 then begin
     338      GameSystem := TGameSystem(ComboBoxGameSystem.Items.Objects[ComboBoxGameSystem.ItemIndex]);
     339      GameSystemName := GameSystem.GetName;
     340    end else begin
     341      GameSystem := nil;
     342      GameSystemName := '';
     343    end;
    336344  end;
    337345end;
     
    366374  finally
    367375    ComboBoxGameSystem.Items.EndUpdate;
     376  end;
     377  if (ComboBoxGameSystem.ItemIndex = -1) and (ComboBoxGameSystem.Items.Count > 0) then
     378    ComboBoxGameSystem.ItemIndex := 0;
     379end;
     380
     381procedure TFormNew.SetServer(AValue: TServer);
     382begin
     383  if FServer = AValue then Exit;
     384  FServer := AValue;
     385  if Assigned(FServer) then begin
     386    Load(FServer);
     387    FormPlayers.Players := FServer.Game.Players;
     388  end else begin
     389    FormPlayers.Players := nil;
    368390  end;
    369391end;
     
    452474  ListViewServers.Items.Count := ServerList.Items.Count;
    453475  ListViewServers.Refresh;
    454   Translate;
    455476  UpdateInterface;
    456477end;
     
    460481  WinObjective: TWinObjective;
    461482begin
    462   GameSystem := TGameSystem(ComboBoxGameSystem.Items.Objects[ComboBoxGameSystem.ItemIndex]);
    463   ComboBoxGridType.Enabled := GameSystem.PreferedMapType = mtNone;
    464   if GameSystem.PreferedMapType <> mtNone then
    465     ComboBoxGridType.ItemIndex := ComboBoxGridType.Items.IndexOfObject(TObject(GameSystem.PreferedMapType));
     483
     484  ComboBoxGridType.Enabled := FServer.Game.GameSystem.PreferedMapType = mtNone;
     485  if FServer.Game.GameSystem.PreferedMapType <> mtNone then
     486    ComboBoxGridType.ItemIndex := ComboBoxGridType.Items.IndexOfObject(TObject(FServer.Game.GameSystem.PreferedMapType));
    466487  EditImageFile.Enabled := ComboBoxMapShape.ItemIndex = Integer(msImage);
    467488  ButtonImageBrowse.Enabled := ComboBoxMapShape.ItemIndex = Integer(msImage);
     
    513534  FormChat.Align := alClient;
    514535  FormChat.Show;
    515   Players := TPlayers.Create;
    516   Players.Game := GamePreview;
    517536  FormPlayers := TFormPlayers.Create(nil);
    518537  FormPlayers.MinItemCount := MinPlayerCount;
    519538  FormPlayers.MaxItemCount := MaxPlayerCount;
    520   FormPlayers.Players := Players;
    521539  FormPlayers.ManualDock(Panel2, nil, alClient);
    522540  FormPlayers.Align := alClient;
     
    549567procedure TFormNew.ComboBoxGameSystemChange(Sender: TObject);
    550568begin
     569  FServer.Game.GameSystem := TGameSystem(ComboBoxGameSystem.Items.Objects[ComboBoxGameSystem.ItemIndex]);
    551570  UpdateInterface;
    552571  MapPreviewRedraw;
     
    641660end;
    642661
     662procedure TFormNew.ButtonOkClick(Sender: TObject);
     663begin
     664  Save(FServer);
     665end;
     666
    643667procedure TFormNew.ButtonRandomizeClick(Sender: TObject);
    644668begin
     
    657681  FreeAndNil(ServerList);
    658682  FreeAndNil(FormChat);
    659   FreeAndNil(Players);
    660683  FreeAndNil(FormPlayers);
    661684  FreeAndNil(GamePreview);
     
    673696  end;
    674697  ServerList.Assign(Core.ServerList);
    675   LoadGame(Core.GameSettings);
     698  LoadGame(Server.Game);
    676699end;
    677700
     
    693716  end;
    694717  Core.ServerList.Assign(ServerList);
    695   SaveGame(Core.GameSettings);
     718  SaveGame(Server.Game);
    696719end;
    697720
Note: See TracChangeset for help on using the changeset viewer.