Add draggable/resizable panels
This commit is contained in:
parent
fc5c2875a9
commit
e592aa435c
6 changed files with 110 additions and 5 deletions
|
@ -18,4 +18,5 @@ corner_radius_bottom_left = 4
|
|||
[resource]
|
||||
default_font = ExtResource( 1 )
|
||||
Panel/styles/panel = SubResource( 1 )
|
||||
PanelContainer/styles/panel = SubResource( 1 )
|
||||
PopupDialog/styles/panel = SubResource( 1 )
|
||||
|
|
|
@ -10,7 +10,6 @@ script = ExtResource( 5 )
|
|||
[node name="world" type="Node2D" parent="."]
|
||||
scale = Vector2( 2, 2 )
|
||||
script = ExtResource( 4 )
|
||||
mapToLoad = 1
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
extends Control
|
||||
|
||||
signal command(command)
|
||||
|
||||
#func _ready():
|
||||
#$MapPopup.popup_centered_ratio()
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://Scenes/UI/SpaceMap.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://Scenes/UI.gd" type="Script" id=2]
|
||||
[ext_resource path="res://Scenes/UI/Widgets/ResizablePanel.tscn" type="PackedScene" id=3]
|
||||
|
||||
[node name="ui" type="Control"]
|
||||
anchor_right = 1.0
|
||||
|
@ -14,3 +15,8 @@ __meta__ = {
|
|||
}
|
||||
|
||||
[node name="MapPopup" parent="." instance=ExtResource( 1 )]
|
||||
|
||||
[node name="PanelContainer" parent="." instance=ExtResource( 3 )]
|
||||
margin_right = 392.0
|
||||
margin_bottom = 256.0
|
||||
title = "Log"
|
||||
|
|
36
Scenes/UI/Widgets/ResizablePanel.gd
Normal file
36
Scenes/UI/Widgets/ResizablePanel.gd
Normal file
|
@ -0,0 +1,36 @@
|
|||
tool
|
||||
|
||||
extends Panel
|
||||
|
||||
export var title = "Unnamed panel" setget set_title
|
||||
|
||||
var dragging = false
|
||||
var resizing = false
|
||||
var last_origin = Vector2.ZERO
|
||||
var last_mouse = Vector2.ZERO
|
||||
|
||||
func _handle_drag(event):
|
||||
if event is InputEventMouseButton:
|
||||
dragging = event.pressed
|
||||
last_origin = rect_position
|
||||
last_mouse = event.global_position
|
||||
if dragging and event is InputEventMouseMotion:
|
||||
rect_position = last_origin + (event.global_position - last_mouse)
|
||||
|
||||
func _handle_resize(event):
|
||||
if event is InputEventMouseButton:
|
||||
resizing = event.pressed
|
||||
last_origin = rect_size
|
||||
last_mouse = event.global_position
|
||||
if resizing and event is InputEventMouseMotion:
|
||||
rect_size = last_origin + (event.global_position - last_mouse)
|
||||
|
||||
func _input(event):
|
||||
if dragging and event is InputEventMouseButton and not event.pressed:
|
||||
dragging = false
|
||||
if resizing and event is InputEventMouseButton and not event.pressed:
|
||||
dragging = false
|
||||
|
||||
func set_title(val):
|
||||
title = val
|
||||
$DragHandle/Label.text = title
|
66
Scenes/UI/Widgets/ResizablePanel.tscn
Normal file
66
Scenes/UI/Widgets/ResizablePanel.tscn
Normal file
|
@ -0,0 +1,66 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://Scenes/UI/Widgets/ResizablePanel.gd" type="Script" id=1]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id=1]
|
||||
bg_color = Color( 0.133333, 0.12549, 0.203922, 0.705882 )
|
||||
border_width_left = 4
|
||||
border_width_top = 4
|
||||
border_width_right = 4
|
||||
border_width_bottom = 4
|
||||
border_color = Color( 0.0941176, 0.0823529, 0.180392, 1 )
|
||||
border_blend = true
|
||||
corner_radius_top_left = 4
|
||||
corner_radius_top_right = 4
|
||||
corner_radius_bottom_right = 4
|
||||
corner_radius_bottom_left = 4
|
||||
|
||||
[node name="ResizablePanel" type="Panel"]
|
||||
margin_left = 10.0
|
||||
margin_top = 10.0
|
||||
margin_right = 376.0
|
||||
margin_bottom = 336.0
|
||||
custom_styles/panel = SubResource( 1 )
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="DragHandle" type="Panel" parent="."]
|
||||
anchor_right = 1.0
|
||||
margin_left = 4.0
|
||||
margin_top = 4.0
|
||||
margin_right = -4.0
|
||||
margin_bottom = 32.0
|
||||
rect_min_size = Vector2( 0, 28 )
|
||||
size_flags_horizontal = 3
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Label" type="Label" parent="DragHandle"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = 2.0
|
||||
margin_top = 2.0
|
||||
margin_right = 2.0
|
||||
margin_bottom = 2.0
|
||||
text = "Unnamed panel"
|
||||
align = 1
|
||||
valign = 1
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="ResizeHandle" type="Panel" parent="."]
|
||||
anchor_left = 1.0
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = -15.0
|
||||
margin_top = -15.0
|
||||
rect_min_size = Vector2( 18, 18 )
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
[connection signal="gui_input" from="DragHandle" to="." method="_handle_drag"]
|
||||
[connection signal="gui_input" from="ResizeHandle" to="." method="_handle_resize"]
|
Reference in a new issue