Work on layered tile maps.

This commit is contained in:
Relintai 2024-03-03 14:32:30 +01:00
parent 7779439e28
commit 840a804a5c
11 changed files with 253 additions and 243 deletions

View File

@ -33,19 +33,21 @@
#include "layered_tile_set_editor.h"
#include "core/core_string_names.h"
#include "core/math/geometry.h"
#include "core/os/keyboard.h"
#include "editor/editor_node.h"
#include "editor/editor_properties.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/themes/editor_scale.h"
#include "core/object/undo_redo.h"
#include "editor/editor_scale.h"
#include "scene/gui/label.h"
#include "scene/gui/menu_button.h"
#include "scene/gui/option_button.h"
#include "scene/gui/popup_menu.h"
#include "scene/gui/separator.h"
#include "scene/gui/spin_box.h"
#include "scene/main/control.h"
@ -54,7 +56,8 @@
void LayeredTileDataEditor::_tile_set_changed_plan_update() {
_tile_set_changed_update_needed = true;
callable_mp(this, &LayeredTileDataEditor::_tile_set_changed_deferred_update).call_deferred();
call_deferred("_tile_set_changed_deferred_update");
}
void LayeredTileDataEditor::_tile_set_changed_deferred_update() {
@ -64,11 +67,11 @@ void LayeredTileDataEditor::_tile_set_changed_deferred_update() {
}
}
TileData *LayeredTileDataEditor::_get_tile_data(LayeredTileMapCell p_cell) {
LayeredTileData *LayeredTileDataEditor::_get_tile_data(LayeredTileMapCell p_cell) {
ERR_FAIL_COND_V(!tile_set.is_valid(), nullptr);
ERR_FAIL_COND_V(!tile_set->has_source(p_cell.source_id), nullptr);
TileData *td = nullptr;
LayeredTileData *td = nullptr;
LayeredTileSetSource *source = *tile_set->get_source(p_cell.source_id);
LayeredTileSetAtlasSource *atlas_source = Object::cast_to<LayeredTileSetAtlasSource>(source);
if (atlas_source) {
@ -82,15 +85,18 @@ TileData *LayeredTileDataEditor::_get_tile_data(LayeredTileMapCell p_cell) {
void LayeredTileDataEditor::_bind_methods() {
ADD_SIGNAL(MethodInfo("needs_redraw"));
ClassDB::bind_method(D_METHOD("_tile_set_changed_deferred_update"), &LayeredTileDataEditor::_tile_set_changed_deferred_update);
ClassDB::bind_method(D_METHOD("_tile_set_changed_plan_update"), &LayeredTileDataEditor::_tile_set_changed_plan_update);
}
void LayeredTileDataEditor::set_tile_set(Ref<LayeredTileSet> p_tile_set) {
if (tile_set.is_valid()) {
tile_set->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &LayeredTileDataEditor::_tile_set_changed_plan_update));
tile_set->disconnect(CoreStringNames::get_singleton()->changed, this, "_tile_set_changed_plan_update");
}
tile_set = p_tile_set;
if (tile_set.is_valid()) {
tile_set->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &LayeredTileDataEditor::_tile_set_changed_plan_update));
tile_set->connect(CoreStringNames::get_singleton()->changed, this, "_tile_set_changed_plan_update");
}
_tile_set_changed_plan_update();
}
@ -135,9 +141,9 @@ void GenericTilePolygonEditor::_base_control_draw() {
real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius");
Color grid_color = EDITOR_GET("editors/tiles_editor/grid_color");
const Ref<Texture> handle = get_editor_theme_icon(SNAME("EditorPathSharpHandle"));
const Ref<Texture> add_handle = get_editor_theme_icon(SNAME("EditorHandleAdd"));
const Ref<StyleBox> focus_stylebox = get_theme_stylebox(SNAME("Focus"), EditorStringName(EditorStyles));
const Ref<Texture> handle = get_theme_icon("EditorPathSharpHandle", "EditorIcons");
const Ref<Texture> add_handle = get_theme_icon("EditorHandleAdd", "EditorIcons");
const Ref<StyleBox> focus_stylebox = get_theme_stylebox("Focus", "EditorStyles");
// Draw the focus rectangle.
if (base_control->has_focus()) {
@ -181,7 +187,9 @@ void GenericTilePolygonEditor::_base_control_draw() {
}
// Draw the polygons.
for (const Vector<Vector2> &polygon : polygons) {
for (uint32_t i = 0; i < polygons.size(); ++i) {
const Vector<Vector2> &polygon = polygons[i];
Color color = polygon_color;
if (!in_creation_polygon.empty()) {
color = color.darkened(0.3);
@ -241,11 +249,10 @@ void GenericTilePolygonEditor::_base_control_draw() {
// Draw the text on top of the selected point.
if (tinted_polygon_index >= 0) {
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
Ref<Font> font = get_theme_font("font", "Label");
String text = multiple_polygon_mode ? vformat("%d:%d", tinted_polygon_index, tinted_point_index) : vformat("%d", tinted_point_index);
Size2 text_size = font->get_string_size(text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size);
base_control->draw_string(font, xform.xform(polygons[tinted_polygon_index][tinted_point_index]) - text_size * 0.5, text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, Color(1.0, 1.0, 1.0, 0.5));
Size2 text_size = font->get_string_size(text);
base_control->draw_string(font, xform.xform(polygons[tinted_polygon_index][tinted_point_index]) - text_size * 0.5, text, Color(1.0, 1.0, 1.0, 0.5));
}
if (drag_type == DRAG_TYPE_CREATE_POINT) {
@ -274,13 +281,7 @@ void GenericTilePolygonEditor::_zoom_changed() {
}
void GenericTilePolygonEditor::_advanced_menu_item_pressed(int p_item_pressed) {
EditorUndoRedoManager *undo_redo;
if (use_undo_redo) {
undo_redo = EditorUndoRedoManager::get_singleton();
} else {
// This nice hack allows for discarding undo actions without making code too complex.
undo_redo = memnew(EditorUndoRedoManager);
}
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
switch (p_item_pressed) {
case RESET_TO_DEFAULT_TILE: {
@ -294,12 +295,14 @@ void GenericTilePolygonEditor::_advanced_menu_item_pressed(int p_item_pressed) {
undo_redo->add_do_method(base_control, "update");
undo_redo->add_do_method(this, "emit_signal", "polygons_changed");
undo_redo->add_undo_method(this, "clear_polygons");
for (const PoolVector2Array &poly : polygons) {
for (uint32_t i = 0; i < polygons.size(); ++i) {
const Vector<Vector2> &poly = polygons[i];
undo_redo->add_undo_method(this, "add_polygon", poly);
}
undo_redo->add_undo_method(base_control, "update");
undo_redo->add_undo_method(this, "emit_signal", "polygons_changed");
undo_redo->commit_action(true);
undo_redo->commit_action();
} break;
case CLEAR_TILE: {
undo_redo->create_action(TTR("Clear Polygons"));
@ -307,12 +310,13 @@ void GenericTilePolygonEditor::_advanced_menu_item_pressed(int p_item_pressed) {
undo_redo->add_do_method(base_control, "update");
undo_redo->add_do_method(this, "emit_signal", "polygons_changed");
undo_redo->add_undo_method(this, "clear_polygons");
for (const PoolVector2Array &polygon : polygons) {
for (uint32_t i = 0; i < polygons.size(); ++i) {
const Vector<Vector2> &polygon = polygons[i];
undo_redo->add_undo_method(this, "add_polygon", polygon);
}
undo_redo->add_undo_method(base_control, "update");
undo_redo->add_undo_method(this, "emit_signal", "polygons_changed");
undo_redo->commit_action(true);
undo_redo->commit_action();
} break;
case ROTATE_RIGHT:
case ROTATE_LEFT:
@ -336,7 +340,12 @@ void GenericTilePolygonEditor::_advanced_menu_item_pressed(int p_item_pressed) {
}
for (unsigned int i = 0; i < polygons.size(); i++) {
Vector<Point2> new_polygon;
for (const Vector2 &vec : polygons[i]) {
const Vector<Point2> &polygon_i = polygons[i];
for (int j = 0; j < polygon_i.size(); ++j) {
const Vector2 &vec = polygon_i[j];
Vector2 point = vec;
switch (p_item_pressed) {
case ROTATE_RIGHT: {
@ -365,7 +374,7 @@ void GenericTilePolygonEditor::_advanced_menu_item_pressed(int p_item_pressed) {
}
undo_redo->add_undo_method(base_control, "update");
undo_redo->add_undo_method(this, "emit_signal", "polygons_changed");
undo_redo->commit_action(true);
undo_redo->commit_action();
} break;
default:
break;
@ -405,7 +414,7 @@ void GenericTilePolygonEditor::_grab_polygon_segment_point(Vector2 p_pos, const
const Vector<Vector2> &polygon = polygons[i];
for (int j = 0; j < polygon.size(); j++) {
Vector2 segment[2] = { polygon[j], polygon[(j + 1) % polygon.size()] };
Vector2 closest_point = Geometry::get_closest_point_to_segment(point, segment);
Vector2 closest_point = Geometry::get_closest_point_to_segment_2d(point, segment);
float distance = closest_point.distance_to(point);
if (distance < grab_threshold / editor_zoom_widget->get_zoom() && distance < closest_distance) {
r_polygon_index = i;
@ -441,7 +450,7 @@ void GenericTilePolygonEditor::_snap_to_tile_shape(Point2 &r_point, float &r_cur
if (!snapped) {
for (int i = 0; i < polygon.size(); i++) {
Point2 segment[2] = { polygon[i], polygon[(i + 1) % polygon.size()] };
Point2 point = Geometry::get_closest_point_to_segment(r_point, segment);
Point2 point = Geometry::get_closest_point_to_segment_2d(r_point, segment);
float distance = r_point.distance_to(point);
if (distance < p_snap_dist && distance < r_current_snapped_dist) {
snapped_point = point;
@ -470,13 +479,7 @@ void GenericTilePolygonEditor::_snap_point(Point2 &r_point) {
}
void GenericTilePolygonEditor::_base_control_gui_input(Ref<InputEvent> p_event) {
EditorUndoRedoManager *undo_redo;
if (use_undo_redo) {
undo_redo = EditorUndoRedoManager::get_singleton();
} else {
// This nice hack allows for discarding undo actions without making code too complex.
undo_redo = memnew(EditorUndoRedoManager);
}
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius");
@ -502,7 +505,7 @@ void GenericTilePolygonEditor::_base_control_gui_input(Ref<InputEvent> p_event)
} else if (drag_type == DRAG_TYPE_PAN) {
panning += mm->get_position() - drag_last_pos;
drag_last_pos = mm->get_position();
button_center_view->set_disabled(panning.is_zero_approx());
button_center_view->set_disabled(panning.is_equal_approx(Vector2()));
} else {
// Update hovered point.
_grab_polygon_point(mm->get_position(), xform, hovered_polygon_index, hovered_point_index);
@ -516,15 +519,15 @@ void GenericTilePolygonEditor::_base_control_gui_input(Ref<InputEvent> p_event)
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid()) {
if (mb->get_button_index() == MouseButton::WHEEL_UP && mb->is_command_or_control_pressed()) {
if (mb->get_button_index() == BUTTON_WHEEL_UP && mb->get_command()) {
editor_zoom_widget->set_zoom_by_increments(1);
_zoom_changed();
accept_event();
} else if (mb->get_button_index() == MouseButton::WHEEL_DOWN && mb->is_command_or_control_pressed()) {
} else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && mb->get_command()) {
editor_zoom_widget->set_zoom_by_increments(-1);
_zoom_changed();
accept_event();
} else if (mb->get_button_index() == MouseButton::LEFT) {
} else if (mb->get_button_index() == BUTTON_LEFT) {
if (mb->is_pressed()) {
if (tools_button_group->get_pressed_button() != button_create) {
in_creation_polygon.clear();
@ -548,8 +551,8 @@ void GenericTilePolygonEditor::_base_control_gui_input(Ref<InputEvent> p_event)
undo_redo->add_do_method(base_control, "update");
undo_redo->add_undo_method(this, "remove_polygon", added);
undo_redo->add_undo_method(base_control, "update");
undo_redo->commit_action(false);
emit_signal(SNAME("polygons_changed"));
undo_redo->commit_action();
emit_signal("polygons_changed");
} else {
// Create a new point.
drag_type = DRAG_TYPE_CREATE_POINT;
@ -582,7 +585,7 @@ void GenericTilePolygonEditor::_base_control_gui_input(Ref<InputEvent> p_event)
int closest_point;
_grab_polygon_point(mb->get_position(), xform, closest_polygon, closest_point);
if (closest_polygon >= 0) {
PoolVector2Array old_polygon = polygons[closest_polygon];
Vector<Point2> old_polygon = polygons[closest_polygon];
polygons[closest_polygon].remove(closest_point);
undo_redo->create_action(TTR("Edit Polygons"));
if (polygons[closest_polygon].size() < 3) {
@ -595,8 +598,8 @@ void GenericTilePolygonEditor::_base_control_gui_input(Ref<InputEvent> p_event)
}
undo_redo->add_do_method(base_control, "update");
undo_redo->add_undo_method(base_control, "update");
undo_redo->commit_action(false);
emit_signal(SNAME("polygons_changed"));
undo_redo->commit_action();
emit_signal("polygons_changed");
}
}
} else {
@ -606,8 +609,8 @@ void GenericTilePolygonEditor::_base_control_gui_input(Ref<InputEvent> p_event)
undo_redo->add_do_method(base_control, "update");
undo_redo->add_undo_method(this, "set_polygon", drag_polygon_index, drag_old_polygon);
undo_redo->add_undo_method(base_control, "update");
undo_redo->commit_action(false);
emit_signal(SNAME("polygons_changed"));
undo_redo->commit_action();
emit_signal("polygons_changed");
} else if (drag_type == DRAG_TYPE_CREATE_POINT) {
Point2 point = xform.affine_inverse().xform(mb->get_position());
float distance = grab_threshold * 2;
@ -619,7 +622,7 @@ void GenericTilePolygonEditor::_base_control_gui_input(Ref<InputEvent> p_event)
drag_point_index = -1;
}
} else if (mb->get_button_index() == MouseButton::RIGHT) {
} else if (mb->get_button_index() == BUTTON_RIGHT) {
if (mb->is_pressed()) {
if (tools_button_group->get_pressed_button() == button_edit) {
// Remove point or pan.
@ -627,7 +630,7 @@ void GenericTilePolygonEditor::_base_control_gui_input(Ref<InputEvent> p_event)
int closest_point;
_grab_polygon_point(mb->get_position(), xform, closest_polygon, closest_point);
if (closest_polygon >= 0) {
PoolVector2Array old_polygon = polygons[closest_polygon];
Vector<Point2> old_polygon = polygons[closest_polygon];
polygons[closest_polygon].remove(closest_point);
undo_redo->create_action(TTR("Edit Polygons"));
if (polygons[closest_polygon].size() < 3) {
@ -640,8 +643,8 @@ void GenericTilePolygonEditor::_base_control_gui_input(Ref<InputEvent> p_event)
}
undo_redo->add_do_method(base_control, "update");
undo_redo->add_undo_method(base_control, "update");
undo_redo->commit_action(false);
emit_signal(SNAME("polygons_changed"));
undo_redo->commit_action();
emit_signal("polygons_changed");
drag_type = DRAG_TYPE_NONE;
} else {
drag_type = DRAG_TYPE_PAN;
@ -654,7 +657,7 @@ void GenericTilePolygonEditor::_base_control_gui_input(Ref<InputEvent> p_event)
} else {
drag_type = DRAG_TYPE_NONE;
}
} else if (mb->get_button_index() == MouseButton::MIDDLE) {
} else if (mb->get_button_index() == BUTTON_MIDDLE) {
if (mb->is_pressed()) {
drag_type = DRAG_TYPE_PAN;
drag_last_pos = mb->get_position();
@ -721,6 +724,7 @@ void GenericTilePolygonEditor::set_tile_set(Ref<LayeredTileSet> p_tile_set) {
editor_zoom_widget->set_zoom_by_increments(6, false);
float current_zoom = editor_zoom_widget->get_zoom();
zoomed_tile = current_zoom * tile_set->get_tile_size();
if (Math::is_equal_approx(current_zoom, editor_zoom_widget->get_max_zoom())) {
break;
}
@ -729,6 +733,7 @@ void GenericTilePolygonEditor::set_tile_set(Ref<LayeredTileSet> p_tile_set) {
editor_zoom_widget->set_zoom_by_increments(-6, false);
float current_zoom = editor_zoom_widget->get_zoom();
zoomed_tile = current_zoom * tile_set->get_tile_size();
if (Math::is_equal_approx(current_zoom, editor_zoom_widget->get_min_zoom())) {
break;
}
@ -814,22 +819,22 @@ void GenericTilePolygonEditor::_notification(int p_what) {
}
} break;
case NOTIFICATION_THEME_CHANGED: {
button_expand->set_icon(get_editor_theme_icon(SNAME("DistractionFree")));
button_create->set_icon(get_editor_theme_icon(SNAME("CurveCreate")));
button_edit->set_icon(get_editor_theme_icon(SNAME("CurveEdit")));
button_delete->set_icon(get_editor_theme_icon(SNAME("CurveDelete")));
button_center_view->set_icon(get_editor_theme_icon(SNAME("CenterView")));
button_advanced_menu->set_icon(get_editor_theme_icon(SNAME("GuiTabMenuHl")));
button_pixel_snap->get_popup()->set_item_icon(0, get_editor_theme_icon(SNAME("SnapDisable")));
button_pixel_snap->get_popup()->set_item_icon(1, get_editor_theme_icon(SNAME("Snap")));
button_pixel_snap->get_popup()->set_item_icon(2, get_editor_theme_icon(SNAME("SnapGrid")));
button_expand->set_icon(get_theme_icon("DistractionFree", "EditorIcons"));
button_create->set_icon(get_theme_icon("CurveCreate", "EditorIcons"));
button_edit->set_icon(get_theme_icon("CurveEdit", "EditorIcons"));
button_delete->set_icon(get_theme_icon("CurveDelete", "EditorIcons"));
button_center_view->set_icon(get_theme_icon("CenterView", "EditorIcons"));
button_advanced_menu->set_icon(get_theme_icon("GuiTabMenuHl", "EditorIcons"));
button_pixel_snap->get_popup()->set_item_icon(0, get_theme_icon("SnapDisable", "EditorIcons"));
button_pixel_snap->get_popup()->set_item_icon(1, get_theme_icon("Snap", "EditorIcons"));
button_pixel_snap->get_popup()->set_item_icon(2, get_theme_icon("SnapGrid", "EditorIcons"));
button_pixel_snap->set_icon(button_pixel_snap->get_popup()->get_item_icon(current_snap_option));
PopupMenu *p = button_advanced_menu->get_popup();
p->set_item_icon(p->get_item_index(ROTATE_RIGHT), get_editor_theme_icon(SNAME("RotateRight")));
p->set_item_icon(p->get_item_index(ROTATE_LEFT), get_editor_theme_icon(SNAME("RotateLeft")));
p->set_item_icon(p->get_item_index(FLIP_HORIZONTALLY), get_editor_theme_icon(SNAME("MirrorX")));
p->set_item_icon(p->get_item_index(FLIP_VERTICALLY), get_editor_theme_icon(SNAME("MirrorY")));
p->set_item_icon(p->get_item_index(ROTATE_RIGHT), get_theme_icon("RotateRight", "EditorIcons"));
p->set_item_icon(p->get_item_index(ROTATE_LEFT), get_theme_icon("RotateLeft", "EditorIcons"));
p->set_item_icon(p->get_item_index(FLIP_HORIZONTALLY), get_theme_icon("MirrorX", "EditorIcons"));
p->set_item_icon(p->get_item_index(FLIP_VERTICALLY), get_theme_icon("MirrorY", "EditorIcons"));
} break;
}
}
@ -842,6 +847,8 @@ void GenericTilePolygonEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_polygon", "index", "polygon"), &GenericTilePolygonEditor::set_polygon);
ClassDB::bind_method(D_METHOD("get_polygon", "index"), &GenericTilePolygonEditor::get_polygon);
ClassDB::bind_method(D_METHOD("_toggle_expand"), &GenericTilePolygonEditor::_toggle_expand);
ADD_SIGNAL(MethodInfo("polygons_changed"));
}
@ -856,7 +863,7 @@ GenericTilePolygonEditor::GenericTilePolygonEditor() {
button_expand->set_toggle_mode(true);
button_expand->set_pressed(false);
button_expand->set_tooltip(TTR("Expand editor"));
button_expand->connect("toggled", callable_mp(this, &GenericTilePolygonEditor::_toggle_expand));
button_expand->connect("toggled", this, "_toggle_expand");
toolbar->add_child(button_expand);
toolbar->add_child(memnew(VSeparator));
@ -990,7 +997,7 @@ Variant TileDataDefaultEditor::_get_value(LayeredTileSetAtlasSource *p_tile_set_
}
void TileDataDefaultEditor::_setup_undo_redo_action(LayeredTileSetAtlasSource *p_tile_set_atlas_source, const HashMap<LayeredTileMapCell, Variant, LayeredTileMapCell> &p_previous_values, const Variant &p_new_value) {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
for (const KeyValue<LayeredTileMapCell, Variant> &E : p_previous_values) {
Vector2i coords = E.key.get_atlas_coords();
undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/%s", coords.x, coords.y, E.key.alternative_tile, property), E.value);
@ -1059,7 +1066,7 @@ void TileDataDefaultEditor::forward_painting_atlas_gui_input(LayeredTileAtlasVie
}
}
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid()) {
if (mb->get_button_index() == MouseButton::LEFT) {
@ -1183,7 +1190,7 @@ void TileDataDefaultEditor::forward_painting_alternatives_gui_input(LayeredTileA
drag_last_pos = mb->get_position();
}
} else {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
undo_redo->create_action(TTR("Painting Tiles Property"));
_setup_undo_redo_action(p_tile_set_atlas_source, drag_modified, drag_painted_value);
undo_redo->commit_action(false);
@ -1293,9 +1300,9 @@ void TileDataDefaultEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
case NOTIFICATION_THEME_CHANGED: {
picker_button->set_icon(get_editor_theme_icon(SNAME("ColorPick")));
tile_bool_checked = get_editor_theme_icon(SNAME("TileChecked"));
tile_bool_unchecked = get_editor_theme_icon(SNAME("TileUnchecked"));
picker_button->set_icon(get_theme_icon(SNAME("ColorPick"), "EditorIcons"));
tile_bool_checked = get_theme_icon(SNAME("TileChecked"), "EditorIcons");
tile_bool_unchecked = get_theme_icon(SNAME("TileUnchecked"), "EditorIcons");
} break;
}
}
@ -1343,7 +1350,7 @@ void TileDataTextureOriginEditor::draw_over_tile(CanvasItem *p_canvas_item, Tran
}
if (atlas_source->is_position_in_tile_texture_region(p_cell.get_atlas_coords(), p_cell.alternative_tile, Vector2())) {
Ref<Texture> position_icon = LayeredTileSetEditor::get_singleton()->get_editor_theme_icon(SNAME("EditorPosition"));
Ref<Texture> position_icon = LayeredTileSetEditor::get_singleton()->get_theme_icon(SNAME("EditorPosition"), "EditorIcons");
p_canvas_item->draw_texture(position_icon, p_transform.xform(Vector2()) - (position_icon->get_size() / 2), color);
} else {
Ref<Font> font = LayeredTileSetEditor::get_singleton()->get_theme_font(SNAME("bold"), EditorStringName(EditorFonts));
@ -1373,7 +1380,7 @@ void TileDataPositionEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform
Color selection_color = Color().from_hsv(Math::fposmod(grid_color.get_h() + 0.5, 1.0), grid_color.get_s(), grid_color.get_v(), 1.0);
color = selection_color;
}
Ref<Texture> position_icon = LayeredTileSetEditor::get_singleton()->get_editor_theme_icon(SNAME("EditorPosition"));
Ref<Texture> position_icon = LayeredTileSetEditor::get_singleton()->get_theme_icon(SNAME("EditorPosition"), "EditorIcons");
p_canvas_item->draw_texture(position_icon, p_transform.xform(Vector2(value)) - position_icon->get_size() / 2, color);
}
@ -1391,7 +1398,7 @@ void TileDataYSortEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D
LayeredTileSetSource *source = *(tile_set->get_source(p_cell.source_id));
LayeredTileSetAtlasSource *atlas_source = Object::cast_to<LayeredTileSetAtlasSource>(source);
if (atlas_source->is_position_in_tile_texture_region(p_cell.get_atlas_coords(), p_cell.alternative_tile, Vector2(0, tile_data->get_y_sort_origin()))) {
Ref<Texture> position_icon = LayeredTileSetEditor::get_singleton()->get_editor_theme_icon(SNAME("EditorPosition"));
Ref<Texture> position_icon = LayeredTileSetEditor::get_singleton()->get_theme_icon(SNAME("EditorPosition"), "EditorIcons");
p_canvas_item->draw_texture(position_icon, p_transform.xform(Vector2(0, tile_data->get_y_sort_origin())) - position_icon->get_size() / 2, color);
} else {
Ref<Font> font = LayeredTileSetEditor::get_singleton()->get_theme_font(SNAME("bold"), EditorStringName(EditorFonts));
@ -1464,7 +1471,7 @@ Variant TileDataOcclusionShapeEditor::_get_value(LayeredTileSetAtlasSource *p_ti
}
void TileDataOcclusionShapeEditor::_setup_undo_redo_action(LayeredTileSetAtlasSource *p_tile_set_atlas_source, const HashMap<LayeredTileMapCell, Variant, LayeredTileMapCell> &p_previous_values, const Variant &p_new_value) {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
for (const KeyValue<LayeredTileMapCell, Variant> &E : p_previous_values) {
Vector2i coords = E.key.get_atlas_coords();
undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/occlusion_layer_%d/polygon", coords.x, coords.y, E.key.alternative_tile, occlusion_layer), E.value);
@ -1644,7 +1651,7 @@ Variant TileDataCollisionEditor::_get_value(LayeredTileSetAtlasSource *p_tile_se
void TileDataCollisionEditor::_setup_undo_redo_action(LayeredTileSetAtlasSource *p_tile_set_atlas_source, const HashMap<LayeredTileMapCell, Variant, LayeredTileMapCell> &p_previous_values, const Variant &p_new_value) {
Dictionary new_dict = p_new_value;
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
for (const KeyValue<LayeredTileMapCell, Variant> &E : p_previous_values) {
Vector2i coords = E.key.get_atlas_coords();
@ -1742,7 +1749,7 @@ void TileDataCollisionEditor::draw_over_tile(CanvasItem *p_canvas_item, Transfor
RenderingServer::get_singleton()->canvas_item_add_set_transform(p_canvas_item->get_canvas_item(), p_transform);
Ref<Texture> one_way_icon = get_editor_theme_icon(SNAME("OneWayTile"));
Ref<Texture> one_way_icon = get_theme_icon(SNAME("OneWayTile"), "EditorIcons");
for (int i = 0; i < tile_data->get_collision_polygons_count(physics_layer); i++) {
Vector<Vector2> polygon = tile_data->get_collision_polygon_points(physics_layer, i);
if (polygon.size() < 3) {
@ -2352,7 +2359,7 @@ void TileDataTerrainsEditor::forward_painting_atlas_gui_input(LayeredTileAtlasVi
}
}
} else {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
if (drag_type == DRAG_TYPE_PAINT_TERRAIN_SET_RECT) {
Rect2i rect;
rect.set_position(p_tile_atlas_view->get_atlas_tile_coords_at_pos(drag_start_pos, true));
@ -2725,7 +2732,7 @@ void TileDataTerrainsEditor::forward_painting_alternatives_gui_input(LayeredTile
}
}
} else {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
if (drag_type == DRAG_TYPE_PAINT_TERRAIN_SET) {
undo_redo->create_action(TTR("Painting Tiles Property"));
for (KeyValue<LayeredTileMapCell, Variant> &E : drag_modified) {
@ -2785,7 +2792,7 @@ void TileDataTerrainsEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
case NOTIFICATION_THEME_CHANGED: {
picker_button->set_icon(get_editor_theme_icon(SNAME("ColorPick")));
picker_button->set_icon(get_theme_icon(SNAME("ColorPick"), "EditorIcons"));
} break;
}
}
@ -2880,7 +2887,7 @@ Variant TileDataNavigationEditor::_get_value(LayeredTileSetAtlasSource *p_tile_s
}
void TileDataNavigationEditor::_setup_undo_redo_action(LayeredTileSetAtlasSource *p_tile_set_atlas_source, const HashMap<LayeredTileMapCell, Variant, LayeredTileMapCell> &p_previous_values, const Variant &p_new_value) {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
for (const KeyValue<LayeredTileMapCell, Variant> &E : p_previous_values) {
Vector2i coords = E.key.get_atlas_coords();
undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/navigation_layer_%d/polygon", coords.x, coords.y, E.key.alternative_tile, navigation_layer), E.value);

View File

@ -42,7 +42,6 @@
class Label;
class MenuButton;
class SpinBox;
class EditorUndoRedoManager;
class LayeredTileDataEditor : public VBoxContainer {
GDCLASS(LayeredTileDataEditor, VBoxContainer);
@ -115,7 +114,7 @@ private:
int drag_polygon_index = 0;
int drag_point_index = 0;
Vector2 drag_last_pos;
PoolVector2Array drag_old_polygon;
Vector<Point2> drag_old_polygon;
HBoxContainer *toolbar = nullptr;
Ref<ButtonGroup> tools_button_group;

View File

@ -35,10 +35,11 @@
#include "editor/editor_node.h"
#include "editor/editor_resource_preview.h"
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/plugins/canvas_item_editor_plugin.h"
#include "editor/themes/editor_scale.h"
#include "core/object/undo_redo.h"
#include "../layered_tile_map_layer.h"
#include "scene/2d/camera_2d.h"
@ -209,7 +210,7 @@ void LayeredTileMapLayerEditorTilesPlugin::_update_tile_set_sources_list() {
// Scene collection source.
LayeredTileSetScenesCollectionSource *scene_collection_source = Object::cast_to<LayeredTileSetScenesCollectionSource>(source);
if (scene_collection_source) {
texture = tiles_bottom_panel->get_editor_theme_icon(SNAME("PackedScene"));
texture = tiles_bottom_panel->get_theme_icon(SNAME("PackedScene"), "EditorIcons");
if (item_text.empty()) {
if (scene_collection_source->get_scene_tiles_count() > 0) {
item_text = vformat(TTR("Scene Collection Source (ID: %d)"), source_id);
@ -311,7 +312,7 @@ void LayeredTileMapLayerEditorTilesPlugin::_patterns_item_list_gui_input(const R
if (ED_IS_SHORTCUT("tiles_editor/paste", p_event) && p_event->is_pressed() && !p_event->is_echo()) {
select_last_pattern = true;
int new_pattern_index = tile_set->get_patterns_count();
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
undo_redo->create_action(TTR("Add LayeredTileSet pattern"));
undo_redo->add_do_method(*tile_set, "add_pattern", tile_map_clipboard, new_pattern_index);
undo_redo->add_undo_method(*tile_set, "remove_pattern", new_pattern_index);
@ -321,7 +322,7 @@ void LayeredTileMapLayerEditorTilesPlugin::_patterns_item_list_gui_input(const R
if (ED_IS_SHORTCUT("tiles_editor/delete", p_event) && p_event->is_pressed() && !p_event->is_echo()) {
Vector<int> selected = patterns_item_list->get_selected_items();
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
undo_redo->create_action(TTR("Remove LayeredTileSet patterns"));
for (int i = 0; i < selected.size(); i++) {
int pattern_index = selected[i];
@ -427,7 +428,7 @@ void LayeredTileMapLayerEditorTilesPlugin::_update_scenes_collection_view() {
Variant udata = i;
EditorResourcePreview::get_singleton()->queue_edited_resource_preview(scene, this, "_scene_thumbnail_done", udata);
} else {
item_index = scene_tiles_list->add_item(TTR("Tile with Invalid Scene"), tiles_bottom_panel->get_editor_theme_icon(SNAME("PackedScene")));
item_index = scene_tiles_list->add_item(TTR("Tile with Invalid Scene"), tiles_bottom_panel->get_theme_icon(SNAME("PackedScene"), "EditorIcons"));
}
scene_tiles_list->set_item_metadata(item_index, scene_id);
@ -503,23 +504,23 @@ void LayeredTileMapLayerEditorTilesPlugin::_scenes_list_lmb_empty_clicked(const
}
void LayeredTileMapLayerEditorTilesPlugin::_update_theme() {
source_sort_button->set_icon(tiles_bottom_panel->get_editor_theme_icon(SNAME("Sort")));
select_tool_button->set_icon(tiles_bottom_panel->get_editor_theme_icon(SNAME("ToolSelect")));
paint_tool_button->set_icon(tiles_bottom_panel->get_editor_theme_icon(SNAME("Edit")));
line_tool_button->set_icon(tiles_bottom_panel->get_editor_theme_icon(SNAME("Line")));
rect_tool_button->set_icon(tiles_bottom_panel->get_editor_theme_icon(SNAME("Rectangle")));
bucket_tool_button->set_icon(tiles_bottom_panel->get_editor_theme_icon(SNAME("Bucket")));
source_sort_button->set_icon(tiles_bottom_panel->get_theme_icon(SNAME("Sort"), "EditorIcons"));
select_tool_button->set_icon(tiles_bottom_panel->get_theme_icon(SNAME("ToolSelect"), "EditorIcons"));
paint_tool_button->set_icon(tiles_bottom_panel->get_theme_icon(SNAME("Edit"), "EditorIcons"));
line_tool_button->set_icon(tiles_bottom_panel->get_theme_icon(SNAME("Line"), "EditorIcons"));
rect_tool_button->set_icon(tiles_bottom_panel->get_theme_icon(SNAME("Rectangle"), "EditorIcons"));
bucket_tool_button->set_icon(tiles_bottom_panel->get_theme_icon(SNAME("Bucket"), "EditorIcons"));
picker_button->set_icon(tiles_bottom_panel->get_editor_theme_icon(SNAME("ColorPick")));
erase_button->set_icon(tiles_bottom_panel->get_editor_theme_icon(SNAME("Eraser")));
random_tile_toggle->set_icon(tiles_bottom_panel->get_editor_theme_icon(SNAME("RandomNumberGenerator")));
picker_button->set_icon(tiles_bottom_panel->get_theme_icon(SNAME("ColorPick"), "EditorIcons"));
erase_button->set_icon(tiles_bottom_panel->get_theme_icon(SNAME("Eraser"), "EditorIcons"));
random_tile_toggle->set_icon(tiles_bottom_panel->get_theme_icon(SNAME("RandomNumberGenerator"), "EditorIcons"));
transform_button_rotate_left->set_icon(tiles_bottom_panel->get_editor_theme_icon("RotateLeft"));
transform_button_rotate_right->set_icon(tiles_bottom_panel->get_editor_theme_icon("RotateRight"));
transform_button_flip_h->set_icon(tiles_bottom_panel->get_editor_theme_icon("MirrorX"));
transform_button_flip_v->set_icon(tiles_bottom_panel->get_editor_theme_icon("MirrorY"));
transform_button_rotate_left->set_icon(tiles_bottom_panel->get_theme_icon("RotateLeft"), "EditorIcons");
transform_button_rotate_right->set_icon(tiles_bottom_panel->get_theme_icon("RotateRight"), "EditorIcons");
transform_button_flip_h->set_icon(tiles_bottom_panel->get_theme_icon("MirrorX"), "EditorIcons");
transform_button_flip_v->set_icon(tiles_bottom_panel->get_theme_icon("MirrorY"), "EditorIcons");
missing_atlas_texture_icon = tiles_bottom_panel->get_editor_theme_icon(SNAME("LayeredTileSet"));
missing_atlas_texture_icon = tiles_bottom_panel->get_theme_icon(SNAME("LayeredTileSet"), "EditorIcons");
_update_tile_set_sources_list();
}
@ -559,7 +560,7 @@ bool LayeredTileMapLayerEditorTilesPlugin::forward_canvas_gui_input(const Ref<In
if (ED_IS_SHORTCUT("tiles_editor/cut", p_event)) {
// Delete selected tiles.
if (!tile_map_selection.empty()) {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
undo_redo->create_action(TTR("Delete tiles"));
for (const Vector2i &coords : tile_map_selection) {
undo_redo->add_do_method(edited_layer, "set_cell", coords, LayeredTileSet::INVALID_SOURCE, LayeredTileSetSource::INVALID_ATLAS_COORDS, LayeredTileSetSource::INVALID_TILE_ALTERNATIVE);
@ -591,7 +592,7 @@ bool LayeredTileMapLayerEditorTilesPlugin::forward_canvas_gui_input(const Ref<In
if (ED_IS_SHORTCUT("tiles_editor/delete", p_event)) {
// Delete selected tiles.
if (!tile_map_selection.empty()) {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
undo_redo->create_action(TTR("Delete tiles"));
for (const Vector2i &coords : tile_map_selection) {
undo_redo->add_do_method(edited_layer, "set_cell", coords, LayeredTileSet::INVALID_SOURCE, LayeredTileSetSource::INVALID_ATLAS_COORDS, LayeredTileSetSource::INVALID_TILE_ALTERNATIVE);
@ -1302,7 +1303,7 @@ void LayeredTileMapLayerEditorTilesPlugin::_stop_dragging() {
Transform2D xform = CanvasItemEditor::get_singleton()->get_canvas_transform() * edited_layer->get_global_transform_with_canvas();
Vector2 mpos = xform.affine_inverse().xform(CanvasItemEditor::get_singleton()->get_viewport_control()->get_local_mouse_position());
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
switch (drag_type) {
case DRAG_TYPE_SELECT: {
undo_redo->create_action(TTR("Change selection"));
@ -2836,7 +2837,7 @@ void LayeredTileMapLayerEditorTerrainsPlugin::_stop_dragging() {
Transform2D xform = CanvasItemEditor::get_singleton()->get_canvas_transform() * edited_layer->get_global_transform_with_canvas();
Vector2 mpos = xform.affine_inverse().xform(CanvasItemEditor::get_singleton()->get_viewport_control()->get_local_mouse_position());
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
switch (drag_type) {
case DRAG_TYPE_PICK: {
Vector2i coords = tile_set->local_to_map(mpos);
@ -3355,13 +3356,13 @@ void LayeredTileMapLayerEditorTerrainsPlugin::_update_terrains_tree() {
TreeItem *terrain_set_tree_item = terrains_tree->create_item();
String matches;
if (tile_set->get_terrain_set_mode(terrain_set_index) == LayeredTileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES) {
terrain_set_tree_item->set_icon(0, main_vbox_container->get_editor_theme_icon(SNAME("TerrainMatchCornersAndSides")));
terrain_set_tree_item->set_icon(0, main_vbox_container->get_theme_icon(SNAME("TerrainMatchCornersAndSides"), "EditorIcons"));
matches = String(TTR("Matches Corners and Sides"));
} else if (tile_set->get_terrain_set_mode(terrain_set_index) == LayeredTileSet::TERRAIN_MODE_MATCH_CORNERS) {
terrain_set_tree_item->set_icon(0, main_vbox_container->get_editor_theme_icon(SNAME("TerrainMatchCorners")));
terrain_set_tree_item->set_icon(0, main_vbox_container->get_theme_icon(SNAME("TerrainMatchCorners"), "EditorIcons"));
matches = String(TTR("Matches Corners Only"));
} else {
terrain_set_tree_item->set_icon(0, main_vbox_container->get_editor_theme_icon(SNAME("TerrainMatchSides")));
terrain_set_tree_item->set_icon(0, main_vbox_container->get_theme_icon(SNAME("TerrainMatchSides"), "EditorIcons"));
matches = String(TTR("Matches Sides Only"));
}
terrain_set_tree_item->set_text(0, vformat(TTR("Terrain Set %d (%s)"), terrain_set_index, matches));
@ -3404,13 +3405,13 @@ void LayeredTileMapLayerEditorTerrainsPlugin::_update_tiles_list() {
ERR_FAIL_INDEX(sel_terrain_id, tile_set->get_terrains_count(sel_terrain_set));
// Add the two first generic modes
int item_index = terrains_tile_list->add_icon_item(main_vbox_container->get_editor_theme_icon(SNAME("TerrainConnect")));
int item_index = terrains_tile_list->add_icon_item(main_vbox_container->get_theme_icon(SNAME("TerrainConnect"), "EditorIcons"));
terrains_tile_list->set_item_tooltip(item_index, TTR("Connect mode: paints a terrain, then connects it with the surrounding tiles with the same terrain."));
Dictionary list_metadata_dict;
list_metadata_dict["type"] = SELECTED_TYPE_CONNECT;
terrains_tile_list->set_item_metadata(item_index, list_metadata_dict);
item_index = terrains_tile_list->add_icon_item(main_vbox_container->get_editor_theme_icon(SNAME("TerrainPath")));
item_index = terrains_tile_list->add_icon_item(main_vbox_container->get_theme_icon(SNAME("TerrainPath"), "EditorIcons"));
terrains_tile_list->set_item_tooltip(item_index, TTR("Path mode: paints a terrain, then connects it to the previous tile painted within the same stroke."));
list_metadata_dict = Dictionary();
list_metadata_dict["type"] = SELECTED_TYPE_PATH;
@ -3483,13 +3484,13 @@ void LayeredTileMapLayerEditorTerrainsPlugin::_update_tiles_list() {
}
void LayeredTileMapLayerEditorTerrainsPlugin::_update_theme() {
paint_tool_button->set_icon(main_vbox_container->get_editor_theme_icon(SNAME("Edit")));
line_tool_button->set_icon(main_vbox_container->get_editor_theme_icon(SNAME("Line")));
rect_tool_button->set_icon(main_vbox_container->get_editor_theme_icon(SNAME("Rectangle")));
bucket_tool_button->set_icon(main_vbox_container->get_editor_theme_icon(SNAME("Bucket")));
paint_tool_button->set_icon(main_vbox_container->get_theme_icon(SNAME("Edit"), "EditorIcons"));
line_tool_button->set_icon(main_vbox_container->get_theme_icon(SNAME("Line"), "EditorIcons"));
rect_tool_button->set_icon(main_vbox_container->get_theme_icon(SNAME("Rectangle"), "EditorIcons"));
bucket_tool_button->set_icon(main_vbox_container->get_theme_icon(SNAME("Bucket"), "EditorIcons"));
picker_button->set_icon(main_vbox_container->get_editor_theme_icon(SNAME("ColorPick")));
erase_button->set_icon(main_vbox_container->get_editor_theme_icon(SNAME("Eraser")));
picker_button->set_icon(main_vbox_container->get_theme_icon(SNAME("ColorPick"), "EditorIcons"));
erase_button->set_icon(main_vbox_container->get_theme_icon(SNAME("Eraser"), "EditorIcons"));
_update_tiles_list();
}
@ -3631,12 +3632,12 @@ LayeredTileMapLayer *LayeredTileMapLayerEditor::_get_edited_layer() const {
void LayeredTileMapLayerEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_THEME_CHANGED: {
missing_tile_texture = get_editor_theme_icon(SNAME("StatusWarning"));
warning_pattern_texture = get_editor_theme_icon(SNAME("WarningPattern"));
advanced_menu_button->set_icon(get_editor_theme_icon(SNAME("Tools")));
toggle_grid_button->set_icon(get_editor_theme_icon(SNAME("Grid")));
missing_tile_texture = get_theme_icon(SNAME("StatusWarning"), "EditorIcons");
warning_pattern_texture = get_theme_icon(SNAME("WarningPattern"), "EditorIcons");
advanced_menu_button->set_icon(get_theme_icon(SNAME("Tools"), "EditorIcons"));
toggle_grid_button->set_icon(get_theme_icon(SNAME("Grid"), "EditorIcons"));
toggle_grid_button->set_pressed(EDITOR_GET("editors/tiles_editor/display_grid"));
toggle_highlight_selected_layer_button->set_icon(get_editor_theme_icon(SNAME("LayeredTileMapHighlightSelected")));
toggle_highlight_selected_layer_button->set_icon(get_theme_icon(SNAME("LayeredTileMapHighlightSelected"), "EditorIcons"));
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
@ -3693,7 +3694,7 @@ void LayeredTileMapLayerEditor::_advanced_menu_button_id_pressed(int p_id) {
}
if (p_id == 0) { // Replace Tile Proxies
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
undo_redo->create_action(TTR("Replace Tiles with Proxies"));
PoolVector2iArray used_cells = edited_layer->get_used_cells();
for (int i = 0; i < used_cells.size(); i++) {
@ -3876,8 +3877,8 @@ void LayeredTileMapLayerEditor::_update_highlighting_toggle() {
}
void LayeredTileMapLayerEditor::_move_tile_map_array_element(Object *p_undo_redo, Object *p_edited, const String &p_array_prefix, int p_from_index, int p_to_pos) {
EditorUndoRedoManager *undo_redo_man = Object::cast_to<EditorUndoRedoManager>(p_undo_redo);
ERR_FAIL_NULL(undo_redo_man);
UndoRedo *undo_redo = Object::cast_to<UndoRedo>(p_undo_redo);
ERR_FAIL_NULL(undo_redo);
LayeredTileMap *tile_map = Object::cast_to<LayeredTileMap>(p_edited);
if (!tile_map) {
@ -3908,12 +3909,12 @@ void LayeredTileMapLayerEditor::_move_tile_map_array_element(Object *p_undo_redo
end = MIN(MAX(p_from_index, p_to_pos) + 1, end);
}
#define ADD_UNDO(obj, property) undo_redo_man->add_undo_property(obj, property, obj->get(property));
#define ADD_UNDO(obj, property) undo_redo->add_undo_property(obj, property, obj->get(property));
// Save layers' properties.
if (p_from_index < 0) {
undo_redo_man->add_undo_method(tile_map, "remove_layer", p_to_pos < 0 ? tile_map->get_layers_count() : p_to_pos);
undo_redo->add_undo_method(tile_map, "remove_layer", p_to_pos < 0 ? tile_map->get_layers_count() : p_to_pos);
} else if (p_to_pos < 0) {
undo_redo_man->add_undo_method(tile_map, "add_layer", p_from_index);
undo_redo->add_undo_method(tile_map, "add_layer", p_from_index);
}
List<PropertyInfo> properties;
@ -3939,11 +3940,11 @@ void LayeredTileMapLayerEditor::_move_tile_map_array_element(Object *p_undo_redo
#undef ADD_UNDO
if (p_from_index < 0) {
undo_redo_man->add_do_method(tile_map, "add_layer", p_to_pos);
undo_redo->add_do_method(tile_map, "add_layer", p_to_pos);
} else if (p_to_pos < 0) {
undo_redo_man->add_do_method(tile_map, "remove_layer", p_from_index);
undo_redo->add_do_method(tile_map, "remove_layer", p_from_index);
} else {
undo_redo_man->add_do_method(tile_map, "move_layer", p_from_index, p_to_pos);
undo_redo->add_do_method(tile_map, "move_layer", p_from_index, p_to_pos);
}
}
@ -4175,8 +4176,8 @@ LayeredTileMapLayerEditor::LayeredTileMapLayerEditor() {
tile_map_editor_plugins.push_back(memnew(LayeredTileMapLayerEditorTilesPlugin));
tile_map_editor_plugins.push_back(memnew(LayeredTileMapLayerEditorTerrainsPlugin));
// TabBar.
tabs_bar = memnew(TabBar);
// Tabs.
tabs_bar = memnew(Tabs);
tabs_bar->set_clip_tabs(false);
for (int plugin_index = 0; plugin_index < tile_map_editor_plugins.size(); plugin_index++) {
Vector<LayeredTileMapLayerSubEditorPlugin::TabData> tabs_vector = tile_map_editor_plugins[plugin_index]->get_tabs();

View File

@ -32,7 +32,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "tile_atlas_view.h"
#include "layered_tile_atlas_view.h"
#include "../layered_tile_map.h"
#include "core/os/thread.h"
@ -46,7 +46,7 @@
#include "scene/gui/separator.h"
#include "scene/gui/spin_box.h"
#include "scene/gui/split_container.h"
#include "scene/gui/tab_bar.h"
#include "scene/gui/tabs.h"
#include "scene/gui/tree.h"
class LayeredTileMapLayerEditor;
@ -167,7 +167,7 @@ private:
void _update_fix_selected_and_hovered();
void _fix_invalid_tiles_in_tile_map_selection();
void patterns_item_list_empty_clicked(const Vector2 &p_pos, MouseButton p_mouse_button_index);
void patterns_item_list_empty_clicked(const Vector2 &p_pos, int p_mouse_button_index);
///// Bottom panel common ////
void _tab_changed();
@ -212,7 +212,7 @@ private:
void _update_scenes_collection_view();
void _scene_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_ud);
void _scenes_list_multi_selected(int p_index, bool p_selected);
void _scenes_list_lmb_empty_clicked(const Vector2 &p_pos, MouseButton p_mouse_button_index);
void _scenes_list_lmb_empty_clicked(const Vector2 &p_pos, int p_mouse_button_index);
///// Bottom panel patterns ////
VBoxContainer *patterns_bottom_panel = nullptr;
@ -365,7 +365,7 @@ private:
// Bottom panel.
Label *missing_tileset_label = nullptr;
TabBar *tabs_bar = nullptr;
Tabs *tabs_bar = nullptr;
LocalVector<LayeredTileMapLayerSubEditorPlugin::TabData> tabs_data;
LocalVector<LayeredTileMapLayerSubEditorPlugin *> tabs_plugins;
void _update_bottom_panel();

View File

@ -31,14 +31,16 @@
#include "layered_tile_proxies_manager_dialog.h"
#include "editor/editor_properties_vector.h"
#include "editor/editor_properties.h"
#include "editor/editor_settings.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/themes/editor_scale.h"
#include "editor/editor_scale.h"
#include "scene/gui/dialogs.h"
#include "scene/gui/popup_menu.h"
#include "scene/gui/separator.h"
#include "core/object/undo_redo.h"
void LayeredTileProxiesManagerDialog::_right_clicked(int p_item, Vector2 p_local_mouse_pos, MouseButton p_mouse_button_index, Object *p_item_list) {
if (p_mouse_button_index != MouseButton::RIGHT) {
return;
@ -58,7 +60,7 @@ void LayeredTileProxiesManagerDialog::_menu_id_pressed(int p_id) {
}
void LayeredTileProxiesManagerDialog::_delete_selected_bindings() {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
undo_redo->create_action(TTR("Remove Tile Proxies"));
Vector<int> source_level_selected = source_level_list->get_selected_items();
@ -158,7 +160,7 @@ void LayeredTileProxiesManagerDialog::_property_changed(const String &p_path, co
}
void LayeredTileProxiesManagerDialog::_add_button_pressed() {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
if (from.source_id != LayeredTileSet::INVALID_SOURCE && to.source_id != LayeredTileSet::INVALID_SOURCE) {
Vector2i from_coords = from.get_atlas_coords();
Vector2i to_coords = to.get_atlas_coords();
@ -199,7 +201,7 @@ void LayeredTileProxiesManagerDialog::_add_button_pressed() {
}
void LayeredTileProxiesManagerDialog::_clear_invalid_button_pressed() {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
undo_redo->create_action(TTR("Delete All Invalid Tile Proxies"));
undo_redo->add_do_method(*tile_set, "cleanup_invalid_tile_proxies");
@ -227,7 +229,7 @@ void LayeredTileProxiesManagerDialog::_clear_invalid_button_pressed() {
}
void LayeredTileProxiesManagerDialog::_clear_all_button_pressed() {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
undo_redo->create_action(TTR("Delete All Tile Proxies"));
undo_redo->add_do_method(*tile_set, "clear_tile_proxies");
@ -308,7 +310,7 @@ void LayeredTileProxiesManagerDialog::_unhandled_key_input(Ref<InputEvent> p_eve
}
void LayeredTileProxiesManagerDialog::cancel_pressed() {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
for (int i = 0; i < commited_actions_count; i++) {
undo_redo->undo();
}

View File

@ -38,7 +38,6 @@
#include "scene/gui/item_list.h"
class EditorPropertyVector2i;
class EditorUndoRedoManager;
class LayeredTileProxiesManagerDialog : public ConfirmationDialog {
GDCLASS(LayeredTileProxiesManagerDialog, ConfirmationDialog);

View File

@ -36,12 +36,12 @@
#include "editor/editor_inspector.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/gui/editor_toaster.h"
#include "editor/plugins/tiles/tile_set_editor.h"
#include "layered_tile_set_editor.h"
#include "editor/progress_dialog.h"
#include "editor/themes/editor_scale.h"
#include "editor/editor_scale.h"
#include "core/object/undo_redo.h"
#include "scene/gui/box_container.h"
#include "scene/gui/button.h"
@ -52,7 +52,7 @@
#include "scene/main/control.h"
#include "core/core_string_names.h"
#include "core/math/geometry_2d.h"
#include "core/math/geometry.h"
#include "core/os/keyboard.h"
#include "servers/navigation_2d_server.h"
@ -758,7 +758,7 @@ void LayeredTileSetAtlasSourceEditor::_update_tile_data_editors() {
if (tile_set->get_physics_layers_count() == 0) {
item = tile_data_editors_tree->create_item(group);
item->set_icon(0, get_editor_theme_icon("Info"));
item->set_icon(0, get_theme_icon("Info"), "EditorIcons");
item->set_icon_modulate(0, disabled_color);
item->set_text(0, TTR("No physics layers"));
item->set_tooltip(0, TTR("Create and customize physics layers in the inspector of the LayeredTileSet resource."));
@ -786,7 +786,7 @@ void LayeredTileSetAtlasSourceEditor::_update_tile_data_editors() {
if (tile_set->get_navigation_layers_count() == 0) {
item = tile_data_editors_tree->create_item(group);
item->set_icon(0, get_editor_theme_icon("Info"));
item->set_icon(0, get_theme_icon("Info"), "EditorIcons");
item->set_icon_modulate(0, disabled_color);
item->set_text(0, TTR("No navigation layers"));
item->set_tooltip(0, TTR("Create and customize navigation layers in the inspector of the LayeredTileSet resource."));
@ -829,7 +829,7 @@ void LayeredTileSetAtlasSourceEditor::_update_tile_data_editors() {
if (tile_set->get_custom_data_layers_count() == 0) {
item = tile_data_editors_tree->create_item(group);
item->set_icon(0, get_editor_theme_icon("Info"));
item->set_icon(0, get_theme_icon("Info"), "EditorIcons");
item->set_icon_modulate(0, disabled_color);
item->set_text(0, TTR("No custom data layers"));
item->set_tooltip(0, TTR("Create and customize custom data layers in the inspector of the LayeredTileSet resource."));
@ -998,7 +998,7 @@ void LayeredTileSetAtlasSourceEditor::_update_atlas_view() {
// Create and position the button.
Button *button = memnew(Button);
button->set_flat(true);
button->set_icon(get_editor_theme_icon(SNAME("Add")));
button->set_icon(get_theme_icon(SNAME("Add"), "EditorIcons"));
button->add_theme_style_override("normal", memnew(StyleBoxEmpty));
button->add_theme_style_override("hover", memnew(StyleBoxEmpty));
button->add_theme_style_override("focus", memnew(StyleBoxEmpty));
@ -1363,7 +1363,7 @@ void LayeredTileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<In
}
void LayeredTileSetAtlasSourceEditor::_end_dragging() {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
switch (drag_type) {
case DRAG_TYPE_CREATE_TILES:
undo_redo->create_action(TTR("Create tiles"));
@ -1594,7 +1594,7 @@ HashMap<Vector2i, List<const PropertyInfo *>> LayeredTileSetAtlasSourceEditor::_
}
void LayeredTileSetAtlasSourceEditor::_menu_option(int p_option) {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
switch (p_option) {
case TILE_DELETE: {
@ -2117,14 +2117,14 @@ void LayeredTileSetAtlasSourceEditor::_atlas_source_proxy_object_changed(const S
}
void LayeredTileSetAtlasSourceEditor::_undo_redo_inspector_callback(Object *p_undo_redo, Object *p_edited, const String &p_property, const Variant &p_new_value) {
EditorUndoRedoManager *undo_redo_man = Object::cast_to<EditorUndoRedoManager>(p_undo_redo);
ERR_FAIL_NULL(undo_redo_man);
UndoRedo *undo_redo = Object::cast_to<UndoRedo>(p_undo_redo);
ERR_FAIL_NULL(undo_redo);
#define ADD_UNDO(obj, property) undo_redo_man->add_undo_property(obj, property, obj->get(property));
#define ADD_UNDO(obj, property) undo_redo->add_undo_property(obj, property, obj->get(property));
LayeredAtlasTileProxyObject *tile_data_proxy = Object::cast_to<LayeredAtlasTileProxyObject>(p_edited);
if (tile_data_proxy) {
UndoRedo *internal_undo_redo = undo_redo_man->get_history_for_object(tile_data_proxy).undo_redo;
UndoRedo *internal_undo_redo = undo_redo->get_history_for_object(tile_data_proxy).undo_redo;
internal_undo_redo->start_force_keep_in_merge_ends();
Vector<String> components = String(p_property).split("/", true, 2);
@ -2269,7 +2269,7 @@ void LayeredTileSetAtlasSourceEditor::_cleanup_outside_tiles() {
HashMap<Vector2i, List<const PropertyInfo *>> per_tile = _group_properties_per_tiles(list, tile_set_atlas_source);
Vector<Vector2i> tiles_outside = tile_set_atlas_source->get_tiles_outside_texture();
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
undo_redo->create_action(TTR("Remove Tiles Outside the Texture"));
undo_redo->add_do_method(tile_set_atlas_source, "clear_tiles_outside_texture");
@ -2301,7 +2301,7 @@ void LayeredTileSetAtlasSourceEditor::_auto_create_tiles() {
Vector2i separation = atlas_source->get_separation();
Vector2i texture_region_size = atlas_source->get_texture_region_size();
Size2i grid_size = atlas_source->get_atlas_grid_size();
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
undo_redo->create_action(TTR("Create tiles in non-transparent texture regions"));
for (int y = 0; y < grid_size.y; y++) {
for (int x = 0; x < grid_size.x; x++) {
@ -2355,7 +2355,7 @@ void LayeredTileSetAtlasSourceEditor::_auto_remove_tiles() {
Vector2i texture_region_size = tile_set_atlas_source->get_texture_region_size();
Vector2i grid_size = tile_set_atlas_source->get_atlas_grid_size();
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
undo_redo->create_action(TTR("Remove tiles in fully transparent texture regions"));
List<PropertyInfo> list;
@ -2438,16 +2438,16 @@ void LayeredTileSetAtlasSourceEditor::_notification(int p_what) {
} break;
case NOTIFICATION_THEME_CHANGED: {
tool_setup_atlas_source_button->set_icon(get_editor_theme_icon(SNAME("Tools")));
tool_select_button->set_icon(get_editor_theme_icon(SNAME("ToolSelect")));
tool_paint_button->set_icon(get_editor_theme_icon(SNAME("Paint")));
tool_setup_atlas_source_button->set_icon(get_theme_icon(SNAME("Tools"), "EditorIcons"));
tool_select_button->set_icon(get_theme_icon(SNAME("ToolSelect"), "EditorIcons"));
tool_paint_button->set_icon(get_theme_icon(SNAME("Paint"), "EditorIcons"));
tools_settings_erase_button->set_icon(get_editor_theme_icon(SNAME("Eraser")));
tool_advanced_menu_button->set_icon(get_editor_theme_icon(SNAME("GuiTabMenuHl")));
outside_tiles_warning->set_texture(get_editor_theme_icon(SNAME("StatusWarning")));
tools_settings_erase_button->set_icon(get_theme_icon(SNAME("Eraser"), "EditorIcons"));
tool_advanced_menu_button->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), "EditorIcons"));
outside_tiles_warning->set_texture(get_theme_icon(SNAME("StatusWarning"), "EditorIcons"));
resize_handle = get_editor_theme_icon(SNAME("EditorHandle"));
resize_handle_disabled = get_editor_theme_icon(SNAME("EditorHandleDisabled"));
resize_handle = get_theme_icon(SNAME("EditorHandle"), "EditorIcons");
resize_handle_disabled = get_theme_icon(SNAME("EditorHandleDisabled"), "EditorIcons");
} break;
case NOTIFICATION_INTERNAL_PROCESS: {

View File

@ -38,9 +38,10 @@
#include "editor/editor_inspector.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/gui/editor_file_dialog.h"
#include "editor/themes/editor_scale.h"
#include "editor/editor_file_dialog.h"
#include "editor/editor_scale.h"
#include "core/object/undo_redo.h"
#include "scene/gui/box_container.h"
#include "scene/gui/dialogs.h"
@ -120,7 +121,7 @@ void LayeredTileSetEditor::_load_texture_files(const Vector<String> &p_paths) {
atlas_source->set_texture(texture);
atlas_source->set_texture_region_size(tile_set->get_tile_size());
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
undo_redo->create_action(TTR("Add a new atlas source"));
undo_redo->add_do_method(*tile_set, "add_source", atlas_source, source_id);
undo_redo->add_undo_method(*tile_set, "remove_source", source_id);
@ -190,7 +191,7 @@ void LayeredTileSetEditor::_update_sources_list(int force_selected_id) {
// Scene collection source.
LayeredTileSetScenesCollectionSource *scene_collection_source = Object::cast_to<LayeredTileSetScenesCollectionSource>(source);
if (scene_collection_source) {
texture = get_editor_theme_icon(SNAME("PackedScene"));
texture = get_theme_icon(SNAME("PackedScene"), "EditorIcons");
if (item_text.empty()) {
if (scene_collection_source->get_scene_tiles_count() > 0) {
item_text = vformat(TTR("Scene Collection Source (ID: %d)"), source_id);
@ -282,7 +283,7 @@ void LayeredTileSetEditor::_source_delete_pressed() {
Ref<LayeredTileSetSource> source = tile_set->get_source(to_delete);
// Remove the source.
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
undo_redo->create_action(TTR("Remove source"));
undo_redo->add_do_method(*tile_set, "remove_source", to_delete);
undo_redo->add_undo_method(*tile_set, "add_source", source, to_delete);
@ -316,7 +317,7 @@ void LayeredTileSetEditor::_source_add_id_pressed(int p_id_pressed) {
Ref<LayeredTileSetScenesCollectionSource> scene_collection_source = memnew(LayeredTileSetScenesCollectionSource);
// Add a new source.
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
undo_redo->create_action(TTR("Add atlas source"));
undo_redo->add_do_method(*tile_set, "add_source", scene_collection_source, source_id);
undo_redo->add_undo_method(*tile_set, "remove_source", source_id);
@ -364,11 +365,11 @@ void LayeredTileSetEditor::_set_source_sort(int p_sort) {
void LayeredTileSetEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_THEME_CHANGED: {
sources_delete_button->set_icon(get_editor_theme_icon(SNAME("Remove")));
sources_add_button->set_icon(get_editor_theme_icon(SNAME("Add")));
source_sort_button->set_icon(get_editor_theme_icon(SNAME("Sort")));
sources_advanced_menu_button->set_icon(get_editor_theme_icon(SNAME("GuiTabMenuHl")));
missing_texture_texture = get_editor_theme_icon(SNAME("LayeredTileSet"));
sources_delete_button->set_icon(get_theme_icon(SNAME("Remove"), "EditorIcons"));
sources_add_button->set_icon(get_theme_icon(SNAME("Add"), "EditorIcons"));
source_sort_button->set_icon(get_theme_icon(SNAME("Sort"), "EditorIcons"));
sources_advanced_menu_button->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), "EditorIcons"));
missing_texture_texture = get_theme_icon(SNAME("LayeredTileSet"), "EditorIcons");
expanded_area->add_theme_style_override("panel", get_theme_stylebox("panel", "Tree"));
_update_sources_list();
} break;
@ -412,7 +413,7 @@ void LayeredTileSetEditor::_patterns_item_list_gui_input(const Ref<InputEvent> &
if (ED_IS_SHORTCUT("tiles_editor/delete", p_event) && p_event->is_pressed() && !p_event->is_echo()) {
Vector<int> selected = patterns_item_list->get_selected_items();
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
undo_redo->create_action(TTR("Remove LayeredTileSet patterns"));
for (int i = 0; i < selected.size(); i++) {
int pattern_index = selected[i];
@ -460,8 +461,8 @@ void LayeredTileSetEditor::_tab_changed(int p_tab_changed) {
}
void LayeredTileSetEditor::_move_tile_set_array_element(Object *p_undo_redo, Object *p_edited, const String &p_array_prefix, int p_from_index, int p_to_pos) {
EditorUndoRedoManager *undo_redo_man = Object::cast_to<EditorUndoRedoManager>(p_undo_redo);
ERR_FAIL_NULL(undo_redo_man);
UndoRedo *undo_redo = Object::cast_to<UndoRedo>(p_undo_redo);
ERR_FAIL_NULL(undo_redo);
LayeredTileSet *ed_tile_set = Object::cast_to<LayeredTileSet>(p_edited);
if (!ed_tile_set) {
@ -505,33 +506,33 @@ void LayeredTileSetEditor::_move_tile_set_array_element(Object *p_undo_redo, Obj
end = MIN(MAX(p_from_index, p_to_pos) + 1, end);
}
#define ADD_UNDO(obj, property) undo_redo_man->add_undo_property(obj, property, obj->get(property));
#define ADD_UNDO(obj, property) undo_redo->add_undo_property(obj, property, obj->get(property));
// Add undo method to adding array element.
if (p_array_prefix == "occlusion_layer_") {
if (p_from_index < 0) {
undo_redo_man->add_undo_method(ed_tile_set, "remove_occlusion_layer", p_to_pos < 0 ? ed_tile_set->get_occlusion_layers_count() : p_to_pos);
undo_redo->add_undo_method(ed_tile_set, "remove_occlusion_layer", p_to_pos < 0 ? ed_tile_set->get_occlusion_layers_count() : p_to_pos);
}
} else if (p_array_prefix == "physics_layer_") {
if (p_from_index < 0) {
undo_redo_man->add_undo_method(ed_tile_set, "remove_physics_layer", p_to_pos < 0 ? ed_tile_set->get_physics_layers_count() : p_to_pos);
undo_redo->add_undo_method(ed_tile_set, "remove_physics_layer", p_to_pos < 0 ? ed_tile_set->get_physics_layers_count() : p_to_pos);
}
} else if (p_array_prefix == "terrain_set_") {
if (p_from_index < 0) {
undo_redo_man->add_undo_method(ed_tile_set, "remove_terrain_set", p_to_pos < 0 ? ed_tile_set->get_terrain_sets_count() : p_to_pos);
undo_redo->add_undo_method(ed_tile_set, "remove_terrain_set", p_to_pos < 0 ? ed_tile_set->get_terrain_sets_count() : p_to_pos);
}
} else if (components.size() >= 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_integer() && components[1] == "terrain_") {
int terrain_set = components[0].trim_prefix("terrain_set_").to_int();
if (p_from_index < 0) {
undo_redo_man->add_undo_method(ed_tile_set, "remove_terrain", terrain_set, p_to_pos < 0 ? ed_tile_set->get_terrains_count(terrain_set) : p_to_pos);
undo_redo->add_undo_method(ed_tile_set, "remove_terrain", terrain_set, p_to_pos < 0 ? ed_tile_set->get_terrains_count(terrain_set) : p_to_pos);
}
} else if (p_array_prefix == "navigation_layer_") {
if (p_from_index < 0) {
undo_redo_man->add_undo_method(ed_tile_set, "remove_navigation_layer", p_to_pos < 0 ? ed_tile_set->get_navigation_layers_count() : p_to_pos);
undo_redo->add_undo_method(ed_tile_set, "remove_navigation_layer", p_to_pos < 0 ? ed_tile_set->get_navigation_layers_count() : p_to_pos);
}
} else if (p_array_prefix == "custom_data_layer_") {
if (p_from_index < 0) {
undo_redo_man->add_undo_method(ed_tile_set, "remove_custom_data_layer", p_to_pos < 0 ? ed_tile_set->get_custom_data_layers_count() : p_to_pos);
undo_redo->add_undo_method(ed_tile_set, "remove_custom_data_layer", p_to_pos < 0 ? ed_tile_set->get_custom_data_layers_count() : p_to_pos);
}
}
@ -619,61 +620,61 @@ void LayeredTileSetEditor::_move_tile_set_array_element(Object *p_undo_redo, Obj
// Add do method to add/remove array element.
if (p_array_prefix == "occlusion_layer_") {
if (p_from_index < 0) {
undo_redo_man->add_do_method(ed_tile_set, "add_occlusion_layer", p_to_pos);
undo_redo->add_do_method(ed_tile_set, "add_occlusion_layer", p_to_pos);
} else if (p_to_pos < 0) {
undo_redo_man->add_do_method(ed_tile_set, "remove_occlusion_layer", p_from_index);
undo_redo->add_do_method(ed_tile_set, "remove_occlusion_layer", p_from_index);
} else {
undo_redo_man->add_do_method(ed_tile_set, "move_occlusion_layer", p_from_index, p_to_pos);
undo_redo->add_do_method(ed_tile_set, "move_occlusion_layer", p_from_index, p_to_pos);
}
} else if (p_array_prefix == "physics_layer_") {
if (p_from_index < 0) {
undo_redo_man->add_do_method(ed_tile_set, "add_physics_layer", p_to_pos);
undo_redo->add_do_method(ed_tile_set, "add_physics_layer", p_to_pos);
} else if (p_to_pos < 0) {
undo_redo_man->add_do_method(ed_tile_set, "remove_physics_layer", p_from_index);
undo_redo->add_do_method(ed_tile_set, "remove_physics_layer", p_from_index);
} else {
undo_redo_man->add_do_method(ed_tile_set, "move_physics_layer", p_from_index, p_to_pos);
undo_redo->add_do_method(ed_tile_set, "move_physics_layer", p_from_index, p_to_pos);
}
} else if (p_array_prefix == "terrain_set_") {
if (p_from_index < 0) {
undo_redo_man->add_do_method(ed_tile_set, "add_terrain_set", p_to_pos);
undo_redo->add_do_method(ed_tile_set, "add_terrain_set", p_to_pos);
} else if (p_to_pos < 0) {
undo_redo_man->add_do_method(ed_tile_set, "remove_terrain_set", p_from_index);
undo_redo->add_do_method(ed_tile_set, "remove_terrain_set", p_from_index);
} else {
undo_redo_man->add_do_method(ed_tile_set, "move_terrain_set", p_from_index, p_to_pos);
undo_redo->add_do_method(ed_tile_set, "move_terrain_set", p_from_index, p_to_pos);
}
} else if (components.size() >= 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_integer() && components[1] == "terrain_") {
int terrain_set = components[0].trim_prefix("terrain_set_").to_int();
if (p_from_index < 0) {
undo_redo_man->add_do_method(ed_tile_set, "add_terrain", terrain_set, p_to_pos);
undo_redo->add_do_method(ed_tile_set, "add_terrain", terrain_set, p_to_pos);
} else if (p_to_pos < 0) {
undo_redo_man->add_do_method(ed_tile_set, "remove_terrain", terrain_set, p_from_index);
undo_redo->add_do_method(ed_tile_set, "remove_terrain", terrain_set, p_from_index);
} else {
undo_redo_man->add_do_method(ed_tile_set, "move_terrain", terrain_set, p_from_index, p_to_pos);
undo_redo->add_do_method(ed_tile_set, "move_terrain", terrain_set, p_from_index, p_to_pos);
}
} else if (p_array_prefix == "navigation_layer_") {
if (p_from_index < 0) {
undo_redo_man->add_do_method(ed_tile_set, "add_navigation_layer", p_to_pos);
undo_redo->add_do_method(ed_tile_set, "add_navigation_layer", p_to_pos);
} else if (p_to_pos < 0) {
undo_redo_man->add_do_method(ed_tile_set, "remove_navigation_layer", p_from_index);
undo_redo->add_do_method(ed_tile_set, "remove_navigation_layer", p_from_index);
} else {
undo_redo_man->add_do_method(ed_tile_set, "move_navigation_layer", p_from_index, p_to_pos);
undo_redo->add_do_method(ed_tile_set, "move_navigation_layer", p_from_index, p_to_pos);
}
} else if (p_array_prefix == "custom_data_layer_") {
if (p_from_index < 0) {
undo_redo_man->add_do_method(ed_tile_set, "add_custom_data_layer", p_to_pos);
undo_redo->add_do_method(ed_tile_set, "add_custom_data_layer", p_to_pos);
} else if (p_to_pos < 0) {
undo_redo_man->add_do_method(ed_tile_set, "remove_custom_data_layer", p_from_index);
undo_redo->add_do_method(ed_tile_set, "remove_custom_data_layer", p_from_index);
} else {
undo_redo_man->add_do_method(ed_tile_set, "move_custom_data_layer", p_from_index, p_to_pos);
undo_redo->add_do_method(ed_tile_set, "move_custom_data_layer", p_from_index, p_to_pos);
}
}
}
void LayeredTileSetEditor::_undo_redo_inspector_callback(Object *p_undo_redo, Object *p_edited, const String &p_property, const Variant &p_new_value) {
EditorUndoRedoManager *undo_redo_man = Object::cast_to<EditorUndoRedoManager>(p_undo_redo);
ERR_FAIL_NULL(undo_redo_man);
UndoRedo *undo_redo = Object::cast_to<UndoRedo>(p_undo_redo);
ERR_FAIL_NULL(undo_redo);
#define ADD_UNDO(obj, property) undo_redo_man->add_undo_property(obj, property, obj->get(property));
#define ADD_UNDO(obj, property) undo_redo->add_undo_property(obj, property, obj->get(property));
LayeredTileSet *ed_tile_set = Object::cast_to<LayeredTileSet>(p_edited);
if (ed_tile_set) {
Vector<String> components = p_property.split("/", true, 3);
@ -686,7 +687,7 @@ void LayeredTileSetEditor::_undo_redo_inspector_callback(Object *p_undo_redo, Ob
Vector2i tile_id = tas->get_tile_id(j);
for (int k = 0; k < tas->get_alternative_tiles_count(tile_id); k++) {
int alternative_id = tas->get_alternative_tile_id(tile_id, k);
TileData *tile_data = tas->get_tile_data(tile_id, alternative_id);
LayeredTileData *tile_data = tas->get_tile_data(tile_id, alternative_id);
ERR_FAIL_NULL(tile_data);
if (components.size() == 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_integer() && components[1] == "mode") {
@ -812,9 +813,9 @@ LayeredTileSetEditor::LayeredTileSetEditor() {
add_child(main_vb);
main_vb->set_anchors_and_margins_preset(PRESET_WIDE);
// TabBar.
tabs_bar = memnew(TabBar);
tabs_bar->set_tab_alignment(TabBar::ALIGNMENT_CENTER);
// Tabs.
tabs_bar = memnew(Tabs);
tabs_bar->set_tab_alignment(Tabs::ALIGNMENT_CENTER);
tabs_bar->set_clip_tabs(false);
tabs_bar->add_tab(TTR("Tiles"));
tabs_bar->add_tab(TTR("Patterns"));

View File

@ -37,7 +37,8 @@
#include "layered_tile_proxies_manager_dialog.h"
#include "layered_tile_set_atlas_source_editor.h"
#include "layered_tile_set_scenes_collection_source_editor.h"
#include "scene/gui/tab_bar.h"
#include "scene/gui/tabs.h"
class AcceptDialog;
class SpinBox;
@ -58,9 +59,9 @@ private:
bool tile_set_changed_needs_update = false;
HSplitContainer *split_container = nullptr;
// TabBar.
// Tabs.
HBoxContainer *tile_set_toolbar = nullptr;
TabBar *tabs_bar = nullptr;
Tabs *tabs_bar = nullptr;
// Tiles.
Label *no_source_selected_label = nullptr;

View File

@ -35,10 +35,13 @@
#include "editor/editor_node.h"
#include "editor/editor_resource_preview.h"
#include "editor/editor_settings.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/gui/editor_file_dialog.h"
#include "editor/plugins/tiles/tile_set_editor.h"
#include "editor/themes/editor_scale.h"
#include "core/object/undo_redo.h"
#include "editor/editor_file_dialog.h"
#include "layered_tile_set_editor.h"
#include "editor/editor_scale.h"
#include "scene/gui/button.h"
#include "scene/gui/item_list.h"
@ -258,7 +261,7 @@ void LayeredTileSetScenesCollectionSourceEditor::_scene_file_selected(const Stri
Ref<PackedScene> scene = ResourceLoader::load(p_path);
int scene_id = tile_set_scenes_collection_source->get_next_scene_tile_id();
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
undo_redo->create_action(TTR("Add a Scene Tile"));
undo_redo->add_do_method(tile_set_scenes_collection_source, "create_scene_tile", scene, scene_id);
undo_redo->add_undo_method(tile_set_scenes_collection_source, "remove_scene_tile", scene_id);
@ -273,7 +276,7 @@ void LayeredTileSetScenesCollectionSourceEditor::_source_delete_pressed() {
ERR_FAIL_COND(selected_indices.empty());
int scene_id = scene_tiles_list->get_item_metadata(selected_indices[0]);
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
undo_redo->create_action(TTR("Remove a Scene Tile"));
undo_redo->add_do_method(tile_set_scenes_collection_source, "remove_scene_tile", scene_id);
undo_redo->add_undo_method(tile_set_scenes_collection_source, "create_scene_tile", tile_set_scenes_collection_source->get_scene_tile_scene(scene_id), scene_id);
@ -333,7 +336,7 @@ void LayeredTileSetScenesCollectionSourceEditor::_update_scenes_list() {
Variant udata = i;
EditorResourcePreview::get_singleton()->queue_edited_resource_preview(scene, this, "_scene_thumbnail_done", udata);
} else {
item_index = scene_tiles_list->add_item(TTR("Tile with Invalid Scene"), get_editor_theme_icon(SNAME("PackedScene")));
item_index = scene_tiles_list->add_item(TTR("Tile with Invalid Scene"), get_theme_icon(SNAME("PackedScene"), "EditorIcons"));
}
scene_tiles_list->set_item_metadata(item_index, scene_id);
@ -370,8 +373,8 @@ void LayeredTileSetScenesCollectionSourceEditor::_notification(int p_what) {
} break;
case NOTIFICATION_THEME_CHANGED: {
scene_tile_add_button->set_icon(get_editor_theme_icon(SNAME("Add")));
scene_tile_delete_button->set_icon(get_editor_theme_icon(SNAME("Remove")));
scene_tile_add_button->set_icon(get_theme_icon(SNAME("Add"), "EditorIcons"));
scene_tile_delete_button->set_icon(get_theme_icon(SNAME("Remove"), "EditorIcons"));
_update_scenes_list();
} break;
@ -460,7 +463,7 @@ void LayeredTileSetScenesCollectionSourceEditor::_drop_data_fw(const Point2 &p_p
Ref<PackedScene> resource = ResourceLoader::load(files[i]);
if (resource.is_valid()) {
int scene_id = tile_set_scenes_collection_source->get_next_scene_tile_id();
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
undo_redo->create_action(TTR("Add a Scene Tile"));
undo_redo->add_do_method(tile_set_scenes_collection_source, "create_scene_tile", resource, scene_id);
undo_redo->add_undo_method(tile_set_scenes_collection_source, "remove_scene_tile", scene_id);

View File

@ -38,18 +38,15 @@
#include "../layered_tile_map.h"
#include "../layered_tile_map_layer.h"
#include "../layered_tile_set.h"
#include "editor/editor_interface.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/gui/editor_bottom_panel.h"
#include "editor/plugins/canvas_item_editor_plugin.h"
#include "editor/themes/editor_scale.h"
#include "editor/editor_scale.h"
#include "scene/gui/box_container.h"
#include "scene/gui/button.h"
#include "scene/gui/separator.h"
#include "scene/main/control.h"
#include "scene/resources/image_texture.h"
#include "scene/resources/texture.h"
LayeredTilesEditorUtils *LayeredTilesEditorUtils::singleton = nullptr;
LayeredTileMapEditorPlugin *tile_map_plugin_singleton = nullptr;