Commit 3a39e1c0 authored by Thibault Soucarre's avatar Thibault Soucarre

cancel available but colors are not reset in settings menu

parent 26cbafc0
......@@ -71,7 +71,7 @@
using namespace std;
Settings_window::Settings_window(Core *c, QWidget *parent) : QWidget(parent), _c(c) {
Settings_window::Settings_window(Core *c, QWidget *parent) : QWidget(parent), _c(c), _reload(false) {
setupUi(this);
plugin_load_dirs_name();
......@@ -207,7 +207,9 @@ void Settings_window::color_changed(string name, QTableWidget *table, const QCol
S.add_state_to_palette(name, palette_name, state_name, color, checked );
p->add_state(state_name, color, checked );
_c->change_entity_color(state_name, color.get_red(), color.get_green(), color.get_blue());
//_c->change_entity_color(state_name, color.get_red(), color.get_green(), color.get_blue());
std::pair<std::string, Color> change(state_name, color);
_states_changes.insert(change);
return;
}
......@@ -427,7 +429,9 @@ void Settings_window::on_reload_states_btn_clicked(){
add_table_line(states_table, SLOT(state_color_changed(const QColor &)),
row, (*it).first.c_str(), (*it).second, true);
}
_c->reload_states();
//_c->reload_states();
_reload = true;
_states_changes.clear();
}
......@@ -666,6 +670,17 @@ void Settings_window::on_apply_clicked() {
}
// emit changes. For now it is a global emit. Maybe only emits signals for what has changed using booleans?
if(_reload)
_c->reload_states();
_reload = false;
std::map<std::string, Color>::iterator it = _states_changes.begin();
Color color;
while(it != _states_changes.end()){
color = it->second;
_c->change_entity_color(it->first, color.get_red(), color.get_green(), color.get_blue());
it++;
}
_states_changes.clear();
emit settings_changed(); // Catch by at least the interface_graphic which will dispatch it to the classes which needs
//hide();
}
......@@ -676,6 +691,8 @@ void Settings_window::on_use_palette_cb_stateChanged(){
}
void Settings_window::on_cancel_clicked() {
_states_changes.clear();
_reload = false;
hide();
}
......
......@@ -67,7 +67,8 @@ class Settings_window : public QWidget, protected Ui::settings {
private:
Core *_c;
std::map<std::string, Color> _states_changes;
bool _reload;
//used to check if leaving the tab needs an apply first when OK button is pressed
bool _changed;
......
......@@ -947,25 +947,21 @@ void Render_alternate::clear_text (){
}
void Render_alternate::change_color(std::string entity, Element_col r, Element_col g, Element_col b){
std::cout << "changement shader" << std::endl;
std::map<EntityValue*, Shader*>::iterator it;
it = _states_shaders.begin();
while(it != _states_shaders.end()){
std::cout << "salut" << std::endl;
//std::cout << it->first->get_name().get_name() << std::endl;
//assert(it->first); // TODO: check why busy state exists and uncomment this assert
if(it->first && (it->first->get_name() == entity)){
Color *c = new Color(r, g, b);
it->first->set_used_color(c);
std::cout << "rentré dans le if" << std::endl;
Shader* s = it->second;
delete s;
s = new Shader(_glsl, r, g, b);
s->charger();
break;
}
std::cout << "iteration" << std::endl;
it++;
}
}
......@@ -974,13 +970,15 @@ void Render_alternate::reload_states(){
std::map<EntityValue*, Shader*>::iterator it;
it = _states_shaders.begin();
while(it != _states_shaders.end()){
it->first->reload_file_color();
Shader* s = it->second;
delete s;
s = new Shader(_glsl, it->first->get_used_color()->get_red(),
it->first->get_used_color()->get_green(),
it->first->get_used_color()->get_blue());
s->charger();
if(it->first){
it->first->reload_file_color();
Shader* s = it->second;
delete s;
s = new Shader(_glsl, it->first->get_used_color()->get_red(),
it->first->get_used_color()->get_green(),
it->first->get_used_color()->get_blue());
s->charger();
}
it++;
}
}
......@@ -114,13 +114,13 @@ const Color* EntityValue::get_used_color() const{
}
void EntityValue::set_used_color(Color *c){
if(_usedcolor!=_filecolor)
if(_usedcolor!=_filecolor && _usedcolor!=NULL)
delete _usedcolor;
_usedcolor = c;
}
void EntityValue::reload_file_color(){
if(_usedcolor!=_filecolor)
if(_usedcolor!=_filecolor && _usedcolor!=NULL)
delete _usedcolor;
_usedcolor = _filecolor;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment