Merge pull request #3309 from MarianoGnu/bug_fixing3

Make SpriteRegionEditor remember state when switching scenes (fixes #3245)
This commit is contained in:
Rémi Verschelde 2016-01-11 11:28:03 +01:00
commit 7055d38c30
2 changed files with 58 additions and 7 deletions

View file

@ -411,6 +411,7 @@ SpriteRegionEditor::SpriteRegionEditor(EditorNode* p_editor)
snap_step=Vector2(10,10);
use_snap=false;
snap_show_grid=false;
drag=false;
add_child( memnew( VSeparator ));
edit_node = memnew( ToolButton );
@ -449,7 +450,7 @@ SpriteRegionEditor::SpriteRegionEditor(EditorNode* p_editor)
hb_tools->add_child( memnew( VSeparator ));
hb_tools->add_child( memnew( Label("Grid Offset:") ) );
SpinBox *sb_off_x = memnew( SpinBox );
sb_off_x = memnew( SpinBox );
sb_off_x->set_min(-256);
sb_off_x->set_max(256);
sb_off_x->set_step(1);
@ -458,7 +459,7 @@ SpriteRegionEditor::SpriteRegionEditor(EditorNode* p_editor)
sb_off_x->connect("value_changed", this, "_set_snap_off_x");
hb_tools->add_child(sb_off_x);
SpinBox *sb_off_y = memnew( SpinBox );
sb_off_y = memnew( SpinBox );
sb_off_y->set_min(-256);
sb_off_y->set_max(256);
sb_off_y->set_step(1);
@ -470,7 +471,7 @@ SpriteRegionEditor::SpriteRegionEditor(EditorNode* p_editor)
hb_tools->add_child( memnew( VSeparator ));
hb_tools->add_child( memnew( Label("Grid Step:") ) );
SpinBox *sb_step_x = memnew( SpinBox );
sb_step_x = memnew( SpinBox );
sb_step_x->set_min(-256);
sb_step_x->set_max(256);
sb_step_x->set_step(1);
@ -479,7 +480,7 @@ SpriteRegionEditor::SpriteRegionEditor(EditorNode* p_editor)
sb_step_x->connect("value_changed", this, "_set_snap_step_x");
hb_tools->add_child(sb_step_x);
SpinBox *sb_step_y = memnew( SpinBox );
sb_step_y = memnew( SpinBox );
sb_step_y->set_min(-256);
sb_step_y->set_max(256);
sb_step_y->set_step(1);
@ -488,8 +489,6 @@ SpriteRegionEditor::SpriteRegionEditor(EditorNode* p_editor)
sb_step_y->connect("value_changed", this, "_set_snap_step_y");
hb_tools->add_child(sb_step_y);
// MARIANOGNU::TODO: Add more tools?
HBoxContainer *main_hb = memnew( HBoxContainer );
main_vb->add_child(main_hb);
edit_draw = memnew( Control );
@ -554,6 +553,50 @@ void SpriteRegionEditorPlugin::make_visible(bool p_visible)
}
}
Dictionary SpriteRegionEditorPlugin::get_state() const {
Dictionary state;
state["zoom"]=region_editor->zoom->get_val();
state["snap_offset"]=region_editor->snap_offset;
state["snap_step"]=region_editor->snap_step;
state["use_snap"]=region_editor->use_snap;
state["snap_show_grid"]=region_editor->snap_show_grid;
return state;
}
void SpriteRegionEditorPlugin::set_state(const Dictionary& p_state){
Dictionary state=p_state;
if (state.has("zoom")) {
region_editor->zoom->set_val(p_state["zoom"]);
}
if (state.has("snap_step")) {
Vector2 s = state["snap_step"];
region_editor->sb_step_x->set_val(s.x);
region_editor->sb_step_y->set_val(s.y);
region_editor->snap_step = s;
}
if (state.has("snap_offset")) {
Vector2 ofs = state["snap_offset"];
region_editor->sb_off_x->set_val(ofs.x);
region_editor->sb_off_y->set_val(ofs.y);
region_editor->snap_offset = ofs;
}
if (state.has("use_snap")) {
region_editor->use_snap=state["use_snap"];
region_editor->b_snap_enable->set_pressed(state["use_snap"]);
}
if (state.has("snap_show_grid")) {
region_editor->snap_show_grid=state["snap_show_grid"];
region_editor->b_snap_grid->set_pressed(state["snap_show_grid"]);
}
}
SpriteRegionEditorPlugin::SpriteRegionEditorPlugin(EditorNode *p_node)
{
editor = p_node;

View file

@ -41,6 +41,8 @@ class SpriteRegionEditor : public HBoxContainer {
OBJ_TYPE(SpriteRegionEditor, HBoxContainer );
friend class SpriteRegionEditorPlugin;
ToolButton *edit_node;
// Button *use_region;
ToolButton *b_snap_enable;
@ -48,6 +50,10 @@ class SpriteRegionEditor : public HBoxContainer {
TextureFrame *icon_zoom;
HSlider *zoom;
SpinBox *zoom_value;
SpinBox *sb_step_y;
SpinBox *sb_step_x;
SpinBox *sb_off_y;
SpinBox *sb_off_x;
Control *edit_draw;
VScrollBar *vscroll;
@ -113,11 +119,13 @@ class SpriteRegionEditorPlugin : public EditorPlugin
EditorNode *editor;
public:
virtual String get_name() const { return "Sprite"; }
virtual String get_name() const { return "SpriteRegion"; }
bool has_main_screen() const { return false; }
virtual void edit(Object *p_node);
virtual bool handles(Object *p_node) const;
virtual void make_visible(bool p_visible);
void set_state(const Dictionary &p_state);
Dictionary get_state() const;
SpriteRegionEditorPlugin(EditorNode *p_node);
};