diff --git a/Space4x/Assets/Scripts/MainMenuAndLobby/Lobby/NewGameDataManager.cs b/Space4x/Assets/Scripts/MainMenuAndLobby/Lobby/NewGameDataManager.cs index b891da6..5eb87d0 100644 --- a/Space4x/Assets/Scripts/MainMenuAndLobby/Lobby/NewGameDataManager.cs +++ b/Space4x/Assets/Scripts/MainMenuAndLobby/Lobby/NewGameDataManager.cs @@ -1,22 +1,107 @@ -using System.Collections; +/** + * @file + * + * @author Aaron Moser + * + * @package Assets.Scripts.MainMenuAndLobby.Lobby + */ using System.Collections.Generic; using UnityEngine; using TMPro; - using System; +/** + * @section DESCRIPTION + * + * Class is container for information, that needs to be transported from lobby to game scene. + * Number of solar systems for random map. + * Number of players for game. + * Colors players chose. + * + * @todo Type of map. + */ public class NewGameDataManager : MonoBehaviour { + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Public values + + /** + * Number of players playing the game. + */ public int NumberOfPlayers; + /** + * Number of solar systems to create. + */ public int NumberOfSolarSystems; + /** + * Color of each player. + */ public List PlayerColors = new List(); - // Static member value is shared over all objects of this class. - // Can be called by any other class by NewGameDataManager.Instance + /** + * Static member value is shared over all objects of this class. + * Can be called by any other class by NewGameDataManager.Instance to access the public attributes. + */ public static NewGameDataManager Instance; + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Private values + + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Public functions + + /** + * Sets public Number of players to value + 1. + * Special function for dropdown menu of lobby. + * Dropdown calls this function with Value = index item of dropdown. + * + * @param Value, number of players to set - 1. + */ + public void SetNumberOfPLayers(int Value) + { + if (Value >= 0 && Value < 8) + { + Instance.NumberOfPlayers = Value + 1; + } + } + + /** + * Sets public number of solar systems to iValue. + * + * @param iValue, number of solar systems to set to. + */ + public void SetNumberOfSolarSystems(int iValue) + { + if (iValue > NumberOfPlayers) + { + Instance.NumberOfSolarSystems = iValue; + } + } + + /** + * Adds new color to player color list. + * + * @todo maybe list not the best data structure here. + * + * @param oColor, color of new player to add. + */ + public void AddPlayerColor(Color oColor) + { + PlayerColors.Add(oColor); + } + + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Private functions + + /** + * Awake is called either when an active GameObject that contains the script is initialized when a Scene loads, + * or when a previously inactive GameObject is set to active, + * or after a GameObject created with Object.Instantiate is initialized. + * + * Inside, game object of this is set to dont destroy on load, to prevent it from destruction on scene change. + */ private void Awake() { if (Instance != null) @@ -28,25 +113,4 @@ public class NewGameDataManager : MonoBehaviour Instance = this; DontDestroyOnLoad(gameObject); } - - public void SetNumberOfPLayers(int Value) - { - if (Value >= 0 && Value < 8) - { - Instance.NumberOfPlayers = Value + 1; - } - } - - public void SetNumberOfSolarSystems(int iValue) - { - if (iValue > NumberOfPlayers) - { - Instance.NumberOfSolarSystems = iValue; - } - } - - public void AddPlayerColor(Color oColor) - { - PlayerColors.Add(oColor); - } } diff --git a/Space4x/Assets/Scripts/MainMenuAndLobby/Lobby/PlayerCountDropdownScript.cs b/Space4x/Assets/Scripts/MainMenuAndLobby/Lobby/PlayerCountDropdownScript.cs index d2528bc..e4e18d6 100644 --- a/Space4x/Assets/Scripts/MainMenuAndLobby/Lobby/PlayerCountDropdownScript.cs +++ b/Space4x/Assets/Scripts/MainMenuAndLobby/Lobby/PlayerCountDropdownScript.cs @@ -1,4 +1,11 @@ -using System.Collections; +/** + * @file + * + * @author Mohamad Kadou + * @author Aaron Moser + * + * @package Assets.Scripts.MainMenuAndLobby.Lobby + */ using System.Collections.Generic; using UnityEngine; @@ -6,51 +13,71 @@ using UnityEngine.UI; using TMPro; +/** + * @section DESCRIPTION + * + * Class contains functionality of dropdown at lobby. + */ public class PlayerCountDropdownScript : MonoBehaviour { + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Public values + + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Private values + + /** + * Reference to the dropdown. + */ TMP_Dropdown m_Dropdown; + + /** + * List of options for the dropdown. + */ List m_DropOptions = new List(); - // Start is called before the first frame update + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Public functions + + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Private functions + + /** + * Start is called before the first frame update + */ void Start() { m_Dropdown = GetComponent(); - InitDropDownOptions(1,4); + InitDropDownOptions(4); m_Dropdown.AddOptions(m_DropOptions); AddOnValueChangedEventListener(); } - // Update is called once per frame - void Update() + /** + * Initializes the dropdown menu with values between 1 and MaximumPlayerCount. + * + * @param MaximumPlayerCount, maximum amount of players. + */ + private void InitDropDownOptions(int MaximumPlayerCount) { - - } - - /// - /// Initializes the dropdown menu with values between MinimumPlayerCount and MaximumPlayerCount. - /// If MinimumPlayerCount is 1, 1 Player Option is added first and only even possibilities. - /// - /// - /// - private void InitDropDownOptions(int MinimumPlayerCount, int MaximumPlayerCount) - { - for (int i = MinimumPlayerCount; i < (MaximumPlayerCount + 1);) + for (int i = 1; i < (MaximumPlayerCount + 1); i++) { if (i == 1) { m_DropOptions.Add(i + " Player"); - i++; } else { m_DropOptions.Add(i + " Players"); - i += 2; } } } + /** + * Adds a new event listener to the dropdown menu, called from @see Start(). + */ private void AddOnValueChangedEventListener() { m_Dropdown.onValueChanged.AddListener(delegate { @@ -58,6 +85,12 @@ public class PlayerCountDropdownScript : MonoBehaviour }); } + /** + * If the dropdown item selected changes, set number of players, to the value of the index of the item at dropdown selected. + * Example: "1 Player" is at index 0, if selected change.value is 0. + * + * @param change, dropdown reference. + */ private void DropdownValueChanged(TMP_Dropdown change) { NewGameDataManager.Instance.SetNumberOfPLayers(change.value);