mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Now games from databases can be edited and saved
This commit is contained in:
parent
c6f648cfb4
commit
6ccdc954c5
3 changed files with 14 additions and 1 deletions
|
@ -2,7 +2,8 @@
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
|
|
||||||
BaseTab::BaseTab(wxFrame *parent, std::string base_file)
|
BaseTab::BaseTab(wxFrame *parent, std::string base_file)
|
||||||
: BasePanelBF(parent), base_file(base_file), TabInfos(TabInfos::BASE), base(NULL) {
|
: BasePanelBF(parent), base_file(base_file), TabInfos(TabInfos::BASE),
|
||||||
|
base(NULL) {
|
||||||
|
|
||||||
game_list->InsertColumn(0, L"id", wxLIST_FORMAT_LEFT, 50);
|
game_list->InsertColumn(0, L"id", wxLIST_FORMAT_LEFT, 50);
|
||||||
game_list->InsertColumn(1, L"White", wxLIST_FORMAT_LEFT, 200);
|
game_list->InsertColumn(1, L"White", wxLIST_FORMAT_LEFT, 200);
|
||||||
|
@ -38,6 +39,9 @@ void BaseTab::OnDelete(wxCommandEvent &event) {
|
||||||
void BaseTab::OnSave(wxCommandEvent &event) {
|
void BaseTab::OnSave(wxCommandEvent &event) {
|
||||||
std::vector<GameBase *> new_games_bases;
|
std::vector<GameBase *> new_games_bases;
|
||||||
std::vector<Game *> new_games;
|
std::vector<Game *> new_games;
|
||||||
|
new_games.insert(
|
||||||
|
new_games.end(), edited.begin(),
|
||||||
|
edited.end()); // Add edited game (since they are also deleted)
|
||||||
base->Save(deleted, new_games_bases, new_games);
|
base->Save(deleted, new_games_bases, new_games);
|
||||||
game_list->DeleteAllItems();
|
game_list->DeleteAllItems();
|
||||||
deleted.clear();
|
deleted.clear();
|
||||||
|
@ -49,6 +53,9 @@ void BaseTab::OnOpenGame(wxListEvent &event) {
|
||||||
long id = std::stoi(event.GetItem().GetText().ToStdString());
|
long id = std::stoi(event.GetItem().GetText().ToStdString());
|
||||||
Game *g = base->GetGame(id);
|
Game *g = base->GetGame(id);
|
||||||
if (g != NULL) {
|
if (g != NULL) {
|
||||||
|
edited.push_back(g);
|
||||||
|
deleted.push_back(id);
|
||||||
|
game_list->SetItemBackgroundColour(event.GetIndex(), *wxGREEN);
|
||||||
wxCommandEvent newGameEvent(NEW_GAME_EVENT, GetId());
|
wxCommandEvent newGameEvent(NEW_GAME_EVENT, GetId());
|
||||||
newGameEvent.SetEventObject(this);
|
newGameEvent.SetEventObject(this);
|
||||||
newGameEvent.SetClientData(g);
|
newGameEvent.SetClientData(g);
|
||||||
|
|
|
@ -11,6 +11,7 @@ wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
|
||||||
class BaseTab : public BasePanelBF, public TabInfos {
|
class BaseTab : public BasePanelBF, public TabInfos {
|
||||||
GameBase *base;
|
GameBase *base;
|
||||||
std::vector<std::uint32_t> deleted;
|
std::vector<std::uint32_t> deleted;
|
||||||
|
std::vector<Game*> edited;
|
||||||
std::string base_file;
|
std::string base_file;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -79,6 +79,11 @@ void PGNGameBase::Save(std::vector<std::uint32_t> to_ignore,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now add new games
|
// Now add new games
|
||||||
|
for (Game *g : new_games) {
|
||||||
|
new_pgn.Write(g->GetPGN());
|
||||||
|
new_pgn.Write("\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
// new_games->Reset();
|
// new_games->Reset();
|
||||||
// while (new_games->NextGame()) {
|
// while (new_games->NextGame()) {
|
||||||
// Game *g = new_games->GetCurrentGame();
|
// Game *g = new_games->GetCurrentGame();
|
||||||
|
|
Loading…
Add table
Reference in a new issue