New TileSet Editor

This commit is contained in:
MAriano Javier Suligoy 2018-07-29 18:54:12 -03:00 committed by Mariano Javier Suligoy
parent 432f2f1a67
commit ce87a30e45
12 changed files with 1323 additions and 883 deletions

View File

@ -0,0 +1,3 @@
<svg width="16" height="16" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
<path d="m7 1v6h-6v2h6v6h2v-6h6v-2h-6v-6h-2z" fill="#c9cfd4"/>
</svg>

After

Width:  |  Height:  |  Size: 168 B

View File

@ -0,0 +1,3 @@
<svg width="16" height="16" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
<path d="m7 1v6h-6v2h6v6h2v-6h6v-2h-6v-6h-2z" fill="#4490fc"/>
</svg>

After

Width:  |  Height:  |  Size: 168 B

View File

@ -0,0 +1,3 @@
<svg width="16" height="16" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
<path d="m7 1v6h-6v2h6v6h2v-6h6v-2h-6v-6h-2z" fill="#fce844"/>
</svg>

After

Width:  |  Height:  |  Size: 168 B

View File

@ -57,8 +57,6 @@ void TextureRegionEditor::_region_draw() {
base_tex = obj_styleBox->get_texture();
else if (atlas_tex.is_valid())
base_tex = atlas_tex->get_atlas();
else if (tile_set.is_valid() && selected_tile != -1 && tile_set->has_tile(selected_tile))
base_tex = tile_set->tile_get_texture(selected_tile);
if (base_tex.is_null())
return;
@ -284,8 +282,6 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
r = obj_styleBox->get_region_rect();
else if (atlas_tex.is_valid())
r = atlas_tex->get_region();
else if (tile_set.is_valid() && selected_tile != -1)
r = tile_set->tile_get_region(selected_tile);
rect.expand_to(r.position);
rect.expand_to(r.position + r.size);
}
@ -302,9 +298,6 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
} else if (atlas_tex.is_valid()) {
undo_redo->add_do_method(atlas_tex.ptr(), "set_region", rect);
undo_redo->add_undo_method(atlas_tex.ptr(), "set_region", atlas_tex->get_region());
} else if (tile_set.is_valid() && selected_tile != -1) {
undo_redo->add_do_method(tile_set.ptr(), "tile_set_region", selected_tile, rect);
undo_redo->add_undo_method(tile_set.ptr(), "tile_set_region", selected_tile, tile_set->tile_get_region(selected_tile));
}
undo_redo->add_do_method(edit_draw, "update");
undo_redo->add_undo_method(edit_draw, "update");
@ -327,8 +320,6 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
rect_prev = obj_styleBox->get_region_rect();
else if (atlas_tex.is_valid())
rect_prev = atlas_tex->get_region();
else if (tile_set.is_valid() && selected_tile != -1)
rect_prev = tile_set->tile_get_region(selected_tile);
for (int i = 0; i < 8; i++) {
Vector2 tuv = endpoints[i];
@ -372,9 +363,6 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
} else if (obj_styleBox.is_valid()) {
undo_redo->add_do_method(obj_styleBox.ptr(), "set_region_rect", obj_styleBox->get_region_rect());
undo_redo->add_undo_method(obj_styleBox.ptr(), "set_region_rect", rect_prev);
} else if (tile_set.is_valid()) {
undo_redo->add_do_method(tile_set.ptr(), "tile_set_region", selected_tile, tile_set->tile_get_region(selected_tile));
undo_redo->add_undo_method(tile_set.ptr(), "tile_set_region", selected_tile, rect_prev);
}
drag_index = -1;
}
@ -595,8 +583,6 @@ void TextureRegionEditor::apply_rect(const Rect2 &rect) {
obj_styleBox->set_region_rect(rect);
else if (atlas_tex.is_valid())
atlas_tex->set_region(rect);
else if (tile_set.is_valid() && selected_tile != -1)
tile_set->tile_set_region(selected_tile, rect);
}
void TextureRegionEditor::_notification(int p_what) {
@ -623,12 +609,11 @@ void TextureRegionEditor::_notification(int p_what) {
}
void TextureRegionEditor::_node_removed(Object *p_obj) {
if (p_obj == node_sprite || p_obj == node_ninepatch || p_obj == obj_styleBox.ptr() || p_obj == atlas_tex.ptr() || p_obj == tile_set.ptr()) {
if (p_obj == node_sprite || p_obj == node_ninepatch || p_obj == obj_styleBox.ptr() || p_obj == atlas_tex.ptr()) {
node_ninepatch = NULL;
node_sprite = NULL;
obj_styleBox = Ref<StyleBox>(NULL);
atlas_tex = Ref<AtlasTexture>(NULL);
tile_set = Ref<TileSet>(NULL);
hide();
}
}
@ -677,8 +662,6 @@ void TextureRegionEditor::edit(Object *p_obj) {
obj_styleBox->remove_change_receptor(this);
if (atlas_tex.is_valid())
atlas_tex->remove_change_receptor(this);
if (tile_set.is_valid())
tile_set->remove_change_receptor(this);
if (p_obj) {
node_sprite = Object::cast_to<Sprite>(p_obj);
node_ninepatch = Object::cast_to<NinePatchRect>(p_obj);
@ -686,8 +669,6 @@ void TextureRegionEditor::edit(Object *p_obj) {
obj_styleBox = Ref<StyleBoxTexture>(Object::cast_to<StyleBoxTexture>(p_obj));
if (Object::cast_to<AtlasTexture>(p_obj))
atlas_tex = Ref<AtlasTexture>(Object::cast_to<AtlasTexture>(p_obj));
if (Object::cast_to<TileSet>(p_obj))
tile_set = Ref<TileSet>(Object::cast_to<TileSet>(p_obj));
p_obj->add_change_receptor(this);
_edit_region();
} else {
@ -695,7 +676,6 @@ void TextureRegionEditor::edit(Object *p_obj) {
node_ninepatch = NULL;
obj_styleBox = Ref<StyleBoxTexture>(NULL);
atlas_tex = Ref<AtlasTexture>(NULL);
tile_set = Ref<TileSet>(NULL);
}
edit_draw->update();
if (node_sprite && !node_sprite->is_region()) {
@ -724,8 +704,6 @@ void TextureRegionEditor::_edit_region() {
texture = obj_styleBox->get_texture();
else if (atlas_tex.is_valid())
texture = atlas_tex->get_atlas();
else if (tile_set.is_valid() && selected_tile != -1 && tile_set->has_tile(selected_tile))
texture = tile_set->tile_get_texture(selected_tile);
if (texture.is_null()) {
edit_draw->update();
@ -794,8 +772,6 @@ void TextureRegionEditor::_edit_region() {
rect = obj_styleBox->get_region_rect();
else if (atlas_tex.is_valid())
rect = atlas_tex->get_region();
else if (tile_set.is_valid() && selected_tile != -1)
rect = tile_set->tile_get_region(selected_tile);
edit_draw->update();
}
@ -814,10 +790,8 @@ TextureRegionEditor::TextureRegionEditor(EditorNode *p_editor) {
node_ninepatch = NULL;
obj_styleBox = Ref<StyleBoxTexture>(NULL);
atlas_tex = Ref<AtlasTexture>(NULL);
tile_set = Ref<TileSet>(NULL);
editor = p_editor;
undo_redo = editor->get_undo_redo();
selected_tile = -1;
snap_step = Vector2(10, 10);
snap_separation = Vector2(0, 0);

View File

@ -38,7 +38,6 @@
#include "scene/gui/nine_patch_rect.h"
#include "scene/resources/style_box.h"
#include "scene/resources/texture.h"
#include "scene/resources/tile_set.h"
/**
@author Mariano Suligoy
@ -56,8 +55,6 @@ class TextureRegionEditor : public Control {
};
friend class TextureRegionEditorPlugin;
friend class TileSetEditor;
friend class TileSetEditorPlugin;
MenuButton *snap_mode_button;
TextureRect *icon_zoom;
ToolButton *zoom_in;
@ -91,14 +88,12 @@ class TextureRegionEditor : public Control {
Sprite *node_sprite;
Ref<StyleBoxTexture> obj_styleBox;
Ref<AtlasTexture> atlas_tex;
Ref<TileSet> tile_set;
Rect2 rect;
Rect2 rect_prev;
float prev_margin;
int edited_margin;
List<Rect2> autoslice_cache;
int selected_tile;
bool drag;
bool creating;

View File

@ -168,10 +168,11 @@ void TileMapEditor::_menu_option(int p_option) {
}
void TileMapEditor::_palette_selected(int index) {
_update_palette();
}
if (manual_autotile) {
_update_palette();
}
void TileMapEditor::_palette_multi_selected(int index, bool selected) {
_update_palette();
}
void TileMapEditor::_canvas_mouse_enter() {
@ -296,7 +297,7 @@ void TileMapEditor::_set_cell(const Point2i &p_pos, Vector<int> p_values, bool p
}
node->set_cell(p_pos.x, p_pos.y, p_value, p_flip_h, p_flip_v, p_transpose);
if (manual_autotile) {
if (manual_autotile || node->get_tileset()->tile_get_tile_mode(p_value) == TileSet::ATLAS_TILE) {
if (current != -1) {
node->set_cell_autotile_coord(p_pos.x, p_pos.y, position);
}
@ -317,7 +318,6 @@ void TileMapEditor::_text_entered(const String &p_text) {
}
void TileMapEditor::_text_changed(const String &p_text) {
_update_palette();
}
@ -427,7 +427,7 @@ void TileMapEditor::_update_palette() {
if (tex.is_valid()) {
Rect2 region = tileset->tile_get_region(entries[i].id);
if (tileset->tile_get_tile_mode(entries[i].id) == TileSet::AUTO_TILE) {
if (tileset->tile_get_tile_mode(entries[i].id) == TileSet::AUTO_TILE || tileset->tile_get_tile_mode(entries[i].id) == TileSet::ATLAS_TILE) {
int spacing = tileset->autotile_get_spacing(entries[i].id);
region.size = tileset->autotile_get_size(entries[i].id);
region.position += (region.size + Vector2(spacing, spacing)) * tileset->autotile_get_icon_coordinate(entries[i].id);
@ -450,7 +450,7 @@ void TileMapEditor::_update_palette() {
palette->select(0);
}
if (manual_autotile && tileset->tile_get_tile_mode(sel_tile) == TileSet::AUTO_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);
@ -676,10 +676,10 @@ void TileMapEditor::_draw_cell(int p_cell, const Point2i &p_point, bool p_flip_h
Vector2 tile_ofs = node->get_tileset()->tile_get_texture_offset(p_cell);
Rect2 r = node->get_tileset()->tile_get_region(p_cell);
if (node->get_tileset()->tile_get_tile_mode(p_cell) == TileSet::AUTO_TILE) {
if (node->get_tileset()->tile_get_tile_mode(p_cell) == TileSet::AUTO_TILE || node->get_tileset()->tile_get_tile_mode(p_cell) == TileSet::ATLAS_TILE) {
Vector2 offset;
int selected = manual_palette->get_current();
if (manual_autotile && selected != -1) {
if ((manual_autotile || node->get_tileset()->tile_get_tile_mode(p_cell) == TileSet::ATLAS_TILE) && selected != -1) {
offset = manual_palette->get_item_metadata(selected);
} else {
offset = node->get_tileset()->autotile_get_icon_coordinate(p_cell);
@ -1673,6 +1673,7 @@ void TileMapEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_tileset_settings_changed"), &TileMapEditor::_tileset_settings_changed);
ClassDB::bind_method(D_METHOD("_update_transform_buttons"), &TileMapEditor::_update_transform_buttons);
ClassDB::bind_method(D_METHOD("_palette_selected"), &TileMapEditor::_palette_selected);
ClassDB::bind_method(D_METHOD("_palette_multi_selected"), &TileMapEditor::_palette_multi_selected);
ClassDB::bind_method(D_METHOD("_fill_points"), &TileMapEditor::_fill_points);
ClassDB::bind_method(D_METHOD("_erase_points"), &TileMapEditor::_erase_points);
@ -1800,6 +1801,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) {
palette->set_max_text_lines(2);
palette->set_select_mode(ItemList::SELECT_MULTI);
palette->connect("item_selected", this, "_palette_selected");
palette->connect("multi_selected", this, "_palette_multi_selected");
palette_container->add_child(palette);
// Add autotile override palette

View File

@ -184,6 +184,7 @@ class TileMapEditor : public VBoxContainer {
void _update_palette();
void _menu_option(int p_option);
void _palette_selected(int index);
void _palette_multi_selected(int index, bool selected);
void _start_undo(const String &p_action);
void _finish_undo();

File diff suppressed because it is too large Load Diff

View File

@ -33,21 +33,38 @@
#include "editor/editor_name_dialog.h"
#include "editor/editor_node.h"
#include "editor/plugins/texture_region_editor_plugin.h"
#include "scene/2d/sprite.h"
#include "scene/resources/convex_polygon_shape_2d.h"
#include "scene/resources/tile_set.h"
class TileSetEditorHelper;
#define WORKSPACE_MARGIN Vector2(10, 10)
class TilesetEditorContext;
class TileSetEditor : public Control {
class TileSetEditor : public Panel {
friend class TileSetEditorPlugin;
friend class TextureRegionEditor;
friend class TilesetEditorContext;
GDCLASS(TileSetEditor, Control);
GDCLASS(TileSetEditor, Panel)
enum TextureToolButtons {
TOOL_TILESET_ADD_TEXTURE,
TOOL_TILESET_REMOVE_TEXTURE,
TOOL_TILESET_CREATE_SCENE,
TOOL_TILESET_MERGE_SCENE,
TOOL_TILESET_MAX
};
enum WorkspaceMode {
WORKSPACE_EDIT,
WORKSPACE_CREATE_SINGLE,
WORKSPACE_CREATE_AUTOTILE,
WORKSPACE_CREATE_ATLAS,
WORKSPACE_MODE_MAX
};
enum EditMode {
EDITMODE_REGION,
EDITMODE_COLLISION,
EDITMODE_OCCLUSION,
EDITMODE_NAVIGATION,
@ -57,13 +74,6 @@ class TileSetEditor : public Control {
EDITMODE_MAX
};
enum TileSetToolbar {
TOOLBAR_DUMMY,
TOOLBAR_BITMASK,
TOOLBAR_SHAPE,
TOOLBAR_MAX
};
enum TileSetTools {
TOOL_SELECT,
BITMASK_COPY,
@ -71,17 +81,42 @@ class TileSetEditor : public Control {
BITMASK_CLEAR,
SHAPE_NEW_POLYGON,
SHAPE_DELETE,
SHAPE_CREATE_FROM_BITMASK,
SHAPE_CREATE_FROM_NOT_BITMASK,
SHAPE_KEEP_INSIDE_TILE,
SHAPE_GRID_SNAP,
TOOL_GRID_SNAP,
ZOOM_OUT,
ZOOM_1,
ZOOM_IN,
VISIBLE_INFO,
TOOL_MAX
};
Ref<TileSet> tileset;
TilesetEditorContext *helper;
EditorNode *editor;
ConfirmationDialog *cd;
AcceptDialog *err_dialog;
EditorFileDialog *texture_dialog;
ItemList *texture_list;
int option;
ToolButton *tileset_toolbar_buttons[TOOL_TILESET_MAX];
MenuButton *tileset_toolbar_tools;
Map<RID, Ref<Texture> > texture_map;
bool creating_shape;
int dragging_point;
float tile_names_opacity;
Vector2 region_from;
Rect2 edited_region;
bool draw_edited_region;
Vector2 edited_shape_coord;
PoolVector2Array current_shape;
Map<Vector2, uint16_t> bitmask_map_copy;
Vector2 snap_step;
Vector2 snap_offset;
Vector2 snap_separation;
Ref<ConvexPolygonShape2D> edited_collision_shape;
Ref<OccluderPolygon2D> edited_occlusion_shape;
@ -94,55 +129,19 @@ class TileSetEditor : public Control {
bool draw_handles;
Control *workspace_overlay;
Control *workspace;
Button *tool_workspacemode[WORKSPACE_MODE_MAX];
Button *tool_editmode[EDITMODE_MAX];
HBoxContainer *tool_containers[TOOLBAR_MAX];
HBoxContainer *toolbar;
HBoxContainer *hb_grid;
ToolButton *tools[TOOL_MAX];
SpinBox *spin_priority;
SpinBox *sb_step_y;
SpinBox *sb_step_x;
SpinBox *sb_off_y;
SpinBox *sb_off_x;
SpinBox *sb_sep_y;
SpinBox *sb_sep_x;
WorkspaceMode workspace_mode;
EditMode edit_mode;
int current_tile;
Vector2 snap_step;
Vector2 snap_offset;
Vector2 snap_separation;
void update_texture_list();
void update_texture_list_icon();
bool creating_shape;
int dragging_point;
Vector2 edited_shape_coord;
PoolVector2Array current_shape;
Map<Vector2, uint16_t> bitmask_map_copy;
EditorNode *editor;
TextureRegionEditor *texture_region_editor;
Control *bottom_panel;
Control *side_panel;
ItemList *tile_list;
PropertyEditor *property_editor;
TileSetEditorHelper *helper;
MenuButton *menu;
ConfirmationDialog *cd;
EditorNameDialog *nd;
AcceptDialog *err_dialog;
enum {
MENU_OPTION_ADD_ITEM,
MENU_OPTION_REMOVE_ITEM,
MENU_OPTION_CREATE_FROM_SCENE,
MENU_OPTION_MERGE_FROM_SCENE
};
int option;
void _menu_cbk(int p_option);
void _menu_confirm();
void _name_dialog_confirm(const String &name);
Ref<Texture> get_current_texture();
static void _import_node(Node *p_node, Ref<TileSet> p_library);
static void _import_scene(Node *p_scene, Ref<TileSet> p_library, bool p_merge);
@ -150,7 +149,6 @@ class TileSetEditor : public Control {
protected:
static void _bind_methods();
void _notification(int p_what);
virtual void _changed_callback(Object *p_changed, const char *p_prop);
public:
void edit(const Ref<TileSet> &p_tileset);
@ -160,53 +158,61 @@ public:
~TileSetEditor();
private:
void _on_tile_list_selected(int p_index);
void _on_tileset_toolbar_button_pressed(int p_index);
void _on_tileset_toolbar_confirm();
void _on_texture_list_selected(int p_index);
void _on_textures_added(const PoolStringArray &p_paths);
void _on_edit_mode_changed(int p_edit_mode);
void _on_workspace_mode_changed(int p_workspace_mode);
void _on_workspace_overlay_draw();
void _on_workspace_draw();
void _on_workspace_process();
void _on_workspace_input(const Ref<InputEvent> &p_ie);
void _on_tool_clicked(int p_tool);
void _on_priority_changed(float val);
void _on_grid_snap_toggled(bool p_val);
void _set_snap_step_x(float p_val);
void _set_snap_step_y(float p_val);
void _set_snap_off_x(float p_val);
void _set_snap_off_y(float p_val);
void _set_snap_sep_x(float p_val);
void _set_snap_sep_y(float p_val);
void _set_snap_step(Vector2 p_val);
void _set_snap_off(Vector2 p_val);
void _set_snap_sep(Vector2 p_val);
void initialize_bottom_editor();
void draw_highlight_tile(Vector2 coord, const Vector<Vector2> &other_highlighted = Vector<Vector2>());
void draw_highlight_current_tile();
void draw_highlight_subtile(Vector2 coord, const Vector<Vector2> &other_highlighted = Vector<Vector2>());
void draw_tile_subdivision(int p_id, Color p_color) const;
void draw_edited_region_subdivision() const;
void draw_grid_snap();
void draw_polygon_shapes();
void close_shape(const Vector2 &shape_anchor);
void select_coord(const Vector2 &coord);
Vector2 snap_point(const Vector2 &point);
void update_tile_list();
void update_tile_list_icon();
void update_workspace_tile_mode();
void update_edited_region(const Vector2 &end_point);
int get_current_tile();
int get_current_tile() const;
void set_current_tile(int p_id);
};
class TileSetEditorHelper : public Object {
class TilesetEditorContext : public Object {
friend class TileSetEditor;
GDCLASS(TileSetEditorHelper, Object);
GDCLASS(TilesetEditorContext, Object);
Ref<TileSet> tileset;
TileSetEditor *tileset_editor;
int selected_tile;
bool snap_options_visible;
public:
void set_tileset(const Ref<TileSet> &p_tileset);
private:
void set_snap_options_visible(bool p_visible);
protected:
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
TileSetEditorHelper(TileSetEditor *p_tileset_editor);
public:
TilesetEditorContext(TileSetEditor *p_tileset_editor);
};
class TileSetEditorPlugin : public EditorPlugin {
@ -214,11 +220,9 @@ class TileSetEditorPlugin : public EditorPlugin {
GDCLASS(TileSetEditorPlugin, EditorPlugin);
TileSetEditor *tileset_editor;
Button *tileset_editor_button;
EditorNode *editor;
ToolButton *tileset_editor_button;
ToolButton *texture_region_button;
public:
virtual String get_name() const { return "TileSet"; }
bool has_main_screen() const { return false; }

View File

@ -368,7 +368,7 @@ void TileMap::update_dirty_quadrants() {
}
Rect2 r = tile_set->tile_get_region(c.id);
if (tile_set->tile_get_tile_mode(c.id) == TileSet::AUTO_TILE) {
if (tile_set->tile_get_tile_mode(c.id) == TileSet::AUTO_TILE || tile_set->tile_get_tile_mode(c.id) == TileSet::ATLAS_TILE) {
int spacing = tile_set->autotile_get_spacing(c.id);
r.size = tile_set->autotile_get_size(c.id);
r.position += (r.size + Vector2(spacing, spacing)) * Vector2(c.autotile_coord_x, c.autotile_coord_y);
@ -491,7 +491,7 @@ void TileMap::update_dirty_quadrants() {
if (navigation) {
Ref<NavigationPolygon> navpoly;
Vector2 npoly_ofs;
if (tile_set->tile_get_tile_mode(c.id) == TileSet::AUTO_TILE) {
if (tile_set->tile_get_tile_mode(c.id) == TileSet::AUTO_TILE || tile_set->tile_get_tile_mode(c.id) == TileSet::ATLAS_TILE) {
navpoly = tile_set->autotile_get_navigation_polygon(c.id, Vector2(c.autotile_coord_x, c.autotile_coord_y));
npoly_ofs = Vector2();
} else {
@ -563,7 +563,7 @@ void TileMap::update_dirty_quadrants() {
}
Ref<OccluderPolygon2D> occluder;
if (tile_set->tile_get_tile_mode(c.id) == TileSet::AUTO_TILE) {
if (tile_set->tile_get_tile_mode(c.id) == TileSet::AUTO_TILE || tile_set->tile_get_tile_mode(c.id) == TileSet::ATLAS_TILE) {
occluder = tile_set->autotile_get_light_occluder(c.id, Vector2(c.autotile_coord_x, c.autotile_coord_y));
} else {
occluder = tile_set->tile_get_light_occluder(c.id);
@ -840,7 +840,7 @@ void TileMap::update_cell_bitmask(int p_x, int p_y) {
Map<PosKey, Cell>::Element *E = tile_map.find(p);
if (E != NULL) {
int id = get_cell(p_x, p_y);
if (tile_set->tile_get_tile_mode(id) == TileSet::AUTO_TILE) {
if (tile_set->tile_get_tile_mode(id) == TileSet::AUTO_TILE || tile_set->tile_get_tile_mode(id) == TileSet::ATLAS_TILE) {
uint16_t mask = 0;
if (tile_set->autotile_get_bitmask_mode(id) == TileSet::BITMASK_2X2) {
if (tile_set->is_tile_bound(id, get_cell(p_x - 1, p_y - 1)) && tile_set->is_tile_bound(id, get_cell(p_x, p_y - 1)) && tile_set->is_tile_bound(id, get_cell(p_x - 1, p_y))) {

View File

@ -262,7 +262,7 @@ void TileSet::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial"));
p_list->push_back(PropertyInfo(Variant::COLOR, pre + "modulate"));
p_list->push_back(PropertyInfo(Variant::RECT2, pre + "region"));
p_list->push_back(PropertyInfo(Variant::INT, pre + "tile_mode", PROPERTY_HINT_ENUM, "SINGLE_TILE,AUTO_TILE"));
p_list->push_back(PropertyInfo(Variant::INT, pre + "tile_mode", PROPERTY_HINT_ENUM, "SINGLE_TILE,AUTO_TILE,ATLAS_TILE"));
if (tile_get_tile_mode(id) == AUTO_TILE) {
p_list->push_back(PropertyInfo(Variant::INT, pre + "autotile/bitmask_mode", PROPERTY_HINT_ENUM, "2X2,3X3 (minimal),3X3", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/bitmask_flags", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
@ -272,6 +272,12 @@ void TileSet::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/occluder_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/navpoly_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/priority_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
} else if (tile_get_tile_mode(id) == ATLAS_TILE) {
p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "autotile/icon_coordinate", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "autotile/tile_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
p_list->push_back(PropertyInfo(Variant::INT, pre + "autotile/spacing", PROPERTY_HINT_RANGE, "0,256,1", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/occluder_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/navpoly_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
}
p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "occluder_offset"));
p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "occluder", PROPERTY_HINT_RESOURCE_TYPE, "OccluderPolygon2D"));
@ -494,8 +500,21 @@ uint16_t TileSet::autotile_get_bitmask(int p_id, Vector2 p_coord) {
const Map<Vector2, uint16_t> &TileSet::autotile_get_bitmask_map(int p_id) {
static Map<Vector2, uint16_t> dummy;
static Map<Vector2, uint16_t> dummy_atlas;
ERR_FAIL_COND_V(!tile_map.has(p_id), dummy);
return tile_map[p_id].autotile_data.flags;
if (tile_get_tile_mode(p_id) == ATLAS_TILE) {
dummy_atlas = Map<Vector2, uint16_t>();
Rect2 region = tile_get_region(p_id);
Size2 size = autotile_get_size(p_id);
float spacing = autotile_get_spacing(p_id);
for (int x = 0; x < (region.size.x / (size.x + spacing)); x++) {
for (int y = 0; y < (region.size.y / (size.y + spacing)); y++) {
dummy_atlas.insert(Vector2(x, y), 0);
}
}
return dummy_atlas;
} else
return tile_map[p_id].autotile_data.flags;
}
Vector2 TileSet::autotile_get_subtile_for_bitmask(int p_id, uint16_t p_bitmask, const Node *p_tilemap_node, const Vector2 &p_tile_location) {
@ -976,7 +995,7 @@ void TileSet::_bind_methods() {
BIND_ENUM_CONSTANT(SINGLE_TILE);
BIND_ENUM_CONSTANT(AUTO_TILE);
BIND_ENUM_CONSTANT(ANIMATED_TILE);
BIND_ENUM_CONSTANT(ATLAS_TILE);
}
TileSet::TileSet() {

View File

@ -75,7 +75,7 @@ public:
enum TileMode {
SINGLE_TILE,
AUTO_TILE,
ANIMATED_TILE
ATLAS_TILE
};
struct AutotileData {