Skip to content

Commit

Permalink
Small improvements to the new Sprite Sheet dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
YeldhamDev committed Apr 21, 2019
1 parent bc71784 commit aa7d10b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 41 deletions.
110 changes: 69 additions & 41 deletions editor/plugins/sprite_frames_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ void SpriteFramesEditor::_sheet_preview_draw() {

if (frames_selected.size() == 0) {
split_sheet_dialog->get_ok()->set_disabled(true);
split_sheet_dialog->get_ok()->set_text(TTR("No frames selected"));
split_sheet_dialog->get_ok()->set_text(TTR("No Frames Selected"));
} else {
split_sheet_dialog->get_ok()->set_disabled(false);
split_sheet_dialog->get_ok()->set_text(vformat(TTR("Add %d frame(s)"), frames_selected.size()));
split_sheet_dialog->get_ok()->set_text(vformat(TTR("Add %d Frame(s)"), frames_selected.size()));
}
}
void SpriteFramesEditor::_sheet_preview_input(const Ref<InputEvent> &p_event) {
Expand Down Expand Up @@ -168,7 +168,24 @@ void SpriteFramesEditor::_sheet_add_frames() {
undo_redo->commit_action();
}

void SpriteFramesEditor::_sheet_select_clear_all_frames() {

bool should_clear = true;
for (int i = 0; i < split_sheet_h->get_value() * split_sheet_v->get_value(); i++) {
if (!frames_selected.has(i)) {
frames_selected.insert(i);
should_clear = false;
}
}
if (should_clear) {
frames_selected.clear();
}

split_sheet_preview->update();
}

void SpriteFramesEditor::_sheet_spin_changed(double) {

frames_selected.clear();
last_frame_selected = -1;
split_sheet_preview->update();
Expand All @@ -195,22 +212,26 @@ void SpriteFramesEditor::_prepare_sprite_sheet(const String &p_file) {

void SpriteFramesEditor::_notification(int p_what) {

if (p_what == NOTIFICATION_ENTER_TREE) {

load->set_icon(get_icon("Load", "EditorIcons"));
load_sheet->set_icon(get_icon("SpriteSheet", "EditorIcons"));
copy->set_icon(get_icon("ActionCopy", "EditorIcons"));
paste->set_icon(get_icon("ActionPaste", "EditorIcons"));
empty->set_icon(get_icon("InsertBefore", "EditorIcons"));
empty2->set_icon(get_icon("InsertAfter", "EditorIcons"));
move_up->set_icon(get_icon("MoveLeft", "EditorIcons"));
move_down->set_icon(get_icon("MoveRight", "EditorIcons"));
_delete->set_icon(get_icon("Remove", "EditorIcons"));
new_anim->set_icon(get_icon("New", "EditorIcons"));
remove_anim->set_icon(get_icon("Remove", "EditorIcons"));
} else if (p_what == NOTIFICATION_READY) {

add_constant_override("autohide", 1); // Fixes the dragger always showing up.
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
load->set_icon(get_icon("Load", "EditorIcons"));
load_sheet->set_icon(get_icon("SpriteSheet", "EditorIcons"));
copy->set_icon(get_icon("ActionCopy", "EditorIcons"));
paste->set_icon(get_icon("ActionPaste", "EditorIcons"));
empty->set_icon(get_icon("InsertBefore", "EditorIcons"));
empty2->set_icon(get_icon("InsertAfter", "EditorIcons"));
move_up->set_icon(get_icon("MoveLeft", "EditorIcons"));
move_down->set_icon(get_icon("MoveRight", "EditorIcons"));
_delete->set_icon(get_icon("Remove", "EditorIcons"));
new_anim->set_icon(get_icon("New", "EditorIcons"));
remove_anim->set_icon(get_icon("Remove", "EditorIcons"));
} // Fallthrough.
case NOTIFICATION_THEME_CHANGED: {
splite_sheet_scroll->add_style_override("bg", get_stylebox("bg", "Tree"));
} break;
case NOTIFICATION_READY: {
add_constant_override("autohide", 1); // Fixes the dragger always showing up.
} break;
}
}

Expand Down Expand Up @@ -818,6 +839,7 @@ void SpriteFramesEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_sheet_preview_input"), &SpriteFramesEditor::_sheet_preview_input);
ClassDB::bind_method(D_METHOD("_sheet_spin_changed"), &SpriteFramesEditor::_sheet_spin_changed);
ClassDB::bind_method(D_METHOD("_sheet_add_frames"), &SpriteFramesEditor::_sheet_add_frames);
ClassDB::bind_method(D_METHOD("_sheet_select_clear_all_frames"), &SpriteFramesEditor::_sheet_select_clear_all_frames);
}

SpriteFramesEditor::SpriteFramesEditor() {
Expand Down Expand Up @@ -879,7 +901,7 @@ SpriteFramesEditor::SpriteFramesEditor() {
hbc->add_child(load);

load_sheet = memnew(ToolButton);
load_sheet->set_tooltip(TTR("Add frames from a Sprite Sheet"));
load_sheet->set_tooltip(TTR("Add Frames from a Sprite Sheet"));
hbc->add_child(load_sheet);

hbc->add_child(memnew(VSeparator));
Expand Down Expand Up @@ -960,33 +982,15 @@ SpriteFramesEditor::SpriteFramesEditor() {
split_sheet_dialog->set_title(TTR("Select Frames"));
split_sheet_dialog->connect("confirmed", this, "_sheet_add_frames");

ScrollContainer *scroll = memnew(ScrollContainer);
split_sheet_preview = memnew(TextureRect);
split_sheet_preview->set_expand(false);
split_sheet_preview->set_mouse_filter(MOUSE_FILTER_PASS);
split_sheet_preview->connect("draw", this, "_sheet_preview_draw");
split_sheet_preview->connect("gui_input", this, "_sheet_preview_input");

scroll->set_enable_h_scroll(true);
scroll->set_enable_v_scroll(true);
CenterContainer *cc = memnew(CenterContainer);
cc->add_child(split_sheet_preview);
cc->set_h_size_flags(SIZE_EXPAND_FILL);
cc->set_v_size_flags(SIZE_EXPAND_FILL);
scroll->add_child(cc);

split_sheet_vb->add_margin_child(TTR("Base Image:"), scroll, true);

HBoxContainer *split_sheet_hb = memnew(HBoxContainer);
split_sheet_hb->add_spacer();

Label *ss_label = memnew(Label(TTR("Horizontal:")));
split_sheet_hb->add_child(ss_label);
split_sheet_h = memnew(SpinBox);
split_sheet_h->set_min(1);
split_sheet_h->set_max(128);
split_sheet_h->set_step(1);
split_sheet_hb->add_child(split_sheet_h);
split_sheet_hb->add_spacer();
split_sheet_h->connect("value_changed", this, "_sheet_spin_changed");

ss_label = memnew(Label(TTR("Vertical:")));
Expand All @@ -996,13 +1000,37 @@ SpriteFramesEditor::SpriteFramesEditor() {
split_sheet_v->set_max(128);
split_sheet_v->set_step(1);
split_sheet_hb->add_child(split_sheet_v);
split_sheet_hb->add_spacer();
split_sheet_v->connect("value_changed", this, "_sheet_spin_changed");

split_sheet_vb->add_margin_child(TTR("Split Settings:"), split_sheet_hb);
split_sheet_hb->add_spacer();

Button *select_clear_all = memnew(Button);
select_clear_all->set_text(TTR("Select/Clear All Frames"));
select_clear_all->connect("pressed", this, "_sheet_select_clear_all_frames");
split_sheet_hb->add_child(select_clear_all);

split_sheet_vb->add_child(split_sheet_hb);

split_sheet_preview = memnew(TextureRect);
split_sheet_preview->set_expand(false);
split_sheet_preview->set_mouse_filter(MOUSE_FILTER_PASS);
split_sheet_preview->connect("draw", this, "_sheet_preview_draw");
split_sheet_preview->connect("gui_input", this, "_sheet_preview_input");

splite_sheet_scroll = memnew(ScrollContainer);
splite_sheet_scroll->set_enable_h_scroll(true);
splite_sheet_scroll->set_enable_v_scroll(true);
splite_sheet_scroll->set_v_size_flags(SIZE_EXPAND_FILL);
CenterContainer *cc = memnew(CenterContainer);
cc->add_child(split_sheet_preview);
cc->set_h_size_flags(SIZE_EXPAND_FILL);
cc->set_v_size_flags(SIZE_EXPAND_FILL);
splite_sheet_scroll->add_child(cc);

split_sheet_vb->add_child(splite_sheet_scroll);

file_split_sheet = memnew(EditorFileDialog);
file_split_sheet->set_title(TTR("Create frames from Sprite Sheet"));
file_split_sheet->set_title(TTR("Create Frames from Sprite Sheet"));
file_split_sheet->set_mode(EditorFileDialog::MODE_OPEN_FILE);
add_child(file_split_sheet);
file_split_sheet->connect("file_selected", this, "_prepare_sprite_sheet");
Expand Down
2 changes: 2 additions & 0 deletions editor/plugins/sprite_frames_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class SpriteFramesEditor : public HSplitContainer {
StringName edited_anim;

ConfirmationDialog *split_sheet_dialog;
ScrollContainer *splite_sheet_scroll;
TextureRect *split_sheet_preview;
SpinBox *split_sheet_h;
SpinBox *split_sheet_v;
Expand Down Expand Up @@ -115,6 +116,7 @@ class SpriteFramesEditor : public HSplitContainer {
void _sheet_spin_changed(double);
void _sheet_preview_input(const Ref<InputEvent> &p_event);
void _sheet_add_frames();
void _sheet_select_clear_all_frames();

protected:
void _notification(int p_what);
Expand Down

0 comments on commit aa7d10b

Please sign in to comment.