mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-11-13 20:47:19 +01:00
More setup and smaller fixes.
This commit is contained in:
parent
af604f845e
commit
a5cb7ab767
@ -237,10 +237,13 @@ func _on_select_all_pressed():
|
||||
_plugin.select_all()
|
||||
|
||||
func onhandle_selection_type_front_toggled(on : bool):
|
||||
_plugin.handle_selection_type_front()
|
||||
if on:
|
||||
_plugin.handle_selection_type_front()
|
||||
|
||||
func onhandle_selection_type_back_toggled(on : bool):
|
||||
_plugin.handle_selection_type_back()
|
||||
if on:
|
||||
_plugin.handle_selection_type_back()
|
||||
|
||||
func onhandle_selection_type_all_toggled(on : bool):
|
||||
_plugin.handle_selection_type_all()
|
||||
if on:
|
||||
_plugin.handle_selection_type_all()
|
||||
|
@ -197,7 +197,6 @@ func apply() -> void:
|
||||
enable_change_event()
|
||||
|
||||
func select_all() -> void:
|
||||
print("asdasd")
|
||||
if _selected_points.size() == _handle_points.size():
|
||||
return
|
||||
|
||||
@ -208,13 +207,22 @@ func select_all() -> void:
|
||||
|
||||
redraw()
|
||||
|
||||
func selection_click_select_through(index, camera, event):
|
||||
func selection_click(index, camera, event) -> bool:
|
||||
if handle_selection_type == HandleSelectionType.HANDLE_SELECTION_TYPE_FRONT:
|
||||
return selection_click_select_front_or_back(index, camera, event)
|
||||
elif handle_selection_type == HandleSelectionType.HANDLE_SELECTION_TYPE_BACK:
|
||||
return selection_click_select_front_or_back(index, camera, event)
|
||||
else:
|
||||
return selection_click_select_through(index, camera, event)
|
||||
|
||||
return false
|
||||
|
||||
func selection_click_select_front_or_back(index, camera, event):
|
||||
var gt : Transform = get_spatial_node().global_transform
|
||||
var ray_from : Vector3 = camera.global_transform.origin
|
||||
var gpoint : Vector2 = event.get_position()
|
||||
var grab_threshold : float = 8
|
||||
|
||||
|
||||
# select vertex
|
||||
var closest_idx : int = -1
|
||||
var closest_dist : float = 1e10
|
||||
@ -264,6 +272,120 @@ func selection_click_select_through(index, camera, event):
|
||||
|
||||
redraw()
|
||||
|
||||
func selection_click_select_through(index, camera, event):
|
||||
var gt : Transform = get_spatial_node().global_transform
|
||||
var ray_from : Vector3 = camera.global_transform.origin
|
||||
var gpoint : Vector2 = event.get_position()
|
||||
var grab_threshold : float = 8
|
||||
|
||||
# select vertex
|
||||
var closest_idx : int = -1
|
||||
var closest_dist : float = 1e10
|
||||
|
||||
for i in range(_handle_points.size()):
|
||||
var vert_pos_3d : Vector3 = gt.xform(_handle_points[i])
|
||||
var vert_pos_2d : Vector2 = camera.unproject_position(vert_pos_3d)
|
||||
var dist_3d : float = ray_from.distance_to(vert_pos_3d)
|
||||
var dist_2d : float = gpoint.distance_to(vert_pos_2d)
|
||||
|
||||
if (dist_2d < grab_threshold && dist_3d < closest_dist):
|
||||
closest_dist = dist_3d
|
||||
closest_idx = i
|
||||
|
||||
if (closest_idx >= 0):
|
||||
for si in range(_selected_points.size()):
|
||||
|
||||
if _selected_points[si] == closest_idx:
|
||||
if event.alt || event.control:
|
||||
_selected_points.remove(si)
|
||||
return true
|
||||
|
||||
return false
|
||||
|
||||
if event.alt || event.control:
|
||||
return false
|
||||
|
||||
if event.shift:
|
||||
_selected_points.append(closest_idx)
|
||||
else:
|
||||
# Select new point only
|
||||
_selected_points.resize(0)
|
||||
_selected_points.append(closest_idx)
|
||||
|
||||
apply()
|
||||
redraw()
|
||||
else:
|
||||
# Don't unselect all if either control or shift is held down
|
||||
if event.shift || event.control || event.alt:
|
||||
return false
|
||||
|
||||
if _selected_points.size() == 0:
|
||||
return false
|
||||
|
||||
#Unselect all
|
||||
_selected_points.resize(0)
|
||||
|
||||
redraw()
|
||||
|
||||
func selection_drag(index, camera, event) -> void:
|
||||
if handle_selection_type == HandleSelectionType.HANDLE_SELECTION_TYPE_FRONT:
|
||||
selection_drag_rect_select_front_back(index, camera, event)
|
||||
elif handle_selection_type == HandleSelectionType.HANDLE_SELECTION_TYPE_FRONT:
|
||||
selection_drag_rect_select_front_back(index, camera, event)
|
||||
else:
|
||||
selection_drag_rect_select_through(index, camera, event)
|
||||
|
||||
func selection_drag_rect_select_front_back(index, camera, event):
|
||||
var gt : Transform = get_spatial_node().global_transform
|
||||
|
||||
var mouse_pos : Vector2 = event.get_position()
|
||||
var rect_size : Vector2 = _rect_drag_start_point - mouse_pos
|
||||
rect_size.x = abs(rect_size.x)
|
||||
rect_size.y = abs(rect_size.y)
|
||||
|
||||
var rect : Rect2 = Rect2(_rect_drag_start_point, rect_size)
|
||||
|
||||
# This is needed so selection works even when you drag from bottom to top, and from right to left
|
||||
var rect_ofs : Vector2 = _rect_drag_start_point - mouse_pos
|
||||
|
||||
if rect_ofs.x > 0:
|
||||
rect.position.x -= rect_ofs.x
|
||||
|
||||
if rect_ofs.y > 0:
|
||||
rect.position.y -= rect_ofs.y
|
||||
|
||||
var selected : PoolIntArray = PoolIntArray()
|
||||
|
||||
for i in range(_handle_points.size()):
|
||||
var vert_pos_3d : Vector3 = gt.xform(_handle_points[i])
|
||||
var vert_pos_2d : Vector2 = camera.unproject_position(vert_pos_3d)
|
||||
|
||||
if rect.has_point(vert_pos_2d):
|
||||
selected.push_back(i)
|
||||
|
||||
if event.alt || event.control:
|
||||
for isel in selected:
|
||||
for i in range(_selected_points.size()):
|
||||
if _selected_points[i] == isel:
|
||||
_selected_points.remove(i)
|
||||
break
|
||||
redraw()
|
||||
|
||||
return
|
||||
|
||||
if event.shift:
|
||||
for isel in selected:
|
||||
if !pool_int_arr_contains(_selected_points, isel):
|
||||
_selected_points.push_back(isel)
|
||||
|
||||
redraw()
|
||||
return
|
||||
|
||||
_selected_points.resize(0)
|
||||
_selected_points.append_array(selected)
|
||||
|
||||
redraw()
|
||||
|
||||
func selection_drag_rect_select_through(index, camera, event):
|
||||
var gt : Transform = get_spatial_node().global_transform
|
||||
|
||||
@ -345,9 +467,9 @@ func forward_spatial_gui_input(index, camera, event):
|
||||
had_rect_drag = true
|
||||
|
||||
if !had_rect_drag:
|
||||
return selection_click_select_through(index, camera, event)
|
||||
return selection_click(index, camera, event)
|
||||
else:
|
||||
selection_drag_rect_select_through(index, camera, event)
|
||||
selection_drag(index, camera, event)
|
||||
# Always return false here, so the drag rect thing disappears in the editor
|
||||
return false
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user