mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-07-03 02:37:39 +00:00
Improve engine managemen
This commit is contained in:
parent
ca6c1b1e75
commit
e601902dd5
11 changed files with 146 additions and 16 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
};
|
|
@ -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();
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue