2023-01-05 12:25:55 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* tile_data_editors.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2021-05-07 13:41:39 +00:00
|
|
|
|
|
|
|
#ifndef TILE_DATA_EDITORS_H
|
|
|
|
#define TILE_DATA_EDITORS_H
|
|
|
|
|
2021-06-09 18:01:08 +00:00
|
|
|
#include "tile_atlas_view.h"
|
|
|
|
|
|
|
|
#include "editor/editor_properties.h"
|
2021-07-28 16:10:01 +00:00
|
|
|
#include "scene/2d/tile_map.h"
|
2021-06-09 18:01:08 +00:00
|
|
|
#include "scene/gui/box_container.h"
|
2023-07-15 18:58:52 +00:00
|
|
|
#include "scene/gui/panel_container.h"
|
2021-05-07 13:41:39 +00:00
|
|
|
|
2023-07-15 18:58:52 +00:00
|
|
|
class Label;
|
2022-11-19 11:45:49 +00:00
|
|
|
class MenuButton;
|
2022-12-23 18:34:28 +00:00
|
|
|
class SpinBox;
|
2022-11-19 11:45:49 +00:00
|
|
|
class EditorUndoRedoManager;
|
|
|
|
|
2021-06-09 18:01:08 +00:00
|
|
|
class TileDataEditor : public VBoxContainer {
|
|
|
|
GDCLASS(TileDataEditor, VBoxContainer);
|
|
|
|
|
|
|
|
private:
|
2021-10-13 12:49:28 +00:00
|
|
|
bool _tile_set_changed_update_needed = false;
|
|
|
|
void _tile_set_changed_plan_update();
|
|
|
|
void _tile_set_changed_deferred_update();
|
2021-05-07 13:41:39 +00:00
|
|
|
|
|
|
|
protected:
|
2021-06-09 18:01:08 +00:00
|
|
|
Ref<TileSet> tile_set;
|
|
|
|
TileData *_get_tile_data(TileMapCell p_cell);
|
|
|
|
virtual void _tile_set_changed(){};
|
2021-05-07 13:41:39 +00:00
|
|
|
|
2021-06-09 18:01:08 +00:00
|
|
|
static void _bind_methods();
|
2021-05-07 13:41:39 +00:00
|
|
|
|
|
|
|
public:
|
2021-06-09 18:01:08 +00:00
|
|
|
void set_tile_set(Ref<TileSet> p_tile_set);
|
|
|
|
|
|
|
|
// Input to handle painting.
|
|
|
|
virtual Control *get_toolbar() { return nullptr; };
|
|
|
|
virtual void forward_draw_over_atlas(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, CanvasItem *p_canvas_item, Transform2D p_transform){};
|
|
|
|
virtual void forward_draw_over_alternatives(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, CanvasItem *p_canvas_item, Transform2D p_transform){};
|
|
|
|
virtual void forward_painting_atlas_gui_input(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, const Ref<InputEvent> &p_event){};
|
|
|
|
virtual void forward_painting_alternatives_gui_input(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, const Ref<InputEvent> &p_event){};
|
2021-05-07 13:41:39 +00:00
|
|
|
|
2021-06-09 18:01:08 +00:00
|
|
|
// Used to draw the tile data property value over a tile.
|
|
|
|
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false){};
|
2021-05-07 13:41:39 +00:00
|
|
|
};
|
|
|
|
|
2021-06-09 18:01:08 +00:00
|
|
|
class DummyObject : public Object {
|
|
|
|
GDCLASS(DummyObject, Object)
|
|
|
|
private:
|
2022-05-13 13:04:37 +00:00
|
|
|
HashMap<String, Variant> properties;
|
2021-06-09 18:01:08 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const;
|
2021-05-07 13:41:39 +00:00
|
|
|
|
|
|
|
public:
|
2021-06-09 18:01:08 +00:00
|
|
|
bool has_dummy_property(StringName p_name);
|
|
|
|
void add_dummy_property(StringName p_name);
|
|
|
|
void remove_dummy_property(StringName p_name);
|
|
|
|
void clear_dummy_properties();
|
2021-05-07 13:41:39 +00:00
|
|
|
};
|
|
|
|
|
2021-06-09 18:01:08 +00:00
|
|
|
class GenericTilePolygonEditor : public VBoxContainer {
|
|
|
|
GDCLASS(GenericTilePolygonEditor, VBoxContainer);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Ref<TileSet> tile_set;
|
|
|
|
LocalVector<Vector<Point2>> polygons;
|
|
|
|
bool multiple_polygon_mode = false;
|
|
|
|
|
2021-10-19 09:40:46 +00:00
|
|
|
bool use_undo_redo = true;
|
2021-06-09 18:01:08 +00:00
|
|
|
|
|
|
|
// UI
|
|
|
|
int hovered_polygon_index = -1;
|
|
|
|
int hovered_point_index = -1;
|
|
|
|
int hovered_segment_index = -1;
|
|
|
|
Vector2 hovered_segment_point;
|
|
|
|
|
|
|
|
enum DragType {
|
|
|
|
DRAG_TYPE_NONE,
|
|
|
|
DRAG_TYPE_DRAG_POINT,
|
|
|
|
DRAG_TYPE_CREATE_POINT,
|
|
|
|
DRAG_TYPE_PAN,
|
|
|
|
};
|
2021-10-19 09:40:46 +00:00
|
|
|
DragType drag_type = DRAG_TYPE_NONE;
|
2022-05-02 14:28:25 +00:00
|
|
|
int drag_polygon_index = 0;
|
|
|
|
int drag_point_index = 0;
|
2021-06-09 18:01:08 +00:00
|
|
|
Vector2 drag_last_pos;
|
|
|
|
PackedVector2Array drag_old_polygon;
|
|
|
|
|
2022-04-04 13:06:57 +00:00
|
|
|
HBoxContainer *toolbar = nullptr;
|
2021-06-09 18:01:08 +00:00
|
|
|
Ref<ButtonGroup> tools_button_group;
|
2023-07-15 18:58:52 +00:00
|
|
|
Button *button_expand = nullptr;
|
2022-04-04 13:06:57 +00:00
|
|
|
Button *button_create = nullptr;
|
|
|
|
Button *button_edit = nullptr;
|
|
|
|
Button *button_delete = nullptr;
|
|
|
|
MenuButton *button_advanced_menu = nullptr;
|
2021-06-09 18:01:08 +00:00
|
|
|
|
2022-12-23 18:34:28 +00:00
|
|
|
enum Snap {
|
|
|
|
SNAP_NONE,
|
|
|
|
SNAP_HALF_PIXEL,
|
|
|
|
SNAP_GRID,
|
|
|
|
};
|
|
|
|
int current_snap_option = SNAP_HALF_PIXEL;
|
|
|
|
MenuButton *button_pixel_snap = nullptr;
|
|
|
|
SpinBox *snap_subdivision = nullptr;
|
|
|
|
|
2021-06-09 18:01:08 +00:00
|
|
|
Vector<Point2> in_creation_polygon;
|
|
|
|
|
2022-04-04 13:06:57 +00:00
|
|
|
Panel *panel = nullptr;
|
|
|
|
Control *base_control = nullptr;
|
|
|
|
EditorZoomWidget *editor_zoom_widget = nullptr;
|
|
|
|
Button *button_center_view = nullptr;
|
2021-06-09 18:01:08 +00:00
|
|
|
Vector2 panning;
|
|
|
|
|
|
|
|
Ref<Texture2D> background_texture;
|
|
|
|
Rect2 background_region;
|
|
|
|
Vector2 background_offset;
|
2022-05-02 14:28:25 +00:00
|
|
|
bool background_h_flip = false;
|
|
|
|
bool background_v_flip = false;
|
|
|
|
bool background_transpose = false;
|
2021-06-09 18:01:08 +00:00
|
|
|
Color background_modulate;
|
|
|
|
|
|
|
|
Color polygon_color = Color(1.0, 0.0, 0.0);
|
|
|
|
|
|
|
|
enum AdvancedMenuOption {
|
|
|
|
RESET_TO_DEFAULT_TILE,
|
|
|
|
CLEAR_TILE,
|
2021-10-19 09:40:46 +00:00
|
|
|
ROTATE_RIGHT,
|
|
|
|
ROTATE_LEFT,
|
|
|
|
FLIP_HORIZONTALLY,
|
|
|
|
FLIP_VERTICALLY,
|
2021-06-09 18:01:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void _base_control_draw();
|
|
|
|
void _zoom_changed();
|
|
|
|
void _advanced_menu_item_pressed(int p_item_pressed);
|
|
|
|
void _center_view();
|
|
|
|
void _base_control_gui_input(Ref<InputEvent> p_event);
|
2022-12-23 18:34:28 +00:00
|
|
|
void _set_snap_option(int p_index);
|
|
|
|
void _store_snap_options();
|
2023-07-15 18:58:52 +00:00
|
|
|
void _toggle_expand(bool p_expand);
|
2021-06-09 18:01:08 +00:00
|
|
|
|
|
|
|
void _snap_to_tile_shape(Point2 &r_point, float &r_current_snapped_dist, float p_snap_dist);
|
2022-12-23 18:34:28 +00:00
|
|
|
void _snap_point(Point2 &r_point);
|
2021-06-09 18:01:08 +00:00
|
|
|
void _grab_polygon_point(Vector2 p_pos, const Transform2D &p_polygon_xform, int &r_polygon_index, int &r_point_index);
|
|
|
|
void _grab_polygon_segment_point(Vector2 p_pos, const Transform2D &p_polygon_xform, int &r_polygon_index, int &r_segment_index, Vector2 &r_point);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
2021-05-07 13:41:39 +00:00
|
|
|
|
|
|
|
public:
|
2021-10-19 09:40:46 +00:00
|
|
|
void set_use_undo_redo(bool p_use_undo_redo);
|
|
|
|
|
2021-06-09 18:01:08 +00:00
|
|
|
void set_tile_set(Ref<TileSet> p_tile_set);
|
|
|
|
void set_background(Ref<Texture2D> p_texture, Rect2 p_region = Rect2(), Vector2 p_offset = Vector2(), bool p_flip_h = false, bool p_flip_v = false, bool p_transpose = false, Color p_modulate = Color(1.0, 1.0, 1.0, 0.0));
|
|
|
|
|
|
|
|
int get_polygon_count();
|
|
|
|
int add_polygon(Vector<Point2> p_polygon, int p_index = -1);
|
|
|
|
void remove_polygon(int p_index);
|
|
|
|
void clear_polygons();
|
|
|
|
void set_polygon(int p_polygon_index, Vector<Point2> p_polygon);
|
|
|
|
Vector<Point2> get_polygon(int p_polygon_index);
|
|
|
|
|
|
|
|
void set_polygons_color(Color p_color);
|
|
|
|
void set_multiple_polygon_mode(bool p_multiple_polygon_mode);
|
|
|
|
|
|
|
|
GenericTilePolygonEditor();
|
2021-05-07 13:41:39 +00:00
|
|
|
};
|
|
|
|
|
2021-06-09 18:01:08 +00:00
|
|
|
class TileDataDefaultEditor : public TileDataEditor {
|
|
|
|
GDCLASS(TileDataDefaultEditor, TileDataEditor);
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Toolbar
|
|
|
|
HBoxContainer *toolbar = memnew(HBoxContainer);
|
2022-04-04 13:06:57 +00:00
|
|
|
Button *picker_button = nullptr;
|
2021-06-09 18:01:08 +00:00
|
|
|
|
|
|
|
// UI
|
|
|
|
Ref<Texture2D> tile_bool_checked;
|
|
|
|
Ref<Texture2D> tile_bool_unchecked;
|
2022-04-04 13:06:57 +00:00
|
|
|
Label *label = nullptr;
|
2021-06-09 18:01:08 +00:00
|
|
|
|
|
|
|
EditorProperty *property_editor = nullptr;
|
|
|
|
|
|
|
|
// Painting state.
|
|
|
|
enum DragType {
|
|
|
|
DRAG_TYPE_NONE = 0,
|
|
|
|
DRAG_TYPE_PAINT,
|
|
|
|
DRAG_TYPE_PAINT_RECT,
|
|
|
|
};
|
|
|
|
DragType drag_type = DRAG_TYPE_NONE;
|
|
|
|
Vector2 drag_start_pos;
|
|
|
|
Vector2 drag_last_pos;
|
2022-05-13 13:04:37 +00:00
|
|
|
HashMap<TileMapCell, Variant, TileMapCell> drag_modified;
|
2021-06-09 18:01:08 +00:00
|
|
|
Variant drag_painted_value;
|
|
|
|
|
|
|
|
void _property_value_changed(StringName p_property, Variant p_value, StringName p_field);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
DummyObject *dummy_object = memnew(DummyObject);
|
|
|
|
|
|
|
|
StringName type;
|
|
|
|
String property;
|
2022-09-28 17:17:53 +00:00
|
|
|
Variant::Type property_type;
|
2021-06-09 18:01:08 +00:00
|
|
|
void _notification(int p_what);
|
|
|
|
|
|
|
|
virtual Variant _get_painted_value();
|
|
|
|
virtual void _set_painted_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile);
|
|
|
|
virtual void _set_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile, Variant p_value);
|
|
|
|
virtual Variant _get_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile);
|
2022-05-13 13:04:37 +00:00
|
|
|
virtual void _setup_undo_redo_action(TileSetAtlasSource *p_tile_set_atlas_source, HashMap<TileMapCell, Variant, TileMapCell> p_previous_values, Variant p_new_value);
|
2021-05-07 13:41:39 +00:00
|
|
|
|
|
|
|
public:
|
2021-06-09 18:01:08 +00:00
|
|
|
virtual Control *get_toolbar() override { return toolbar; };
|
|
|
|
virtual void forward_draw_over_atlas(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, CanvasItem *p_canvas_item, Transform2D p_transform) override;
|
|
|
|
virtual void forward_draw_over_alternatives(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, CanvasItem *p_canvas_item, Transform2D p_transform) override;
|
|
|
|
virtual void forward_painting_atlas_gui_input(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, const Ref<InputEvent> &p_event) override;
|
|
|
|
virtual void forward_painting_alternatives_gui_input(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, const Ref<InputEvent> &p_event) override;
|
|
|
|
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) override;
|
|
|
|
|
|
|
|
void setup_property_editor(Variant::Type p_type, String p_property, String p_label = "", Variant p_default_value = Variant());
|
2022-09-28 17:17:53 +00:00
|
|
|
Variant::Type get_property_type();
|
2021-06-09 18:01:08 +00:00
|
|
|
|
|
|
|
TileDataDefaultEditor();
|
|
|
|
~TileDataDefaultEditor();
|
2021-05-07 13:41:39 +00:00
|
|
|
};
|
|
|
|
|
2023-01-26 17:47:54 +00:00
|
|
|
class TileDataTextureOriginEditor : public TileDataDefaultEditor {
|
|
|
|
GDCLASS(TileDataTextureOriginEditor, TileDataDefaultEditor);
|
2021-05-07 13:41:39 +00:00
|
|
|
|
|
|
|
public:
|
2021-06-09 18:01:08 +00:00
|
|
|
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) override;
|
2021-05-07 13:41:39 +00:00
|
|
|
};
|
|
|
|
|
2021-06-09 18:01:08 +00:00
|
|
|
class TileDataPositionEditor : public TileDataDefaultEditor {
|
|
|
|
GDCLASS(TileDataPositionEditor, TileDataDefaultEditor);
|
2021-05-21 08:08:15 +00:00
|
|
|
|
|
|
|
public:
|
2021-06-09 18:01:08 +00:00
|
|
|
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) override;
|
2021-05-21 08:08:15 +00:00
|
|
|
};
|
|
|
|
|
2021-06-09 18:01:08 +00:00
|
|
|
class TileDataYSortEditor : public TileDataDefaultEditor {
|
|
|
|
GDCLASS(TileDataYSortEditor, TileDataDefaultEditor);
|
2021-05-07 13:41:39 +00:00
|
|
|
|
|
|
|
public:
|
2021-06-09 18:01:08 +00:00
|
|
|
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) override;
|
2021-05-07 13:41:39 +00:00
|
|
|
};
|
|
|
|
|
2021-06-09 18:01:08 +00:00
|
|
|
class TileDataOcclusionShapeEditor : public TileDataDefaultEditor {
|
|
|
|
GDCLASS(TileDataOcclusionShapeEditor, TileDataDefaultEditor);
|
|
|
|
|
|
|
|
private:
|
|
|
|
int occlusion_layer = -1;
|
|
|
|
|
|
|
|
// UI
|
2022-04-04 13:06:57 +00:00
|
|
|
GenericTilePolygonEditor *polygon_editor = nullptr;
|
2021-06-09 18:01:08 +00:00
|
|
|
|
|
|
|
void _polygon_changed(PackedVector2Array p_polygon);
|
|
|
|
|
|
|
|
virtual Variant _get_painted_value() override;
|
|
|
|
virtual void _set_painted_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) override;
|
|
|
|
virtual void _set_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile, Variant p_value) override;
|
|
|
|
virtual Variant _get_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) override;
|
2022-05-13 13:04:37 +00:00
|
|
|
virtual void _setup_undo_redo_action(TileSetAtlasSource *p_tile_set_atlas_source, HashMap<TileMapCell, Variant, TileMapCell> p_previous_values, Variant p_new_value) override;
|
2021-06-09 18:01:08 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void _tile_set_changed() override;
|
|
|
|
|
|
|
|
void _notification(int p_what);
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) override;
|
|
|
|
|
|
|
|
void set_occlusion_layer(int p_occlusion_layer) { occlusion_layer = p_occlusion_layer; }
|
|
|
|
|
|
|
|
TileDataOcclusionShapeEditor();
|
|
|
|
};
|
|
|
|
|
|
|
|
class TileDataCollisionEditor : public TileDataDefaultEditor {
|
|
|
|
GDCLASS(TileDataCollisionEditor, TileDataDefaultEditor);
|
|
|
|
|
|
|
|
int physics_layer = -1;
|
|
|
|
|
|
|
|
// UI
|
2022-04-04 13:06:57 +00:00
|
|
|
GenericTilePolygonEditor *polygon_editor = nullptr;
|
2021-06-09 18:01:08 +00:00
|
|
|
DummyObject *dummy_object = memnew(DummyObject);
|
2022-05-13 13:04:37 +00:00
|
|
|
HashMap<StringName, EditorProperty *> property_editors;
|
2021-06-09 18:01:08 +00:00
|
|
|
|
|
|
|
void _property_value_changed(StringName p_property, Variant p_value, StringName p_field);
|
2021-12-26 15:26:58 +00:00
|
|
|
void _property_selected(StringName p_path, int p_focusable);
|
2021-06-09 18:01:08 +00:00
|
|
|
void _polygons_changed();
|
|
|
|
|
|
|
|
virtual Variant _get_painted_value() override;
|
|
|
|
virtual void _set_painted_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) override;
|
|
|
|
virtual void _set_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile, Variant p_value) override;
|
|
|
|
virtual Variant _get_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) override;
|
2022-05-13 13:04:37 +00:00
|
|
|
virtual void _setup_undo_redo_action(TileSetAtlasSource *p_tile_set_atlas_source, HashMap<TileMapCell, Variant, TileMapCell> p_previous_values, Variant p_new_value) override;
|
2021-06-09 18:01:08 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void _tile_set_changed() override;
|
|
|
|
|
|
|
|
void _notification(int p_what);
|
2021-05-07 13:41:39 +00:00
|
|
|
|
|
|
|
public:
|
2021-06-09 18:01:08 +00:00
|
|
|
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) override;
|
|
|
|
|
|
|
|
void set_physics_layer(int p_physics_layer) { physics_layer = p_physics_layer; }
|
|
|
|
|
|
|
|
TileDataCollisionEditor();
|
|
|
|
~TileDataCollisionEditor();
|
2021-05-07 13:41:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class TileDataTerrainsEditor : public TileDataEditor {
|
|
|
|
GDCLASS(TileDataTerrainsEditor, TileDataEditor);
|
|
|
|
|
2021-06-09 18:01:08 +00:00
|
|
|
private:
|
|
|
|
// Toolbar
|
|
|
|
HBoxContainer *toolbar = memnew(HBoxContainer);
|
2022-04-04 13:06:57 +00:00
|
|
|
Button *picker_button = nullptr;
|
2021-06-09 18:01:08 +00:00
|
|
|
|
|
|
|
// Painting state.
|
|
|
|
enum DragType {
|
|
|
|
DRAG_TYPE_NONE = 0,
|
|
|
|
DRAG_TYPE_PAINT_TERRAIN_SET,
|
|
|
|
DRAG_TYPE_PAINT_TERRAIN_SET_RECT,
|
|
|
|
DRAG_TYPE_PAINT_TERRAIN_BITS,
|
|
|
|
DRAG_TYPE_PAINT_TERRAIN_BITS_RECT,
|
|
|
|
};
|
|
|
|
DragType drag_type = DRAG_TYPE_NONE;
|
|
|
|
Vector2 drag_start_pos;
|
|
|
|
Vector2 drag_last_pos;
|
2022-05-13 13:04:37 +00:00
|
|
|
HashMap<TileMapCell, Variant, TileMapCell> drag_modified;
|
2021-06-09 18:01:08 +00:00
|
|
|
Variant drag_painted_value;
|
|
|
|
|
|
|
|
// UI
|
2022-04-04 13:06:57 +00:00
|
|
|
Label *label = nullptr;
|
2021-06-09 18:01:08 +00:00
|
|
|
DummyObject *dummy_object = memnew(DummyObject);
|
|
|
|
EditorPropertyEnum *terrain_set_property_editor = nullptr;
|
|
|
|
EditorPropertyEnum *terrain_property_editor = nullptr;
|
|
|
|
|
|
|
|
void _property_value_changed(StringName p_property, Variant p_value, StringName p_field);
|
|
|
|
|
|
|
|
void _update_terrain_selector();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void _tile_set_changed() override;
|
|
|
|
|
|
|
|
void _notification(int p_what);
|
|
|
|
|
2021-05-07 13:41:39 +00:00
|
|
|
public:
|
2021-06-09 18:01:08 +00:00
|
|
|
virtual Control *get_toolbar() override { return toolbar; };
|
|
|
|
virtual void forward_draw_over_atlas(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, CanvasItem *p_canvas_item, Transform2D p_transform) override;
|
|
|
|
virtual void forward_draw_over_alternatives(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, CanvasItem *p_canvas_item, Transform2D p_transform) override;
|
|
|
|
virtual void forward_painting_atlas_gui_input(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, const Ref<InputEvent> &p_event) override;
|
|
|
|
virtual void forward_painting_alternatives_gui_input(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, const Ref<InputEvent> &p_event) override;
|
|
|
|
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) override;
|
|
|
|
|
|
|
|
TileDataTerrainsEditor();
|
|
|
|
~TileDataTerrainsEditor();
|
2021-05-07 13:41:39 +00:00
|
|
|
};
|
|
|
|
|
2021-06-09 18:01:08 +00:00
|
|
|
class TileDataNavigationEditor : public TileDataDefaultEditor {
|
|
|
|
GDCLASS(TileDataNavigationEditor, TileDataDefaultEditor);
|
|
|
|
|
|
|
|
private:
|
|
|
|
int navigation_layer = -1;
|
|
|
|
PackedVector2Array navigation_polygon;
|
|
|
|
|
|
|
|
// UI
|
2022-04-04 13:06:57 +00:00
|
|
|
GenericTilePolygonEditor *polygon_editor = nullptr;
|
2021-06-09 18:01:08 +00:00
|
|
|
|
|
|
|
void _polygon_changed(PackedVector2Array p_polygon);
|
|
|
|
|
|
|
|
virtual Variant _get_painted_value() override;
|
|
|
|
virtual void _set_painted_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) override;
|
|
|
|
virtual void _set_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile, Variant p_value) override;
|
|
|
|
virtual Variant _get_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) override;
|
2022-05-13 13:04:37 +00:00
|
|
|
virtual void _setup_undo_redo_action(TileSetAtlasSource *p_tile_set_atlas_source, HashMap<TileMapCell, Variant, TileMapCell> p_previous_values, Variant p_new_value) override;
|
2021-06-09 18:01:08 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void _tile_set_changed() override;
|
|
|
|
|
|
|
|
void _notification(int p_what);
|
2021-05-07 13:41:39 +00:00
|
|
|
|
|
|
|
public:
|
2021-06-09 18:01:08 +00:00
|
|
|
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) override;
|
|
|
|
|
|
|
|
void set_navigation_layer(int p_navigation_layer) { navigation_layer = p_navigation_layer; }
|
|
|
|
|
|
|
|
TileDataNavigationEditor();
|
2021-05-07 13:41:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // TILE_DATA_EDITORS_H
|