Skip to content

Commit

Permalink
Merge pull request opensuspect#234 from jngo102/bug-227/ui-exits-game
Browse files Browse the repository at this point in the history
UI exits game, takes back to menu screen
  • Loading branch information
TheSecondReal0 authored Dec 4, 2020
2 parents 3e86c81 + 93e152c commit 87c4e7a
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 51 deletions.
3 changes: 2 additions & 1 deletion src/assets/autoload/uimanager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ var ui_list: Dictionary = {

#common UI
"pausemenu": {"scene": preload("res://assets/ui/pausemenu/pausemenu.tscn")},
"chatbox": {"scene": preload("res://assets/ui/lobbyui/chatbox/chatbox.tscn")},
"chatbox": {"scene": preload("res://assets/ui/lobbyui/chatbox/chatbox.tscn")},
"keybind": {"scene": preload("res://assets/ui/submenus/settings/keybind/keybind.tscn")},

#task UI
"clockset": {"scene": preload("res://assets/ui/tasks/clockset/clockset.tscn")}
Expand Down
68 changes: 37 additions & 31 deletions src/assets/ui/mainmenu/mainmenu.tscn
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
[gd_scene load_steps=7 format=2]
[gd_scene load_steps=8 format=2]

[ext_resource path="res://assets/ui/mainmenu/mainmenu.gd" type="Script" id=1]
[ext_resource path="res://assets/ui/submenus/settings/keybind/keybind.tscn" type="PackedScene" id=2]
[ext_resource path="res://assets/ui/submenus/settings/settings.tscn" type="PackedScene" id=3]
[ext_resource path="res://assets/ui/mainmenu/playgame/playgame.tscn" type="PackedScene" id=4]
[ext_resource path="res://assets/common/fonts/title-font.tres" type="DynamicFont" id=5]
[ext_resource path="res://assets/common/fonts/menufont.tres" type="DynamicFont" id=6]
[ext_resource path="res://assets/common/themes/iso_dark.theme" type="Theme" id=7]

[node name="TitleScreen" type="MarginContainer"]
[node name="TitleScreen" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0

[node name="MarginContainer" type="MarginContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
theme = ExtResource( 7 )
Expand All @@ -19,29 +24,29 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="VBoxContainer" type="VBoxContainer" parent="."]
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
margin_left = 64.0
margin_top = 64.0
margin_right = 960.0
margin_bottom = 536.0

[node name="CenterContainer" type="CenterContainer" parent="VBoxContainer"]
[node name="CenterContainer" type="CenterContainer" parent="MarginContainer/VBoxContainer"]
margin_right = 896.0
margin_bottom = 208.0
rect_min_size = Vector2( 0, 208 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Title" type="Label" parent="VBoxContainer/CenterContainer"]
[node name="Title" type="Label" parent="MarginContainer/VBoxContainer/CenterContainer"]
margin_left = 255.0
margin_top = 61.0
margin_right = 640.0
margin_bottom = 147.0
custom_fonts/font = ExtResource( 5 )
text = "OpenSuspect"

[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer"]
[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/VBoxContainer"]
margin_top = 212.0
margin_right = 896.0
margin_bottom = 472.0
Expand All @@ -50,7 +55,7 @@ size_flags_vertical = 3
custom_constants/margin_right = 64
custom_constants/margin_left = 64

[node name="MenuArea" type="MarginContainer" parent="VBoxContainer/MarginContainer"]
[node name="MenuArea" type="MarginContainer" parent="MarginContainer/VBoxContainer/MarginContainer"]
margin_left = 64.0
margin_top = 15.0
margin_right = 832.0
Expand All @@ -64,25 +69,25 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="MainMenu" type="VBoxContainer" parent="VBoxContainer/MarginContainer/MenuArea"]
[node name="MainMenu" type="VBoxContainer" parent="MarginContainer/VBoxContainer/MarginContainer/MenuArea"]
margin_left = 64.0
margin_top = 15.0
margin_right = 704.0
margin_bottom = 215.0
size_flags_vertical = 3
custom_constants/separation = 50

[node name="Control" type="Control" parent="VBoxContainer/MarginContainer/MenuArea/MainMenu"]
[node name="Control" type="Control" parent="MarginContainer/VBoxContainer/MarginContainer/MenuArea/MainMenu"]
margin_right = 640.0

[node name="CenterContainer" type="CenterContainer" parent="VBoxContainer/MarginContainer/MenuArea/MainMenu/Control"]
[node name="CenterContainer" type="CenterContainer" parent="MarginContainer/VBoxContainer/MarginContainer/MenuArea/MainMenu/Control"]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}

[node name="PlayGame" type="Button" parent="VBoxContainer/MarginContainer/MenuArea/MainMenu/Control/CenterContainer"]
[node name="PlayGame" type="Button" parent="MarginContainer/VBoxContainer/MarginContainer/MenuArea/MainMenu/Control/CenterContainer"]
margin_left = 294.0
margin_right = 346.0
margin_bottom = 34.0
Expand All @@ -93,19 +98,19 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="Control2" type="Control" parent="VBoxContainer/MarginContainer/MenuArea/MainMenu"]
[node name="Control2" type="Control" parent="MarginContainer/VBoxContainer/MarginContainer/MenuArea/MainMenu"]
margin_top = 50.0
margin_right = 640.0
margin_bottom = 50.0

[node name="CenterContainer" type="CenterContainer" parent="VBoxContainer/MarginContainer/MenuArea/MainMenu/Control2"]
[node name="CenterContainer" type="CenterContainer" parent="MarginContainer/VBoxContainer/MarginContainer/MenuArea/MainMenu/Control2"]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Appearence" type="Button" parent="VBoxContainer/MarginContainer/MenuArea/MainMenu/Control2/CenterContainer"]
[node name="Appearence" type="Button" parent="MarginContainer/VBoxContainer/MarginContainer/MenuArea/MainMenu/Control2/CenterContainer"]
margin_left = 263.0
margin_right = 377.0
margin_bottom = 34.0
Expand All @@ -115,19 +120,19 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="Control3" type="Control" parent="VBoxContainer/MarginContainer/MenuArea/MainMenu"]
[node name="Control3" type="Control" parent="MarginContainer/VBoxContainer/MarginContainer/MenuArea/MainMenu"]
margin_top = 100.0
margin_right = 640.0
margin_bottom = 100.0

[node name="CenterContainer" type="CenterContainer" parent="VBoxContainer/MarginContainer/MenuArea/MainMenu/Control3"]
[node name="CenterContainer" type="CenterContainer" parent="MarginContainer/VBoxContainer/MarginContainer/MenuArea/MainMenu/Control3"]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Settings" type="Button" parent="VBoxContainer/MarginContainer/MenuArea/MainMenu/Control3/CenterContainer"]
[node name="Settings" type="Button" parent="MarginContainer/VBoxContainer/MarginContainer/MenuArea/MainMenu/Control3/CenterContainer"]
margin_left = 276.0
margin_right = 364.0
margin_bottom = 34.0
Expand All @@ -137,20 +142,20 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="Control5" type="Control" parent="VBoxContainer/MarginContainer/MenuArea/MainMenu"]
[node name="Control5" type="Control" parent="MarginContainer/VBoxContainer/MarginContainer/MenuArea/MainMenu"]
margin_top = 150.0
margin_right = 640.0
margin_bottom = 150.0

