aboutsummaryrefslogtreecommitdiff
path: root/src/base_tab/GameListManager.cpp
blob: e073eedf635c64beeb32a848dd517cf89de6f621 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "GameListManager.hpp"


GameListManager::GameListManager(wxListCtrl *game_list): game_list(game_list), game_counter(0) {
  game_list->InsertColumn(0, L"Id", wxLIST_FORMAT_LEFT, 50);
  game_list->InsertColumn(1, L"White", wxLIST_FORMAT_LEFT, 200);
  game_list->InsertColumn(2, L"Black", wxLIST_FORMAT_LEFT, 200);
  game_list->InsertColumn(3, L"Event", wxLIST_FORMAT_LEFT, 150);
  game_list->InsertColumn(4, L"Round", wxLIST_FORMAT_LEFT, 100);
  game_list->InsertColumn(5, L"Result", wxLIST_FORMAT_LEFT, 200);
  game_list->InsertColumn(6, L"ECO", wxLIST_FORMAT_LEFT, 200);
}

void GameListManager::AddGame(CType White,CType Black,CType Event,CType Round, CType Result, CType Eco){
  // Update rows elements
  rows.push_back({White,Black,Event,Round,Result,Eco});
  // Display the row
  DisplayRow(game_counter);
  game_counter++;
}

void GameListManager::DisplayRow(long id){
  RType row=rows[id];
  long index =
            game_list->InsertItem(game_counter, std::to_string(id)); // want this for col. 1
  game_list->SetItem(index, 1, row.White);
  game_list->SetItem(index, 2, row.Black);
  game_list->SetItem(index, 3, row.Event);
  game_list->SetItem(index, 4, row.Round);
  game_list->SetItem(index, 5, row.Result);
  game_list->SetItem(index, 6, row.Eco);
}

void GameListManager::Clear(){
  game_list->DeleteAllItems();
  rows.clear();
}

void GameListManager::ClearDisplayedRow(){
  game_list->DeleteAllItems();
}

void GameListManager::MarkItemAsOpen(long item){
  game_list->SetItemBackgroundColour(item, *wxGREEN);
}

void GameListManager::MarkItemAsDeleted(long item){
  game_list->SetItemBackgroundColour(item, *wxRED);
}

std::vector<long> GameListManager::GetSelectedItems(){
  std::vector<long> items;
  long selected = -1;
  while ((selected = game_list->GetNextItem(selected, wxLIST_NEXT_ALL,
                                            wxLIST_STATE_SELECTED)) !=
         wxNOT_FOUND) {
    items.push_back(selected);
  }
  return(items);
}

long GameListManager::GetItemGameId(long item){
  wxListItem listItem;
    listItem.m_itemId = item;     // sets row
    listItem.m_col = 0;           // sets column to Id (column 0)
    game_list->GetItem(listItem); // gets item

  return std::stol(listItem.GetText().ToStdString());
}