Simple title screen and level select menu

This commit is contained in:
blinry 2020-12-23 12:01:07 +01:00
parent 2e6d30134c
commit 8bfba3f0aa
8 changed files with 225 additions and 46 deletions

View file

@ -51,8 +51,9 @@ _global_script_class_icons={
[application]
config/name="git-hydra"
run/main_scene="res://scenes/main.tscn"
run/main_scene="res://scenes/level_select.tscn"
config/use_custom_user_dir=true
boot_splash/bg_color=Color( 0, 0, 0, 1 )
[autoload]
@ -141,3 +142,7 @@ limits/debugger_stdout/max_chars_per_second=100000
limits/debugger_stdout/max_messages_per_frame=1000
limits/debugger_stdout/max_errors_per_second=1000
limits/debugger_stdout/max_warnings_per_second=1000
[rendering]
environment/default_clear_color=Color( 0, 0, 0, 1 )

View file

@ -7,6 +7,9 @@ var fake_editor
var dragged_object
var energy = 2
var current_chapter = 0
var current_level = 0
var _file = "user://savegame.json"
var state = {}

33
scenes/level_select.gd Normal file
View file

@ -0,0 +1,33 @@
extends Control
onready var level_list = $ScrollContainer/MarginContainer/Levels
func _ready():
var chapter_id = 0
for chapter in levels.chapters:
var level_id = 0
var l = Label.new()
l.text = chapter.slug
l.set("custom_fonts/font", preload("res://fonts/big.tres"))
l.align = HALIGN_CENTER
level_list.add_child(l)
for level in chapter.levels:
var b = Button.new()
b.text = level.title
b.align = HALIGN_LEFT
b.connect("pressed", self, "load", [chapter_id, level_id])
level_list.add_child(b)
level_id += 1
chapter_id += 1
func load(chapter_id, level_id):
game.current_chapter = chapter_id
game.current_level = level_id
get_tree().change_scene("res://scenes/main.tscn")
func back():
get_tree().change_scene("res://scenes/title.tscn")

45
scenes/level_select.tscn Normal file
View file

@ -0,0 +1,45 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://styles/theme.tres" type="Theme" id=1]
[ext_resource path="res://scenes/level_select.gd" type="Script" id=2]
[node name="LevelSelect" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
theme = ExtResource( 1 )
script = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ScrollContainer" type="ScrollContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="MarginContainer" type="MarginContainer" parent="ScrollContainer"]
margin_right = 1920.0
margin_bottom = 1080.0
size_flags_horizontal = 3
size_flags_vertical = 3
custom_constants/margin_right = 600
custom_constants/margin_left = 600
[node name="Levels" type="VBoxContainer" parent="ScrollContainer/MarginContainer"]
margin_left = 600.0
margin_right = 1320.0
margin_bottom = 1080.0
size_flags_horizontal = 3
[node name="Button" type="Button" parent="."]
margin_left = 61.0902
margin_top = 59.0538
margin_right = 126.09
margin_bottom = 98.0538
text = "Back"
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="pressed" from="Button" to="." method="back"]

View file

