Ignore:
Timestamp:
Dec 10, 2024, 11:05:12 AM (5 weeks ago)
Author:
chronos
Message:
  • Added: Sorting by individual columns in Score window.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/FormScore.pas

    r109 r110  
    55uses
    66  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls,
    7   FormEx, Score;
     7  FormEx, ListViewSort, Score, DateUtils, Generics.Collections;
    88
    99type
     
    1515    ButtonClear: TButton;
    1616    ListView1: TListView;
     17    ListViewSort1: TListViewSort;
    1718    procedure ButtonClearClick(Sender: TObject);
    1819    procedure FormShow(Sender: TObject);
    1920    procedure ListView1Data(Sender: TObject; Item: TListItem);
     21    function ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
     22    procedure ListViewSort1Filter(ListViewSort: TListViewSort);
    2023  private
    2124    FScores: TScores;
    2225    procedure SetScores(AValue: TScores);
     26    procedure FilterList(List: TObjectList<TObject>);
    2327  public
    2428    procedure ReloadList;
     
    3539  SClearQuery = 'Do you really want to clear score history?';
    3640
    37 
    3841{ TFormScore }
    3942
    4043procedure TFormScore.ListView1Data(Sender: TObject; Item: TListItem);
    4144begin
    42   if Item.Index < FScores.Count then
    43   with FScores[Item.Index] do begin
     45  if Item.Index < ListViewSort1.List.Count then
     46  with TScore(ListViewSort1.List[Item.Index]) do begin
    4447    Item.Caption := DateTimeToStr(StartTime);
     48    Item.Data := ListViewSort1.List[Item.Index];
    4549    Item.SubItems.Add(BoardSize);
    4650    Item.SubItems.Add(IntToStr(Score));
     
    5256    Item.SubItems.Add(TimeToStr(Duration));
    5357  end;
     58end;
     59
     60function TFormScore.ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
     61var
     62  Score1, Score2: TScore;
     63begin
     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;
     82end;
     83
     84procedure TFormScore.ListViewSort1Filter(ListViewSort: TListViewSort);
     85begin
     86  if Assigned(Scores) then Scores.AssignToList(ListViewSort1.List)
     87    else begin
     88      ListViewSort1.List.Clear;
     89    end;
     90  FilterList(ListViewSort1.List);
    5491end;
    5592
     
    74111end;
    75112
     113procedure TFormScore.FilterList(List: TObjectList<TObject>);
     114begin
     115end;
     116
    76117procedure TFormScore.ReloadList;
    77118begin
    78   if Assigned(FScores) then begin
    79     ListView1.Items.Count := FScores.Count;
    80   end else ListView1.Items.Count := 0;
    81   ListView1.Refresh;
     119  ListViewSort1.Refresh;
    82120end;
    83121
Note: See TracChangeset for help on using the changeset viewer.