mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-09 22:56:53 +00:00
Now engines can be added
This commit is contained in:
parent
e601902dd5
commit
6c34ef20fb
4 changed files with 126 additions and 41 deletions
|
@ -8,6 +8,7 @@
|
||||||
wxDEFINE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
|
wxDEFINE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
|
||||||
wxDEFINE_EVENT(NEW_GAME_EVENT, wxCommandEvent);
|
wxDEFINE_EVENT(NEW_GAME_EVENT, wxCommandEvent);
|
||||||
wxDEFINE_EVENT(CLOSE_TAB_EVENT, wxCommandEvent);
|
wxDEFINE_EVENT(CLOSE_TAB_EVENT, wxCommandEvent);
|
||||||
|
wxDEFINE_EVENT(REFRESH_ENGINE_LIST, wxCommandEvent);
|
||||||
|
|
||||||
/// ---------- MainWindow ----------
|
/// ---------- MainWindow ----------
|
||||||
|
|
||||||
|
@ -21,23 +22,18 @@ MainWindow::MainWindow()
|
||||||
/// File menu
|
/// File menu
|
||||||
wxMenu *menuFile = new wxMenu;
|
wxMenu *menuFile = new wxMenu;
|
||||||
menuFile->Append(1, "Open", "Open file");
|
menuFile->Append(1, "Open", "Open file");
|
||||||
Bind(wxEVT_MENU, &MainWindow::OnOpen, this, 1);
|
|
||||||
menuFile->AppendSeparator();
|
menuFile->AppendSeparator();
|
||||||
menuFile->Append(10, "Save", "Save current game");
|
menuFile->Append(10, "Save", "Save current game");
|
||||||
menuFile->Append(11, "Save As", "Save current game as");
|
menuFile->Append(11, "Save As", "Save current game as");
|
||||||
menuFile->AppendSeparator();
|
menuFile->AppendSeparator();
|
||||||
menuFile->Append(4, "Settings", "Configure OChess");
|
menuFile->Append(4, "Settings", "Configure OChess");
|
||||||
Bind(wxEVT_MENU, &MainWindow::OnSettings, this, 4);
|
|
||||||
menuFile->AppendSeparator();
|
menuFile->AppendSeparator();
|
||||||
menuFile->Append(wxID_EXIT);
|
menuFile->Append(wxID_EXIT);
|
||||||
Bind(wxEVT_MENU, &MainWindow::OnExit, this, wxID_EXIT);
|
|
||||||
|
|
||||||
// Game menu
|
// Game menu
|
||||||
menuGame = new wxMenu;
|
menuGame = new wxMenu;
|
||||||
menuGame->Append(2, "New", "Create new game");
|
menuGame->Append(2, "New", "Create new game");
|
||||||
Bind(wxEVT_MENU, &MainWindow::OnMenuNewGame, this, 2);
|
|
||||||
menuGame->Append(3, "New from FEN", "Create new game using FEN");
|
menuGame->Append(3, "New from FEN", "Create new game using FEN");
|
||||||
Bind(wxEVT_MENU, &MainWindow::OnMenuNewGame, this, 3);
|
|
||||||
|
|
||||||
// Game base menu
|
// Game base menu
|
||||||
wxMenu *menuBase = new wxMenu;
|
wxMenu *menuBase = new wxMenu;
|
||||||
|
@ -46,7 +42,10 @@ MainWindow::MainWindow()
|
||||||
// Engine menu
|
// Engine menu
|
||||||
wxMenu *engineMenu = new wxMenu;
|
wxMenu *engineMenu = new wxMenu;
|
||||||
engineMenu->Append(6, "New", "Create a new engine configuration");
|
engineMenu->Append(6, "New", "Create a new engine configuration");
|
||||||
Bind(wxEVT_MENU, &MainWindow::OnNewEngine, this, 6);
|
manageMenu = new wxMenu;
|
||||||
|
engineMenu->AppendSubMenu(manageMenu, "Manage");
|
||||||
|
wxCommandEvent dummy(REFRESH_ENGINE_LIST, GetId());
|
||||||
|
OnRefreshEngineList(dummy);
|
||||||
|
|
||||||
/// Menu bar
|
/// Menu bar
|
||||||
menuBar = new wxMenuBar;
|
menuBar = new wxMenuBar;
|
||||||
|
@ -66,6 +65,8 @@ MainWindow::MainWindow()
|
||||||
Bind(NEW_GAME_EVENT, &MainWindow::OnNewGame, this, wxID_ANY);
|
Bind(NEW_GAME_EVENT, &MainWindow::OnNewGame, this, wxID_ANY);
|
||||||
Bind(wxEVT_CLOSE_WINDOW, &MainWindow::OnClose, this);
|
Bind(wxEVT_CLOSE_WINDOW, &MainWindow::OnClose, this);
|
||||||
Bind(CLOSE_TAB_EVENT, &MainWindow::OnCloseTabEvent, this, wxID_ANY);
|
Bind(CLOSE_TAB_EVENT, &MainWindow::OnCloseTabEvent, this, wxID_ANY);
|
||||||
|
Bind(wxEVT_MENU, &MainWindow::OnMenuItemClick, this, wxID_ANY);
|
||||||
|
Bind(REFRESH_ENGINE_LIST, &MainWindow::OnRefreshEngineList, this, wxID_ANY);
|
||||||
|
|
||||||
/*BaseTab *bt = new BaseTab((wxFrame *)notebook,
|
/*BaseTab *bt = new BaseTab((wxFrame *)notebook,
|
||||||
"/home/loic/hartwig_tests.pgn"); notebook->AddPage(bt, bt->GetLabel());
|
"/home/loic/hartwig_tests.pgn"); notebook->AddPage(bt, bt->GetLabel());
|
||||||
|
@ -83,7 +84,58 @@ void MainWindow::OnCloseTabEvent(wxCommandEvent &event) {
|
||||||
notebook->DeletePage(notebook->GetSelection());
|
notebook->DeletePage(notebook->GetSelection());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::OnNewEngine(wxCommandEvent &event) {
|
void MainWindow::OnMenuItemClick(wxCommandEvent &event) {
|
||||||
|
std::uint32_t id = event.GetId();
|
||||||
|
if (id == wxID_EXIT) {
|
||||||
|
Close(true);
|
||||||
|
} else if (id >= 100) {
|
||||||
|
wxLogDebug("Engine selected!");
|
||||||
|
wxMenuItemList items = manageMenu->GetMenuItems();
|
||||||
|
for (wxMenuItem *item : items) {
|
||||||
|
if (item->GetId() == id) {
|
||||||
|
wxLogDebug("Selected %s", item->GetItemLabel());
|
||||||
|
EngineTab *bt = new EngineTab((wxWindow *)notebook,
|
||||||
|
item->GetItemLabel().ToStdString());
|
||||||
|
notebook->AddPage(bt, bt->GetLabel());
|
||||||
|
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) {
|
||||||
|
OpenSettings();
|
||||||
|
} else if (id == 6) {
|
||||||
|
NewEngine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::OnRefreshEngineList(wxCommandEvent &event) {
|
||||||
|
// Delete all items
|
||||||
|
wxMenuItemList items = manageMenu->GetMenuItems();
|
||||||
|
for (wxMenuItem *item : items) {
|
||||||
|
manageMenu->Delete(item->GetId());
|
||||||
|
}
|
||||||
|
// Refresh items
|
||||||
|
CONFIG_OPEN(conf);
|
||||||
|
conf->SetPath("engines/");
|
||||||
|
wxString engine_name;
|
||||||
|
long index;
|
||||||
|
if (conf->GetFirstGroup(engine_name, index)) {
|
||||||
|
std::uint32_t id = 0;
|
||||||
|
do {
|
||||||
|
manageMenu->Append(100 + id, engine_name, "Configure " + engine_name);
|
||||||
|
id++;
|
||||||
|
} while (conf->GetNextGroup(engine_name, index));
|
||||||
|
}
|
||||||
|
|
||||||
|
CONFIG_CLOSE(conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::NewEngine() {
|
||||||
wxFileDialog openFileDialog(this, _("Use engine"), "", "", "Executable|*",
|
wxFileDialog openFileDialog(this, _("Use engine"), "", "", "Executable|*",
|
||||||
wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
||||||
if (openFileDialog.ShowModal() != wxID_CANCEL) {
|
if (openFileDialog.ShowModal() != wxID_CANCEL) {
|
||||||
|
@ -100,7 +152,7 @@ void MainWindow::OnNewEngine(wxCommandEvent &event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::OnSettings(wxCommandEvent &event) {
|
void MainWindow::OpenSettings() {
|
||||||
if (prefsEditor != NULL) {
|
if (prefsEditor != NULL) {
|
||||||
delete prefsEditor;
|
delete prefsEditor;
|
||||||
}
|
}
|
||||||
|
@ -117,8 +169,6 @@ void MainWindow::ApplyPreferences() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::OnExit(wxCommandEvent &event) { Close(true); }
|
|
||||||
|
|
||||||
std::vector<TabInfos *> MainWindow::ListTabInfos() {
|
std::vector<TabInfos *> MainWindow::ListTabInfos() {
|
||||||
std::vector<TabInfos *> tinfos;
|
std::vector<TabInfos *> tinfos;
|
||||||
for (int i = 0; i < notebook->GetPageCount(); i++) {
|
for (int i = 0; i < notebook->GetPageCount(); i++) {
|
||||||
|
@ -134,7 +184,7 @@ void MainWindow::OnClose(wxCloseEvent &e) {
|
||||||
e.Skip();
|
e.Skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::OnOpen(wxCommandEvent &event) {
|
void MainWindow::OpenFile() {
|
||||||
wxFileDialog openFileDialog(this, _("Open file"), "", "",
|
wxFileDialog openFileDialog(this, _("Open file"), "", "",
|
||||||
"PGN files (*.pgn)|*.pgn",
|
"PGN files (*.pgn)|*.pgn",
|
||||||
wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
||||||
|
@ -147,8 +197,8 @@ void MainWindow::OnOpen(wxCommandEvent &event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::OnMenuNewGame(wxCommandEvent &event) {
|
void MainWindow::NewGame(bool useFen) {
|
||||||
if (event.GetId() == 3) {
|
if (useFen) {
|
||||||
wxTextEntryDialog *dial =
|
wxTextEntryDialog *dial =
|
||||||
new wxTextEntryDialog(NULL, wxT("Enter FEN:"), wxT("Error"));
|
new wxTextEntryDialog(NULL, wxT("Enter FEN:"), wxT("Error"));
|
||||||
if (dial->ShowModal() == wxID_OK) {
|
if (dial->ShowModal() == wxID_OK) {
|
||||||
|
|
|
@ -11,24 +11,27 @@
|
||||||
wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
|
wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
|
||||||
wxDECLARE_EVENT(NEW_GAME_EVENT, wxCommandEvent);
|
wxDECLARE_EVENT(NEW_GAME_EVENT, wxCommandEvent);
|
||||||
wxDECLARE_EVENT(CLOSE_TAB_EVENT, wxCommandEvent);
|
wxDECLARE_EVENT(CLOSE_TAB_EVENT, wxCommandEvent);
|
||||||
|
wxDECLARE_EVENT(REFRESH_ENGINE_LIST, wxCommandEvent);
|
||||||
|
|
||||||
class MainWindow : public wxFrame {
|
class MainWindow : public wxFrame {
|
||||||
wxAuiNotebook *notebook;
|
wxAuiNotebook *notebook;
|
||||||
wxMenu *menuGame;
|
wxMenu *menuGame;
|
||||||
wxMenuBar *menuBar;
|
wxMenuBar *menuBar;
|
||||||
wxPreferencesEditor *prefsEditor;
|
wxPreferencesEditor *prefsEditor;
|
||||||
|
wxMenu *manageMenu;
|
||||||
|
|
||||||
void OnExit(wxCommandEvent &event);
|
|
||||||
void OnClose(wxCloseEvent &e);
|
void OnClose(wxCloseEvent &e);
|
||||||
void OnMenuNewGame(wxCommandEvent &event);
|
void NewGame(bool useFen);
|
||||||
void OnNewGame(wxCommandEvent &event);
|
void OnNewGame(wxCommandEvent &event);
|
||||||
void OnOpen(wxCommandEvent &event);
|
void OpenFile();
|
||||||
void OnPageChange(wxAuiNotebookEvent &event);
|
void OnPageChange(wxAuiNotebookEvent &event);
|
||||||
void OnRefreshTabTitle(wxCommandEvent &event);
|
void OnRefreshTabTitle(wxCommandEvent &event);
|
||||||
void NewGame(Game *game);
|
void NewGame(Game *game);
|
||||||
void OnSettings(wxCommandEvent &event);
|
void OpenSettings();
|
||||||
void OnNewEngine(wxCommandEvent &event);
|
void NewEngine();
|
||||||
void OnCloseTabEvent(wxCommandEvent &event);
|
void OnCloseTabEvent(wxCommandEvent &event);
|
||||||
|
void OnRefreshEngineList(wxCommandEvent &event);
|
||||||
|
void OnMenuItemClick(wxCommandEvent &event);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MainWindow();
|
MainWindow();
|
||||||
|
|
|
@ -22,7 +22,46 @@ EngineTab::EngineTab(wxWindow *parent, uciadapter::UCI *engine,
|
||||||
// conf->Write(confGroup + "/path", wxString(engine_path_or_name));
|
// conf->Write(confGroup + "/path", wxString(engine_path_or_name));
|
||||||
CONFIG_CLOSE(conf);
|
CONFIG_CLOSE(conf);
|
||||||
InitConfiguration();
|
InitConfiguration();
|
||||||
|
LoadConfiguration();
|
||||||
|
RefreshItemList();
|
||||||
|
|
||||||
|
Bind(wxEVT_BUTTON, &EngineTab::OnSave, this, ENGINE_SAVE_CONF_BUTTON);
|
||||||
|
Bind(wxEVT_BUTTON, &EngineTab::OnDelete, this, ENGINE_DELETE_CONF_BUTTON);
|
||||||
|
}
|
||||||
|
|
||||||
|
EngineTab::EngineTab(wxWindow *parent, std::string name)
|
||||||
|
: EngineTabBF(parent), TabInfos(TabInfos::ENGINE) {
|
||||||
|
SetLabel(name);
|
||||||
|
engineName = name;
|
||||||
|
confGroup = "engines/" + engineName;
|
||||||
|
engine_name->SetValue(engineName);
|
||||||
|
CONFIG_OPEN(conf);
|
||||||
|
engine_location->SetValue(conf->Read(confGroup + "/path"));
|
||||||
|
CONFIG_CLOSE(conf);
|
||||||
|
LoadConfiguration();
|
||||||
|
|
||||||
|
Bind(wxEVT_BUTTON, &EngineTab::OnSave, this, ENGINE_SAVE_CONF_BUTTON);
|
||||||
|
Bind(wxEVT_BUTTON, &EngineTab::OnDelete, this, ENGINE_DELETE_CONF_BUTTON);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EngineTab::OnDelete(wxCommandEvent &event) {
|
||||||
|
CONFIG_OPEN(conf);
|
||||||
|
conf->DeleteGroup(confGroup);
|
||||||
|
CONFIG_CLOSE(conf);
|
||||||
|
RefreshItemList();
|
||||||
|
|
||||||
|
wxCommandEvent closeTabEvent(CLOSE_TAB_EVENT, GetId());
|
||||||
|
closeTabEvent.SetEventObject(this);
|
||||||
|
ProcessEvent(closeTabEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EngineTab::RefreshItemList() {
|
||||||
|
wxCommandEvent refreshEngineList(REFRESH_ENGINE_LIST, GetId());
|
||||||
|
refreshEngineList.SetEventObject(this);
|
||||||
|
ProcessEvent(refreshEngineList);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EngineTab::LoadConfiguration() {
|
||||||
// Build wxPropertyGrid according to engine configuration
|
// Build wxPropertyGrid according to engine configuration
|
||||||
CONFIG_OPEN(conf2);
|
CONFIG_OPEN(conf2);
|
||||||
long index;
|
long index;
|
||||||
|
@ -48,28 +87,17 @@ EngineTab::EngineTab(wxWindow *parent, uciadapter::UCI *engine,
|
||||||
} while (conf2->GetNextGroup(opt_name, index));
|
} while (conf2->GetNextGroup(opt_name, index));
|
||||||
}
|
}
|
||||||
CONFIG_CLOSE(conf2);
|
CONFIG_CLOSE(conf2);
|
||||||
|
|
||||||
Bind(wxEVT_BUTTON, &EngineTab::OnSave, this, ENGINE_SAVE_CONF_BUTTON);
|
|
||||||
Bind(wxEVT_BUTTON, &EngineTab::OnDelete, this, ENGINE_DELETE_CONF_BUTTON);
|
|
||||||
}
|
|
||||||
|
|
||||||
void EngineTab::OnDelete(wxCommandEvent &event) {
|
|
||||||
CONFIG_OPEN(conf);
|
|
||||||
conf->DeleteGroup(confGroup);
|
|
||||||
CONFIG_CLOSE(conf);
|
|
||||||
|
|
||||||
wxCommandEvent closeTabEvent(CLOSE_TAB_EVENT, GetId());
|
|
||||||
closeTabEvent.SetEventObject(this);
|
|
||||||
ProcessEvent(closeTabEvent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EngineTab::OnSave(wxCommandEvent &event) {
|
void EngineTab::OnSave(wxCommandEvent &event) {
|
||||||
CONFIG_OPEN(conf2);
|
CONFIG_OPEN(conf2);
|
||||||
wxString new_engine_name = engine_name->GetValue();
|
wxString new_engine_name = engine_name->GetValue();
|
||||||
if (new_engine_name != engineName) {
|
if (new_engine_name != engineName) {
|
||||||
conf2->RenameGroup(confGroup, "engines/" + new_engine_name);
|
conf2->SetPath("engines/");
|
||||||
|
conf2->RenameGroup(engineName, new_engine_name);
|
||||||
engineName = new_engine_name;
|
engineName = new_engine_name;
|
||||||
confGroup = "engines/" + engineName;
|
confGroup = "engines/" + engineName;
|
||||||
|
conf2->SetPath("..");
|
||||||
}
|
}
|
||||||
long index;
|
long index;
|
||||||
std::string optsPath = confGroup + "/options";
|
std::string optsPath = confGroup + "/options";
|
||||||
|
@ -91,6 +119,7 @@ void EngineTab::OnSave(wxCommandEvent &event) {
|
||||||
} while (conf2->GetNextGroup(opt_name, index));
|
} while (conf2->GetNextGroup(opt_name, index));
|
||||||
}
|
}
|
||||||
CONFIG_CLOSE(conf2);
|
CONFIG_CLOSE(conf2);
|
||||||
|
RefreshItemList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EngineTab::InitConfiguration() {
|
void EngineTab::InitConfiguration() {
|
||||||
|
|
|
@ -4,16 +4,19 @@
|
||||||
|
|
||||||
// Foreign event
|
// Foreign event
|
||||||
wxDECLARE_EVENT(CLOSE_TAB_EVENT, wxCommandEvent);
|
wxDECLARE_EVENT(CLOSE_TAB_EVENT, wxCommandEvent);
|
||||||
|
wxDECLARE_EVENT(REFRESH_ENGINE_LIST, wxCommandEvent);
|
||||||
|
|
||||||
class EngineTab : public EngineTabBF, public TabInfos {
|
class EngineTab : public EngineTabBF, public TabInfos {
|
||||||
uciadapter::UCI *engine;
|
uciadapter::UCI *engine;
|
||||||
std::string confGroup, enginePath;
|
std::string confGroup, enginePath;
|
||||||
std::string engineName;
|
std::string engineName;
|
||||||
void InitConfiguration();
|
void InitConfiguration();
|
||||||
|
void LoadConfiguration();
|
||||||
|
void RefreshItemList();
|
||||||
public:
|
public:
|
||||||
EngineTab(wxWindow *parent, uciadapter::UCI *engine,
|
EngineTab(wxWindow *parent, uciadapter::UCI *engine,
|
||||||
std::string engine_path_or_name);
|
std::string engine_path_or_name);
|
||||||
|
EngineTab(wxWindow *parent, std::string name);
|
||||||
void ApplyPreferences() {}
|
void ApplyPreferences() {}
|
||||||
void *GetGame() { return (NULL); }
|
void *GetGame() { return (NULL); }
|
||||||
void *GetBase() { return (NULL); }
|
void *GetBase() { return (NULL); }
|
||||||
|
|
Loading…
Add table
Reference in a new issue