Implement painting properties over TileSets

This commit is contained in:
Gilles Roudière 2021-06-09 20:01:08 +02:00
parent eb318d3e04
commit 30a615dd94
20 changed files with 4993 additions and 2103 deletions

View File

@ -362,6 +362,19 @@ public:
return (intersections & 1);
}
static bool is_segment_intersecting_polygon(const Vector2 &p_from, const Vector2 &p_to, const Vector<Vector2> &p_polygon) {
int c = p_polygon.size();
const Vector2 *p = p_polygon.ptr();
for (int i = 0; i < c; i++) {
const Vector2 &v1 = p[i];
const Vector2 &v2 = p[(i + 1) % c];
if (segment_intersects_segment(p_from, p_to, v1, v2, nullptr)) {
return true;
}
}
return false;
}
static real_t vec2_cross(const Point2 &O, const Point2 &A, const Point2 &B) {
return (real_t)(A.x - O.x) * (B.y - O.y) - (real_t)(A.y - O.y) * (B.x - O.x);
}

View File

@ -7,7 +7,7 @@
<tutorials>
</tutorials>
<methods>
<method name="add_collision_shape">
<method name="add_collision_polygon">
<return type="void">
</return>
<argument index="0" name="layer_id" type="int">
@ -15,27 +15,27 @@
<description>
</description>
</method>
<method name="get_collision_shape_one_way_margin" qualifiers="const">
<method name="get_collision_polygon_one_way_margin" qualifiers="const">
<return type="float">
</return>
<argument index="0" name="layer_id" type="int">
</argument>
<argument index="1" name="shape_index" type="int">
<argument index="1" name="polygon_index" type="int">
</argument>
<description>
</description>
</method>
<method name="get_collision_shape_shape" qualifiers="const">
<return type="Shape2D">
<method name="get_collision_polygon_points" qualifiers="const">
<return type="PackedVector2Array">
</return>
<argument index="0" name="layer_id" type="int">
</argument>
<argument index="1" name="shape_index" type="int">
<argument index="1" name="polygon_index" type="int">
</argument>
<description>
</description>
</method>
<method name="get_collision_shapes_count" qualifiers="const">
<method name="get_collision_polygons_count" qualifiers="const">
<return type="int">
</return>
<argument index="0" name="layer_id" type="int">
@ -83,68 +83,68 @@
<description>
</description>
</method>
<method name="is_collision_shape_one_way" qualifiers="const">
<method name="is_collision_polygon_one_way" qualifiers="const">
<return type="bool">
</return>
<argument index="0" name="layer_id" type="int">
</argument>
<argument index="1" name="shape_index" type="int">
<argument index="1" name="polygon_index" type="int">
</argument>
<description>
</description>
</method>
<method name="remove_collision_shape">
<method name="remove_collision_polygon">
<return type="void">
</return>
<argument index="0" name="layer_id" type="int">
</argument>
<argument index="1" name="shape_index" type="int">
<argument index="1" name="polygon_index" type="int">
</argument>
<description>
</description>
</method>
<method name="set_collision_shape_one_way">
<method name="set_collision_polygon_one_way">
<return type="void">
</return>
<argument index="0" name="layer_id" type="int">
</argument>
<argument index="1" name="shape_index" type="int">
<argument index="1" name="polygon_index" type="int">
</argument>
<argument index="2" name="one_way" type="bool">
</argument>
<description>
</description>
</method>
<method name="set_collision_shape_one_way_margin">
<method name="set_collision_polygon_one_way_margin">
<return type="void">
</return>
<argument index="0" name="layer_id" type="int">
</argument>
<argument index="1" name="shape_index" type="int">
<argument index="1" name="polygon_index" type="int">
</argument>
<argument index="2" name="one_way_margin" type="float">
</argument>
<description>
</description>
</method>
<method name="set_collision_shape_shape">
<method name="set_collision_polygon_points">
<return type="void">
</return>
<argument index="0" name="layer_id" type="int">
</argument>
<argument index="1" name="shape_index" type="int">
<argument index="1" name="polygon_index" type="int">
</argument>
<argument index="2" name="shape" type="Shape2D">
<argument index="2" name="polygon" type="PackedVector2Array">
</argument>
<description>
</description>
</method>
<method name="set_collision_shapes_count">
<method name="set_collision_polygons_count">
<return type="void">
</return>
<argument index="0" name="layer_id" type="int">
</argument>
<argument index="1" name="shapes_count" type="int">
<argument index="1" name="polygons_count" type="int">
</argument>
<description>
</description>

View File

@ -289,8 +289,6 @@
</member>
<member name="tile_size" type="Vector2i" setter="set_tile_size" getter="get_tile_size" default="Vector2i(16, 16)">
</member>
<member name="tile_skew" type="Vector2" setter="set_tile_skew" getter="get_tile_skew" default="Vector2(0, 0)">
</member>
<member name="uv_clipping" type="bool" setter="set_uv_clipping" getter="is_uv_clipping" default="false">
</member>
<member name="y_sorting" type="bool" setter="set_y_sorting" getter="is_y_sorting" default="false">

View File

