mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-12-21 13:16:49 +01:00
Now RectView's zoom will resize everything, instead of just setting rect_scale.
This commit is contained in:
parent
69b7cbb388
commit
b45e197d69
@ -5,7 +5,7 @@ var rect_editor_node_scene : PackedScene = preload("res://addons/world_generator
|
||||
|
||||
export(NodePath) var zoom_widget_path : NodePath = ""
|
||||
|
||||
var stored_rect_scale : Vector2 = Vector2(1, 1)
|
||||
var _rect_scale : float = 1
|
||||
|
||||
var edited_resource : WorldGenBaseResource = null
|
||||
var edited_resource_current_size : Vector2 = Vector2()
|
||||
@ -20,14 +20,24 @@ func _enter_tree():
|
||||
connect("visibility_changed", self, "on_visibility_changed")
|
||||
|
||||
func on_visibility_changed() -> void:
|
||||
call_deferred("reapply_zoom")
|
||||
call_deferred("apply_zoom")
|
||||
|
||||
func reapply_zoom() -> void:
|
||||
rect_scale = stored_rect_scale
|
||||
func apply_zoom() -> void:
|
||||
if !edited_resource:
|
||||
return
|
||||
|
||||
var rect : Rect2 = edited_resource.rect
|
||||
edited_resource_current_size = rect.size
|
||||
rect.position = rect.position * _rect_scale
|
||||
rect.size = rect.size * _rect_scale
|
||||
set_custom_minimum_size(rect.size)
|
||||
|
||||
for c in get_children():
|
||||
c.set_editor_rect_scale(_rect_scale)
|
||||
|
||||
func on_zoom_changed(zoom : float) -> void:
|
||||
stored_rect_scale = Vector2(zoom, zoom)
|
||||
rect_scale = Vector2(zoom, zoom)
|
||||
_rect_scale = zoom
|
||||
apply_zoom()
|
||||
|
||||
func _draw():
|
||||
draw_rect(Rect2(Vector2(), get_size()), Color(0.2, 0.2, 0.2, 1))
|
||||
@ -39,9 +49,9 @@ func refresh() -> void:
|
||||
return
|
||||
|
||||
var rect : Rect2 = edited_resource.rect
|
||||
|
||||
edited_resource_current_size = rect.size
|
||||
|
||||
rect.position = rect.position * _rect_scale
|
||||
rect.size = rect.size * _rect_scale
|
||||
set_custom_minimum_size(rect.size)
|
||||
|
||||
var p : MarginContainer = get_parent() as MarginContainer
|
||||
@ -51,6 +61,8 @@ func refresh() -> void:
|
||||
p.add_constant_override("margin_top", min(rect.size.y / 4.0, 50))
|
||||
p.add_constant_override("margin_bottom", min(rect.size.y / 4.0, 50))
|
||||
|
||||
apply_zoom()
|
||||
|
||||
refresh_rects()
|
||||
|
||||
func clear() -> void:
|
||||
@ -69,6 +81,7 @@ func refresh_rects() -> void:
|
||||
var s : Node = rect_editor_node_scene.instance()
|
||||
|
||||
add_child(s)
|
||||
s.set_editor_rect_scale(_rect_scale)
|
||||
s.edited_resource_parent_size = edited_resource_current_size
|
||||
s.set_edited_resource(c)
|
||||
|
||||
|
@ -23,6 +23,8 @@ var drag_type : int
|
||||
var drag_offset : Vector2
|
||||
var drag_offset_far : Vector2
|
||||
|
||||
var _rect_scale : float = 1
|
||||
|
||||
func _draw():
|
||||
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)
|
||||
@ -51,15 +53,22 @@ func refresh() -> void:
|
||||
|
||||
#anchor is bottom left here
|
||||
var rect : Rect2 = edited_resource.get_rect()
|
||||
rect.position *= _rect_scale
|
||||
rect.size *= _rect_scale
|
||||
|
||||
#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
|
||||
rp.y = edited_resource_parent_size.y * _rect_scale - rect.size.y - rect.position.y
|
||||
rect_position = rp
|
||||
rect_size = rect.size
|
||||
|
||||
update()
|
||||
|
||||
func set_editor_rect_scale(rect_scale) -> void:
|
||||
_rect_scale = rect_scale
|
||||
|
||||
refresh()
|
||||
|
||||
func set_edited_resource(res : WorldGenBaseResource):
|
||||
edited_resource = res
|
||||
|
||||
@ -163,7 +172,9 @@ func _gui_input(p_event : InputEvent) -> void:
|
||||
set_position(rect.position)
|
||||
|
||||
#rect needs to be converted back
|
||||
rect.position.y = edited_resource_parent_size.y - 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.size /= _rect_scale
|
||||
edited_resource.set_rect(rect)
|
||||
|
||||
#based on / ported from engine/scene/gui/dialogs.h and .cpp
|
||||
|
@ -21,14 +21,14 @@ vendor = ExtResource( 9 )
|
||||
[sub_resource type="Resource" id=3]
|
||||
resource_name = "TestForest"
|
||||
script = ExtResource( 3 )
|
||||
rect = Rect2( 28, 35, 378, 407 )
|
||||
rect = Rect2( 28.5, 27, 378, 407 )
|
||||
locked = false
|
||||
subzones = [ SubResource( 2 ) ]
|
||||
|
||||
[sub_resource type="Resource" id=1]
|
||||
resource_name = "Continent"
|
||||
script = ExtResource( 2 )
|
||||
rect = Rect2( 28, 25, 434, 459 )
|
||||
rect = Rect2( 33.5, 19.5, 434, 459 )
|
||||
locked = false
|
||||
zones = [ SubResource( 3 ) ]
|
||||
dungeon_teleporter = ExtResource( 5 )
|
||||
|
Loading…
Reference in New Issue
Block a user