2
0

polygon_2d_editor_plugin.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*************************************************************************/
  2. /* polygon_2d_editor_plugin.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef POLYGON_2D_EDITOR_PLUGIN_H
  31. #define POLYGON_2D_EDITOR_PLUGIN_H
  32. #include "editor/plugins/abstract_polygon_2d_editor.h"
  33. #include "scene/gui/scroll_container.h"
  34. class Polygon2DEditor : public AbstractPolygon2DEditor {
  35. GDCLASS(Polygon2DEditor, AbstractPolygon2DEditor);
  36. enum Mode {
  37. MODE_EDIT_UV = MODE_CONT,
  38. UVEDIT_POLYGON_TO_UV,
  39. UVEDIT_UV_TO_POLYGON,
  40. UVEDIT_UV_CLEAR,
  41. UVEDIT_GRID_SETTINGS
  42. };
  43. enum UVMode {
  44. UV_MODE_CREATE,
  45. UV_MODE_CREATE_INTERNAL,
  46. UV_MODE_REMOVE_INTERNAL,
  47. UV_MODE_EDIT_POINT,
  48. UV_MODE_MOVE,
  49. UV_MODE_ROTATE,
  50. UV_MODE_SCALE,
  51. UV_MODE_ADD_POLYGON,
  52. UV_MODE_REMOVE_POLYGON,
  53. UV_MODE_PAINT_WEIGHT,
  54. UV_MODE_CLEAR_WEIGHT,
  55. UV_MODE_MAX
  56. };
  57. ToolButton *uv_edit_mode[4];
  58. Ref<ButtonGroup> uv_edit_group;
  59. Polygon2D *node;
  60. UVMode uv_mode;
  61. AcceptDialog *uv_edit;
  62. ToolButton *uv_button[UV_MODE_MAX];
  63. ToolButton *b_snap_enable;
  64. ToolButton *b_snap_grid;
  65. Panel *uv_edit_draw;
  66. HSlider *uv_zoom;
  67. SpinBox *uv_zoom_value;
  68. HScrollBar *uv_hscroll;
  69. VScrollBar *uv_vscroll;
  70. MenuButton *uv_menu;
  71. TextureRect *uv_icon_zoom;
  72. VBoxContainer *bone_scroll_main_vb;
  73. ScrollContainer *bone_scroll;
  74. VBoxContainer *bone_scroll_vb;
  75. Button *sync_bones;
  76. HSlider *bone_paint_strength;
  77. SpinBox *bone_paint_radius;
  78. Label *bone_paint_radius_label;
  79. bool bone_painting;
  80. int bone_painting_bone;
  81. PoolVector<float> prev_weights;
  82. Vector2 bone_paint_pos;
  83. AcceptDialog *grid_settings;
  84. void _sync_bones();
  85. void _update_bone_list();
  86. Vector2 uv_draw_ofs;
  87. float uv_draw_zoom;
  88. PoolVector<Vector2> points_prev;
  89. PoolVector<Vector2> uv_create_uv_prev;
  90. PoolVector<Vector2> uv_create_poly_prev;
  91. PoolVector<Color> uv_create_colors_prev;
  92. int uv_create_prev_internal_vertices;
  93. Array uv_create_bones_prev;
  94. Array polygons_prev;
  95. Vector2 uv_create_to;
  96. int point_drag_index;
  97. bool uv_drag;
  98. bool uv_create;
  99. Vector<int> polygon_create;
  100. UVMode uv_move_current;
  101. Vector2 uv_drag_from;
  102. bool updating_uv_scroll;
  103. AcceptDialog *error;
  104. ToolButton *button_uv;
  105. bool use_snap;
  106. bool snap_show_grid;
  107. Vector2 snap_offset;
  108. Vector2 snap_step;
  109. virtual void _menu_option(int p_option);
  110. void _cancel_editing();
  111. void _update_polygon_editing_state();
  112. void _uv_scroll_changed(float);
  113. void _uv_input(const Ref<InputEvent> &p_input);
  114. void _uv_draw();
  115. void _uv_mode(int p_mode);
  116. void _set_use_snap(bool p_use);
  117. void _set_show_grid(bool p_show);
  118. void _set_snap_off_x(float p_val);
  119. void _set_snap_off_y(float p_val);
  120. void _set_snap_step_x(float p_val);
  121. void _set_snap_step_y(float p_val);
  122. void _uv_edit_mode_select(int p_mode);
  123. void _uv_edit_popup_hide();
  124. void _bone_paint_selected(int p_index);
  125. int _get_polygon_count() const;
  126. protected:
  127. virtual Node2D *_get_node() const;
  128. virtual void _set_node(Node *p_polygon);
  129. virtual Vector2 _get_offset(int p_idx) const;
  130. virtual bool _has_uv() const { return true; };
  131. virtual void _commit_action();
  132. void _notification(int p_what);
  133. static void _bind_methods();
  134. Vector2 snap_point(Vector2 p_target) const;
  135. public:
  136. Polygon2DEditor(EditorNode *p_editor);
  137. };
  138. class Polygon2DEditorPlugin : public AbstractPolygon2DEditorPlugin {
  139. GDCLASS(Polygon2DEditorPlugin, AbstractPolygon2DEditorPlugin);
  140. public:
  141. Polygon2DEditorPlugin(EditorNode *p_node);
  142. };
  143. #endif // POLYGON_2D_EDITOR_PLUGIN_H