[node name="CenterContainer" type="CenterContainer" parent="VBoxContainer/MarginContainer/MenuArea/MainMenu/Control5"]
[node name="CenterContainer" type="CenterContainer" parent="MarginContainer/VBoxContainer/MarginContainer/MenuArea/MainMenu/Control5"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_bottom = 28.0
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Quit" type="Button" parent="VBoxContainer/MarginContainer/MenuArea/MainMenu/Control5/CenterContainer"]
[node name="Quit" type="Button" parent="MarginContainer/VBoxContainer/MarginContainer/MenuArea/MainMenu/Control5/CenterContainer"]
margin_left = 295.0
margin_right = 344.0
margin_bottom = 34.0
Expand All @@ -160,36 +165,37 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="AppearenceEditor" type="HBoxContainer" parent="VBoxContainer/MarginContainer/MenuArea"]
[node name="AppearenceEditor" type="HBoxContainer" parent="MarginContainer/VBoxContainer/MarginContainer/MenuArea"]
visible = false
margin_left = 64.0
margin_top = 15.0
margin_right = 704.0
margin_bottom = 215.0

[node name="Settings" parent="VBoxContainer/MarginContainer/MenuArea" instance=ExtResource( 3 )]
[node name="Settings" parent="MarginContainer/VBoxContainer/MarginContainer/MenuArea" instance=ExtResource( 3 )]
visible = false
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 64.0
margin_top = 15.0
margin_right = 704.0
margin_bottom = 215.0
scroll_cont = NodePath("../../../../../../TitleScreen/TitleScreen/VBoxContainer/MarginContainer/MenuArea/Settings/Settings")

