Example #1
0
        /// <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
        }