Path: blob/master/editor/scene/sprite_frames_editor_plugin.h
9896 views
/**************************************************************************/1/* sprite_frames_editor_plugin.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "editor/plugins/editor_plugin.h"33#include "scene/gui/button.h"34#include "scene/gui/dialogs.h"35#include "scene/gui/item_list.h"36#include "scene/gui/line_edit.h"37#include "scene/gui/scroll_container.h"38#include "scene/gui/spin_box.h"39#include "scene/gui/split_container.h"40#include "scene/gui/texture_rect.h"41#include "scene/gui/tree.h"42#include "scene/resources/image_texture.h"43#include "scene/resources/sprite_frames.h"4445class OptionButton;46class EditorFileDialog;4748class ClipboardSpriteFrames : public Resource {49GDCLASS(ClipboardSpriteFrames, Resource);5051public:52struct Frame {53Ref<Texture2D> texture;54float duration;55};56Vector<Frame> frames;57};5859class SpriteFramesEditor : public HSplitContainer {60GDCLASS(SpriteFramesEditor, HSplitContainer);6162Ref<SpriteFrames> frames;63Node *animated_sprite = nullptr;6465enum {66PARAM_USE_CURRENT, // Used in callbacks to indicate `dominant_param` should be not updated.67PARAM_FRAME_COUNT, // Keep "Horizontal" & "Vertical" values.68PARAM_SIZE, // Keep "Size" values.69};70int dominant_param = PARAM_FRAME_COUNT;7172enum {73FRAME_ORDER_SELECTION, // Order frames were selected in.7475// By Row.76FRAME_ORDER_LEFT_RIGHT_TOP_BOTTOM,77FRAME_ORDER_LEFT_RIGHT_BOTTOM_TOP,78FRAME_ORDER_RIGHT_LEFT_TOP_BOTTOM,79FRAME_ORDER_RIGHT_LEFT_BOTTOM_TOP,8081// By Column.82FRAME_ORDER_TOP_BOTTOM_LEFT_RIGHT,83FRAME_ORDER_TOP_BOTTOM_RIGHT_LEFT,84FRAME_ORDER_BOTTOM_TOP_LEFT_RIGHT,85FRAME_ORDER_BOTTOM_TOP_RIGHT_LEFT,86};8788enum {89MENU_SHOW_IN_FILESYSTEM,90};9192int right_clicked_frame = -1;9394bool read_only = false;9596Ref<Texture2D> autoplay_icon;97Ref<Texture2D> stop_icon;98Ref<Texture2D> pause_icon;99Ref<Texture2D> empty_icon = memnew(ImageTexture);100101HBoxContainer *playback_container = nullptr;102Button *stop = nullptr;103Button *play = nullptr;104Button *play_from = nullptr;105Button *play_bw = nullptr;106Button *play_bw_from = nullptr;107108Button *load = nullptr;109Button *load_sheet = nullptr;110Button *delete_frame = nullptr;111Button *copy = nullptr;112Button *paste = nullptr;113Button *empty_before = nullptr;114Button *empty_after = nullptr;115Button *move_up = nullptr;116Button *move_down = nullptr;117Button *zoom_out = nullptr;118Button *zoom_reset = nullptr;119Button *zoom_in = nullptr;120SpinBox *frame_duration = nullptr;121ItemList *frame_list = nullptr;122bool loading_scene;123Vector<int> selection;124125Button *add_anim = nullptr;126Button *duplicate_anim = nullptr;127Button *delete_anim = nullptr;128SpinBox *anim_speed = nullptr;129Button *anim_loop = nullptr;130131HBoxContainer *autoplay_container = nullptr;132Button *autoplay = nullptr;133134LineEdit *anim_search_box = nullptr;135Tree *animations = nullptr;136137Label *missing_anim_label = nullptr;138VBoxContainer *anim_frames_vb = nullptr;139140EditorFileDialog *file = nullptr;141142AcceptDialog *dialog = nullptr;143144PopupMenu *menu = nullptr;145146StringName edited_anim;147148ConfirmationDialog *delete_dialog = nullptr;149150ConfirmationDialog *split_sheet_dialog = nullptr;151ScrollContainer *split_sheet_scroll = nullptr;152TextureRect *split_sheet_preview = nullptr;153VBoxContainer *split_sheet_settings_vb = nullptr;154SpinBox *split_sheet_h = nullptr;155SpinBox *split_sheet_v = nullptr;156SpinBox *split_sheet_size_x = nullptr;157SpinBox *split_sheet_size_y = nullptr;158SpinBox *split_sheet_sep_x = nullptr;159SpinBox *split_sheet_sep_y = nullptr;160SpinBox *split_sheet_offset_x = nullptr;161SpinBox *split_sheet_offset_y = nullptr;162Button *split_sheet_zoom_out = nullptr;163Button *split_sheet_zoom_reset = nullptr;164Button *split_sheet_zoom_in = nullptr;165Button *toggle_settings_button = nullptr;166OptionButton *split_sheet_order = nullptr;167EditorFileDialog *file_split_sheet = nullptr;168HashMap<int, int> frames_selected; // Key is frame index. Value is selection order.169HashSet<int> frames_toggled_by_mouse_hover;170Vector<Pair<int, int>> frames_ordered; // First is the index to be ordered by. Second is the actual frame index.171int selected_count = 0;172bool frames_need_sort = false;173int last_frame_selected = 0;174175Size2i previous_texture_size;176177float scale_ratio;178int thumbnail_default_size;179float thumbnail_zoom;180float max_thumbnail_zoom;181float min_thumbnail_zoom;182float sheet_zoom;183float max_sheet_zoom;184float min_sheet_zoom;185186Size2i _get_frame_count() const;187Size2i _get_frame_size() const;188Size2i _get_offset() const;189Size2i _get_separation() const;190191void _load_pressed();192void _file_load_request(const Vector<String> &p_path, int p_at_pos = -1);193void _copy_pressed();194void _paste_pressed();195void _paste_frame_array(const Ref<ClipboardSpriteFrames> &p_clipboard_frames);196void _paste_texture(const Ref<Texture2D> &p_texture);197198void _empty_pressed();199void _empty2_pressed();200void _delete_pressed();201void _up_pressed();202void _down_pressed();203void _frame_duration_changed(double p_value);204void _update_library(bool p_skip_selector = false);205void _update_library_impl();206207void _update_stop_icon();208void _play_pressed();209void _play_from_pressed();210void _play_bw_pressed();211void _play_bw_from_pressed();212void _autoplay_pressed();213void _stop_pressed();214215void _animation_selected();216void _animation_name_edited();217void _animation_add();218void _animation_duplicate();219void _animation_remove();220void _animation_remove_confirmed();221void _animation_search_text_changed(const String &p_text);222void _animation_loop_changed();223void _animation_speed_resized();224void _animation_speed_changed(double p_value);225226void _frame_list_gui_input(const Ref<InputEvent> &p_event);227void _frame_list_item_selected(int p_index, bool p_selected);228229void _menu_selected(int p_id);230231void _zoom_in();232void _zoom_out();233void _zoom_reset();234235bool animations_dirty = false;236bool pending_update = false;237238bool updating;239bool updating_split_settings = false; // Skip SpinBox/Range callback when setting value by code.240241Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);242bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;243void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);244245void _open_sprite_sheet();246void _auto_slice_sprite_sheet();247bool _matches_background_color(const Color &p_background_color, const Color &p_pixel_color);248Size2i _estimate_sprite_sheet_size(const Ref<Texture2D> p_texture);249void _prepare_sprite_sheet(const String &p_file);250int _sheet_preview_position_to_frame_index(const Vector2 &p_position);251void _sheet_preview_draw();252void _sheet_spin_changed(double p_value, int p_dominant_param);253void _sheet_preview_input(const Ref<InputEvent> &p_event);254void _sheet_scroll_input(const Ref<InputEvent> &p_event);255void _sheet_add_frames();256void _sheet_zoom_on_position(float p_zoom, const Vector2 &p_position);257void _sheet_zoom_in();258void _sheet_zoom_out();259void _sheet_zoom_reset();260void _sheet_order_selected(int p_option);261void _sheet_select_all_frames();262void _sheet_clear_all_frames();263void _sheet_sort_frames();264void _toggle_show_settings();265void _update_show_settings();266267void _edit();268void _fetch_sprite_node();269void _remove_sprite_node();270271bool sprite_node_updating = false;272void _sync_animation();273274void _select_animation(const String &p_name, bool p_update_node = true);275void _rename_node_animation(EditorUndoRedoManager *undo_redo, bool is_undo, const String &p_filter, const String &p_new_animation, const String &p_new_autoplay);276277protected:278void _notification(int p_what);279void _node_removed(Node *p_node);280static void _bind_methods();281282public:283void edit(Ref<SpriteFrames> p_frames);284Ref<SpriteFrames> get_sprite_frames() const;285286SpriteFramesEditor();287};288289class SpriteFramesEditorPlugin : public EditorPlugin {290GDCLASS(SpriteFramesEditorPlugin, EditorPlugin);291292SpriteFramesEditor *frames_editor = nullptr;293Button *button = nullptr;294295public:296virtual String get_plugin_name() const override { return "SpriteFrames"; }297bool has_main_screen() const override { return false; }298virtual void edit(Object *p_object) override;299virtual bool handles(Object *p_object) const override;300virtual void make_visible(bool p_visible) override;301302SpriteFramesEditorPlugin();303};304305306