Put everything into nested Control nodes

This commit is contained in:
Sebastian Morr 2020-09-21 15:25:54 +02:00
parent 31751ce9d1
commit 260beefbe9
3 changed files with 203 additions and 143 deletions

54
main.gd
View file

@ -1,4 +1,4 @@
extends Node2D extends Control
var dragged = null var dragged = null
@ -6,19 +6,38 @@ var server
var client_connection var client_connection
var current_level = 0 var current_level = 0
onready var terminal = $Terminal export(NodePath) var terminal_path
onready var terminal = get_node(terminal_path)
onready var input = terminal.input onready var input = terminal.input
onready var output = terminal.output onready var output = terminal.output
onready var goal_repository = $Repositories/GoalRepository
onready var active_repository = $Repositories/ActiveRepository export(NodePath) var goal_repository_path
export(NodePath) var active_repository_path
onready var goal_repository = get_node(goal_repository_path)
onready var active_repository = get_node(active_repository_path)
export(NodePath) var level_select_path
onready var level_select = get_node(level_select_path)
export(NodePath) var next_level_button_path
onready var next_level_button = get_node(next_level_button_path)
export(NodePath) var level_name_path
onready var level_name = get_node(level_name_path)
export(NodePath) var level_description_path
onready var level_description = get_node(level_description_path)
export(NodePath) var level_congrats_path
onready var level_congrats = get_node(level_congrats_path)
func _ready(): func _ready():
# Initialize level select. # Initialize level select.
var options = $LevelSelect.get_popup() var options = level_select.get_popup()
repopulate_levels() repopulate_levels()
options.connect("id_pressed", self, "load_level") options.connect("id_pressed", self, "load_level")
$LevelSelect.theme = Theme.new() level_select.theme = Theme.new()
$LevelSelect.theme.default_font = load("res://fonts/default.tres") level_select.theme.default_font = load("res://fonts/default.tres")
# Initialize TCP server for fake editor. # Initialize TCP server for fake editor.
server = TCP_Server.new() server = TCP_Server.new()
@ -75,9 +94,9 @@ func list_levels():
return level_sequence return level_sequence
func load_level(id): func load_level(id):
$NextLevelButton.hide() next_level_button.hide()
$LevelCongrats.hide() level_congrats.hide()
$LevelDescription.show() level_description.show()
current_level = id current_level = id
var levels = list_levels() var levels = list_levels()
@ -92,13 +111,13 @@ func load_level(id):
var description_file = level_prefix+level+"/description" var description_file = level_prefix+level+"/description"
var description = game.read_file(description_file, "no description") var description = game.read_file(description_file, "no description")
$LevelDescription.bbcode_text = description level_description.bbcode_text = description
var congrats_file = level_prefix+level+"/congrats" var congrats_file = level_prefix+level+"/congrats"
var congrats = game.read_file(congrats_file, "Good job, you solved the level!\n\nFeel free to try a few more things or click 'Next Level'.") var congrats = game.read_file(congrats_file, "Good job, you solved the level!\n\nFeel free to try a few more things or click 'Next Level'.")
$LevelCongrats.bbcode_text = congrats level_congrats.bbcode_text = congrats
$LevelName.text = level level_name.text = level
# We're actually destroying stuff here. # We're actually destroying stuff here.
# Make sure that active_repository is in a temporary directory. # Make sure that active_repository is in a temporary directory.
@ -182,13 +201,12 @@ func save_message():
input.grab_focus() input.grab_focus()
func show_win_status(): func show_win_status():
$NextLevelButton.show() next_level_button.show()
$LevelDescription.hide() level_description.hide()
$LevelCongrats.show() level_congrats.show()
func repopulate_levels(): func repopulate_levels():
var options = $LevelSelect.get_popup() var options = level_select.get_popup()
options.clear() options.clear()
for level in list_levels(): for level in list_levels():
options.add_item(level) options.add_item(level)

275
main.tscn
View file

