diff options
| author | rom <romangraef@gmail.com> | 2021-04-24 21:47:27 +0200 |
|---|---|---|
| committer | rom <romangraef@gmail.com> | 2021-04-24 21:47:27 +0200 |
| commit | 5d74b160790f35f201f2dd1876b84201a8be9534 (patch) | |
| tree | 6b38166cb8e0e5e49f3b476e460b7896c36dddfc | |
| parent | bcbbc97af8a9c1d3620c45df8e8d26aa4223524b (diff) | |
| download | ldjam48-5d74b160790f35f201f2dd1876b84201a8be9534.tar.gz ldjam48-5d74b160790f35f201f2dd1876b84201a8be9534.tar.bz2 ldjam48-5d74b160790f35f201f2dd1876b84201a8be9534.zip | |
dynamic button size
| -rw-r--r-- | components/buttontest.gd | 20 | ||||
| -rw-r--r-- | components/buttontest.tscn | 20 | ||||
| -rw-r--r-- | hackingscene.tscn | 1 | ||||
| -rw-r--r-- | project.godot | 9 | ||||
| -rw-r--r-- | scenes/menu.tscn | 7 |
5 files changed, 43 insertions, 14 deletions
diff --git a/components/buttontest.gd b/components/buttontest.gd new file mode 100644 index 0000000..0303480 --- /dev/null +++ b/components/buttontest.gd @@ -0,0 +1,20 @@ +extends Node2D +class_name ButtonTest +export var text = "Hello, Button" +onready var stretcher : Node2D = $Middle +onready var left : Node2D = $Left +onready var right : Node2D = $Right +onready var font_source : RichTextLabel = $FontSource +const BASE_WIDTH = 6 + +func _ready(): + var label = Label.new() + label.text = text + label.theme = font_source.theme + add_child(label) + label.rect_position = -label.rect_size / 2 + var width = label.rect_size.x + stretcher.scale.x = width / BASE_WIDTH + left.position.x = -label.rect_size.x / 2 - BASE_WIDTH + right.position.x = label.rect_size.x / 2 + diff --git a/components/buttontest.tscn b/components/buttontest.tscn index d0d4e6b..cd9ff17 100644 --- a/components/buttontest.tscn +++ b/components/buttontest.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=8 format=2] [ext_resource path="res://textures/components/button/middle.png" type="Texture" id=1] [ext_resource path="res://textures/components/button/right.png" type="Texture" id=2] [ext_resource path="res://fonts/Fipps-Regular.otf" type="DynamicFontData" id=3] [ext_resource path="res://textures/components/button/left.png" type="Texture" id=4] +[ext_resource path="res://components/buttontest.gd" type="Script" id=5] [sub_resource type="DynamicFont" id=1] outline_color = Color( 0, 0, 0, 1 ) @@ -12,7 +13,8 @@ font_data = ExtResource( 3 ) [sub_resource type="Theme" id=2] default_font = SubResource( 1 ) -[node name="Node2D" type="Node2D"] +[node name="ButtonTest" type="Node2D"] +script = ExtResource( 5 ) [node name="Left" type="Sprite" parent="."] position = Vector2( -100, 0 ) @@ -25,22 +27,18 @@ scale = Vector2( 4, 4 ) texture = ExtResource( 2 ) [node name="Middle" type="Sprite" parent="."] +position = Vector2( -0.5, 0 ) scale = Vector2( 30.321, 4 ) texture = ExtResource( 1 ) -[node name="RichTextLabel" type="RichTextLabel" parent="."] -anchor_left = 0.5 -anchor_top = 0.5 -anchor_right = 0.5 -anchor_bottom = 0.5 -margin_left = -31.9373 -margin_top = -19.027 -margin_right = 76.0627 -margin_bottom = 27.973 +[node name="FontSource" type="RichTextLabel" parent="."] grow_horizontal = 2 grow_vertical = 2 +rect_clip_content = false +size_flags_horizontal = 3 theme = SubResource( 2 ) text = "Menu" +scroll_active = false __meta__ = { "_edit_use_anchors_": false } diff --git a/hackingscene.tscn b/hackingscene.tscn index c77546e..992ef96 100644 --- a/hackingscene.tscn +++ b/hackingscene.tscn @@ -37,4 +37,5 @@ environment = ExtResource( 4 ) [node name="heart" type="Sprite" parent="."] position = Vector2( 467.501, -263.722 ) texture = ExtResource( 7 ) + [connection signal="on_click" from="HackButton" to="." method="_on_HackButton_on_click"] diff --git a/project.godot b/project.godot index a04a182..7acd388 100644 --- a/project.godot +++ b/project.godot @@ -8,9 +8,14 @@ config_version=4 -_global_script_classes=[ ] +_global_script_classes=[ { +"base": "Node2D", +"class": "ButtonTest", +"language": "GDScript", +"path": "res://components/buttontest.gd" +} ] _global_script_class_icons={ - +"ButtonTest": "" } [application] diff --git a/scenes/menu.tscn b/scenes/menu.tscn index 32a75a0..912ff99 100644 --- a/scenes/menu.tscn +++ b/scenes/menu.tscn @@ -1,8 +1,13 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://components/Logo.tscn" type="PackedScene" id=1] +[ext_resource path="res://components/buttontest.tscn" type="PackedScene" id=2] [node name="Node2D" type="Node2D"] [node name="Node2D" parent="." instance=ExtResource( 1 )] position = Vector2( 144.311, 162.722 ) + +[node name="ButtonTest" parent="." instance=ExtResource( 2 )] +position = Vector2( 713.045, 367.228 ) +text = "Goodbye" |
