Ejemplo n.º 1
0
    /// <summary>
    /// Equip the specified item automatically replacing an existing one.
    /// </summary>

    public InvGameItem Replace(InvBaseItem.Slot slot, InvGameItem item)
    {
        InvBaseItem baseItem = (item != null) ? item.baseItem : null;

        if (slot != InvBaseItem.Slot.None)
        {
            // If the item is not of appropriate type, we shouldn't do anything
            if (baseItem != null && baseItem.slot != slot)
            {
                return(item);
            }

            if (mItems == null)
            {
                // Automatically figure out how many item slots we need
                int count = (int)InvBaseItem.Slot._LastDoNotUse;
                mItems = new InvGameItem[count];
            }

            // Equip this item
            InvGameItem prev = mItems[(int)slot - 1];
            mItems[(int)slot - 1] = item;

            // Get the list of all attachment points
            if (mAttachments == null)
            {
                mAttachments = GetComponentsInChildren <InvAttachmentPoint>();
            }

            // Equip the item visually
            for (int i = 0, imax = mAttachments.Length; i < imax; ++i)
            {
                InvAttachmentPoint ip = mAttachments[i];

                if (ip.slot == slot)
                {
                    GameObject go = ip.Attach(baseItem != null ? baseItem.attachment : null);

                    if (baseItem != null && go != null)
                    {
                        Renderer ren = go.GetComponent <Renderer>();
                        if (ren != null)
                        {
                            ren.material.color = baseItem.color;
                        }
                    }
                }
            }
            return(prev);
        }
        else if (item != null)
        {
            Debug.LogWarning("Can't equip \"" + item.name + "\" because it doesn't specify an item slot");
        }
        return(item);
    }
Ejemplo n.º 2
0
    public InvGameItem Replace(InvBaseItem.Slot slot, InvGameItem item)
    {
        var item2 = item == null ? null : item.baseItem;

        if (slot != InvBaseItem.Slot.None)
        {
            if (item2 != null && item2.slot != slot)
            {
                return(item);
            }

            if (mItems == null)
            {
                var num = 8;
                mItems = new InvGameItem[num];
            }

            var item3 = mItems[(int)slot - 1];
            mItems[(int)slot - 1] = item;
            if (mAttachments == null)
            {
                mAttachments = GetComponentsInChildren <InvAttachmentPoint>();
            }

            var index  = 0;
            var length = mAttachments.Length;
            while (index < length)
            {
                var point = mAttachments[index];
                if (point.slot == slot)
                {
                    var obj2 = point.Attach(item2 == null ? null : item2.attachment);
                    if (item2 != null && obj2 != null)
                    {
                        var renderer = obj2.renderer;
                        if (renderer != null)
                        {
                            renderer.material.color = item2.color;
                        }
                    }
                }

                index++;
            }

            return(item3);
        }

        if (item != null)
        {
            Debug.LogWarning("Can't equip \"" + item.name + "\" because it doesn't specify an item slot");
        }

        return(item);
    }
Ejemplo n.º 3
0
 public InvGameItem GetItem(InvBaseItem.Slot slot)
 {
     if (slot != InvBaseItem.Slot.None)
     {
         int num = slot - InvBaseItem.Slot.Weapon;
         if (this.mItems != null && num < this.mItems.Length)
         {
             return(this.mItems[num]);
         }
     }
     return(null);
 }
Ejemplo n.º 4
0
 public InvGameItem GetItem(InvBaseItem.Slot slot)
 {
     if (slot != InvBaseItem.Slot.None)
     {
         int index = ((int)slot) - 1;
         if ((this.mItems != null) && (index < this.mItems.Length))
         {
             return(this.mItems[index]);
         }
     }
     return(null);
 }
Ejemplo n.º 5
0
 public InvGameItem GetItem(InvBaseItem.Slot slot)
 {
     if (slot != 0)
     {
         int num = (int)(slot - 1);
         if (mItems != null && num < mItems.Length)
         {
             return(mItems[num]);
         }
     }
     return(null);
 }
Ejemplo n.º 6
0
    /// <summary>
    /// Retrieves the item in the specified slot.
    /// </summary>

    public InvGameItem GetItem(InvBaseItem.Slot slot)
    {
        if (slot != InvBaseItem.Slot.None)
        {
            int index = (int)slot - 1;

            if (mItems != null && index < mItems.Length)
            {
                return(mItems[index]);
            }
        }
        return(null);
    }
