ochess/src/base_tab/BaseTab.cpp

58 lines
1.9 KiB
C++
Raw Normal View History

2022-02-24 11:50:16 +01:00
#include "BaseTab.hpp"
#include <wx/filename.h>
BaseTab::BaseTab(wxFrame *parent)
: BasePanelBF(parent), TabInfos(TabInfos::BASE), base(NULL) {
2022-02-24 15:22:56 +01:00
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);
2022-02-24 17:53:30 +01:00
game_list->InsertColumn(3, L"Event", wxLIST_FORMAT_LEFT, 150);
2022-02-24 15:22:56 +01:00
game_list->InsertColumn(4, L"Round", wxLIST_FORMAT_LEFT, 100);
game_list->InsertColumn(5, L"Result", wxLIST_FORMAT_LEFT, 200);
2022-02-24 17:53:30 +01:00
game_list->InsertColumn(6, L"ECO", wxLIST_FORMAT_LEFT, 200);
2022-02-24 15:22:56 +01:00
this->Bind(wxEVT_BUTTON, &BaseTab::OnBim, this, wxID_ANY);
this->Bind(wxEVT_LIST_ITEM_ACTIVATED, &BaseTab::OnOpenGame, this, wxID_ANY);
}
void BaseTab::OnBim(wxCommandEvent &event) {
2022-02-24 19:11:44 +01:00
LoadFile("/home/loic/hartwig.pgn");
2022-02-24 15:22:56 +01:00
}
void BaseTab::OnOpenGame(wxListEvent &event) {
wxLogDebug("Open!");
long id = std::stoi(event.GetItem().GetText().ToStdString());
2022-02-24 15:22:56 +01:00
Game *g = base->GetGame(id);
if (g != NULL) {
wxCommandEvent newGameEvent(NEW_GAME_EVENT, GetId());
newGameEvent.SetEventObject(this);
newGameEvent.SetClientData(g);
ProcessEvent(newGameEvent);
2022-02-24 15:22:56 +01:00
}
2022-02-24 11:50:16 +01:00
}
void BaseTab::ApplyPreferences() {}
void BaseTab::LoadFile(std::string path) {
wxFileName file(path);
wxString ext = file.GetExt().Lower();
if (ext == "pgn") {
base = new PGNGameBase(path);
}
if (base != NULL) {
2022-02-24 15:22:56 +01:00
long id = 0;
while (base->NextGame()) {
long index =
game_list->InsertItem(0, std::to_string(id)); // want this for col. 1
2022-02-24 15:22:56 +01:00
game_list->SetItem(index, 1, base->GetTag("White"));
game_list->SetItem(index, 2, base->GetTag("Black"));
game_list->SetItem(index, 3, base->GetTag("Event"));
game_list->SetItem(index, 4, base->GetTag("Round"));
game_list->SetItem(index, 5, base->GetTag("Result"));
2022-02-24 17:53:30 +01:00
game_list->SetItem(index, 5, base->GetTag("ECO"));
2022-02-24 15:22:56 +01:00
id++;
}
2022-02-24 11:50:16 +01:00
}
}