Esempio n. 1
0
        void Paste(object obj)
        {
            int               i    = (int)obj;
            NewItem           itm  = ItemEditor.CopiedItem;
            GearSlotAttribute attr = itm.GetAttribute <GearSlotAttribute>();

            if (attr == null)
            {
                Debug.LogWarning("This Item lack GearSlot Attribute and cannot be added to the Gear slot");
            }
            else
            {
                WeaponAttribute weaponAttr   = itm.GetAttribute <WeaponAttribute>();
                bool            weaponCancel = false;
                if (weaponAttr)
                {
                    if (!stats.CanEquipWeapons.Contains((int)weaponAttr.WeaponType))
                    {
                        weaponCancel = true;
                    }
                }
                //Add to a slot
                if (attr.PossibleSlots[i] && !weaponCancel)
                {
                    Undo.RecordObject(UndoObj, "Modify Stats");
                    stats.Gear.Equip(itm, i, null);
                }
                else
                {
                    Debug.LogWarning("This items GearSlot attribute does not allow this slot!");
                }
            }
            RefreshDictionary();
        }
Esempio n. 2
0
        private void OpenMiniMenuInventory(NewItem itm)
        {
            List <ButtonArgument> buttonArguments = new List <ButtonArgument>();

            onCancelActions.Remove(DropDownMenu.Hide);
            onCancelActions.Add(DropDownMenu.Hide);
            if (itm.GetAttribute <UseAttribute>() != null)
            {
                ButtonArgument UseArgument = new ButtonArgument("Use");


                UseArgument.onClickCallback.Add(() => DropDownMenu.Hide());
                UseArgument.onClickCallback.Add(() => itm.GetAttribute <UseAttribute>().Use(TurnManager.currentCharacter));

                if (itm.GetAttribute <UseAttribute>().destoryOnUse)
                {
                    UseArgument.onClickCallback.Add(() => inventory.DepleteItem(itm));
                }

                UseArgument.onClickCallback.Add(() => GenerateUI());
                UseArgument.onClickCallback.Add(() => UpdateStatLabels());


                buttonArguments.Add(UseArgument);
            }

            if (itm.GetAttribute <GearSlotAttribute>() != null)
            {
                ButtonArgument GearArgument = new ButtonArgument("Equip");

                WeaponAttribute weaponAttr = itm.GetAttribute <WeaponAttribute>();
                if (weaponAttr)
                {
                    GearArgument.Interactable = TurnManager.currentCharacter.stats.CanEquipWeapons.Contains((int)weaponAttr.WeaponType) ? true : false;
                }

                GearArgument.onClickCallback.Add(() => DropDownMenu.Hide());
                GearArgument.onClickCallback.Add(() => gear.Equip(itm, inventory));
                GearArgument.onClickCallback.Add(() => UpdateStatLabels());
                GearArgument.onClickCallback.Add(() => GenerateUI());

                buttonArguments.Add(GearArgument);
            }


            ButtonArgument DropArgument = new ButtonArgument("Drop");

            DropArgument.onClickCallback.Add(() => DropDownMenu.Hide());
            DropArgument.onClickCallback.Add(() => inventory.DepleteItem(itm));
            DropArgument.onClickCallback.Add(() => GenerateUI());

            buttonArguments.Add(DropArgument);


            DropDownMenu.Initialize(buttonArguments, null);
        }