@ -491,6 +491,7 @@ void EditorPropertyEnum::update_property() {
}
void EditorPropertyEnum::setup(const Vector<String> &p_options) {
options->clear();
int64_t current_val = 0;
for (int i = 0; i < p_options.size(); i++) {
Vector<String> text_split = p_options[i].split(":");
@ -2699,30 +2700,42 @@ void EditorInspectorDefaultPlugin::parse_begin(Object *p_object) {
}
bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) {
Control *editor = EditorInspectorDefaultPlugin::get_editor_for_property(p_object, p_type, p_path, p_hint, p_hint_text, p_usage, p_wide);
if (editor) {
add_property_editor(p_path, editor);
}
return false;
}
void EditorInspectorDefaultPlugin::parse_end() {
//do none
}
EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) {
double default_float_step = EDITOR_GET("interface/inspector/default_float_step");
switch (p_type) {
// atomic types
case Variant::NIL: {
EditorPropertyNil *editor = memnew(EditorPropertyNil);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::BOOL: {
EditorPropertyCheck *editor = memnew(EditorPropertyCheck);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::INT: {
if (p_hint == PROPERTY_HINT_ENUM) {
EditorPropertyEnum *editor = memnew(EditorPropertyEnum);
Vector<String> options = p_hint_text.split(",");
editor->setup(options);
add_property_editor(p_path, editor);
return editor;
} else if (p_hint == PROPERTY_HINT_FLAGS) {
EditorPropertyFlags *editor = memnew(EditorPropertyFlags);
Vector<String> options = p_hint_text.split(",");
editor->setup(options);
add_property_editor(p_path, editor);
return editor;
} else if (p_hint == PROPERTY_HINT_LAYERS_2D_PHYSICS ||
p_hint == PROPERTY_HINT_LAYERS_2D_RENDER ||
@ -2755,11 +2768,11 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
}
EditorPropertyLayers *editor = memnew(EditorPropertyLayers);
editor->setup(lt);
add_property_editor(p_path, editor);
return editor;
} else if (p_hint == PROPERTY_HINT_OBJECT_ID) {
EditorPropertyObjectID *editor = memnew(EditorPropertyObjectID);
editor->setup(p_hint_text);
add_property_editor(p_path, editor);
return editor;
} else {
EditorPropertyInteger *editor = memnew(EditorPropertyInteger);
@ -2789,7 +2802,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
editor->setup(min, max, step, greater, lesser);
add_property_editor(p_path, editor);
return editor;
}
} break;
case Variant::FLOAT: {
@ -2809,7 +2822,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
}
editor->setup(full, flip);
add_property_editor(p_path, editor);
return editor;
} else {
EditorPropertyFloat *editor = memnew(EditorPropertyFloat);
@ -2841,7 +2854,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
editor->setup(min, max, step, hide_slider, exp_range, greater, lesser);
add_property_editor(p_path, editor);
return editor;
}
} break;
case Variant::STRING: {
@ -2849,14 +2862,14 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
EditorPropertyTextEnum *editor = memnew(EditorPropertyTextEnum);
Vector<String> options = p_hint_text.split(",");
editor->setup(options);
add_property_editor(p_path, editor);
return editor;
} else if (p_hint == PROPERTY_HINT_MULTILINE_TEXT) {
EditorPropertyMultilineText *editor = memnew(EditorPropertyMultilineText);
add_property_editor(p_path, editor);
return editor;
} else if (p_hint == PROPERTY_HINT_TYPE_STRING) {
EditorPropertyClassName *editor = memnew(EditorPropertyClassName);
editor->setup("Object", p_hint_text);
add_property_editor(p_path, editor);
return editor;
} else if (p_hint == PROPERTY_HINT_DIR || p_hint == PROPERTY_HINT_FILE || p_hint == PROPERTY_HINT_SAVE_FILE || p_hint == PROPERTY_HINT_GLOBAL_DIR || p_hint == PROPERTY_HINT_GLOBAL_FILE) {
Vector<String> extensions = p_hint_text.split(",");
bool global = p_hint == PROPERTY_HINT_GLOBAL_DIR || p_hint == PROPERTY_HINT_GLOBAL_FILE;
@ -2867,7 +2880,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
if (save) {
editor->set_save_mode();
}
add_property_editor(p_path, editor);
return editor;
} else if (p_hint == PROPERTY_HINT_METHOD_OF_VARIANT_TYPE ||
p_hint == PROPERTY_HINT_METHOD_OF_BASE_TYPE ||
p_hint == PROPERTY_HINT_METHOD_OF_INSTANCE ||
@ -2905,14 +2918,14 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
}
}
editor->setup(type, p_hint_text);
add_property_editor(p_path, editor);
return editor;
} else {
EditorPropertyText *editor = memnew(EditorPropertyText);
if (p_hint == PROPERTY_HINT_PLACEHOLDER_TEXT) {
editor->set_placeholder(p_hint_text);
}
add_property_editor(p_path, editor);
return editor;
}
} break;
@ -2933,7 +2946,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
}
editor->setup(min, max, step, hide_slider);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::VECTOR2I: {
@ -2948,7 +2961,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
}
editor->setup(min, max, hide_slider);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::RECT2: {
@ -2966,7 +2979,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
}
editor->setup(min, max, step, hide_slider);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::RECT2I: {
EditorPropertyRect2i *editor = memnew(EditorPropertyRect2i(p_wide));
@ -2980,7 +2993,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
}
editor->setup(min, max, hide_slider);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::VECTOR3: {
EditorPropertyVector3 *editor = memnew(EditorPropertyVector3(p_wide));
@ -2997,7 +3010,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
}
editor->setup(min, max, step, hide_slider);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::VECTOR3I: {
@ -3013,7 +3026,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
}
editor->setup(min, max, hide_slider);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::TRANSFORM2D: {
@ -3031,7 +3044,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
}
editor->setup(min, max, step, hide_slider);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::PLANE: {
@ -3049,7 +3062,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
}
editor->setup(min, max, step, hide_slider);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::QUATERNION: {
EditorPropertyQuaternion *editor = memnew(EditorPropertyQuaternion);
@ -3066,7 +3079,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
}
editor->setup(min, max, step, hide_slider);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::AABB: {
EditorPropertyAABB *editor = memnew(EditorPropertyAABB);
@ -3083,7 +3096,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
}
editor->setup(min, max, step, hide_slider);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::BASIS: {
EditorPropertyBasis *editor = memnew(EditorPropertyBasis);
@ -3100,7 +3113,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
}
editor->setup(min, max, step, hide_slider);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::TRANSFORM3D: {
EditorPropertyTransform3D *editor = memnew(EditorPropertyTransform3D);
@ -3117,7 +3130,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
}
editor->setup(min, max, step, hide_slider);
add_property_editor(p_path, editor);
return editor;
} break;
@ -3125,21 +3138,21 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
case Variant::COLOR: {
EditorPropertyColor *editor = memnew(EditorPropertyColor);
editor->setup(p_hint != PROPERTY_HINT_COLOR_NO_ALPHA);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::STRING_NAME: {
if (p_hint == PROPERTY_HINT_ENUM) {
EditorPropertyTextEnum *editor = memnew(EditorPropertyTextEnum);
Vector<String> options = p_hint_text.split(",");
editor->setup(options, true);
add_property_editor(p_path, editor);
return editor;
} else {
EditorPropertyText *editor = memnew(EditorPropertyText);
if (p_hint == PROPERTY_HINT_PLACEHOLDER_TEXT) {
editor->set_placeholder(p_hint_text);
}
editor->set_string_name(true);
add_property_editor(p_path, editor);
return editor;
}
} break;
case Variant::NODE_PATH: {
@ -3152,12 +3165,12 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
Vector<StringName> sn = Variant(types); //convert via variant
editor->setup(NodePath(), sn, (p_usage & PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT));
}
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::RID: {
EditorPropertyRID *editor = memnew(EditorPropertyRID);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::OBJECT: {
EditorPropertyResource *editor = memnew(EditorPropertyResource);
@ -3176,70 +3189,66 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
}
}
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::DICTIONARY: {
EditorPropertyDictionary *editor = memnew(EditorPropertyDictionary);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::ARRAY: {
EditorPropertyArray *editor = memnew(EditorPropertyArray);
editor->setup(Variant::ARRAY, p_hint_text);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::PACKED_BYTE_ARRAY: {
EditorPropertyArray *editor = memnew(EditorPropertyArray);
editor->setup(Variant::PACKED_BYTE_ARRAY);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::PACKED_INT32_ARRAY: {
EditorPropertyArray *editor = memnew(EditorPropertyArray);
editor->setup(Variant::PACKED_INT32_ARRAY);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::PACKED_INT64_ARRAY: {
EditorPropertyArray *editor = memnew(EditorPropertyArray);
editor->setup(Variant::PACKED_INT64_ARRAY);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::PACKED_FLOAT32_ARRAY: {
EditorPropertyArray *editor = memnew(EditorPropertyArray);
editor->setup(Variant::PACKED_FLOAT32_ARRAY);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::PACKED_FLOAT64_ARRAY: {
EditorPropertyArray *editor = memnew(EditorPropertyArray);
editor->setup(Variant::PACKED_FLOAT64_ARRAY);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::PACKED_STRING_ARRAY: {
EditorPropertyArray *editor = memnew(EditorPropertyArray);
editor->setup(Variant::PACKED_STRING_ARRAY);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::PACKED_VECTOR2_ARRAY: {
EditorPropertyArray *editor = memnew(EditorPropertyArray);
editor->setup(Variant::PACKED_VECTOR2_ARRAY);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::PACKED_VECTOR3_ARRAY: {
EditorPropertyArray *editor = memnew(EditorPropertyArray);
editor->setup(Variant::PACKED_VECTOR3_ARRAY);
add_property_editor(p_path, editor);
return editor;
} break;
case Variant::PACKED_COLOR_ARRAY: {
EditorPropertyArray *editor = memnew(EditorPropertyArray);
editor->setup(Variant::PACKED_COLOR_ARRAY);
add_property_editor(p_path, editor);
} break;
default: {
}
}
return false; //can be overridden, although it will most likely be last anyway
}
void EditorInspectorDefaultPlugin::parse_end() {
//do none
return nullptr;
}

View File

@ -649,6 +649,8 @@ public:
virtual void parse_begin(Object *p_object) override;
virtual bool parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide = false) override;
virtual void parse_end() override;
static EditorProperty *get_editor_for_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide = false);
};
#endif // EDITOR_PROPERTIES_H

View File

@ -0,0 +1 @@
<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><circle cx="4" cy="12" fill="none" r="2"/><g fill="#e0e0e0"><path d="m7.3333333 6c-.7386666 0-1.3333333.5946667-1.3333333 1.3333333v1.3333334c0 .7386663.5946667 1.3333333 1.3333333 1.3333333h1.3333334c.7386666 0 1.3333333-.594667 1.3333333-1.3333333v-1.3333334c0-.7386666-.5946667-1.3333333-1.3333333-1.3333333z" stroke-width=".666667"/><g stroke-width=".830398"><path d="m2.9918978 5.5000002c-.7478701.0001968-1.1170118.9026572-.5810669 1.4205652l.2441488.2424178h-2.15497967v1.6548989h2.15497967l-.2441488.242418c-.8159014.77992.3929613 1.9802119 1.178451 1.1700959l1.6667154-1.6548989c.3253369-.3231472.3253369-.8469488 0-1.170096l-1.6667154-1.6548989c-.1568986-.1601378-.3723426-.2504824-.5973507-.2504937z"/><path d="m13.008102 10.5c.74787-.000197 1.117012-.9026571.581067-1.4205651l-.244149-.242418h2.15498v-1.6548988h-2.15498l.244149-.2424179c.815901-.7799207-.392961-1.9802122-1.178451-1.1700961l-1.666715 1.6548987c-.325337.3231474-.325337.846949 0 1.1700961l1.666715 1.6548991c.156899.160138.372343.250482.597351.250494z"/><path d="m5.5000001 13.008102c.000197.74787.902657 1.117012 1.420565.581067l.242418-.244149v2.15498h1.654899v-2.15498l.242418.244149c.77992.815901 1.9802119-.392961 1.1700959-1.178451l-1.6548989-1.666715c-.323147-.325337-.846949-.325337-1.170096 0l-1.654899 1.666715c-.160138.156899-.250482.372343-.250494.597351z"/><path d="m10.5 2.9918983c-.000197-.7478701-.9026571-1.1170121-1.4205651-.581067l-.242418.244149v-2.1549801h-1.6548989v2.1549801l-.242418-.2441491c-.77992-.815901-1.9802121.3929611-1.170096 1.1784512l1.654899 1.6667148c.3231469.325337.8469489.325337 1.1700959 0l1.6548991-1.6667148c.160138-.156899.250482-.3723431.250494-.597351z"/></g></g></svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -1 +0,0 @@
<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m2 2c-.5522619.0000552-.9999448.4477381-1 1v10c.0000552.552262.4477381.999945 1 1h6v-2h-5v-8h10v1h2v-2c-.000055-.5522619-.447738-.9999448-1-1zm9.25 4v2.25h-2.25v1.5h2.25v2.25h1.5v-2.25h2.25v-1.5h-2.25v-2.25zm-2.25 7.5v1.5h6v-1.5z" fill="#e0e0e0"/></svg>

Before

Width:  |  Height:  |  Size: 346 B

View File

@ -0,0 +1 @@
<svg height="16" viewBox="0 0 16 15.999999" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m3.3333333 1c-1.2887 0-2.3333333 1.0446683-2.3333333 2.3333333v9.3333337c0 1.2887 1.0446683 2.333333 2.3333333 2.333333h9.3333337c1.2887 0 2.333333-1.044668 2.333333-2.333333v-9.3333337c0-1.2887-1.044668-2.3333333-2.333333-2.3333333z" fill="#808080" stroke-width="1.16667"/><path d="m11.500773 3.7343508-5.6117507 5.6117502-1.7045017-1.6814543-1.4992276 1.4992276 3.2037293 3.1806817 7.1109777-7.1109775z" fill="#fff" stroke-width="1.06023"/></svg>

After

Width:  |  Height:  |  Size: 548 B

View File

@ -0,0 +1 @@
<svg height="16" viewBox="0 0 16 15.999999" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m3.3333333 1c-1.2887 0-2.3333333 1.0446683-2.3333333 2.3333333v9.3333337c0 1.2887 1.0446683 2.333333 2.3333333 2.333333h9.3333337c1.2887 0 2.333333-1.044668 2.333333-2.333333v-9.3333337c0-1.2887-1.044668-2.3333333-2.333333-2.3333333z" fill="#808080" stroke-width="1.16667"/></svg>

After

Width:  |  Height:  |  Size: 380 B

View File

@ -33,7 +33,6 @@
#include "core/input/input.h"
#include "core/os/keyboard.h"
#include "scene/gui/box_container.h"
#include "scene/gui/center_container.h"
#include "scene/gui/label.h"
#include "scene/gui/panel.h"
#include "scene/gui/texture_rect.h"
@ -44,21 +43,41 @@
void TileAtlasView::_gui_input(const Ref<InputEvent> &p_event) {
bool ctrl = Input::get_singleton()->is_key_pressed(KEY_CTRL);
Ref<InputEventMouseButton> b = p_event;
if (b.is_valid()) {
if (ctrl && b->is_pressed() && b->get_button_index() == MOUSE_BUTTON_WHEEL_DOWN) {
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid()) {
drag_type = DRAG_TYPE_NONE;
if (ctrl && mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_WHEEL_DOWN) {
// Zoom out
zoom_widget->set_zoom_by_increments(-2);
emit_signal("transform_changed", zoom_widget->get_zoom(), Vector2(scroll_container->get_h_scroll(), scroll_container->get_v_scroll()));
_update_zoom(zoom_widget->get_zoom(), true);
emit_signal("transform_changed", zoom_widget->get_zoom(), panning);
_update_zoom_and_panning(true);
accept_event();
}
if (ctrl && b->is_pressed() && b->get_button_index() == MOUSE_BUTTON_WHEEL_UP) {
if (ctrl && mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_WHEEL_UP) {
// Zoom in
zoom_widget->set_zoom_by_increments(2);
emit_signal("transform_changed", zoom_widget->get_zoom(), Vector2(scroll_container->get_h_scroll(), scroll_container->get_v_scroll()));
_update_zoom(zoom_widget->get_zoom(), true);
emit_signal("transform_changed", zoom_widget->get_zoom(), panning);
_update_zoom_and_panning(true);
accept_event();
}
if (mb->get_button_index() == MOUSE_BUTTON_MIDDLE || mb->get_button_index() == MOUSE_BUTTON_RIGHT) {
if (mb->is_pressed()) {
drag_type = DRAG_TYPE_PAN;
} else {
drag_type = DRAG_TYPE_NONE;
}
accept_event();
}
}
Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid()) {
if (drag_type == DRAG_TYPE_PAN) {
panning += mm->get_relative();
_update_zoom_and_panning();
emit_signal("transform_changed", zoom_widget->get_zoom(), panning);
accept_event();
}
}
@ -103,25 +122,27 @@ Size2i TileAtlasView::_compute_alternative_tiles_control_size() {
return size;
}
void TileAtlasView::_update_zoom(float p_zoom, bool p_zoom_on_mouse_pos, Vector2i p_scroll) {
void TileAtlasView::_update_zoom_and_panning(bool p_zoom_on_mouse_pos) {
float zoom = zoom_widget->get_zoom();
// Compute the minimum sizes.
Size2i base_tiles_control_size = _compute_base_tiles_control_size();
base_tiles_root_control->set_custom_minimum_size(Vector2(base_tiles_control_size) * p_zoom);
base_tiles_root_control->set_custom_minimum_size(Vector2(base_tiles_control_size) * zoom);
Size2i alternative_tiles_control_size = _compute_alternative_tiles_control_size();
alternative_tiles_root_control->set_custom_minimum_size(Vector2(alternative_tiles_control_size) * p_zoom);
alternative_tiles_root_control->set_custom_minimum_size(Vector2(alternative_tiles_control_size) * zoom);
// Set the texture for the base tiles.
Ref<Texture2D> texture = tile_set_atlas_source->get_texture();
// Set the scales.
if (base_tiles_control_size.x > 0 && base_tiles_control_size.y > 0) {
base_tiles_drawing_root->set_scale(Vector2(p_zoom, p_zoom));
base_tiles_drawing_root->set_scale(Vector2(zoom, zoom));
} else {
base_tiles_drawing_root->set_scale(Vector2(1, 1));
}
if (alternative_tiles_control_size.x > 0 && alternative_tiles_control_size.y > 0) {
alternative_tiles_drawing_root->set_scale(Vector2(p_zoom, p_zoom));
alternative_tiles_drawing_root->set_scale(Vector2(zoom, zoom));
} else {
alternative_tiles_drawing_root->set_scale(Vector2(1, 1));
}
@ -129,64 +150,40 @@ void TileAtlasView::_update_zoom(float p_zoom, bool p_zoom_on_mouse_pos, Vector2
// Update the margin container's margins.
const char *constants[] = { "margin_left", "margin_top", "margin_right", "margin_bottom" };
for (int i = 0; i < 4; i++) {
margin_container->add_theme_constant_override(constants[i], margin_container_paddings[i] * p_zoom);
margin_container->add_theme_constant_override(constants[i], margin_container_paddings[i] * zoom);
}
// Update the backgrounds.
background_left->update();
background_right->update();
if (p_scroll != Vector2i(-1, -1)) {
scroll_container->set_h_scroll(p_scroll.x);
scroll_container->set_v_scroll(p_scroll.y);
}
// Zoom on the position.
if (previous_zoom != p_zoom) {
// TODO: solve this.
// There is however an issue with scrollcainter preventing this, as it seems
// that the scrollbars are not updated right aways after its children update.
// Compute point on previous area.
/*Vector2 max = Vector2(scroll_container->get_h_scrollbar()->get_max(), scroll_container->get_v_scrollbar()->get_max());
Vector2 min = Vector2(scroll_container->get_h_scrollbar()->get_min(), scroll_container->get_v_scrollbar()->get_min());
Vector2 value = Vector2(scroll_container->get_h_scrollbar()->get_value(), scroll_container->get_v_scrollbar()->get_value());
Vector2 old_max = max * previous_zoom / p_zoom;
Vector2 max_pixel_change = max - old_max;
Vector2 ratio = ((value + scroll_container->get_local_mouse_position()) / old_max).max(Vector2()).min(Vector2(1,1));
Vector2 offset = max_pixel_change * ratio;
print_line("--- ZOOMED ---");
print_line(vformat("max: %s", max));
print_line(vformat("min: %s", min));
print_line(vformat("value: %s", value));
print_line(vformat("size: %s", scroll_container->get_size()));
print_line(vformat("mouse_pos: %s", scroll_container->get_local_mouse_position()));
print_line(vformat("ratio: %s", ratio));
print_line(vformat("max_pixel_change: %s", max_pixel_change));
print_line(vformat("offset: %s", offset));
print_line(vformat("value before: %s", Vector2(scroll_container->get_h_scroll(), scroll_container->get_v_scroll())));
scroll_container->set_h_scroll(10000);//scroll_container->get_h_scroll()+offset.x);
scroll_container->set_v_scroll(10000);//scroll_container->get_v_scroll()+offset.y);
print_line(vformat("value after: %s", Vector2(scroll_container->get_h_scroll(), scroll_container->get_v_scroll())));
*/
previous_zoom = p_zoom;
if (p_zoom_on_mouse_pos) {
// Offset the panning relative to the center of panel.
Vector2 relative_mpos = get_local_mouse_position() - get_size() / 2;
panning = (panning - relative_mpos) * zoom / previous_zoom + relative_mpos;
} else {
// Center of panel.
panning = panning * zoom / previous_zoom;
}
}
button_center_view->set_disabled(panning.is_equal_approx(Vector2()));
void TileAtlasView::_scroll_changed() {
emit_signal("transform_changed", zoom_widget->get_zoom(), Vector2(scroll_container->get_h_scroll(), scroll_container->get_v_scroll()));
previous_zoom = zoom;
center_container->set_begin(panning - center_container->get_minimum_size() / 2);
center_container->set_size(center_container->get_minimum_size());
}
void TileAtlasView::_zoom_widget_changed() {
_update_zoom(zoom_widget->get_zoom());
emit_signal("transform_changed", zoom_widget->get_zoom(), Vector2(scroll_container->get_h_scroll(), scroll_container->get_v_scroll()));
_update_zoom_and_panning();
emit_signal("transform_changed", zoom_widget->get_zoom(), panning);
}
void TileAtlasView::_center_view() {
panning = Vector2();
button_center_view->set_disabled(true);
_update_zoom_and_panning();
emit_signal("transform_changed", zoom_widget->get_zoom(), panning);
}
void TileAtlasView::_base_tiles_root_control_gui_input(const Ref<InputEvent> &p_event) {
@ -415,7 +412,7 @@ void TileAtlasView::set_atlas_source(TileSet *p_tile_set, TileSetAtlasSource *p_
_update_alternative_tiles_rect_cache();
// Update everything.
_update_zoom(zoom_widget->get_zoom());
_update_zoom_and_panning();
// Change children control size.
Size2i base_tiles_control_size = _compute_base_tiles_control_size();
@ -448,9 +445,10 @@ float TileAtlasView::get_zoom() const {
return zoom_widget->get_zoom();
};
void TileAtlasView::set_transform(float p_zoom, Vector2i p_scroll) {
void TileAtlasView::set_transform(float p_zoom, Vector2i p_panning) {
zoom_widget->set_zoom(p_zoom);
_update_zoom(zoom_widget->get_zoom(), false, p_scroll);
panning = p_panning;
_update_zoom_and_panning();
};
void TileAtlasView::set_padding(Side p_side, int p_padding) {
@ -525,7 +523,7 @@ Rect2i TileAtlasView::get_alternative_tile_rect(const Vector2i p_coords, int p_a
}
void TileAtlasView::update() {
scroll_container->update();
base_tiles_draw->update();
base_tiles_texture_grid->update();
base_tiles_shape_grid->update();
base_tiles_dark->update();
@ -534,124 +532,149 @@ void TileAtlasView::update() {
background_right->update();
}
void TileAtlasView::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_READY:
button_center_view->set_icon(get_theme_icon("CenterView", "EditorIcons"));
break;
}
}
void TileAtlasView::_bind_methods() {
ClassDB::bind_method("_gui_input", &TileAtlasView::_gui_input);
ADD_SIGNAL(MethodInfo("transform_changed", PropertyInfo(Variant::FLOAT, "zoom"), PropertyInfo(Variant::VECTOR2, "scroll")));
}
TileAtlasView::TileAtlasView() {
Panel *panel_container = memnew(Panel);
panel_container->set_h_size_flags(SIZE_EXPAND_FILL);
panel_container->set_v_size_flags(SIZE_EXPAND_FILL);
panel_container->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
add_child(panel_container);
set_texture_filter(CanvasItem::TEXTURE_FILTER_NEAREST);
//Scrolling
scroll_container = memnew(ScrollContainer);
scroll_container->get_h_scrollbar()->connect("value_changed", callable_mp(this, &TileAtlasView::_scroll_changed).unbind(1));
scroll_container->get_v_scrollbar()->connect("value_changed", callable_mp(this, &TileAtlasView::_scroll_changed).unbind(1));
panel_container->add_child(scroll_container);
scroll_container->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
Panel *panel = memnew(Panel);
panel->set_clip_contents(true);
panel->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
panel->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
panel->set_h_size_flags(SIZE_EXPAND_FILL);
panel->set_v_size_flags(SIZE_EXPAND_FILL);
add_child(panel);
// Scrollingsc
zoom_widget = memnew(EditorZoomWidget);
add_child(zoom_widget);
zoom_widget->set_anchors_and_offsets_preset(Control::PRESET_TOP_LEFT, Control::PRESET_MODE_MINSIZE, 2 * EDSCALE);
zoom_widget->connect("zoom_changed", callable_mp(this, &TileAtlasView::_zoom_widget_changed).unbind(1));
CenterContainer *center_container = memnew(CenterContainer);
center_container->set_h_size_flags(SIZE_EXPAND_FILL);
center_container->set_v_size_flags(SIZE_EXPAND_FILL);
button_center_view = memnew(Button);
button_center_view->set_icon(get_theme_icon("CenterView", "EditorIcons"));
button_center_view->set_anchors_and_offsets_preset(Control::PRESET_TOP_RIGHT, Control::PRESET_MODE_MINSIZE, 5);
button_center_view->connect("pressed", callable_mp(this, &TileAtlasView::_center_view));
button_center_view->set_flat(true);
button_center_view->set_disabled(true);
add_child(button_center_view);
center_container = memnew(CenterContainer);
center_container->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
center_container->set_anchors_preset(Control::PRESET_CENTER);
center_container->connect("gui_input", callable_mp(this, &TileAtlasView::_gui_input));
scroll_container->add_child(center_container);
panel->add_child(center_container);
missing_source_label = memnew(Label);
missing_source_label->set_text(TTR("No atlas source with a valid texture selected."));
center_container->add_child(missing_source_label);
margin_container = memnew(MarginContainer);
margin_container->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
center_container->add_child(margin_container);
hbox = memnew(HBoxContainer);
hbox->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
hbox->add_theme_constant_override("separation", 10);
hbox->hide();
margin_container->add_child(hbox);
VBoxContainer *left_vbox = memnew(VBoxContainer);
left_vbox->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
hbox->add_child(left_vbox);
VBoxContainer *right_vbox = memnew(VBoxContainer);
right_vbox->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
hbox->add_child(right_vbox);
// Base tiles.
Label *base_tile_label = memnew(Label);
base_tile_label->set_mouse_filter(Control::MOUSE_FILTER_PASS);
base_tile_label->set_text(TTR("Base Tiles"));
base_tile_label->set_align(Label::ALIGN_CENTER);
left_vbox->add_child(base_tile_label);
base_tiles_root_control = memnew(Control);
base_tiles_root_control->set_mouse_filter(Control::MOUSE_FILTER_PASS);
base_tiles_root_control->set_v_size_flags(Control::SIZE_EXPAND_FILL);
base_tiles_root_control->connect("gui_input", callable_mp(this, &TileAtlasView::_base_tiles_root_control_gui_input));
left_vbox->add_child(base_tiles_root_control);
background_left = memnew(Control);
background_left->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
background_left->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
background_left->set_texture_repeat(TextureRepeat::TEXTURE_REPEAT_ENABLED);
background_left->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
background_left->connect("draw", callable_mp(this, &TileAtlasView::_draw_background_left));
base_tiles_root_control->add_child(background_left);
base_tiles_drawing_root = memnew(Control);
base_tiles_drawing_root->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
base_tiles_drawing_root->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
base_tiles_drawing_root->set_texture_filter(TEXTURE_FILTER_NEAREST);
base_tiles_drawing_root->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
base_tiles_root_control->add_child(base_tiles_drawing_root);
base_tiles_draw = memnew(Control);
base_tiles_draw->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
base_tiles_draw->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
base_tiles_draw->connect("draw", callable_mp(this, &TileAtlasView::_draw_base_tiles));
base_tiles_draw->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
base_tiles_drawing_root->add_child(base_tiles_draw);
base_tiles_texture_grid = memnew(Control);
base_tiles_texture_grid->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
base_tiles_texture_grid->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
base_tiles_texture_grid->connect("draw", callable_mp(this, &TileAtlasView::_draw_base_tiles_texture_grid));
base_tiles_texture_grid->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
base_tiles_drawing_root->add_child(base_tiles_texture_grid);
base_tiles_shape_grid = memnew(Control);
base_tiles_shape_grid->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
base_tiles_shape_grid->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
base_tiles_shape_grid->connect("draw", callable_mp(this, &TileAtlasView::_draw_base_tiles_shape_grid));
base_tiles_shape_grid->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
base_tiles_drawing_root->add_child(base_tiles_shape_grid);
base_tiles_dark = memnew(Control);
base_tiles_dark->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
base_tiles_dark->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
base_tiles_dark->connect("draw", callable_mp(this, &TileAtlasView::_draw_base_tiles_dark));
base_tiles_dark->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
base_tiles_drawing_root->add_child(base_tiles_dark);
// Alternative tiles.
Label *alternative_tiles_label = memnew(Label);
alternative_tiles_label->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
alternative_tiles_label->set_text(TTR("Alternative Tiles"));
alternative_tiles_label->set_align(Label::ALIGN_CENTER);
right_vbox->add_child(alternative_tiles_label);
alternative_tiles_root_control = memnew(Control);
alternative_tiles_root_control->set_mouse_filter(Control::MOUSE_FILTER_PASS);
alternative_tiles_root_control->connect("gui_input", callable_mp(this, &TileAtlasView::_alternative_tiles_root_control_gui_input));
right_vbox->add_child(alternative_tiles_root_control);
background_right = memnew(Control);
background_right->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
background_right->set_texture_repeat(TextureRepeat::TEXTURE_REPEAT_ENABLED);
background_right->connect("draw", callable_mp(this, &TileAtlasView::_draw_background_right));
background_right->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
alternative_tiles_root_control->add_child(background_right);
alternative_tiles_drawing_root = memnew(Control);
alternative_tiles_drawing_root->set_texture_filter(TEXTURE_FILTER_NEAREST);
alternative_tiles_drawing_root->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
alternative_tiles_drawing_root->set_texture_filter(TEXTURE_FILTER_NEAREST);
alternative_tiles_root_control->add_child(alternative_tiles_drawing_root);
alternatives_draw = memnew(Control);
alternatives_draw->connect("draw", callable_mp(this, &TileAtlasView::_draw_alternatives));
alternatives_draw->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
alternatives_draw->connect("draw", callable_mp(this, &TileAtlasView::_draw_alternatives));
alternative_tiles_drawing_root->add_child(alternatives_draw);
}

View File

@ -34,6 +34,7 @@
#include "editor/editor_zoom_widget.h"
#include "scene/gui/box_container.h"
#include "scene/gui/button.h"
#include "scene/gui/center_container.h"
#include "scene/gui/label.h"
#include "scene/gui/margin_container.h"
#include "scene/gui/scroll_container.h"
@ -48,17 +49,24 @@ private:
TileSetAtlasSource *tile_set_atlas_source;
int source_id = -1;
enum DragType {
DRAG_TYPE_NONE,
DRAG_TYPE_PAN,
};
DragType drag_type = DRAG_TYPE_NONE;
float previous_zoom = 1.0;
EditorZoomWidget *zoom_widget;
Button *button_center_view;
CenterContainer *center_container;
Vector2 panning;
void _update_zoom_and_panning(bool p_zoom_on_mouse_pos = false);
void _zoom_widget_changed();
void _scroll_changed();
void _update_zoom(float p_zoom, bool p_zoom_on_mouse_pos = false, Vector2i p_scroll = Vector2i(-1, -1));
void _center_view();
void _gui_input(const Ref<InputEvent> &p_event);
Map<Vector2, Map<int, Rect2i>> alternative_tiles_rect_cache;
void _update_alternative_tiles_rect_cache();
ScrollContainer *scroll_container;
MarginContainer *margin_container;
int margin_container_paddings[4] = { 0, 0, 0, 0 };
HBoxContainer *hbox;
@ -102,16 +110,15 @@ private:
Size2i _compute_alternative_tiles_control_size();
protected:
void _notification(int p_what);
static void _bind_methods();
public:
// Global.
void set_atlas_source(TileSet *p_tile_set, TileSetAtlasSource *p_tile_set_atlas_source, int p_source_id);
ScrollContainer *get_scroll_container() { return scroll_container; };
float get_zoom() const;
void set_transform(float p_zoom, Vector2i p_scroll);
void set_transform(float p_zoom, Vector2i p_panning);
void set_padding(Side p_side, int p_padding);

File diff suppressed because it is too large Load Diff

View File

@ -31,87 +31,378 @@
#ifndef TILE_DATA_EDITORS_H
#define TILE_DATA_EDITORS_H
#include "tile_atlas_view.h"
#include "editor/editor_node.h"
#include "editor/editor_properties.h"
#include "scene/gui/box_container.h"
#include "scene/gui/control.h"
#include "scene/gui/label.h"
#include "scene/resources/tile_set.h"
class TileDataEditor : public Control {
GDCLASS(TileDataEditor, Control);
class TileDataEditor : public VBoxContainer {
GDCLASS(TileDataEditor, VBoxContainer);
private:
void _call_tile_set_changed();
protected:
TileData *tile_data;
Ref<TileSet> tile_set;
TileData *_get_tile_data(TileMapCell p_cell);
virtual void _tile_set_changed(){};
static void _bind_methods();
public:
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){};
// 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){};
};
class DummyObject : public Object {
GDCLASS(DummyObject, Object)
private:
Map<String, Variant> properties;
protected:
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
public:
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();
};
class GenericTilePolygonEditor : public VBoxContainer {
GDCLASS(GenericTilePolygonEditor, VBoxContainer);
private:
Ref<TileSet> tile_set;
LocalVector<Vector<Point2>> polygons;
bool multiple_polygon_mode = false;
UndoRedo *undo_redo = EditorNode::get_undo_redo();
// 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,
};
DragType drag_type;
int drag_polygon_index;
int drag_point_index;
Vector2 drag_last_pos;
PackedVector2Array drag_old_polygon;
HBoxContainer *toolbar;
Ref<ButtonGroup> tools_button_group;
Button *button_create;
Button *button_edit;
Button *button_delete;
Button *button_pixel_snap;
MenuButton *button_advanced_menu;
Vector<Point2> in_creation_polygon;
Panel *panel;
Control *base_control;
EditorZoomWidget *editor_zoom_widget;
Button *button_center_view;
Vector2 panning;
Ref<Texture2D> background_texture;
Rect2 background_region;
Vector2 background_offset;
bool background_h_flip;
bool background_v_flip;
bool background_transpose;
Color background_modulate;
Color polygon_color = Color(1.0, 0.0, 0.0);
enum AdvancedMenuOption {
RESET_TO_DEFAULT_TILE,
CLEAR_TILE,
};
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);
void _snap_to_tile_shape(Point2 &r_point, float &r_current_snapped_dist, float p_snap_dist);
void _snap_to_half_pixel(Point2 &r_point);
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();
public:
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();
};
class TileDataDefaultEditor : public TileDataEditor {
GDCLASS(TileDataDefaultEditor, TileDataEditor);
private:
// Toolbar
HBoxContainer *toolbar = memnew(HBoxContainer);
Button *picker_button;
// UI
Ref<Texture2D> tile_bool_checked;
Ref<Texture2D> tile_bool_unchecked;
Label *label;
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;
Map<TileMapCell, Variant> drag_modified;
Variant drag_painted_value;
void _property_value_changed(StringName p_property, Variant p_value, StringName p_field);
protected:
DummyObject *dummy_object = memnew(DummyObject);
UndoRedo *undo_redo = EditorNode::get_undo_redo();
StringName type;
String property;
void _notification(int p_what);
TileData *_get_tile_data(TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile);
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);
virtual void _setup_undo_redo_action(TileSetAtlasSource *p_tile_set_atlas_source, Map<TileMapCell, Variant> p_previous_values, Variant p_new_value);
public:
// Edits a TileData property.
void edit(TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property);
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;
// Used to draw the value over a tile.
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property){};
void setup_property_editor(Variant::Type p_type, String p_property, String p_label = "", Variant p_default_value = Variant());
TileDataDefaultEditor();
~TileDataDefaultEditor();
};
class TileDataTextureOffsetEditor : public TileDataEditor {
GDCLASS(TileDataTextureOffsetEditor, TileDataEditor);
class TileDataTextureOffsetEditor : public TileDataDefaultEditor {
GDCLASS(TileDataTextureOffsetEditor, TileDataDefaultEditor);
public:
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) override;
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) override;
};
class TileDataIntegerEditor : public TileDataEditor {
GDCLASS(TileDataIntegerEditor, TileDataEditor);
class TileDataPositionEditor : public TileDataDefaultEditor {
GDCLASS(TileDataPositionEditor, TileDataDefaultEditor);
public:
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) override;
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) override;
};
class TileDataFloatEditor : public TileDataEditor {
GDCLASS(TileDataFloatEditor, TileDataEditor);
class TileDataYSortEditor : public TileDataDefaultEditor {
GDCLASS(TileDataYSortEditor, TileDataDefaultEditor);
public:
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) override;
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) override;
};
class TileDataPositionEditor : public TileDataEditor {
GDCLASS(TileDataPositionEditor, TileDataEditor);
class TileDataOcclusionShapeEditor : public TileDataDefaultEditor {
GDCLASS(TileDataOcclusionShapeEditor, TileDataDefaultEditor);
private:
int occlusion_layer = -1;
// UI
GenericTilePolygonEditor *polygon_editor;
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;
virtual void _setup_undo_redo_action(TileSetAtlasSource *p_tile_set_atlas_source, Map<TileMapCell, Variant> p_previous_values, Variant p_new_value) override;
protected:
UndoRedo *undo_redo = EditorNode::get_undo_redo();
virtual void _tile_set_changed() override;
void _notification(int p_what);
public:
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) override;
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 TileDataYSortEditor : public TileDataEditor {
GDCLASS(TileDataYSortEditor, TileDataEditor);
class TileDataCollisionEditor : public TileDataDefaultEditor {
GDCLASS(TileDataCollisionEditor, TileDataDefaultEditor);
int physics_layer = -1;
// UI
GenericTilePolygonEditor *polygon_editor;
DummyObject *dummy_object = memnew(DummyObject);
Map<StringName, EditorProperty *> property_editors;
void _property_value_changed(StringName p_property, Variant p_value, StringName p_field);
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;
virtual void _setup_undo_redo_action(TileSetAtlasSource *p_tile_set_atlas_source, Map<TileMapCell, Variant> p_previous_values, Variant p_new_value) override;
protected:
UndoRedo *undo_redo = EditorNode::get_undo_redo();
virtual void _tile_set_changed() override;
void _notification(int p_what);
public:
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) override;
};
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) override;
class TileDataOcclusionShapeEditor : public TileDataEditor {
GDCLASS(TileDataOcclusionShapeEditor, TileDataEditor);
void set_physics_layer(int p_physics_layer) { physics_layer = p_physics_layer; }
public:
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) override;
};
class TileDataCollisionShapeEditor : public TileDataEditor {
GDCLASS(TileDataCollisionShapeEditor, TileDataEditor);
public:
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) override;
TileDataCollisionEditor();
~TileDataCollisionEditor();
};
class TileDataTerrainsEditor : public TileDataEditor {
GDCLASS(TileDataTerrainsEditor, TileDataEditor);
private:
// Toolbar
HBoxContainer *toolbar = memnew(HBoxContainer);
Button *picker_button;
// 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;
Map<TileMapCell, Variant> drag_modified;
Variant drag_painted_value;
// UI
Label *label;
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);
UndoRedo *undo_redo = EditorNode::get_undo_redo();
public:
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) override;
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();
};
class TileDataNavigationPolygonEditor : public TileDataEditor {
GDCLASS(TileDataNavigationPolygonEditor, TileDataEditor);
class TileDataNavigationEditor : public TileDataDefaultEditor {
GDCLASS(TileDataNavigationEditor, TileDataDefaultEditor);
private:
int navigation_layer = -1;
PackedVector2Array navigation_polygon;
// UI
GenericTilePolygonEditor *polygon_editor;
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;
virtual void _setup_undo_redo_action(TileSetAtlasSource *p_tile_set_atlas_source, Map<TileMapCell, Variant> p_previous_values, Variant p_new_value) override;
protected:
UndoRedo *undo_redo = EditorNode::get_undo_redo();
virtual void _tile_set_changed() override;
void _notification(int p_what);
public:
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) override;
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();
};
#endif // TILE_DATA_EDITORS_H

View File

@ -2989,6 +2989,7 @@ void TileMapEditorTerrainsPlugin::_update_terrains_tree() {
}
// Fill in the terrain list.
Vector<Vector<Ref<Texture2D>>> icons = tile_set->generate_terrains_icons(Size2(16, 16) * EDSCALE);
for (int terrain_set_index = 0; terrain_set_index < tile_set->get_terrain_sets_count(); terrain_set_index++) {
// Add an item for the terrain set.
TreeItem *terrain_set_tree_item = terrains_tree->create_item();
@ -3007,58 +3008,12 @@ void TileMapEditorTerrainsPlugin::_update_terrains_tree() {
terrain_set_tree_item->set_selectable(0, false);
for (int terrain_index = 0; terrain_index < tile_set->get_terrains_count(terrain_set_index); terrain_index++) {
// Compute the terrains_tile_pattern used for terrain preview (whenever possible).
TerrainsTilePattern terrains_tile_pattern;
int max_bit_count = -1;
for (Set<TerrainsTilePattern>::Element *E = per_terrain_terrains_tile_patterns[terrain_set_index][terrain_index].front(); E; E = E->next()) {
int count = 0;
for (int i = 0; i < E->get().size(); i++) {
if (int(E->get()[i]) == terrain_index) {
count++;
}
}
if (count > max_bit_count) {
terrains_tile_pattern = E->get();
max_bit_count = count;
}
}
// Get the preview.
Ref<Texture2D> icon;
Rect2 region;
if (max_bit_count >= 0) {
double max_probability = -1.0;
for (Set<TileMapCell>::Element *E = per_terrain_terrains_tile_patterns_tiles[terrain_set_index][terrains_tile_pattern].front(); E; E = E->next()) {
Ref<TileSetSource> source = tile_set->get_source(E->get().source_id);
Ref<TileSetAtlasSource> atlas_source = source;
if (atlas_source.is_valid()) {
TileData *tile_data = Object::cast_to<TileData>(atlas_source->get_tile_data(E->get().get_atlas_coords(), E->get().alternative_tile));
if (tile_data->get_probability() > max_probability) {
icon = atlas_source->get_texture();
region = atlas_source->get_tile_texture_region(E->get().get_atlas_coords());
max_probability = tile_data->get_probability();
}
}
}
} else {
Ref<Image> image;
image.instantiate();
image->create(1, 1, false, Image::FORMAT_RGBA8);
image->set_pixel(0, 0, tile_set->get_terrain_color(terrain_set_index, terrain_index));
Ref<ImageTexture> image_texture;
image_texture.instantiate();
image_texture->create_from_image(image);
image_texture->set_size_override(Size2(32, 32) * EDSCALE);
icon = image_texture;
}
// Add the item to the terrain list.
TreeItem *terrain_tree_item = terrains_tree->create_item(terrain_set_tree_item);
terrain_tree_item->set_text(0, tile_set->get_terrain_name(terrain_set_index, terrain_index));
terrain_tree_item->set_icon_max_width(0, 32 * EDSCALE);
terrain_tree_item->set_icon(0, icon);
terrain_tree_item->set_icon_region(0, region);
terrain_tree_item->set_icon(0, icons[terrain_set_index][terrain_index]);
Dictionary metadata_dict;
metadata_dict["terrain_set"] = terrain_set_index;
metadata_dict["terrain_id"] = terrain_index;

View File

@ -357,6 +357,7 @@ void TileSetAtlasSourceEditor::AtlasTileProxyObject::_bind_methods() {
void TileSetAtlasSourceEditor::_inspector_property_selected(String p_property) {
selected_property = p_property;
_update_atlas_view();
_update_current_tile_data_editor();
}
void TileSetAtlasSourceEditor::_update_tile_id_label() {
@ -398,17 +399,315 @@ void TileSetAtlasSourceEditor::_update_fix_selected_and_hovered_tiles() {
}
}
void TileSetAtlasSourceEditor::_update_tile_inspector() {
bool has_atlas_tile_selected = (tools_button_group->get_pressed_button() == tool_select_button) && !selection.is_empty();
void TileSetAtlasSourceEditor::_update_atlas_source_inspector() {
// Update visibility.
bool visible = tools_button_group->get_pressed_button() == tool_setup_atlas_source_button;
atlas_source_inspector_label->set_visible(visible);
atlas_source_inspector->set_visible(visible);
}
// Update the proxy object.
if (has_atlas_tile_selected) {
void TileSetAtlasSourceEditor::_update_tile_inspector() {
// Update visibility.
if (tools_button_group->get_pressed_button() == tool_select_button) {
if (!selection.is_empty()) {
tile_proxy_object->edit(tile_set_atlas_source, selection);
}
tile_inspector_label->show();
tile_inspector->set_visible(!selection.is_empty());
tile_inspector_no_tile_selected_label->set_visible(selection.is_empty());
} else {
tile_inspector_label->hide();
tile_inspector->hide();
tile_inspector_no_tile_selected_label->hide();
}
}
void TileSetAtlasSourceEditor::_update_tile_data_editors() {
String previously_selected;
if (tile_data_editors_tree && tile_data_editors_tree->get_selected()) {
previously_selected = tile_data_editors_tree->get_selected()->get_metadata(0);
}
tile_data_editors_tree->clear();
TreeItem *root = tile_data_editors_tree->create_item();
TreeItem *group;
#define ADD_TILE_DATA_EDITOR_GROUP(text) \
group = tile_data_editors_tree->create_item(root); \
group->set_custom_bg_color(0, group_color); \
group->set_selectable(0, false); \
group->set_disable_folding(true); \
group->set_text(0, text);
TreeItem *item;
#define ADD_TILE_DATA_EDITOR(parent, text, property) \
item = tile_data_editors_tree->create_item(parent); \
item->set_text(0, text); \
item->set_metadata(0, property); \
if (property == previously_selected) { \
item->select(0); \
}
// Theming.
tile_data_editors_tree->add_theme_constant_override("vseparation", 1);
tile_data_editors_tree->add_theme_constant_override("hseparation", 3);
Color group_color = get_theme_color("prop_category", "Editor");
// List of editors.
// --- Rendering ---
ADD_TILE_DATA_EDITOR_GROUP("Rendering");
ADD_TILE_DATA_EDITOR(group, "Texture Offset", "texture_offset");
if (!tile_data_editors.has("texture_offset")) {
TileDataTextureOffsetEditor *tile_data_texture_offset_editor = memnew(TileDataTextureOffsetEditor);
tile_data_texture_offset_editor->hide();
tile_data_texture_offset_editor->setup_property_editor(Variant::VECTOR2, "texture_offset");
tile_data_texture_offset_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::update));
tile_data_texture_offset_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::update));
tile_data_editors["texture_offset"] = tile_data_texture_offset_editor;
}
ADD_TILE_DATA_EDITOR(group, "Modulate", "modulate");
if (!tile_data_editors.has("modulate")) {
TileDataDefaultEditor *tile_data_modulate_editor = memnew(TileDataDefaultEditor());
tile_data_modulate_editor->hide();
tile_data_modulate_editor->setup_property_editor(Variant::COLOR, "modulate", "", Color(1.0, 1.0, 1.0, 1.0));
tile_data_modulate_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::update));
tile_data_modulate_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::update));
tile_data_editors["modulate"] = tile_data_modulate_editor;
}
ADD_TILE_DATA_EDITOR(group, "Z Index", "z_index");
if (!tile_data_editors.has("z_index")) {
TileDataDefaultEditor *tile_data_z_index_editor = memnew(TileDataDefaultEditor());
tile_data_z_index_editor->hide();
tile_data_z_index_editor->setup_property_editor(Variant::INT, "z_index");
tile_data_z_index_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::update));
tile_data_z_index_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::update));
tile_data_editors["z_index"] = tile_data_z_index_editor;
}
ADD_TILE_DATA_EDITOR(group, "Y Sort Origin", "y_sort_origin");
if (!tile_data_editors.has("y_sort_origin")) {
TileDataYSortEditor *tile_data_y_sort_editor = memnew(TileDataYSortEditor);
tile_data_y_sort_editor->hide();
tile_data_y_sort_editor->setup_property_editor(Variant::INT, "y_sort_origin");
tile_data_y_sort_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::update));
tile_data_y_sort_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::update));
tile_data_editors["y_sort_origin"] = tile_data_y_sort_editor;
}
for (int i = 0; i < tile_set->get_occlusion_layers_count(); i++) {
ADD_TILE_DATA_EDITOR(group, vformat("Occlusion Layer %d", i), vformat("occlusion_layer_%d", i));
if (!tile_data_editors.has(vformat("occlusion_layer_%d", i))) {
TileDataOcclusionShapeEditor *tile_data_occlusion_shape_editor = memnew(TileDataOcclusionShapeEditor());
tile_data_occlusion_shape_editor->hide();
tile_data_occlusion_shape_editor->set_occlusion_layer(i);
tile_data_occlusion_shape_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::update));
tile_data_occlusion_shape_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::update));
tile_data_editors[vformat("occlusion_layer_%d", i)] = tile_data_occlusion_shape_editor;
}
}
for (int i = tile_set->get_occlusion_layers_count(); tile_data_editors.has(vformat("occlusion_layer_%d", i)); i++) {
tile_data_editors[vformat("occlusion_layer_%d", i)]->queue_delete();
tile_data_editors.erase(vformat("occlusion_layer_%d", i));
}
// --- Rendering ---
ADD_TILE_DATA_EDITOR(root, "Terrains", "terrain_set");
if (!tile_data_editors.has("terrain_set")) {
TileDataTerrainsEditor *tile_data_terrains_editor = memnew(TileDataTerrainsEditor);
tile_data_terrains_editor->hide();
tile_data_terrains_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::update));
tile_data_terrains_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::update));
tile_data_editors["terrain_set"] = tile_data_terrains_editor;
}
// --- Miscellaneous ---
ADD_TILE_DATA_EDITOR(root, "Probability", "probability");
if (!tile_data_editors.has("probability")) {
TileDataDefaultEditor *tile_data_probability_editor = memnew(TileDataDefaultEditor());
tile_data_probability_editor->hide();
tile_data_probability_editor->setup_property_editor(Variant::FLOAT, "probability", "", 1.0);
tile_data_probability_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::update));
tile_data_probability_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::update));
tile_data_editors["probability"] = tile_data_probability_editor;
}
// --- Physics ---
ADD_TILE_DATA_EDITOR_GROUP("Physics");
for (int i = 0; i < tile_set->get_physics_layers_count(); i++) {
ADD_TILE_DATA_EDITOR(group, vformat("Physics Layer %d", i), vformat("physics_layer_%d", i));
if (!tile_data_editors.has(vformat("physics_layer_%d", i))) {
TileDataCollisionEditor *tile_data_collision_editor = memnew(TileDataCollisionEditor());
tile_data_collision_editor->hide();
tile_data_collision_editor->set_physics_layer(i);
tile_data_collision_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::update));
tile_data_collision_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::update));
tile_data_editors[vformat("physics_layer_%d", i)] = tile_data_collision_editor;
}
}
for (int i = tile_set->get_physics_layers_count(); tile_data_editors.has(vformat("physics_layer_%d", i)); i++) {
tile_data_editors[vformat("physics_layer_%d", i)]->queue_delete();
tile_data_editors.erase(vformat("physics_layer_%d", i));
}
// --- Navigation ---
ADD_TILE_DATA_EDITOR_GROUP("Navigation");
for (int i = 0; i < tile_set->get_navigation_layers_count(); i++) {
ADD_TILE_DATA_EDITOR(group, vformat("Navigation Layer %d", i), vformat("navigation_layer_%d", i));
if (!tile_data_editors.has(vformat("navigation_layer_%d", i))) {
TileDataNavigationEditor *tile_data_navigation_editor = memnew(TileDataNavigationEditor());
tile_data_navigation_editor->hide();
tile_data_navigation_editor->set_navigation_layer(i);
tile_data_navigation_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::update));
tile_data_navigation_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::update));
tile_data_editors[vformat("navigation_layer_%d", i)] = tile_data_navigation_editor;
}
}
for (int i = tile_set->get_navigation_layers_count(); tile_data_editors.has(vformat("navigation_layer_%d", i)); i++) {
tile_data_editors[vformat("navigation_layer_%d", i)]->queue_delete();
tile_data_editors.erase(vformat("navigation_layer_%d", i));
}
// --- Custom Data ---
ADD_TILE_DATA_EDITOR_GROUP("Custom Data");
for (int i = 0; i < tile_set->get_custom_data_layers_count(); i++) {
if (tile_set->get_custom_data_name(i).is_empty()) {
ADD_TILE_DATA_EDITOR(group, vformat("Custom Data %d", i), vformat("custom_data_%d", i));
} else {
ADD_TILE_DATA_EDITOR(group, tile_set->get_custom_data_name(i), vformat("custom_data_%d", i));
}
if (!tile_data_editors.has(vformat("custom_data_%d", i))) {
TileDataDefaultEditor *tile_data_custom_data_editor = memnew(TileDataDefaultEditor());
tile_data_custom_data_editor->hide();
tile_data_custom_data_editor->setup_property_editor(tile_set->get_custom_data_type(i), vformat("custom_data_%d", i), tile_set->get_custom_data_name(i));
tile_data_custom_data_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::update));
tile_data_custom_data_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::update));
tile_data_editors[vformat("custom_data_%d", i)] = tile_data_custom_data_editor;
}
}
for (int i = tile_set->get_custom_data_layers_count(); tile_data_editors.has(vformat("custom_data_%d", i)); i++) {
tile_data_editors[vformat("custom_data_%d", i)]->queue_delete();
tile_data_editors.erase(vformat("custom_data_%d", i));
}
#undef ADD_TILE_DATA_EDITOR_GROUP
#undef ADD_TILE_DATA_EDITOR
// Add tile data editors as children.
for (Map<String, TileDataEditor *>::Element *E = tile_data_editors.front(); E; E = E->next()) {
// Tile Data Editor.
TileDataEditor *tile_data_editor = E->get();
if (!tile_data_editor->is_inside_tree()) {
tile_data_painting_editor_container->add_child(tile_data_editor);
}
tile_data_editor->set_tile_set(tile_set);
// Toolbar.
Control *toolbar = tile_data_editor->get_toolbar();
if (!toolbar->is_inside_tree()) {
tool_settings_tile_data_toolbar_container->add_child(toolbar);
}
toolbar->hide();
}
// Update visibility.
tile_inspector_label->set_visible(has_atlas_tile_selected);
tile_inspector->set_visible(has_atlas_tile_selected);
bool is_visible = tools_button_group->get_pressed_button() == tool_paint_button;
tile_data_editor_dropdown_button->set_visible(is_visible);
tile_data_editor_dropdown_button->set_text(TTR("Select a property editor"));
tile_data_editors_label->set_visible(is_visible);
}
void TileSetAtlasSourceEditor::_update_current_tile_data_editor() {
// Find the property to use.
String property;
if (tools_button_group->get_pressed_button() == tool_select_button && tile_inspector->is_visible() && !tile_inspector->get_selected_path().is_empty()) {
Vector<String> components = tile_inspector->get_selected_path().split("/");
if (components.size() >= 1) {
property = components[0];
// Workaround for terrains as they don't have a common first component.
if (property.begins_with("terrains_")) {
property = "terrain_set";
}
}
} else if (tools_button_group->get_pressed_button() == tool_paint_button && tile_data_editors_tree->get_selected()) {
property = tile_data_editors_tree->get_selected()->get_metadata(0);
tile_data_editor_dropdown_button->set_text(tile_data_editors_tree->get_selected()->get_text(0));
}
// Hide all editors but the current one.
for (Map<String, TileDataEditor *>::Element *E = tile_data_editors.front(); E; E = E->next()) {
E->get()->hide();
E->get()->get_toolbar()->hide();
}
if (tile_data_editors.has(property)) {
current_tile_data_editor = tile_data_editors[property];
} else {
current_tile_data_editor = nullptr;
}
// Get the correct editor for the TileData's property.
if (current_tile_data_editor) {
current_tile_data_editor_toolbar = current_tile_data_editor->get_toolbar();
current_property = property;
current_tile_data_editor->set_visible(tools_button_group->get_pressed_button() == tool_paint_button);
current_tile_data_editor_toolbar->set_visible(tools_button_group->get_pressed_button() == tool_paint_button);
}
}
void TileSetAtlasSourceEditor::_tile_data_editor_dropdown_button_draw() {
if (!has_theme_icon("arrow", "OptionButton")) {
return;
}
RID ci = tile_data_editor_dropdown_button->get_canvas_item();
Ref<Texture2D> arrow = Control::get_theme_icon("arrow", "OptionButton");
Color clr = Color(1, 1, 1);
if (get_theme_constant("modulate_arrow")) {
switch (tile_data_editor_dropdown_button->get_draw_mode()) {
case BaseButton::DRAW_PRESSED:
clr = get_theme_color("font_pressed_color");
break;
case BaseButton::DRAW_HOVER:
clr = get_theme_color("font_hover_color");
break;
case BaseButton::DRAW_DISABLED:
clr = get_theme_color("font_disabled_color");
break;
default:
clr = get_theme_color("font_color");
}
}
Size2 size = tile_data_editor_dropdown_button->get_size();
Point2 ofs;
if (is_layout_rtl()) {
ofs = Point2(get_theme_constant("arrow_margin", "OptionButton"), int(Math::abs((size.height - arrow->get_height()) / 2)));
} else {
ofs = Point2(size.width - arrow->get_width() - get_theme_constant("arrow_margin", "OptionButton"), int(Math::abs((size.height - arrow->get_height()) / 2)));
}
arrow->draw(ci, ofs, clr);
}
void TileSetAtlasSourceEditor::_tile_data_editor_dropdown_button_pressed() {
Size2 size = tile_data_editor_dropdown_button->get_size();
tile_data_editors_popup->set_position(tile_data_editor_dropdown_button->get_screen_position() + Size2(0, size.height * get_global_transform().get_scale().y));
tile_data_editors_popup->set_size(Size2(size.width, 0));
tile_data_editors_popup->popup();
}
void TileSetAtlasSourceEditor::_tile_data_editors_tree_selected() {
tile_data_editors_popup->call_deferred("hide");
_update_current_tile_data_editor();
tile_atlas_control->update();
tile_atlas_control_unscaled->update();
alternative_tiles_control->update();
alternative_tiles_control_unscaled->update();
}
void TileSetAtlasSourceEditor::_update_atlas_view() {
@ -467,19 +766,28 @@ void TileSetAtlasSourceEditor::_update_atlas_view() {
}
void TileSetAtlasSourceEditor::_update_toolbar() {
// Hide all settings.
for (int i = 0; i < tool_settings->get_child_count(); i++) {
Object::cast_to<CanvasItem>(tool_settings->get_child(i))->hide();
// Show the tools and settings.
if (tools_button_group->get_pressed_button() == tool_setup_atlas_source_button) {
if (current_tile_data_editor_toolbar) {
current_tile_data_editor_toolbar->hide();
}
// SHow only the correct settings.
if (tools_button_group->get_pressed_button() == tool_select_button) {
} else if (tools_button_group->get_pressed_button() == tool_add_remove_button) {
tool_settings_vsep->show();
tools_settings_erase_button->show();
} else if (tools_button_group->get_pressed_button() == tool_add_remove_rect_button) {
tool_settings_vsep->show();
tools_settings_erase_button->show();
tool_advanced_menu_buttom->show();
} else if (tools_button_group->get_pressed_button() == tool_select_button) {
if (current_tile_data_editor_toolbar) {
current_tile_data_editor_toolbar->hide();
}
tool_settings_vsep->hide();
tools_settings_erase_button->hide();
tool_advanced_menu_buttom->hide();
} else if (tools_button_group->get_pressed_button() == tool_paint_button) {
if (current_tile_data_editor_toolbar) {
current_tile_data_editor_toolbar->show();
}
tool_settings_vsep->hide();
tools_settings_erase_button->hide();
tool_advanced_menu_buttom->hide();
}
}
@ -499,6 +807,21 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
// Update the hovered coords.
hovered_base_tile_coords = tile_atlas_view->get_atlas_tile_coords_at_pos(tile_atlas_control->get_local_mouse_position());
// Forward the event to the current tile data editor if we are in the painting mode.
if (tools_button_group->get_pressed_button() == tool_paint_button) {
if (current_tile_data_editor) {
current_tile_data_editor->forward_painting_atlas_gui_input(tile_atlas_view, tile_set_atlas_source, p_event);
}
// Update only what's needed.
tile_set_atlas_source_changed_needs_update = false;
tile_atlas_control->update();
tile_atlas_control_unscaled->update();
alternative_tiles_control->update();
alternative_tiles_control_unscaled->update();
tile_atlas_view->update();
return;
} else {
// Handle the event.
Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid()) {
@ -596,6 +919,11 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
_update_tile_inspector();
_update_atlas_view();
_update_tile_id_label();
_update_current_tile_data_editor();
}
} else if (drag_type == DRAG_TYPE_MAY_POPUP_MENU) {
if (Vector2(drag_start_mouse_pos).distance_to(tile_atlas_control->get_local_mouse_position()) > 5.0 * EDSCALE) {
drag_type = DRAG_TYPE_NONE;
}
} else if (drag_type >= DRAG_TYPE_RESIZE_TOP_LEFT && drag_type <= DRAG_TYPE_RESIZE_LEFT) {
// Resizing a tile.
@ -631,6 +959,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
_update_tile_inspector();
_update_atlas_view();
_update_tile_id_label();
_update_current_tile_data_editor();
}
}
@ -649,8 +978,17 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
if (mb->get_button_index() == MOUSE_BUTTON_LEFT) {
if (mb->is_pressed()) {
// Left click pressed.
if (tools_button_group->get_pressed_button() == tool_add_remove_button) {
if (tools_button_group->get_pressed_button() == tool_setup_atlas_source_button) {
if (tools_settings_erase_button->is_pressed()) {
// Erasing
if (mb->is_ctrl_pressed() || mb->is_shift_pressed()) {
// Remove tiles using rect.
// Setup the dragging info.
drag_type = DRAG_TYPE_REMOVE_TILES_USING_RECT;
drag_start_mouse_pos = mouse_local_pos;
drag_last_mouse_pos = drag_start_mouse_pos;
} else {
// Remove tiles.
// Setup the dragging info.
@ -666,7 +1004,9 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
if (coords != TileSetSource::INVALID_ATLAS_COORDS) {
drag_modified_tiles.insert(coords);
}
}
} else {
// Creating
if (mb->is_shift_pressed()) {
// Create a big tile.
Vector2i coords = tile_atlas_view->get_atlas_tile_coords_at_pos(mouse_local_pos);
@ -680,6 +1020,11 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
// Create a tile.
tile_set_atlas_source->create_tile(coords);
}
} else if (mb->is_ctrl_pressed()) {
// Create tiles using rect.
drag_type = DRAG_TYPE_CREATE_TILES_USING_RECT;
drag_start_mouse_pos = mouse_local_pos;
drag_last_mouse_pos = drag_start_mouse_pos;
} else {
// Create tiles.
@ -696,35 +1041,6 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
}
}
}
} else if (tools_button_group->get_pressed_button() == tool_add_remove_rect_button) {
if (tools_settings_erase_button->is_pressed()) {
// Remove tiles using rect.
// Setup the dragging info.
drag_type = DRAG_TYPE_REMOVE_TILES_USING_RECT;
drag_start_mouse_pos = mouse_local_pos;
drag_last_mouse_pos = drag_start_mouse_pos;
} else {
if (mb->is_shift_pressed()) {
// Create a big tile.
Vector2i coords = tile_atlas_view->get_atlas_tile_coords_at_pos(mouse_local_pos);
if (coords != TileSetSource::INVALID_ATLAS_COORDS && tile_set_atlas_source->get_tile_at_coords(coords) == TileSetSource::INVALID_ATLAS_COORDS) {
// Setup the dragging info, only if we start on an empty tile.
drag_type = DRAG_TYPE_CREATE_BIG_TILE;
drag_start_mouse_pos = mouse_local_pos;
drag_last_mouse_pos = drag_start_mouse_pos;
drag_current_tile = coords;
// Create a tile.
tile_set_atlas_source->create_tile(coords);
}
} else {
// Create tiles using rect.
drag_type = DRAG_TYPE_CREATE_TILES_USING_RECT;
drag_start_mouse_pos = mouse_local_pos;
drag_last_mouse_pos = drag_start_mouse_pos;
}
}
} else if (tools_button_group->get_pressed_button() == tool_select_button) {
// Dragging a handle.
drag_type = DRAG_TYPE_NONE;
@ -806,40 +1122,10 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
tile_atlas_view->update();
return;
} else if (mb->get_button_index() == MOUSE_BUTTON_RIGHT) {
if (mb->is_pressed()) {
// Right click pressed.
TileSelection selected = { tile_atlas_view->get_atlas_tile_coords_at_pos(mouse_local_pos), 0 };
if (selected.tile != TileSetSource::INVALID_ATLAS_COORDS) {
selected.tile = tile_set_atlas_source->get_tile_at_coords(selected.tile);
}
// Set the selection if needed.
if (selection.size() <= 1) {
if (selected.tile != TileSetSource::INVALID_ATLAS_COORDS) {
undo_redo->create_action(TTR("Select tiles"));
undo_redo->add_undo_method(this, "_set_selection_from_array", _get_selection_as_array());
selection.clear();
selection.insert(selected);
undo_redo->add_do_method(this, "_set_selection_from_array", _get_selection_as_array());
undo_redo->commit_action(false);
_update_tile_inspector();
_update_tile_id_label();
}
}
// Pops up the correct menu, depending on whether we have a tile or not.
if (selected.tile != TileSetSource::INVALID_ATLAS_COORDS && selection.has(selected)) {
// We have a tile.
menu_option_coords = selected.tile;
menu_option_alternative = 0;
base_tile_popup_menu->popup(Rect2i(get_global_mouse_position(), Size2i()));
} else if (hovered_base_tile_coords != TileSetSource::INVALID_ATLAS_COORDS) {
// We don't have a tile, but can create one.
menu_option_coords = hovered_base_tile_coords;
menu_option_alternative = TileSetSource::INVALID_TILE_ALTERNATIVE;
empty_base_tile_popup_menu->popup(Rect2i(get_global_mouse_position(), Size2i()));
}
if (mb->is_pressed()) {
drag_type = DRAG_TYPE_MAY_POPUP_MENU;
drag_start_mouse_pos = tile_atlas_control->get_local_mouse_position();
} else {
// Right click released.
_end_dragging();
@ -852,6 +1138,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
return;
}
}
}
}
void TileSetAtlasSourceEditor::_end_dragging() {
@ -1000,10 +1287,45 @@ void TileSetAtlasSourceEditor::_end_dragging() {
}
_update_tile_inspector();
_update_tile_id_label();
_update_current_tile_data_editor();
undo_redo->add_do_method(this, "_set_selection_from_array", _get_selection_as_array());
undo_redo->commit_action(false);
break;
} break;
case DRAG_TYPE_MAY_POPUP_MENU: {
Vector2 mouse_local_pos = tile_atlas_control->get_local_mouse_position();
TileSelection selected = { tile_atlas_view->get_atlas_tile_coords_at_pos(mouse_local_pos), 0 };
if (selected.tile != TileSetSource::INVALID_ATLAS_COORDS) {
selected.tile = tile_set_atlas_source->get_tile_at_coords(selected.tile);
}
// Set the selection if needed.
if (selection.size() <= 1) {
if (selected.tile != TileSetSource::INVALID_ATLAS_COORDS) {
undo_redo->create_action(TTR("Select tiles"));
undo_redo->add_undo_method(this, "_set_selection_from_array", _get_selection_as_array());
selection.clear();
selection.insert(selected);
undo_redo->add_do_method(this, "_set_selection_from_array", _get_selection_as_array());
undo_redo->commit_action(false);
_update_tile_inspector();
_update_tile_id_label();
_update_current_tile_data_editor();
}
}
// Pops up the correct menu, depending on whether we have a tile or not.
if (selected.tile != TileSetSource::INVALID_ATLAS_COORDS && selection.has(selected)) {
// We have a tile.
menu_option_coords = selected.tile;
menu_option_alternative = 0;
base_tile_popup_menu->popup(Rect2i(get_global_mouse_position(), Size2i()));
} else if (hovered_base_tile_coords != TileSetSource::INVALID_ATLAS_COORDS) {
// We don't have a tile, but can create one.
menu_option_coords = hovered_base_tile_coords;
menu_option_alternative = TileSetSource::INVALID_TILE_ALTERNATIVE;
empty_base_tile_popup_menu->popup(Rect2i(get_global_mouse_position(), Size2i()));
}
} break;
case DRAG_TYPE_RESIZE_TOP_LEFT:
case DRAG_TYPE_RESIZE_TOP:
case DRAG_TYPE_RESIZE_TOP_RIGHT:
@ -1166,6 +1488,7 @@ void TileSetAtlasSourceEditor::_set_selection_from_array(Array p_selection) {
_update_tile_inspector();
_update_tile_id_label();
_update_atlas_view();
_update_current_tile_data_editor();
}
Array TileSetAtlasSourceEditor::_get_selection_as_array() {
@ -1297,7 +1620,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_draw() {
tile_atlas_control->draw_rect(tile_set_atlas_source->get_tile_texture_region(hovered_tile), Color(1.0, 1.0, 1.0), false);
} else {
// Draw empty tile, only in add/remove tiles mode.
if (tools_button_group->get_pressed_button() == tool_add_remove_button || tools_button_group->get_pressed_button() == tool_add_remove_rect_button) {
if (tools_button_group->get_pressed_button() == tool_setup_atlas_source_button) {
Vector2i margins = tile_set_atlas_source->get_margins();
Vector2i separation = tile_set_atlas_source->get_separation();
Vector2i tile_size = tile_set_atlas_source->get_texture_region_size();
@ -1310,9 +1633,8 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_draw() {
}
void TileSetAtlasSourceEditor::_tile_atlas_control_unscaled_draw() {
if (current_tile_data_editor) {
// Draw the preview of the selected property.
TileDataEditor *tile_data_editor = TileSetEditor::get_singleton()->get_tile_data_editor(selected_property);
if (tile_data_editor && tile_inspector->is_visible_in_tree()) {
for (int i = 0; i < tile_set_atlas_source->get_tiles_count(); i++) {
Vector2i coords = tile_set_atlas_source->get_tile_id(i);
Rect2i texture_region = tile_set_atlas_source->get_tile_texture_region(coords);
@ -1321,7 +1643,41 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_unscaled_draw() {
Transform2D xform = tile_atlas_control->get_parent_control()->get_transform();
xform.translate(position);
tile_data_editor->draw_over_tile(tile_atlas_control_unscaled, xform, *tile_set, tile_set_atlas_source_id, coords, 0, selected_property);
if (tools_button_group->get_pressed_button() == tool_select_button && selection.has({ coords, 0 })) {
continue;
}
TileMapCell cell;
cell.source_id = tile_set_atlas_source_id;
cell.set_atlas_coords(coords);
cell.alternative_tile = 0;
current_tile_data_editor->draw_over_tile(tile_atlas_control_unscaled, xform, cell);
}
// Draw the selection on top of other.
if (tools_button_group->get_pressed_button() == tool_select_button) {
for (Set<TileSelection>::Element *E = selection.front(); E; E = E->next()) {
if (E->get().alternative != 0) {
continue;
}
Rect2i texture_region = tile_set_atlas_source->get_tile_texture_region(E->get().tile);
Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + tile_set_atlas_source->get_tile_effective_texture_offset(E->get().tile, 0);
Transform2D xform = tile_atlas_control->get_parent_control()->get_transform();
xform.translate(position);
TileMapCell cell;
cell.source_id = tile_set_atlas_source_id;
cell.set_atlas_coords(E->get().tile);
cell.alternative_tile = 0;
current_tile_data_editor->draw_over_tile(tile_atlas_control_unscaled, xform, cell, true);
}
}
// Call the TileData's editor custom draw function.
if (tools_button_group->get_pressed_button() == tool_paint_button) {
Transform2D xform = tile_atlas_control->get_parent_control()->get_transform();
current_tile_data_editor->forward_draw_over_atlas(tile_atlas_view, tile_set_atlas_source, tile_atlas_control_unscaled, xform);
}
}
}
@ -1330,6 +1686,19 @@ void TileSetAtlasSourceEditor::_tile_alternatives_control_gui_input(const Ref<In
// Update the hovered alternative tile.
hovered_alternative_tile_coords = tile_atlas_view->get_alternative_tile_at_pos(alternative_tiles_control->get_local_mouse_position());
// Forward the event to the current tile data editor if we are in the painting mode.
if (tools_button_group->get_pressed_button() == tool_paint_button) {
if (current_tile_data_editor) {
current_tile_data_editor->forward_painting_alternatives_gui_input(tile_atlas_view, tile_set_atlas_source, p_event);
}
tile_atlas_control->update();
tile_atlas_control_unscaled->update();
alternative_tiles_control->update();
alternative_tiles_control_unscaled->update();
tile_atlas_view->update();
return;
}
Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid()) {
tile_atlas_control->update();
@ -1425,7 +1794,60 @@ void TileSetAtlasSourceEditor::_tile_alternatives_control_draw() {
}
void TileSetAtlasSourceEditor::_tile_alternatives_control_unscaled_draw() {
//TODO
// Draw the preview of the selected property.
if (current_tile_data_editor) {
// Draw the preview of the currently selected property.
for (int i = 0; i < tile_set_atlas_source->get_tiles_count(); i++) {
Vector2i coords = tile_set_atlas_source->get_tile_id(i);
for (int j = 0; j < tile_set_atlas_source->get_alternative_tiles_count(coords); j++) {
int alternative_tile = tile_set_atlas_source->get_alternative_tile_id(coords, j);
if (alternative_tile == 0) {
continue;
}
Rect2i rect = tile_atlas_view->get_alternative_tile_rect(coords, alternative_tile);
Vector2 position = (rect.get_position() + rect.get_end()) / 2;
Transform2D xform = alternative_tiles_control->get_parent_control()->get_transform();
xform.translate(position);
if (tools_button_group->get_pressed_button() == tool_select_button && selection.has({ coords, alternative_tile })) {
continue;
}
TileMapCell cell;
cell.source_id = tile_set_atlas_source_id;
cell.set_atlas_coords(coords);
cell.alternative_tile = alternative_tile;
current_tile_data_editor->draw_over_tile(alternative_tiles_control_unscaled, xform, cell);
}
}
// Draw the selection on top of other.
if (tools_button_group->get_pressed_button() == tool_select_button) {
for (Set<TileSelection>::Element *E = selection.front(); E; E = E->next()) {
if (E->get().alternative == 0) {
continue;
}
Rect2i rect = tile_atlas_view->get_alternative_tile_rect(E->get().tile, E->get().alternative);
Vector2 position = (rect.get_position() + rect.get_end()) / 2;
Transform2D xform = alternative_tiles_control->get_parent_control()->get_transform();
xform.translate(position);
TileMapCell cell;
cell.source_id = tile_set_atlas_source_id;
cell.set_atlas_coords(E->get().tile);
cell.alternative_tile = E->get().alternative;
current_tile_data_editor->draw_over_tile(alternative_tiles_control_unscaled, xform, cell, true);
}
}
// Call the TileData's editor custom draw function.
if (tools_button_group->get_pressed_button() == tool_paint_button) {
Transform2D xform = tile_atlas_control->get_parent_control()->get_transform();
current_tile_data_editor->forward_draw_over_alternatives(tile_atlas_view, tile_set_atlas_source, alternative_tiles_control_unscaled, xform);
}
}
}
void TileSetAtlasSourceEditor::_tile_set_atlas_source_changed() {
@ -1449,15 +1871,23 @@ void TileSetAtlasSourceEditor::_undo_redo_inspector_callback(Object *p_undo_redo
AtlasTileProxyObject *tile_data = Object::cast_to<AtlasTileProxyObject>(p_edited);
if (tile_data) {
Vector<String> components = String(p_property).split("/", true, 2);
if (components.size() == 2 && components[1] == "shapes_count") {
if (components.size() == 2 && components[1] == "polygons_count") {
int layer_index = components[0].trim_prefix("physics_layer_").to_int();
int new_shapes_count = p_new_value;
int old_shapes_count = tile_data->get(vformat("physics_layer_%d/shapes_count", layer_index));
if (new_shapes_count < old_shapes_count) {
for (int i = new_shapes_count - 1; i < old_shapes_count; i++) {
ADD_UNDO(tile_data, vformat("physics_layer_%d/shape_%d/shape", layer_index, i));
ADD_UNDO(tile_data, vformat("physics_layer_%d/shape_%d/one_way", layer_index, i));
ADD_UNDO(tile_data, vformat("physics_layer_%d/shape_%d/one_way_margin", layer_index, i));
int new_polygons_count = p_new_value;
int old_polygons_count = tile_data->get(vformat("physics_layer_%d/polygons_count", layer_index));
if (new_polygons_count < old_polygons_count) {
for (int i = new_polygons_count - 1; i < old_polygons_count; i++) {
ADD_UNDO(tile_data, vformat("physics_layer_%d/polygon_%d/points", layer_index, i));
ADD_UNDO(tile_data, vformat("physics_layer_%d/polygon_%d/one_way", layer_index, i));
ADD_UNDO(tile_data, vformat("physics_layer_%d/polygon_%d/one_way_margin", layer_index, i));
}
}
} else if (p_property == "terrain_set") {
int current_terrain_set = tile_data->get("terrain_set");
for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) {
TileSet::CellNeighbor bit = TileSet::CellNeighbor(i);
if (tile_set->is_valid_peering_bit_terrain(current_terrain_set, bit)) {
ADD_UNDO(tile_data, "terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]));
}
}
}
@ -1500,7 +1930,10 @@ void TileSetAtlasSourceEditor::edit(Ref<TileSet> p_tile_set, TileSetAtlasSource
_update_fix_selected_and_hovered_tiles();
_update_tile_id_label();
_update_atlas_view();
_update_atlas_source_inspector();
_update_tile_inspector();
_update_tile_data_editors();
_update_current_tile_data_editor();
}
void TileSetAtlasSourceEditor::init_source() {
@ -1616,13 +2049,13 @@ void TileSetAtlasSourceEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
case NOTIFICATION_THEME_CHANGED:
tool_setup_atlas_source_button->set_icon(get_theme_icon("Tools", "EditorIcons"));
tool_select_button->set_icon(get_theme_icon("ToolSelect", "EditorIcons"));
tool_add_remove_button->set_icon(get_theme_icon("EditAddRemove", "EditorIcons"));
tool_add_remove_rect_button->set_icon(get_theme_icon("RectangleAddRemove", "EditorIcons"));
tool_paint_button->set_icon(get_theme_icon("CanvasItem", "EditorIcons"));
tools_settings_erase_button->set_icon(get_theme_icon("Eraser", "EditorIcons"));
tool_advanced_menu_buttom->set_icon(get_theme_icon("Tools", "EditorIcons"));
tool_advanced_menu_buttom->set_icon(get_theme_icon("GuiTabMenu", "EditorIcons"));
resize_handle = get_theme_icon("EditorHandle", "EditorIcons");
resize_handle_disabled = get_theme_icon("EditorHandleDisabled", "EditorIcons");
@ -1636,7 +2069,10 @@ void TileSetAtlasSourceEditor::_notification(int p_what) {
_update_fix_selected_and_hovered_tiles();
_update_tile_id_label();
_update_atlas_view();
_update_atlas_source_inspector();
_update_tile_inspector();
_update_tile_data_editors();
_update_current_tile_data_editor();
tile_set_atlas_source_changed_needs_update = false;
}
@ -1675,7 +2111,6 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() {
// Tile inspector.
tile_inspector_label = memnew(Label);
tile_inspector_label->set_text(TTR("Tile Properties:"));
tile_inspector_label->hide();
middle_vbox_container->add_child(tile_inspector_label);
tile_proxy_object = memnew(AtlasTileProxyObject(this));
@ -1689,6 +2124,36 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() {
tile_inspector->connect("property_selected", callable_mp(this, &TileSetAtlasSourceEditor::_inspector_property_selected));
middle_vbox_container->add_child(tile_inspector);
tile_inspector_no_tile_selected_label = memnew(Label);
tile_inspector_no_tile_selected_label->set_align(Label::ALIGN_CENTER);
tile_inspector_no_tile_selected_label->set_text(TTR("No tile selected."));
middle_vbox_container->add_child(tile_inspector_no_tile_selected_label);
// Property values palette.
tile_data_editors_popup = memnew(Popup);
tile_data_editors_label = memnew(Label);
tile_data_editors_label->set_text(TTR("Paint Properties:"));
middle_vbox_container->add_child(tile_data_editors_label);
tile_data_editor_dropdown_button = memnew(Button);
tile_data_editor_dropdown_button->connect("draw", callable_mp(this, &TileSetAtlasSourceEditor::_tile_data_editor_dropdown_button_draw));
tile_data_editor_dropdown_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_tile_data_editor_dropdown_button_pressed));
middle_vbox_container->add_child(tile_data_editor_dropdown_button);
tile_data_editor_dropdown_button->add_child(tile_data_editors_popup);
tile_data_editors_tree = memnew(Tree);
tile_data_editors_tree->set_hide_root(true);
tile_data_editors_tree->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
tile_data_editors_tree->set_h_scroll_enabled(false);
tile_data_editors_tree->set_v_scroll_enabled(false);
tile_data_editors_tree->connect("item_selected", callable_mp(this, &TileSetAtlasSourceEditor::_tile_data_editors_tree_selected));
tile_data_editors_popup->add_child(tile_data_editors_tree);
tile_data_painting_editor_container = memnew(VBoxContainer);
tile_data_painting_editor_container->set_h_size_flags(SIZE_EXPAND_FILL);
middle_vbox_container->add_child(tile_data_painting_editor_container);
// Atlas source inspector.
atlas_source_inspector_label = memnew(Label);
atlas_source_inspector_label->set_text(TTR("Atlas Properties:"));
@ -1720,46 +2185,40 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() {
// -- Toolbox --
tools_button_group.instantiate();
tools_button_group->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_fix_selected_and_hovered_tiles).unbind(1));
tools_button_group->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_tile_id_label).unbind(1));
tools_button_group->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_atlas_source_inspector).unbind(1));
tools_button_group->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_tile_inspector).unbind(1));
tools_button_group->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_tile_data_editors).unbind(1));
tools_button_group->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_current_tile_data_editor).unbind(1));
tools_button_group->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_atlas_view).unbind(1));
tools_button_group->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_toolbar).unbind(1));
toolbox = memnew(HBoxContainer);
right_panel->add_child(toolbox);
tool_setup_atlas_source_button = memnew(Button);
tool_setup_atlas_source_button->set_flat(true);
tool_setup_atlas_source_button->set_toggle_mode(true);
tool_setup_atlas_source_button->set_pressed(true);
tool_setup_atlas_source_button->set_button_group(tools_button_group);
tool_setup_atlas_source_button->set_tooltip(TTR("Atlas Setup. Add/Remove tiles tool (use the shift key to create big tiles, control for rectangle editing)."));
toolbox->add_child(tool_setup_atlas_source_button);
tool_select_button = memnew(Button);
tool_select_button->set_flat(true);
tool_select_button->set_toggle_mode(true);
tool_select_button->set_pressed(true);
tool_select_button->set_pressed(false);
tool_select_button->set_button_group(tools_button_group);
tool_select_button->set_tooltip(TTR("Select tiles."));
tool_select_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_fix_selected_and_hovered_tiles));
tool_select_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_tile_id_label));
tool_select_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_tile_inspector));
tool_select_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_atlas_view));
tool_select_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_toolbar));
toolbox->add_child(tool_select_button);
tool_add_remove_button = memnew(Button);
tool_add_remove_button->set_flat(true);
tool_add_remove_button->set_toggle_mode(true);
tool_add_remove_button->set_button_group(tools_button_group);
tool_add_remove_button->set_tooltip(TTR("Add/Remove tiles tool (use the shift key to create big tiles)."));
tool_add_remove_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_fix_selected_and_hovered_tiles));
tool_add_remove_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_tile_id_label));
tool_add_remove_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_tile_inspector));
tool_add_remove_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_atlas_view));
tool_add_remove_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_toolbar));
toolbox->add_child(tool_add_remove_button);
tool_add_remove_rect_button = memnew(Button);
tool_add_remove_rect_button->set_flat(true);
tool_add_remove_rect_button->set_toggle_mode(true);
tool_add_remove_rect_button->set_button_group(tools_button_group);
tool_add_remove_rect_button->set_tooltip(TTR("Add/Remove tiles rectangle tool (use the shift key to create big tiles)."));
tool_add_remove_rect_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_fix_selected_and_hovered_tiles));
tool_add_remove_rect_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_tile_id_label));
tool_add_remove_rect_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_tile_inspector));
tool_add_remove_rect_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_atlas_view));
tool_add_remove_rect_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_toolbar));
toolbox->add_child(tool_add_remove_rect_button);
tool_paint_button = memnew(Button);
tool_paint_button->set_flat(true);
tool_paint_button->set_toggle_mode(true);
tool_paint_button->set_button_group(tools_button_group);
tool_paint_button->set_tooltip(TTR("Paint properties."));
toolbox->add_child(tool_paint_button);
// Tool settings.
tool_settings = memnew(HBoxContainer);
@ -1768,6 +2227,9 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() {
tool_settings_vsep = memnew(VSeparator);
tool_settings->add_child(tool_settings_vsep);
tool_settings_tile_data_toolbar_container = memnew(HBoxContainer);
tool_settings->add_child(tool_settings_tile_data_toolbar_container);
tools_settings_erase_button = memnew(Button);
tools_settings_erase_button->set_flat(true);
tools_settings_erase_button->set_toggle_mode(true);
@ -1775,9 +2237,6 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() {
tools_settings_erase_button->set_shortcut_context(this);
tool_settings->add_child(tools_settings_erase_button);
VSeparator *tool_advanced_vsep = memnew(VSeparator);
toolbox->add_child(tool_advanced_vsep);
tool_advanced_menu_buttom = memnew(MenuButton);
tool_advanced_menu_buttom->set_flat(true);
tool_advanced_menu_buttom->get_popup()->add_item(TTR("Cleanup Tiles Outside Texture"), ADVANCED_CLEANUP_TILES_OUTSIDE_TEXTURE);
@ -1844,7 +2303,7 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() {
alternative_tiles_control_unscaled = memnew(Control);
alternative_tiles_control_unscaled->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
alternative_tiles_control_unscaled->connect("draw", callable_mp(this, &TileSetAtlasSourceEditor::_tile_alternatives_control_unscaled_draw));
tile_atlas_view->add_control_over_atlas_tiles(alternative_tiles_control_unscaled, false);
tile_atlas_view->add_control_over_alternative_tiles(alternative_tiles_control_unscaled, false);
alternative_tiles_control_unscaled->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
tile_atlas_view_missing_source_label = memnew(Label);

View File

@ -32,6 +32,7 @@
#define TILE_SET_ATLAS_SOURCE_EDITOR_H
#include "tile_atlas_view.h"
#include "tile_data_editors.h"
#include "editor/editor_node.h"
#include "scene/gui/split_container.h"
@ -113,10 +114,27 @@ private:
bool tile_set_atlas_source_changed_needs_update = false;
// -- Properties painting --
VBoxContainer *tile_data_painting_editor_container;
Label *tile_data_editors_label;
Button *tile_data_editor_dropdown_button;
Popup *tile_data_editors_popup;
Tree *tile_data_editors_tree;
void _tile_data_editor_dropdown_button_draw();
void _tile_data_editor_dropdown_button_pressed();
// -- Tile data editors --
String current_property;
Control *current_tile_data_editor_toolbar = nullptr;
Map<String, TileDataEditor *> tile_data_editors;
TileDataEditor *current_tile_data_editor = nullptr;
void _tile_data_editors_tree_selected();
// -- Inspector --
AtlasTileProxyObject *tile_proxy_object;
Label *tile_inspector_label;
EditorInspector *tile_inspector;
Label *tile_inspector_no_tile_selected_label;
String selected_property;
void _inspector_property_selected(String p_property);
@ -142,6 +160,8 @@ private:
DRAG_TYPE_RECT_SELECT,
DRAG_TYPE_MAY_POPUP_MENU,
// Warning: keep in this order.
DRAG_TYPE_RESIZE_TOP_LEFT,
DRAG_TYPE_RESIZE_TOP,
@ -179,15 +199,16 @@ private:
// Tool buttons.
Ref<ButtonGroup> tools_button_group;
Button *tool_setup_atlas_source_button;
Button *tool_select_button;
Button *tool_add_remove_button;
Button *tool_add_remove_rect_button;
Button *tool_paint_button;
Label *tool_tile_id_label;
// Tool settings.
HBoxContainer *tool_settings;
VSeparator *tool_settings_vsep;
HBoxContainer *tool_settings_tile_data_toolbar_container;
Button *tools_settings_erase_button;
MenuButton *tool_advanced_menu_buttom;
// Selection.
@ -226,7 +247,10 @@ private:
void _update_tile_id_label();
void _update_source_inspector();
void _update_fix_selected_and_hovered_tiles();
void _update_atlas_source_inspector();
void _update_tile_inspector();
void _update_tile_data_editors();
void _update_current_tile_data_editor();
void _update_manage_tile_properties_button();
void _update_atlas_view();
void _update_toolbar();

View File

@ -347,11 +347,11 @@ void TileSetEditor::_undo_redo_inspector_callback(Object *p_undo_redo, Object *p
int old_layer_count = tile_set->get_physics_layers_count();
if (new_layer_count < old_layer_count) {
for (int physics_layer_index = new_layer_count - 1; physics_layer_index < old_layer_count; physics_layer_index++) {
ADD_UNDO(tile_data, vformat("physics_layer_%d/shapes_count", physics_layer_index));
for (int shape_index = 0; shape_index < tile_data->get_collision_shapes_count(physics_layer_index); shape_index++) {
ADD_UNDO(tile_data, vformat("physics_layer_%d/shape_%d/shape", physics_layer_index, shape_index));
ADD_UNDO(tile_data, vformat("physics_layer_%d/shape_%d/one_way", physics_layer_index, shape_index));
ADD_UNDO(tile_data, vformat("physics_layer_%d/shape_%d/one_way_margin", physics_layer_index, shape_index));
ADD_UNDO(tile_data, vformat("physics_layer_%d/polygons_count", physics_layer_index));
for (int polygon_index = 0; polygon_index < tile_data->get_collision_polygons_count(physics_layer_index); polygon_index++) {
ADD_UNDO(tile_data, vformat("physics_layer_%d/polygon_%d/points", physics_layer_index, polygon_index));
ADD_UNDO(tile_data, vformat("physics_layer_%d/polygon_%d/one_way", physics_layer_index, polygon_index));
ADD_UNDO(tile_data, vformat("physics_layer_%d/polygon_%d/one_way_margin", physics_layer_index, polygon_index));
}
}
}
@ -359,53 +359,11 @@ void TileSetEditor::_undo_redo_inspector_callback(Object *p_undo_redo, Object *p
(components.size() == 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_int() && components[1] == "mode") ||
(components.size() == 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_int() && components[1] == "terrains_count" && tile_data->get_terrain_set() == components[0].trim_prefix("terrain_set_").to_int() && (int)p_new_value < tile_set->get_terrains_count(tile_data->get_terrain_set()))) {
ADD_UNDO(tile_data, "terrain_set");
if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_RIGHT_SIDE)) {
ADD_UNDO(tile_data, "terrains_peering_bit/right_side");
for (int l = 0; l < TileSet::CELL_NEIGHBOR_MAX; l++) {
TileSet::CellNeighbor bit = TileSet::CellNeighbor(l);
if (tile_data->is_valid_peering_bit_terrain(bit)) {
ADD_UNDO(tile_data, "terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[l]));
}
if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_RIGHT_CORNER)) {
ADD_UNDO(tile_data, "terrains_peering_bit/right_corner");
}
if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE)) {
ADD_UNDO(tile_data, "terrains_peering_bit/bottom_right_side");
}
if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER)) {
ADD_UNDO(tile_data, "terrains_peering_bit/bottom_right_corner");
}
if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)) {
ADD_UNDO(tile_data, "terrains_peering_bit/bottom_side");
}
if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_CORNER)) {
ADD_UNDO(tile_data, "terrains_peering_bit/bottom_corner");
}
if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE)) {
ADD_UNDO(tile_data, "terrains_peering_bit/bottom_left_side");
}
if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER)) {
ADD_UNDO(tile_data, "terrains_peering_bit/bottom_left_corner");
}
if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_LEFT_SIDE)) {
ADD_UNDO(tile_data, "terrains_peering_bit/left_side");
}
if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_LEFT_CORNER)) {
ADD_UNDO(tile_data, "terrains_peering_bit/left_corner");
}
if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE)) {
ADD_UNDO(tile_data, "terrains_peering_bit/top_left_side");
}
if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER)) {
ADD_UNDO(tile_data, "terrains_peering_bit/top_left_corner");
}
if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_SIDE)) {
ADD_UNDO(tile_data, "terrains_peering_bit/top_side");
}
if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_CORNER)) {
ADD_UNDO(tile_data, "terrains_peering_bit/top_corner");
}
if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE)) {
ADD_UNDO(tile_data, "terrains_peering_bit/top_right_side");
}
if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER)) {
ADD_UNDO(tile_data, "terrains_peering_bit/top_right_corner");
}
} else if (p_property == "navigation_layers_count") {
int new_layer_count = p_new_value;
@ -440,30 +398,6 @@ void TileSetEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_drop_data_fw"), &TileSetEditor::drop_data_fw);
}
TileDataEditor *TileSetEditor::get_tile_data_editor(String p_property) {
Vector<String> components = String(p_property).split("/", true);
if (p_property == "z_index") {
return tile_data_integer_editor;
} else if (p_property == "probability") {
return tile_data_float_editor;
} else if (p_property == "y_sort_origin") {
return tile_data_y_sort_editor;
} else if (p_property == "texture_offset") {
return tile_data_texture_offset_editor;
} else if (components.size() >= 1 && components[0].begins_with("occlusion_layer_")) {
return tile_data_occlusion_shape_editor;
} else if (components.size() >= 1 && components[0].begins_with("physics_layer_")) {
return tile_data_collision_shape_editor;
} else if (p_property == "mode" || p_property == "terrain" || (components.size() >= 1 && components[0] == "terrains_peering_bit")) {
return tile_data_terrains_editor;
} else if (components.size() >= 1 && components[0].begins_with("navigation_layer_")) {
return tile_data_navigation_polygon_editor;
}
return nullptr;
}
void TileSetEditor::edit(Ref<TileSet> p_tile_set) {
if (p_tile_set == tile_set) {
return;
@ -575,14 +509,4 @@ TileSetEditor::~TileSetEditor() {
if (tile_set.is_valid()) {
tile_set->disconnect("changed", callable_mp(this, &TileSetEditor::_tile_set_changed));
}
// Delete tile data editors.
memdelete(tile_data_texture_offset_editor);
memdelete(tile_data_y_sort_editor);
memdelete(tile_data_integer_editor);
memdelete(tile_data_float_editor);
memdelete(tile_data_occlusion_shape_editor);
memdelete(tile_data_collision_shape_editor);
memdelete(tile_data_terrains_editor);
memdelete(tile_data_navigation_polygon_editor);
}

View File

@ -33,7 +33,6 @@
#include "scene/gui/box_container.h"
#include "scene/resources/tile_set.h"
#include "tile_data_editors.h"
#include "tile_set_atlas_source_editor.h"
#include "tile_set_scenes_collection_source_editor.h"
@ -54,16 +53,6 @@ private:
void _update_atlas_sources_list(int force_selected_id = -1);
// List of tile data editors.
TileDataTextureOffsetEditor *tile_data_texture_offset_editor = memnew(TileDataTextureOffsetEditor);
TileDataYSortEditor *tile_data_y_sort_editor = memnew(TileDataYSortEditor);
TileDataIntegerEditor *tile_data_integer_editor = memnew(TileDataIntegerEditor);
TileDataFloatEditor *tile_data_float_editor = memnew(TileDataFloatEditor);
TileDataOcclusionShapeEditor *tile_data_occlusion_shape_editor = memnew(TileDataOcclusionShapeEditor);
TileDataCollisionShapeEditor *tile_data_collision_shape_editor = memnew(TileDataCollisionShapeEditor);
TileDataTerrainsEditor *tile_data_terrains_editor = memnew(TileDataTerrainsEditor);
TileDataNavigationPolygonEditor *tile_data_navigation_polygon_editor = memnew(TileDataNavigationPolygonEditor);
// -- Sources management --
Button *sources_delete_button;
MenuButton *sources_add_button;
@ -84,7 +73,6 @@ protected:
public:
_FORCE_INLINE_ static TileSetEditor *get_singleton() { return singleton; }
TileDataEditor *get_tile_data_editor(String property);
void edit(Ref<TileSet> p_tile_set);
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;

File diff suppressed because it is too large Load Diff

View File

@ -33,19 +33,18 @@
#include "core/io/resource.h"
#include "core/object/object.h"
#include "core/templates/local_vector.h"
#include "scene/2d/light_occluder_2d.h"
#include "scene/2d/navigation_region_2d.h"
#include "scene/main/canvas_item.h"
#include "scene/resources/concave_polygon_shape_2d.h"
#include "scene/resources/convex_polygon_shape_2d.h"
#include "scene/resources/packed_scene.h"
#include "scene/resources/physics_material.h"
#include "scene/resources/shape_2d.h"
#ifndef DISABLE_DEPRECATED
#include "scene/2d/light_occluder_2d.h"
#include "scene/2d/navigation_region_2d.h"
#include "scene/resources/shader.h"
#include "scene/resources/shape_2d.h"
#include "scene/resources/texture.h"
#endif
@ -60,7 +59,6 @@ class TileSetPlugin;
class TileSetPluginAtlasRendering;
class TileSetPluginAtlasPhysics;
class TileSetPluginAtlasNavigation;
class TileSetPluginAtlasTerrain;
class TileSet : public Resource {
GDCLASS(TileSet, Resource);
@ -138,6 +136,8 @@ public:
CELL_NEIGHBOR_MAX,
};
static const char *CELL_NEIGHBOR_ENUM_TO_TEXT[];
enum TerrainMode {
TERRAIN_MODE_MATCH_CORNERS_AND_SIDES = 0,
TERRAIN_MODE_MATCH_CORNERS,
@ -194,6 +194,10 @@ private:
};
Vector<OcclusionLayer> occlusion_layers;
Ref<ArrayMesh> tile_lines_mesh;
Ref<ArrayMesh> tile_filled_mesh;
bool tile_meshes_dirty = true;
// Physics
struct PhysicsLayer {
uint32_t collision_layer = 1;
@ -213,6 +217,9 @@ private:
};
Vector<TerrainSet> terrain_sets;
Map<TerrainMode, Map<CellNeighbor, Ref<ArrayMesh>>> terrain_bits_meshes;
bool terrain_bits_meshes_dirty = true;
// Navigation
struct Navigationlayer {
uint32_t layers = 1;
@ -239,6 +246,19 @@ private:
void _compute_next_source_id();
void _source_changed();
// Helpers
Vector<Point2> _get_square_corner_or_side_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit);
Vector<Point2> _get_square_corner_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit);
Vector<Point2> _get_square_side_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit);
Vector<Point2> _get_isometric_corner_or_side_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit);
Vector<Point2> _get_isometric_corner_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit);
Vector<Point2> _get_isometric_side_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit);
Vector<Point2> _get_half_offset_corner_or_side_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit, float p_overlap, TileSet::TileOffsetAxis p_offset_axis);
Vector<Point2> _get_half_offset_corner_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit, float p_overlap, TileSet::TileOffsetAxis p_offset_axis);
Vector<Point2> _get_half_offset_side_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit, float p_overlap, TileSet::TileOffsetAxis p_offset_axis);
protected:
static void _bind_methods();
@ -257,8 +277,6 @@ public:
TileOffsetAxis get_tile_offset_axis() const;
void set_tile_size(Size2i p_size);
Size2i get_tile_size() const;
void set_tile_skew(Vector2 p_skew);
Vector2 get_tile_skew() const;
// -- Sources management --
int get_next_source_id() const;
@ -305,6 +323,7 @@ public:
String get_terrain_name(int p_terrain_set, int p_terrain_index) const;
void set_terrain_color(int p_terrain_set, int p_terrain_index, Color p_color);
Color get_terrain_color(int p_terrain_set, int p_terrain_index) const;
bool is_valid_peering_bit_for_mode(TileSet::TerrainMode p_terrain_mode, TileSet::CellNeighbor p_peering_bit) const;
bool is_valid_peering_bit_terrain(int p_terrain_set, TileSet::CellNeighbor p_peering_bit) const;
// Navigation
@ -323,8 +342,14 @@ public:
Variant::Type get_custom_data_type(int p_layer_id) const;
// Helpers
Vector<Vector2> get_tile_shape_polygon();
void draw_tile_shape(CanvasItem *p_canvas_item, Rect2 p_region, Color p_color, bool p_filled = false, Ref<Texture2D> p_texture = Ref<Texture2D>());
Vector<Point2> get_terrain_bit_polygon(int p_terrain_set, TileSet::CellNeighbor p_bit);
void draw_terrains(CanvasItem *p_canvas_item, Transform2D p_transform, const TileData *p_tile_data);
Vector<Vector<Ref<Texture2D>>> generate_terrains_icons(Size2i p_size);
// Resource management
virtual void reset_state() override;
TileSet();
@ -509,13 +534,14 @@ private:
// Physics
struct PhysicsLayerTileData {
struct ShapeTileData {
Ref<Shape2D> shape = Ref<Shape2D>();
struct PolygonShapeTileData {
LocalVector<Vector2> polygon;
LocalVector<Ref<ConvexPolygonShape2D>> shapes;
bool one_way = false;
float one_way_margin = 1.0;
};
Vector<ShapeTileData> shapes;
Vector<PolygonShapeTileData> polygons;
};
Vector<PhysicsLayerTileData> physics;
// TODO add support for areas.
@ -570,16 +596,18 @@ public:
Ref<OccluderPolygon2D> get_occluder(int p_layer_id) const;
// Physics
int get_collision_shapes_count(int p_layer_id) const;
void set_collision_shapes_count(int p_layer_id, int p_shapes_count);
void add_collision_shape(int p_layer_id);
void remove_collision_shape(int p_layer_id, int p_shape_index);
void set_collision_shape_shape(int p_layer_id, int p_shape_index, Ref<Shape2D> p_shape);
Ref<Shape2D> get_collision_shape_shape(int p_layer_id, int p_shape_index) const;
void set_collision_shape_one_way(int p_layer_id, int p_shape_index, bool p_one_way);
bool is_collision_shape_one_way(int p_layer_id, int p_shape_index) const;
void set_collision_shape_one_way_margin(int p_layer_id, int p_shape_index, float p_one_way_margin);
float get_collision_shape_one_way_margin(int p_layer_id, int p_shape_index) const;
int get_collision_polygons_count(int p_layer_id) const;
void set_collision_polygons_count(int p_layer_id, int p_shapes_count);
void add_collision_polygon(int p_layer_id);
void remove_collision_polygon(int p_layer_id, int p_polygon_index);
void set_collision_polygon_points(int p_layer_id, int p_polygon_index, Vector<Vector2> p_polygon);
Vector<Vector2> get_collision_polygon_points(int p_layer_id, int p_polygon_index) const;
void set_collision_polygon_one_way(int p_layer_id, int p_polygon_index, bool p_one_way);
bool is_collision_polygon_one_way(int p_layer_id, int p_polygon_index) const;
void set_collision_polygon_one_way_margin(int p_layer_id, int p_polygon_index, float p_one_way_margin);
float get_collision_polygon_one_way_margin(int p_layer_id, int p_polygon_index) const;
int get_collision_polygon_shapes_count(int p_layer_id, int p_polygon_index) const;
Ref<ConvexPolygonShape2D> get_collision_polygon_shape(int p_layer_id, int p_polygon_index, int shape_index) const;
// Terrain
void set_terrain_set(int p_terrain_id);
@ -637,26 +665,6 @@ public:
static void draw_tile(RID p_canvas_item, Vector2i p_position, const Ref<TileSet> p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, Color p_modulation = Color(1.0, 1.0, 1.0, 1.0));
};
class TileSetPluginAtlasTerrain : public TileSetPlugin {
GDCLASS(TileSetPluginAtlasTerrain, TileSetPlugin);
private:
static void _draw_square_corner_or_side_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit);
static void _draw_square_corner_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit);
static void _draw_square_side_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit);
static void _draw_isometric_corner_or_side_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit);
static void _draw_isometric_corner_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit);
static void _draw_isometric_side_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit);
static void _draw_half_offset_corner_or_side_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit, float p_overlap, TileSet::TileOffsetAxis p_offset_axis);
static void _draw_half_offset_corner_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit, float p_overlap, TileSet::TileOffsetAxis p_offset_axis);
static void _draw_half_offset_side_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit, float p_overlap, TileSet::TileOffsetAxis p_offset_axis);
public:
static void draw_terrains(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, const TileData *p_tile_data);
};
class TileSetPluginAtlasPhysics : public TileSetPlugin {
GDCLASS(TileSetPluginAtlasPhysics, TileSetPlugin);