Ignore:
Timestamp:
Feb 14, 2019, 10:52:04 PM (6 years ago)
Author:
chronos
Message:
  • Modified: User interface for the list of players moved to the separate form.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormNew.pas

    r276 r279  
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    99  ComCtrls, Spin, ExtCtrls, ActnList, ExtDlgs, Menus, UGame, UGeometry, UPlayer,
    10   UGameServer, UServerList, UMap;
     10  UGameServer, UServerList, UMap, UFormPlayers;
    1111
    1212type
     
    1616  TFormNew = class(TForm)
    1717    ActionList1: TActionList;
    18     APlayerAdd: TAction;
    19     APlayerModify: TAction;
    20     APlayerRemove: TAction;
    2118    AServerAdd: TAction;
    2219    AServerModify: TAction;
     
    3027    ButtonImageBrowse: TButton;
    3128    ButtonOk: TButton;
    32     ButtonPlayerAdd: TButton;
    33     ButtonPlayerModify: TButton;
    34     ButtonPlayerRemove: TButton;
    3529    CheckBoxBridges: TCheckBox;
    3630    CheckBoxCity: TCheckBox;
     
    6256    Label8: TLabel;
    6357    Label9: TLabel;
    64     ListViewPlayers: TListView;
    6558    ListViewServers: TListView;
    66     MenuItem1: TMenuItem;
    67     MenuItem2: TMenuItem;
    68     MenuItem3: TMenuItem;
    6959    MenuItem4: TMenuItem;
    7060    MenuItem5: TMenuItem;
     
    8070    PanelButtons: TPanel;
    8171    PanelChat: TPanel;
    82     PopupMenuPlayers: TPopupMenu;
    8372    PopupMenuServers: TPopupMenu;
    8473    RadioButtonModeLocal: TRadioButton;
     
    111100    TrackBarSizeX: TTrackBar;
    112101    TrackBarSizeY: TTrackBar;
    113     procedure APlayerAddExecute(Sender: TObject);
    114     procedure APlayerModifyExecute(Sender: TObject);
    115     procedure APlayerRemoveExecute(Sender: TObject);
    116102    procedure AServerAddExecute(Sender: TObject);
    117103    procedure AServerModifyExecute(Sender: TObject);
     
    134120    procedure FormShow(Sender: TObject);
    135121    procedure Image1Resize(Sender: TObject);
    136     procedure ListViewPlayersCustomDrawSubItem(Sender: TCustomListView;
    137       Item: TListItem; SubItem: Integer; State: TCustomDrawState;
    138       var DefaultDraw: Boolean);
    139     procedure ListViewPlayersData(Sender: TObject; Item: TListItem);
    140     procedure ListViewPlayersDblClick(Sender: TObject);
    141     procedure ListViewPlayersKeyPress(Sender: TObject; var Key: char);
    142     procedure ListViewPlayersKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState
    143       );
    144     procedure ListViewPlayersSelectItem(Sender: TObject; Item: TListItem;
    145       Selected: Boolean);
    146122    procedure ListViewServersData(Sender: TObject; Item: TListItem);
    147123    procedure ListViewServersKeyPress(Sender: TObject; var Key: char);
     
    166142    MapPreviewRedrawPending: Boolean;
    167143    NewRandSeed: Cardinal;
     144    FormPlayers: TFormPlayers;
    168145    procedure LoadGame(Game: TGame);
    169146    procedure SaveGame(Game: TGame);
     
    216193{ TFormNew }
    217194
    218 procedure TFormNew.ListViewPlayersData(Sender: TObject; Item: TListItem);
    219 begin
    220   if (Item.Index >= 0) and (Item.Index < Players.Count) then
    221   with Players[Item.Index] do begin
    222     Item.Caption := Name;
    223     Item.Data := Players[Item.Index];
    224     Item.SubItems.Add(PlayerModeText[Mode]);
    225     Item.SubItems.Add(''); // Do not show color text
    226     Item.SubItems.Add(IntToStr(StartUnits));
    227   end;
    228 end;
    229 
    230 procedure TFormNew.ListViewPlayersDblClick(Sender: TObject);
    231 begin
    232   APlayerModify.Execute;
    233 end;
    234 
    235 procedure TFormNew.ListViewPlayersKeyPress(Sender: TObject; var Key: char);
    236 begin
    237   if (Key = #13) then APlayerModify.Execute;
    238 end;
    239 
    240 procedure TFormNew.ListViewPlayersKeyUp(Sender: TObject; var Key: Word;
    241   Shift: TShiftState);
    242 begin
    243   if Key = 45 then APlayerAdd.Execute;
    244   if Key = 46 then APlayerRemove.Execute;
    245 end;
    246 
    247 procedure TFormNew.ListViewPlayersSelectItem(Sender: TObject; Item: TListItem;
    248   Selected: Boolean);
    249 begin
    250   ReloadView;
    251 end;
    252 
    253195procedure TFormNew.ListViewServersData(Sender: TObject; Item: TListItem);
    254196begin
     
    339281procedure TFormNew.LoadGame(Game: TGame);
    340282begin
    341   Players.Assign(Game.Players);
     283  FormPlayers.Players.Assign(Game.Players);
    342284  with Game do begin
    343285    CheckBoxSymetricMap.Checked := SymetricMap;
     
    370312procedure TFormNew.SaveGame(Game: TGame);
    371313begin
    372   Game.Players.Assign(Players);
     314  Game.Players.Assign(FormPlayers.Players);
    373315  with Game do begin
    374316    StoredRandSeed := NewRandSeed;
     
    510452procedure TFormNew.ReloadView;
    511453begin
    512   ListViewPlayers.Items.Count := Players.Count;
    513   ListViewPlayers.Refresh;
    514454  ListViewServers.Items.Count := ServerList.Items.Count;
    515455  ListViewServers.Refresh;
     
    522462  WinObjective: TWinObjective;
    523463begin
    524   APlayerRemove.Enabled := Assigned(ListViewPlayers.Selected) and (Players.Count > MinPlayerCount);
    525   APlayerAdd.Enabled := Players.Count < MaxPlayerCount;
    526   APlayerModify.Enabled := Assigned(ListViewPlayers.Selected);
    527464  EditImageFile.Enabled := ComboBoxMapShape.ItemIndex = Integer(msImage);
    528465  ButtonImageBrowse.Enabled := ComboBoxMapShape.ItemIndex = Integer(msImage);
     
    566503end;
    567504
    568 procedure TFormNew.ListViewPlayersCustomDrawSubItem(Sender: TCustomListView;
    569   Item: TListItem; SubItem: Integer; State: TCustomDrawState;
    570   var DefaultDraw: Boolean);
    571 begin
    572   if SubItem = 2 then
    573   with ListViewPlayers.Canvas do begin
    574     Brush.Color := TPlayer(Item.Data).Color;
    575     Brush.Style := bsSolid;
    576     FillRect(Item.DisplayRectSubItem(2, drBounds));
    577   end;
    578 end;
    579 
    580505procedure TFormNew.FormCreate(Sender: TObject);
    581506begin
    582507  GamePreview := TGame.Create;
    583   Players := TPlayers.Create;
    584508  ServerList := TServerList.Create;
    585509  FormChat := TFormChat.Create(nil);
     
    587511  FormChat.Align := alClient;
    588512  FormChat.Show;
     513  Players := TPlayers.Create;
     514  FormPlayers := TFormPlayers.Create(nil);
     515  FormPlayers.MinItemCount := MinPlayerCount;
     516  FormPlayers.MaxItemCount := MaxPlayerCount;
     517  FormPlayers.Players := Players;
     518  FormPlayers.ManualDock(Panel2, nil, alClient);
     519  FormPlayers.Align := alClient;
     520  FormPlayers.Visible := True;
    589521  Translate;
    590522end;
     
    636568begin
    637569  Core.PersistentForm.Save(Self);
    638 end;
    639 
    640 procedure TFormNew.APlayerModifyExecute(Sender: TObject);
    641 begin
    642   FormPlayer := TFormPlayer.Create(nil);
    643   try
    644     if Assigned(ListViewPlayers.Selected) then begin
    645       FormPlayer.Load(TPlayer(ListViewPlayers.Selected.Data));
    646        if FormPlayer.ShowModal = mrOk then begin
    647          FormPlayer.Save(TPlayer(ListViewPlayers.Selected.Data));
    648          ReloadView;
    649       end;
    650     end;
    651   finally
    652     FormPlayer.Free;
    653   end;
    654 end;
    655 
    656 procedure TFormNew.APlayerRemoveExecute(Sender: TObject);
    657 var
    658   I: Integer;
    659 begin
    660   for I := ListViewPlayers.Items.Count - 1 downto 0 do
    661   if ListViewPlayers.Items[I].Selected then begin
    662     Players.Remove(ListViewPlayers.Items[I].Data);
    663     if Players.Count <= MinPlayerCount then Break;
    664   end;
    665   ReloadView;
    666570end;
    667571
     
    740644end;
    741645
    742 procedure TFormNew.APlayerAddExecute(Sender: TObject);
    743 var
    744   NewPlayer: TPlayer;
    745 begin
    746   if Players.Count <= (MaxPlayerCount - 1) then begin
    747     NewPlayer := TPlayer.Create;
    748     NewPlayer.Id := Players.GetNewId;
    749     NewPlayer.Name := SPlayer + ' ' + IntToStr(NewPlayer.Id);
    750     NewPlayer.Color := PlayerColors[Players.Count];
    751     NewPlayer.Mode := pmComputer;
    752     NewPlayer.Agressivity := caMedium;
    753     Players.Add(NewPlayer);
    754     ReloadView;
    755   end;
    756 end;
    757 
    758646procedure TFormNew.FormDestroy(Sender: TObject);
    759647begin
    760648  FreeAndNil(ServerList);
     649  FreeAndNil(FormChat);
    761650  FreeAndNil(Players);
    762   FreeAndNil(FormChat);
     651  FreeAndNil(FormPlayers);
    763652  FreeAndNil(GamePreview);
    764653end;
Note: See TracChangeset for help on using the changeset viewer.