You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks
This commit is contained in:
@@ -39,23 +39,19 @@
|
||||
#include "scene/2d/skeleton_2d.h"
|
||||
|
||||
Node2D *Polygon2DEditor::_get_node() const {
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_set_node(Node *p_polygon) {
|
||||
|
||||
node = Object::cast_to<Polygon2D>(p_polygon);
|
||||
_update_polygon_editing_state();
|
||||
}
|
||||
|
||||
Vector2 Polygon2DEditor::_get_offset(int p_idx) const {
|
||||
|
||||
return node->get_offset();
|
||||
}
|
||||
|
||||
int Polygon2DEditor::_get_polygon_count() const {
|
||||
|
||||
if (node->get_internal_vertex_count() > 0) {
|
||||
return 0; //do not edit if internal vertices exist
|
||||
} else {
|
||||
@@ -64,17 +60,13 @@ int Polygon2DEditor::_get_polygon_count() const {
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_notification(int p_what) {
|
||||
|
||||
switch (p_what) {
|
||||
|
||||
case NOTIFICATION_ENTER_TREE:
|
||||
case NOTIFICATION_THEME_CHANGED: {
|
||||
|
||||
uv_edit_draw->add_style_override("panel", get_stylebox("bg", "Tree"));
|
||||
bone_scroll->add_style_override("bg", get_stylebox("bg", "Tree"));
|
||||
} break;
|
||||
case NOTIFICATION_READY: {
|
||||
|
||||
button_uv->set_icon(get_icon("Uv", "EditorIcons"));
|
||||
|
||||
uv_button[UV_MODE_CREATE]->set_icon(get_icon("Edit", "EditorIcons"));
|
||||
@@ -97,7 +89,6 @@ void Polygon2DEditor::_notification(int p_what) {
|
||||
uv_hscroll->set_anchors_and_margins_preset(PRESET_BOTTOM_WIDE);
|
||||
} break;
|
||||
case NOTIFICATION_VISIBILITY_CHANGED: {
|
||||
|
||||
if (!is_visible()) {
|
||||
uv_edit->hide();
|
||||
}
|
||||
@@ -106,7 +97,6 @@ void Polygon2DEditor::_notification(int p_what) {
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_sync_bones() {
|
||||
|
||||
Skeleton2D *skeleton = NULL;
|
||||
if (!node->has_node(node->get_skeleton())) {
|
||||
error->set_text(TTR("The skeleton property of the Polygon2D does not point to a Skeleton2D node"));
|
||||
@@ -161,7 +151,6 @@ void Polygon2DEditor::_sync_bones() {
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_update_bone_list() {
|
||||
|
||||
NodePath selected;
|
||||
while (bone_scroll_vb->get_child_count()) {
|
||||
CheckBox *cb = Object::cast_to<CheckBox>(bone_scroll_vb->get_child(0));
|
||||
@@ -203,7 +192,6 @@ void Polygon2DEditor::_bone_paint_selected(int p_index) {
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_uv_edit_mode_select(int p_mode) {
|
||||
|
||||
if (p_mode == 0) { //uv
|
||||
|
||||
uv_button[UV_MODE_CREATE]->hide();
|
||||
@@ -274,20 +262,15 @@ void Polygon2DEditor::_uv_edit_mode_select(int p_mode) {
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_uv_edit_popup_hide() {
|
||||
|
||||
EditorSettings::get_singleton()->set("interface/dialogs/uv_editor_bounds", uv_edit->get_rect());
|
||||
|
||||
_cancel_editing();
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_menu_option(int p_option) {
|
||||
|
||||
switch (p_option) {
|
||||
|
||||
case MODE_EDIT_UV: {
|
||||
|
||||
if (node->get_texture().is_null()) {
|
||||
|
||||
error->set_text(TTR("No texture in this polygon.\nSet a texture to be able to edit UV."));
|
||||
error->popup_centered_minsize();
|
||||
return;
|
||||
@@ -311,7 +294,6 @@ void Polygon2DEditor::_menu_option(int p_option) {
|
||||
_update_bone_list();
|
||||
} break;
|
||||
case UVEDIT_POLYGON_TO_UV: {
|
||||
|
||||
PoolVector<Vector2> points = node->get_polygon();
|
||||
if (points.size() == 0)
|
||||
break;
|
||||
@@ -324,7 +306,6 @@ void Polygon2DEditor::_menu_option(int p_option) {
|
||||
undo_redo->commit_action();
|
||||
} break;
|
||||
case UVEDIT_UV_TO_POLYGON: {
|
||||
|
||||
PoolVector<Vector2> points = node->get_polygon();
|
||||
PoolVector<Vector2> uvs = node->get_uv();
|
||||
if (uvs.size() == 0)
|
||||
@@ -338,7 +319,6 @@ void Polygon2DEditor::_menu_option(int p_option) {
|
||||
undo_redo->commit_action();
|
||||
} break;
|
||||
case UVEDIT_UV_CLEAR: {
|
||||
|
||||
PoolVector<Vector2> uvs = node->get_uv();
|
||||
if (uvs.size() == 0)
|
||||
break;
|
||||
@@ -350,18 +330,15 @@ void Polygon2DEditor::_menu_option(int p_option) {
|
||||
undo_redo->commit_action();
|
||||
} break;
|
||||
case UVEDIT_GRID_SETTINGS: {
|
||||
|
||||
grid_settings->popup_centered_minsize();
|
||||
} break;
|
||||
default: {
|
||||
|
||||
AbstractPolygon2DEditor::_menu_option(p_option);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_cancel_editing() {
|
||||
|
||||
if (uv_create) {
|
||||
uv_drag = false;
|
||||
uv_create = false;
|
||||
@@ -386,7 +363,6 @@ void Polygon2DEditor::_cancel_editing() {
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_update_polygon_editing_state() {
|
||||
|
||||
if (!_get_node())
|
||||
return;
|
||||
|
||||
@@ -397,7 +373,6 @@ void Polygon2DEditor::_update_polygon_editing_state() {
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_commit_action() {
|
||||
|
||||
// Makes that undo/redoing actions made outside of the UV editor still affect its polygon.
|
||||
undo_redo->add_do_method(uv_edit_draw, "update");
|
||||
undo_redo->add_undo_method(uv_edit_draw, "update");
|
||||
@@ -442,7 +417,6 @@ void Polygon2DEditor::_set_snap_step_y(float p_val) {
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_uv_mode(int p_mode) {
|
||||
|
||||
polygon_create.clear();
|
||||
uv_drag = false;
|
||||
uv_create = false;
|
||||
@@ -454,7 +428,6 @@ void Polygon2DEditor::_uv_mode(int p_mode) {
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
|
||||
if (!_get_node())
|
||||
return;
|
||||
|
||||
@@ -465,11 +438,8 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
Ref<InputEventMouseButton> mb = p_input;
|
||||
|
||||
if (mb.is_valid()) {
|
||||
|
||||
if (mb->get_button_index() == BUTTON_LEFT) {
|
||||
|
||||
if (mb->is_pressed()) {
|
||||
|
||||
uv_drag_from = snap_point(Vector2(mb->get_position().x, mb->get_position().y));
|
||||
uv_drag = true;
|
||||
points_prev = node->get_uv();
|
||||
@@ -482,9 +452,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
|
||||
uv_move_current = uv_mode;
|
||||
if (uv_move_current == UV_MODE_CREATE) {
|
||||
|
||||
if (!uv_create) {
|
||||
|
||||
points_prev.resize(0);
|
||||
Vector2 tuv = mtx.affine_inverse().xform(snap_point(Vector2(mb->get_position().x, mb->get_position().y)));
|
||||
points_prev.push_back(tuv);
|
||||
@@ -506,7 +474,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
|
||||
uv_edit_draw->update();
|
||||
} else {
|
||||
|
||||
Vector2 tuv = mtx.affine_inverse().xform(snap_point(Vector2(mb->get_position().x, mb->get_position().y)));
|
||||
|
||||
// Close the polygon if selected point is near start. Threshold for closing scaled by zoom level
|
||||
@@ -545,7 +512,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
}
|
||||
|
||||
if (uv_move_current == UV_MODE_CREATE_INTERNAL) {
|
||||
|
||||
uv_create_uv_prev = node->get_uv();
|
||||
uv_create_poly_prev = node->get_polygon();
|
||||
uv_create_colors_prev = node->get_vertex_colors();
|
||||
@@ -583,7 +549,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
}
|
||||
|
||||
if (uv_move_current == UV_MODE_REMOVE_INTERNAL) {
|
||||
|
||||
uv_create_uv_prev = node->get_uv();
|
||||
uv_create_poly_prev = node->get_polygon();
|
||||
uv_create_colors_prev = node->get_vertex_colors();
|
||||
@@ -597,7 +562,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
float closest_dist = 1e20;
|
||||
|
||||
for (int i = points_prev.size() - internal_vertices; i < points_prev.size(); i++) {
|
||||
|
||||
Vector2 tuv = mtx.xform(uv_create_poly_prev[i]);
|
||||
float dist = tuv.distance_to(Vector2(mb->get_position().x, mb->get_position().y));
|
||||
if (dist < 8 && dist < closest_dist) {
|
||||
@@ -638,7 +602,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
}
|
||||
|
||||
if (uv_move_current == UV_MODE_EDIT_POINT) {
|
||||
|
||||
if (mb->get_shift() && mb->get_command())
|
||||
uv_move_current = UV_MODE_SCALE;
|
||||
else if (mb->get_shift())
|
||||
@@ -648,10 +611,8 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
}
|
||||
|
||||
if (uv_move_current == UV_MODE_EDIT_POINT) {
|
||||
|
||||
point_drag_index = -1;
|
||||
for (int i = 0; i < points_prev.size(); i++) {
|
||||
|
||||
Vector2 tuv = mtx.xform(points_prev[i]);
|
||||
if (tuv.distance_to(Vector2(mb->get_position().x, mb->get_position().y)) < 8) {
|
||||
uv_drag_from = tuv;
|
||||
@@ -665,12 +626,10 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
}
|
||||
|
||||
if (uv_move_current == UV_MODE_ADD_POLYGON) {
|
||||
|
||||
int closest = -1;
|
||||
float closest_dist = 1e20;
|
||||
|
||||
for (int i = 0; i < points_prev.size(); i++) {
|
||||
|
||||
Vector2 tuv = mtx.xform(points_prev[i]);
|
||||
float dist = tuv.distance_to(Vector2(mb->get_position().x, mb->get_position().y));
|
||||
if (dist < 8 && dist < closest_dist) {
|
||||
@@ -741,7 +700,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
}
|
||||
|
||||
if (uv_move_current == UV_MODE_PAINT_WEIGHT || uv_move_current == UV_MODE_CLEAR_WEIGHT) {
|
||||
|
||||
int bone_selected = -1;
|
||||
for (int i = 0; i < bone_scroll_vb->get_child_count(); i++) {
|
||||
CheckBox *c = Object::cast_to<CheckBox>(bone_scroll_vb->get_child(i));
|
||||
@@ -752,7 +710,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
}
|
||||
|
||||
if (bone_selected != -1 && node->get_bone_weights(bone_selected).size() == points_prev.size()) {
|
||||
|
||||
prev_weights = node->get_bone_weights(bone_selected);
|
||||
bone_painting = true;
|
||||
bone_painting_bone = bone_selected;
|
||||
@@ -790,7 +747,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
}
|
||||
}
|
||||
} else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) {
|
||||
|
||||
_cancel_editing();
|
||||
|
||||
if (bone_painting)
|
||||
@@ -799,10 +755,8 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
uv_edit_draw->update();
|
||||
|
||||
} else if (mb->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed()) {
|
||||
|
||||
uv_zoom->set_value(uv_zoom->get_value() / (1 - (0.1 * mb->get_factor())));
|
||||
} else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && mb->is_pressed()) {
|
||||
|
||||
uv_zoom->set_value(uv_zoom->get_value() * (1 - (0.1 * mb->get_factor())));
|
||||
}
|
||||
}
|
||||
@@ -810,29 +764,23 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
Ref<InputEventMouseMotion> mm = p_input;
|
||||
|
||||
if (mm.is_valid()) {
|
||||
|
||||
if ((mm->get_button_mask() & BUTTON_MASK_MIDDLE) || Input::get_singleton()->is_key_pressed(KEY_SPACE)) {
|
||||
|
||||
Vector2 drag(mm->get_relative().x, mm->get_relative().y);
|
||||
uv_hscroll->set_value(uv_hscroll->get_value() - drag.x);
|
||||
uv_vscroll->set_value(uv_vscroll->get_value() - drag.y);
|
||||
|
||||
} else if (uv_drag) {
|
||||
|
||||
Vector2 uv_drag_to = mm->get_position();
|
||||
uv_drag_to = snap_point(uv_drag_to); // FIXME: Only works correctly with 'UV_MODE_EDIT_POINT', it's imprecise with the rest.
|
||||
Vector2 drag = mtx.affine_inverse().xform(uv_drag_to) - mtx.affine_inverse().xform(uv_drag_from);
|
||||
|
||||
switch (uv_move_current) {
|
||||
|
||||
case UV_MODE_CREATE: {
|
||||
|
||||
if (uv_create) {
|
||||
uv_create_to = mtx.affine_inverse().xform(snap_point(Vector2(mm->get_position().x, mm->get_position().y)));
|
||||
}
|
||||
} break;
|
||||
case UV_MODE_EDIT_POINT: {
|
||||
|
||||
PoolVector<Vector2> uv_new = points_prev;
|
||||
uv_new.set(point_drag_index, uv_new[point_drag_index] + drag);
|
||||
|
||||
@@ -843,7 +791,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
}
|
||||
} break;
|
||||
case UV_MODE_MOVE: {
|
||||
|
||||
PoolVector<Vector2> uv_new = points_prev;
|
||||
for (int i = 0; i < uv_new.size(); i++)
|
||||
uv_new.set(i, uv_new[i] + drag);
|
||||
@@ -855,7 +802,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
}
|
||||
} break;
|
||||
case UV_MODE_ROTATE: {
|
||||
|
||||
Vector2 center;
|
||||
PoolVector<Vector2> uv_new = points_prev;
|
||||
|
||||
@@ -878,7 +824,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
}
|
||||
} break;
|
||||
case UV_MODE_SCALE: {
|
||||
|
||||
Vector2 center;
|
||||
PoolVector<Vector2> uv_new = points_prev;
|
||||
|
||||
@@ -907,7 +852,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
} break;
|
||||
case UV_MODE_PAINT_WEIGHT:
|
||||
case UV_MODE_CLEAR_WEIGHT: {
|
||||
|
||||
bone_paint_pos = Vector2(mm->get_position().x, mm->get_position().y);
|
||||
} break;
|
||||
default: {
|
||||
@@ -953,20 +897,17 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
|
||||
Ref<InputEventMagnifyGesture> magnify_gesture = p_input;
|
||||
if (magnify_gesture.is_valid()) {
|
||||
|
||||
uv_zoom->set_value(uv_zoom->get_value() * magnify_gesture->get_factor());
|
||||
}
|
||||
|
||||
Ref<InputEventPanGesture> pan_gesture = p_input;
|
||||
if (pan_gesture.is_valid()) {
|
||||
|
||||
uv_hscroll->set_value(uv_hscroll->get_value() + uv_hscroll->get_page() * pan_gesture->get_delta().x / 8);
|
||||
uv_vscroll->set_value(uv_vscroll->get_value() + uv_vscroll->get_page() * pan_gesture->get_delta().y / 8);
|
||||
}
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_uv_scroll_changed(float) {
|
||||
|
||||
if (updating_uv_scroll)
|
||||
return;
|
||||
|
||||
@@ -977,7 +918,6 @@ void Polygon2DEditor::_uv_scroll_changed(float) {
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_uv_draw() {
|
||||
|
||||
if (!uv_edit->is_visible() || !_get_node())
|
||||
return;
|
||||
|
||||
@@ -1045,7 +985,6 @@ void Polygon2DEditor::_uv_draw() {
|
||||
}
|
||||
|
||||
if (bone_selected != -1 && node->get_bone_weights(bone_selected).size() == uvs.size()) {
|
||||
|
||||
weight_r = node->get_bone_weights(bone_selected).read();
|
||||
}
|
||||
}
|
||||
@@ -1075,7 +1014,6 @@ void Polygon2DEditor::_uv_draw() {
|
||||
}
|
||||
|
||||
for (int i = 0; i < uvs.size(); i++) {
|
||||
|
||||
int next = uv_draw_max > 0 ? (i + 1) % uv_draw_max : 0;
|
||||
|
||||
if (i < uv_draw_max && uv_drag && uv_move_current == UV_MODE_EDIT_POINT && EDITOR_DEF("editors/poly_editor/show_previous_outline", true)) {
|
||||
@@ -1094,7 +1032,6 @@ void Polygon2DEditor::_uv_draw() {
|
||||
}
|
||||
|
||||
for (int i = 0; i < polygons.size(); i++) {
|
||||
|
||||
PoolVector<int> points = polygons[i];
|
||||
Vector<Vector2> polypoints;
|
||||
for (int j = 0; j < points.size(); j++) {
|
||||
@@ -1116,7 +1053,6 @@ void Polygon2DEditor::_uv_draw() {
|
||||
}
|
||||
|
||||
for (int i = 0; i < uvs.size(); i++) {
|
||||
|
||||
if (weight_r.ptr()) {
|
||||
Vector2 draw_pos = mtx.xform(uvs[i]);
|
||||
float weight = weight_r[i];
|
||||
@@ -1140,7 +1076,6 @@ void Polygon2DEditor::_uv_draw() {
|
||||
}
|
||||
|
||||
if (uv_mode == UV_MODE_PAINT_WEIGHT || uv_mode == UV_MODE_CLEAR_WEIGHT) {
|
||||
|
||||
NodePath bone_path;
|
||||
for (int i = 0; i < bone_scroll_vb->get_child_count(); i++) {
|
||||
CheckBox *c = Object::cast_to<CheckBox>(bone_scroll_vb->get_child(i));
|
||||
@@ -1156,7 +1091,6 @@ void Polygon2DEditor::_uv_draw() {
|
||||
Skeleton2D *skeleton = Object::cast_to<Skeleton2D>(node->get_node(skeleton_path));
|
||||
if (skeleton) {
|
||||
for (int i = 0; i < skeleton->get_bone_count(); i++) {
|
||||
|
||||
Bone2D *bone = skeleton->get_bone(i);
|
||||
if (bone->get_rest() == Transform2D(0, 0, 0, 0, 0, 0))
|
||||
continue; //not set
|
||||
@@ -1166,7 +1100,6 @@ void Polygon2DEditor::_uv_draw() {
|
||||
bool found_child = false;
|
||||
|
||||
for (int j = 0; j < bone->get_child_count(); j++) {
|
||||
|
||||
Bone2D *n = Object::cast_to<Bone2D>(bone->get_child(j));
|
||||
if (!n)
|
||||
continue;
|
||||
@@ -1234,7 +1167,6 @@ void Polygon2DEditor::_uv_draw() {
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_uv_mode"), &Polygon2DEditor::_uv_mode);
|
||||
ClassDB::bind_method(D_METHOD("_uv_draw"), &Polygon2DEditor::_uv_draw);
|
||||
ClassDB::bind_method(D_METHOD("_uv_input"), &Polygon2DEditor::_uv_input);
|
||||
@@ -1264,7 +1196,6 @@ Vector2 Polygon2DEditor::snap_point(Vector2 p_target) const {
|
||||
|
||||
Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) :
|
||||
AbstractPolygon2DEditor(p_editor) {
|
||||
|
||||
node = NULL;
|
||||
snap_offset = EditorSettings::get_singleton()->get_project_metadata("polygon_2d_uv_editor", "snap_offset", Vector2());
|
||||
snap_step = EditorSettings::get_singleton()->get_project_metadata("polygon_2d_uv_editor", "snap_step", Vector2(10, 10));
|
||||
@@ -1322,7 +1253,6 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) :
|
||||
|
||||
uv_main_vb->add_child(uv_mode_hb);
|
||||
for (int i = 0; i < UV_MODE_MAX; i++) {
|
||||
|
||||
uv_button[i] = memnew(ToolButton);
|
||||
uv_button[i]->set_toggle_mode(true);
|
||||
uv_mode_hb->add_child(uv_button[i]);
|
||||
|
||||
Reference in New Issue
Block a user