Path: blob/master/editor/scene/2d/tiles/tiles_editor_plugin.h
21735 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 TileSetSourceItemList : public ItemList {110GDCLASS(TileSetSourceItemList, ItemList);111112public:113Ref<TileSet> tile_set;114115virtual String get_tooltip(const Point2 &p_pos) const override;116117TileSetSourceItemList();118};119120class TileMapEditorPlugin : public EditorPlugin {121GDCLASS(TileMapEditorPlugin, EditorPlugin);122123TileMapLayerEditor *editor = nullptr;124ObjectID tile_map_layer_id;125ObjectID tile_map_group_id; // Allow keeping the layer selector up to date.126127bool tile_map_changed_needs_update = false;128ObjectID tile_set_id; // The TileSet associated with the TileMap.129130void _tile_map_layer_changed();131void _tile_map_layer_removed();132void _update_tile_map();133void _select_layer(const StringName &p_name);134135void _edit_tile_map_layer(TileMapLayer *p_tile_map_layer, bool p_show_layer_selector);136void _edit_tile_map(TileMap *p_tile_map);137138protected:139void _notification(int p_notification);140141public:142virtual void edit(Object *p_object) override;143virtual bool handles(Object *p_object) const override;144virtual void make_visible(bool p_visible) override;145146virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) override;147virtual void forward_canvas_draw_over_viewport(Control *p_overlay) override;148149bool is_editor_visible() const;150151TileMapEditorPlugin();152~TileMapEditorPlugin();153};154155class TileSetEditorPlugin : public EditorPlugin {156GDCLASS(TileSetEditorPlugin, EditorPlugin);157158TileSetEditor *editor = nullptr;159160ObjectID edited_tileset;161162public:163virtual void edit(Object *p_object) override;164virtual bool handles(Object *p_object) const override;165virtual void make_visible(bool p_visible) override;166void open_editor();167168ObjectID get_edited_tileset() const;169170TileSetEditorPlugin();171~TileSetEditorPlugin();172};173174175