Changeset 196 for trunk


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
Files:
2 added
10 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;
  • trunk/Languages/xtactics.cs.po

    r195 r196  
    305305#: tformnew.aplayeradd.caption
    306306#| msgid "Add player"
     307msgctxt "tformnew.aplayeradd.caption"
    307308msgid "Add"
    308309msgstr "Přidat"
     
    314315#: tformnew.aplayerremove.caption
    315316#| msgid "Remove player"
     317msgctxt "tformnew.aplayerremove.caption"
     318msgid "Remove"
     319msgstr "Odstranit"
     320
     321#: tformnew.aserveradd.caption
     322msgctxt "tformnew.aserveradd.caption"
     323msgid "Add"
     324msgstr "Přidat"
     325
     326#: tformnew.aservermodify.caption
     327msgctxt "tformnew.aservermodify.caption"
     328msgid "Modify"
     329msgstr "Upravit"
     330
     331#: tformnew.aserverremove.caption
     332msgctxt "tformnew.aserverremove.caption"
    316333msgid "Remove"
    317334msgstr "Odstranit"
     
    333350
    334351#: tformnew.buttonplayermodify.caption
     352msgctxt "tformnew.buttonplayermodify.caption"
    335353msgid "Modify"
    336354msgstr "Upravit"
     
    372390
    373391#: tformnew.label11.caption
     392msgctxt "tformnew.label11.caption"
    374393msgid "Port:"
    375394msgstr "Port:"
    376395
    377396#: tformnew.label12.caption
     397msgctxt "tformnew.label12.caption"
    378398msgid "Address:"
    379399msgstr "Adresa:"
     
    508528
    509529#: tformplayer.label1.caption
     530msgctxt "tformplayer.label1.caption"
    510531msgid "Name:"
    511532msgstr "Jméno:"
     
    563584msgid "Units"
    564585msgstr "Jednotky"
     586
     587#: tformserver.buttoncancel.caption
     588msgctxt "tformserver.buttoncancel.caption"
     589msgid "Cancel"
     590msgstr "Zrušit"
     591
     592#: tformserver.buttonok.caption
     593msgid "OK"
     594msgstr "OK"
     595
     596#: tformserver.caption
     597msgid "Server"
     598msgstr "Server"
     599
     600#: tformserver.label1.caption
     601msgctxt "tformserver.label1.caption"
     602msgid "Name:"
     603msgstr "Jméno:"
     604
     605#: tformserver.label2.caption
     606msgctxt "tformserver.label2.caption"
     607msgid "Address:"
     608msgstr "Adresa:"
     609
     610#: tformserver.label3.caption
     611msgctxt "tformserver.label3.caption"
     612msgid "Port:"
     613msgstr "Port:"
    565614
    566615#: tformsettings.buttoncancel.caption
     
    778827msgstr "Obdelníkový"
    779828
     829#: uformnew.sremoveserver
     830msgid "Remove server"
     831msgstr "Odstranit server"
     832
     833#: uformnew.sremoveserverquery
     834msgid "Do you want to remove server?"
     835msgstr "Chcete odstranit server?"
     836
    780837#: uformnew.srounded
    781838msgid "Rounded"
  • trunk/Languages/xtactics.po

    r195 r196  
    293293
    294294#: tformnew.aplayeradd.caption
     295msgctxt "tformnew.aplayeradd.caption"
    295296msgid "Add"
    296297msgstr ""
     
    301302
    302303#: tformnew.aplayerremove.caption
     304msgctxt "tformnew.aplayerremove.caption"
     305msgid "Remove"
     306msgstr ""
     307
     308#: tformnew.aserveradd.caption
     309msgctxt "tformnew.aserveradd.caption"
     310msgid "Add"
     311msgstr ""
     312
     313#: tformnew.aservermodify.caption
     314msgctxt "tformnew.aservermodify.caption"
     315msgid "Modify"
     316msgstr ""
     317
     318#: tformnew.aserverremove.caption
     319msgctxt "tformnew.aserverremove.caption"
    303320msgid "Remove"
    304321msgstr ""
     
    320337
    321338#: tformnew.buttonplayermodify.caption
     339msgctxt "tformnew.buttonplayermodify.caption"
    322340msgid "Modify"
    323341msgstr ""
     
    358376
    359377#: tformnew.label11.caption
     378msgctxt "tformnew.label11.caption"
    360379msgid "Port:"
    361380msgstr ""
    362381
    363382#: tformnew.label12.caption
     383msgctxt "tformnew.label12.caption"
    364384msgid "Address:"
    365385msgstr ""
     
    493513
    494514#: tformplayer.label1.caption
     515msgctxt "tformplayer.label1.caption"
    495516msgid "Name:"
    496517msgstr ""
     
    547568msgctxt "tformplayersstats.listview1.columns[5].caption"
    548569msgid "Units"
     570msgstr ""
     571
     572#: tformserver.buttoncancel.caption
     573msgctxt "tformserver.buttoncancel.caption"
     574msgid "Cancel"
     575msgstr ""
     576
     577#: tformserver.buttonok.caption
     578msgid "OK"
     579msgstr ""
     580
     581#: tformserver.caption
     582msgid "Server"
     583msgstr ""
     584
     585#: tformserver.label1.caption
     586msgctxt "tformserver.label1.caption"
     587msgid "Name:"
     588msgstr ""
     589
     590#: tformserver.label2.caption
     591msgctxt "tformserver.label2.caption"
     592msgid "Address:"
     593msgstr ""
     594
     595#: tformserver.label3.caption
     596msgctxt "tformserver.label3.caption"
     597msgid "Port:"
    549598msgstr ""
    550599
     
    757806msgstr ""
    758807
     808#: uformnew.sremoveserver
     809msgid "Remove server"
     810msgstr ""
     811
     812#: uformnew.sremoveserverquery
     813msgid "Do you want to remove server?"
     814msgstr ""
     815
    759816#: uformnew.srounded
    760817msgid "Rounded"
  • trunk/UCore.pas

    r195 r196  
    99  UGame, UApplicationInfo, UPersistentForm, UScaleDPI, UCoolTranslator,
    1010  URegistry, ULastOpenedList, Registry, Menus, UGeometry, UFormClient,
    11   UGameServer, UGameClient, fgl;
     11  UGameServer, UGameClient, fgl, UServerList;
    1212
    1313type
     
    9191    FormClients: TFPGObjectList<TFormClient>;
    9292    Clients: TClients;
     93    ServerList: TServerList;
    9394    procedure Spectate(Player: TPlayer);
    9495    procedure UpdateActions;
    9596    procedure Init;
     97    procedure Done;
    9698    property Initialized: Boolean read FInitialized;
    9799  end;
     
    295297  try
    296298    FormNew.Load(Server);
     299    FormNew.ServerList := ServerList;
    297300    if FormNew.ShowModal = mrOk then begin
    298301      FormNew.Save(Server);
     
    392395  ForceDirectories(GetAppConfigDir(False));
    393396  FormClients := TFPGObjectList<TFormClient>.Create;
     397  ServerList := TServerList.Create;
    394398end;
    395399
    396400procedure TCore.DataModuleDestroy(Sender: TObject);
    397401begin
     402  FreeAndNil(ServerList);
    398403  if Assigned(FormPlayersStats) then FreeAndNil(FormPlayersStats);
    399404  if Assigned(FormUnitMoves) then FreeAndNil(FormUnitMoves);
     
    401406  FreeAndNil(FormClients);
    402407  FreeAndNil(StoredDimension);
    403   Game.SaveConfig(XMLConfig1, 'Game');
    404   Server.SaveConfig(XMLConfig1, 'Server');
    405   SaveConfig;
    406408  FreeAndNil(Server);
    407409  FreeAndNil(Game);
     
    546548    Game.LoadConfig(XMLConfig1, 'Game');
    547549    Server.LoadConfig(XMLConfig1, 'Server');
     550    ServerList.LoadConfig(XmlConfig1, 'ServerList');
    548551
    549552    CommandLineParams;
     
    556559end;
    557560
     561procedure TCore.Done;
     562begin
     563  Game.SaveConfig(XMLConfig1, 'Game');
     564  Server.SaveConfig(XMLConfig1, 'Server');
     565  ServerList.SaveConfig(XmlConfig1, 'ServerList');
     566  SaveConfig;
     567  XMLConfig1.Flush;
     568end;
     569
    558570end.
    559571
  • trunk/UGameServer.pas

    r191 r196  
    6262  end;
    6363
     64const
     65  DefaultServerPort = 40009;
    6466
    6567implementation
     
    173175  with Config do begin
    174176    LocalNetworkAddress := string(GetValue(DOMString(Path + '/LocalNetworkAddress'), 'localhost'));
    175     LocalNetworkPort := GetValue(DOMString(Path + '/LocalNetworkPort'), 40009);
     177    LocalNetworkPort := GetValue(DOMString(Path + '/LocalNetworkPort'), DefaultServerPort);
    176178    RemoteNetworkAddress := string(GetValue(DOMString(Path + '/RemoteNetworkAddress'), 'localhost'));
    177     RemoteNetworkPort := GetValue(DOMString(Path + '/RemoteNetworkPort'), 40009);
     179    RemoteNetworkPort := GetValue(DOMString(Path + '/RemoteNetworkPort'), DefaultServerPort);
    178180    Mode := TServerMode(GetValue(DOMString(Path + '/Mode'), Integer(smLocal)));
    179181  end;
  • trunk/UServerList.pas

    r180 r196  
    66
    77uses
    8   Classes, SysUtils, contnrs;
     8  Classes, SysUtils, fgl, XMLConf;
    99
    1010type
     11
     12  { TServerInfo }
     13
    1114  TServerInfo = class
    1215    Name: string;
     
    1821    MapName: string;
    1922    Latency: TTime;
     23    constructor Create;
    2024  end;
    2125
    22   TServerInfos = class(TObjectList)
     26  TServerInfos = class(TFPGObjectList<TServerInfo>)
    2327  end;
    2428
     
    3135    constructor Create;
    3236    destructor Destroy; override;
     37    procedure LoadConfig(Config: TXmlConfig; Path: string);
     38    procedure SaveConfig(Config: TXmlConfig; Path: string);
    3339  end;
    3440
     41
    3542implementation
     43
     44uses
     45  UGameServer;
     46
     47{ TServerInfo }
     48
     49constructor TServerInfo.Create;
     50begin
     51  Port := DefaultServerPort;
     52end;
    3653
    3754{ TServerList }
     
    4865end;
    4966
     67procedure TServerList.LoadConfig(Config: TXmlConfig; Path: string);
     68var
     69  I: Integer;
     70  Server: TServerInfo;
     71begin
     72  Items.Clear;
     73  Items.Count := Config.GetValue(UnicodeString(Path + '/Count'), 0);
     74  for I := 0 to Items.Count - 1 do begin
     75    Server := TServerInfo.Create;
     76    Server.Name := string(Config.GetValue(UnicodeString(Path + '/Item' + IntToStr(I) + '/Name'), ''));
     77    Server.Address := string(Config.GetValue(UnicodeString(Path + '/Item' + IntToStr(I) + '/Address'), ''));
     78    Server.Port := Config.GetValue(UnicodeString(Path + '/Item' + IntToStr(I) + '/Port'), 0);
     79    Items[I] := Server;
     80  end;
     81end;
     82
     83procedure TServerList.SaveConfig(Config: TXmlConfig; Path: string);
     84var
     85  I: Integer;
     86  Server: TServerInfo;
     87begin
     88  Config.SetValue(UnicodeString(Path + '/Count'), Items.Count);
     89  for I := 0 to Items.Count - 1 do begin
     90    Server := Items[I];
     91    Config.SetValue(UnicodeString(Path + '/Item' + IntToStr(I) + '/Name'), UnicodeString(Server.Name));
     92    Config.SetValue(UnicodeString(Path + '/Item' + IntToStr(I) + '/Address'), UnicodeString(Server.Address));
     93    Config.SetValue(UnicodeString(Path + '/Item' + IntToStr(I) + '/Port'), Server.Port);
     94  end;
     95end;
     96
    5097end.
    5198
  • trunk/xtactics.lpi

    r192 r196  
    104104      </Item7>
    105105    </RequiredPackages>
    106     <Units Count="24">
     106    <Units Count="25">
    107107      <Unit0>
    108108        <Filename Value="xtactics.lpr"/>
     
    240240        <IsPartOfProject Value="True"/>
    241241      </Unit23>
     242      <Unit24>
     243        <Filename Value="Forms/UFormServer.pas"/>
     244        <IsPartOfProject Value="True"/>
     245        <ComponentName Value="FormServer"/>
     246        <ResourceBaseClass Value="Form"/>
     247      </Unit24>
    242248    </Units>
    243249  </ProjectOptions>
  • trunk/xtactics.lpr

    r192 r196  
    1111  CoolTranslator, TemplateGenerics
    1212  { you can add units after this },
    13   SysUtils, UFormMain, CoolStreaming;
     13  SysUtils, UFormMain, CoolStreaming, UFormServer;
    1414
    1515{$R *.res}
     
    3232  Application.CreateForm(TCore, Core);
    3333  Application.CreateForm(TFormMain, FormMain);
     34  Application.CreateForm(TFormServer, FormServer);
    3435  Application.Run;
    3536end.
Note: See TracChangeset for help on using the changeset viewer.