2022-02-23 18:11:55 +01:00
|
|
|
#include "EditorPanel.hpp"
|
2022-02-27 16:29:14 +01:00
|
|
|
#include "LiveEngineDialog.hpp"
|
2022-02-23 18:11:55 +01:00
|
|
|
|
|
|
|
wxDEFINE_EVENT(GOTO_MOVE_EVENT, wxCommandEvent);
|
|
|
|
wxDEFINE_EVENT(DELETE_MOVE_EVENT, wxCommandEvent);
|
|
|
|
wxDEFINE_EVENT(PROMOTE_MOVE_EVENT, wxCommandEvent);
|
|
|
|
wxDEFINE_EVENT(SET_AS_MAINLINE_EVENT, wxCommandEvent);
|
|
|
|
wxDEFINE_EVENT(PREVIOUS_MOVE_EVENT, wxCommandEvent);
|
|
|
|
wxDEFINE_EVENT(NEXT_MOVE_EVENT, wxCommandEvent);
|
|
|
|
|
|
|
|
EditorPanel::EditorPanel(wxFrame *parent, Game *game)
|
2022-02-26 15:37:03 +01:00
|
|
|
: EditorPanelBF(parent), game(game), selected_item(-1) {
|
|
|
|
editor_canvas = new EditorCanvas((wxFrame *)editor_page);
|
|
|
|
editor_canvas_sizer->Add(editor_canvas, 1, wxEXPAND);
|
2022-02-23 18:47:18 +01:00
|
|
|
tags_list->InsertColumn(0, L"Name", wxLIST_FORMAT_LEFT, 200);
|
2022-02-23 18:11:55 +01:00
|
|
|
tags_list->InsertColumn(1, L"Value", wxLIST_FORMAT_LEFT, 500);
|
2022-02-26 15:37:03 +01:00
|
|
|
tagTextCtrl->SetHint("Tag");
|
|
|
|
valueTextCtrl->SetHint("Value");
|
2022-02-26 20:34:42 +01:00
|
|
|
|
2022-02-27 18:32:57 +01:00
|
|
|
/*LiveEngineDialog *diag=new LiveEngineDialog(this, "Stockfish");
|
|
|
|
diag->SetFEN("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
|
|
|
|
|
|
|
|
diag->Show();*/
|
2022-02-23 18:11:55 +01:00
|
|
|
RefreshTagsList();
|
|
|
|
|
|
|
|
// Bind events
|
|
|
|
this->Bind(wxEVT_TEXT, &EditorPanel::OnCommentChange, this,
|
|
|
|
COMMENT_INPUT_BOX);
|
|
|
|
this->Bind(GOTO_MOVE_EVENT, &EditorPanel::OnGotoMove, this, wxID_ANY);
|
|
|
|
this->Bind(DELETE_MOVE_EVENT, &EditorPanel::OnMoveDelete, this, wxID_ANY);
|
|
|
|
this->Bind(PROMOTE_MOVE_EVENT, &EditorPanel::OnMovePromote, this, wxID_ANY);
|
|
|
|
this->Bind(SET_AS_MAINLINE_EVENT, &EditorPanel::OnMoveSetAsMainline, this,
|
|
|
|
wxID_ANY);
|
|
|
|
this->Bind(NEXT_MOVE_EVENT, &EditorPanel::OnNextMove, this, wxID_ANY);
|
|
|
|
this->Bind(PREVIOUS_MOVE_EVENT, &EditorPanel::OnPreviousMove, this, wxID_ANY);
|
|
|
|
this->Bind(wxEVT_LIST_ITEM_SELECTED, &EditorPanel::OnTagSelected, this,
|
|
|
|
wxID_ANY);
|
|
|
|
this->Bind(wxEVT_LIST_ITEM_DESELECTED, &EditorPanel::OnTagDeselected, this,
|
|
|
|
wxID_ANY);
|
|
|
|
this->Bind(wxEVT_BUTTON, &EditorPanel::OnApply, this, UPDATE_BTN);
|
|
|
|
this->Bind(wxEVT_BUTTON, &EditorPanel::OnDelete, this, DELETE_BTN);
|
2022-02-27 19:55:30 +01:00
|
|
|
this->Bind(wxEVT_BUTTON, &EditorPanel::OnLiveAnalysis, this,
|
|
|
|
LIVE_ANALYSIS_GAME_BUTTON);
|
|
|
|
|
2022-02-26 21:59:41 +01:00
|
|
|
ApplyPreferences();
|
2022-02-23 18:11:55 +01:00
|
|
|
}
|
|
|
|
|
2022-02-27 19:55:30 +01:00
|
|
|
void EditorPanel::OnLiveAnalysis(wxCommandEvent &event) {
|
|
|
|
int selection = engine_list->GetSelection();
|
|
|
|
if (selection != wxNOT_FOUND) {
|
|
|
|
LiveEngineDialog *diag = new LiveEngineDialog(this, engine_list->GetString(selection).ToStdString());
|
|
|
|
diag->SetFEN("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
|
|
|
|
diag->Show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-23 18:11:55 +01:00
|
|
|
void EditorPanel::OnTagSelected(wxListEvent &event) {
|
|
|
|
wxListItem item = event.GetItem();
|
|
|
|
std::string key = item.GetText().ToStdString();
|
|
|
|
tagTextCtrl->ChangeValue(key);
|
|
|
|
item.SetColumn(1);
|
|
|
|
tags_list->GetItem(item);
|
|
|
|
valueTextCtrl->ChangeValue(item.GetText().ToStdString());
|
|
|
|
selected_item = item.GetId();
|
|
|
|
delete_button->Enable(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorPanel::OnTagDeselected(wxListEvent &event) {
|
|
|
|
selected_item = -1;
|
|
|
|
delete_button->Enable(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorPanel::NotifyBoard() {
|
|
|
|
wxCommandEvent previousEvent(GAME_CHANGE, GetId());
|
|
|
|
previousEvent.SetEventObject(this);
|
|
|
|
ProcessEvent(previousEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorPanel::OnCommentChange(wxCommandEvent &event) {
|
|
|
|
wxLogDebug("EditorPanel: comment input change");
|
|
|
|
HalfMove *m = game->GetCurrentMove();
|
|
|
|
if (m != NULL) {
|
|
|
|
m->SetComment(event.GetString().ToStdString());
|
|
|
|
}
|
|
|
|
editor_canvas->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorPanel::OnApply(wxCommandEvent &event) {
|
|
|
|
std::string key = tagTextCtrl->GetValue().ToStdString();
|
|
|
|
if (key == "FEN") {
|
|
|
|
SHOW_DIALOG_ERROR("Editing the FEN tag is forbidden");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (key.size() > 0) {
|
|
|
|
std::string value = valueTextCtrl->GetValue().ToStdString();
|
|
|
|
game->SetTag(key, value);
|
|
|
|
RefreshTagsList();
|
|
|
|
wxCommandEvent event(REFRESH_TAB_TITLE, GetId());
|
|
|
|
event.SetEventObject(this);
|
|
|
|
ProcessEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorPanel::OnDelete(wxCommandEvent &event) {
|
|
|
|
if (selected_item >= 0) {
|
|
|
|
wxListItem item;
|
|
|
|
item.SetColumn(0);
|
|
|
|
item.SetId(selected_item);
|
|
|
|
tags_list->GetItem(item);
|
|
|
|
std::string key = item.GetText().ToStdString();
|
|
|
|
if (key != "FEN") {
|
|
|
|
game->DeleteTag(key);
|
|
|
|
selected_item = -1;
|
|
|
|
RefreshTagsList();
|
|
|
|
} else {
|
|
|
|
SHOW_DIALOG_ERROR("Deleting the FEN tag is forbidden.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorPanel::OnGotoMove(wxCommandEvent &event) {
|
|
|
|
wxLogDebug("EditorPanel: received GOTO_MOVE_EVENT");
|
|
|
|
game->SetCurrent((HalfMove *)event.GetClientData());
|
|
|
|
NotifyBoard();
|
|
|
|
editor_canvas->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorPanel::OnMoveDelete(wxCommandEvent &event) {
|
|
|
|
game->DeleteMove((HalfMove *)event.GetClientData());
|
|
|
|
NotifyBoard();
|
|
|
|
editor_canvas->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorPanel::OnMovePromote(wxCommandEvent &event) {
|
|
|
|
wxLogDebug("EditorPanel: promote move called");
|
|
|
|
game->PromoteMove((HalfMove *)event.GetClientData());
|
|
|
|
NotifyBoard();
|
|
|
|
editor_canvas->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorPanel::OnMoveSetAsMainline(wxCommandEvent &event) {
|
|
|
|
wxLogDebug("EditorPanel: set move as mainline called");
|
|
|
|
game->SetMoveAsMainline((HalfMove *)event.GetClientData());
|
|
|
|
NotifyBoard();
|
|
|
|
editor_canvas->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorPanel::Notify() {
|
|
|
|
HalfMove *m = game->GetCurrentMove();
|
|
|
|
if (m != NULL) {
|
|
|
|
comment_input->ChangeValue(
|
|
|
|
m->GetComment()); // ChangeValue do not raise events
|
|
|
|
}
|
|
|
|
editor_canvas->SetMoves(game->GetMoves(), m);
|
|
|
|
}
|
|
|
|
|
2022-02-26 21:59:41 +01:00
|
|
|
void EditorPanel::ApplyPreferences() {
|
|
|
|
engine_list->Clear();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-02-23 18:11:55 +01:00
|
|
|
void EditorPanel::RefreshTagsList() {
|
|
|
|
tags_list->DeleteAllItems();
|
|
|
|
for (std::string s : game->ListTags()) {
|
|
|
|
long index = tags_list->InsertItem(0, s);
|
|
|
|
tags_list->SetItem(index, 1, game->GetTag(s));
|
|
|
|
if (s == "FEN") {
|
|
|
|
tags_list->SetItemBackgroundColour(index, wxColour(200, 200, 200));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorPanel::OnPreviousMove(wxCommandEvent &event) {
|
|
|
|
game->Previous();
|
|
|
|
Notify();
|
|
|
|
NotifyBoard();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorPanel::OnNextMove(wxCommandEvent &event) {
|
|
|
|
game->Next();
|
|
|
|
Notify();
|
|
|
|
NotifyBoard();
|
|
|
|
}
|