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();
        }
        public override void OnInspectorGUI()
        {
            GearSlotAttribute atr = (GearSlotAttribute)target;

            EditorGUILayout.BeginVertical();

            toggle = EditorGUILayout.Foldout(toggle, "Gear Slots (Slot Name / Slot / Fill)");
            if (toggle)
            {
                EditorGUI.indentLevel++;
                for (int i = 0; i < atr.PossibleSlots.Length; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(_names[i]);
                    EditorGUI.BeginChangeCheck();
                    bool slotBoolA = EditorGUILayout.Toggle(atr.PossibleSlots[i]);
                    bool slotBoolB = EditorGUILayout.Toggle(atr.UnequipLots[i]);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RegisterCompleteObjectUndo(atr, "Modify Attribute");
                        atr.UnequipLots[i]   = slotBoolB;
                        atr.PossibleSlots[i] = slotBoolA;
                        EditorUtility.SetDirty(target);
                    }
                    GUILayout.FlexibleSpace();
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUI.indentLevel--;
                EditorGUILayout.Space();
            }
            EditorGUILayout.EndVertical();
        }
Example #3
0
        public void Equip(NewItem itm, Inventory inv)
        {
            int firstEquip         = -1;
            int firstFreeEquip     = -1;
            GearSlotAttribute attr = itm.GetAttribute <GearSlotAttribute>();

            //Look for thew first open slot and unequip all future slots
            for (int i = 0; i < attr.PossibleSlots.Length; i++)
            {
                if (attr.PossibleSlots[i])
                {
                    if (firstEquip == -1)
                    {
                        firstEquip = i;
                    }
                    if (items[i] == null && firstFreeEquip == -1)
                    {
                        firstFreeEquip = i;
                    }
                }
            }

            int slot = firstFreeEquip == -1 ? firstEquip : firstFreeEquip;

            Equip(itm, slot, inv);
        }
Example #4
0
        public void Equip(NewItem itm, int slot, Inventory inv)
        {
            GearSlotAttribute attr = itm.GetAttribute <GearSlotAttribute>();

            if (attr)
            {
                //Unequip item slots
                for (int i = 0; i < attr.UnequipLots.Length; i++)
                {
                    if (attr.UnequipLots[i])
                    {
                        if (gear[i])
                        {
                            Unequip(i, inv);
                        }
                    }
                }
            }

            //Unequip item that is currently in the slot
            if (gear[slot])
            {
                NewItem           lastItem = gear[slot];
                GearSlotAttribute attrLast = lastItem.GetAttribute <GearSlotAttribute>();
                for (int q = 0; q < attrLast.UnequipLots.Length; q++)
                {
                    if (attr.UnequipLots[q])
                    {
                        gear[q]      = null;
                        gearNames[q] = null;
                    }
                }

                gear[slot] = null;
            }

            gear[slot] = itm;

            //Fill other slots
            for (int i = 0; i < attr.UnequipLots.Length; i++)
            {
                if (attr.UnequipLots[i])
                {
                    gearNames[i] = itm;
                }
            }

            if (Application.isPlaying && inv != null)
            {
                inv.DepleteItem(itm);
            }
        }
Example #5
0
        public void Unequip(int slot, Inventory inv)
        {
            NewItem           lastItem = items[slot];
            GearSlotAttribute attrLast = lastItem.GetAttribute <GearSlotAttribute>();

            for (int q = 0; q < attrLast.UnequipLots.Length; q++)
            {
                if (attrLast.UnequipLots[q])
                {
                    gearNames[q] = null;
                }
            }

            if (Application.isPlaying && inv != null)
            {
                inv.AddItem(lastItem);
            }


            gear[slot] = null;
        }
Example #6
0
        public void BuildArmorSlotAttributeUI(GameObject container, GearSlotAttribute attr)
        {
            if (GearHelper)
            {
                GearHelper.SetActive(true);
            }
            for (int i = 0; i < attr.PossibleSlots.Length; i++)
            {
                if (!attr.PossibleSlots[i])
                {
                    GearSlotImages[i].color = new Color(GearSlotImages[i].color.r, GearSlotImages[i].color.g, GearSlotImages[i].color.b, 0.33f);
                }
                else
                {
                    GearSlotImages[i].color = new Color(GearSlotImages[i].color.r, GearSlotImages[i].color.g, GearSlotImages[i].color.b, 1f);
                }

                Outline outline = GearSlotImages[i].GetComponent <Outline>();

                if (outline)
                {
                    outline.enabled = false;

                    /*
                     * if (!attr.UnequipLots[i])
                     * {
                     *  outline.enabled = false;
                     *
                     * }
                     * else
                     * {
                     *  outline.enabled = true;
                     * }
                     */
                }
            }
        }
        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();
            }
        }