Ejemplo n.º 7
0
    public InvGameItem Replace(InvBaseItem.Slot slot, InvGameItem item)
    {
        InvBaseItem invBaseItem = (item == null) ? null : item.baseItem;

        if (slot == InvBaseItem.Slot.None)
        {
            if (item != null)
            {
                Debug.LogWarning("Can't equip \"" + item.name + "\" because it doesn't specify an item slot");
            }
            return(item);
        }
        if (invBaseItem != null && invBaseItem.slot != slot)
        {
            return(item);
        }
        if (this.mItems == null)
        {
            int num = 8;
            this.mItems = new InvGameItem[num];
        }
        InvGameItem result = this.mItems[slot - InvBaseItem.Slot.Weapon];

        this.mItems[slot - InvBaseItem.Slot.Weapon] = item;
        if (this.mAttachments == null)
        {
            this.mAttachments = base.GetComponentsInChildren <InvAttachmentPoint>();
        }
        int i    = 0;
        int num2 = this.mAttachments.Length;

        while (i < num2)
        {
            InvAttachmentPoint invAttachmentPoint = this.mAttachments[i];
            if (invAttachmentPoint.slot == slot)
            {
                GameObject gameObject = invAttachmentPoint.Attach((invBaseItem == null) ? null : invBaseItem.attachment);
                if (invBaseItem != null && gameObject != null)
                {
                    Renderer component = gameObject.GetComponent <Renderer>();
                    if (component != null)
                    {
                        component.material.color = invBaseItem.color;
                    }
                }
            }
            i++;
        }
        return(result);
    }
Ejemplo n.º 8
0
    /// <summary>
    /// Whether the specified slot currently has an item equipped.
    /// </summary>

    public bool HasEquipped(InvBaseItem.Slot slot)
    {
        if (mItems != null)
        {
            for (int i = 0, imax = mItems.Length; i < imax; ++i)
            {
                InvBaseItem baseItem = mItems[i].baseItem;
                if (baseItem != null && baseItem.slot == slot)
                {
                    return(true);
                }
            }
        }
        return(false);
    }
Ejemplo n.º 9
0
    /// <summary>
    /// Whether the specified slot currently has an item equipped.
    /// </summary>

    public bool HasEquipped(InvBaseItem.Slot slot)
    {
        if (mItems != null)
        {
            foreach (InvGameItem i in mItems)
            {
                InvBaseItem baseItem = i.baseItem;
                if (baseItem != null && baseItem.slot == slot)
                {
                    return(true);
                }
            }
        }
        return(false);
    }
Ejemplo n.º 10
0
    public InvGameItem Replace(InvBaseItem.Slot slot, InvGameItem item)
    {
        InvBaseItem item2 = (item == null) ? null : item.baseItem;

        if (slot != InvBaseItem.Slot.None)
        {
            if ((item2 != null) && (item2.slot != slot))
            {
                return(item);
            }
            if (this.mItems == null)
            {
                int num = 8;
                this.mItems = new InvGameItem[num];
            }
            InvGameItem item3 = this.mItems[((int)slot) - 1];
            this.mItems[((int)slot) - 1] = item;
            if (this.mAttachments == null)
            {
                this.mAttachments = base.GetComponentsInChildren <InvAttachmentPoint>();
            }
            int index  = 0;
            int length = this.mAttachments.Length;
            while (index < length)
            {
                InvAttachmentPoint point = this.mAttachments[index];
                if (point.slot == slot)
                {
                    GameObject obj2 = point.Attach((item2 == null) ? null : item2.attachment);
                    if ((item2 != null) && (obj2 != null))
                    {
                        Renderer renderer = obj2.renderer;
                        if (renderer != null)
                        {
                            renderer.material.color = item2.color;
                        }
                    }
                }
                index++;
            }
            return(item3);
        }
        if (item != null)
        {
            Debug.LogWarning("Can't equip \"" + item.name + "\" because it doesn't specify an item slot");
        }
        return(item);
    }
