Changeset 196 for trunk/Forms


Ignore:
Timestamp:
May 16, 2018, 9:56:24 AM (7 years ago)
Author:
chronos
Message:
  • Added: Allow to manage list of servers where to connect as client.
Location:
trunk/Forms
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.pas

    r192 r196  
    168168  Core.PersistentForm.Save(Self);
    169169  SaveConfig(Core.XMLConfig1, 'FormMain');
    170   Core.XMLConfig1.Flush;
     170  Core.Done;
    171171end;
    172172
  • trunk/Forms/UFormNew.lfm

    r194 r196  
    2121    Top = 4
    2222    Width = 1061
    23     ActivePage = TabSheet2
     23    ActivePage = TabSheetMode
    2424    Align = alClient
    2525    BorderSpacing.Around = 4
    26     TabIndex = 2
     26    TabIndex = 0
    2727    TabOrder = 0
    2828    object TabSheetMode: TTabSheet
    2929      Caption = 'Mode'
    30       ClientHeight = 297
    31       ClientWidth = 759
     30      ClientHeight = 523
     31      ClientWidth = 1053
    3232      object RadioButtonModeLocal: TRadioButton
    3333        Left = 10
     
    9090      object ListViewServers: TListView
    9191        Left = 26
    92         Height = 97
     92        Height = 291
    9393        Top = 181
    94         Width = 326
     94        Width = 334
    9595        Anchors = [akTop, akLeft, akBottom]
    9696        Columns = <       
     
    103103            Width = 200
    104104          end>
     105        MultiSelect = True
     106        OwnerData = True
     107        PopupMenu = PopupMenuServers
     108        ReadOnly = True
     109        RowSelect = True
    105110        TabOrder = 5
    106111        ViewStyle = vsReport
     112        OnData = ListViewServersData
     113        OnDblClick = AServerModifyExecute
     114        OnKeyPress = ListViewServersKeyPress
     115        OnSelectItem = ListViewServersSelectItem
     116      end
     117      object Button1: TButton
     118        Left = 27
     119        Height = 31
     120        Top = 484
     121        Width = 94
     122        Action = AServerAdd
     123        Anchors = [akLeft, akBottom]
     124        TabOrder = 6
     125      end
     126      object Button2: TButton
     127        Left = 240
     128        Height = 31
     129        Top = 484
     130        Width = 94
     131        Action = AServerRemove
     132        Anchors = [akLeft, akBottom]
     133        TabOrder = 7
     134      end
     135      object Button3: TButton
     136        Left = 136
     137        Height = 30
     138        Top = 484
     139        Width = 94
     140        Action = AServerModify
     141        Anchors = [akLeft, akBottom]
     142        TabOrder = 8
    107143      end
    108144    end
     
    137173          end>
    138174        OwnerData = True
    139         PopupMenu = PopupMenu1
     175        PopupMenu = PopupMenuPlayers
    140176        ReadOnly = True
    141177        RowSelect = True
     
    557593  object ActionList1: TActionList
    558594    Images = Core.ImageListSmall
    559     left = 256
    560     top = 440
     595    left = 568
     596    top = 296
    561597    object APlayerModify: TAction
    562598      Caption = 'Modify player'
     
    571607      OnExecute = APlayerRemoveExecute
    572608    end
     609    object AServerAdd: TAction
     610      Caption = 'Add'
     611      OnExecute = AServerAddExecute
     612    end
     613    object AServerRemove: TAction
     614      Caption = 'Remove'
     615      OnExecute = AServerRemoveExecute
     616    end
     617    object AServerModify: TAction
     618      Caption = 'Modify'
     619      OnExecute = AServerModifyExecute
     620    end
    573621  end
    574622  object OpenPictureDialog1: TOpenPictureDialog
    575     left = 424
    576     top = 440
    577   end
    578   object PopupMenu1: TPopupMenu
    579     left = 128
    580     top = 440
     623    left = 568
     624    top = 360
     625  end
     626  object PopupMenuPlayers: TPopupMenu
     627    left = 568
     628    top = 232
    581629    object MenuItem1: TMenuItem
    582630      Action = APlayerAdd
     
    590638    end
    591639  end
     640  object PopupMenuServers: TPopupMenu
     641    left = 121
     642    top = 317
     643    object MenuItem4: TMenuItem
     644      Action = AServerAdd
     645    end
     646    object MenuItem6: TMenuItem
     647      Action = AServerModify
     648    end
     649    object MenuItem5: TMenuItem
     650      Action = AServerRemove
     651    end
     652  end
    592653end
  • 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.