mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-11-13 20:47:19 +01:00
Set up drawing and resource handling logic for the rect view nodes. They also get instanced now.
This commit is contained in:
parent
34b6877afc
commit
9916554d94
@ -190,3 +190,25 @@ static func get_handle_face_to_vertex_map(arrays : Array) -> Array:
|
|||||||
|
|
||||||
static func calculate_map_midpoints(mesh : Array, vertex_map : Array) -> PoolVector3Array:
|
static func calculate_map_midpoints(mesh : Array, vertex_map : Array) -> PoolVector3Array:
|
||||||
return PoolVector3Array()
|
return PoolVector3Array()
|
||||||
|
|
||||||
|
static func partition_mesh(mdr : MeshDataResource) -> Array:
|
||||||
|
var partitions : Array = Array()
|
||||||
|
|
||||||
|
var arrays : Array = mdr.get_array()
|
||||||
|
|
||||||
|
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
||||||
|
return partitions
|
||||||
|
|
||||||
|
if arrays[ArrayMesh.ARRAY_INDEX] == null:
|
||||||
|
return partitions
|
||||||
|
|
||||||
|
var indices : PoolIntArray = arrays[ArrayMesh.ARRAY_INDEX]
|
||||||
|
|
||||||
|
# TODO! Just copy indices and return them for now so I can develop the gui
|
||||||
|
var iarr : PoolIntArray = PoolIntArray()
|
||||||
|
for i in indices:
|
||||||
|
iarr.push_back(i)
|
||||||
|
|
||||||
|
partitions.append(iarr)
|
||||||
|
|
||||||
|
return partitions
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
tool
|
tool
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
|
var MeshDecompose = preload("res://addons/mesh_data_resource_editor/utilities/mesh_decompose.gd")
|
||||||
|
|
||||||
var rect_editor_node_scene : PackedScene = preload("res://addons/mesh_data_resource_editor/uv_editor/RectViewNode.tscn")
|
var rect_editor_node_scene : PackedScene = preload("res://addons/mesh_data_resource_editor/uv_editor/RectViewNode.tscn")
|
||||||
|
|
||||||
export(NodePath) var zoom_widget_path : NodePath = ""
|
export(NodePath) var zoom_widget_path : NodePath = ""
|
||||||
@ -77,17 +79,16 @@ func refresh_rects() -> void:
|
|||||||
|
|
||||||
if !_mdr:
|
if !_mdr:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
var partitions : Array = MeshDecompose.partition_mesh(_mdr)
|
||||||
|
|
||||||
# var cont : Array = edited_resource.get_content()
|
for p in partitions:
|
||||||
#
|
var s : Node = rect_editor_node_scene.instance()
|
||||||
# for c in cont:
|
|
||||||
# if c:
|
add_child(s)
|
||||||
# var s : Node = rect_editor_node_scene.instance()
|
s.set_editor_rect_scale(_rect_scale)
|
||||||
#
|
s.edited_resource_parent_size = edited_resource_current_size
|
||||||
# add_child(s)
|
s.set_edited_resource(_mdr, p)
|
||||||
# s.set_editor_rect_scale(_rect_scale)
|
|
||||||
# s.edited_resource_parent_size = edited_resource_current_size
|
|
||||||
# s.set_edited_resource(c)
|
|
||||||
|
|
||||||
func clear_rects():
|
func clear_rects():
|
||||||
for c in get_children():
|
for c in get_children():
|
||||||
|
@ -10,11 +10,16 @@ enum DragType {
|
|||||||
DRAG_RESIZE_LEFT = 1 << 4
|
DRAG_RESIZE_LEFT = 1 << 4
|
||||||
};
|
};
|
||||||
|
|
||||||
var edited_resource : WorldGenBaseResource = null
|
var _mdr : MeshDataResource = null
|
||||||
|
var _indices : PoolIntArray = PoolIntArray()
|
||||||
|
var _uvs : PoolVector2Array = PoolVector2Array()
|
||||||
|
var _base_rect : Rect2 = Rect2(0, 0, 100, 100)
|
||||||
|
|
||||||
var edited_resource_parent_size : Vector2 = Vector2()
|
var edited_resource_parent_size : Vector2 = Vector2()
|
||||||
|
|
||||||
var _edited_resource_rect_border_color : Color = Color(1, 1, 1, 1)
|
var _edited_resource_rect_border_color : Color = Color(1, 1, 1, 1)
|
||||||
var _edited_resource_rect_color : Color = Color(0.8, 0.8, 0.8, 0.9)
|
var _edited_resource_rect_color : Color = Color(0.5, 0.5, 0.5, 0.2)
|
||||||
|
var _edited_resource_uv_mesh_color : Color = Color(0.8, 0.8, 0.8, 1)
|
||||||
var _editor_rect_border_size : int = 2
|
var _editor_rect_border_size : int = 2
|
||||||
var _edited_resource_font_color : Color = Color(0, 0, 0, 1)
|
var _edited_resource_font_color : Color = Color(0, 0, 0, 1)
|
||||||
var _editor_additional_text : String = ""
|
var _editor_additional_text : String = ""
|
||||||
@ -29,30 +34,38 @@ func _draw():
|
|||||||
draw_rect(Rect2(Vector2(), get_size()), _edited_resource_rect_color)
|
draw_rect(Rect2(Vector2(), get_size()), _edited_resource_rect_color)
|
||||||
draw_rect(Rect2(Vector2(), get_size()), _edited_resource_rect_border_color, false, _editor_rect_border_size)
|
draw_rect(Rect2(Vector2(), get_size()), _edited_resource_rect_border_color, false, _editor_rect_border_size)
|
||||||
|
|
||||||
var font : Font = get_font("font")
|
if _mdr && _uvs.size() > 0:
|
||||||
|
for i in range(0, len(_indices), 3):
|
||||||
var res_name : String = "NULL"
|
var c : Color = Color(1, 1, 1, 1)
|
||||||
|
|
||||||
if edited_resource:
|
if _uvs[_indices[i]].is_equal_approx(Vector2()) || _uvs[_indices[i + 1]].is_equal_approx(Vector2()):
|
||||||
res_name = edited_resource.resource_name
|
c = Color(1, 0, 0, 1)
|
||||||
|
else:
|
||||||
var res_cls : String = ""
|
c = Color(1, 1, 1, 1)
|
||||||
|
|
||||||
if edited_resource:
|
draw_line(_uvs[_indices[i]] * get_size(), _uvs[_indices[i + 1]] * get_size(), c, 1, false)
|
||||||
res_cls = edited_resource.get_editor_class()
|
|
||||||
|
if _uvs[_indices[i + 1]].is_equal_approx(Vector2()) || _uvs[_indices[i + 2]].is_equal_approx(Vector2()):
|
||||||
draw_string(font, Vector2(_editor_rect_border_size, font.get_height()), res_name, _edited_resource_font_color)
|
c = Color(1, 0, 0, 1)
|
||||||
draw_string(font, Vector2(_editor_rect_border_size, font.get_height() * 2), _editor_additional_text, _edited_resource_font_color, get_rect().size.x)
|
else:
|
||||||
|
c = Color(1, 1, 1, 1)
|
||||||
if res_cls != "":
|
|
||||||
draw_string(font, Vector2(_editor_rect_border_size, font.get_height() * 3), res_cls, _edited_resource_font_color, get_rect().size.x)
|
draw_line(_uvs[_indices[i + 1]] * get_size(), _uvs[_indices[i + 2]] * get_size(), c, 1, false)
|
||||||
|
|
||||||
|
if _uvs[_indices[i + 2]].is_equal_approx(Vector2()) || _uvs[_indices[i]].is_equal_approx(Vector2()):
|
||||||
|
c = Color(1, 0, 0, 1)
|
||||||
|
else:
|
||||||
|
c = Color(1, 1, 1, 1)
|
||||||
|
|
||||||
|
draw_line(_uvs[_indices[i + 2]] * get_size(), _uvs[_indices[i]] * get_size(), c, 1, false)
|
||||||
|
|
||||||
|
|
||||||
func refresh() -> void:
|
func refresh() -> void:
|
||||||
if !edited_resource:
|
if !_mdr:
|
||||||
return
|
return
|
||||||
|
|
||||||
#anchor is bottom left here
|
#anchor is bottom left here
|
||||||
var rect : Rect2 = edited_resource.get_rect()
|
var rect : Rect2 = _base_rect
|
||||||
rect.position *= _rect_scale
|
rect.position *= _rect_scale
|
||||||
rect.size *= _rect_scale
|
rect.size *= _rect_scale
|
||||||
|
|
||||||
@ -69,23 +82,60 @@ func set_editor_rect_scale(rect_scale) -> void:
|
|||||||
|
|
||||||
refresh()
|
refresh()
|
||||||
|
|
||||||
func set_edited_resource(res : WorldGenBaseResource):
|
func set_edited_resource(mdr : MeshDataResource, indices : PoolIntArray):
|
||||||
edited_resource = res
|
_mdr = mdr
|
||||||
|
_indices = indices
|
||||||
|
_uvs.resize(0)
|
||||||
|
|
||||||
if edited_resource:
|
var arrays : Array = _mdr.get_array()
|
||||||
_edited_resource_rect_border_color = edited_resource.get_editor_rect_border_color()
|
|
||||||
_edited_resource_rect_color = edited_resource.get_editor_rect_color()
|
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
||||||
_editor_rect_border_size = edited_resource.get_editor_rect_border_size()
|
return
|
||||||
_edited_resource_font_color = edited_resource.get_editor_font_color()
|
|
||||||
_editor_additional_text = edited_resource.get_editor_additional_text()
|
if arrays[ArrayMesh.ARRAY_TEX_UV] == null:
|
||||||
|
return
|
||||||
|
|
||||||
|
_uvs = arrays[ArrayMesh.ARRAY_TEX_UV]
|
||||||
|
|
||||||
|
set_up_base_rect()
|
||||||
|
|
||||||
refresh()
|
refresh()
|
||||||
|
|
||||||
|
func set_up_base_rect() -> void:
|
||||||
|
_base_rect = Rect2()
|
||||||
|
|
||||||
|
if !_mdr:
|
||||||
|
return
|
||||||
|
|
||||||
|
if _uvs.size() == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
var vmin : Vector2 = _uvs[_indices[0]]
|
||||||
|
var vmax : Vector2 = vmin
|
||||||
|
for i in range(1, _indices.size()):
|
||||||
|
var uv : Vector2 = _uvs[_indices[i]]
|
||||||
|
|
||||||
|
if uv.x < vmin.x:
|
||||||
|
vmin.x = uv.x
|
||||||
|
|
||||||
|
if uv.x > vmax.x:
|
||||||
|
vmax.x = uv.x
|
||||||
|
|
||||||
|
if uv.y < vmin.y:
|
||||||
|
vmin.y = uv.y
|
||||||
|
|
||||||
|
if uv.y > vmax.y:
|
||||||
|
vmax.y = uv.y
|
||||||
|
|
||||||
|
_base_rect = Rect2(vmin.x, vmin.y, vmax.x - vmin.x, vmax.y - vmin.y)
|
||||||
|
_base_rect.position *= edited_resource_parent_size
|
||||||
|
_base_rect.size *= edited_resource_parent_size
|
||||||
|
|
||||||
#based on / ported from engine/scene/gui/dialogs.h and .cpp
|
#based on / ported from engine/scene/gui/dialogs.h and .cpp
|
||||||
func _notification(p_what : int) -> void:
|
func _notification(p_what : int) -> void:
|
||||||
if (p_what == NOTIFICATION_MOUSE_EXIT):
|
if (p_what == NOTIFICATION_MOUSE_EXIT):
|
||||||
# Reset the mouse cursor when leaving the resizable window border.
|
# Reset the mouse cursor when leaving the resizable window border.
|
||||||
if (edited_resource && !edited_resource.locked && !drag_type):
|
if (_mdr && !drag_type):
|
||||||
if (get_default_cursor_shape() != CURSOR_ARROW):
|
if (get_default_cursor_shape() != CURSOR_ARROW):
|
||||||
set_default_cursor_shape(CURSOR_ARROW)
|
set_default_cursor_shape(CURSOR_ARROW)
|
||||||
|
|
||||||
@ -113,31 +163,31 @@ func _gui_input(p_event : InputEvent) -> void:
|
|||||||
if (drag_type == DragType.DRAG_NONE):
|
if (drag_type == DragType.DRAG_NONE):
|
||||||
# Update the cursor while moving along the borders.
|
# Update the cursor while moving along the borders.
|
||||||
var cursor = CURSOR_ARROW
|
var cursor = CURSOR_ARROW
|
||||||
if (!edited_resource.locked):
|
|
||||||
var preview_drag_type : int = _drag_hit_test(Vector2(mm.get_position().x, mm.get_position().y))
|
var preview_drag_type : int = _drag_hit_test(Vector2(mm.get_position().x, mm.get_position().y))
|
||||||
|
|
||||||
var top_left : int = DragType.DRAG_RESIZE_TOP + DragType.DRAG_RESIZE_LEFT
|
var top_left : int = DragType.DRAG_RESIZE_TOP + DragType.DRAG_RESIZE_LEFT
|
||||||
var bottom_right : int = DragType.DRAG_RESIZE_BOTTOM + DragType.DRAG_RESIZE_RIGHT
|
var bottom_right : int = DragType.DRAG_RESIZE_BOTTOM + DragType.DRAG_RESIZE_RIGHT
|
||||||
var top_right : int = DragType.DRAG_RESIZE_TOP + DragType.DRAG_RESIZE_RIGHT
|
var top_right : int = DragType.DRAG_RESIZE_TOP + DragType.DRAG_RESIZE_RIGHT
|
||||||
var bottom_left : int = DragType.DRAG_RESIZE_BOTTOM + DragType.DRAG_RESIZE_LEFT
|
var bottom_left : int = DragType.DRAG_RESIZE_BOTTOM + DragType.DRAG_RESIZE_LEFT
|
||||||
|
|
||||||
match (preview_drag_type):
|
match (preview_drag_type):
|
||||||
DragType.DRAG_RESIZE_TOP:
|
DragType.DRAG_RESIZE_TOP:
|
||||||
cursor = CURSOR_VSIZE
|
cursor = CURSOR_VSIZE
|
||||||
DragType.DRAG_RESIZE_BOTTOM:
|
DragType.DRAG_RESIZE_BOTTOM:
|
||||||
cursor = CURSOR_VSIZE
|
cursor = CURSOR_VSIZE
|
||||||
DragType.DRAG_RESIZE_LEFT:
|
DragType.DRAG_RESIZE_LEFT:
|
||||||
cursor = CURSOR_HSIZE
|
cursor = CURSOR_HSIZE
|
||||||
DragType.DRAG_RESIZE_RIGHT:
|
DragType.DRAG_RESIZE_RIGHT:
|
||||||
cursor = CURSOR_HSIZE
|
cursor = CURSOR_HSIZE
|
||||||
top_left:
|
top_left:
|
||||||
cursor = CURSOR_FDIAGSIZE
|
cursor = CURSOR_FDIAGSIZE
|
||||||
bottom_right:
|
bottom_right:
|
||||||
cursor = CURSOR_FDIAGSIZE
|
cursor = CURSOR_FDIAGSIZE
|
||||||
top_right:
|
top_right:
|
||||||
cursor = CURSOR_BDIAGSIZE
|
cursor = CURSOR_BDIAGSIZE
|
||||||
bottom_left:
|
bottom_left:
|
||||||
cursor = CURSOR_BDIAGSIZE
|
cursor = CURSOR_BDIAGSIZE
|
||||||
|
|
||||||
if (get_cursor_shape() != cursor):
|
if (get_cursor_shape() != cursor):
|
||||||
set_default_cursor_shape(cursor);
|
set_default_cursor_shape(cursor);
|
||||||
@ -175,28 +225,28 @@ func _gui_input(p_event : InputEvent) -> void:
|
|||||||
rect.position.y = edited_resource_parent_size.y * _rect_scale - rect.size.y - rect.position.y
|
rect.position.y = edited_resource_parent_size.y * _rect_scale - rect.size.y - rect.position.y
|
||||||
rect.position /= _rect_scale
|
rect.position /= _rect_scale
|
||||||
rect.size /= _rect_scale
|
rect.size /= _rect_scale
|
||||||
edited_resource.set_rect(rect)
|
#edited_resource.set_rect(rect)
|
||||||
|
#TODO re write uvs -> but only om drag end
|
||||||
|
|
||||||
#based on / ported from engine/scene/gui/dialogs.h and .cpp
|
#based on / ported from engine/scene/gui/dialogs.h and .cpp
|
||||||
func _drag_hit_test(pos : Vector2) -> int:
|
func _drag_hit_test(pos : Vector2) -> int:
|
||||||
var drag_type : int = DragType.DRAG_NONE
|
var drag_type : int = DragType.DRAG_NONE
|
||||||
|
|
||||||
if (!edited_resource.locked):
|
var scaleborder_size : int = 5 #get_constant("scaleborder_size", "WindowDialog")
|
||||||
var scaleborder_size : int = 5 #get_constant("scaleborder_size", "WindowDialog")
|
|
||||||
|
|
||||||
var rect : Rect2 = get_rect()
|
var rect : Rect2 = get_rect()
|
||||||
|
|
||||||
if (pos.y < (scaleborder_size)):
|
if (pos.y < (scaleborder_size)):
|
||||||
drag_type = DragType.DRAG_RESIZE_TOP
|
drag_type = DragType.DRAG_RESIZE_TOP
|
||||||
elif (pos.y >= (rect.size.y - scaleborder_size)):
|
elif (pos.y >= (rect.size.y - scaleborder_size)):
|
||||||
drag_type = DragType.DRAG_RESIZE_BOTTOM
|
drag_type = DragType.DRAG_RESIZE_BOTTOM
|
||||||
|
|
||||||
if (pos.x < scaleborder_size):
|
if (pos.x < scaleborder_size):
|
||||||
drag_type |= DragType.DRAG_RESIZE_LEFT
|
drag_type |= DragType.DRAG_RESIZE_LEFT
|
||||||
elif (pos.x >= (rect.size.x - scaleborder_size)):
|
elif (pos.x >= (rect.size.x - scaleborder_size)):
|
||||||
drag_type |= DragType.DRAG_RESIZE_RIGHT
|
drag_type |= DragType.DRAG_RESIZE_RIGHT
|
||||||
|
|
||||||
if (drag_type == DragType.DRAG_NONE):
|
if (drag_type == DragType.DRAG_NONE):
|
||||||
drag_type = DragType.DRAG_MOVE
|
drag_type = DragType.DRAG_MOVE
|
||||||
|
|
||||||
return drag_type
|
return drag_type
|
||||||
|
Loading…
Reference in New Issue
Block a user