Changeset 196 for trunk/Forms/UFormNew.pas
- Timestamp:
- May 16, 2018, 9:56:24 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormNew.pas
r194 r196 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 9 ComCtrls, Spin, ExtCtrls, ActnList, ExtDlgs, Menus, UGame, UGeometry, 10 UGameServer ;10 UGameServer, UServerList; 11 11 12 12 type … … 15 15 16 16 TFormNew = class(TForm) 17 AServerModify: TAction; 18 AServerAdd: TAction; 19 AServerRemove: TAction; 17 20 APlayerAdd: TAction; 18 21 APlayerRemove: TAction; 19 22 APlayerModify: TAction; 20 23 ActionList1: TActionList; 24 Button1: TButton; 25 Button2: TButton; 26 Button3: TButton; 21 27 ButtonCancel: TButton; 22 28 ButtonImageBrowse: TButton; … … 52 58 MenuItem2: TMenuItem; 53 59 MenuItem3: TMenuItem; 60 MenuItem4: TMenuItem; 61 MenuItem5: TMenuItem; 62 MenuItem6: TMenuItem; 54 63 OpenPictureDialog1: TOpenPictureDialog; 55 64 PageControl1: TPageControl; 56 65 PanelButtons: TPanel; 57 66 PanelChat: TPanel; 58 PopupMenu1: TPopupMenu; 67 PopupMenuPlayers: TPopupMenu; 68 PopupMenuServers: TPopupMenu; 59 69 RadioButtonModeNetworkServer: TRadioButton; 60 70 RadioButtonModeNetworkClient: TRadioButton; … … 79 89 procedure APlayerModifyExecute(Sender: TObject); 80 90 procedure APlayerRemoveExecute(Sender: TObject); 91 procedure AServerAddExecute(Sender: TObject); 92 procedure AServerModifyExecute(Sender: TObject); 93 procedure AServerRemoveExecute(Sender: TObject); 81 94 procedure ButtonImageBrowseClick(Sender: TObject); 82 95 procedure CheckBoxCityChange(Sender: TObject); … … 97 110 procedure ListViewPlayersSelectItem(Sender: TObject; Item: TListItem; 98 111 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); 99 116 procedure RadioButtonModeLocalChange(Sender: TObject); 100 117 procedure SpinEditMapSizeXChange(Sender: TObject); … … 106 123 Players: TPlayers; 107 124 public 125 ServerList: TServerList; 108 126 procedure Translate; 109 127 procedure ReloadView; … … 121 139 122 140 uses 123 UFormPlayer, UFormChat, UCore ;141 UFormPlayer, UFormChat, UCore, UFormServer; 124 142 125 143 resourcestring … … 141 159 SRounded = 'Rounded'; 142 160 SFromImageFile = 'From image file'; 161 SRemoveServer = 'Remove server'; 162 SRemoveServerQuery = 'Do you want to remove server?'; 143 163 144 164 { TFormNew } … … 177 197 begin 178 198 ReloadView; 199 end; 200 201 procedure TFormNew.ListViewServersData(Sender: TObject; Item: TListItem); 202 begin 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; 209 end; 210 211 procedure TFormNew.ListViewServersKeyPress(Sender: TObject; var Key: char); 212 begin 213 if Key = #13 then AServerModify.Execute; 214 end; 215 216 procedure TFormNew.ListViewServersSelectItem(Sender: TObject; Item: TListItem; 217 Selected: Boolean); 218 begin 219 UpdateInterface; 179 220 end; 180 221 … … 262 303 ListViewPlayers.Items.Count := Players.Count; 263 304 ListViewPlayers.Refresh; 305 ListViewServers.Items.Count := ServerList.Items.Count; 306 ListViewServers.Refresh; 264 307 Translate; 265 308 UpdateInterface; … … 278 321 PanelChat.Visible := RadioButtonModeNetworkClient.Checked or RadioButtonModeNetworkServer.Checked; 279 322 SpinEditNeutralUnits.MaxValue := SpinEditMaxPower.Value; 323 AServerRemove.Enabled := RadioButtonModeNetworkClient.Checked and Assigned(ListViewServers.Selected); 324 AServerAdd.Enabled := RadioButtonModeNetworkClient.Checked; 325 AServerModify.Enabled := RadioButtonModeNetworkClient.Checked; 280 326 end; 281 327 … … 350 396 if Assigned(ListViewPlayers.Selected) then begin 351 397 Players.Remove(ListViewPlayers.Selected.Data); 398 ReloadView; 399 end; 400 end; 401 402 procedure TFormNew.AServerAddExecute(Sender: TObject); 403 var 404 NewServer: TServerInfo; 405 begin 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; 415 end; 416 417 procedure TFormNew.AServerModifyExecute(Sender: TObject); 418 var 419 Server: TServerInfo; 420 begin 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; 429 end; 430 431 procedure TFormNew.AServerRemoveExecute(Sender: TObject); 432 var 433 I: Integer; 434 begin 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); 352 440 ReloadView; 353 441 end; … … 424 512 LocalNetworkAddress := EditServerAddress.Text; 425 513 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; 426 521 Game.PlayersSetting.Assign(Players); 427 522 Game.SymetricMap := CheckBoxSymetricMap.Checked;
Note:
See TracChangeset
for help on using the changeset viewer.