2016-06-18 14:46:12 +02:00
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
/* polygon_2d_editor_plugin.h */
|
2016-06-18 14:46:12 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2016-06-18 14:46:12 +02:00
|
|
|
/*************************************************************************/
|
2022-01-03 21:27:34 +01:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2016-06-18 14:46:12 +02: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. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-07-07 22:44:21 +02:00
|
|
|
#ifndef POLYGON_2D_EDITOR_PLUGIN_H
|
|
|
|
#define POLYGON_2D_EDITOR_PLUGIN_H
|
|
|
|
|
2017-09-06 18:41:14 +02:00
|
|
|
#include "editor/plugins/abstract_polygon_2d_editor.h"
|
2022-01-13 17:19:15 +01:00
|
|
|
|
2022-02-12 02:46:22 +01:00
|
|
|
class HSlider;
|
2022-02-14 14:00:03 +01:00
|
|
|
class Panel;
|
|
|
|
class ScrollContainer;
|
2022-02-12 02:46:22 +01:00
|
|
|
class SpinBox;
|
2022-02-14 14:00:03 +01:00
|
|
|
class ViewPanner;
|
2019-08-10 14:28:17 +02:00
|
|
|
|
2017-09-06 18:41:14 +02:00
|
|
|
class Polygon2DEditor : public AbstractPolygon2DEditor {
|
|
|
|
GDCLASS(Polygon2DEditor, AbstractPolygon2DEditor);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
|
|
enum Mode {
|
2017-09-06 18:41:14 +02:00
|
|
|
MODE_EDIT_UV = MODE_CONT,
|
2014-07-07 22:44:21 +02:00
|
|
|
UVEDIT_POLYGON_TO_UV,
|
|
|
|
UVEDIT_UV_TO_POLYGON,
|
2018-05-03 22:29:15 +02:00
|
|
|
UVEDIT_UV_CLEAR,
|
|
|
|
UVEDIT_GRID_SETTINGS
|
2014-07-07 22:44:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum UVMode {
|
2018-02-22 21:38:33 +01:00
|
|
|
UV_MODE_CREATE,
|
2019-01-08 23:10:24 +01:00
|
|
|
UV_MODE_CREATE_INTERNAL,
|
|
|
|
UV_MODE_REMOVE_INTERNAL,
|
2014-07-07 22:44:21 +02:00
|
|
|
UV_MODE_EDIT_POINT,
|
|
|
|
UV_MODE_MOVE,
|
|
|
|
UV_MODE_ROTATE,
|
|
|
|
UV_MODE_SCALE,
|
2019-01-08 23:10:24 +01:00
|
|
|
UV_MODE_ADD_POLYGON,
|
|
|
|
UV_MODE_REMOVE_POLYGON,
|
2018-05-02 16:00:35 +02:00
|
|
|
UV_MODE_PAINT_WEIGHT,
|
|
|
|
UV_MODE_CLEAR_WEIGHT,
|
2014-07-07 22:44:21 +02:00
|
|
|
UV_MODE_MAX
|
|
|
|
};
|
|
|
|
|
2020-06-19 20:49:04 +02:00
|
|
|
Button *uv_edit_mode[4];
|
2018-02-22 21:38:33 +01:00
|
|
|
Ref<ButtonGroup> uv_edit_group;
|
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
Polygon2D *node = nullptr;
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
|
|
UVMode uv_mode;
|
2022-04-04 15:06:57 +02:00
|
|
|
AcceptDialog *uv_edit = nullptr;
|
2020-06-19 20:49:04 +02:00
|
|
|
Button *uv_button[UV_MODE_MAX];
|
2022-04-04 15:06:57 +02:00
|
|
|
Button *b_snap_enable = nullptr;
|
|
|
|
Button *b_snap_grid = nullptr;
|
|
|
|
Panel *uv_edit_draw = nullptr;
|
|
|
|
HSlider *uv_zoom = nullptr;
|
|
|
|
SpinBox *uv_zoom_value = nullptr;
|
|
|
|
HScrollBar *uv_hscroll = nullptr;
|
|
|
|
VScrollBar *uv_vscroll = nullptr;
|
|
|
|
MenuButton *uv_menu = nullptr;
|
|
|
|
TextureRect *uv_icon_zoom = nullptr;
|
2014-07-07 22:44:21 +02:00
|
|
|
|
2022-01-13 17:19:15 +01:00
|
|
|
Ref<ViewPanner> uv_panner;
|
2022-01-23 13:49:53 +01:00
|
|
|
void _uv_scroll_callback(Vector2 p_scroll_vec, bool p_alt);
|
2022-01-13 17:19:15 +01:00
|
|
|
void _uv_pan_callback(Vector2 p_scroll_vec);
|
2022-01-19 19:59:12 +01:00
|
|
|
void _uv_zoom_callback(Vector2 p_scroll_vec, Vector2 p_origin, bool p_alt);
|
2022-01-13 17:19:15 +01:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
VBoxContainer *bone_scroll_main_vb = nullptr;
|
|
|
|
ScrollContainer *bone_scroll = nullptr;
|
|
|
|
VBoxContainer *bone_scroll_vb = nullptr;
|
|
|
|
Button *sync_bones = nullptr;
|
|
|
|
HSlider *bone_paint_strength = nullptr;
|
|
|
|
SpinBox *bone_paint_radius = nullptr;
|
|
|
|
Label *bone_paint_radius_label = nullptr;
|
2018-05-02 16:00:35 +02:00
|
|
|
bool bone_painting;
|
|
|
|
int bone_painting_bone;
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<float> prev_weights;
|
2018-05-02 16:00:35 +02:00
|
|
|
Vector2 bone_paint_pos;
|
2022-04-04 15:06:57 +02:00
|
|
|
AcceptDialog *grid_settings = nullptr;
|
2018-05-02 16:00:35 +02:00
|
|
|
|
|
|
|
void _sync_bones();
|
|
|
|
void _update_bone_list();
|
|
|
|
|
2014-07-07 22:44:21 +02:00
|
|
|
Vector2 uv_draw_ofs;
|
2021-06-21 05:30:19 +02:00
|
|
|
real_t uv_draw_zoom;
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<Vector2> points_prev;
|
|
|
|
Vector<Vector2> uv_create_uv_prev;
|
|
|
|
Vector<Vector2> uv_create_poly_prev;
|
|
|
|
Vector<Color> uv_create_colors_prev;
|
2019-01-08 23:10:24 +01:00
|
|
|
int uv_create_prev_internal_vertices;
|
2018-05-02 16:00:35 +02:00
|
|
|
Array uv_create_bones_prev;
|
2019-01-08 23:10:24 +01:00
|
|
|
Array polygons_prev;
|
2018-02-25 16:06:30 +01:00
|
|
|
|
2018-02-22 21:38:33 +01:00
|
|
|
Vector2 uv_create_to;
|
2018-05-04 14:32:40 +02:00
|
|
|
int point_drag_index;
|
2014-07-07 22:44:21 +02:00
|
|
|
bool uv_drag;
|
2018-02-22 21:38:33 +01:00
|
|
|
bool uv_create;
|
2019-01-08 23:10:24 +01:00
|
|
|
Vector<int> polygon_create;
|
2014-07-07 22:44:21 +02:00
|
|
|
UVMode uv_move_current;
|
|
|
|
Vector2 uv_drag_from;
|
|
|
|
bool updating_uv_scroll;
|
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
AcceptDialog *error = nullptr;
|
2014-07-07 22:44:21 +02:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
Button *button_uv = nullptr;
|
2014-07-07 22:44:21 +02:00
|
|
|
|
2015-09-28 05:06:06 +02:00
|
|
|
bool use_snap;
|
|
|
|
bool snap_show_grid;
|
|
|
|
Vector2 snap_offset;
|
|
|
|
Vector2 snap_step;
|
|
|
|
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual void _menu_option(int p_option) override;
|
2017-09-06 18:41:14 +02:00
|
|
|
|
2018-11-24 05:38:26 +01:00
|
|
|
void _cancel_editing();
|
2019-02-16 19:46:09 +01:00
|
|
|
void _update_polygon_editing_state();
|
2018-11-24 05:38:26 +01:00
|
|
|
|
2021-06-21 05:30:19 +02:00
|
|
|
void _uv_scroll_changed(real_t);
|
2017-05-20 17:38:03 +02:00
|
|
|
void _uv_input(const Ref<InputEvent> &p_input);
|
2014-07-07 22:44:21 +02:00
|
|
|
void _uv_draw();
|
|
|
|
void _uv_mode(int p_mode);
|
|
|
|
|
2015-09-28 05:06:06 +02:00
|
|
|
void _set_use_snap(bool p_use);
|
|
|
|
void _set_show_grid(bool p_show);
|
2021-06-21 05:30:19 +02:00
|
|
|
void _set_snap_off_x(real_t p_val);
|
|
|
|
void _set_snap_off_y(real_t p_val);
|
|
|
|
void _set_snap_step_x(real_t p_val);
|
|
|
|
void _set_snap_step_y(real_t p_val);
|
2015-09-28 05:06:06 +02:00
|
|
|
|
2018-02-22 21:38:33 +01:00
|
|
|
void _uv_edit_mode_select(int p_mode);
|
2018-11-24 05:38:26 +01:00
|
|
|
void _uv_edit_popup_hide();
|
2018-05-02 16:00:35 +02:00
|
|
|
void _bone_paint_selected(int p_index);
|
2018-02-22 21:38:33 +01:00
|
|
|
|
2020-07-10 12:34:39 +02:00
|
|
|
int _get_polygon_count() const override;
|
2019-01-08 23:10:24 +01:00
|
|
|
|
2014-07-07 22:44:21 +02:00
|
|
|
protected:
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual Node2D *_get_node() const override;
|
|
|
|
virtual void _set_node(Node *p_polygon) override;
|
2017-09-06 18:41:14 +02:00
|
|
|
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual Vector2 _get_offset(int p_idx) const override;
|
2017-09-06 18:41:14 +02:00
|
|
|
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual bool _has_uv() const override { return true; };
|
|
|
|
virtual void _commit_action() override;
|
2018-11-24 05:38:26 +01:00
|
|
|
|
2014-07-07 22:44:21 +02:00
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
2015-09-28 05:06:06 +02:00
|
|
|
|
|
|
|
Vector2 snap_point(Vector2 p_target) const;
|
|
|
|
|
2014-07-07 22:44:21 +02:00
|
|
|
public:
|
2022-01-27 10:36:51 +01:00
|
|
|
Polygon2DEditor();
|
2014-07-07 22:44:21 +02:00
|
|
|
};
|
|
|
|
|
2017-09-06 18:41:14 +02:00
|
|
|
class Polygon2DEditorPlugin : public AbstractPolygon2DEditorPlugin {
|
|
|
|
GDCLASS(Polygon2DEditorPlugin, AbstractPolygon2DEditorPlugin);
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
|
|
public:
|
2022-01-27 10:36:51 +01:00
|
|
|
Polygon2DEditorPlugin();
|
2014-07-07 22:44:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // POLYGON_2D_EDITOR_PLUGIN_H
|