1 | unit FormScore;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls,
|
---|
7 | FormEx, ListViewSort, Score, DateUtils, Generics.Collections;
|
---|
8 |
|
---|
9 | type
|
---|
10 |
|
---|
11 | { TFormScore }
|
---|
12 |
|
---|
13 | TFormScore = class(TFormEx)
|
---|
14 | ButtonClose: TButton;
|
---|
15 | ButtonClear: TButton;
|
---|
16 | ListView1: TListView;
|
---|
17 | ListViewSort1: TListViewSort;
|
---|
18 | procedure ButtonClearClick(Sender: TObject);
|
---|
19 | procedure FormShow(Sender: TObject);
|
---|
20 | procedure ListView1Data(Sender: TObject; Item: TListItem);
|
---|
21 | function ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
|
---|
22 | procedure ListViewSort1Filter(ListViewSort: TListViewSort);
|
---|
23 | private
|
---|
24 | FScores: TScores;
|
---|
25 | procedure SetScores(AValue: TScores);
|
---|
26 | procedure FilterList(List: TObjectList<TObject>);
|
---|
27 | public
|
---|
28 | procedure ReloadList;
|
---|
29 | property Scores: TScores read FScores write SetScores;
|
---|
30 | end;
|
---|
31 |
|
---|
32 |
|
---|
33 | implementation
|
---|
34 |
|
---|
35 | {$R *.lfm}
|
---|
36 |
|
---|
37 | resourcestring
|
---|
38 | SClearCaption = 'Clear score';
|
---|
39 | SClearQuery = 'Do you really want to clear score history?';
|
---|
40 |
|
---|
41 | { TFormScore }
|
---|
42 |
|
---|
43 | procedure TFormScore.ListView1Data(Sender: TObject; Item: TListItem);
|
---|
44 | begin
|
---|
45 | if Item.Index < ListViewSort1.List.Count then
|
---|
46 | with TScore(ListViewSort1.List[Item.Index]) do begin
|
---|
47 | Item.Caption := DateTimeToStr(StartTime);
|
---|
48 | Item.Data := ListViewSort1.List[Item.Index];
|
---|
49 | Item.SubItems.Add(BoardSize);
|
---|
50 | Item.SubItems.Add(IntToStr(Score));
|
---|
51 | Item.SubItems.Add(IntToStr(1 shl BiggestTile));
|
---|
52 | Item.SubItems.Add(IntToStr(Moves));
|
---|
53 | Item.SubItems.Add(IntToStr(UsedUndos));
|
---|
54 | Item.SubItems.Add(IntToStr(DisabledTiles));
|
---|
55 | Item.SubItems.Add(IntToStr(UnmergeableTiles));
|
---|
56 | Item.SubItems.Add(TimeToStr(Duration));
|
---|
57 | end;
|
---|
58 | end;
|
---|
59 |
|
---|
60 | function TFormScore.ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
|
---|
61 | var
|
---|
62 | Score1, Score2: TScore;
|
---|
63 | begin
|
---|
64 | Result := 0;
|
---|
65 | if Assigned(Item1) and Assigned(Item2) and (ListViewSort1.Order <> soNone) then begin
|
---|
66 | Score1 := TScore(Item1);
|
---|
67 | Score2 := TScore(Item2);
|
---|
68 | with ListViewSort1 do
|
---|
69 | case Column of
|
---|
70 | 0: Result := CompareDateTime(Score1.StartTime, Score2.StartTime);
|
---|
71 | 1: Result := CompareString(Score1.BoardSize, Score2.BoardSize);
|
---|
72 | 2: Result := CompareInteger(Score1.Score, Score2.Score);
|
---|
73 | 3: Result := CompareInteger(Score1.BiggestTile, Score2.BiggestTile);
|
---|
74 | 4: Result := CompareInteger(Score1.Moves, Score2.Moves);
|
---|
75 | 5: Result := CompareInteger(Score1.UsedUndos, Score2.UsedUndos);
|
---|
76 | 6: Result := CompareInteger(Score1.DisabledTiles, Score2.DisabledTiles);
|
---|
77 | 7: Result := CompareInteger(Score1.UnmergeableTiles, Score2.UnmergeableTiles);
|
---|
78 | 8: Result := CompareDateTime(Score1.Duration, Score2.Duration);
|
---|
79 | end;
|
---|
80 | if ListViewSort1.Order = soDown then Result := -Result;
|
---|
81 | end else Result := 0;
|
---|
82 | end;
|
---|
83 |
|
---|
84 | procedure TFormScore.ListViewSort1Filter(ListViewSort: TListViewSort);
|
---|
85 | begin
|
---|
86 | if Assigned(Scores) then Scores.AssignToList(ListViewSort1.List)
|
---|
87 | else begin
|
---|
88 | ListViewSort1.List.Clear;
|
---|
89 | end;
|
---|
90 | FilterList(ListViewSort1.List);
|
---|
91 | end;
|
---|
92 |
|
---|
93 | procedure TFormScore.FormShow(Sender: TObject);
|
---|
94 | begin
|
---|
95 | ReloadList;
|
---|
96 | end;
|
---|
97 |
|
---|
98 | procedure TFormScore.ButtonClearClick(Sender: TObject);
|
---|
99 | begin
|
---|
100 | if MessageDlg(SClearCaption, SClearQuery, mtConfirmation, [mbOk, mbCancel], 0) = mrOK then begin
|
---|
101 | FScores.Clear;
|
---|
102 | ReloadList;
|
---|
103 | end;
|
---|
104 | end;
|
---|
105 |
|
---|
106 | procedure TFormScore.SetScores(AValue: TScores);
|
---|
107 | begin
|
---|
108 | if FScores = AValue then Exit;
|
---|
109 | FScores := AValue;
|
---|
110 | ReloadList;
|
---|
111 | end;
|
---|
112 |
|
---|
113 | procedure TFormScore.FilterList(List: TObjectList<TObject>);
|
---|
114 | begin
|
---|
115 | end;
|
---|
116 |
|
---|
117 | procedure TFormScore.ReloadList;
|
---|
118 | begin
|
---|
119 | ListViewSort1.Refresh;
|
---|
120 | end;
|
---|
121 |
|
---|
122 | end.
|
---|
123 |
|
---|