From e5ebf5bd5f0c222e9c29ef7b4a987317672fc9d5 Mon Sep 17 00:00:00 2001 From: rsxri Date: Wed, 23 Apr 2025 15:56:10 +0100 Subject: [PATCH] -feat: implement player type and color customisation prior to starting game --- MB_FYP/scenes/main_menu.tscn | 54 ++++++++++++++++---- MB_FYP/scenes/ship_choice.tscn | 91 ++++++++++++++++++++++++++++++++++ MB_FYP/script/main_menu.cs | 14 ++++-- MB_FYP/script/player.cs | 5 +- MB_FYP/script/player_config.cs | 5 ++ MB_FYP/script/ship_choice.cs | 24 +++++++++ 6 files changed, 178 insertions(+), 15 deletions(-) create mode 100644 MB_FYP/scenes/ship_choice.tscn create mode 100644 MB_FYP/script/player_config.cs create mode 100644 MB_FYP/script/ship_choice.cs diff --git a/MB_FYP/scenes/main_menu.tscn b/MB_FYP/scenes/main_menu.tscn index 5f9fad9..8713d0e 100644 --- a/MB_FYP/scenes/main_menu.tscn +++ b/MB_FYP/scenes/main_menu.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=3 format=3 uid="uid://bh3heupvlc1ok"] +[gd_scene load_steps=4 format=3 uid="uid://bh3heupvlc1ok"] [ext_resource type="Script" path="res://script/main_menu.cs" id="1_wxwq5"] [ext_resource type="PackedScene" uid="uid://01tjlnox4crb" path="res://scenes/input_menu.tscn" id="2_2h615"] +[ext_resource type="PackedScene" uid="uid://fwvsy2g3lj4f" path="res://scenes/ship_choice.tscn" id="3_the1x"] [node name="MainMenu" type="Control"] layout_mode = 3 @@ -10,24 +11,42 @@ offset_right = 40.0 offset_bottom = 40.0 script = ExtResource("1_wxwq5") -[node name="Layout" type="VBoxContainer" parent="."] -layout_mode = 0 -offset_right = 40.0 -offset_bottom = 40.0 +[node name="CanvasLayer" type="CanvasLayer" parent="."] +layer = -2 -[node name="StartButton" type="Button" parent="Layout"] +[node name="ColorRect" type="ColorRect" parent="CanvasLayer"] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +color = Color(0.143949, 0.135649, 0.124581, 1) + +[node name="CenterContainer" type="CenterContainer" parent="CanvasLayer"] +anchors_preset = 5 +anchor_left = 0.5 +anchor_right = 0.5 +offset_left = -48.0 +offset_right = 48.0 +offset_bottom = 101.0 +grow_horizontal = 2 + +[node name="Layout" type="VBoxContainer" parent="CanvasLayer/CenterContainer"] layout_mode = 2 -text = "Start Game + +[node name="ExitButton" type="Button" parent="CanvasLayer/CenterContainer/Layout"] +layout_mode = 2 +text = "Exit Game " -[node name="InputButton" type="Button" parent="Layout"] +[node name="InputButton" type="Button" parent="CanvasLayer/CenterContainer/Layout"] layout_mode = 2 text = "Inputs " -[node name="ExitButton" type="Button" parent="Layout"] +[node name="StartButton" type="Button" parent="CanvasLayer/CenterContainer/Layout"] layout_mode = 2 -text = "Exit Game +text = "Start Game " [node name="InputMenu" parent="." instance=ExtResource("2_2h615")] @@ -44,3 +63,18 @@ offset_right = 1170.0 offset_bottom = 770.0 grow_horizontal = 1 grow_vertical = 1 + +[node name="ShipChoice" parent="." instance=ExtResource("3_the1x")] +visible = false +layout_mode = 0 +anchors_preset = 0 +anchor_left = 0.0 +anchor_top = 0.0 +anchor_right = 0.0 +anchor_bottom = 0.0 +offset_left = 770.0 +offset_top = 270.0 +offset_right = 1170.0 +offset_bottom = 470.0 +grow_horizontal = 1 +grow_vertical = 1 diff --git a/MB_FYP/scenes/ship_choice.tscn b/MB_FYP/scenes/ship_choice.tscn new file mode 100644 index 0000000..ad2cbce --- /dev/null +++ b/MB_FYP/scenes/ship_choice.tscn @@ -0,0 +1,91 @@ +[gd_scene load_steps=8 format=3 uid="uid://fwvsy2g3lj4f"] + +[ext_resource type="Script" path="res://script/ship_choice.cs" id="1_bn5x2"] +[ext_resource type="FontFile" uid="uid://be6xxaq8drt5q" path="res://assets/Fonts/Kenney Pixel Square.ttf" id="2_kov8d"] +[ext_resource type="FontFile" uid="uid://dtpvg4lmre10g" path="res://assets/Fonts/Kenney Future Narrow.ttf" id="3_c045h"] + +[sub_resource type="LabelSettings" id="LabelSettings_6mqtv"] +font = ExtResource("2_kov8d") +font_size = 28 + +[sub_resource type="Theme" id="Theme_siirn"] +default_font = ExtResource("3_c045h") + +[sub_resource type="Theme" id="Theme_gbhoc"] +default_font = ExtResource("3_c045h") + +[sub_resource type="Theme" id="Theme_eci35"] +default_font = ExtResource("3_c045h") + +[node name="ShipChoice" type="CenterContainer"] +process_mode = 3 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -200.0 +offset_top = -100.0 +offset_right = 200.0 +offset_bottom = 100.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_bn5x2") + +[node name="ColorRect" type="ColorRect" parent="."] +custom_minimum_size = Vector2(400, 200) +layout_mode = 2 +color = Color(0.231373, 0.219608, 0.203922, 1) + +[node name="VBox" type="VBoxContainer" parent="."] +layout_mode = 2 + +[node name="Label" type="Label" parent="VBox"] +layout_mode = 2 +text = "Choose a ship" +label_settings = SubResource("LabelSettings_6mqtv") +horizontal_alignment = 1 + +[node name="VSeparator" type="VSeparator" parent="VBox"] +visibility_layer = 0 +custom_minimum_size = Vector2(0, 30) +layout_mode = 2 + +[node name="HBox" type="HBoxContainer" parent="VBox"] +layout_mode = 2 + +[node name="TypeOption" type="OptionButton" parent="VBox/HBox"] +custom_minimum_size = Vector2(100, 0) +layout_mode = 2 +theme = SubResource("Theme_siirn") +item_count = 3 +selected = 2 +popup/item_0/text = "Fighter" +popup/item_0/id = 0 +popup/item_1/text = "Interceptor" +popup/item_1/id = 1 +popup/item_2/text = "Guardian" +popup/item_2/id = 2 + +[node name="ColorOption" type="OptionButton" parent="VBox/HBox"] +custom_minimum_size = Vector2(100, 35) +layout_mode = 2 +theme = SubResource("Theme_gbhoc") +item_count = 3 +selected = 0 +popup/item_0/text = "Red" +popup/item_0/id = 0 +popup/item_1/text = "Green" +popup/item_1/id = 1 +popup/item_2/text = "Blue" +popup/item_2/id = 2 + +[node name="VSeparator2" type="VSeparator" parent="VBox"] +visibility_layer = 0 +custom_minimum_size = Vector2(0, 30) +layout_mode = 2 + +[node name="ConfirmButton" type="Button" parent="VBox"] +layout_mode = 2 +theme = SubResource("Theme_eci35") +text = "Confirm" diff --git a/MB_FYP/script/main_menu.cs b/MB_FYP/script/main_menu.cs index 127a21f..4adff36 100644 --- a/MB_FYP/script/main_menu.cs +++ b/MB_FYP/script/main_menu.cs @@ -5,20 +5,26 @@ public partial class main_menu : Control { // Called when the node enters the scene tree for the first time. private input_menu _inputMenu; + private ship_choice _shipChoice; + private VBoxContainer _layout; public override void _Ready() { _inputMenu = GetNode("InputMenu"); + _shipChoice = GetNode("ShipChoice"); + _layout = GetNode("CanvasLayer/CenterContainer/Layout"); //Connecting Buttons - GetNode