From 1958420f0b067eba328f6f547aeccf2d148aa326 Mon Sep 17 00:00:00 2001 From: Joel Machens Date: Sun, 12 Mar 2023 16:28:07 -0500 Subject: Refactor Credits -> CreditsMenu --- game/src/Credits/Credits.gd | 128 ---------------------------------- game/src/Credits/Credits.tscn | 49 ------------- game/src/CreditsMenu/CreditsMenu.gd | 126 +++++++++++++++++++++++++++++++++ game/src/CreditsMenu/CreditsMenu.tscn | 49 +++++++++++++ game/src/GameMenu.gd | 4 +- game/src/GameMenu.tscn | 6 +- 6 files changed, 180 insertions(+), 182 deletions(-) delete mode 100644 game/src/Credits/Credits.gd delete mode 100644 game/src/Credits/Credits.tscn create mode 100644 game/src/CreditsMenu/CreditsMenu.gd create mode 100644 game/src/CreditsMenu/CreditsMenu.tscn diff --git a/game/src/Credits/Credits.gd b/game/src/Credits/Credits.gd deleted file mode 100644 index a69732c..0000000 --- a/game/src/Credits/Credits.gd +++ /dev/null @@ -1,128 +0,0 @@ -extends Control - -signal back_button_pressed - -############### -# Credits CSV format -# The project title row is the only requirement within the csv file, however -# it can be on any row, so long as it exists. -# ---------------------- -# title,project-title -# role-name,person-name -# role-name,person-name -# role-name,person-name -# ... -############### - -@export_file("*.csv") -var core_credits_path : String - -# TODO: implement for theme instead -# waiting for https://github.com/OpenVic2Project/OpenVic2/pull/48 -@export_group("Label Variants", "label_variants_") -@export -var label_variants_project : StringName - -@export -var label_variants_role : StringName - -@export -var label_variants_person : StringName - -@export -var credits_list: VBoxContainer - -const title_key : String = "TITLE" - -# REQUIREMENTS: -# * 1.5 Credits Menu -# * SS-17 - -# REQUIREMENTS -# * FS-4 -func _load_credit_file(path : String) -> Dictionary: - var roles := {} - var core_credits = FileAccess.open(path, FileAccess.READ) - if core_credits == null: - push_error("Failed to open credits file %s (error code %d)" % [path, FileAccess.get_open_error()]) - return roles - - while not core_credits.eof_reached(): - var line := core_credits.get_csv_line() - var role := line[0].strip_edges().to_upper() - - # If the line does not have an identifiable role or is empty then skip it - if role.is_empty() or line.size() < 2: - if not (role.is_empty() and line.size() < 2): - push_warning("Incorrectly formatted credit line %s in %s" % [line, path]) - continue - - var person := line[1].strip_edges() - - if person.is_empty(): - push_warning("Incorrectly formatted credit line %s in %s" % [line, path]) - continue - if line.size() > 2: - push_warning("Extra entries ignored in credit line %s in %s" % [line, path]) - - if role not in roles: - roles[role] = [person] - else: - if person in roles[role]: - push_warning("Duplicate person %s for role %s in %s" % [person, role, path]) - else: - roles[role].push_back(person) - if title_key in roles: - if roles[title_key].size() > 1: - push_warning("More than one %s: %s in %s" % [title_key, roles[title_key], path]) - roles[title_key] = [roles[title_key][0]] - else: - push_warning("Credits file %s missing %s" % [path, title_key]) - for role_list in roles.values(): - role_list.sort_custom(func(a : String, b : String) -> bool: return a.naturalnocasecmp_to(b) < 0) - return roles - -func _add_label(node : Node, text : String, type_variation : StringName) -> void: - var label := Label.new() - label.name = 'Label' + text - label.text = text - label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER - label.theme_type_variation = type_variation - node.add_child(label) - -# REQUIREMENTS: -# * UI-34, UI-35 -func _add_project_credits(project : Dictionary) -> void: - var project_credits_list = VBoxContainer.new() - project_credits_list.name = 'Credits' - if title_key in project: - var title : String = project[title_key][0] - project_credits_list.name += title - _add_label(project_credits_list, title, label_variants_project) - project_credits_list.add_child(HSeparator.new()) - - for role in project: - if role == title_key: - continue - - var role_parent = VBoxContainer.new() - - for person in project[role]: - _add_label(role_parent, person, label_variants_person) - - _add_label(project_credits_list, role, label_variants_role) - project_credits_list.add_child(role_parent) - project_credits_list.add_child(HSeparator.new()) - - credits_list.add_child(project_credits_list) - -# REQUIREMENTS: -# * SS-17 -func _ready(): - _add_project_credits(_load_credit_file(core_credits_path)) - -# REQUIREMENTS: -# * UI-38 -# * UIFUN-37 -func _on_back_button_pressed() -> void: - back_button_pressed.emit() \ No newline at end of file diff --git a/game/src/Credits/Credits.tscn b/game/src/Credits/Credits.tscn deleted file mode 100644 index fce29fa..0000000 --- a/game/src/Credits/Credits.tscn +++ /dev/null @@ -1,49 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://c8knthxkwj1uj"] - -[ext_resource type="Script" path="res://src/Credits/Credits.gd" id="1_csd7i"] - -[node name="Credits" type="Control" node_paths=PackedStringArray("credits_list")] -editor_description = "UI-34" -layout_mode = 3 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 -script = ExtResource("1_csd7i") -core_credits_path = "res://common/credits.csv" -label_variants_project = &"Label_ProjectCredits" -label_variants_role = &"Label_RoleCredits" -label_variants_person = &"Label_PersonCredits" -credits_list = NodePath("Scroll/CreditsList") - -[node name="ControlMargin" type="MarginContainer" parent="."] -layout_mode = 2 -anchor_right = 1.0 -anchor_bottom = 0.071 -offset_bottom = -0.120003 -theme_override_constants/margin_left = 20 -theme_override_constants/margin_top = 10 -theme_override_constants/margin_right = 20 -theme_override_constants/margin_bottom = 10 - -[node name="BackButton" type="Button" parent="ControlMargin"] -editor_description = "UI-38" -layout_mode = 2 -text = "Back to Main Menu" - -[node name="Scroll" type="ScrollContainer" parent="."] -editor_description = "UI-35" -layout_mode = 2 -anchor_top = 0.071 -anchor_right = 1.0 -anchor_bottom = 1.0 -offset_top = -0.120003 -offset_bottom = -6.0 - -[node name="CreditsList" type="VBoxContainer" parent="Scroll"] -layout_mode = 2 -size_flags_horizontal = 3 -size_flags_vertical = 3 - -[connection signal="pressed" from="ControlMargin/BackButton" to="." method="_on_back_button_pressed"] diff --git a/game/src/CreditsMenu/CreditsMenu.gd b/game/src/CreditsMenu/CreditsMenu.gd new file mode 100644 index 0000000..be992ef --- /dev/null +++ b/game/src/CreditsMenu/CreditsMenu.gd @@ -0,0 +1,126 @@ +extends Control + +signal back_button_pressed + +############### +# Credits CSV format +# The project title row is the only requirement within the csv file, however +# it can be on any row, so long as it exists. +# ---------------------- +# title,project-title +# role-name,person-name +# role-name,person-name +# role-name,person-name +# ... +############### + +@export_file("*.csv") +var core_credits_path : String + +@export_group("Label Variants", "label_variants_") +@export +var label_variants_project : StringName + +@export +var label_variants_role : StringName + +@export +var label_variants_person : StringName + +@export +var credits_list: VBoxContainer + +const title_key : String = "TITLE" + +# REQUIREMENTS: +# * 1.5 Credits Menu +# * SS-17 + +# REQUIREMENTS +# * FS-4 +func _load_credit_file(path : String) -> Dictionary: + var roles := {} + var core_credits = FileAccess.open(path, FileAccess.READ) + if core_credits == null: + push_error("Failed to open credits file %s (error code %d)" % [path, FileAccess.get_open_error()]) + return roles + + while not core_credits.eof_reached(): + var line := core_credits.get_csv_line() + var role := line[0].strip_edges().to_upper() + + # If the line does not have an identifiable role or is empty then skip it + if role.is_empty() or line.size() < 2: + if not (role.is_empty() and line.size() < 2): + push_warning("Incorrectly formatted credit line %s in %s" % [line, path]) + continue + + var person := line[1].strip_edges() + + if person.is_empty(): + push_warning("Incorrectly formatted credit line %s in %s" % [line, path]) + continue + if line.size() > 2: + push_warning("Extra entries ignored in credit line %s in %s" % [line, path]) + + if role not in roles: + roles[role] = [person] + else: + if person in roles[role]: + push_warning("Duplicate person %s for role %s in %s" % [person, role, path]) + else: + roles[role].push_back(person) + if title_key in roles: + if roles[title_key].size() > 1: + push_warning("More than one %s: %s in %s" % [title_key, roles[title_key], path]) + roles[title_key] = [roles[title_key][0]] + else: + push_warning("Credits file %s missing %s" % [path, title_key]) + for role_list in roles.values(): + role_list.sort_custom(func(a : String, b : String) -> bool: return a.naturalnocasecmp_to(b) < 0) + return roles + +func _add_label(node : Node, text : String, type_variation : StringName) -> void: + var label := Label.new() + label.name = 'Label' + text + label.text = text + label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER + label.theme_type_variation = type_variation + node.add_child(label) + +# REQUIREMENTS: +# * UI-34, UI-35 +func _add_project_credits(project : Dictionary) -> void: + var project_credits_list = VBoxContainer.new() + project_credits_list.name = 'Credits' + if title_key in project: + var title : String = project[title_key][0] + project_credits_list.name += title + _add_label(project_credits_list, title, label_variants_project) + project_credits_list.add_child(HSeparator.new()) + + for role in project: + if role == title_key: + continue + + var role_parent = VBoxContainer.new() + + for person in project[role]: + _add_label(role_parent, person, label_variants_person) + + _add_label(project_credits_list, role, label_variants_role) + project_credits_list.add_child(role_parent) + project_credits_list.add_child(HSeparator.new()) + + credits_list.add_child(project_credits_list) + +# REQUIREMENTS: +# * SS-17 +func _ready(): + _add_project_credits(_load_credit_file(core_credits_path)) + +# REQUIREMENTS: +# * UI-38 +# * UIFUN-37 +func _on_back_button_pressed() -> void: + back_button_pressed.emit() \ No newline at end of file diff --git a/game/src/CreditsMenu/CreditsMenu.tscn b/game/src/CreditsMenu/CreditsMenu.tscn new file mode 100644 index 0000000..8a81823 --- /dev/null +++ b/game/src/CreditsMenu/CreditsMenu.tscn @@ -0,0 +1,49 @@ +[gd_scene load_steps=2 format=3 uid="uid://c8knthxkwj1uj"] + +[ext_resource type="Script" path="res://src/CreditsMenu/CreditsMenu.gd" id="1_csd7i"] + +[node name="CreditsMenu" type="Control" node_paths=PackedStringArray("credits_list")] +editor_description = "UI-34" +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_csd7i") +core_credits_path = "res://common/credits.csv" +label_variants_project = &"Label_ProjectCredits" +label_variants_role = &"Label_RoleCredits" +label_variants_person = &"Label_PersonCredits" +credits_list = NodePath("Scroll/CreditsList") + +[node name="ControlMargin" type="MarginContainer" parent="."] +layout_mode = 2 +anchor_right = 1.0 +anchor_bottom = 0.071 +offset_bottom = -0.120003 +theme_override_constants/margin_left = 20 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 20 +theme_override_constants/margin_bottom = 10 + +[node name="BackButton" type="Button" parent="ControlMargin"] +editor_description = "UI-38" +layout_mode = 2 +text = "Back to Main Menu" + +[node name="Scroll" type="ScrollContainer" parent="."] +editor_description = "UI-35" +layout_mode = 2 +anchor_top = 0.071 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_top = -0.120003 +offset_bottom = -6.0 + +[node name="CreditsList" type="VBoxContainer" parent="Scroll"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[connection signal="pressed" from="ControlMargin/BackButton" to="." method="_on_back_button_pressed"] diff --git a/game/src/GameMenu.gd b/game/src/GameMenu.gd index 8430c23..c979f44 100644 --- a/game/src/GameMenu.gd +++ b/game/src/GameMenu.gd @@ -28,10 +28,10 @@ func _on_lobby_menu_back_button_pressed(): func _on_credits_back_button_pressed(): - $Credits.hide() + $CreditsMenu.hide() $MainMenu.show() func _on_main_menu_credits_button_pressed(): - $Credits.show() + $CreditsMenu.show() $MainMenu.hide() diff --git a/game/src/GameMenu.tscn b/game/src/GameMenu.tscn index 4cb14b9..7e86e87 100644 --- a/game/src/GameMenu.tscn +++ b/game/src/GameMenu.tscn @@ -4,7 +4,7 @@ [ext_resource type="Theme" uid="uid://cr4lh0vraucx7" path="res://default_theme.tres" id="1_q3b4c"] [ext_resource type="PackedScene" uid="uid://dvoin538iby54" path="res://src/MainMenu/MainMenu.tscn" id="2_2jbkh"] [ext_resource type="PackedScene" uid="uid://cnbfxjy1m6wja" path="res://src/OptionMenu/OptionsMenu.tscn" id="3_111lv"] -[ext_resource type="PackedScene" uid="uid://c8knthxkwj1uj" path="res://src/Credits/Credits.tscn" id="4_n0hoo"] +[ext_resource type="PackedScene" uid="uid://c8knthxkwj1uj" path="res://src/CreditsMenu/CreditsMenu.tscn" id="4_n0hoo"] [ext_resource type="PackedScene" uid="uid://crhkgngfnxf4y" path="res://src/LobbyMenu/LobbyMenu.tscn" id="4_nofk1"] [ext_resource type="PackedScene" uid="uid://cvl76duuym1wq" path="res://src/MusicConductor/MusicPlayer.tscn" id="6_lts1m"] @@ -30,7 +30,7 @@ layout_mode = 1 visible = false layout_mode = 1 -[node name="Credits" parent="." instance=ExtResource("4_n0hoo")] +[node name="CreditsMenu" parent="." instance=ExtResource("4_n0hoo")] visible = false layout_mode = 1 @@ -49,4 +49,4 @@ grow_horizontal = 0 [connection signal="options_button_pressed" from="MainMenu" to="." method="_on_main_menu_options_button_pressed"] [connection signal="back_button_pressed" from="OptionsMenu" to="." method="_on_options_menu_back_button_pressed"] [connection signal="back_button_pressed" from="LobbyMenu" to="." method="_on_lobby_menu_back_button_pressed"] -[connection signal="back_button_pressed" from="Credits" to="." method="_on_credits_back_button_pressed"] +[connection signal="back_button_pressed" from="CreditsMenu" to="." method="_on_credits_back_button_pressed"] -- cgit v1.2.3-56-ga3b1