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