Ignore:
Timestamp:
Feb 6, 2018, 3:47:23 PM (7 years ago)
Author:
chronos
Message:
  • Added: A preparation for gameplay over network.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormNew.pas

    r170 r179  
    1818    APlayerModify: TAction;
    1919    ActionList1: TActionList;
     20    ButtonCancel: TButton;
    2021    ButtonImageBrowse: TButton;
    21     ButtonCancel: TButton;
    2222    ButtonOk: TButton;
    2323    ButtonPlayerAdd: TButton;
     
    3232    ComboBoxMapShape: TComboBox;
    3333    ComboBoxWinObjective: TComboBox;
     34    EditServerAddress: TEdit;
    3435    EditImageFile: TEdit;
    3536    Label1: TLabel;
     37    Label11: TLabel;
     38    Label12: TLabel;
    3639    Label2: TLabel;
    3740    Label3: TLabel;
     
    4245    Label8: TLabel;
    4346    Label9: TLabel;
    44     ListView1: TListView;
     47    ListViewPlayers: TListView;
     48    ListViewServers: TListView;
    4549    MenuItem1: TMenuItem;
    4650    MenuItem2: TMenuItem;
     
    4852    OpenPictureDialog1: TOpenPictureDialog;
    4953    PageControl1: TPageControl;
     54    PanelButtons: TPanel;
     55    PanelChat: TPanel;
    5056    PopupMenu1: TPopupMenu;
     57    RadioButtonModeNetworkServer: TRadioButton;
     58    RadioButtonModeNetworkClient: TRadioButton;
     59    RadioButtonModeLocal: TRadioButton;
    5160    RadioGroupGrowAmount: TRadioGroup;
    5261    RadioGroupGrowCells: TRadioGroup;
     62    SpinEditServerPort: TSpinEdit;
    5363    SpinEditCityPercent: TSpinEdit;
    5464    SpinEditMapSizeX: TSpinEdit;
     
    5666    SpinEditNeutralUnits: TSpinEdit;
    5767    SpinEditVoidPercent: TSpinEdit;
     68    Splitter1: TSplitter;
    5869    TabSheet1: TTabSheet;
    5970    TabSheet2: TTabSheet;
    6071    TabSheet3: TTabSheet;
     72    TabSheetMode: TTabSheet;
    6173    TrackBarSizeX: TTrackBar;
    6274    TrackBarSizeY: TTrackBar;
     
    6880    procedure CheckBoxVoidChange(Sender: TObject);
    6981    procedure ComboBoxMapShapeChange(Sender: TObject);
     82    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    7083    procedure FormCreate(Sender: TObject);
    7184    procedure FormDestroy(Sender: TObject);
    7285    procedure FormShow(Sender: TObject);
    73     procedure ListView1CustomDrawSubItem(Sender: TCustomListView;
     86    procedure ListViewPlayersCustomDrawSubItem(Sender: TCustomListView;
    7487      Item: TListItem; SubItem: Integer; State: TCustomDrawState;
    7588      var DefaultDraw: Boolean);
    76     procedure ListView1Data(Sender: TObject; Item: TListItem);
    77     procedure ListView1DblClick(Sender: TObject);
    78     procedure ListView1KeyPress(Sender: TObject; var Key: char);
    79     procedure ListView1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState
     89    procedure ListViewPlayersData(Sender: TObject; Item: TListItem);
     90    procedure ListViewPlayersDblClick(Sender: TObject);
     91    procedure ListViewPlayersKeyPress(Sender: TObject; var Key: char);
     92    procedure ListViewPlayersKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState
    8093      );
    81     procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
     94    procedure ListViewPlayersSelectItem(Sender: TObject; Item: TListItem;
    8295      Selected: Boolean);
     96    procedure RadioButtonModeLocalChange(Sender: TObject);
    8397    procedure SpinEditMapSizeXChange(Sender: TObject);
    8498    procedure SpinEditMapSizeYChange(Sender: TObject);
     
    91105    procedure ReloadView;
    92106    procedure UpdateInterface;
    93     procedure Load(Game: TGame);
    94     procedure Save(Game: TGame);
     107    procedure Load(Server: TServer);
     108    procedure Save(Server: TServer);
    95109  end;
    96110
     
    103117
    104118uses
    105   UFormPlayer;
     119  UFormPlayer, UFormChat, UCore;
    106120
    107121resourcestring
     
    125139{ TFormNew }
    126140
    127 procedure TFormNew.ListView1Data(Sender: TObject; Item: TListItem);
     141procedure TFormNew.ListViewPlayersData(Sender: TObject; Item: TListItem);
    128142begin
    129143  if (Item.Index >= 0) and (Item.Index < Players.Count) then
     
    137151end;
    138152
    139 procedure TFormNew.ListView1DblClick(Sender: TObject);
     153procedure TFormNew.ListViewPlayersDblClick(Sender: TObject);
    140154begin
    141155  APlayerModify.Execute;
    142156end;
    143157
    144 procedure TFormNew.ListView1KeyPress(Sender: TObject; var Key: char);
     158procedure TFormNew.ListViewPlayersKeyPress(Sender: TObject; var Key: char);
    145159begin
    146160  if (Key = #13) then APlayerModify.Execute;
    147161end;
    148162
    149 procedure TFormNew.ListView1KeyUp(Sender: TObject; var Key: Word;
     163procedure TFormNew.ListViewPlayersKeyUp(Sender: TObject; var Key: Word;
    150164  Shift: TShiftState);
    151165begin
     
    154168end;
    155169
    156 procedure TFormNew.ListView1SelectItem(Sender: TObject; Item: TListItem;
     170procedure TFormNew.ListViewPlayersSelectItem(Sender: TObject; Item: TListItem;
    157171  Selected: Boolean);
    158172begin
    159173  ReloadView;
     174end;
     175
     176procedure TFormNew.RadioButtonModeLocalChange(Sender: TObject);
     177begin
     178  UpdateInterface;
    160179end;
    161180
     
    225244    ItemIndex := LastIndex;
    226245  end;
     246  Core.CoolTranslator1.TranslateComponentRecursive(Self);
    227247end;
    228248
    229249procedure TFormNew.ReloadView;
    230250begin
    231   ListView1.Items.Count := Players.Count;
    232   ListView1.Refresh;
     251  ListViewPlayers.Items.Count := Players.Count;
     252  ListViewPlayers.Refresh;
    233253  Translate;
    234254  UpdateInterface;
     
    237257procedure TFormNew.UpdateInterface;
    238258begin
    239   APlayerRemove.Enabled := Assigned(ListView1.Selected) and (Players.Count > 2);
     259  APlayerRemove.Enabled := Assigned(ListViewPlayers.Selected) and (Players.Count > 2);
    240260  APlayerAdd.Enabled := Players.Count < MaxPlayerCount;
    241   APlayerModify.Enabled := Assigned(ListView1.Selected);
     261  APlayerModify.Enabled := Assigned(ListViewPlayers.Selected);
    242262  EditImageFile.Enabled := ComboBoxMapShape.ItemIndex = Integer(msImage);
    243263  ButtonImageBrowse.Enabled := ComboBoxMapShape.ItemIndex = Integer(msImage);
     264  EditServerAddress.Enabled := RadioButtonModeNetworkServer.Checked;
     265  SpinEditServerPort.Enabled := RadioButtonModeNetworkServer.Checked;
     266  ListViewServers.Enabled := RadioButtonModeNetworkClient.Checked;
    244267end;
    245268
    246269procedure TFormNew.FormShow(Sender: TObject);
    247270begin
     271  Core.PersistentForm.Load(Self);
    248272  ReloadView;
    249273  //Height := Trunc(1.5 * Height);
     
    251275end;
    252276
    253 procedure TFormNew.ListView1CustomDrawSubItem(Sender: TCustomListView;
     277procedure TFormNew.ListViewPlayersCustomDrawSubItem(Sender: TCustomListView;
    254278  Item: TListItem; SubItem: Integer; State: TCustomDrawState;
    255279  var DefaultDraw: Boolean);
    256280begin
    257281  if SubItem = 2 then
    258   with ListView1.Canvas do begin
     282  with ListViewPlayers.Canvas do begin
    259283    Brush.Color := TPlayer(Item.Data).Color;
    260284    Brush.Style := bsSolid;
     
    266290begin
    267291  Players := TPlayers.Create;
     292  FormChat := TFormChat.Create(nil);
     293  FormChat.ManualDock(PanelChat, nil, alClient);
     294  FormChat.Align := alClient;
     295  FormChat.Show;
     296  Translate;
    268297end;
    269298
     
    283312end;
    284313
     314procedure TFormNew.FormClose(Sender: TObject; var CloseAction: TCloseAction);
     315begin
     316  Core.PersistentForm.Save(Self);
     317end;
     318
    285319procedure TFormNew.APlayerModifyExecute(Sender: TObject);
    286320begin
    287   if Assigned(ListView1.Selected) then begin
    288     FormPlayer.Load(TPlayer(ListView1.Selected.Data));
     321  if Assigned(ListViewPlayers.Selected) then begin
     322    FormPlayer.Load(TPlayer(ListViewPlayers.Selected.Data));
    289323    if FormPlayer.ShowModal = mrOk then begin
    290       FormPlayer.Save(TPlayer(ListView1.Selected.Data));
     324      FormPlayer.Save(TPlayer(ListViewPlayers.Selected.Data));
    291325      ReloadView;
    292326    end;
     
    296330procedure TFormNew.APlayerRemoveExecute(Sender: TObject);
    297331begin
    298   if Assigned(ListView1.Selected) then begin
    299     Players.Remove(ListView1.Selected.Data);
     332  if Assigned(ListViewPlayers.Selected) then begin
     333    Players.Remove(ListViewPlayers.Selected.Data);
    300334    ReloadView;
    301335  end;
     
    328362procedure TFormNew.FormDestroy(Sender: TObject);
    329363begin
    330   Players.Free;
    331 end;
    332 
    333 procedure TFormNew.Load(Game: TGame);
    334 begin
    335   CheckBoxSymetricMap.Checked := Game.SymetricMap;
    336   CheckBoxVoid.Checked := Game.VoidEnabled;
    337   SpinEditVoidPercent.Value := Game.VoidPercentage;
    338   SpinEditVoidPercent.Enabled := Game.VoidEnabled;
    339   Players.Assign(Game.PlayersSetting);
    340   CheckBoxCity.Checked := Game.CityEnabled;
    341   SpinEditCityPercent.Value := Game.CityPercentage;
    342   SpinEditMapSizeX.Value := Game.Map.Size.X;
    343   SpinEditMapSizeY.Value := Game.Map.Size.Y;
    344   TrackBarSizeX.Position := Game.Map.Size.X;
    345   TrackBarSizeY.Position := Game.Map.Size.Y;
    346   RadioGroupGrowAmount.ItemIndex := Integer(Game.GrowAmount);
    347   RadioGroupGrowCells.ItemIndex := Integer(Game.GrowCells);
    348   ComboBoxGridType.ItemIndex := Integer(Game.MapType) - 1;
    349   ComboBoxWinObjective.ItemIndex := Integer(Game.WinObjective);
    350   SpinEditNeutralUnits.Value := Game.MaxNeutralUnits;
    351   ComboBoxMapShape.ItemIndex := Integer(Game.Map.Shape);
    352   EditImageFile.Text := Game.MapImageFileName;
    353   CheckBoxFogOfWar.Checked := Game.FogOfWar;
    354   CheckBoxBridges.Checked := Game.BridgeEnabled;
    355 end;
    356 
    357 procedure TFormNew.Save(Game: TGame);
    358 begin
    359   Game.PlayersSetting.Assign(Players);
    360   Game.SymetricMap := CheckBoxSymetricMap.Checked;
    361   Game.VoidEnabled := CheckBoxVoid.Checked;
    362   Game.VoidPercentage := SpinEditVoidPercent.Value;
    363   Game.CityEnabled := CheckBoxCity.Checked;
    364   Game.CityPercentage := SpinEditCityPercent.Value;
    365   Game.Map.Size := TPoint.Create(SpinEditMapSizeX.Value, SpinEditMapSizeY.Value);
    366   Game.GrowAmount := TGrowAmount(RadioGroupGrowAmount.ItemIndex);
    367   Game.GrowCells := TGrowCells(RadioGroupGrowCells.ItemIndex);
    368   Game.MapType := TMapType(ComboBoxGridType.ItemIndex + 1);
    369   Game.WinObjective := TWinObjective(ComboBoxWinObjective.ItemIndex);
    370   Game.MaxNeutralUnits := SpinEditNeutralUnits.Value;
    371   Game.Map.Shape := TMapShape(ComboBoxMapShape.ItemIndex);
    372   Game.MapImageFileName := EditImageFile.Text;
    373   Game.FogOfWar := CheckBoxFogOfWar.Checked;
    374   Game.BridgeEnabled := CheckBoxBridges.Checked;
     364  FreeAndNil(Players);
     365  FreeAndNil(FormChat);
     366end;
     367
     368procedure TFormNew.Load(Server: TServer);
     369begin
     370  with Server do begin
     371    CheckBoxSymetricMap.Checked := Game.SymetricMap;
     372    CheckBoxVoid.Checked := Game.VoidEnabled;
     373    SpinEditVoidPercent.Value := Game.VoidPercentage;
     374    SpinEditVoidPercent.Enabled := Game.VoidEnabled;
     375    Players.Assign(Game.PlayersSetting);
     376    CheckBoxCity.Checked := Game.CityEnabled;
     377    SpinEditCityPercent.Value := Game.CityPercentage;
     378    SpinEditMapSizeX.Value := Game.Map.Size.X;
     379    SpinEditMapSizeY.Value := Game.Map.Size.Y;
     380    TrackBarSizeX.Position := Game.Map.Size.X;
     381    TrackBarSizeY.Position := Game.Map.Size.Y;
     382    RadioGroupGrowAmount.ItemIndex := Integer(Game.GrowAmount);
     383    RadioGroupGrowCells.ItemIndex := Integer(Game.GrowCells);
     384    ComboBoxGridType.ItemIndex := Integer(Game.MapType) - 1;
     385    ComboBoxWinObjective.ItemIndex := Integer(Game.WinObjective);
     386    SpinEditNeutralUnits.Value := Game.MaxNeutralUnits;
     387    ComboBoxMapShape.ItemIndex := Integer(Game.Map.Shape);
     388    EditImageFile.Text := Game.MapImageFileName;
     389    CheckBoxFogOfWar.Checked := Game.FogOfWar;
     390    CheckBoxBridges.Checked := Game.BridgeEnabled;
     391    RadioButtonModeLocal.Checked := Mode = smLocal;
     392    RadioButtonModeNetworkClient.Checked := Mode = smNetworkClient;
     393    RadioButtonModeNetworkServer.Checked := Mode = smNetworkServer;
     394    EditServerAddress.Text := LocalNetworkAddress;
     395    SpinEditServerPort.Value := LocalNetworkPort;
     396  end;
     397end;
     398
     399procedure TFormNew.Save(Server: TServer);
     400begin
     401  with Server do begin
     402    if RadioButtonModeLocal.Checked then Mode := smLocal
     403    else if RadioButtonModeNetworkClient.Checked then Mode := smNetworkClient
     404    else if RadioButtonModeNetworkServer.Checked then Mode := smNetworkServer;
     405    LocalNetworkAddress := EditServerAddress.Text;
     406    LocalNetworkPort := SpinEditServerPort.Value;
     407    Game.PlayersSetting.Assign(Players);
     408    Game.SymetricMap := CheckBoxSymetricMap.Checked;
     409    Game.VoidEnabled := CheckBoxVoid.Checked;
     410    Game.VoidPercentage := SpinEditVoidPercent.Value;
     411    Game.CityEnabled := CheckBoxCity.Checked;
     412    Game.CityPercentage := SpinEditCityPercent.Value;
     413    Game.Map.Size := TPoint.Create(SpinEditMapSizeX.Value, SpinEditMapSizeY.Value);
     414    Game.GrowAmount := TGrowAmount(RadioGroupGrowAmount.ItemIndex);
     415    Game.GrowCells := TGrowCells(RadioGroupGrowCells.ItemIndex);
     416    Game.MapType := TMapType(ComboBoxGridType.ItemIndex + 1);
     417    Game.WinObjective := TWinObjective(ComboBoxWinObjective.ItemIndex);
     418    Game.MaxNeutralUnits := SpinEditNeutralUnits.Value;
     419    Game.Map.Shape := TMapShape(ComboBoxMapShape.ItemIndex);
     420    Game.MapImageFileName := EditImageFile.Text;
     421    Game.FogOfWar := CheckBoxFogOfWar.Checked;
     422    Game.BridgeEnabled := CheckBoxBridges.Checked;
     423  end;
    375424end;
    376425
Note: See TracChangeset for help on using the changeset viewer.