From 926714b020a89f7a2b4db00a23156bce3e54ff9e Mon Sep 17 00:00:00 2001 From: rom Date: Mon, 26 Apr 2021 00:25:07 +0200 Subject: revert buttons --- components/button.gd | 22 ++++++---------------- scenes/levels/level1.gd | 1 + scenes/levels/level1.tscn | 9 +++++++++ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/components/button.gd b/components/button.gd index 45a3f4f..734e048 100644 --- a/components/button.gd +++ b/components/button.gd @@ -1,6 +1,6 @@ extends Node2D class_name ButtonTest -export var text = "Hello, Button" setget _text +export var text = "Hello, Button" # Force a fixed width if != -1 export var fixed_width = -1 signal on_click() @@ -30,23 +30,13 @@ const right_nohover = preload("res://textures/components/button/right.png") const right_hover = preload("res://textures/components/button/right_hover.png") const right_press = preload("res://textures/components/button/right_press.png") -onready var label = Label.new() +var label func _ready(): + label = Label.new() + label.text = text label.theme = theme add_child(label) - _text_changed() - -func _text(value): - text = value - if label == null: - return - _text_changed() - -func _text_changed(): - label.text = "" - label.rect_size = Vector2(0,0) - label.text = text label.rect_position = -label.rect_size / 2 var width = label.rect_size.x if fixed_width > 0: @@ -57,8 +47,8 @@ func _text_changed(): hitbox.shape = RectangleShape2D.new() hitbox.shape.extents.y = 32 hitbox.shape.extents.x = right.position.x + right.scale.x * BASE_WIDTH / 2 - update() - label.update() + + func _on_ButtonTest_input_event(viewport, event, shape_idx): if not (event is InputEventMouseButton): diff --git a/scenes/levels/level1.gd b/scenes/levels/level1.gd index 9d48dfd..707b97a 100644 --- a/scenes/levels/level1.gd +++ b/scenes/levels/level1.gd @@ -16,6 +16,7 @@ func _on_Any_button_click(btn_idx): sequence_index += 1 if sequence_index == buttons.size(): finish_level() + return buttons[sequence_index].visible = true print("Correct button: ", btn_idx) else: diff --git a/scenes/levels/level1.tscn b/scenes/levels/level1.tscn index 204374d..7c52e6a 100644 --- a/scenes/levels/level1.tscn +++ b/scenes/levels/level1.tscn @@ -11,36 +11,45 @@ script = ExtResource( 1 ) [node name="Button" parent="ButtonHolder" instance=ExtResource( 2 )] position = Vector2( -370.845, -187.832 ) +text = "1" fixed_width = 30 [node name="Button2" parent="ButtonHolder" instance=ExtResource( 2 )] position = Vector2( -256.483, 79.5727 ) +text = "2" fixed_width = 30 [node name="Button3" parent="ButtonHolder" instance=ExtResource( 2 )] position = Vector2( 269.918, 246.07 ) +text = "3" fixed_width = 30 [node name="Button4" parent="ButtonHolder" instance=ExtResource( 2 )] position = Vector2( -401.118, 15.6646 ) +text = "4" fixed_width = 30 [node name="Button5" parent="ButtonHolder" instance=ExtResource( 2 )] position = Vector2( -130.349, -46.5617 ) +text = "5" fixed_width = 30 [node name="Button6" parent="ButtonHolder" instance=ExtResource( 2 )] position = Vector2( -158.94, 224.207 ) +text = "6" fixed_width = 30 [node name="Button7" parent="ButtonHolder" instance=ExtResource( 2 )] position = Vector2( 128.647, 79.5727 ) +text = "7" fixed_width = 30 [node name="Button8" parent="ButtonHolder" instance=ExtResource( 2 )] position = Vector2( 21.0123, -209.696 ) +text = "8" fixed_width = 30 [node name="Button9" parent="ButtonHolder" instance=ExtResource( 2 )] position = Vector2( 216.1, -39.8346 ) +text = "9" fixed_width = 30 -- cgit