Esempio n. 3
0
        public void BuildWeaponUI(GameObject container, WeaponAttribute attr)
        {
            HorizontalLayoutGroup g = BuildLine(container, 20);

            CreateText(GetStyle("WeaponStatLabel"), g.gameObject, "Type");
            CreateText(GetStyle("WeaponStatLabelRight"), g.gameObject, attr.WeaponType.ToString());
            g = BuildLine(container, 20);
            CreateText(GetStyle("WeaponStatLabel"), g.gameObject, "Range");
            CreateText(GetStyle("WeaponStatLabelRight"), g.gameObject, attr.range.ToString());
            Canvas.ForceUpdateCanvases();
        }
        public override void OnInspectorGUI()
        {
            WeaponAttribute atr = (WeaponAttribute)target;

            EditorGUILayout.BeginVertical();
            EditorGUI.BeginChangeCheck();
            int val = EditorGUILayout.IntSlider("Range", atr.range, 1, 50);

            Stats.WeaponType _t = (Stats.WeaponType)EditorGUILayout.EnumPopup("Weapon Type", atr.WeaponType);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(atr, "Modify attribute");
                atr.range      = val;
                atr.WeaponType = _t;
                EditorUtility.SetDirty(target);
            }
            EditorGUILayout.EndVertical();
        }
