Improve user experience

This commit is contained in:
Loic Guegan 2022-12-28 07:21:30 +01:00
parent 4eeb110f80
commit 214d46b8e2
6 changed files with 61 additions and 41 deletions

View file

@ -21,25 +21,23 @@ MainWindow::MainWindow()
SetStatusText("OChess");
/// File menu
menu_file->Append(1, "Open", "Open file");
menu_file->AppendSeparator();
menu_file->Append(10, "Save", "Save current game");
menu_file->Append(11, "Save As", "Save current game as");
menu_file->AppendSeparator();
menu_file->Append(4, "Settings", "Configure OChess");
menu_file->Append(1, "Settings", "Configure OChess");
menu_file->AppendSeparator();
menu_file->Append(wxID_EXIT);
// Game menu
menu_game->Append(2, "New", "Create new game");
menu_game->Append(3, "New from FEN", "Create new game using FEN");
menu_game->Append(3, "New from position", "Create new game using FEN");
menu_game->Append(4, "Open", "Open first game of a file");
// Game base menu
menu_db->Append(7, "New", "Create database");
menu_db->Append(5, "Open", "Open database");
menu_db->Append(5, "New", "Create database");
menu_db->Append(6, "Open", "Open database");
// Engine menu
menu_engine->Append(6, "New", "Create a new engine configuration");
menu_engine->Append(7, "New", "Create a new engine configuration");
menu_engine->AppendSeparator();
// Dynamically build manage submenu
manageMenu = new wxMenu;
menu_engine->AppendSubMenu(manageMenu, "Manage");
wxCommandEvent dummy(REFRESH_ENGINE_LIST, GetId());
@ -58,6 +56,8 @@ MainWindow::MainWindow()
// Add new game tab by default
NewGame(std::shared_ptr<Game>(new Game()));
// Temporary TO REMOVE JUST FOR TESTS:
/*BaseTab *bt = new BaseTab((wxFrame *)notebook, "/home/loic/pgn/Milov.pgn");
this->AddPage(bt,bt);
@ -105,8 +105,7 @@ void MainWindow::OnMenuItemClick(wxCommandEvent &event) {
std::uint32_t id = event.GetId();
if (id == wxID_EXIT) {
Close(true);
} else if (id >= 100) {
wxLogDebug("Engine selected!");
} else if (id >= 100) { // Engine from manage menu
wxMenuItemList items = manageMenu->GetMenuItems();
for (wxMenuItem *item : items) {
if (item->GetId() == id) {
@ -117,19 +116,21 @@ void MainWindow::OnMenuItemClick(wxCommandEvent &event) {
notebook->SetSelection(notebook->GetPageIndex(bt));
}
}
} else if (id == 1) {
OpenFile();
} else if (id == 2) {
NewGame(false);
} else if (id == 3) {
NewGame(true);
} else if (id == 4) {
} else if (id == 1) { // Settings
OpenSettings();
} else if (id == 5) {
OpenFile();
} else if (id == 6) {
NewEngine();
} else if (id == 7) {
} else if (id == 2) { // New game
NewGame(false);
} else if (id == 3) { // New game from FEN
NewGame(true);
} else if (id == 4) { // Open first game
wxFileDialog openFileDialog(this, _("Open single game"), "", "",
"PGN files (*.pgn)|*.pgn",
wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (openFileDialog.ShowModal() != wxID_CANCEL) {
std::string path = openFileDialog.GetPath().ToStdString();
NewGame(OpenGameX(path,0));
}
} else if (id == 5) { // Create database
wxFileDialog
newFileDialog(this, _("Create database file"), "", "",
"PGN files (*.pgn)|*.pgn", wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
@ -139,6 +140,18 @@ void MainWindow::OnMenuItemClick(wxCommandEvent &event) {
std::string path = newFileDialog.GetPath().ToStdString();
BaseTab *bt = new BaseTab((wxFrame *)notebook, path);
AddPage(bt,bt);
} else if (id == 6) { // Open Database
wxFileDialog openFileDialog(this, _("Open database"), "", "",
"PGN files (*.pgn)|*.pgn",
wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (openFileDialog.ShowModal() != wxID_CANCEL) {
std::string path = openFileDialog.GetPath().ToStdString();
// Test base tab
BaseTab *bt = new BaseTab((wxFrame *)notebook, path);
AddPage(bt,bt);
}
} else if (id == 7) { // Create new engine
NewEngine();
}
}
@ -205,18 +218,6 @@ void MainWindow::OnClose(wxCloseEvent &e) {
}
void MainWindow::OpenFile() {
wxFileDialog openFileDialog(this, _("Open file"), "", "",
"PGN files (*.pgn)|*.pgn",
wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (openFileDialog.ShowModal() != wxID_CANCEL) {
std::string path = openFileDialog.GetPath().ToStdString();
// Test base tab
BaseTab *bt = new BaseTab((wxFrame *)notebook, path);
AddPage(bt,bt);
}
}
void MainWindow::NewGame(bool useFen) {
if (useFen) {
wxTextEntryDialog *dial =

View file

@ -19,7 +19,6 @@ class MainWindow : public MainFrame {
void OnClose(wxCloseEvent &e);
void NewGame(bool useFen);
void OpenFile();
void OnPageChange(wxAuiNotebookEvent &event);
void OnRefreshTabTitle(wxCommandEvent &event);
void OpenSettings();

View file

@ -36,13 +36,18 @@ void BaseGameTab::OnApplyFilter(wxCommandEvent &event){
void BaseGameTab::OnDelete(wxCommandEvent &event) {
for(auto i: glm->GetSelectedItems()){
deleted.push_back(glm->GetItemGameId(i));
glm->MarkItemAsDeleted(i);
game_list->SetItemState(i, 0, wxLIST_STATE_SELECTED); // First deselect
long gameid=glm->GetItemGameId(i);
if(!std::count(deleted.begin(), deleted.end(), gameid)){
deleted.push_back(gameid);
glm->MarkItemAsDeleted(i);
}
}
NOTIFY_MANAGE_TAB();
}
std::shared_ptr<Game> BaseGameTab::OpenGame(long gameid, long item) {
game_list->SetItemState(item, 0, wxLIST_STATE_SELECTED); // First deselect
if(edited.find(gameid) != edited.end()){
// TODO: Focus on the game tab and if close reopen it
wxLogDebug("Already opened!");

View file

@ -77,6 +77,7 @@ void BaseImportTab::OnImportSelection(wxCommandEvent &event){
while ((selected = game_list->GetNextItem(selected, wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED)) !=
wxNOT_FOUND) {
game_list->SetItemState(selected, 0, wxLIST_STATE_SELECTED); // First deselect
// Get game id
long game_id=glm->GetItemGameId(selected);
// Select the right db hashmap
@ -112,6 +113,7 @@ void BaseImportTab::OnLoad(wxCommandEvent &event){
selected_base=OpenDatabase(game_tab->GetBase()->GetFilePath());
SHOW_DIALOG_BUSY("Loading database...");
auto &game_list=selected_games_to_import[selected_base->GetFilePath()];
bool baseImported=std::count(databases_to_import.begin(),databases_to_import.end(),selected_base->GetFilePath())>0;
while (selected_base->NextGame()) {
long id=glm->AddGame(
selected_base->GetTag("White"),
@ -120,7 +122,7 @@ void BaseImportTab::OnLoad(wxCommandEvent &event){
selected_base->GetTag("Round"),
selected_base->GetTag("Result"),
selected_base->GetTag("ECO"));
if(game_list.find(id)!=game_list.end()){
if(game_list.find(id)!=game_list.end() || baseImported){
glm->MarkItemAsImported(id);
}
}

View file

@ -11,4 +11,9 @@ std::shared_ptr<GameBase> OpenDatabase(const std::string &dbpath, bool createIfN
return std::shared_ptr<GameBase>(new PGNGameBase(dbpath));
}
return nullptr;
}
std::shared_ptr<Game> OpenGameX(const std::string &dbpath, long id){
std::shared_ptr<GameBase> base=OpenDatabase(dbpath);
return base->GetGame(id);
}

View file

@ -35,4 +35,12 @@ public:
* @param dbpath
* @return std::shared_ptr<GameBase>
*/
std::shared_ptr<GameBase> OpenDatabase(const std::string &dbpath, bool createIfNotExist=true);
std::shared_ptr<GameBase> OpenDatabase(const std::string &dbpath, bool createIfNotExist=true);
/**
* @brief Single game open
*
* @param dbpath
* @param id
* @return std::shared_ptr<Game>
*/
std::shared_ptr<Game> OpenGameX(const std::string &dbpath, long id);