You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-06 12:20:30 +00:00
General enhancements to the Polygon2D, TextureRegion, and TileSet editors
This commit is contained in:
@@ -56,6 +56,12 @@ 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"));
|
||||
@@ -73,66 +79,68 @@ void Polygon2DEditor::_notification(int p_what) {
|
||||
b_snap_grid->set_icon(get_icon("Grid", "EditorIcons"));
|
||||
b_snap_enable->set_icon(get_icon("SnapGrid", "EditorIcons"));
|
||||
uv_icon_zoom->set_texture(get_icon("Zoom", "EditorIcons"));
|
||||
|
||||
} break;
|
||||
case NOTIFICATION_PHYSICS_PROCESS: {
|
||||
case NOTIFICATION_VISIBILITY_CHANGED: {
|
||||
|
||||
if (!is_visible()) {
|
||||
uv_edit->hide();
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_sync_bones() {
|
||||
|
||||
Skeleton2D *skeleton;
|
||||
if (!node->has_node(node->get_skeleton())) {
|
||||
error->set_text(TTR("The skeleton property of the Polygon2D does not point to a Skeleton2D node"));
|
||||
error->popup_centered_minsize();
|
||||
return;
|
||||
}
|
||||
|
||||
Node *sn = node->get_node(node->get_skeleton());
|
||||
Skeleton2D *skeleton = Object::cast_to<Skeleton2D>(sn);
|
||||
|
||||
if (!skeleton) {
|
||||
error->set_text(TTR("The skeleton property of the Polygon2D does not point to a Skeleton2D node"));
|
||||
error->popup_centered_minsize();
|
||||
return;
|
||||
} else {
|
||||
Node *sn = node->get_node(node->get_skeleton());
|
||||
skeleton = Object::cast_to<Skeleton2D>(sn);
|
||||
}
|
||||
|
||||
Array prev_bones = node->call("_get_bones");
|
||||
node->clear_bones();
|
||||
|
||||
for (int i = 0; i < skeleton->get_bone_count(); i++) {
|
||||
NodePath path = skeleton->get_path_to(skeleton->get_bone(i));
|
||||
PoolVector<float> weights;
|
||||
int wc = node->get_polygon().size();
|
||||
if (!skeleton) {
|
||||
error->set_text(TTR("The skeleton property of the Polygon2D does not point to a Skeleton2D node"));
|
||||
error->popup_centered_minsize();
|
||||
} else {
|
||||
for (int i = 0; i < skeleton->get_bone_count(); i++) {
|
||||
NodePath path = skeleton->get_path_to(skeleton->get_bone(i));
|
||||
PoolVector<float> weights;
|
||||
int wc = node->get_polygon().size();
|
||||
|
||||
for (int j = 0; j < prev_bones.size(); j += 2) {
|
||||
NodePath pvp = prev_bones[j];
|
||||
PoolVector<float> pv = prev_bones[j + 1];
|
||||
if (pvp == path && pv.size() == wc) {
|
||||
weights = pv;
|
||||
for (int j = 0; j < prev_bones.size(); j += 2) {
|
||||
NodePath pvp = prev_bones[j];
|
||||
PoolVector<float> pv = prev_bones[j + 1];
|
||||
if (pvp == path && pv.size() == wc) {
|
||||
weights = pv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (weights.size() == 0) { //create them
|
||||
weights.resize(node->get_polygon().size());
|
||||
PoolVector<float>::Write w = weights.write();
|
||||
for (int j = 0; j < wc; j++) {
|
||||
w[j] = 0.0;
|
||||
if (weights.size() == 0) { //create them
|
||||
weights.resize(node->get_polygon().size());
|
||||
PoolVector<float>::Write w = weights.write();
|
||||
for (int j = 0; j < wc; j++) {
|
||||
w[j] = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
node->add_bone(path, weights);
|
||||
node->add_bone(path, weights);
|
||||
}
|
||||
}
|
||||
|
||||
Array new_bones = node->call("_get_bones");
|
||||
|
||||
undo_redo->create_action(TTR("Sync bones"));
|
||||
undo_redo->create_action(TTR("Sync Bones"));
|
||||
undo_redo->add_do_method(node, "_set_bones", new_bones);
|
||||
undo_redo->add_undo_method(node, "_set_bones", prev_bones);
|
||||
undo_redo->add_do_method(uv_edit_draw, "update");
|
||||
undo_redo->add_undo_method(uv_edit_draw, "update");
|
||||
undo_redo->add_do_method(this, "_update_bone_list");
|
||||
undo_redo->add_undo_method(this, "_update_bone_list");
|
||||
undo_redo->add_do_method(uv_edit_draw, "update");
|
||||
undo_redo->add_undo_method(uv_edit_draw, "update");
|
||||
undo_redo->commit_action();
|
||||
}
|
||||
|
||||
@@ -162,9 +170,10 @@ void Polygon2DEditor::_update_bone_list() {
|
||||
cb->set_text(name);
|
||||
cb->set_button_group(bg);
|
||||
cb->set_meta("bone_path", np);
|
||||
cb->set_focus_mode(FOCUS_NONE);
|
||||
bone_scroll_vb->add_child(cb);
|
||||
|
||||
if (np == selected)
|
||||
if (np == selected || bone_scroll_vb->get_child_count() < 2)
|
||||
cb->set_pressed(true);
|
||||
|
||||
cb->connect("pressed", this, "_bone_paint_selected", varray(i));
|
||||
@@ -180,6 +189,7 @@ 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();
|
||||
for (int i = UV_MODE_MOVE; i <= UV_MODE_SCALE; i++) {
|
||||
uv_button[i]->show();
|
||||
@@ -194,8 +204,8 @@ void Polygon2DEditor::_uv_edit_mode_select(int p_mode) {
|
||||
bone_paint_strength->hide();
|
||||
bone_paint_radius->hide();
|
||||
bone_paint_radius_label->hide();
|
||||
|
||||
} else if (p_mode == 1) { //poly
|
||||
|
||||
for (int i = 0; i <= UV_MODE_SCALE; i++) {
|
||||
uv_button[i]->show();
|
||||
}
|
||||
@@ -209,8 +219,8 @@ void Polygon2DEditor::_uv_edit_mode_select(int p_mode) {
|
||||
bone_paint_strength->hide();
|
||||
bone_paint_radius->hide();
|
||||
bone_paint_radius_label->hide();
|
||||
|
||||
} else if (p_mode == 2) { //splits
|
||||
|
||||
for (int i = 0; i <= UV_MODE_SCALE; i++) {
|
||||
uv_button[i]->hide();
|
||||
}
|
||||
@@ -224,8 +234,8 @@ void Polygon2DEditor::_uv_edit_mode_select(int p_mode) {
|
||||
bone_paint_strength->hide();
|
||||
bone_paint_radius->hide();
|
||||
bone_paint_radius_label->hide();
|
||||
|
||||
} else if (p_mode == 3) { //bones´
|
||||
|
||||
for (int i = 0; i <= UV_MODE_REMOVE_SPLIT; i++) {
|
||||
uv_button[i]->hide();
|
||||
}
|
||||
@@ -241,9 +251,17 @@ void Polygon2DEditor::_uv_edit_mode_select(int p_mode) {
|
||||
bone_paint_pos = Vector2(-100000, -100000); //send brush away when switching
|
||||
}
|
||||
|
||||
uv_edit->set_size(uv_edit->get_size()); // Necessary readjustment of the popup window.
|
||||
uv_edit_draw->update();
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -252,7 +270,7 @@ void Polygon2DEditor::_menu_option(int p_option) {
|
||||
|
||||
if (node->get_texture().is_null()) {
|
||||
|
||||
error->set_text("No texture in this polygon.\nSet a texture to be able to edit UV.");
|
||||
error->set_text(TTR("No texture in this polygon.\nSet a texture to be able to edit UV."));
|
||||
error->popup_centered_minsize();
|
||||
return;
|
||||
}
|
||||
@@ -268,7 +286,10 @@ void Polygon2DEditor::_menu_option(int p_option) {
|
||||
undo_redo->commit_action();
|
||||
}
|
||||
|
||||
uv_edit->popup_centered_ratio(0.85);
|
||||
if (EditorSettings::get_singleton()->has_setting("interface/dialogs/uv_editor_bounds"))
|
||||
uv_edit->popup(EditorSettings::get_singleton()->get("interface/dialogs/uv_editor_bounds"));
|
||||
else
|
||||
uv_edit->popup_centered_ratio(0.85);
|
||||
} break;
|
||||
case UVEDIT_POLYGON_TO_UV: {
|
||||
|
||||
@@ -282,7 +303,6 @@ void Polygon2DEditor::_menu_option(int p_option) {
|
||||
undo_redo->add_do_method(uv_edit_draw, "update");
|
||||
undo_redo->add_undo_method(uv_edit_draw, "update");
|
||||
undo_redo->commit_action();
|
||||
|
||||
} break;
|
||||
case UVEDIT_UV_TO_POLYGON: {
|
||||
|
||||
@@ -291,13 +311,12 @@ void Polygon2DEditor::_menu_option(int p_option) {
|
||||
if (uvs.size() == 0)
|
||||
break;
|
||||
|
||||
undo_redo->create_action(TTR("Create UV Map"));
|
||||
undo_redo->create_action(TTR("Create Polygon"));
|
||||
undo_redo->add_do_method(node, "set_polygon", uvs);
|
||||
undo_redo->add_undo_method(node, "set_polygon", points);
|
||||
undo_redo->add_do_method(uv_edit_draw, "update");
|
||||
undo_redo->add_undo_method(uv_edit_draw, "update");
|
||||
undo_redo->commit_action();
|
||||
|
||||
} break;
|
||||
case UVEDIT_UV_CLEAR: {
|
||||
|
||||
@@ -310,43 +329,81 @@ void Polygon2DEditor::_menu_option(int p_option) {
|
||||
undo_redo->add_do_method(uv_edit_draw, "update");
|
||||
undo_redo->add_undo_method(uv_edit_draw, "update");
|
||||
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;
|
||||
node->set_uv(uv_create_uv_prev);
|
||||
node->set_polygon(uv_create_poly_prev);
|
||||
node->call("_set_bones", uv_create_bones_prev);
|
||||
node->set_splits(splits_prev);
|
||||
} else if (uv_drag) {
|
||||
uv_drag = false;
|
||||
if (uv_edit_mode[0]->is_pressed()) { // Edit UV.
|
||||
node->set_uv(points_prev);
|
||||
} else if (uv_edit_mode[1]->is_pressed()) { // Edit polygon.
|
||||
node->set_polygon(points_prev);
|
||||
}
|
||||
} else if (split_create) {
|
||||
split_create = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_commit_action() {
|
||||
|
||||
// Makes that undo/redoing actions made outside of the UV editor still affects its polygon.
|
||||
undo_redo->add_do_method(uv_edit_draw, "update");
|
||||
undo_redo->add_undo_method(uv_edit_draw, "update");
|
||||
undo_redo->add_do_method(CanvasItemEditor::get_singleton(), "update_viewport");
|
||||
undo_redo->add_undo_method(CanvasItemEditor::get_singleton(), "update_viewport");
|
||||
undo_redo->commit_action();
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_set_use_snap(bool p_use) {
|
||||
use_snap = p_use;
|
||||
EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "snap_enabled", p_use);
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_set_show_grid(bool p_show) {
|
||||
snap_show_grid = p_show;
|
||||
EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "show_grid", p_show);
|
||||
uv_edit_draw->update();
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_set_snap_off_x(float p_val) {
|
||||
snap_offset.x = p_val;
|
||||
EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "snap_offset", snap_offset);
|
||||
uv_edit_draw->update();
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_set_snap_off_y(float p_val) {
|
||||
snap_offset.y = p_val;
|
||||
EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "snap_offset", snap_offset);
|
||||
uv_edit_draw->update();
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_set_snap_step_x(float p_val) {
|
||||
snap_step.x = p_val;
|
||||
EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "snap_step", snap_step);
|
||||
uv_edit_draw->update();
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_set_snap_step_y(float p_val) {
|
||||
snap_step.y = p_val;
|
||||
EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "snap_step", snap_step);
|
||||
uv_edit_draw->update();
|
||||
}
|
||||
|
||||
@@ -364,6 +421,9 @@ void Polygon2DEditor::_uv_mode(int p_mode) {
|
||||
|
||||
void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
|
||||
if (!_get_node())
|
||||
return;
|
||||
|
||||
Transform2D mtx;
|
||||
mtx.elements[2] = -uv_draw_ofs;
|
||||
mtx.scale_basis(Vector2(uv_draw_zoom, uv_draw_zoom));
|
||||
@@ -376,7 +436,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
|
||||
if (mb->is_pressed()) {
|
||||
|
||||
uv_drag_from = Vector2(mb->get_position().x, mb->get_position().y);
|
||||
uv_drag_from = snap_point(Vector2(mb->get_position().x, mb->get_position().y));
|
||||
uv_drag = true;
|
||||
points_prev = node->get_uv();
|
||||
|
||||
@@ -390,8 +450,9 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
if (uv_move_current == UV_MODE_CREATE) {
|
||||
|
||||
if (!uv_create) {
|
||||
|
||||
points_prev.resize(0);
|
||||
Vector2 tuv = mtx.affine_inverse().xform(Vector2(mb->get_position().x, mb->get_position().y));
|
||||
Vector2 tuv = mtx.affine_inverse().xform(snap_point(Vector2(mb->get_position().x, mb->get_position().y)));
|
||||
points_prev.push_back(tuv);
|
||||
uv_create_to = tuv;
|
||||
point_drag_index = 0;
|
||||
@@ -405,23 +466,27 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
node->set_polygon(points_prev);
|
||||
node->set_uv(points_prev);
|
||||
|
||||
uv_edit_draw->update();
|
||||
} else {
|
||||
Vector2 tuv = mtx.affine_inverse().xform(Vector2(mb->get_position().x, mb->get_position().y));
|
||||
|
||||
if (points_prev.size() > 3 && tuv.distance_to(points_prev[0]) < 8) {
|
||||
Vector2 tuv = mtx.affine_inverse().xform(snap_point(Vector2(mb->get_position().x, mb->get_position().y)));
|
||||
|
||||
if (points_prev.size() > 2 && tuv.distance_to(points_prev[0]) < 8) {
|
||||
undo_redo->create_action(TTR("Create Polygon & UV"));
|
||||
undo_redo->add_do_method(node, "set_uv", node->get_uv());
|
||||
undo_redo->add_undo_method(node, "set_uv", points_prev);
|
||||
undo_redo->add_undo_method(node, "set_uv", uv_create_uv_prev);
|
||||
undo_redo->add_do_method(node, "set_polygon", node->get_polygon());
|
||||
undo_redo->add_undo_method(node, "set_polygon", points_prev);
|
||||
undo_redo->add_undo_method(node, "set_polygon", uv_create_poly_prev);
|
||||
undo_redo->add_do_method(node, "clear_bones");
|
||||
undo_redo->add_undo_method(node, "_set_bones", node->call("_get_bones"));
|
||||
undo_redo->add_undo_method(node, "_set_bones", uv_create_bones_prev);
|
||||
undo_redo->add_do_method(uv_edit_draw, "update");
|
||||
undo_redo->add_undo_method(uv_edit_draw, "update");
|
||||
undo_redo->commit_action();
|
||||
uv_drag = false;
|
||||
uv_create = false;
|
||||
|
||||
_uv_mode(UV_MODE_EDIT_POINT);
|
||||
_menu_option(MODE_EDIT);
|
||||
} else {
|
||||
points_prev.push_back(tuv);
|
||||
point_drag_index = points_prev.size() - 1;
|
||||
@@ -430,6 +495,8 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
node->set_polygon(points_prev);
|
||||
node->set_uv(points_prev);
|
||||
}
|
||||
|
||||
CanvasItemEditor::get_singleton()->update_viewport();
|
||||
}
|
||||
|
||||
if (uv_move_current == UV_MODE_EDIT_POINT) {
|
||||
@@ -540,7 +607,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
splits_prev.push_back(split_to_index);
|
||||
|
||||
undo_redo->create_action(TTR("Add Split"));
|
||||
|
||||
undo_redo->add_do_method(node, "set_splits", splits_prev);
|
||||
undo_redo->add_undo_method(node, "set_splits", node->get_splits());
|
||||
undo_redo->add_do_method(uv_edit_draw, "update");
|
||||
@@ -575,13 +641,11 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
splits_prev.remove(i);
|
||||
|
||||
undo_redo->create_action(TTR("Remove Split"));
|
||||
|
||||
undo_redo->add_do_method(node, "set_splits", splits_prev);
|
||||
undo_redo->add_undo_method(node, "set_splits", node->get_splits());
|
||||
undo_redo->add_do_method(uv_edit_draw, "update");
|
||||
undo_redo->add_undo_method(uv_edit_draw, "update");
|
||||
undo_redo->commit_action();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -608,12 +672,12 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
|
||||
} else if (uv_drag && !uv_create) {
|
||||
|
||||
undo_redo->create_action(TTR("Transform UV Map"));
|
||||
|
||||
if (uv_edit_mode[0]->is_pressed()) { //edit uv
|
||||
undo_redo->create_action(TTR("Transform UV Map"));
|
||||
undo_redo->add_do_method(node, "set_uv", node->get_uv());
|
||||
undo_redo->add_undo_method(node, "set_uv", points_prev);
|
||||
} else if (uv_edit_mode[1]->is_pressed()) { //edit polygon
|
||||
undo_redo->create_action(TTR("Transform Polygon"));
|
||||
undo_redo->add_do_method(node, "set_polygon", node->get_polygon());
|
||||
undo_redo->add_undo_method(node, "set_polygon", points_prev);
|
||||
}
|
||||
@@ -624,7 +688,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
uv_drag = false;
|
||||
} else if (bone_painting) {
|
||||
|
||||
undo_redo->create_action(TTR("Paint bone weights"));
|
||||
undo_redo->create_action(TTR("Paint Bone Weights"));
|
||||
undo_redo->add_do_method(node, "set_bone_weights", bone_painting_bone, node->get_bone_weights(bone_painting_bone));
|
||||
undo_redo->add_undo_method(node, "set_bone_weights", bone_painting_bone, prev_weights);
|
||||
undo_redo->add_do_method(uv_edit_draw, "update");
|
||||
@@ -635,30 +699,12 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
|
||||
} else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) {
|
||||
|
||||
if (uv_create) {
|
||||
_cancel_editing();
|
||||
|
||||
uv_drag = false;
|
||||
uv_create = false;
|
||||
node->set_uv(uv_create_uv_prev);
|
||||
node->set_polygon(uv_create_poly_prev);
|
||||
node->call("_set_bones", uv_create_bones_prev);
|
||||
node->set_splits(splits_prev);
|
||||
uv_edit_draw->update();
|
||||
} else if (uv_drag) {
|
||||
|
||||
uv_drag = false;
|
||||
if (uv_edit_mode[0]->is_pressed()) { //edit uv
|
||||
node->set_uv(points_prev);
|
||||
} else if (uv_edit_mode[1]->is_pressed()) { //edit polygon
|
||||
node->set_polygon(points_prev);
|
||||
}
|
||||
uv_edit_draw->update();
|
||||
} else if (split_create) {
|
||||
split_create = false;
|
||||
uv_edit_draw->update();
|
||||
} else if (bone_painting) {
|
||||
if (bone_painting)
|
||||
node->set_bone_weights(bone_painting_bone, prev_weights);
|
||||
}
|
||||
|
||||
uv_edit_draw->update();
|
||||
|
||||
} else if (mb->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed()) {
|
||||
|
||||
@@ -682,13 +728,15 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
} 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(Vector2(mm->get_position().x, mm->get_position().y));
|
||||
uv_create_to = mtx.affine_inverse().xform(snap_point(Vector2(mm->get_position().x, mm->get_position().y)));
|
||||
}
|
||||
} break;
|
||||
case UV_MODE_EDIT_POINT: {
|
||||
@@ -713,7 +761,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
} else if (uv_edit_mode[1]->is_pressed()) { //edit polygon
|
||||
node->set_polygon(uv_new);
|
||||
}
|
||||
|
||||
} break;
|
||||
case UV_MODE_ROTATE: {
|
||||
|
||||
@@ -737,7 +784,6 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
} else if (uv_edit_mode[1]->is_pressed()) { //edit polygon
|
||||
node->set_polygon(uv_new);
|
||||
}
|
||||
|
||||
} break;
|
||||
case UV_MODE_SCALE: {
|
||||
|
||||
@@ -767,11 +813,15 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
node->set_polygon(uv_new);
|
||||
}
|
||||
} 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: {}
|
||||
}
|
||||
|
||||
if (bone_painting) {
|
||||
bone_paint_pos = Vector2(mm->get_position().x, mm->get_position().y);
|
||||
PoolVector<float> painted_weights = node->get_bone_weights(bone_painting_bone);
|
||||
|
||||
{
|
||||
@@ -796,7 +846,9 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
|
||||
|
||||
node->set_bone_weights(bone_painting_bone, painted_weights);
|
||||
}
|
||||
|
||||
uv_edit_draw->update();
|
||||
CanvasItemEditor::get_singleton()->update_viewport();
|
||||
} else if (split_create) {
|
||||
uv_create_to = mtx.affine_inverse().xform(Vector2(mm->get_position().x, mm->get_position().y));
|
||||
uv_edit_draw->update();
|
||||
@@ -833,6 +885,9 @@ void Polygon2DEditor::_uv_scroll_changed(float) {
|
||||
|
||||
void Polygon2DEditor::_uv_draw() {
|
||||
|
||||
if (!uv_edit->is_visible() || !_get_node())
|
||||
return;
|
||||
|
||||
Ref<Texture> base_tex = node->get_texture();
|
||||
if (base_tex.is_null())
|
||||
return;
|
||||
@@ -848,6 +903,7 @@ void Polygon2DEditor::_uv_draw() {
|
||||
VS::get_singleton()->canvas_item_add_set_transform(uv_edit_draw->get_canvas_item(), Transform2D());
|
||||
|
||||
if (snap_show_grid) {
|
||||
Color grid_color = Color(1.0, 1.0, 1.0, 0.15);
|
||||
Size2 s = uv_edit_draw->get_size();
|
||||
int last_cell = 0;
|
||||
|
||||
@@ -857,7 +913,7 @@ void Polygon2DEditor::_uv_draw() {
|
||||
if (i == 0)
|
||||
last_cell = cell;
|
||||
if (last_cell != cell)
|
||||
uv_edit_draw->draw_line(Point2(i, 0), Point2(i, s.height), Color(0.3, 0.7, 1, 0.3));
|
||||
uv_edit_draw->draw_line(Point2(i, 0), Point2(i, s.height), grid_color);
|
||||
last_cell = cell;
|
||||
}
|
||||
}
|
||||
@@ -868,7 +924,7 @@ void Polygon2DEditor::_uv_draw() {
|
||||
if (i == 0)
|
||||
last_cell = cell;
|
||||
if (last_cell != cell)
|
||||
uv_edit_draw->draw_line(Point2(0, i), Point2(s.width, i), Color(0.3, 0.7, 1, 0.3));
|
||||
uv_edit_draw->draw_line(Point2(0, i), Point2(s.width, i), grid_color);
|
||||
last_cell = cell;
|
||||
}
|
||||
}
|
||||
@@ -901,19 +957,26 @@ void Polygon2DEditor::_uv_draw() {
|
||||
|
||||
Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons");
|
||||
|
||||
Color poly_line_color = Color(0.9, 0.5, 0.5);
|
||||
Color prev_color = Color(0.5, 0.5, 0.5);
|
||||
Rect2 rect(Point2(), mtx.basis_xform(base_tex->get_size()));
|
||||
rect.expand_to(mtx.basis_xform(uv_edit_draw->get_size()));
|
||||
|
||||
for (int i = 0; i < uvs.size(); i++) {
|
||||
|
||||
int next = (i + 1) % uvs.size();
|
||||
|
||||
if (uv_drag && uv_move_current == UV_MODE_EDIT_POINT && EDITOR_DEF("editors/poly_editor/show_previous_outline", true)) {
|
||||
uv_edit_draw->draw_line(mtx.xform(points_prev[i]), mtx.xform(points_prev[next]), prev_color, 2 * EDSCALE);
|
||||
}
|
||||
|
||||
Vector2 next_point = uvs[next];
|
||||
if (uv_create && i == uvs.size() - 1) {
|
||||
next_point = uv_create_to;
|
||||
}
|
||||
uv_edit_draw->draw_line(mtx.xform(uvs[i]), mtx.xform(next_point), Color(0.9, 0.5, 0.5), 2);
|
||||
if (weight_r.ptr()) {
|
||||
uv_edit_draw->draw_line(mtx.xform(uvs[i]), mtx.xform(next_point), poly_line_color, 2 * EDSCALE);
|
||||
|
||||
if (weight_r.ptr()) {
|
||||
Vector2 draw_pos = mtx.xform(uvs[i]);
|
||||
float weight = weight_r[i];
|
||||
uv_edit_draw->draw_rect(Rect2(draw_pos - Vector2(2, 2) * EDSCALE, Vector2(5, 5) * EDSCALE), Color(weight, weight, weight, 1.0));
|
||||
@@ -926,7 +989,7 @@ void Polygon2DEditor::_uv_draw() {
|
||||
if (split_create) {
|
||||
Vector2 from = uvs[point_drag_index];
|
||||
Vector2 to = uv_create_to;
|
||||
uv_edit_draw->draw_line(mtx.xform(from), mtx.xform(to), Color(0.9, 0.5, 0.5), 2);
|
||||
uv_edit_draw->draw_line(mtx.xform(from), mtx.xform(to), poly_line_color, 2);
|
||||
}
|
||||
|
||||
PoolVector<int> splits = node->get_splits();
|
||||
@@ -936,7 +999,7 @@ void Polygon2DEditor::_uv_draw() {
|
||||
int idx_to = splits[i + 1];
|
||||
if (idx_from < 0 || idx_to >= uvs.size())
|
||||
continue;
|
||||
uv_edit_draw->draw_line(mtx.xform(uvs[idx_from]), mtx.xform(uvs[idx_to]), Color(0.9, 0.5, 0.5), 2);
|
||||
uv_edit_draw->draw_line(mtx.xform(uvs[idx_from]), mtx.xform(uvs[idx_to]), poly_line_color, 2);
|
||||
}
|
||||
|
||||
if (uv_mode == UV_MODE_PAINT_WEIGHT || uv_mode == UV_MODE_CLEAR_WEIGHT) {
|
||||
@@ -1002,15 +1065,23 @@ void Polygon2DEditor::_uv_draw() {
|
||||
updating_uv_scroll = true;
|
||||
uv_hscroll->set_min(rect.position.x);
|
||||
uv_hscroll->set_max(rect.position.x + rect.size.x);
|
||||
uv_hscroll->set_page(uv_edit_draw->get_size().x);
|
||||
uv_hscroll->set_value(uv_draw_ofs.x);
|
||||
uv_hscroll->set_step(0.001);
|
||||
if (ABS(rect.position.x - (rect.position.x + rect.size.x)) <= uv_edit_draw->get_size().x) {
|
||||
uv_hscroll->hide();
|
||||
} else {
|
||||
uv_hscroll->show();
|
||||
uv_hscroll->set_page(uv_edit_draw->get_size().x);
|
||||
uv_hscroll->set_value(uv_draw_ofs.x);
|
||||
}
|
||||
|
||||
uv_vscroll->set_min(rect.position.y);
|
||||
uv_vscroll->set_max(rect.position.y + rect.size.y);
|
||||
uv_vscroll->set_page(uv_edit_draw->get_size().y);
|
||||
uv_vscroll->set_value(uv_draw_ofs.y);
|
||||
uv_vscroll->set_step(0.001);
|
||||
if (ABS(rect.position.y - (rect.position.y + rect.size.y)) <= uv_edit_draw->get_size().y) {
|
||||
uv_vscroll->hide();
|
||||
} else {
|
||||
uv_vscroll->show();
|
||||
uv_vscroll->set_page(uv_edit_draw->get_size().y);
|
||||
uv_vscroll->set_value(uv_draw_ofs.y);
|
||||
}
|
||||
updating_uv_scroll = false;
|
||||
}
|
||||
|
||||
@@ -1027,9 +1098,9 @@ void Polygon2DEditor::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("_set_snap_step_x"), &Polygon2DEditor::_set_snap_step_x);
|
||||
ClassDB::bind_method(D_METHOD("_set_snap_step_y"), &Polygon2DEditor::_set_snap_step_y);
|
||||
ClassDB::bind_method(D_METHOD("_uv_edit_mode_select"), &Polygon2DEditor::_uv_edit_mode_select);
|
||||
ClassDB::bind_method(D_METHOD("_uv_edit_popup_hide"), &Polygon2DEditor::_uv_edit_popup_hide);
|
||||
ClassDB::bind_method(D_METHOD("_sync_bones"), &Polygon2DEditor::_sync_bones);
|
||||
ClassDB::bind_method(D_METHOD("_update_bone_list"), &Polygon2DEditor::_update_bone_list);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_bone_paint_selected"), &Polygon2DEditor::_bone_paint_selected);
|
||||
}
|
||||
|
||||
@@ -1046,23 +1117,25 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) :
|
||||
AbstractPolygon2DEditor(p_editor) {
|
||||
|
||||
node = NULL;
|
||||
snap_step = Vector2(10, 10);
|
||||
use_snap = false;
|
||||
snap_show_grid = false;
|
||||
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));
|
||||
use_snap = EditorSettings::get_singleton()->get_project_metadata("polygon_2d_uv_editor", "snap_enabled", false);
|
||||
snap_show_grid = EditorSettings::get_singleton()->get_project_metadata("polygon_2d_uv_editor", "show_grid", false);
|
||||
|
||||
button_uv = memnew(ToolButton);
|
||||
add_child(button_uv);
|
||||
button_uv->set_tooltip(TTR("Open Polygon 2D UV editor."));
|
||||
button_uv->connect("pressed", this, "_menu_option", varray(MODE_EDIT_UV));
|
||||
|
||||
uv_mode = UV_MODE_EDIT_POINT;
|
||||
uv_edit = memnew(AcceptDialog);
|
||||
add_child(uv_edit);
|
||||
uv_edit->set_title(TTR("Polygon 2D UV Editor"));
|
||||
uv_edit->set_self_modulate(Color(1, 1, 1, 0.9));
|
||||
uv_edit->set_resizable(true);
|
||||
uv_edit->connect("popup_hide", this, "_uv_edit_popup_hide");
|
||||
|
||||
VBoxContainer *uv_main_vb = memnew(VBoxContainer);
|
||||
uv_edit->add_child(uv_main_vb);
|
||||
//uv_edit->set_child_rect(uv_main_vb);
|
||||
HBoxContainer *uv_mode_hb = memnew(HBoxContainer);
|
||||
|
||||
uv_edit_group.instance();
|
||||
@@ -1109,14 +1182,14 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) :
|
||||
}
|
||||
|
||||
uv_button[0]->set_tooltip(TTR("Create Polygon"));
|
||||
uv_button[1]->set_tooltip(TTR("Move Point") + "\n" + TTR("Ctrl: Rotate") + "\n" + TTR("Shift: Move All") + "\n" + TTR("Shift+Ctrl: Scale"));
|
||||
uv_button[1]->set_tooltip(TTR("Move Points") + "\n" + TTR("Ctrl: Rotate") + "\n" + TTR("Shift: Move All") + "\n" + TTR("Shift+Ctrl: Scale"));
|
||||
uv_button[2]->set_tooltip(TTR("Move Polygon"));
|
||||
uv_button[3]->set_tooltip(TTR("Rotate Polygon"));
|
||||
uv_button[4]->set_tooltip(TTR("Scale Polygon"));
|
||||
uv_button[5]->set_tooltip(TTR("Connect two points to make a split"));
|
||||
uv_button[6]->set_tooltip(TTR("Select a split to erase it"));
|
||||
uv_button[7]->set_tooltip(TTR("Paint weights with specified intensity"));
|
||||
uv_button[8]->set_tooltip(TTR("UnPaint weights with specified intensity"));
|
||||
uv_button[5]->set_tooltip(TTR("Connect two points to make a split."));
|
||||
uv_button[6]->set_tooltip(TTR("Select a split to erase it."));
|
||||
uv_button[7]->set_tooltip(TTR("Paint weights with specified intensity."));
|
||||
uv_button[8]->set_tooltip(TTR("Unpaint weights with specified intensity."));
|
||||
|
||||
uv_button[0]->hide();
|
||||
uv_button[5]->hide();
|
||||
@@ -1134,7 +1207,7 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) :
|
||||
bone_paint_strength->set_step(0.01);
|
||||
bone_paint_strength->set_value(0.5);
|
||||
|
||||
bone_paint_radius_label = memnew(Label(" " + TTR("Radius:") + " "));
|
||||
bone_paint_radius_label = memnew(Label(TTR("Radius:")));
|
||||
uv_mode_hb->add_child(bone_paint_radius_label);
|
||||
bone_paint_radius = memnew(SpinBox);
|
||||
uv_mode_hb->add_child(bone_paint_radius);
|
||||
@@ -1147,12 +1220,13 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) :
|
||||
bone_paint_radius->set_step(1);
|
||||
bone_paint_radius->set_value(32);
|
||||
|
||||
HBoxContainer *uv_main_hb = memnew(HBoxContainer);
|
||||
uv_main_vb->add_child(uv_main_hb);
|
||||
uv_edit_draw = memnew(Control);
|
||||
uv_main_hb->add_child(uv_edit_draw);
|
||||
uv_main_hb->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
HSplitContainer *uv_main_hsc = memnew(HSplitContainer);
|
||||
uv_main_vb->add_child(uv_main_hsc);
|
||||
uv_main_hsc->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
uv_edit_draw = memnew(Panel);
|
||||
uv_main_hsc->add_child(uv_edit_draw);
|
||||
uv_edit_draw->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
uv_edit_draw->set_custom_minimum_size(Size2(200, 200) * EDSCALE);
|
||||
uv_menu = memnew(MenuButton);
|
||||
uv_mode_hb->add_child(uv_menu);
|
||||
uv_menu->set_text(TTR("Edit"));
|
||||
@@ -1228,6 +1302,7 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) :
|
||||
|
||||
uv_mode_hb->add_child(memnew(VSeparator));
|
||||
uv_icon_zoom = memnew(TextureRect);
|
||||
uv_icon_zoom->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);
|
||||
uv_mode_hb->add_child(uv_icon_zoom);
|
||||
uv_zoom = memnew(HSlider);
|
||||
uv_zoom->set_min(0.01);
|
||||
@@ -1245,17 +1320,25 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) :
|
||||
uv_zoom->connect("value_changed", this, "_uv_scroll_changed");
|
||||
|
||||
uv_vscroll = memnew(VScrollBar);
|
||||
uv_main_hb->add_child(uv_vscroll);
|
||||
uv_vscroll->set_step(0.001);
|
||||
uv_edit_draw->add_child(uv_vscroll);
|
||||
uv_vscroll->set_anchors_and_margins_preset(PRESET_RIGHT_WIDE);
|
||||
uv_vscroll->connect("value_changed", this, "_uv_scroll_changed");
|
||||
uv_hscroll = memnew(HScrollBar);
|
||||
uv_main_vb->add_child(uv_hscroll);
|
||||
uv_hscroll->set_step(0.001);
|
||||
uv_edit_draw->add_child(uv_hscroll);
|
||||
uv_hscroll->set_anchors_and_margins_preset(PRESET_BOTTOM_WIDE);
|
||||
uv_hscroll->set_margin(MARGIN_RIGHT, -uv_vscroll->get_size().x * EDSCALE);
|
||||
uv_hscroll->connect("value_changed", this, "_uv_scroll_changed");
|
||||
|
||||
bone_scroll_main_vb = memnew(VBoxContainer);
|
||||
bone_scroll_main_vb->hide();
|
||||
bone_scroll_main_vb->set_custom_minimum_size(Size2(150 * EDSCALE, 0));
|
||||
sync_bones = memnew(Button(TTR("Sync Bones to Polygon")));
|
||||
bone_scroll_main_vb->add_child(sync_bones);
|
||||
uv_main_hb->add_child(bone_scroll_main_vb);
|
||||
sync_bones->set_h_size_flags(0);
|
||||
sync_bones->connect("pressed", this, "_sync_bones");
|
||||
uv_main_hsc->add_child(bone_scroll_main_vb);
|
||||
bone_scroll = memnew(ScrollContainer);
|
||||
bone_scroll->set_v_scroll(true);
|
||||
bone_scroll->set_h_scroll(false);
|
||||
@@ -1263,7 +1346,6 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) :
|
||||
bone_scroll->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
bone_scroll_vb = memnew(VBoxContainer);
|
||||
bone_scroll->add_child(bone_scroll_vb);
|
||||
sync_bones->connect("pressed", this, "_sync_bones");
|
||||
|
||||
uv_edit_draw->connect("draw", this, "_uv_draw");
|
||||
uv_edit_draw->connect("gui_input", this, "_uv_input");
|
||||
|
||||
Reference in New Issue
Block a user