From d57674acca4584afd303abaf7d048d188dd88fd4 Mon Sep 17 00:00:00 2001 From: blinry Date: Tue, 10 Nov 2020 22:20:40 +0100 Subject: [PATCH] Allow cards with [string] parameters --- resources/cards.json | 10 ++++++++++ scenes/card.gd | 13 ++++++++++++- scenes/input_dialog.tscn | 24 ++++++++++++++++++++++++ scripts/input_dialog.gd | 11 +++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 scenes/input_dialog.tscn create mode 100644 scripts/input_dialog.gd diff --git a/resources/cards.json b/resources/cards.json index 92b4c41..ef9fce5 100644 --- a/resources/cards.json +++ b/resources/cards.json @@ -88,5 +88,15 @@ "id": "show", "command": "git show [commit]", "description": "Show what changed in the commit." + }, + { + "id": "branch", + "command": "git branch [string]", + "description": "Create a new branch." + }, + { + "id": "file-new", + "command": "touch [string]", + "description": "Create a new file." } ] diff --git a/scenes/card.gd b/scenes/card.gd index 26706bd..6f3168f 100644 --- a/scenes/card.gd +++ b/scenes/card.gd @@ -53,7 +53,14 @@ func _unhandled_input(event): _turn_off_highlights() modulate.a = 1 - if "[" in command: + if "[string]" in command: + var dialog = preload("res://scenes/input_dialog.tscn").instance() + add_child(dialog) + dialog.popup_centered() + dialog.connect("entered", self, "entered_string") + dialog.connect("popup_hide", self, "move_back") + hide() + elif "[" in command: move_back() else: try_play(command) @@ -103,6 +110,7 @@ func move_back(): position = _home_position rotation_degrees = _home_rotation $ReturnSound.play() + show() func dropped_on(other): if "[" in command: @@ -133,3 +141,6 @@ func try_play(full_command): game.energy -= energy else: move_back() + +func entered_string(string): + try_play(command.replace("[string]", "'"+string+"'")) diff --git a/scenes/input_dialog.tscn b/scenes/input_dialog.tscn new file mode 100644 index 0000000..17876b9 --- /dev/null +++ b/scenes/input_dialog.tscn @@ -0,0 +1,24 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://scripts/input_dialog.gd" type="Script" id=1] + +[node name="InputDialog" type="WindowDialog"] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = 816.0 +margin_top = 446.0 +margin_right = -826.0 +margin_bottom = -591.0 +window_title = "Please enter a value:" +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="LineEdit" type="LineEdit" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 +__meta__ = { +"_edit_use_anchors_": false +} +[connection signal="text_entered" from="LineEdit" to="." method="_text_entered"] diff --git a/scripts/input_dialog.gd b/scripts/input_dialog.gd new file mode 100644 index 0000000..d27e07a --- /dev/null +++ b/scripts/input_dialog.gd @@ -0,0 +1,11 @@ +extends WindowDialog + +signal entered(text) + +func _text_entered(text): + emit_signal("entered", text) + queue_free() + +func _notification(what): + if what == Popup.NOTIFICATION_POST_POPUP: + $LineEdit.grab_focus()