[node name="VBoxContainer" parent="VBoxContainer/MarginContainer/MenuArea/Settings/Settings" index="0"]
margin_right = 640.0

[node name="PlayGame" parent="VBoxContainer/MarginContainer/MenuArea" instance=ExtResource( 4 )]
[node name="PlayGame" parent="MarginContainer/VBoxContainer/MarginContainer/MenuArea" instance=ExtResource( 4 )]
visible = false
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 64.0
margin_top = 15.0
margin_right = 704.0
margin_bottom = 215.0
[connection signal="returnToMainMenu" from="VBoxContainer/MarginContainer/MenuArea" to="VBoxContainer/MarginContainer/MenuArea" method="_on_MenuArea_returnToMainMenu"]
[connection signal="pressed" from="VBoxContainer/MarginContainer/MenuArea/MainMenu/Control/CenterContainer/PlayGame" to="VBoxContainer/MarginContainer/MenuArea" method="_on_NewGame_pressed"]
[connection signal="pressed" from="VBoxContainer/MarginContainer/MenuArea/MainMenu/Control3/CenterContainer/Settings" to="VBoxContainer/MarginContainer/MenuArea" method="_on_Settings_pressed"]
[connection signal="pressed" from="VBoxContainer/MarginContainer/MenuArea/MainMenu/Control5/CenterContainer/Quit" to="VBoxContainer/MarginContainer/MenuArea" method="_on_Quit_pressed"]