@ -17,56 +17,84 @@ corner_radius_top_right = 3
corner_radius_bottom_right = 3 corner_radius_bottom_right = 3
corner_radius_bottom_left = 3 corner_radius_bottom_left = 3
[node name="Main" type="Node2D"] [node name="Main" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 2 ) script = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": false
}
terminal_path = NodePath("HBoxContainer/RightSide/InputArea/Terminal")
goal_repository_path = NodePath("HBoxContainer/Repositories/GoalRepository")
active_repository_path = NodePath("HBoxContainer/Repositories/ActiveRepository")
level_select_path = NodePath("HBoxContainer/RightSide/Menu/LevelSelect")
next_level_button_path = NodePath("HBoxContainer/RightSide/Menu/NextLevelButton")
level_name_path = NodePath("HBoxContainer/RightSide/LevelPanel/LevelName")
level_description_path = NodePath("HBoxContainer/RightSide/LevelPanel/Text/LevelDescription")
level_congrats_path = NodePath("HBoxContainer/RightSide/LevelPanel/Text/LevelCongrats")
[node name="Background" type="ColorRect" parent="."] [node name="Background" type="ColorRect" parent="."]
margin_right = 1922.0 anchor_right = 1.0
margin_bottom = 1081.0 anchor_bottom = 1.0
mouse_filter = 2 mouse_filter = 2
color = Color( 0.0705882, 0.0705882, 0.0705882, 1 ) color = Color( 0.0705882, 0.0705882, 0.0705882, 1 )
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="Terminal" parent="." instance=ExtResource( 1 )] [node name="HBoxContainer" type="HBoxContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Repositories" type="HBoxContainer" parent="HBoxContainer"]
margin_right = 1277.0
margin_bottom = 1080.0
mouse_filter = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 2.0
custom_constants/separation = 0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="GoalRepository" parent="HBoxContainer/Repositories" instance=ExtResource( 3 )]
anchor_right = 0.0 anchor_right = 0.0
anchor_bottom = 0.0 anchor_bottom = 0.0
margin_left = 1218.0 margin_left = 0.0
margin_top = 607.0 margin_top = 0.0
margin_right = 1913.0 margin_right = 638.0
margin_bottom = 1071.0 margin_bottom = 1080.0
size_flags_horizontal = 3
size_flags_vertical = 3
label = "Goal"
[node name="TextEditor" type="TextEdit" parent="."] [node name="ActiveRepository" parent="HBoxContainer/Repositories" instance=ExtResource( 3 )]
visible = false anchor_right = 0.0
margin_left = 1209.0 anchor_bottom = 0.0
margin_top = 484.0 margin_left = 638.0
margin_right = 1907.0 margin_top = 0.0
margin_bottom = 1068.0 margin_right = 1277.0
custom_fonts/font = ExtResource( 5 ) margin_bottom = 1080.0
custom_colors/background_color = Color( 0, 0, 0, 1 ) size_flags_horizontal = 3
syntax_highlighting = true size_flags_vertical = 3
script = ExtResource( 6 ) label = "Your repository"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="SaveButton" type="Button" parent="TextEditor"] [node name="RightSide" type="VBoxContainer" parent="HBoxContainer"]
margin_left = 540.661 margin_left = 1281.0
margin_top = 528.031 margin_right = 1920.0
margin_right = 689.661 margin_bottom = 1080.0
margin_bottom = 577.031 size_flags_horizontal = 3
custom_fonts/font = ExtResource( 5 )
text = "Save"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="LevelSelect" type="MenuButton" parent="."] [node name="Menu" type="HBoxContainer" parent="HBoxContainer/RightSide"]
margin_left = 1226.25 margin_right = 639.0
margin_top = 16.2615 margin_bottom = 32.0
margin_right = 1388.25
margin_bottom = 48.2615 [node name="LevelSelect" type="MenuButton" parent="HBoxContainer/RightSide/Menu"]
margin_right = 162.0
margin_bottom = 32.0
custom_fonts/font = ExtResource( 5 ) custom_fonts/font = ExtResource( 5 )
text = "Select level..." text = "Select level..."
flat = false flat = false
@ -74,82 +102,20 @@ __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="Repositories" type="HBoxContainer" parent="."] [node name="ReloadButton" type="Button" parent="HBoxContainer/RightSide/Menu"]
margin_left = 5.0 margin_left = 166.0
margin_top = 5.0 margin_right = 238.0
margin_right = 1218.0 margin_bottom = 32.0
margin_bottom = 1076.0 custom_fonts/font = ExtResource( 5 )
mouse_filter = 2 text = "Reload"
custom_constants/separation = 0
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="GoalRepository" parent="Repositories" instance=ExtResource( 3 )] [node name="NextLevelButton" type="Button" parent="HBoxContainer/RightSide/Menu"]
anchor_right = 0.0 margin_left = 242.0
anchor_bottom = 0.0 margin_right = 342.0
margin_left = 0.0 margin_bottom = 32.0
margin_top = 0.0
margin_right = 606.0
margin_bottom = 1071.0
size_flags_horizontal = 3
size_flags_vertical = 3
label = "Goal"
[node name="ActiveRepository" parent="Repositories" instance=ExtResource( 3 )]
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 606.0
margin_top = 0.0
margin_right = 1213.0
margin_bottom = 1071.0
size_flags_horizontal = 3
size_flags_vertical = 3
label = "Your repository"
[node name="LevelName" type="RichTextLabel" parent="."]
margin_left = 1224.0
margin_top = 62.0
margin_right = 1889.0
margin_bottom = 128.0
custom_fonts/normal_font = ExtResource( 7 )
text = "Level name here!"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="LevelDescription" type="RichTextLabel" parent="."]
margin_left = 1224.0
margin_top = 121.0
margin_right = 1908.0
margin_bottom = 605.0
custom_fonts/normal_font = ExtResource( 5 )
bbcode_enabled = true
bbcode_text = "Level description here!"
text = "Level description here!"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="LevelCongrats" type="RichTextLabel" parent="."]
visible = false
margin_left = 1224.0
margin_top = 121.0
margin_right = 1908.0
margin_bottom = 605.0
custom_fonts/normal_font = ExtResource( 5 )
bbcode_enabled = true
bbcode_text = "Level description here!"
text = "Level description here!"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="NextLevelButton" type="Button" parent="."]
margin_left = 1688.03
margin_top = 16.2615
margin_right = 1906.03
margin_bottom = 47.2615
custom_styles/hover = SubResource( 1 ) custom_styles/hover = SubResource( 1 )
custom_styles/normal = ExtResource( 4 ) custom_styles/normal = ExtResource( 4 )
custom_fonts/font = ExtResource( 5 ) custom_fonts/font = ExtResource( 5 )
@ -158,13 +124,85 @@ __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="ReloadButton" type="Button" parent="."] [node name="LevelPanel" type="VBoxContainer" parent="HBoxContainer/RightSide"]
margin_left = 1400.72 margin_top = 36.0
margin_top = 16.2615 margin_right = 639.0
margin_right = 1545.72 margin_bottom = 556.0
margin_bottom = 47.2615 size_flags_vertical = 3
[node name="LevelName" type="RichTextLabel" parent="HBoxContainer/RightSide/LevelPanel"]
margin_right = 639.0
margin_bottom = 60.0
rect_min_size = Vector2( 0, 60 )
custom_fonts/normal_font = ExtResource( 7 )
text = "Level name here!"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Text" type="Control" parent="HBoxContainer/RightSide/LevelPanel"]
margin_top = 64.0
margin_right = 639.0
margin_bottom = 520.0
size_flags_vertical = 3
[node name="LevelDescription" type="RichTextLabel" parent="HBoxContainer/RightSide/LevelPanel/Text"]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_vertical = 3
custom_fonts/normal_font = ExtResource( 5 )
bbcode_enabled = true
bbcode_text = "Level description here!"
text = "Level description here!"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="LevelCongrats" type="RichTextLabel" parent="HBoxContainer/RightSide/LevelPanel/Text"]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_vertical = 3
custom_fonts/normal_font = ExtResource( 5 )
bbcode_enabled = true
bbcode_text = "Level description here!"
text = "Level description here!"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="InputArea" type="Control" parent="HBoxContainer/RightSide"]
margin_top = 560.0
margin_right = 639.0
margin_bottom = 1080.0
size_flags_vertical = 3
[node name="Terminal" parent="HBoxContainer/RightSide/InputArea" instance=ExtResource( 1 )]
repository_path = NodePath("../../../Repositories/ActiveRepository")
[node name="TextEditor" type="TextEdit" parent="HBoxContainer/RightSide/InputArea"]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
custom_fonts/font = ExtResource( 5 ) custom_fonts/font = ExtResource( 5 )
text = "Reload" custom_colors/background_color = Color( 0, 0, 0, 1 )
syntax_highlighting = true
script = ExtResource( 6 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="SaveButton" type="Button" parent="HBoxContainer/RightSide/InputArea/TextEditor"]
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = -117.279
margin_top = -59.399
margin_right = -17.2788
margin_bottom = -14.399
custom_fonts/font = ExtResource( 5 )
text = "Save"
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
@ -182,12 +220,13 @@ margin_left = 1362.49
margin_top = 827.517 margin_top = 827.517
margin_right = 1772.49 margin_right = 1772.49
margin_bottom = 914.517 margin_bottom = 914.517
caret_blink = true
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[connection signal="pressed" from="TextEditor/SaveButton" to="." method="save_message"] [connection signal="button_down" from="HBoxContainer/RightSide/Menu/LevelSelect" to="." method="repopulate_levels"]
[connection signal="button_down" from="LevelSelect" to="." method="repopulate_levels"] [connection signal="pressed" from="HBoxContainer/RightSide/Menu/ReloadButton" to="." method="reload_level"]
[connection signal="pressed" from="NextLevelButton" to="." method="load_next_level"] [connection signal="pressed" from="HBoxContainer/RightSide/Menu/NextLevelButton" to="." method="load_next_level"]
[connection signal="pressed" from="ReloadButton" to="." method="reload_level"] [connection signal="pressed" from="HBoxContainer/RightSide/InputArea/TextEditor/SaveButton" to="." method="save_message"]
[connection signal="data_received" from="Test/TCPServer" to="Test" method="data"] [connection signal="data_received" from="Test/TCPServer" to="Test" method="data"]
[connection signal="text_entered" from="Test/LineEdit" to="Test" method="send"] [connection signal="text_entered" from="Test/LineEdit" to="Test" method="send"]