@ -2,9 +2,6 @@ extends Control
var dragged = null
var current_chapter
var current_level
onready var terminal = $Rows/Controls/Terminal
onready var input = terminal.input
onready var output = terminal.output
@ -35,21 +32,18 @@ func _ready():
helpers.crash("Could not change to sandbox scene")
return
current_chapter = 0
current_level = 0
# Initialize level select.
level_select.connect("item_selected", self, "load_level")
repopulate_levels()
level_select.select(current_level)
level_select.select(game.current_level)
# Initialize chapter select.
chapter_select.connect("item_selected", self, "load_chapter")
repopulate_chapters()
chapter_select.select(current_chapter)
chapter_select.select(game.current_chapter)
# Load first chapter.
load_chapter(current_chapter)
# Load current level.
load_level(game.current_level)
input.grab_focus()
func _process(delta):
@ -61,7 +55,7 @@ func _process(delta):
func load_chapter(id):
current_chapter = id
game.current_chapter = id
repopulate_levels()
load_level(0)
@ -69,20 +63,20 @@ func load_level(level_id):
next_level_button.hide()
level_congrats.hide()
level_description.show()
current_level = level_id
game.current_level = level_id
AudioServer.set_bus_mute(AudioServer.get_bus_index("Master"), true)
levels.chapters[current_chapter].levels[current_level].construct()
levels.chapters[game.current_chapter].levels[game.current_level].construct()
var level = levels.chapters[current_chapter].levels[current_level]
var level = levels.chapters[game.current_chapter].levels[game.current_level]
level_description.bbcode_text = level.description[0]
level_congrats.bbcode_text = level.congrats
level_name.text = level.title
if levels.chapters[current_chapter].levels[current_level].cards.size() == 0:
if levels.chapters[game.current_chapter].levels[game.current_level].cards.size() == 0:
cards.redraw_all_cards()
else:
cards.draw(levels.chapters[current_chapter].levels[current_level].cards)
cards.draw(levels.chapters[game.current_chapter].levels[game.current_level].cards)
for r in repositories_node.get_children():
r.queue_free()
@ -122,17 +116,17 @@ func load_level(level_id):
AudioServer.set_bus_mute(AudioServer.get_bus_index("Master"), false)
# FIXME: Need to clean these up when switching levels somehow.
chapter_select.select(current_chapter)
level_select.select(current_level)
chapter_select.select(game.current_chapter)
level_select.select(game.current_level)
func reload_level():
levels.reload()
load_level(current_level)
load_level(game.current_level)
func load_next_level():
current_level = (current_level + 1) % levels.chapters[current_chapter].levels.size()
load_level(current_level)
game.current_level = (game.current_level + 1) % levels.chapters[game.current_chapter].levels.size()
load_level(game.current_level)
func show_win_status(win_states):
var all_won = true
@ -141,7 +135,7 @@ func show_win_status(win_states):
win_text += "%s: %s\n" % [state, win_states[state]]
if not win_states[state]:
all_won = false
var level = levels.chapters[current_chapter].levels[current_level]
var level = levels.chapters[game.current_chapter].levels[game.current_level]
level_description.bbcode_text = level.description[0] + win_text
for i in range(1,level.tipp_level+1):
level_description.bbcode_text += level.description[i]
@ -155,19 +149,19 @@ func show_win_status(win_states):
func repopulate_levels():
levels.reload()
level_select.clear()
for level in levels.chapters[current_chapter].levels:
for level in levels.chapters[game.current_chapter].levels:
level_select.add_item(level.title)
level_select.select(current_level)
level_select.select(game.current_level)
func repopulate_chapters():
levels.reload()
chapter_select.clear()
for c in levels.chapters:
chapter_select.add_item(c.slug)
chapter_select.select(current_chapter)
chapter_select.select(game.current_chapter)
func update_repos():
var win_states = levels.chapters[current_chapter].levels[current_level].check_win()
var win_states = levels.chapters[game.current_chapter].levels[game.current_level].check_win()
show_win_status(win_states)
for r in repositories:
@ -180,7 +174,10 @@ func toggle_cards():
cards.visible = not cards.visible
func new_tip():
var level = levels.chapters[current_chapter].levels[current_level]
var level = levels.chapters[game.current_chapter].levels[game.current_level]
if level.description.size() - 1 > level.tipp_level :
level.tipp_level += 1
level_description.bbcode_text += level.description[level.tipp_level]
func back():
get_tree().change_scene("res://scenes/level_select.tscn")

View file

