diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2022-02-26 20:34:42 +0100 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2022-02-26 20:34:42 +0100 |
| commit | e601902dd5a9f023594fef6a0f4995e59b4d9a0e (patch) | |
| tree | 4ed1fdbaa9503a2dcfbc701377d9f5d2309858c3 | |
| parent | ca6c1b1e75e771e3bea596367e502b77dea2c3aa (diff) | |
Improve engine managemen
| -rw-r--r-- | src/MainWindow.cpp | 15 | ||||
| -rw-r--r-- | src/MainWindow.hpp | 2 | ||||
| -rw-r--r-- | src/engine_tab/EngineTab.cpp | 40 | ||||
| -rw-r--r-- | src/engine_tab/EngineTab.hpp | 6 | ||||
| -rw-r--r-- | src/engine_tab/EngineTabBF.cpp | 3 | ||||
| -rw-r--r-- | src/engine_tab/EngineTabBF.h | 2 | ||||
| -rw-r--r-- | src/game_tab/editor/EditorPanel.cpp | 11 | ||||
| -rw-r--r-- | src/game_tab/editor/EditorPanelBF.cpp | 2 | ||||
| -rw-r--r-- | src/game_tab/editor/EditorPanelBF.h | 3 | ||||
| -rw-r--r-- | tools/wxframebuilder/EditorPanel.fbp | 5 | ||||
| -rw-r--r-- | tools/wxframebuilder/EngineTab.fbp | 73 |
11 files changed, 146 insertions, 16 deletions
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index efe3f06..348e772 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -7,6 +7,7 @@ wxDEFINE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent); wxDEFINE_EVENT(NEW_GAME_EVENT, wxCommandEvent); +wxDEFINE_EVENT(CLOSE_TAB_EVENT, wxCommandEvent); /// ---------- MainWindow ---------- @@ -64,16 +65,24 @@ MainWindow::MainWindow() Bind(REFRESH_TAB_TITLE, &MainWindow::OnRefreshTabTitle, this, wxID_ANY); Bind(NEW_GAME_EVENT, &MainWindow::OnNewGame, this, wxID_ANY); Bind(wxEVT_CLOSE_WINDOW, &MainWindow::OnClose, this); + Bind(CLOSE_TAB_EVENT, &MainWindow::OnCloseTabEvent, this, wxID_ANY); /*BaseTab *bt = new BaseTab((wxFrame *)notebook, "/home/loic/hartwig_tests.pgn"); notebook->AddPage(bt, bt->GetLabel()); notebook->SetSelection(notebook->GetPageIndex(bt));*/ - - /*EngineTab *bt = new EngineTab((wxWindow *)notebook, - "/home/loic/.local/bin/stockfish"); notebook->AddPage(bt, bt->GetLabel()); +/* + EngineTab *bt = + new EngineTab((wxWindow *)notebook, + new uciadapter::UCI("/home/loic/.local/bin/stockfish"), + "/home/loic/.local/bin/stockfish"); + notebook->AddPage(bt, bt->GetLabel()); notebook->SetSelection(notebook->GetPageIndex(bt));*/ } +void MainWindow::OnCloseTabEvent(wxCommandEvent &event) { + notebook->DeletePage(notebook->GetSelection()); +} + void MainWindow::OnNewEngine(wxCommandEvent &event) { wxFileDialog openFileDialog(this, _("Use engine"), "", "", "Executable|*", wxFD_OPEN | wxFD_FILE_MUST_EXIST); diff --git a/src/MainWindow.hpp b/src/MainWindow.hpp index 918dc8a..4111612 100644 --- a/src/MainWindow.hpp +++ b/src/MainWindow.hpp @@ -10,6 +10,7 @@ wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent); wxDECLARE_EVENT(NEW_GAME_EVENT, wxCommandEvent); +wxDECLARE_EVENT(CLOSE_TAB_EVENT, wxCommandEvent); class MainWindow : public wxFrame { wxAuiNotebook *notebook; @@ -27,6 +28,7 @@ class MainWindow : public wxFrame { void NewGame(Game *game); void OnSettings(wxCommandEvent &event); void OnNewEngine(wxCommandEvent &event); + void OnCloseTabEvent(wxCommandEvent &event); public: MainWindow(); diff --git a/src/engine_tab/EngineTab.cpp b/src/engine_tab/EngineTab.cpp index ae9b447..ca2880f 100644 --- a/src/engine_tab/EngineTab.cpp +++ b/src/engine_tab/EngineTab.cpp @@ -1,20 +1,27 @@ #include "EngineTab.hpp" -EngineTab::EngineTab(wxWindow *parent, uciadapter::UCI *engine,std::string engine_path_or_name) +EngineTab::EngineTab(wxWindow *parent, uciadapter::UCI *engine, + std::string engine_path_or_name) : EngineTabBF(parent), TabInfos(TabInfos::ENGINE), enginePath(engine_path_or_name), engine(engine) { SetLabel("New Engine"); engine_location->SetValue(engine_path_or_name); - confGroup = "engines/bob"; CONFIG_OPEN(conf); - conf->DeleteGroup(confGroup); - bool configExists = conf->HasGroup(confGroup); - conf->Write(confGroup + "/path", wxString(engine_path_or_name)); - CONFIG_CLOSE(conf); - if (!configExists) { - InitConfiguration(); + // conf->DeleteGroup(confGroup); + engineName = "NewEngine"; + confGroup = "engines/" + engineName; + std::uint32_t key = 2; + while (conf->HasGroup(confGroup)) { + engineName = "NewEngine" + std::to_string(key); + confGroup = "engines/" + engineName; + key++; } + engine_name->SetValue(engineName); + + // conf->Write(confGroup + "/path", wxString(engine_path_or_name)); + CONFIG_CLOSE(conf); + InitConfiguration(); // Build wxPropertyGrid according to engine configuration CONFIG_OPEN(conf2); @@ -43,10 +50,27 @@ EngineTab::EngineTab(wxWindow *parent, uciadapter::UCI *engine,std::string engin 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) { CONFIG_OPEN(conf2); + wxString new_engine_name = engine_name->GetValue(); + if (new_engine_name != engineName) { + conf2->RenameGroup(confGroup, "engines/" + new_engine_name); + engineName = new_engine_name; + confGroup = "engines/" + engineName; + } long index; std::string optsPath = confGroup + "/options"; conf2->SetPath(optsPath); diff --git a/src/engine_tab/EngineTab.hpp b/src/engine_tab/EngineTab.hpp index c4e8a52..6e4913b 100644 --- a/src/engine_tab/EngineTab.hpp +++ b/src/engine_tab/EngineTab.hpp @@ -2,10 +2,13 @@ #include "UCI.hpp" #include "ochess.hpp" +// Foreign event +wxDECLARE_EVENT(CLOSE_TAB_EVENT, wxCommandEvent); + class EngineTab : public EngineTabBF, public TabInfos { uciadapter::UCI *engine; std::string confGroup, enginePath; - + std::string engineName; void InitConfiguration(); public: @@ -15,4 +18,5 @@ public: void *GetGame() { return (NULL); } void *GetBase() { return (NULL); } void OnSave(wxCommandEvent &event); + void OnDelete(wxCommandEvent &event); };
\ No newline at end of file diff --git a/src/engine_tab/EngineTabBF.cpp b/src/engine_tab/EngineTabBF.cpp index 0e33939..90ba99d 100644 --- a/src/engine_tab/EngineTabBF.cpp +++ b/src/engine_tab/EngineTabBF.cpp @@ -53,6 +53,9 @@ EngineTabBF::EngineTabBF( wxWindow* parent, wxWindowID id, const wxPoint& pos, c save_button = new wxButton( this, ENGINE_SAVE_CONF_BUTTON, wxT("Save"), wxDefaultPosition, wxDefaultSize, 0 ); main_sizer->Add( save_button, 0, wxALL|wxEXPAND, 5 ); + delete_button = new wxButton( this, ENGINE_DELETE_CONF_BUTTON, wxT("Delete engine"), wxDefaultPosition, wxDefaultSize, 0 ); + main_sizer->Add( delete_button, 0, wxALL|wxEXPAND, 5 ); + this->SetSizer( main_sizer ); this->Layout(); diff --git a/src/engine_tab/EngineTabBF.h b/src/engine_tab/EngineTabBF.h index fc65a03..fe7dae1 100644 --- a/src/engine_tab/EngineTabBF.h +++ b/src/engine_tab/EngineTabBF.h @@ -29,6 +29,7 @@ /////////////////////////////////////////////////////////////////////////// #define ENGINE_SAVE_CONF_BUTTON 1000 +#define ENGINE_DELETE_CONF_BUTTON 1001 /////////////////////////////////////////////////////////////////////////////// /// Class EngineTabBF @@ -46,6 +47,7 @@ class EngineTabBF : public wxPanel wxStaticText* params_label; wxPropertyGrid* engine_parameters; wxButton* save_button; + wxButton* delete_button; public: diff --git a/src/game_tab/editor/EditorPanel.cpp b/src/game_tab/editor/EditorPanel.cpp index 641448e..3e6a7db 100644 --- a/src/game_tab/editor/EditorPanel.cpp +++ b/src/game_tab/editor/EditorPanel.cpp @@ -15,6 +15,17 @@ EditorPanel::EditorPanel(wxFrame *parent, Game *game) tags_list->InsertColumn(1, L"Value", wxLIST_FORMAT_LEFT, 500); tagTextCtrl->SetHint("Tag"); valueTextCtrl->SetHint("Value"); + CONFIG_OPEN(conf); + conf->SetPath("engines/"); + wxString engine_name; + long index; + if (conf->GetFirstGroup(engine_name, index)) { + do { + engine_list->Append(engine_name); + } while (conf->GetNextGroup(engine_name, index)); + } + + CONFIG_CLOSE(conf); RefreshTagsList(); // Bind events diff --git a/src/game_tab/editor/EditorPanelBF.cpp b/src/game_tab/editor/EditorPanelBF.cpp index f74ef64..8aac38e 100644 --- a/src/game_tab/editor/EditorPanelBF.cpp +++ b/src/game_tab/editor/EditorPanelBF.cpp @@ -82,7 +82,7 @@ EditorPanelBF::EditorPanelBF( wxWindow* parent, wxWindowID id, const wxPoint& po engine_list_label->Wrap( -1 ); engine_page_sizer->Add( engine_list_label, 0, wxALL, 5 ); - engine_list = new wxListCtrl( engine_page, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_ICON ); + engine_list = new wxListBox( engine_page, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 ); engine_page_sizer->Add( engine_list, 1, wxALL|wxEXPAND, 5 ); analyze_game_button = new wxButton( engine_page, wxID_ANY, wxT("Analyze game"), wxDefaultPosition, wxDefaultSize, 0 ); diff --git a/src/game_tab/editor/EditorPanelBF.h b/src/game_tab/editor/EditorPanelBF.h index 092d750..c5b38d5 100644 --- a/src/game_tab/editor/EditorPanelBF.h +++ b/src/game_tab/editor/EditorPanelBF.h @@ -24,6 +24,7 @@ #include <wx/icon.h> #include <wx/button.h> #include <wx/listctrl.h> +#include <wx/listbox.h> #include <wx/notebook.h> /////////////////////////////////////////////////////////////////////////// @@ -55,7 +56,7 @@ class EditorPanelBF : public wxPanel wxButton* delete_button; wxPanel* engine_page; wxStaticText* engine_list_label; - wxListCtrl* engine_list; + wxListBox* engine_list; wxButton* analyze_game_button; wxButton* live_analysis_button; diff --git a/tools/wxframebuilder/EditorPanel.fbp b/tools/wxframebuilder/EditorPanel.fbp index 411938e..3960615 100644 --- a/tools/wxframebuilder/EditorPanel.fbp +++ b/tools/wxframebuilder/EditorPanel.fbp @@ -917,7 +917,7 @@ <property name="border">5</property> <property name="flag">wxALL|wxEXPAND</property> <property name="proportion">1</property> - <object class="wxListCtrl" expanded="1"> + <object class="wxListBox" expanded="1"> <property name="BottomDockable">1</property> <property name="LeftDockable">1</property> <property name="RightDockable">1</property> @@ -931,6 +931,7 @@ <property name="caption"></property> <property name="caption_visible">1</property> <property name="center_pane">0</property> + <property name="choices"></property> <property name="close_button">1</property> <property name="context_help"></property> <property name="context_menu">1</property> @@ -962,7 +963,7 @@ <property name="resize">Resizable</property> <property name="show">1</property> <property name="size"></property> - <property name="style">wxLC_ICON</property> + <property name="style"></property> <property name="subclass">; ; forward_declare</property> <property name="toolbar_pane">0</property> <property name="tooltip"></property> diff --git a/tools/wxframebuilder/EngineTab.fbp b/tools/wxframebuilder/EngineTab.fbp index 0ee11d0..b37ff08 100644 --- a/tools/wxframebuilder/EngineTab.fbp +++ b/tools/wxframebuilder/EngineTab.fbp @@ -582,6 +582,79 @@ <property name="window_style"></property> </object> </object> + <object class="sizeritem" expanded="1"> + <property name="border">5</property> + <property name="flag">wxALL|wxEXPAND</property> + <property name="proportion">0</property> + <object class="wxButton" expanded="1"> + <property name="BottomDockable">1</property> + <property name="LeftDockable">1</property> + <property name="RightDockable">1</property> + <property name="TopDockable">1</property> + <property name="aui_layer"></property> + <property name="aui_name"></property> + <property name="aui_position"></property> + <property name="aui_row"></property> + <property name="auth_needed">0</property> + <property name="best_size"></property> + <property name="bg"></property> + <property name="bitmap"></property> + <property name="caption"></property> + <property name="caption_visible">1</property> + <property name="center_pane">0</property> + <property name="close_button">1</property> + <property name="context_help"></property> + <property name="context_menu">1</property> + <property name="current"></property> + <property name="default">0</property> + <property name="default_pane">0</property> + <property name="disabled"></property> + <property name="dock">Dock</property> + <property name="dock_fixed">0</property> + <property name="docking">Left</property> + <property name="enabled">1</property> + <property name="fg"></property> + <property name="floatable">1</property> + <property name="focus"></property> + <property name="font"></property> + <property name="gripper">0</property> + <property name="hidden">0</property> + <property name="id">ENGINE_DELETE_CONF_BUTTON</property> + <property name="label">Delete engine</property> + <property name="margins"></property> + <property name="markup">0</property> + <property name="max_size"></property> + <property name="maximize_button">0</property> + <property name="maximum_size"></property> + <property name="min_size"></property> + <property name="minimize_button">0</property> + <property name="minimum_size"></property> + <property name="moveable">1</property> + <property name="name">delete_button</property> + <property name="pane_border">1</property> + <property name="pane_position"></property> + <property name="pane_size"></property> + <property name="permission">protected</property> + <property name="pin_button">1</property> + <property name="pos"></property> + <property name="position"></property> + <property name="pressed"></property> + <property name="resize">Resizable</property> + <property name="show">1</property> + <property name="size"></property> + <property name="style"></property> + <property name="subclass">; ; forward_declare</property> + <property name="toolbar_pane">0</property> + <property name="tooltip"></property> + <property name="validator_data_type"></property> + <property name="validator_style">wxFILTER_NONE</property> + <property name="validator_type">wxDefaultValidator</property> + <property name="validator_variable"></property> + <property name="window_extra_style"></property> + <property name="window_name"></property> + <property name="window_style"></property> + </object> + </object> </object> </object> </object> |