View file

@ -7,9 +7,10 @@ var history_position = 0
onready var input = $Control/InputLine/Input onready var input = $Control/InputLine/Input
onready var output = $Control/Output onready var output = $Control/Output
onready var repo = $"../Repositories/ActiveRepository" export(NodePath) var repository_path
onready var repository = get_node(repository_path)
onready var command_dropdown = $Control/InputLine/CommandDropdown onready var command_dropdown = $Control/InputLine/CommandDropdown
onready var main = get_parent() onready var main = get_tree().get_root().get_node("Main")
onready var text_editor = $"../TextEditor" onready var text_editor = $"../TextEditor"
var premade_commands = [ var premade_commands = [
@ -19,13 +20,15 @@ var premade_commands = [
] ]
func _ready(): func _ready():
#repo.shell.connect("output", self, "receive_output") #repository.shell.connect("output", self, "receive_output")
for command in premade_commands: for command in premade_commands:
command_dropdown.get_popup().add_item(command) command_dropdown.get_popup().add_item(command)
command_dropdown.get_popup().connect("id_pressed", self, "load_command") command_dropdown.get_popup().connect("id_pressed", self, "load_command")
command_dropdown.theme = Theme.new() command_dropdown.theme = Theme.new()
command_dropdown.theme.default_font = load("res://fonts/default.tres") command_dropdown.theme.default_font = load("res://fonts/default.tres")
print(main)
func _input(event): func _input(event):
if event is InputEventKey and not text_editor.visible: if event is InputEventKey and not text_editor.visible:
@ -63,16 +66,16 @@ func send_command(command):
func send_command_async(command): func send_command_async(command):
output.text += "$ "+command+"\n" output.text += "$ "+command+"\n"
input.text = "" input.text = ""
repo.shell.run_async(command) repository.shell.run_async(command)
func run_command_in_a_thread(command): func run_command_in_a_thread(command):
var o = repo.shell.run(command) var o = repository.shell.run(command)
check_win_condition() check_win_condition()
input.text = "" input.text = ""
input.editable = true input.editable = true
output.text = output.text + "$ " + command + "\n" + o output.text = output.text + "$ " + command + "\n" + o
repo.update_everything() repository.update_everything()
func receive_output(text): func receive_output(text):
output.text += text output.text += text
@ -81,5 +84,5 @@ func clear():
output.text = "" output.text = ""
func check_win_condition(): func check_win_condition():
if repo.shell.run("bash /tmp/win 2>/dev/null >/dev/null && echo yes || echo no") == "yes\n": if repository.shell.run("bash /tmp/win 2>/dev/null >/dev/null && echo yes || echo no") == "yes\n":
main.show_win_status() main.show_win_status()