Esempio n. 5
0
        public void OnGUI()
        {
            if (stats == null || UndoObj == null)
            {
                return;
            }
            EditorGUI.BeginChangeCheck();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.BeginVertical();
            EditorGUILayout.LabelField("Base stats");
            float baseHP    = (int)EditorGUILayout.FloatField("HP", stats.BaseHP);
            float baseMP    = (int)EditorGUILayout.FloatField("MP", stats.BaseMP);
            float baseAtt   = (int)EditorGUILayout.FloatField("Attack", stats.BaseAttack);
            float baseDef   = (int)EditorGUILayout.FloatField("Defence", stats.BaseDef);
            float baseSpeed = (int)EditorGUILayout.FloatField("Speed", stats.BaseSpeed);

            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical();
            stats.CalculateStats();
            EditorGUILayout.LabelField("Calculated stats");
            EditorGUILayout.SelectableLabel(((int)stats.CalculatedHP).ToString(), GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUILayout.SelectableLabel(((int)stats.CalculatedMP).ToString(), GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUILayout.SelectableLabel(((int)stats.CalculatedAtt).ToString(), GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUILayout.SelectableLabel(((int)stats.CalculatedDef).ToString(), GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUILayout.SelectableLabel(((int)stats.CalculatedSpeed).ToString(), GUILayout.Height(EditorGUIUtility.singleLineHeight));

            EditorGUILayout.EndVertical();



            EditorGUILayout.EndHorizontal();
            if (EditorGUI.EndChangeCheck())
            {
                if (UndoObj != null)
                {
                    Undo.RegisterCompleteObjectUndo(UndoObj, "Modify Stats");
                }

                stats.BaseHP     = Mathf.Max(1, baseHP);
                stats.BaseMP     = Mathf.Max(0, baseMP);
                stats.BaseAttack = Mathf.Max(1, baseAtt);
                stats.BaseDef    = Mathf.Max(0, baseDef);
                stats.BaseSpeed  = Mathf.Max(0, baseSpeed);;
            }

            for (int i = 0; i < stats.Gear.items.Length; i++)
            {
                if (stats.Gear.items[i] != null)
                {
                    if (!dict.ContainsKey(i))
                    {
                        RefreshDictionary();
                        break;
                    }
                }
            }
            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Weapon Types", EditorStyles.boldLabel, GUILayout.Width(120));

            if (GUILayout.Button("+", GUILayout.Width(25)))
            {
                var myEnumMemberCount = Enum.GetNames(typeof(Stats.WeaponType)).Length;

                GenericMenu CreateMenu = new GenericMenu();

                for (int i = 0; i < myEnumMemberCount; i++)
                {
                    if (!stats.CanEquipWeapons.Contains(i))
                    {
                        CreateMenu.AddItem(new GUIContent(((Stats.WeaponType)i).ToString()), false, AddToEquipables, i);
                    }
                }

                CreateMenu.ShowAsContext();
            }
            GUILayout.FlexibleSpace();

            EditorGUILayout.EndHorizontal();

            int deleteIndex1 = -1;

            for (int i = 0; i < stats.CanEquipWeapons.Count; i++)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(((Stats.WeaponType)stats.CanEquipWeapons[i]).ToString(), GUILayout.Width(75));
                if (GUILayout.Button("x", GUILayout.Width(20)))
                {
                    deleteIndex1 = i;
                }
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
            }

            if (deleteIndex1 != -1)
            {
                Undo.RecordObject(UndoObj, "Modify Stats");
                stats.CanEquipWeapons.RemoveAt(deleteIndex1);
            }


            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Gear", EditorStyles.boldLabel);

            int deleteIndex = -1;

            for (int i = 0; i < stats.Gear.items.Length; i++)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(((Stats.GearSlots)i).ToString(), GUILayout.Width(100));
                if (stats.Gear.items[i] != null || stats.Gear.Names[i] != null)
                {
                    EditorGUI.BeginDisabledGroup(stats.Gear.items[i] == null);

                    NewItem item = stats.Gear.items[i] != null ? stats.Gear.items[i] : stats.Gear.Names[i];

                    EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                    gearFolds[i] = EditorGUILayout.Foldout(gearFolds[i], item.ItemName);
                    if (gearFolds[i])
                    {
                        if (dict.ContainsKey(i))
                        {
                            dict[i].OnInspectorGUI();
                        }
                        else
                        {
                            RefreshDictionary();
                        }
                    }
                    EditorGUILayout.EndVertical();

                    if (GUILayout.Button("X", GUILayout.Width(20)))
                    {
                        deleteIndex = i;
                    }

                    EditorGUI.EndDisabledGroup();
                }
                else
                {
                    EditorGUILayout.HorizontalScope v = new EditorGUILayout.HorizontalScope();
                    using (v) {
                        EditorGUILayout.HelpBox("No Gear", MessageType.Info);
                        EditorGUI.BeginChangeCheck();

                        EditorGUILayout.BeginVertical();

                        EditorGUILayout.Space();
                        EditorGUILayout.Space();
                        int select = EditorGUILayout.Popup(0, slotItemStrings[i]);
                        EditorGUILayout.EndVertical();

                        if (EditorGUI.EndChangeCheck())
                        {
                            NewItem           itm  = slotItems[i][slotItemStrings[i][select]];
                            GearSlotAttribute attr = itm.GetAttribute <GearSlotAttribute>();
                            if (attr == null)
                            {
                                Debug.LogWarning("This Item lack GearSlot Attribute and cannot be added to the Gear slot");
                            }
                            else
                            {
                                WeaponAttribute weaponAttr   = itm.GetAttribute <WeaponAttribute>();
                                bool            weaponCancel = false;
                                if (weaponAttr)
                                {
                                    if (!stats.CanEquipWeapons.Contains((int)weaponAttr.WeaponType))
                                    {
                                        weaponCancel = true;
                                        Debug.LogWarning("This character cannot equip this weapon type");
                                    }
                                }

                                //Add to a slot
                                if (attr.PossibleSlots[i] && !weaponCancel)
                                {
                                    Undo.RecordObject(UndoObj, "Modify Stats");
                                    stats.Gear.Equip(itm, i, null);
                                }
                            }
                            RefreshDictionary();
                        }
                    }
                    Event e = Event.current;
                    if (e.isMouse && e.button == 1 && v.rect.Contains(e.mousePosition))
                    {
                        GenericMenu CreateMenu = new GenericMenu();
                        if (ItemEditor.CopiedItem == null)
                        {
                            CreateMenu.AddDisabledItem(new GUIContent("Paste"));
                        }
                        else
                        {
                            CreateMenu.AddItem(new GUIContent("Paste"), false, Paste, i);
                        }
                        CreateMenu.ShowAsContext();
                    }
                }

                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Space();
            }
            if (deleteIndex != -1)
            {
                Undo.RecordObject(UndoObj, "Modify Stats");
                stats.Gear.Unequip(deleteIndex, null);
                RefreshDictionary();
            }
        }