Ejemplo n.º 11
0
    public InvGameItem Replace(InvBaseItem.Slot slot, InvGameItem item)
    {
        InvBaseItem invBaseItem = item?.baseItem;

        if (slot != 0)
        {
            if (invBaseItem != null && invBaseItem.slot != slot)
            {
                return(item);
            }
            if (mItems == null)
            {
                int num = 8;
                mItems = new InvGameItem[num];
            }
            InvGameItem result = mItems[(int)(slot - 1)];
            mItems[(int)(slot - 1)] = item;
            if (mAttachments == null)
            {
                mAttachments = GetComponentsInChildren <InvAttachmentPoint>();
            }
            int i = 0;
            for (int num2 = mAttachments.Length; i < num2; i++)
            {
                InvAttachmentPoint invAttachmentPoint = mAttachments[i];
                if (invAttachmentPoint.slot != slot)
                {
                    continue;
                }
                GameObject gameObject = invAttachmentPoint.Attach(invBaseItem?.attachment);
                if (invBaseItem != null && gameObject != null)
                {
                    Renderer renderer = gameObject.renderer;
                    if (renderer != null)
                    {
                        renderer.material.color = invBaseItem.color;
                    }
                }
            }
            return(result);
        }
        if (item != null)
        {
            Debug.LogWarning("Can't equip \"" + item.name + "\" because it doesn't specify an item slot");
        }
        return(item);
    }
Ejemplo n.º 12
0
 public bool HasEquipped(InvBaseItem.Slot slot)
 {
     if (this.mItems != null)
     {
         int i   = 0;
         int num = this.mItems.Length;
         while (i < num)
         {
             InvBaseItem baseItem = this.mItems[i].baseItem;
             if (baseItem != null && baseItem.slot == slot)
             {
                 return(true);
             }
             i++;
         }
     }
     return(false);
 }
Ejemplo n.º 13
0
 public bool HasEquipped(InvBaseItem.Slot slot)
 {
     if (this.mItems != null)
     {
         int index  = 0;
         int length = this.mItems.Length;
         while (index < length)
         {
             InvBaseItem baseItem = this.mItems[index].baseItem;
             if ((baseItem != null) && (baseItem.slot == slot))
             {
                 return(true);
             }
             index++;
         }
     }
     return(false);
 }
Ejemplo n.º 14
0
    public bool HasEquipped(InvBaseItem.Slot slot)
    {
        if (mItems != null)
        {
            var index  = 0;
            var length = mItems.Length;
            while (index < length)
            {
                var baseItem = mItems[index].baseItem;
                if (baseItem != null && baseItem.slot == slot)
                {
                    return(true);
                }

                index++;
            }
        }

        return(false);
    }
