1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

TileSet editor Fixes

Properly draw navigation and oclusion polygons for SINGLE type tiles. Fixes #21398
Add some checks for TileID validation before accessing to it's properties. Fixes #21397
Fix 'Keep inside region' snap option for tiles with SINGLE_TILE mode. Fixes #21402
Restore hability to asign/unasign an script to a tileset. Fixes #20886
This commit is contained in:
Mariano Javier Suligoy
2018-08-26 17:10:01 -03:00
parent db55d8a4b6
commit c64ab97063
2 changed files with 51 additions and 33 deletions

View File

@@ -457,6 +457,7 @@ void TileMapEditor::_update_palette() {
palette->select(0); palette->select(0);
} }
if (sel_tile != TileMap::INVALID_CELL) {
if ((manual_autotile && tileset->tile_get_tile_mode(sel_tile) == TileSet::AUTO_TILE) || tileset->tile_get_tile_mode(sel_tile) == TileSet::ATLAS_TILE) { if ((manual_autotile && tileset->tile_get_tile_mode(sel_tile) == TileSet::AUTO_TILE) || tileset->tile_get_tile_mode(sel_tile) == TileSet::ATLAS_TILE) {
const Map<Vector2, uint16_t> &tiles = tileset->autotile_get_bitmask_map(sel_tile); const Map<Vector2, uint16_t> &tiles = tileset->autotile_get_bitmask_map(sel_tile);
@@ -489,6 +490,7 @@ void TileMapEditor::_update_palette() {
manual_palette->set_item_metadata(manual_palette->get_item_count() - 1, entries[i]); manual_palette->set_item_metadata(manual_palette->get_item_count() - 1, entries[i]);
} }
} }
}
if (manual_palette->get_item_count() > 0) { if (manual_palette->get_item_count() > 0) {
// Only show the manual palette if at least tile exists in it // Only show the manual palette if at least tile exists in it

View File

@@ -1715,16 +1715,18 @@ void TileSetEditor::draw_polygon_shapes() {
Vector<Vector2> polygon; Vector<Vector2> polygon;
Vector<Color> colors; Vector<Color> colors;
Vector2 anchor = WORKSPACE_MARGIN;
anchor += tileset->tile_get_region(get_current_tile()).position;
for (int j = 0; j < shape->get_polygon().size(); j++) { for (int j = 0; j < shape->get_polygon().size(); j++) {
polygon.push_back(shape->get_polygon()[j]); polygon.push_back(shape->get_polygon()[j] + anchor);
colors.push_back(c_bg); colors.push_back(c_bg);
} }
workspace->draw_polygon(polygon, colors); workspace->draw_polygon(polygon, colors);
for (int j = 0; j < shape->get_polygon().size() - 1; j++) { for (int j = 0; j < shape->get_polygon().size() - 1; j++) {
workspace->draw_line(shape->get_polygon()[j], shape->get_polygon()[j + 1], c_border, 1, true); workspace->draw_line(shape->get_polygon()[j] + anchor, shape->get_polygon()[j + 1] + anchor, c_border, 1, true);
} }
workspace->draw_line(shape->get_polygon()[shape->get_polygon().size() - 1], shape->get_polygon()[0], c_border, 1, true); workspace->draw_line(shape->get_polygon()[shape->get_polygon().size() - 1] + anchor, shape->get_polygon()[0] + anchor, c_border, 1, true);
if (shape == edited_occlusion_shape) { if (shape == edited_occlusion_shape) {
draw_handles = true; draw_handles = true;
} }
@@ -1788,10 +1790,11 @@ void TileSetEditor::draw_polygon_shapes() {
Vector<Vector2> polygon; Vector<Vector2> polygon;
Vector<Color> colors; Vector<Color> colors;
Vector2 anchor = WORKSPACE_MARGIN;
anchor += tileset->tile_get_region(get_current_tile()).position;
PoolVector<Vector2> vertices = shape->get_vertices(); PoolVector<Vector2> vertices = shape->get_vertices();
for (int j = 0; j < shape->get_polygon(0).size(); j++) { for (int j = 0; j < shape->get_polygon(0).size(); j++) {
polygon.push_back(vertices[shape->get_polygon(0)[j]]); polygon.push_back(vertices[shape->get_polygon(0)[j]] + anchor);
colors.push_back(c_bg); colors.push_back(c_bg);
} }
workspace->draw_polygon(polygon, colors); workspace->draw_polygon(polygon, colors);
@@ -1799,7 +1802,7 @@ void TileSetEditor::draw_polygon_shapes() {
if (shape->get_polygon_count() > 0) { if (shape->get_polygon_count() > 0) {
PoolVector<Vector2> vertices = shape->get_vertices(); PoolVector<Vector2> vertices = shape->get_vertices();
for (int j = 0; j < shape->get_polygon(0).size() - 1; j++) { for (int j = 0; j < shape->get_polygon(0).size() - 1; j++) {
workspace->draw_line(vertices[shape->get_polygon(0)[j]], vertices[shape->get_polygon(0)[j + 1]], c_border, 1, true); workspace->draw_line(vertices[shape->get_polygon(0)[j]] + anchor, vertices[shape->get_polygon(0)[j + 1]] + anchor, c_border, 1, true);
} }
if (shape == edited_navigation_shape) { if (shape == edited_navigation_shape) {
draw_handles = true; draw_handles = true;
@@ -1954,6 +1957,8 @@ void TileSetEditor::close_shape(const Vector2 &shape_anchor) {
void TileSetEditor::select_coord(const Vector2 &coord) { void TileSetEditor::select_coord(const Vector2 &coord) {
current_shape = PoolVector2Array(); current_shape = PoolVector2Array();
if (get_current_tile() == -1)
return;
Rect2 current_tile_region = tileset->tile_get_region(get_current_tile()); Rect2 current_tile_region = tileset->tile_get_region(get_current_tile());
current_tile_region.position += WORKSPACE_MARGIN; current_tile_region.position += WORKSPACE_MARGIN;
if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) { if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) {
@@ -2038,8 +2043,10 @@ Vector2 TileSetEditor::snap_point(const Vector2 &point) {
anchor += tileset->tile_get_region(get_current_tile()).position; anchor += tileset->tile_get_region(get_current_tile()).position;
anchor += WORKSPACE_MARGIN; anchor += WORKSPACE_MARGIN;
Rect2 region(anchor, tile_size); Rect2 region(anchor, tile_size);
if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) {
region.position = tileset->tile_get_region(get_current_tile()).position + WORKSPACE_MARGIN; region.position = tileset->tile_get_region(get_current_tile()).position + WORKSPACE_MARGIN;
region.size = tileset->tile_get_region(get_current_tile()).size;
}
if (tools[TOOL_GRID_SNAP]->is_pressed()) { if (tools[TOOL_GRID_SNAP]->is_pressed()) {
p.x = Math::snap_scalar_seperation(snap_offset.x, snap_step.x, p.x, snap_separation.x); p.x = Math::snap_scalar_seperation(snap_offset.x, snap_step.x, p.x, snap_separation.x);
@@ -2254,6 +2261,9 @@ bool TilesetEditorContext::_set(const StringName &p_name, const Variant &p_value
tileset_editor->workspace_overlay->update(); tileset_editor->workspace_overlay->update();
} }
return v; return v;
} else if (name == "tileset_script") {
tileset->set_script(p_value);
return true;
} }
tileset_editor->err_dialog->set_text(TTR("This property can't be changed.")); tileset_editor->err_dialog->set_text(TTR("This property can't be changed."));
@@ -2302,6 +2312,9 @@ bool TilesetEditorContext::_get(const StringName &p_name, Variant &r_ret) const
} else if (name == "selected_occlusion") { } else if (name == "selected_occlusion") {
r_ret = tileset_editor->edited_occlusion_shape; r_ret = tileset_editor->edited_occlusion_shape;
v = true; v = true;
} else if (name == "tileset_script") {
r_ret = tileset->get_script();
v = true;
} }
return v; return v;
} }
@@ -2346,6 +2359,9 @@ void TilesetEditorContext::_get_property_list(List<PropertyInfo> *p_list) const
if (tileset_editor->edit_mode == TileSetEditor::EDITMODE_OCCLUSION && tileset_editor->edited_occlusion_shape.is_valid()) { if (tileset_editor->edit_mode == TileSetEditor::EDITMODE_OCCLUSION && tileset_editor->edited_occlusion_shape.is_valid()) {
p_list->push_back(PropertyInfo(Variant::OBJECT, "selected_occlusion", PROPERTY_HINT_RESOURCE_TYPE, tileset_editor->edited_occlusion_shape->get_class())); p_list->push_back(PropertyInfo(Variant::OBJECT, "selected_occlusion", PROPERTY_HINT_RESOURCE_TYPE, tileset_editor->edited_occlusion_shape->get_class()));
} }
if (!tileset.is_null()) {
p_list->push_back(PropertyInfo(Variant::OBJECT, "tileset_script", PROPERTY_HINT_RESOURCE_TYPE, "Script"));
}
} }
TilesetEditorContext::TilesetEditorContext(TileSetEditor *p_tileset_editor) { TilesetEditorContext::TilesetEditorContext(TileSetEditor *p_tileset_editor) {