2014-02-10 09:10:30 +08:00
|
|
|
/*************************************************************************/
|
|
|
|
/* tile_set_editor_plugin.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 20:16:55 +08:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 09:10:30 +08:00
|
|
|
/*************************************************************************/
|
2017-01-02 05:01:57 +08:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-08 06:11:42 +08:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 09:10:30 +08:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#ifndef TILE_SET_EDITOR_PLUGIN_H
|
|
|
|
#define TILE_SET_EDITOR_PLUGIN_H
|
|
|
|
|
2017-03-05 21:21:25 +08:00
|
|
|
#include "editor/editor_name_dialog.h"
|
2017-03-05 23:44:50 +08:00
|
|
|
#include "editor/editor_node.h"
|
2017-10-22 09:42:23 +08:00
|
|
|
#include "scene/2d/sprite.h"
|
2017-12-28 13:57:37 +08:00
|
|
|
#include "scene/resources/convex_polygon_shape_2d.h"
|
2017-03-05 23:44:50 +08:00
|
|
|
#include "scene/resources/tile_set.h"
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-10-22 09:42:23 +08:00
|
|
|
class AutotileEditorHelper;
|
|
|
|
class AutotileEditor : public Control {
|
|
|
|
|
|
|
|
friend class TileSetEditorPlugin;
|
|
|
|
friend class AutotileEditorHelper;
|
|
|
|
GDCLASS(AutotileEditor, Control);
|
|
|
|
|
|
|
|
enum EditMode {
|
|
|
|
EDITMODE_ICON,
|
|
|
|
EDITMODE_BITMASK,
|
|
|
|
EDITMODE_COLLISION,
|
|
|
|
EDITMODE_OCCLUSION,
|
|
|
|
EDITMODE_NAVIGATION,
|
|
|
|
EDITMODE_PRIORITY,
|
|
|
|
EDITMODE_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
enum AutotileToolbars {
|
|
|
|
TOOLBAR_DUMMY,
|
|
|
|
TOOLBAR_BITMASK,
|
|
|
|
TOOLBAR_SHAPE,
|
|
|
|
TOOLBAR_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
enum AutotileTools {
|
|
|
|
TOOL_SELECT,
|
|
|
|
BITMASK_COPY,
|
|
|
|
BITMASK_PASTE,
|
|
|
|
BITMASK_CLEAR,
|
|
|
|
SHAPE_NEW_POLYGON,
|
|
|
|
SHAPE_DELETE,
|
|
|
|
SHAPE_CREATE_FROM_BITMASK,
|
|
|
|
SHAPE_CREATE_FROM_NOT_BITMASK,
|
|
|
|
SHAPE_KEEP_INSIDE_TILE,
|
2017-12-28 13:57:37 +08:00
|
|
|
SHAPE_GRID_SNAP,
|
2017-10-22 09:42:23 +08:00
|
|
|
ZOOM_OUT,
|
|
|
|
ZOOM_1,
|
|
|
|
ZOOM_IN,
|
|
|
|
TOOL_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
Ref<TileSet> tile_set;
|
2017-12-28 13:57:37 +08:00
|
|
|
Ref<ConvexPolygonShape2D> edited_collision_shape;
|
2017-10-22 09:42:23 +08:00
|
|
|
Ref<OccluderPolygon2D> edited_occlusion_shape;
|
|
|
|
Ref<NavigationPolygon> edited_navigation_shape;
|
|
|
|
|
|
|
|
EditorNode *editor;
|
|
|
|
|
|
|
|
int current_item_index;
|
|
|
|
Sprite *preview;
|
|
|
|
Control *workspace_container;
|
|
|
|
Control *workspace;
|
|
|
|
Button *tool_editmode[EDITMODE_MAX];
|
|
|
|
HBoxContainer *tool_containers[TOOLBAR_MAX];
|
|
|
|
HBoxContainer *toolbar;
|
2017-12-28 13:57:37 +08:00
|
|
|
HBoxContainer *hb_grid;
|
2017-10-22 09:42:23 +08:00
|
|
|
ToolButton *tools[TOOL_MAX];
|
|
|
|
SpinBox *spin_priority;
|
2017-12-28 13:57:37 +08:00
|
|
|
SpinBox *sb_step_y;
|
|
|
|
SpinBox *sb_step_x;
|
|
|
|
SpinBox *sb_off_y;
|
|
|
|
SpinBox *sb_off_x;
|
|
|
|
SpinBox *sb_sep_y;
|
|
|
|
SpinBox *sb_sep_x;
|
2017-10-22 09:42:23 +08:00
|
|
|
EditMode edit_mode;
|
|
|
|
|
2017-12-28 13:57:37 +08:00
|
|
|
Vector2 snap_step;
|
|
|
|
Vector2 snap_offset;
|
|
|
|
Vector2 snap_separation;
|
|
|
|
|
2017-10-22 09:42:23 +08:00
|
|
|
bool creating_shape;
|
|
|
|
int dragging_point;
|
|
|
|
Vector2 edited_shape_coord;
|
|
|
|
PoolVector2Array current_shape;
|
|
|
|
Map<Vector2, uint16_t> bitmask_map_copy;
|
|
|
|
|
|
|
|
Control *side_panel;
|
|
|
|
ItemList *autotile_list;
|
|
|
|
PropertyEditor *property_editor;
|
|
|
|
AutotileEditorHelper *helper;
|
|
|
|
|
|
|
|
AutotileEditor(EditorNode *p_editor);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
void _notification(int p_what);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void _on_autotile_selected(int p_index);
|
|
|
|
void _on_edit_mode_changed(int p_edit_mode);
|
|
|
|
void _on_workspace_draw();
|
|
|
|
void _on_workspace_input(const Ref<InputEvent> &p_ie);
|
|
|
|
void _on_tool_clicked(int p_tool);
|
|
|
|
void _on_priority_changed(float val);
|
2017-12-28 13:57:37 +08:00
|
|
|
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);
|
2017-10-22 09:42:23 +08:00
|
|
|
|
|
|
|
void draw_highlight_tile(Vector2 coord, const Vector<Vector2> &other_highlighted = Vector<Vector2>());
|
2017-12-28 13:57:37 +08:00
|
|
|
void draw_grid_snap();
|
2017-10-22 09:42:23 +08:00
|
|
|
void draw_polygon_shapes();
|
|
|
|
void close_shape(const Vector2 &shape_anchor);
|
|
|
|
Vector2 snap_point(const Vector2 &point);
|
|
|
|
|
|
|
|
void edit(Object *p_node);
|
|
|
|
int get_current_tile();
|
|
|
|
};
|
|
|
|
|
|
|
|
class AutotileEditorHelper : public Object {
|
|
|
|
|
|
|
|
friend class AutotileEditor;
|
|
|
|
GDCLASS(AutotileEditorHelper, Object);
|
|
|
|
|
|
|
|
Ref<TileSet> tile_set;
|
|
|
|
AutotileEditor *autotile_editor;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_tileset(const Ref<TileSet> &p_tileset);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
AutotileEditorHelper(AutotileEditor *p_autotile_editor);
|
|
|
|
};
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
class TileSetEditor : public Control {
|
|
|
|
|
2017-10-22 09:42:23 +08:00
|
|
|
friend class TileSetEditorPlugin;
|
2017-03-05 23:44:50 +08:00
|
|
|
GDCLASS(TileSetEditor, Control);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
Ref<TileSet> tileset;
|
|
|
|
|
|
|
|
EditorNode *editor;
|
|
|
|
MenuButton *menu;
|
|
|
|
ConfirmationDialog *cd;
|
2015-12-16 06:35:35 +08:00
|
|
|
EditorNameDialog *nd;
|
|
|
|
AcceptDialog *err_dialog;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
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);
|
2015-12-16 06:35:35 +08:00
|
|
|
void _menu_confirm();
|
2017-03-05 23:44:50 +08:00
|
|
|
void _name_dialog_confirm(const String &name);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-05-20 05:49:37 +08:00
|
|
|
static void _import_node(Node *p_node, Ref<TileSet> p_library);
|
2014-02-10 09:10:30 +08:00
|
|
|
static void _import_scene(Node *p_scene, Ref<TileSet> p_library, bool p_merge);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
public:
|
|
|
|
void edit(const Ref<TileSet> &p_tileset);
|
|
|
|
static Error update_library_file(Node *p_base_scene, Ref<TileSet> ml, bool p_merge = true);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
TileSetEditor(EditorNode *p_editor);
|
|
|
|
};
|
|
|
|
|
|
|
|
class TileSetEditorPlugin : public EditorPlugin {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
GDCLASS(TileSetEditorPlugin, EditorPlugin);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
TileSetEditor *tileset_editor;
|
2017-10-22 09:42:23 +08:00
|
|
|
AutotileEditor *autotile_editor;
|
2014-02-10 09:10:30 +08:00
|
|
|
EditorNode *editor;
|
|
|
|
|
2017-10-22 09:42:23 +08:00
|
|
|
ToolButton *autotile_button;
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
public:
|
|
|
|
virtual String get_name() const { return "TileSet"; }
|
|
|
|
bool has_main_screen() const { return false; }
|
|
|
|
virtual void edit(Object *p_node);
|
|
|
|
virtual bool handles(Object *p_node) const;
|
|
|
|
virtual void make_visible(bool p_visible);
|
|
|
|
|
|
|
|
TileSetEditorPlugin(EditorNode *p_node);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // TILE_SET_EDITOR_PLUGIN_H
|