Ejemplo n.º 15
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        NGUIEditorTools.SetLabelWidth(80f);
        InvDatabase db = target as InvDatabase;

        NGUIEditorTools.DrawSeparator();

        InvBaseItem item = null;

        if (db.items == null || db.items.Count == 0)
        {
            mIndex = 0;
        }
        else
        {
            mIndex = Mathf.Clamp(mIndex, 0, db.items.Count - 1);
            item   = db.items[mIndex];
        }

        if (mConfirmDelete)
        {
            // Show the confirmation dialog
            GUILayout.Label("Are you sure you want to delete '" + item.name + "'?");
            NGUIEditorTools.DrawSeparator();

            GUILayout.BeginHorizontal();
            {
                GUI.backgroundColor = Color.green;
                if (GUILayout.Button("Cancel"))
                {
                    mConfirmDelete = false;
                }
                GUI.backgroundColor = Color.red;

                if (GUILayout.Button("Delete"))
                {
                    NGUIEditorTools.RegisterUndo("Delete Inventory Item", db);
                    db.items.RemoveAt(mIndex);
                    mConfirmDelete = false;
                }
                GUI.backgroundColor = Color.white;
            }
            GUILayout.EndHorizontal();
        }
        else
        {
            // Database icon atlas
            var atlas = db.iconAtlas;
            if (atlas is UIAtlas)
            {
                atlas = EditorGUILayout.ObjectField("Icon Atlas", atlas, typeof(UIAtlas), false) as UIAtlas;
            }
            else
            {
                atlas = EditorGUILayout.ObjectField("Icon Atlas", atlas, typeof(NGUIAtlas), false) as NGUIAtlas;
            }

            if (atlas != db.iconAtlas)
            {
                NGUIEditorTools.RegisterUndo("Databse Atlas change", db);
                db.iconAtlas = atlas;
                foreach (InvBaseItem i in db.items)
                {
                    i.iconAtlas = atlas;
                }
            }

            // Database ID
            int dbID = EditorGUILayout.IntField("Database ID", db.databaseID);

            if (dbID != db.databaseID)
            {
                NGUIEditorTools.RegisterUndo("Database ID change", db);
                db.databaseID = dbID;
            }

            // "New" button
            GUI.backgroundColor = Color.green;

            if (GUILayout.Button("New Item"))
            {
                NGUIEditorTools.RegisterUndo("Add Inventory Item", db);

                InvBaseItem bi = new InvBaseItem();
                bi.iconAtlas = db.iconAtlas;
                bi.id16      = (db.items.Count > 0) ? db.items[db.items.Count - 1].id16 + 1 : 0;
                db.items.Add(bi);
                mIndex = db.items.Count - 1;

                if (item != null)
                {
                    bi.name         = "Copy of " + item.name;
                    bi.description  = item.description;
                    bi.slot         = item.slot;
                    bi.color        = item.color;
                    bi.iconName     = item.iconName;
                    bi.attachment   = item.attachment;
                    bi.minItemLevel = item.minItemLevel;
                    bi.maxItemLevel = item.maxItemLevel;

                    foreach (InvStat stat in item.stats)
                    {
                        InvStat copy = new InvStat();
                        copy.id       = stat.id;
                        copy.amount   = stat.amount;
                        copy.modifier = stat.modifier;
                        bi.stats.Add(copy);
                    }
                }
                else
                {
                    bi.name        = "New Item";
                    bi.description = "Item Description";
                }

                item = bi;
            }
            GUI.backgroundColor = Color.white;

            if (item != null)
            {
                NGUIEditorTools.DrawSeparator();

                // Navigation section
                GUILayout.BeginHorizontal();
                {
                    if (mIndex == 0)
                    {
                        GUI.color = Color.grey;
                    }
                    if (GUILayout.Button("<<"))
                    {
                        mConfirmDelete = false; --mIndex;
                    }
                    GUI.color = Color.white;
                    mIndex    = EditorGUILayout.IntField(mIndex + 1, GUILayout.Width(40f)) - 1;
                    GUILayout.Label("/ " + db.items.Count, GUILayout.Width(40f));
                    if (mIndex + 1 == db.items.Count)
                    {
                        GUI.color = Color.grey;
                    }
                    if (GUILayout.Button(">>"))
                    {
                        mConfirmDelete = false; ++mIndex;
                    }
                    GUI.color = Color.white;
                }
                GUILayout.EndHorizontal();

                NGUIEditorTools.DrawSeparator();

                // Item name and delete item button
                GUILayout.BeginHorizontal();
                {
                    string itemName = EditorGUILayout.TextField("Item Name", item.name);

                    GUI.backgroundColor = Color.red;

                    if (GUILayout.Button("Delete", GUILayout.Width(55f)))
                    {
                        mConfirmDelete = true;
                    }
                    GUI.backgroundColor = Color.white;

                    if (!itemName.Equals(item.name))
                    {
                        NGUIEditorTools.RegisterUndo("Rename Item", db);
                        item.name = itemName;
                    }
                }
                GUILayout.EndHorizontal();

                string           itemDesc   = GUILayout.TextArea(item.description, 200, GUILayout.Height(100f));
                InvBaseItem.Slot slot       = (InvBaseItem.Slot)EditorGUILayout.EnumPopup("Slot", item.slot);
                string           iconName   = "";
                float            iconSize   = 64f;
                bool             drawIcon   = false;
                float            extraSpace = 0f;
                var ia = item.iconAtlas as INGUIAtlas;

                if (ia != null)
                {
                    var sprites = ia.GetListOfSprites();
                    sprites.Insert(0, "<None>");

                    int    index      = 0;
                    string spriteName = (item.iconName != null) ? item.iconName : sprites[0];

                    // We need to find the sprite in order to have it selected
                    if (!string.IsNullOrEmpty(spriteName))
                    {
                        for (int i = 1; i < sprites.size; ++i)
                        {
                            if (spriteName.Equals(sprites[i], System.StringComparison.OrdinalIgnoreCase))
                            {
                                index = i;
                                break;
                            }
                        }
                    }

                    // Draw the sprite selection popup
                    index = EditorGUILayout.Popup("Icon", index, sprites.ToArray());
                    UISpriteData sprite = (index > 0) ? ia.GetSprite(sprites[index]) : null;

                    if (sprite != null)
                    {
                        iconName = sprite.name;

                        var mat = ia.spriteMaterial;

                        if (mat != null)
                        {
                            Texture2D tex = mat.mainTexture as Texture2D;

                            if (tex != null)
                            {
                                drawIcon = true;
                                Rect rect = new Rect(sprite.x, sprite.y, sprite.width, sprite.height);
                                rect = NGUIMath.ConvertToTexCoords(rect, tex.width, tex.height);

                                GUILayout.Space(4f);
                                GUILayout.BeginHorizontal();
                                {
                                    GUILayout.Space(Screen.width - iconSize);
                                    DrawSprite(tex, rect, null, false);
                                }
                                GUILayout.EndHorizontal();

                                extraSpace = iconSize * (float)sprite.height / sprite.width;
                            }
                        }
                    }
                }

                // Item level range
                GUILayout.BeginHorizontal();
                GUILayout.Label("Level Range", GUILayout.Width(77f));
                int min = EditorGUILayout.IntField(item.minItemLevel, GUILayout.MinWidth(40f));
                int max = EditorGUILayout.IntField(item.maxItemLevel, GUILayout.MinWidth(40f));
                if (drawIcon)
                {
                    GUILayout.Space(iconSize);
                }
                GUILayout.EndHorizontal();

                // Game Object attachment field, left of the icon
                GUILayout.BeginHorizontal();
                GameObject go = (GameObject)EditorGUILayout.ObjectField("Attachment", item.attachment, typeof(GameObject), false);
                if (drawIcon)
                {
                    GUILayout.Space(iconSize);
                }
                GUILayout.EndHorizontal();

                // Color tint field, left of the icon
                GUILayout.BeginHorizontal();
                Color color = EditorGUILayout.ColorField("Color", item.color);
                if (drawIcon)
                {
                    GUILayout.Space(iconSize);
                }
                GUILayout.EndHorizontal();

                // Calculate the extra spacing necessary for the icon to show up properly and not overlap anything
                if (drawIcon)
                {
                    extraSpace = Mathf.Max(0f, extraSpace - 60f);
                    GUILayout.Space(extraSpace);
                }

                // Item stats
                NGUIEditorTools.DrawSeparator();

                if (item.stats != null)
                {
                    for (int i = 0; i < item.stats.Count; ++i)
                    {
                        InvStat stat = item.stats[i];

                        GUILayout.BeginHorizontal();
                        {
                            InvStat.Identifier iden = (InvStat.Identifier)EditorGUILayout.EnumPopup(stat.id, GUILayout.Width(80f));

                            // Color the field red if it's negative, green if it's positive
                            if (stat.amount > 0)
                            {
                                GUI.backgroundColor = Color.green;
                            }
                            else if (stat.amount < 0)
                            {
                                GUI.backgroundColor = Color.red;
                            }
                            int amount = EditorGUILayout.IntField(stat.amount, GUILayout.Width(40f));
                            GUI.backgroundColor = Color.white;

                            InvStat.Modifier mod = (InvStat.Modifier)EditorGUILayout.EnumPopup(stat.modifier);

                            GUI.backgroundColor = Color.red;
                            if (GUILayout.Button("X", GUILayout.Width(20f)))
                            {
                                NGUIEditorTools.RegisterUndo("Delete Item Stat", db);
                                item.stats.RemoveAt(i);
                                --i;
                            }
                            else if (iden != stat.id || amount != stat.amount || mod != stat.modifier)
                            {
                                NGUIEditorTools.RegisterUndo("Item Stats", db);
                                stat.id       = iden;
                                stat.amount   = amount;
                                stat.modifier = mod;
                            }
                            GUI.backgroundColor = Color.white;
                        }
                        GUILayout.EndHorizontal();
                    }
                }

                if (GUILayout.Button("Add Stat", GUILayout.Width(80f)))
                {
                    NGUIEditorTools.RegisterUndo("Add Item Stat", db);
                    InvStat stat = new InvStat();
                    stat.id = InvStat.Identifier.Armor;
                    item.stats.Add(stat);
                }

                // Save all values
                if (!itemDesc.Equals(item.description) ||
                    slot != item.slot ||
                    go != item.attachment ||
                    color != item.color ||
                    min != item.minItemLevel ||
                    max != item.maxItemLevel ||
                    !iconName.Equals(item.iconName))
                {
                    NGUIEditorTools.RegisterUndo("Item Properties", db);
                    item.description  = itemDesc;
                    item.slot         = slot;
                    item.attachment   = go;
                    item.color        = color;
                    item.iconName     = iconName;
                    item.minItemLevel = min;
                    item.maxItemLevel = max;
                }
            }
        }
    }
Ejemplo n.º 16
0
 public InvGameItem Unequip(InvBaseItem.Slot slot)
 {
     return(this.Replace(slot, null));
 }