[editable path="VBoxContainer/MarginContainer/MenuArea/Settings"]
[node name="KeyBind" parent="." instance=ExtResource( 2 )]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
[connection signal="returnToMainMenu" from="MarginContainer/VBoxContainer/MarginContainer/MenuArea" to="MarginContainer/VBoxContainer/MarginContainer/MenuArea" method="_on_MenuArea_returnToMainMenu"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/MarginContainer/MenuArea/MainMenu/Control/CenterContainer/PlayGame" to="MarginContainer/VBoxContainer/MarginContainer/MenuArea" method="_on_NewGame_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/MarginContainer/MenuArea/MainMenu/Control3/CenterContainer/Settings" to="MarginContainer/VBoxContainer/MarginContainer/MenuArea" method="_on_Settings_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/MarginContainer/MenuArea/MainMenu/Control5/CenterContainer/Quit" to="MarginContainer/VBoxContainer/MarginContainer/MenuArea" method="_on_Quit_pressed"]
23 changes: 16 additions & 7 deletions src/assets/ui/submenus/settings/keybind/keybind.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends CanvasLayer
extends Control

onready var buttoncontainer = get_node("Panel/VBoxContainer")
onready var buttonscript = load("res://assets/ui/submenus/settings/keybind/keybutton.gd")
Expand Down Expand Up @@ -38,8 +38,13 @@ func _ready():
buttoncontainer.add_child(hbox)

buttons[key] = button



func open() -> void:
show()

func close() -> void:
hide()

func change_bind(key, value):
keybinds[key] = value
for k in keybinds.keys():
Expand All @@ -51,21 +56,25 @@ func change_bind(key, value):


func back():
get_tree().change_scene("res://assets/ui/mainmenu/mainmenu.tscn")
UIManager.close_ui("keybind")
UIManager.open_ui("pausemenu")
hide()



func save():
UIManager.keybinds = keybinds.duplicate()
UIManager.set_game_binds()
UIManager.write_config()
get_tree().change_scene("res://assets/ui/mainmenu/mainmenu.tscn")
UIManager.close_ui("keybind")
UIManager.open_ui("pausemenu")
hide()

func label_text(key, label):
if key == "ui_up":
label.text = "UP"
label.text = "Up"
elif key == "ui_down":
label.text = "DOWN"
label.text = "Down"
elif key == "ui_left":
label.text = "Left"
elif key == "ui_right":
Expand Down
5 changes: 4 additions & 1 deletion src/assets/ui/submenus/settings/keybind/keybind.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

[ext_resource path="res://assets/ui/submenus/settings/keybind/keybind.gd" type="Script" id=1]

[node name="KeyBind" type="CanvasLayer"]
[node name="KeyBind" type="Control"]
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Panel" type="Panel" parent="."]
margin_right = 1024.0
Expand Down
16 changes: 10 additions & 6 deletions src/assets/ui/submenus/settings/settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ func _ready():
back_button.text = tr("Back")
back_button.connect("pressed", get_node(".."), "_on_Return")

var button = Button.new()
button.text = tr("Keybinds")
button.connect("pressed", self, "_on_Button_pressed")
var keybinds_button = Button.new()
keybinds_button.text = tr("Keybinds")
keybinds_button.connect("pressed", self, "_on_KeyBindsButton_pressed")


# Init settings view
Expand Down Expand Up @@ -137,7 +137,7 @@ func _ready():


vbox.add_child(hbox)
vbox.add_child(button)
vbox.add_child(keybinds_button)
vbox.add_child(back_button)


Expand All @@ -158,5 +158,9 @@ func get_languages() -> Array:
func set_language(setting):
TranslationServer.set_locale(setting.available[setting.value])

func _on_Button_pressed():
get_tree().change_scene("res://assets/ui/submenus/settings/keybind/keybind.tscn")
func _on_KeyBindsButton_pressed():
if GameManager.state == GameManager.State.Start:
get_owner().get_node("KeyBind").show()
else:
UIManager.open_ui("keybind")
UIManager.close_ui("pausemenu")
3 changes: 3 additions & 0 deletions src/assets/ui/uicontroller/uicontroller.gd
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ func open_ui(ui_name: String, ui_data: Dictionary = {}, reinstance: bool = false
current_ui.open()

func close_ui(ui_name: String, free: bool = false):
print("Closing: ", ui_name)
update_instanced_uis()
if not instanced_uis.has(ui_name):
return
print("Continuing to close: ", ui_name)
var current_ui = get_ui(ui_name)
#call close on a lower class, handles ui system integration
if current_ui.has_method("base_close"):
Expand All @@ -58,6 +60,7 @@ func close_ui(ui_name: String, free: bool = false):
current_ui.close()
if free:
current_ui.free_ui(ui_name)
print("Closed: ", ui_name)

func instance_ui(ui_name: String, ui_data: Dictionary = {}):
update_instanced_uis()
Expand Down
6 changes: 1 addition & 5 deletions src/assets/ui/uicontroller/uicontroller.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=5 format=2]

[ext_resource path="res://assets/ui/hud/defaulthud/defaulthud.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/ui/uicontroller/uicontroller.gd" type="Script" id=2]
[ext_resource path="res://assets/common/shaders/colorblind.shader" type="Shader" id=3]
[ext_resource path="res://assets/ui/pausemenu/pausemenu.tscn" type="PackedScene" id=4]

[sub_resource type="ShaderMaterial" id=1]
shader = ExtResource( 3 )
Expand All @@ -23,6 +22,3 @@ __meta__ = {
[node name="defaulthud" parent="." instance=ExtResource( 1 )]
margin_left = 1.0
margin_right = 1.0

[node name="pausemenu" parent="." instance=ExtResource( 4 )]
visible = false

0 comments on commit 87c4e7a

Please sign in to comment.