mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Improve user experience
This commit is contained in:
parent
4eeb110f80
commit
214d46b8e2
6 changed files with 61 additions and 41 deletions
|
@ -21,25 +21,23 @@ MainWindow::MainWindow()
|
||||||
SetStatusText("OChess");
|
SetStatusText("OChess");
|
||||||
|
|
||||||
/// File menu
|
/// File menu
|
||||||
menu_file->Append(1, "Open", "Open file");
|
menu_file->Append(1, "Settings", "Configure OChess");
|
||||||
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->AppendSeparator();
|
menu_file->AppendSeparator();
|
||||||
menu_file->Append(wxID_EXIT);
|
menu_file->Append(wxID_EXIT);
|
||||||
|
|
||||||
// Game menu
|
// Game menu
|
||||||
menu_game->Append(2, "New", "Create new game");
|
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
|
// Game base menu
|
||||||
menu_db->Append(7, "New", "Create database");
|
menu_db->Append(5, "New", "Create database");
|
||||||
menu_db->Append(5, "Open", "Open database");
|
menu_db->Append(6, "Open", "Open database");
|
||||||
|
|
||||||
// Engine menu
|
// 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;
|
manageMenu = new wxMenu;
|
||||||
menu_engine->AppendSubMenu(manageMenu, "Manage");
|
menu_engine->AppendSubMenu(manageMenu, "Manage");
|
||||||
wxCommandEvent dummy(REFRESH_ENGINE_LIST, GetId());
|
wxCommandEvent dummy(REFRESH_ENGINE_LIST, GetId());
|
||||||
|
@ -58,6 +56,8 @@ MainWindow::MainWindow()
|
||||||
// Add new game tab by default
|
// Add new game tab by default
|
||||||
NewGame(std::shared_ptr<Game>(new Game()));
|
NewGame(std::shared_ptr<Game>(new Game()));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Temporary TO REMOVE JUST FOR TESTS:
|
// Temporary TO REMOVE JUST FOR TESTS:
|
||||||
/*BaseTab *bt = new BaseTab((wxFrame *)notebook, "/home/loic/pgn/Milov.pgn");
|
/*BaseTab *bt = new BaseTab((wxFrame *)notebook, "/home/loic/pgn/Milov.pgn");
|
||||||
this->AddPage(bt,bt);
|
this->AddPage(bt,bt);
|
||||||
|
@ -105,8 +105,7 @@ void MainWindow::OnMenuItemClick(wxCommandEvent &event) {
|
||||||
std::uint32_t id = event.GetId();
|
std::uint32_t id = event.GetId();
|
||||||
if (id == wxID_EXIT) {
|
if (id == wxID_EXIT) {
|
||||||
Close(true);
|
Close(true);
|
||||||
} else if (id >= 100) {
|
} else if (id >= 100) { // Engine from manage menu
|
||||||
wxLogDebug("Engine selected!");
|
|
||||||
wxMenuItemList items = manageMenu->GetMenuItems();
|
wxMenuItemList items = manageMenu->GetMenuItems();
|
||||||
for (wxMenuItem *item : items) {
|
for (wxMenuItem *item : items) {
|
||||||
if (item->GetId() == id) {
|
if (item->GetId() == id) {
|
||||||
|
@ -117,19 +116,21 @@ void MainWindow::OnMenuItemClick(wxCommandEvent &event) {
|
||||||
notebook->SetSelection(notebook->GetPageIndex(bt));
|
notebook->SetSelection(notebook->GetPageIndex(bt));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (id == 1) {
|
} else if (id == 1) { // Settings
|
||||||
OpenFile();
|
|
||||||
} else if (id == 2) {
|
|
||||||
NewGame(false);
|
|
||||||
} else if (id == 3) {
|
|
||||||
NewGame(true);
|
|
||||||
} else if (id == 4) {
|
|
||||||
OpenSettings();
|
OpenSettings();
|
||||||
} else if (id == 5) {
|
} else if (id == 2) { // New game
|
||||||
OpenFile();
|
NewGame(false);
|
||||||
} else if (id == 6) {
|
} else if (id == 3) { // New game from FEN
|
||||||
NewEngine();
|
NewGame(true);
|
||||||
} else if (id == 7) {
|
} 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
|
wxFileDialog
|
||||||
newFileDialog(this, _("Create database file"), "", "",
|
newFileDialog(this, _("Create database file"), "", "",
|
||||||
"PGN files (*.pgn)|*.pgn", wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
|
"PGN files (*.pgn)|*.pgn", wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
|
||||||
|
@ -139,6 +140,18 @@ void MainWindow::OnMenuItemClick(wxCommandEvent &event) {
|
||||||
std::string path = newFileDialog.GetPath().ToStdString();
|
std::string path = newFileDialog.GetPath().ToStdString();
|
||||||
BaseTab *bt = new BaseTab((wxFrame *)notebook, path);
|
BaseTab *bt = new BaseTab((wxFrame *)notebook, path);
|
||||||
AddPage(bt,bt);
|
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) {
|
void MainWindow::NewGame(bool useFen) {
|
||||||
if (useFen) {
|
if (useFen) {
|
||||||
wxTextEntryDialog *dial =
|
wxTextEntryDialog *dial =
|
||||||
|
|
|
@ -19,7 +19,6 @@ class MainWindow : public MainFrame {
|
||||||
|
|
||||||
void OnClose(wxCloseEvent &e);
|
void OnClose(wxCloseEvent &e);
|
||||||
void NewGame(bool useFen);
|
void NewGame(bool useFen);
|
||||||
void OpenFile();
|
|
||||||
void OnPageChange(wxAuiNotebookEvent &event);
|
void OnPageChange(wxAuiNotebookEvent &event);
|
||||||
void OnRefreshTabTitle(wxCommandEvent &event);
|
void OnRefreshTabTitle(wxCommandEvent &event);
|
||||||
void OpenSettings();
|
void OpenSettings();
|
||||||
|
|
|
@ -36,13 +36,18 @@ void BaseGameTab::OnApplyFilter(wxCommandEvent &event){
|
||||||
|
|
||||||
void BaseGameTab::OnDelete(wxCommandEvent &event) {
|
void BaseGameTab::OnDelete(wxCommandEvent &event) {
|
||||||
for(auto i: glm->GetSelectedItems()){
|
for(auto i: glm->GetSelectedItems()){
|
||||||
deleted.push_back(glm->GetItemGameId(i));
|
game_list->SetItemState(i, 0, wxLIST_STATE_SELECTED); // First deselect
|
||||||
glm->MarkItemAsDeleted(i);
|
long gameid=glm->GetItemGameId(i);
|
||||||
|
if(!std::count(deleted.begin(), deleted.end(), gameid)){
|
||||||
|
deleted.push_back(gameid);
|
||||||
|
glm->MarkItemAsDeleted(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
NOTIFY_MANAGE_TAB();
|
NOTIFY_MANAGE_TAB();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Game> BaseGameTab::OpenGame(long gameid, long item) {
|
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()){
|
if(edited.find(gameid) != edited.end()){
|
||||||
// TODO: Focus on the game tab and if close reopen it
|
// TODO: Focus on the game tab and if close reopen it
|
||||||
wxLogDebug("Already opened!");
|
wxLogDebug("Already opened!");
|
||||||
|
|
|
@ -77,6 +77,7 @@ void BaseImportTab::OnImportSelection(wxCommandEvent &event){
|
||||||
while ((selected = game_list->GetNextItem(selected, wxLIST_NEXT_ALL,
|
while ((selected = game_list->GetNextItem(selected, wxLIST_NEXT_ALL,
|
||||||
wxLIST_STATE_SELECTED)) !=
|
wxLIST_STATE_SELECTED)) !=
|
||||||
wxNOT_FOUND) {
|
wxNOT_FOUND) {
|
||||||
|
game_list->SetItemState(selected, 0, wxLIST_STATE_SELECTED); // First deselect
|
||||||
// Get game id
|
// Get game id
|
||||||
long game_id=glm->GetItemGameId(selected);
|
long game_id=glm->GetItemGameId(selected);
|
||||||
// Select the right db hashmap
|
// Select the right db hashmap
|
||||||
|
@ -112,6 +113,7 @@ void BaseImportTab::OnLoad(wxCommandEvent &event){
|
||||||
selected_base=OpenDatabase(game_tab->GetBase()->GetFilePath());
|
selected_base=OpenDatabase(game_tab->GetBase()->GetFilePath());
|
||||||
SHOW_DIALOG_BUSY("Loading database...");
|
SHOW_DIALOG_BUSY("Loading database...");
|
||||||
auto &game_list=selected_games_to_import[selected_base->GetFilePath()];
|
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()) {
|
while (selected_base->NextGame()) {
|
||||||
long id=glm->AddGame(
|
long id=glm->AddGame(
|
||||||
selected_base->GetTag("White"),
|
selected_base->GetTag("White"),
|
||||||
|
@ -120,7 +122,7 @@ void BaseImportTab::OnLoad(wxCommandEvent &event){
|
||||||
selected_base->GetTag("Round"),
|
selected_base->GetTag("Round"),
|
||||||
selected_base->GetTag("Result"),
|
selected_base->GetTag("Result"),
|
||||||
selected_base->GetTag("ECO"));
|
selected_base->GetTag("ECO"));
|
||||||
if(game_list.find(id)!=game_list.end()){
|
if(game_list.find(id)!=game_list.end() || baseImported){
|
||||||
glm->MarkItemAsImported(id);
|
glm->MarkItemAsImported(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,4 +11,9 @@ std::shared_ptr<GameBase> OpenDatabase(const std::string &dbpath, bool createIfN
|
||||||
return std::shared_ptr<GameBase>(new PGNGameBase(dbpath));
|
return std::shared_ptr<GameBase>(new PGNGameBase(dbpath));
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Game> OpenGameX(const std::string &dbpath, long id){
|
||||||
|
std::shared_ptr<GameBase> base=OpenDatabase(dbpath);
|
||||||
|
return base->GetGame(id);
|
||||||
}
|
}
|
|
@ -35,4 +35,12 @@ public:
|
||||||
* @param dbpath
|
* @param dbpath
|
||||||
* @return std::shared_ptr<GameBase>
|
* @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);
|
Loading…
Add table
Reference in a new issue