mirror of
https://github.com/JohnBreaux/Boat-Battle.git
synced 2024-11-15 05:25:57 +00:00
Add help text to debug menu
This commit is contained in:
parent
5f8c881c1c
commit
4cbccbbbbe
@ -48,6 +48,7 @@ placeholder_text = "By your command."
|
|||||||
caret_blink = true
|
caret_blink = true
|
||||||
script = ExtResource( 3 )
|
script = ExtResource( 3 )
|
||||||
|
|
||||||
[connection signal="clear_line" from="." to="debug_canvas/VBoxContainer/LineEdit" method="_on_Debug_clear_line"]
|
[connection signal="clear_in" from="." to="debug_canvas/VBoxContainer/LineEdit" method="_on_Debug_clear_in"]
|
||||||
|
[connection signal="clear_out" from="." to="debug_canvas/VBoxContainer/TextEdit" method="_on_Debug_clear_out"]
|
||||||
[connection signal="print_text" from="." to="debug_canvas/VBoxContainer/TextEdit" method="_on_Debug_print_text"]
|
[connection signal="print_text" from="." to="debug_canvas/VBoxContainer/TextEdit" method="_on_Debug_print_text"]
|
||||||
[connection signal="text_entered" from="debug_canvas/VBoxContainer/LineEdit" to="." method="_on_LineEdit_text_entered"]
|
[connection signal="text_entered" from="debug_canvas/VBoxContainer/LineEdit" to="." method="_on_LineEdit_text_entered"]
|
||||||
|
@ -5,5 +5,5 @@ extends LineEdit
|
|||||||
# var a = 2
|
# var a = 2
|
||||||
# var b = "text"
|
# var b = "text"
|
||||||
|
|
||||||
func _on_Debug_clear_line():
|
func _on_Debug_clear_in():
|
||||||
clear()
|
clear()
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
extends LineEdit
|
|
||||||
|
|
||||||
|
|
||||||
# Declare member variables here. Examples:
|
|
||||||
# var a = 2
|
|
||||||
# var b = "text"
|
|
||||||
|
|
||||||
func _on_Debug_clear_line():
|
|
||||||
clear()
|
|
@ -8,3 +8,9 @@ func _ready():
|
|||||||
|
|
||||||
func _on_Debug_print_text(text):
|
func _on_Debug_print_text(text):
|
||||||
insert_text_at_cursor(text)
|
insert_text_at_cursor(text)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_Debug_clear_out():
|
||||||
|
cursor_set_line(0)
|
||||||
|
cursor_set_column(0)
|
||||||
|
text = "";
|
||||||
|
@ -16,7 +16,8 @@ var menu_hidden = Transform2D(Vector2(1,0), Vector2(0,1), Vector2(0,-170))
|
|||||||
var menu_active = Transform2D(Vector2(1,0), Vector2(0,1), Vector2(0, 0))
|
var menu_active = Transform2D(Vector2(1,0), Vector2(0,1), Vector2(0, 0))
|
||||||
|
|
||||||
# signals
|
# signals
|
||||||
signal clear_line
|
signal clear_in
|
||||||
|
signal clear_out
|
||||||
signal print_text(text)
|
signal print_text(text)
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
@ -43,36 +44,112 @@ func _input(event):
|
|||||||
debug_active = !debug_active;
|
debug_active = !debug_active;
|
||||||
|
|
||||||
func _on_LineEdit_text_entered(line):
|
func _on_LineEdit_text_entered(line):
|
||||||
emit_signal("clear_line")
|
emit_signal("clear_in")
|
||||||
debug_print_line("")
|
debug_print_line("")
|
||||||
var command = line.split(' ', true, 1)
|
var command = line.split(' ', true, 1)
|
||||||
if command.size() > 0:
|
match command[0]:
|
||||||
match command[0]:
|
"start", "s":
|
||||||
"start":
|
command_start(command)
|
||||||
if command.size() > 1:
|
"stop", "kill", "k":
|
||||||
MessageBus.emit_signal("change_scene", command[1])
|
command_stop(command)
|
||||||
debug_print_line("start '" + command[1] + "'\n".c_unescape())
|
"list", "ls", "l":
|
||||||
else:
|
command_list(command)
|
||||||
debug_print_line("Usage: start scene")
|
"restart", "killall":
|
||||||
"kill":
|
command_restart(command)
|
||||||
if command.size() > 1 and command[1] != "Debug":
|
"print", "p":
|
||||||
MessageBus.emit_signal("kill_scene", command[1])
|
command_print(command)
|
||||||
debug_print_line("kill '" + command[1] + "'\n".c_unescape())
|
"raw_emit", "emit", "r", "e": # Send a signal over the MessageBus
|
||||||
else:
|
command_emit(command)
|
||||||
debug_print_line("Usage: kill scene")
|
"clear","cls": # Clear the output
|
||||||
"restart":
|
command_clear(command)
|
||||||
MessageBus.emit_signal("return_to_title")
|
"help", "h":
|
||||||
"print":
|
command_help(command)
|
||||||
if command.size() > 1:
|
_:
|
||||||
debug_print_line(command[1].c_unescape())
|
debug_print_line("Command not recognized.\n")
|
||||||
"raw_emit":
|
|
||||||
var mbus_signal = command[1].split(' ', true, 1)
|
|
||||||
match mbus_signal.size():
|
|
||||||
2: MessageBus.emit_signal(mbus_signal[0], mbus_signal[1])
|
|
||||||
1: MessageBus.emit_signal(mbus_signal[0])
|
|
||||||
0: debug_print_line( "Usage: raw_emit signal [value]\n")
|
|
||||||
_:
|
|
||||||
debug_print_line("BY YOUR COMMAND.\n")
|
|
||||||
|
|
||||||
func debug_print_line(string):
|
func debug_print_line(string):
|
||||||
emit_signal("print_text", string.c_unescape())
|
emit_signal("print_text", string.c_unescape())
|
||||||
|
|
||||||
|
# Commands
|
||||||
|
|
||||||
|
# start: Loads scene from res://scenes/*.tscn by filename, and starts it
|
||||||
|
func command_start (command):
|
||||||
|
if command.size() > 1:
|
||||||
|
MessageBus.emit_signal("start_tcsn", command[1])
|
||||||
|
debug_print_line("start '" + command[1] + "'\n")
|
||||||
|
else:
|
||||||
|
debug_print_line("Usage: start scene")
|
||||||
|
|
||||||
|
# stop: Stops scene by name of root node.
|
||||||
|
func command_stop (command):
|
||||||
|
if command.size() > 1 and command[1] != "Debug":
|
||||||
|
MessageBus.emit_signal("kill_scene", command[1])
|
||||||
|
debug_print_line("kill '" + command[1] + "'\n")
|
||||||
|
else:
|
||||||
|
debug_print_line("Usage: kill scene")
|
||||||
|
|
||||||
|
# list: Lists names of active scenes (children of Root)
|
||||||
|
func command_list (command):
|
||||||
|
debug_print_line("list: ")
|
||||||
|
MessageBus.emit_signal("list_scenes")
|
||||||
|
|
||||||
|
# restart: Kills the current tree and replants Root
|
||||||
|
func command_restart (command):
|
||||||
|
MessageBus.emit_signal("return_to_title")
|
||||||
|
|
||||||
|
# print: prints a message to the in-game debug console
|
||||||
|
func command_print(command):
|
||||||
|
if command.size() > 1:
|
||||||
|
debug_print_line(command[1] + "\n")
|
||||||
|
|
||||||
|
# emit: emits a message onto the MessageBus (!Extremely Danger!)
|
||||||
|
func command_emit (command):
|
||||||
|
var mbus_signal = command[1].split(' ', true, 1)
|
||||||
|
match mbus_signal.size():
|
||||||
|
2:
|
||||||
|
debug_print_line("Message: " + String(mbus_signal) + "\n")
|
||||||
|
MessageBus.emit_signal(mbus_signal[0], mbus_signal[1])
|
||||||
|
1:
|
||||||
|
debug_print_line("Message: " + String(mbus_signal) + "\n")
|
||||||
|
MessageBus.emit_signal(mbus_signal[0])
|
||||||
|
0: debug_print_line( "Usage: raw_emit signal [value]\n")
|
||||||
|
|
||||||
|
# clear: clears the debug output
|
||||||
|
func command_clear (command):
|
||||||
|
emit_signal("clear_out");
|
||||||
|
|
||||||
|
# help: Prints help dialogue
|
||||||
|
func command_help (command):
|
||||||
|
if (command.size() == 1):
|
||||||
|
debug_print_line("Ship's Commander V0.1\n")
|
||||||
|
debug_print_line("Valid commands:\nstart, stop, list, restart, print, emit, clear, help\n")
|
||||||
|
else:
|
||||||
|
debug_print_line(command[1])
|
||||||
|
match command[1]:
|
||||||
|
"start", "s":
|
||||||
|
debug_print_line(" filename\nAliases: 'start', 's'\n")
|
||||||
|
debug_print_line("Loads and runs the scene filename.tscn\n")
|
||||||
|
"stop", "kill", "k":
|
||||||
|
debug_print_line(" scene\nAliases: 'stop', 'kill', 'k'\n")
|
||||||
|
debug_print_line("Kills an active scene whose name matches node.\n")
|
||||||
|
"list", "ls", "l":
|
||||||
|
debug_print_line("\nAliases: 'list', 'ls', 'l'\n")
|
||||||
|
debug_print_line("Lists the currently active scenes\n")
|
||||||
|
"restart", "killall":
|
||||||
|
debug_print_line("\nAliases: 'restart', 'killall'\n")
|
||||||
|
debug_print_line("Kills the current scene tree and plants a new Root.\n")
|
||||||
|
"print", "p":
|
||||||
|
debug_print_line(" string\nAliases: 'print', 'p'\n")
|
||||||
|
debug_print_line("Prints a string to the in-game debug console\n")
|
||||||
|
"raw_emit", "emit", "r", "e":
|
||||||
|
debug_print_line(" signal [message]\nAliases: 'raw_emit', 'emit', 'r', 'e'\n")
|
||||||
|
debug_print_line("Puts a message on the MessageBus without validation.\n")
|
||||||
|
"clear","cls":
|
||||||
|
debug_print_line("\nAliases: 'clear', 'cls'\n")
|
||||||
|
debug_print_line("Clears the debug output.\n")
|
||||||
|
"help", "h":
|
||||||
|
debug_print_line(" [command]\nAliases: 'help', 'h'\n")
|
||||||
|
debug_print_line("Prints information about a command.\n")
|
||||||
|
_:
|
||||||
|
debug_print_line(command[1] + "\nIsn't a valid command\n")
|
||||||
|
debug_print_line("\n")
|
||||||
|
@ -11,9 +11,11 @@ var debug_enabled = true
|
|||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
# Connect to signals
|
# Connect to signals
|
||||||
|
MessageBus.connect("start_tcsn", self, "_on_scene_start_by_name")
|
||||||
MessageBus.connect("change_scene", self, "_on_scene_start")
|
MessageBus.connect("change_scene", self, "_on_scene_start")
|
||||||
MessageBus.connect("kill_scene", self, "_on_scene_kill")
|
MessageBus.connect("kill_scene", self, "_on_scene_kill")
|
||||||
MessageBus.connect("quit", self, "_on_quit_request")
|
MessageBus.connect("list_scenes", self, "_on_scene_list")
|
||||||
|
MessageBus.connect("quit", self, "_on_quit_request")
|
||||||
MessageBus.connect("return_to_title", self, "_on_title_request")
|
MessageBus.connect("return_to_title", self, "_on_title_request")
|
||||||
# Create the scenes
|
# Create the scenes
|
||||||
title_screen = preload("res://scenes/Title Screen.tscn")
|
title_screen = preload("res://scenes/Title Screen.tscn")
|
||||||
@ -42,23 +44,32 @@ func _on_scene_start(scene):
|
|||||||
add_child (title_screen.instance())
|
add_child (title_screen.instance())
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
func _on_scene_start_by_name(scene):
|
||||||
|
var pack = load("res://scenes/" + scene + ".tscn");
|
||||||
|
add_child(pack.instance());
|
||||||
|
|
||||||
# Kills all child nodes with name matching `scene`
|
# Kills all child nodes with name matching `scene`
|
||||||
func _on_scene_kill(scene):
|
func _on_scene_kill(scene):
|
||||||
print ("_on_scene_kill(",scene,")")
|
|
||||||
var c = get_children()
|
var c = get_children()
|
||||||
for i in range (c.size()):
|
for i in range (c.size()):
|
||||||
if c[i].name == scene:
|
if c[i].name == scene:
|
||||||
c[i].queue_free()
|
c[i].queue_free()
|
||||||
|
MessageBus.emit_signal("print_console", String(c[i].name) + " killed.\n".c_unescape())
|
||||||
return true
|
return true
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
func _on_scene_list():
|
||||||
|
var children = get_children()
|
||||||
|
var names = []
|
||||||
|
for i in range (children.size()):
|
||||||
|
names.append(children[i].name)
|
||||||
|
MessageBus.emit_signal("print_console", String(names) + "\n".c_unescape())
|
||||||
|
|
||||||
|
|
||||||
# Quits
|
# Quits
|
||||||
func _on_quit_request():
|
func _on_quit_request():
|
||||||
print ("_on_quit_request()")
|
|
||||||
get_tree().quit()
|
get_tree().quit()
|
||||||
|
|
||||||
# Kills the current tree and replaces it with a new one
|
# Kills the current tree and replaces it with a new one
|
||||||
func _on_title_request():
|
func _on_title_request():
|
||||||
print ("_on_title_request()")
|
|
||||||
return get_tree().change_scene("res://scenes/Main.tscn")
|
return get_tree().change_scene("res://scenes/Main.tscn")
|
||||||
|
@ -1,9 +1,16 @@
|
|||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
# Ignore "unused signal" warnings in this class
|
||||||
|
# warning-ignore-all:unused_signal
|
||||||
|
|
||||||
# Ask for a scene change
|
# Ask for a scene change
|
||||||
signal change_scene(scene_name)
|
signal change_scene(scene_name)
|
||||||
|
|
||||||
|
signal start_tcsn(scene_tcsn_name)
|
||||||
# Ask to kill scene
|
# Ask to kill scene
|
||||||
signal kill_scene(scene_name)
|
signal kill_scene(scene_name)
|
||||||
|
# Ask to list active scenes
|
||||||
|
signal list_scenes()
|
||||||
# Ask to quit the game
|
# Ask to quit the game
|
||||||
signal quit
|
signal quit
|
||||||
# Ask to return to title screen
|
# Ask to return to title screen
|
||||||
|
Loading…
Reference in New Issue
Block a user