@ -67,7 +67,7 @@ mouse_filter = 2
size_flags_vertical = 3
[node name="Repositories" type="VBoxContainer" parent="Rows/Columns"]
margin_right = 1260.0
margin_right = 1266.0
margin_bottom = 782.0
mouse_filter = 2
size_flags_horizontal = 3
@ -75,7 +75,7 @@ size_flags_stretch_ratio = 2.0
custom_constants/separation = 8
[node name="RightSide" type="VBoxContainer" parent="Rows/Columns"]
margin_left = 1265.0
margin_left = 1271.0
margin_right = 1904.0
margin_bottom = 782.0
size_flags_horizontal = 3
@ -83,18 +83,19 @@ size_flags_vertical = 3
custom_constants/separation = 8
[node name="LevelInfo" type="VBoxContainer" parent="Rows/Columns/RightSide"]
margin_right = 639.0
margin_right = 633.0
margin_bottom = 383.0
size_flags_horizontal = 3
size_flags_vertical = 3
custom_constants/separation = 8
[node name="Menu" type="HBoxContainer" parent="Rows/Columns/RightSide/LevelInfo"]
margin_right = 639.0
margin_right = 633.0
margin_bottom = 39.0
custom_constants/separation = 8
[node name="ChapterSelect" type="OptionButton" parent="Rows/Columns/RightSide/LevelInfo/Menu"]
visible = false
margin_right = 187.0
margin_bottom = 39.0
focus_mode = 0
@ -102,17 +103,27 @@ enabled_focus_mode = 0
text = "Select chapter..."
[node name="LevelSelect" type="OptionButton" parent="Rows/Columns/RightSide/LevelInfo/Menu"]
margin_left = 195.0
margin_right = 354.0
visible = false
margin_right = 159.0
margin_bottom = 39.0
focus_mode = 0
enabled_focus_mode = 0
text = "Select level..."
expand_icon = true
[node name="ReloadButton" type="Button" parent="Rows/Columns/RightSide/LevelInfo/Menu"]
margin_left = 362.0
margin_right = 450.0
[node name="BackButton" type="Button" parent="Rows/Columns/RightSide/LevelInfo/Menu"]
margin_right = 65.0
margin_bottom = 39.0
focus_mode = 0
enabled_focus_mode = 0
text = "Back"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ReloadButton2" type="Button" parent="Rows/Columns/RightSide/LevelInfo/Menu"]
margin_left = 73.0
margin_right = 161.0
margin_bottom = 39.0
focus_mode = 0
enabled_focus_mode = 0
@ -134,8 +145,8 @@ __meta__ = {
}
[node name="Tip!" type="Button" parent="Rows/Columns/RightSide/LevelInfo/Menu"]
margin_left = 458.0
margin_right = 514.0
margin_left = 169.0
margin_right = 225.0
margin_bottom = 39.0
focus_mode = 0
enabled_focus_mode = 0
@ -145,8 +156,8 @@ __meta__ = {
}
[node name="NextLevelButton" type="Button" parent="Rows/Columns/RightSide/LevelInfo/Menu"]
margin_left = 522.0
margin_right = 639.0
margin_left = 233.0
margin_right = 350.0
margin_bottom = 39.0
focus_mode = 0
custom_styles/hover = SubResource( 1 )
@ -159,7 +170,7 @@ __meta__ = {
[node name="LevelPanel" type="VBoxContainer" parent="Rows/Columns/RightSide/LevelInfo"]
margin_top = 47.0
margin_right = 639.0
margin_right = 633.0
margin_bottom = 383.0
size_flags_vertical = 3
@ -175,7 +186,7 @@ __meta__ = {
}
[node name="Text" type="Control" parent="Rows/Columns/RightSide/LevelInfo/LevelPanel"]
margin_right = 639.0
margin_right = 633.0
margin_bottom = 336.0
size_flags_vertical = 3
@ -206,7 +217,7 @@ __meta__ = {
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 391.0
margin_right = 639.0
margin_right = 633.0
margin_bottom = 582.0
size_flags_vertical = 3
size_flags_stretch_ratio = 0.5
@ -217,7 +228,7 @@ mode = 2
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 590.0
margin_right = 639.0
margin_right = 633.0
margin_bottom = 782.0
size_flags_vertical = 3
size_flags_stretch_ratio = 0.5
@ -266,7 +277,8 @@ collision_mask = 0
shape = SubResource( 2 )
[connection signal="button_down" from="Rows/Columns/RightSide/LevelInfo/Menu/ChapterSelect" to="." method="repopulate_chapters"]
[connection signal="button_down" from="Rows/Columns/RightSide/LevelInfo/Menu/LevelSelect" to="." method="repopulate_levels"]
[connection signal="pressed" from="Rows/Columns/RightSide/LevelInfo/Menu/ReloadButton" to="." method="reload_level"]
[connection signal="pressed" from="Rows/Columns/RightSide/LevelInfo/Menu/BackButton" to="." method="back"]
[connection signal="pressed" from="Rows/Columns/RightSide/LevelInfo/Menu/ReloadButton2" to="." method="reload_level"]
[connection signal="pressed" from="Rows/Columns/RightSide/LevelInfo/Menu/CardsButton" to="." method="toggle_cards"]
[connection signal="pressed" from="Rows/Columns/RightSide/LevelInfo/Menu/Tip!" to="." method="new_tip"]
[connection signal="pressed" from="Rows/Columns/RightSide/LevelInfo/Menu/NextLevelButton" to="." method="load_next_level"]

10
scenes/title.gd Normal file
View file

@ -0,0 +1,10 @@
extends Control
func _ready():
pass
func quit():
get_tree().quit()
func levels():
get_tree().change_scene("res://scenes/level_select.tscn")

74
scenes/title.tscn Normal file
View file

@ -0,0 +1,74 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://styles/theme.tres" type="Theme" id=1]
[ext_resource path="res://nodes/head.svg" type="Texture" id=2]
[ext_resource path="res://scenes/title.gd" type="Script" id=3]
[ext_resource path="res://fonts/big.tres" type="DynamicFont" id=4]
[ext_resource path="res://fonts/default.tres" type="DynamicFont" id=5]
[node name="Title" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
theme = ExtResource( 1 )
script = ExtResource( 3 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ColorRect" type="ColorRect" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 0, 0, 0, 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="."]
margin_left = 854.463
margin_top = 234.592
margin_right = 1034.46
margin_bottom = 290.592
custom_fonts/font = ExtResource( 4 )
text = "git-hydra"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label2" type="Label" parent="."]
margin_left = 774.698
margin_top = 297.059
margin_right = 1115.7
margin_bottom = 353.059
custom_fonts/font = ExtResource( 5 )
custom_colors/font_color = Color( 0.533333, 0.392157, 0.392157, 1 )
text = "by bleeptrack & blinry"
align = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="head" type="Sprite" parent="."]
position = Vector2( 946.624, 163.148 )
texture = ExtResource( 2 )
[node name="VBoxContainer" type="VBoxContainer" parent="."]
margin_left = 772.095
margin_top = 394.369
margin_right = 1124.09
margin_bottom = 577.369
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Button" type="Button" parent="VBoxContainer"]
margin_right = 352.0
margin_bottom = 39.0
text = "Levels"
[node name="Button2" type="Button" parent="VBoxContainer"]
margin_top = 44.0
margin_right = 352.0
margin_bottom = 83.0
text = "Quit"
[connection signal="pressed" from="VBoxContainer/Button" to="." method="levels"]
[connection signal="pressed" from="VBoxContainer/Button2" to="." method="quit"]