mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Improve the binding between LiveEngineDialog and BoardCanvas
This commit is contained in:
parent
93c7cb3d24
commit
d2f078adb5
6 changed files with 45 additions and 27 deletions
2
TODO.md
2
TODO.md
|
@ -10,7 +10,7 @@
|
||||||
- [ ] Make PGNGameBase use GotoNextGame() instead of ParseNextGame() in the NextGame() method to improve performance
|
- [ ] Make PGNGameBase use GotoNextGame() instead of ParseNextGame() in the NextGame() method to improve performance
|
||||||
- [x] Clean and debug DragNDrop in BoardCanvas
|
- [x] Clean and debug DragNDrop in BoardCanvas
|
||||||
- [ ] Disable the "Analyze entire game" button (Not Yet Implemented)
|
- [ ] Disable the "Analyze entire game" button (Not Yet Implemented)
|
||||||
- [ ] Keep engine evaluation bar visible (and best move arrows) as long as the live engine dialog is open
|
- [x] Keep engine evaluation bar visible (and best move arrows) as long as the live engine dialog is open
|
||||||
|
|
||||||
## Additional Features
|
## Additional Features
|
||||||
- [x] Add a live evaluation bar to the BoardCanvas
|
- [x] Add a live evaluation bar to the BoardCanvas
|
||||||
|
|
|
@ -33,6 +33,9 @@ GameTab::GameTab(wxFrame *parent, std::shared_ptr<Game> game)
|
||||||
p->board_panel->SetEngineEvaluation(*eval);
|
p->board_panel->SetEngineEvaluation(*eval);
|
||||||
free(eval);
|
free(eval);
|
||||||
});
|
});
|
||||||
|
Bind(LIVE_ANALYSIS_STATUS, [p=this](wxCommandEvent &event){
|
||||||
|
p->board_panel->SetLiveEngineState((bool)event.GetInt());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameTab::OnToolClick(wxCommandEvent &event){
|
void GameTab::OnToolClick(wxCommandEvent &event){
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include <wx/clipbrd.h>
|
#include <wx/clipbrd.h>
|
||||||
|
|
||||||
GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game)
|
GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game)
|
||||||
: TabGameLeftPanel(parent), game(game), repeat(false) {
|
: TabGameLeftPanel(parent), game(game), repeat(false), is_engine_on(false) {
|
||||||
|
|
||||||
// Configure toolbar (note that toolbar events are processed into the GameTab class)
|
// Configure toolbar (note that toolbar events are processed into the GameTab class)
|
||||||
game_toolbar->AddTool(0, wxT("Save As"),
|
game_toolbar->AddTool(0, wxT("Save As"),
|
||||||
|
@ -86,20 +86,32 @@ void GameTabLeftPanel::OnPlay(wxCommandEvent &event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameTabLeftPanel::SetEngineEvaluation(EngineEvaluation eval){
|
void GameTabLeftPanel::SetEngineEvaluation(EngineEvaluation eval){
|
||||||
engine_arrows.clear();
|
if(is_engine_on){
|
||||||
float scale=1;
|
engine_arrows.clear();
|
||||||
unsigned char color=0;
|
float scale=1;
|
||||||
for(auto const &arrow: eval.best_lines){
|
unsigned char color=0;
|
||||||
std::string src=arrow.substr(0,2);
|
for(auto const &arrow: eval.best_lines){
|
||||||
std::string dst=arrow.substr(2,2);
|
std::string src=arrow.substr(0,2);
|
||||||
engine_arrows.push_back({src,dst,wxColour(color,color,color),scale});
|
std::string dst=arrow.substr(2,2);
|
||||||
scale=std::max(0.1,scale-0.25);
|
engine_arrows.push_back({src,dst,wxColour(color,color,color),scale});
|
||||||
color=std::min(255,color+70);
|
scale=std::max(0.1,scale-0.25);
|
||||||
|
color=std::min(255,color+70);
|
||||||
|
}
|
||||||
|
eval_cp=eval.eval;
|
||||||
|
Notify(true);
|
||||||
}
|
}
|
||||||
eval_cp=eval.eval;
|
|
||||||
Notify(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameTabLeftPanel::SetLiveEngineState(bool isOn){
|
||||||
|
is_engine_on=isOn;
|
||||||
|
if(!is_engine_on){
|
||||||
|
engine_arrows.clear();
|
||||||
|
eval_cp=0;
|
||||||
|
Notify(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void GameTabLeftPanel::Notify(bool skip_animation) {
|
void GameTabLeftPanel::Notify(bool skip_animation) {
|
||||||
// Update fen and captures
|
// Update fen and captures
|
||||||
std::string fen = game->GetFen();
|
std::string fen = game->GetFen();
|
||||||
|
@ -138,7 +150,7 @@ void GameTabLeftPanel::Notify(bool skip_animation) {
|
||||||
gs.mat_white=game->IsCheckmate(false);
|
gs.mat_white=game->IsCheckmate(false);
|
||||||
gs.arrows=engine_arrows;
|
gs.arrows=engine_arrows;
|
||||||
gs.promotion=promote_on;
|
gs.promotion=promote_on;
|
||||||
gs.show_evalbar=engine_arrows.size()>0;
|
gs.show_evalbar=is_engine_on;
|
||||||
gs.eval=eval_cp/100;
|
gs.eval=eval_cp/100;
|
||||||
if(m){
|
if(m){
|
||||||
// There should be a valid src_hl or dst_hl ortherwise it explode:
|
// There should be a valid src_hl or dst_hl ortherwise it explode:
|
||||||
|
|
|
@ -18,6 +18,7 @@ class GameTabLeftPanel : public TabGameLeftPanel {
|
||||||
std::string promote_on;
|
std::string promote_on;
|
||||||
std::string promotion_move;
|
std::string promotion_move;
|
||||||
float eval_cp;
|
float eval_cp;
|
||||||
|
bool is_engine_on;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game);
|
GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game);
|
||||||
|
@ -28,4 +29,5 @@ public:
|
||||||
void ApplyPreferences();
|
void ApplyPreferences();
|
||||||
void SetSaveToolEnable(bool state){game_toolbar->EnableTool(0,state);};
|
void SetSaveToolEnable(bool state){game_toolbar->EnableTool(0,state);};
|
||||||
void SetEngineEvaluation(EngineEvaluation eval);
|
void SetEngineEvaluation(EngineEvaluation eval);
|
||||||
|
void SetLiveEngineState(bool isOn);
|
||||||
};
|
};
|
|
@ -1,11 +1,6 @@
|
||||||
#include "GameTabRightPanel.hpp"
|
#include "GameTabRightPanel.hpp"
|
||||||
|
|
||||||
wxDEFINE_EVENT(GOTO_MOVE_EVENT, wxCommandEvent);
|
wxDEFINE_EVENT(LIVE_ANALYSIS_STATUS, 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);
|
|
||||||
|
|
||||||
GameTabRightPanel::GameTabRightPanel(wxFrame *parent, std::shared_ptr<Game> game)
|
GameTabRightPanel::GameTabRightPanel(wxFrame *parent, std::shared_ptr<Game> game)
|
||||||
: TabGameRightPanel(parent), game(game), selected_item(-1),
|
: TabGameRightPanel(parent), game(game), selected_item(-1),
|
||||||
|
@ -53,6 +48,12 @@ void GameTabRightPanel::OnLiveAnalysis(wxCommandEvent &event) {
|
||||||
if (live_engine == nullptr) {
|
if (live_engine == nullptr) {
|
||||||
int selection = engine_list->GetSelection();
|
int selection = engine_list->GetSelection();
|
||||||
if (selection != wxNOT_FOUND) {
|
if (selection != wxNOT_FOUND) {
|
||||||
|
// Notify about the state of the LiveEngine
|
||||||
|
wxCommandEvent notifyEvent(LIVE_ANALYSIS_STATUS,GetId());
|
||||||
|
notifyEvent.SetEventObject(this);
|
||||||
|
notifyEvent.SetInt(1);
|
||||||
|
ProcessEvent(notifyEvent);
|
||||||
|
|
||||||
live_engine = new LiveEngineDialog(
|
live_engine = new LiveEngineDialog(
|
||||||
this, engine_list->GetString(selection).ToStdString());
|
this, engine_list->GetString(selection).ToStdString());
|
||||||
live_engine->SetFEN(game->GetFen());
|
live_engine->SetFEN(game->GetFen());
|
||||||
|
@ -87,6 +88,12 @@ void GameTabRightPanel::OnTagDeselected(wxListEvent &event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameTabRightPanel::OnLiveEngineClose(wxCloseEvent &e) {
|
void GameTabRightPanel::OnLiveEngineClose(wxCloseEvent &e) {
|
||||||
|
// Notify about the state of the LiveEngine
|
||||||
|
wxCommandEvent notifyEvent(LIVE_ANALYSIS_STATUS,GetId());
|
||||||
|
notifyEvent.SetEventObject(this);
|
||||||
|
notifyEvent.SetInt(0);
|
||||||
|
ProcessEvent(notifyEvent);
|
||||||
|
// Refresh pointer
|
||||||
live_engine = nullptr;
|
live_engine = nullptr;
|
||||||
e.Skip();
|
e.Skip();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,16 +7,10 @@
|
||||||
#include <wx/listctrl.h>
|
#include <wx/listctrl.h>
|
||||||
#include <wx/notebook.h>
|
#include <wx/notebook.h>
|
||||||
|
|
||||||
// Local events
|
|
||||||
wxDECLARE_EVENT(GOTO_MOVE_EVENT, wxCommandEvent);
|
|
||||||
wxDECLARE_EVENT(DELETE_MOVE_EVENT, wxCommandEvent);
|
|
||||||
wxDECLARE_EVENT(PROMOTE_MOVE_EVENT, wxCommandEvent);
|
|
||||||
wxDECLARE_EVENT(SET_AS_MAINLINE_EVENT, wxCommandEvent);
|
|
||||||
wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
|
|
||||||
|
|
||||||
// Foreign events
|
// Foreign events
|
||||||
wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent);
|
wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent);
|
||||||
wxDECLARE_EVENT(SHOW_ENGINE_EVALUATION, wxCommandEvent);
|
wxDECLARE_EVENT(SHOW_ENGINE_EVALUATION, wxCommandEvent);
|
||||||
|
wxDECLARE_EVENT(LIVE_ANALYSIS_STATUS, wxCommandEvent);
|
||||||
|
|
||||||
class GameTabRightPanel : public TabGameRightPanel {
|
class GameTabRightPanel : public TabGameRightPanel {
|
||||||
std::shared_ptr<Game> game;
|
std::shared_ptr<Game> game;
|
||||||
|
|
Loading…
Add table
Reference in a new issue