-feat: implement player type and color customisation prior to starting game
This commit is contained in:
parent
d008a3d32c
commit
e5ebf5bd5f
|
|
@ -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
|
||||
|
|
|
|||
91
MB_FYP/scenes/ship_choice.tscn
Normal file
91
MB_FYP/scenes/ship_choice.tscn
Normal file
|
|
@ -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"
|
||||
|
|
@ -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<input_menu>("InputMenu");
|
||||
_shipChoice = GetNode<ship_choice>("ShipChoice");
|
||||
_layout = GetNode<VBoxContainer>("CanvasLayer/CenterContainer/Layout");
|
||||
|
||||
//Connecting Buttons
|
||||
GetNode<Button>("Layout/StartButton").Pressed += OnStartButtonPressed;
|
||||
GetNode<Button>("Layout/ExitButton").Pressed += OnExitButtonPressed;
|
||||
GetNode<Button>("Layout/InputButton").Pressed += OnInputButtonPressed;
|
||||
GetNode<Button>("CanvasLayer/CenterContainer/Layout/StartButton").Pressed += OnStartButtonPressed;
|
||||
GetNode<Button>("CanvasLayer/CenterContainer/Layout/ExitButton").Pressed += OnExitButtonPressed;
|
||||
GetNode<Button>("CanvasLayer/CenterContainer/Layout/InputButton").Pressed += OnInputButtonPressed;
|
||||
|
||||
}
|
||||
|
||||
private void OnStartButtonPressed()
|
||||
{
|
||||
GetTree().ChangeSceneToFile("res://scenes/game.tscn");
|
||||
_layout.Hide();
|
||||
_shipChoice.Show();
|
||||
}
|
||||
|
||||
private void OnExitButtonPressed()
|
||||
|
|
|
|||
|
|
@ -103,6 +103,9 @@ public partial class player : ship // Inherits from base ship class
|
|||
|
||||
public override void _Ready()
|
||||
{
|
||||
Type = player_config.SelectedType;
|
||||
Color = player_config.SelectedColor;
|
||||
|
||||
SetupVisual();
|
||||
//GD.Print(Faction);
|
||||
|
||||
|
|
|
|||
5
MB_FYP/script/player_config.cs
Normal file
5
MB_FYP/script/player_config.cs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
public static class player_config // simple class for customising player type and color
|
||||
{
|
||||
public static player.ShipType SelectedType = ship.ShipType.FIGHTER;
|
||||
public static player.ShipColor SelectedColor = player.ShipColor.BLUE;
|
||||
}
|
||||
24
MB_FYP/script/ship_choice.cs
Normal file
24
MB_FYP/script/ship_choice.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class ship_choice : CenterContainer
|
||||
{
|
||||
public override void _Ready()
|
||||
{
|
||||
GetNode<Button>("VBox/ConfirmButton").Pressed += OnConfirmButtonPressed;
|
||||
}
|
||||
|
||||
private void OnConfirmButtonPressed()
|
||||
{
|
||||
var colorIndex = GetNode<OptionButton>("VBox/HBox/ColorOption").Selected;
|
||||
var typeIndex = GetNode<OptionButton>("VBox/HBox/TypeOption").Selected;
|
||||
|
||||
player_config.SelectedColor = (player.ShipColor)colorIndex;
|
||||
player_config.SelectedType = (ship.ShipType)typeIndex;
|
||||
|
||||
//GD.Print("attempting start");
|
||||
|
||||
GetTree().ChangeSceneToFile("res://scenes/game.tscn");
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue