From 0cbf540e3030a23b6593a7bc3631624f762d1686 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 27 Dec 2021 02:36:52 +0100 Subject: [PATCH] RectViewNodes now convert between yup and ydown coordinate systems to store rect.position.ys. --- game/addons/world_generator/ui/RectView.gd | 4 ++++ game/addons/world_generator/ui/RectViewNode.gd | 11 +++++++++-- game/modules/planets/test_planet/test_world.tres | 6 +++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/game/addons/world_generator/ui/RectView.gd b/game/addons/world_generator/ui/RectView.gd index aefc7daf..b4ea3302 100644 --- a/game/addons/world_generator/ui/RectView.gd +++ b/game/addons/world_generator/ui/RectView.gd @@ -8,6 +8,7 @@ export(NodePath) var zoom_widget_path : NodePath = "" var stored_rect_scale : Vector2 = Vector2(1, 1) var edited_resource : WorldGenBaseResource = null +var edited_resource_current_size : Vector2 = Vector2() func _enter_tree(): var zoom_widget : Node = get_node_or_null(zoom_widget_path) @@ -39,6 +40,8 @@ func refresh() -> void: var rect : Rect2 = edited_resource.rect + edited_resource_current_size = rect.size + set_custom_minimum_size(rect.size) var p : MarginContainer = get_parent() as MarginContainer @@ -66,6 +69,7 @@ func refresh_rects() -> void: var s : Node = rect_editor_node_scene.instance() add_child(s) + s.edited_resource_parent_size = edited_resource_current_size s.set_edited_resource(c) func clear_rects(): diff --git a/game/addons/world_generator/ui/RectViewNode.gd b/game/addons/world_generator/ui/RectViewNode.gd index 3b4a13bc..b73a284a 100644 --- a/game/addons/world_generator/ui/RectViewNode.gd +++ b/game/addons/world_generator/ui/RectViewNode.gd @@ -11,6 +11,7 @@ enum DragType { }; var edited_resource : WorldGenBaseResource = null +var edited_resource_parent_size : Vector2 = Vector2() 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) @@ -47,10 +48,14 @@ func _draw(): func refresh() -> void: if !edited_resource: return - + + #anchor is bottom left here var rect : Rect2 = edited_resource.get_rect() - rect_position = rect.position + #anchor needs to be on top left here + var rp : Vector2 = rect.position + rp.y = edited_resource_parent_size.y - rect.size.y - rect.position.y + rect_position = rp rect_size = rect.size update() @@ -157,6 +162,8 @@ func _gui_input(p_event : InputEvent) -> void: set_size(rect.size) set_position(rect.position) + #rect needs to be converted back + rect.position.y = edited_resource_parent_size.y - rect.size.y - rect.position.y edited_resource.set_rect(rect) #based on / ported from engine/scene/gui/dialogs.h and .cpp diff --git a/game/modules/planets/test_planet/test_world.tres b/game/modules/planets/test_planet/test_world.tres index 97e7ab97..8c90b5aa 100644 --- a/game/modules/planets/test_planet/test_world.tres +++ b/game/modules/planets/test_planet/test_world.tres @@ -11,20 +11,20 @@ [sub_resource type="Resource" id=2] resource_name = "Spawner" script = ExtResource( 4 ) -rect = Rect2( 55, 78, 22, 25 ) +rect = Rect2( 162, 172, 22, 25 ) locked = false [sub_resource type="Resource" id=3] resource_name = "TestForest" script = ExtResource( 3 ) -rect = Rect2( 39, 35, 142, 171 ) +rect = Rect2( 28, 35, 378, 407 ) locked = false subzones = [ SubResource( 2 ) ] [sub_resource type="Resource" id=1] resource_name = "Continent" script = ExtResource( 2 ) -rect = Rect2( 30, 15, 434, 459 ) +rect = Rect2( 28, 25, 434, 459 ) locked = false zones = [ SubResource( 3 ) ] dungeon_teleporter = ExtResource( 5 )