Path: blob/master/editor/scene/2d/tiles/tiles_editor_plugin.h
9906 views
/**************************************************************************/1/* tiles_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"3334#include "tile_map_layer_editor.h"35#include "tile_set_editor.h"3637class TilesEditorUtils : public Object {38GDCLASS(TilesEditorUtils, Object);3940static TilesEditorUtils *singleton;4142public:43enum SourceSortOption {44SOURCE_SORT_ID = 0,45SOURCE_SORT_ID_REVERSE,46SOURCE_SORT_NAME,47SOURCE_SORT_NAME_REVERSE,48SOURCE_SORT_MAX49};5051private:52// For synchronization.53int atlas_sources_lists_current = 0;54float atlas_view_zoom = 1.0;55Vector2 atlas_view_scroll;5657// Source sorting.58int source_sort = SOURCE_SORT_ID;5960struct SourceNameComparator {61static Ref<TileSet> tile_set;62bool operator()(const int &p_a, const int &p_b) const;63};6465// Patterns preview generation.66struct QueueItem {67Ref<TileSet> tile_set;68Ref<TileMapPattern> pattern;69Callable callback;70};71List<QueueItem> pattern_preview_queue;72Mutex pattern_preview_mutex;73Semaphore pattern_preview_sem;74Thread pattern_preview_thread;75SafeFlag pattern_thread_exit;76SafeFlag pattern_thread_exited;77Semaphore pattern_preview_done;78void _preview_frame_started();79void _pattern_preview_done();80static void _thread_func(void *ud);81void _thread();8283public:84_FORCE_INLINE_ static TilesEditorUtils *get_singleton() { return singleton; }8586// Pattern preview API.87void queue_pattern_preview(Ref<TileSet> p_tile_set, Ref<TileMapPattern> p_pattern, Callable p_callback);8889// To synchronize the atlas sources lists.90void set_sources_lists_current(int p_current);91void synchronize_sources_list(Object *p_current_list, Object *p_current_sort_button);9293void set_atlas_view_transform(float p_zoom, Vector2 p_scroll);94void synchronize_atlas_view(Object *p_current);9596// Sorting.97void set_sorting_option(int p_option);98List<int> get_sorted_sources(const Ref<TileSet> p_tile_set) const;99100// Misc.101void display_tile_set_editor_panel();102103static void draw_selection_rect(CanvasItem *p_ci, const Rect2 &p_rect, const Color &p_color = Color(1.0, 1.0, 1.0));104105TilesEditorUtils();106~TilesEditorUtils();107};108109class TileMapEditorPlugin : public EditorPlugin {110GDCLASS(TileMapEditorPlugin, EditorPlugin);111112TileMapLayerEditor *editor = nullptr;113Button *button = nullptr;114ObjectID tile_map_layer_id;115ObjectID tile_map_group_id; // Allow keeping the layer selector up to date.116117bool tile_map_changed_needs_update = false;118ObjectID tile_set_id; // The TileSet associated with the TileMap.119120void _tile_map_layer_changed();121void _tile_map_layer_removed();122void _update_tile_map();123void _select_layer(const StringName &p_name);124125void _edit_tile_map_layer(TileMapLayer *p_tile_map_layer, bool p_show_layer_selector);126void _edit_tile_map(TileMap *p_tile_map);127128protected:129void _notification(int p_notification);130131public:132virtual void edit(Object *p_object) override;133virtual bool handles(Object *p_object) const override;134virtual void make_visible(bool p_visible) override;135136virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) override;137virtual void forward_canvas_draw_over_viewport(Control *p_overlay) override;138139void hide_editor();140bool is_editor_visible() const;141142TileMapEditorPlugin();143~TileMapEditorPlugin();144};145146class TileSetEditorPlugin : public EditorPlugin {147GDCLASS(TileSetEditorPlugin, EditorPlugin);148149TileSetEditor *editor = nullptr;150Button *button = nullptr;151152ObjectID edited_tileset;153154public:155virtual void edit(Object *p_object) override;156virtual bool handles(Object *p_object) const override;157virtual void make_visible(bool p_visible) override;158159ObjectID get_edited_tileset() const;160161TileSetEditorPlugin();162~TileSetEditorPlugin();163};164165166