| 1 | unit FormPlayersStats;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
|
|---|
| 7 | Menus, ActnList, StdCtrls, Game, ListViewSort, FormEx, Player;
|
|---|
| 8 |
|
|---|
| 9 | type
|
|---|
| 10 |
|
|---|
| 11 | { TFormPlayersStats }
|
|---|
| 12 |
|
|---|
| 13 | TFormPlayersStats = class(TFormEx)
|
|---|
| 14 | ASpectate: TAction;
|
|---|
| 15 | ActionList1: TActionList;
|
|---|
| 16 | ButtonClose: TButton;
|
|---|
| 17 | ListView1: TListView;
|
|---|
| 18 | ListViewSort1: TListViewSort;
|
|---|
| 19 | MenuItem1: TMenuItem;
|
|---|
| 20 | PopupMenu1: TPopupMenu;
|
|---|
| 21 | procedure ASpectateExecute(Sender: TObject);
|
|---|
| 22 | procedure ButtonCloseClick(Sender: TObject);
|
|---|
| 23 | procedure FormShow(Sender: TObject);
|
|---|
| 24 | procedure ListView1Data(Sender: TObject; Item: TListItem);
|
|---|
| 25 | function ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
|
|---|
| 26 | procedure ListViewSort1Filter(ListViewSort: TListViewSort);
|
|---|
| 27 | private
|
|---|
| 28 | FOnSpectate: TPlayerEvent;
|
|---|
| 29 | public
|
|---|
| 30 | Game: TGame;
|
|---|
| 31 | procedure ReloadList;
|
|---|
| 32 | property OnSpectate: TPlayerEvent read FOnSpectate write FOnSpectate;
|
|---|
| 33 | end;
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 | implementation
|
|---|
| 37 |
|
|---|
| 38 | {$R *.lfm}
|
|---|
| 39 |
|
|---|
| 40 | { TFormPlayersStats }
|
|---|
| 41 |
|
|---|
| 42 | procedure TFormPlayersStats.ListView1Data(Sender: TObject; Item: TListItem);
|
|---|
| 43 | begin
|
|---|
| 44 | with Game do
|
|---|
| 45 | if Item.Index < ListViewSort1.List.Count then
|
|---|
| 46 | with TPlayer(ListViewSort1.List[Item.Index]) do begin
|
|---|
| 47 | Item.Caption := Name;
|
|---|
| 48 | Item.Data := ListViewSort1.List[Item.Index];
|
|---|
| 49 | Item.SubItems.Add(PlayerModeText[Mode]);
|
|---|
| 50 | Item.SubItems.Add(IntToStr(TotalCells));
|
|---|
| 51 | Item.SubItems.Add(IntToStr(TotalDiscovered));
|
|---|
| 52 | Item.SubItems.Add(IntToStr(TotalCities));
|
|---|
| 53 | Item.SubItems.Add(IntToStr(TotalUnits));
|
|---|
| 54 | Item.SubItems.Add(IntToStr(TotalWinObjectiveCells));
|
|---|
| 55 | end;
|
|---|
| 56 | end;
|
|---|
| 57 |
|
|---|
| 58 | function TFormPlayersStats.ListViewSort1CompareItem(Item1, Item2: TObject
|
|---|
| 59 | ): Integer;
|
|---|
| 60 | begin
|
|---|
| 61 | Result := 0;
|
|---|
| 62 | if Assigned(Item1) and Assigned(Item2) and (ListViewSort1.Order <> soNone) then begin
|
|---|
| 63 | with ListViewSort1 do
|
|---|
| 64 | case Column of
|
|---|
| 65 | 0: Result := CompareString(TPlayer(Item1).Name, TPlayer(Item2).Name);
|
|---|
| 66 | 1: Result := CompareString(PlayerModeText[TPlayer(Item1).Mode], PlayerModeText[TPlayer(Item2).Mode]);
|
|---|
| 67 | 2: Result := CompareInteger(TPlayer(Item1).TotalCells, TPlayer(Item2).TotalCells);
|
|---|
| 68 | 3: Result := CompareInteger(TPlayer(Item1).TotalDiscovered, TPlayer(Item2).TotalDiscovered);
|
|---|
| 69 | 4: Result := CompareInteger(TPlayer(Item1).TotalCities, TPlayer(Item2).TotalCities);
|
|---|
| 70 | 5: Result := CompareInteger(TPlayer(Item1).TotalUnits, TPlayer(Item2).TotalUnits);
|
|---|
| 71 | 6: Result := CompareInteger(TPlayer(Item1).TotalWinObjectiveCells, TPlayer(Item2).TotalWinObjectiveCells);
|
|---|
| 72 | end;
|
|---|
| 73 | if ListViewSort1.Order = soDown then Result := -Result;
|
|---|
| 74 | end else Result := 0;
|
|---|
| 75 | end;
|
|---|
| 76 |
|
|---|
| 77 | procedure TFormPlayersStats.ListViewSort1Filter(ListViewSort: TListViewSort);
|
|---|
| 78 | var
|
|---|
| 79 | I: Integer;
|
|---|
| 80 | begin
|
|---|
| 81 | ListViewSort1.List.Clear;
|
|---|
| 82 | for I := 0 to Game.Players.Count - 1 do begin
|
|---|
| 83 | ListViewSort1.List.Add(Game.Players[I]);
|
|---|
| 84 | end;
|
|---|
| 85 | end;
|
|---|
| 86 |
|
|---|
| 87 | procedure TFormPlayersStats.FormShow(Sender: TObject);
|
|---|
| 88 | begin
|
|---|
| 89 | ReloadList;
|
|---|
| 90 | end;
|
|---|
| 91 |
|
|---|
| 92 | procedure TFormPlayersStats.ASpectateExecute(Sender: TObject);
|
|---|
| 93 | begin
|
|---|
| 94 | if Assigned(ListView1.Selected) then
|
|---|
| 95 | if Assigned(FOnSpectate) then
|
|---|
| 96 | FOnSpectate(TPlayer(ListView1.Selected.Data));
|
|---|
| 97 | end;
|
|---|
| 98 |
|
|---|
| 99 | procedure TFormPlayersStats.ButtonCloseClick(Sender: TObject);
|
|---|
| 100 | begin
|
|---|
| 101 | Close;
|
|---|
| 102 | end;
|
|---|
| 103 |
|
|---|
| 104 | procedure TFormPlayersStats.ReloadList;
|
|---|
| 105 | begin
|
|---|
| 106 | ListViewSort1.Refresh;
|
|---|
| 107 | end;
|
|---|
| 108 |
|
|---|
| 109 | end.
|
|---|
| 110 |
|
|---|