Ignore:
Timestamp:
May 16, 2018, 9:56:24 AM (6 years ago)
Author:
chronos
Message:
  • Added: Allow to manage list of servers where to connect as client.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormNew.pas

    r194 r196  
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    99  ComCtrls, Spin, ExtCtrls, ActnList, ExtDlgs, Menus, UGame, UGeometry,
    10   UGameServer;
     10  UGameServer, UServerList;
    1111
    1212type
     
    1515
    1616  TFormNew = class(TForm)
     17    AServerModify: TAction;
     18    AServerAdd: TAction;
     19    AServerRemove: TAction;
    1720    APlayerAdd: TAction;
    1821    APlayerRemove: TAction;
    1922    APlayerModify: TAction;
    2023    ActionList1: TActionList;
     24    Button1: TButton;
     25    Button2: TButton;
     26    Button3: TButton;
    2127    ButtonCancel: TButton;
    2228    ButtonImageBrowse: TButton;
     
    5258    MenuItem2: TMenuItem;
    5359    MenuItem3: TMenuItem;
     60    MenuItem4: TMenuItem;
     61    MenuItem5: TMenuItem;
     62    MenuItem6: TMenuItem;
    5463    OpenPictureDialog1: TOpenPictureDialog;
    5564    PageControl1: TPageControl;
    5665    PanelButtons: TPanel;
    5766    PanelChat: TPanel;
    58     PopupMenu1: TPopupMenu;
     67    PopupMenuPlayers: TPopupMenu;
     68    PopupMenuServers: TPopupMenu;
    5969    RadioButtonModeNetworkServer: TRadioButton;
    6070    RadioButtonModeNetworkClient: TRadioButton;
     
    7989    procedure APlayerModifyExecute(Sender: TObject);
    8090    procedure APlayerRemoveExecute(Sender: TObject);
     91    procedure AServerAddExecute(Sender: TObject);
     92    procedure AServerModifyExecute(Sender: TObject);
     93    procedure AServerRemoveExecute(Sender: TObject);
    8194    procedure ButtonImageBrowseClick(Sender: TObject);
    8295    procedure CheckBoxCityChange(Sender: TObject);
     
    97110    procedure ListViewPlayersSelectItem(Sender: TObject; Item: TListItem;
    98111      Selected: Boolean);
     112    procedure ListViewServersData(Sender: TObject; Item: TListItem);
     113    procedure ListViewServersKeyPress(Sender: TObject; var Key: char);
     114    procedure ListViewServersSelectItem(Sender: TObject; Item: TListItem;
     115      Selected: Boolean);
    99116    procedure RadioButtonModeLocalChange(Sender: TObject);
    100117    procedure SpinEditMapSizeXChange(Sender: TObject);
     
    106123    Players: TPlayers;
    107124  public
     125    ServerList: TServerList;
    108126    procedure Translate;
    109127    procedure ReloadView;
     
    121139
    122140uses
    123   UFormPlayer, UFormChat, UCore;
     141  UFormPlayer, UFormChat, UCore, UFormServer;
    124142
    125143resourcestring
     
    141159  SRounded = 'Rounded';
    142160  SFromImageFile = 'From image file';
     161  SRemoveServer = 'Remove server';
     162  SRemoveServerQuery = 'Do you want to remove server?';
    143163
    144164{ TFormNew }
     
    177197begin
    178198  ReloadView;
     199end;
     200
     201procedure TFormNew.ListViewServersData(Sender: TObject; Item: TListItem);
     202begin
     203  if Item.Index < ServerList.Items.Count then
     204  with TServerInfo(ServerList.Items[Item.Index]) do begin
     205    Item.Caption := Name;
     206    Item.Data := ServerList.Items[Item.Index];
     207    Item.SubItems.Add(Address + ':' + IntToStr(Port));
     208  end;
     209end;
     210
     211procedure TFormNew.ListViewServersKeyPress(Sender: TObject; var Key: char);
     212begin
     213  if Key = #13 then AServerModify.Execute;
     214end;
     215
     216procedure TFormNew.ListViewServersSelectItem(Sender: TObject; Item: TListItem;
     217  Selected: Boolean);
     218begin
     219  UpdateInterface;
    179220end;
    180221
     
    262303  ListViewPlayers.Items.Count := Players.Count;
    263304  ListViewPlayers.Refresh;
     305  ListViewServers.Items.Count := ServerList.Items.Count;
     306  ListViewServers.Refresh;
    264307  Translate;
    265308  UpdateInterface;
     
    278321  PanelChat.Visible := RadioButtonModeNetworkClient.Checked or RadioButtonModeNetworkServer.Checked;
    279322  SpinEditNeutralUnits.MaxValue := SpinEditMaxPower.Value;
     323  AServerRemove.Enabled := RadioButtonModeNetworkClient.Checked and Assigned(ListViewServers.Selected);
     324  AServerAdd.Enabled := RadioButtonModeNetworkClient.Checked;
     325  AServerModify.Enabled := RadioButtonModeNetworkClient.Checked;
    280326end;
    281327
     
    350396  if Assigned(ListViewPlayers.Selected) then begin
    351397    Players.Remove(ListViewPlayers.Selected.Data);
     398    ReloadView;
     399  end;
     400end;
     401
     402procedure TFormNew.AServerAddExecute(Sender: TObject);
     403var
     404  NewServer: TServerInfo;
     405begin
     406  FormServer := TFormServer.Create(nil);
     407  NewServer := TServerInfo.Create;
     408  FormServer.Load(NewServer);
     409  if FormServer.ShowModal = mrOK then begin
     410    FormServer.Save(NewServer);
     411    ServerList.Items.Add(NewServer);
     412    ReloadView;
     413  end else NewServer.Free;
     414  FormServer.Free;
     415end;
     416
     417procedure TFormNew.AServerModifyExecute(Sender: TObject);
     418var
     419  Server: TServerInfo;
     420begin
     421  FormServer := TFormServer.Create(nil);
     422  Server := TServerInfo(ListViewServers.Selected.Data);
     423  FormServer.Load(Server);
     424  if FormServer.ShowModal = mrOK then begin
     425    FormServer.Save(Server);
     426    ReloadView;
     427  end;
     428  FormServer.Free;
     429end;
     430
     431procedure TFormNew.AServerRemoveExecute(Sender: TObject);
     432var
     433  I: Integer;
     434begin
     435  if MessageDlg(SRemoveServer, SRemoveServerQuery,
     436  TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
     437    for I := ListViewServers.Items.Count - 1 downto 0 do
     438    if ListViewServers.Items[I].Selected then
     439      ServerList.Items.Delete(I);
    352440    ReloadView;
    353441  end;
     
    424512    LocalNetworkAddress := EditServerAddress.Text;
    425513    LocalNetworkPort := SpinEditServerPort.Value;
     514    if Assigned(ListViewServers.Selected) then begin
     515      RemoteNetworkAddress := TServerInfo(ListViewServers.Selected.Data).Address;
     516      RemoteNetworkPort := TServerInfo(ListViewServers.Selected.Data).Port;
     517    end else begin
     518      RemoteNetworkAddress := '';
     519      RemoteNetworkPort := 0;
     520    end;
    426521    Game.PlayersSetting.Assign(Players);
    427522    Game.SymetricMap := CheckBoxSymetricMap.Checked;
Note: See TracChangeset for help on using the changeset viewer.