aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-02-26 20:34:42 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-02-26 20:34:42 +0100
commite601902dd5a9f023594fef6a0f4995e59b4d9a0e (patch)
tree4ed1fdbaa9503a2dcfbc701377d9f5d2309858c3 /src
parentca6c1b1e75e771e3bea596367e502b77dea2c3aa (diff)
Improve engine managemen
Diffstat (limited to 'src')
-rw-r--r--src/MainWindow.cpp15
-rw-r--r--src/MainWindow.hpp2
-rw-r--r--src/engine_tab/EngineTab.cpp40
-rw-r--r--src/engine_tab/EngineTab.hpp6
-rw-r--r--src/engine_tab/EngineTabBF.cpp3
-rw-r--r--src/engine_tab/EngineTabBF.h2
-rw-r--r--src/game_tab/editor/EditorPanel.cpp11
-rw-r--r--src/game_tab/editor/EditorPanelBF.cpp2
-rw-r--r--src/game_tab/editor/EditorPanelBF.h3
9 files changed, 70 insertions, 14 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;