Merge pull request #21456 from MarianoGnu/tileset_editor
TileSet editor Fixes
This commit is contained in:
commit
9df5ddae29
|
@ -457,36 +457,38 @@ void TileMapEditor::_update_palette() {
|
||||||
palette->select(0);
|
palette->select(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((manual_autotile && tileset->tile_get_tile_mode(sel_tile) == TileSet::AUTO_TILE) || tileset->tile_get_tile_mode(sel_tile) == TileSet::ATLAS_TILE) {
|
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) {
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
Vector<Vector2> entries;
|
Vector<Vector2> entries;
|
||||||
for (const Map<Vector2, uint16_t>::Element *E = tiles.front(); E; E = E->next()) {
|
for (const Map<Vector2, uint16_t>::Element *E = tiles.front(); E; E = E->next()) {
|
||||||
entries.push_back(E->key());
|
entries.push_back(E->key());
|
||||||
}
|
|
||||||
entries.sort();
|
|
||||||
|
|
||||||
Ref<Texture> tex = tileset->tile_get_texture(sel_tile);
|
|
||||||
|
|
||||||
for (int i = 0; i < entries.size(); i++) {
|
|
||||||
|
|
||||||
manual_palette->add_item(String());
|
|
||||||
|
|
||||||
if (tex.is_valid()) {
|
|
||||||
|
|
||||||
Rect2 region = tileset->tile_get_region(sel_tile);
|
|
||||||
int spacing = tileset->autotile_get_spacing(sel_tile);
|
|
||||||
region.size = tileset->autotile_get_size(sel_tile); // !!
|
|
||||||
region.position += (region.size + Vector2(spacing, spacing)) * entries[i];
|
|
||||||
|
|
||||||
if (!region.has_no_area())
|
|
||||||
manual_palette->set_item_icon_region(manual_palette->get_item_count() - 1, region);
|
|
||||||
|
|
||||||
manual_palette->set_item_icon(manual_palette->get_item_count() - 1, tex);
|
|
||||||
}
|
}
|
||||||
|
entries.sort();
|
||||||
|
|
||||||
manual_palette->set_item_metadata(manual_palette->get_item_count() - 1, entries[i]);
|
Ref<Texture> tex = tileset->tile_get_texture(sel_tile);
|
||||||
|
|
||||||
|
for (int i = 0; i < entries.size(); i++) {
|
||||||
|
|
||||||
|
manual_palette->add_item(String());
|
||||||
|
|
||||||
|
if (tex.is_valid()) {
|
||||||
|
|
||||||
|
Rect2 region = tileset->tile_get_region(sel_tile);
|
||||||
|
int spacing = tileset->autotile_get_spacing(sel_tile);
|
||||||
|
region.size = tileset->autotile_get_size(sel_tile); // !!
|
||||||
|
region.position += (region.size + Vector2(spacing, spacing)) * entries[i];
|
||||||
|
|
||||||
|
if (!region.has_no_area())
|
||||||
|
manual_palette->set_item_icon_region(manual_palette->get_item_count() - 1, region);
|
||||||
|
|
||||||
|
manual_palette->set_item_icon(manual_palette->get_item_count() - 1, tex);
|
||||||
|
}
|
||||||
|
|
||||||
|
manual_palette->set_item_metadata(manual_palette->get_item_count() - 1, entries[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue