Allow cards with [string] parameters

This commit is contained in:
blinry 2020-11-10 22:20:40 +01:00
parent 4fa9b27354
commit d57674acca
4 changed files with 57 additions and 1 deletions

View file

@ -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."
}
]

View file

@ -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+"'"))

24
scenes/input_dialog.tscn Normal file
View file

@ -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"]

11
scripts/input_dialog.gd Normal file
View file

@ -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()