/// <summary> /// Fills the load game GUI screen from the data layer /// </summary> public void ShowLoadGame() { // load the character list from the data layer AllCharacters = GlobalFuncs.TheDatabase().GetCharacterSlotList(); // build string array from the names List <string> AllCharNames = new List <string>(); foreach (SimpleDataPair sdp in AllCharacters) { string[] sdpSplit = sdp.Display.Split('~'); AllCharNames.Add(sdpSplit[0] + " (" + sdpSplit[1].Split('T')[0] + ")"); } // fill the dropdown CharacterDropDown.ClearOptions(); CharacterDropDown.AddOptions(AllCharNames); // fill the save game list if (AllCharacters.Count > 0) { ChangeCharacter(CurrentCharacter); } // show the load game window FirstWindow.gameObject.SetActive(false); LoadGameWindow.SetActive(true); }
/// <summary> /// Initialise the game control menu. /// </summary> /// <remarks> /// Sets up the unity don't destroy and locks the main menu open when in the lobby scene. /// </remarks> void Start() { // input handling inputModule = FindObjectOfType <StandaloneInputModule>(); // ensure this script is moved between scenes if (dontDestroyOnLoad) { DontDestroyOnLoad(gameObject); } // force main menu open when scene is the lobby if (!isNotLobby) { // fill dropdown lists on new character AxisDropDown.ClearOptions(); AxisDropDown.AddOptions(new List <string>(Enum.GetNames(typeof(BaseAxis)))); AlignDropDown.ClearOptions(); AlignDropDown.AddOptions(new List <string>(Enum.GetNames(typeof(BaseAlignment)))); RaceDropDown.ClearOptions(); RaceDropDown.AddOptions(new List <string>(Enum.GetNames(typeof(BaseRace)))); ClassDropDown.ClearOptions(); ClassDropDown.AddOptions(new List <string>(Enum.GetNames(typeof(BaseClass)))); ValidationLabel.text = ""; // show the continue button and cache the most recent save game GlobalFuncs.TheDatabase().FindMostRecentSaveGameID(ref LatestSaveSlotID, ref LatestSaveGameID); ContinueButton.SetActive(LatestSaveGameID > 0 && LatestSaveSlotID > 0); LoadGameButton.SetActive(LatestSaveGameID > 0 && LatestSaveSlotID > 0); // lock the main menu open StartCoroutine(forceMenuOpen()); } }
/// <summary> /// Loads the selected save game scene from when selected in the GUI. /// </summary> /// <param name="SaveGameID">ID of the save game to load from the data layer.</param> public void LoadGame(int SaveGameID) { // clear player state GlobalFuncs.TheDatabase().ClearInventoryAndHUD(); // find the leveling system if (!LevelingSystem) { GameObject player = GlobalFuncs.FindPlayerInstance(); if (player) { LevelingSystem = player.GetComponent <CharacterBase>(); } else { if (GlobalFuncs.DEBUGGING_MESSAGES) { Debug.Log("Unable to find player"); } } } if (!LevelingSystem) { // not found? if (GlobalFuncs.DEBUGGING_MESSAGES) { Debug.Log("Levelling system not found on player"); } } else { // all good // load character from the data layer LevelingSystem.SaveSlotID = SelectedSlotID; LevelingSystem.LastSaveGameID = SaveGameID; string SceneName = GlobalFuncs.TheDatabase().LoadPlayerState(ref LevelingSystem, SaveGameID); // close the menu and load the scene if (SceneName != "") { #if !VANILLA Inventory.gameObject.SetActive(true); #endif LoadGameWindow.SetActive(false); FirstWindow.gameObject.SetActive(false); Fader.BeginFade(1); isOpen = false; lockInput = false; Fader.LoadSceneAsync(SceneName); // start the load with progress bar } else { if (GlobalFuncs.DEBUGGING_MESSAGES) { Debug.Log("Failed to load save game ID " + SaveGameID); } } } }
/// <summary> /// Save the current scene/character state to the data layer /// </summary> public void SaveGame() { if (!LevelingSystem) { GameObject player = GlobalFuncs.FindPlayerInstance(); if (player) { LevelingSystem = player.GetComponent <CharacterBase>(); } else { if (GlobalFuncs.DEBUGGING_MESSAGES) { Debug.Log("Unable to find player"); } } } if (!LevelingSystem) { // not found? if (GlobalFuncs.DEBUGGING_MESSAGES) { Debug.Log("Leveling system not found on player"); } } else { // all good // save the game LevelingSystem.LastSaveGameID = GlobalFuncs.TheDatabase().SavePlayerState(ref LevelingSystem, SceneManager.GetActiveScene().name, -1); LatestSaveGameID = LevelingSystem.LastSaveGameID; // hide the menu and enable time foreach (GameObject ui in UserInterface) { ui.SetActive(true); } #if !VANILLA Inventory.gameObject.SetActive(true); #endif FirstWindow.gameObject.SetActive(false); isOpen = false; lockInput = false; Time.timeScale = 1f; // confirm save to user SaveGameMessage.CrossFadeAlpha(1f, 0.01f, true); SaveGameMessage.text = "Save Complete.."; SaveGameMessage.CrossFadeAlpha(0f, 3f, true); } }
/// <summary> /// Updates the list of save games from the character drop down selection /// </summary> /// <param name="SelectedIndex">Index of the character that has been selected.</param> public void ChangeCharacter(int SelectedIndex) { CurrentCharacter = SelectedIndex; // remove previous buttons if (SaveGameCreatedButtonList.Count > 0) { foreach (GameObject child in SaveGameCreatedButtonList) { DestroyImmediate(child); } } // load all save games for this character from the datalayer SaveGameCreatedButtonList = new List <GameObject>(); SelectedSlotID = AllCharacters[SelectedIndex].Value; //SaveGamesForSelectedCharacter = GlobalFuncs.TheDatabase().GetShortList("vSaveGames", "ID", new string[] { "CreatedOn", "Level", "XP", "SceneName" }, "CreatedOn", true, "SlotID", SelectedSlotID.ToString(), false, "^"); SaveGamesForSelectedCharacter = GlobalFuncs.TheDatabase().GetSaveGameListForSlot(SelectedSlotID); // clone a button from the master for each save game foreach (SimpleDataPair sdp in SaveGamesForSelectedCharacter) { GameObject LoadButton = Instantiate(LoadGameScrollItem); LoadButton.transform.SetParent(LoadGameScrollable.transform); Text LoadButtonText = LoadButton.GetComponentInChildren <Text>(); string[] sdpSplit = sdp.Display.Split('~'); LoadButtonText.text = sdpSplit[0].Replace('T', ' ') + " (Lvl " + sdpSplit[1] + " XP " + sdpSplit[2] + ") " + sdpSplit[3]; Button LoadActualButton = LoadButton.GetComponent <Button>(); LoadActualButton.onClick.AddListener(() => { LoadGame(sdp.Value); }); LoadButton.SetActive(true); SaveGameCreatedButtonList.Add(LoadButton); } }
/// <summary> /// Occurs when the new game menu option is clicked. /// </summary> public void NewGame() { if (CharacterNameTextBox.text.Length > 2) { ValidationLabel.text = ""; if (FirstSceneName.Length > 0) { // find the leveling system if (!LevelingSystem) { GameObject player = GlobalFuncs.FindPlayerInstance(); if (player) { LevelingSystem = player.GetComponent <CharacterBase>(); } else { if (GlobalFuncs.DEBUGGING_MESSAGES) { Debug.Log("Unable to find player"); } } } if (!LevelingSystem) { // not found? if (GlobalFuncs.DEBUGGING_MESSAGES) { Debug.Log("Leveling system not found on player"); } } else { // all good // set the leveling system initial values LevelingSystem.CurrentLevel = 1; LevelingSystem.Name = CharacterNameTextBox.text; LevelingSystem.CurrentAxis = (BaseAxis)AxisDropDown.value; LevelingSystem.CurrentAlignment = (BaseAlignment)AlignDropDown.value; LevelingSystem.CurrentRace = (BaseRace)RaceDropDown.value; LevelingSystem.CurrentClass = (BaseClass)ClassDropDown.value; LevelingSystem.ResetToDefaults(); // reset character to the selection LevelingSystem.reCalcCore(true); // recalc the core stats, max out health etc CharacterNameTextBox.text = ""; // clear for mid game create new character // create a new slot and first save game in the data layer LevelingSystem.SaveSlotID = 0; LevelingSystem.LastSaveGameID = GlobalFuncs.TheDatabase().SavePlayerState(ref LevelingSystem, FirstSceneName, -1); GlobalFuncs.TheDatabase().ClearInventoryAndHUD(); // close the menu and load the scene #if !VANILLA Inventory.gameObject.SetActive(true); #endif NewCharacterWindow.SetActive(false); Fader.BeginFade(1); isOpen = false; lockInput = false; Fader.LoadSceneAsync(FirstSceneName); // start the load with progress bar } } else { if (GlobalFuncs.DEBUGGING_MESSAGES) { Debug.Log("First scene name is not specified"); } } } else { ValidationLabel.text = "Missing Character Name.."; } }
/// <summary> /// Save the game and load the next scene when collider trigger entered by the player. /// </summary> /// <param name="other">Collider that has entered the trigger.</param> void OnTriggerEnter(Collider other) { if (other.gameObject.tag.Equals("Player")) { // only player can trigger if (SceneToLoad != "") { // fail safe // spawn all if (SpawnOnEnter.Count > 0) { StartCoroutine(GlobalFuncs.SpawnAllDelayed(SpawnOnEnter, SpawnDelay, NoneSequentialSpawns, transform, null, 0, false, SpawnTarget.Any)); // trigger all spawns the the array } // save to data layer LevelingSystem = other.gameObject.GetComponent <CharacterBase>(); if (!LevelingSystem) { // not found? if (GlobalFuncs.DEBUGGING_MESSAGES) { Debug.Log("Leveling system not found on player"); } } else { // all good // save the game LevelingSystem.LastSaveGameID = GlobalFuncs.TheDatabase().SavePlayerState(ref LevelingSystem, SceneToLoad, -1); MainMenu MainMenuSystem = GlobalFuncs.TheMainMenu(); if (MainMenuSystem) { MainMenuSystem.LatestSaveGameID = LevelingSystem.LastSaveGameID; // confirm save to user MainMenuSystem.SaveGameMessage.CrossFadeAlpha(1f, 0.01f, true); MainMenuSystem.SaveGameMessage.text = "Save Complete.."; MainMenuSystem.SaveGameMessage.CrossFadeAlpha(0f, 3f, true); // load the next scene MainMenu_FadingLoad Fader = MainMenuSystem.gameObject.GetComponent <MainMenu_FadingLoad>(); if (Fader) { Fader.BeginFade(1); Fader.LoadSceneAsync(SceneToLoad, LoadDelay); // start the load with progress bar } else { if (GlobalFuncs.DEBUGGING_MESSAGES) { Debug.Log("Main menu system NOT found in scene"); } } } else { if (GlobalFuncs.DEBUGGING_MESSAGES) { Debug.Log("Main menu system NOT found in scene"); } } } } else { if (GlobalFuncs.DEBUGGING_MESSAGES) { Debug.Log("Scene to load is NOT set"); } } } }
/// <summary> /// Inspector custom GUI override /// </summary> public override void OnInspectorGUI() { #if !VANILLA oldSkin = GUI.skin; if (skin) { GUI.skin = skin; } #endif GUILayout.BeginVertical("CHARACTER ATTRIBUTES", "window"); #if !VANILLA GUILayout.Label(m_Logo, GUILayout.MaxHeight(25)); #endif // grab the underlying class instance CharacterBase cc = (CharacterBase)target; // show values + modifier bOpenCloseWindow = GUILayout.Toggle(bOpenCloseWindow, bOpenCloseWindow ? "Close" : "Open", EditorStyles.toolbarButton); if (bOpenCloseWindow) { // reset to defaults GUILayout.BeginHorizontal(); if (GUILayout.Button("Reset to Defaults", GUILayout.ExpandWidth(true))) { cc.ConditionsRoot = cc.transform.Find("Conditions"); cc.ResetToDefaults(); } GUILayout.EndHorizontal(); // feed stats into the animator GUILayout.BeginHorizontal(); #if !VANILLA GUI.skin = oldSkin; #endif GUILayout.Label("Send Stats", GUILayout.Width(75)); cc.FeedStatsToAnimator = GUILayout.Toggle(cc.FeedStatsToAnimator, " to the Animator", GUILayout.ExpandWidth(true)); #if !VANILLA GUI.skin = skin; #endif GUILayout.EndHorizontal(); // increase by GUILayout.BeginHorizontal(); #if !VANILLA GUI.skin = oldSkin; #endif GUILayout.Label("Increase By", GUILayout.Width(75)); CurrentIncrease = (BaseIncrease)EditorGUILayout.EnumPopup(CurrentIncrease, GUILayout.ExpandWidth(true)); #if !VANILLA GUI.skin = skin; #endif GUILayout.EndHorizontal(); // core foldout GUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.BeginHorizontal(); #if !VANILLA GUI.skin = oldSkin; #endif bShowCore = GUILayout.Toggle(bShowCore, "Core Attributes", "Foldout", GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); if (bShowCore) { GUICoreDisplay(ref cc); } #if !VANILLA GUI.skin = skin; #endif GUILayout.EndVertical(); // collectables foldout GUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.BeginHorizontal(); #if !VANILLA GUI.skin = oldSkin; #endif bShowCollectables = GUILayout.Toggle(bShowCollectables, "Collectables", "Foldout", GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); if (bShowCollectables) { for (int i = 0; i < cc.Collectables.Count; i++) { // name GUILayout.BeginHorizontal(); GUILayout.Label(cc.Collectables[i].Type.ToString(), GUILayout.Width(75)); // allow value modification GUIGenericValueDisplay(ref cc, ref cc.Collectables[i].Value, 0, -1); // current value GUI.skin.label.alignment = TextAnchor.UpperRight; GUILayout.Label(cc.Collectables[i].Value.ToString("#,##0"), GUILayout.ExpandWidth(true)); GUI.skin.label.alignment = TextAnchor.UpperLeft; GUILayout.EndHorizontal(); // only the player sees the collectable prefabs config as are global if (cc.gameObject.tag == "Player") { // temp initialise for our existing scenes if (cc.Collectables[i].Spawns == null) { cc.Collectables[i].Spawns = new List <CollectablePrefab>(); } // remove b4 release // list all prefabs for (int s = 0; s < cc.Collectables[i].Spawns.Count; s++) { GUILayout.BeginHorizontal(); GUILayout.Space(10); // prefab GUILayout.Label("Prefab", GUILayout.Width(65)); cc.Collectables[i].Spawns[s].Prefab = EditorGUILayout.ObjectField(cc.Collectables[i].Spawns[s].Prefab, typeof(GameObject), false) as GameObject; // amount GUILayout.Label(" = ", GUILayout.Width(20)); cc.Collectables[i].Spawns[s].Amount = (int)EditorGUILayout.FloatField(cc.Collectables[i].Spawns[s].Amount, GUILayout.Width(35)); if (cc.Collectables[i].Spawns[s].Amount < 1) { cc.Collectables[i].Spawns[s].Amount = 1; } // remove if (GUILayout.Button("X", GUILayout.Width(30))) { cc.Collectables[i].Spawns.RemoveAt(s); break; // drop out till next editor frame } GUILayout.EndHorizontal(); } // add more GUILayout.BeginHorizontal(); GUILayout.Space(75); if (GUILayout.Button("Add Prefab/Value", GUILayout.ExpandWidth(true))) { cc.Collectables[i].Spawns.Add(new CollectablePrefab()); } GUILayout.EndHorizontal(); } } } #if !VANILLA GUI.skin = skin; #endif GUILayout.EndVertical(); // skill points foldout if (cc.Skills != null) { GUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.BeginHorizontal(); #if !VANILLA GUI.skin = oldSkin; #endif bShowSkillPoints = GUILayout.Toggle(bShowSkillPoints, "Skill Points", "Foldout", GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); if (bShowSkillPoints) { // available skill points GUILayout.BeginHorizontal(); GUILayout.Label("Unspent", GUILayout.Width(75)); if (cc.UnspentSkillPoints > 0) { if (GUILayout.Button("Seq", GUILayout.Width(64))) { cc.DistributePoints(false); } if (GUILayout.Button("Rnd", GUILayout.Width(64))) { cc.DistributePoints(true); } } GUILayout.Label(cc.UnspentSkillPoints.ToString(), GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); // skill point list for (int i = 0; i < cc.Skills.Count; i++) { GUILayout.BeginHorizontal(); GUISkillPointDisplay(ref cc, ref i); GUILayout.EndHorizontal(); } } #if !VANILLA GUI.skin = skin; #endif GUILayout.EndVertical(); } // resistances foldout if (cc.Resist != null) { GUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.BeginHorizontal(); #if !VANILLA GUI.skin = oldSkin; #endif bShowResistances = GUILayout.Toggle(bShowResistances, "Resistances", "Foldout", GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); if (bShowResistances) { for (int i = 0; i < cc.Resist.Count; i++) { // attribute name GUILayout.BeginHorizontal(); GUILayout.Label(cc.Resist[i].Resist.ToString(), GUILayout.Width(75)); // allow value modification GUIGenericValueDisplay(ref cc, ref cc.Resist[i].Value, 0, 100); // current value GUI.skin.label.alignment = TextAnchor.UpperRight; GUILayout.Label("(" + (cc.ResistModTotals[i].Value > 0 ? "+" : "") + cc.ResistModTotals[i].Value.ToString() + ") " + cc.Resist[i].Value.ToString() + '%', GUILayout.ExpandWidth(true)); GUI.skin.label.alignment = TextAnchor.UpperLeft; GUILayout.EndHorizontal(); } } #if !VANILLA GUI.skin = skin; #endif GUILayout.EndVertical(); } // conditions foldout if (cc.Conditions != null) { GUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.BeginHorizontal(); #if !VANILLA GUI.skin = oldSkin; #endif bShowConditions = GUILayout.Toggle(bShowConditions, "Elemental Conditions", "Foldout", GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); if (bShowConditions) { for (int i = 0; i < cc.Conditions.Count; i++) { if (cc.Conditions[i].Type != BaseDamage.Physical) // ignore physical { // attribute name GUILayout.BeginHorizontal(); GUILayout.Label(cc.Conditions[i].Type.ToString(), GUILayout.Width(75)); // display //GUILayout.Label("Display", GUILayout.Width(65)); cc.Conditions[i].Display = EditorGUILayout.ObjectField(cc.Conditions[i].Display, typeof(GameObject), false) as GameObject; GUILayout.EndHorizontal(); } } } #if !VANILLA GUI.skin = skin; #endif GUILayout.EndVertical(); } // data layer helper functions if (cc.gameObject.tag == "Player") { bOpenDataHelpers = GUILayout.Toggle(bOpenDataHelpers, bOpenDataHelpers ? "Close Data Layer Helpers" : "Open Data Layer Helpers", EditorStyles.toolbarButton); if (bOpenDataHelpers) { // attempt find data layer if (!GlobalFuncs.TheDatabase()) { GUILayout.Label("Data layer NOT found..", GUILayout.ExpandWidth(true)); GUILayout.Label("Add a data layer connector..", GUILayout.ExpandWidth(true)); GUILayout.Label("E.g. CharacterDataSQLLite!", GUILayout.ExpandWidth(true)); } else { // reset to defaults GUILayout.BeginHorizontal(); if (GUILayout.Button("Validate DB", GUILayout.ExpandWidth(true))) { GlobalFuncs.TheDatabase().ValidateDatabase(false); } if (GUILayout.Button("Wipe DB", GUILayout.ExpandWidth(true))) { GlobalFuncs.TheDatabase().ValidateDatabase(true); SaveSlots = null; // force reload SaveGames = null; // of slot/save shortlists cc.SaveSlotID = 0; cc.LastSaveGameID = 0; } GUILayout.EndHorizontal(); //// slot choice //GUILayout.BeginHorizontal(); //GUILayout.Label("Save Slot", GUILayout.Width(60)); //if (SaveSlots == null) { // SaveSlots = GlobalFuncs.TheDatabase().GetShortList("SaveSlots", "ID", new string[] { "CharacterName", "CreatedOn" }, "CreatedOn", true, "", "", true, " :: "); //} //iNewValue = GlobalFuncs.TheDatabase().SimpleDataGUIPopup(ref SaveSlots, cc.SaveSlotID, GUILayout.ExpandWidth(true)); //if (cc.SaveSlotID != iNewValue) { // cc.SaveSlotID = iNewValue; // SaveGames = null; // force reload of dependant save game list //} //// save choice dependant upon slot //GUILayout.Label("Save Game", GUILayout.Width(75)); //if (SaveGames == null) { // SaveGames = GlobalFuncs.TheDatabase().GetShortList("SaveGames", "ID", new string[] { "CreatedOn" }, "CreatedOn", true, "SlotID", cc.SaveSlotID.ToString(), true, " :: "); //} //cc.LastSaveGameID = GlobalFuncs.TheDatabase().SimpleDataGUIPopup(ref SaveGames, cc.LastSaveGameID, GUILayout.ExpandWidth(true)); //GUILayout.EndHorizontal(); //GUILayout.BeginHorizontal(); //if (cc.LastSaveGameID > 0) { // if (GUILayout.Button("Load", GUILayout.ExpandWidth(true))) { // GlobalFuncs.TheDatabase().LoadPlayerState(ref cc, false, cc.LastSaveGameID); // } //} //if (GUILayout.Button("Save", GUILayout.ExpandWidth(true))) { // cc.LastSaveGameID = GlobalFuncs.TheDatabase().SavePlayerState(ref cc, SceneManager.GetActiveScene().name, (cc.LastSaveGameID > 0 ? cc.LastSaveGameID : - 1)); // SaveSlots = null; // force reload // SaveGames = null; // of slot/save shortlists //} //GUILayout.EndHorizontal(); } } } } GUILayout.EndVertical(); #if !VANILLA GUI.skin = oldSkin; #endif }