source: trunk/Forms/FormPlayersStats.pas

Last change on this file was 318, checked in by chronos, 6 months ago
  • Modified: Code cleanup.
File size: 3.0 KB
Line 
1unit FormPlayersStats;
2
3interface
4
5uses
6 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
7 Menus, ActnList, Game, ListViewSort, FormEx, Player;
8
9type
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
34implementation
35
36{$R *.lfm}
37
38{ TFormPlayersStats }
39
40procedure TFormPlayersStats.ListView1Data(Sender: TObject; Item: TListItem);
41begin
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;
54end;
55
56function TFormPlayersStats.ListViewSort1CompareItem(Item1, Item2: TObject
57 ): Integer;
58begin
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;
73end;
74
75procedure TFormPlayersStats.ListViewSort1Filter(ListViewSort: TListViewSort);
76var
77 I: Integer;
78begin
79 ListViewSort1.List.Clear;
80 for I := 0 to Game.Players.Count - 1 do begin
81 ListViewSort1.List.Add(Game.Players[I]);
82 end;
83end;
84
85procedure TFormPlayersStats.FormShow(Sender: TObject);
86begin
87 ReloadList;
88end;
89
90procedure TFormPlayersStats.ASpectateExecute(Sender: TObject);
91begin
92 if Assigned(ListView1.Selected) then
93 if Assigned(FOnSpectate) then
94 FOnSpectate(TPlayer(ListView1.Selected.Data));
95end;
96
97procedure TFormPlayersStats.ReloadList;
98begin
99 ListViewSort1.Refresh;
100end;
101
102end.
103
Note: See TracBrowser for help on using the repository browser.