public bool CanSetItem(Gameplay.EquipmentSlotType Slot, GameplayItem Item)
    {
        //Check if this slot is locked by other item
        if (Slot < Gameplay.EquipmentSlotType._COUNT)
        {
            if (Slots[(int)Slot].LockedByOtherSlot)
            {
                return false;
            }
        }

        //Check generics
        if (Item.Slot == Gameplay.EquipmentSlotType.HAND || Item.Slot == Gameplay.EquipmentSlotType.LEFT_RIGHT_HAND)
        {
            if (Slot == Gameplay.EquipmentSlotType.LEFT_HAND)
                return true;
            if (Slot == Gameplay.EquipmentSlotType.RIGHT_HAND)
                return true;
        }
        else if (Item.Slot == Gameplay.EquipmentSlotType.FINGER || Item.Slot == Gameplay.EquipmentSlotType.LEFT_RIGHT_FINGER)
        {
            if (Slot == Gameplay.EquipmentSlotType.LEFT_FINGER)
                return true;
            if (Slot == Gameplay.EquipmentSlotType.RIGHT_FINGER)
                return true;
        }

        return Slot == Item.Slot;
    }
    public bool AddItem(GameplayItem Item)
    {
        if (m_Items.Count + 1 >= MaxSize)
            return false; //no free space

        m_Items.Add(Item);
        return true;
    }
    public void Show(GameplayItem Item, float posX, float posY)
    {
        //Add offset to enable click content below this window (eg. item slot)
        MainWndRect.x = posX + 1;
        MainWndRect.y = posY + 1;
        m_Item = Item;

        base.Show(true);
    }
 public GameplayItem Drop(BaseGUI DstGUI)
 {
     m_Tex = null;
     GameplayItem Item = m_Item;
     m_Item = null;
     m_active = false;
     m_DstGUI = DstGUI;
     return Item;
 }
    public bool HasItem(GameplayItem Item)
    {
        foreach(ItemSlotGUI Slot in m_ItemSlots)
        {
            if(Slot.Item == Item)
                return true;
        }

        return false;
    }
    public void Drag(BaseGUI DragGUI, GameplayItem Item)
    {
        if(Item == null)
            return;

        m_Item = Item;
        m_Tex = Item.GetIcon();

        m_Rect.width = m_Tex.width;
        m_Rect.height = m_Tex.height;
        m_active = true;
        m_SrcGUI = DragGUI;
    }
    protected override bool OnDropItem(BaseGUI Src, GameplayItem Item)
    {
        if(m_Obj != null)
        {
            m_Obj.AddItem(Item);
            return true;
        }

        if(m_Unit != null)
        {
        }

        return false;
    }
    protected override bool OnGetItem(GameplayItem Item)
    {
        if(m_Obj != null)
        {
            m_Obj.RemoveItem(Item);
            return true;
        }

        if(m_Unit != null)
        {
        }

        return false;
    }
 public void AddItem(GameplayItem Item)
 {
     if (Item == null)
         return;
     //m_Items.Add(Item);
     foreach(ItemSlotGUI Slot in m_ItemSlots)
     {
         if(Slot.Item == null)
         {
             Slot.Item = Item;
             //Slot.Content.image = Item.GetIcon();
             //Slot.Content.text = Item.Name;
             break;
         }
     }
 }
    public List<Gameplay.EquipmentSlotType> CheckItemSlots(Gameplay.EquipmentSlotType DstSlot, GameplayItem Item)
    {
        List<Gameplay.EquipmentSlotType> List = new List<Gameplay.EquipmentSlotType>();
        //Check generics
        if (Item.Slot == Gameplay.EquipmentSlotType.LEFT_RIGHT_HAND)
        {
            List.Add(Gameplay.EquipmentSlotType.RIGHT_HAND);
            List.Add(Gameplay.EquipmentSlotType.LEFT_HAND);
        }
        else if (Item.Slot == Gameplay.EquipmentSlotType.LEFT_RIGHT_FINGER)
        {
            List.Add(Gameplay.EquipmentSlotType.LEFT_FINGER);
            List.Add(Gameplay.EquipmentSlotType.RIGHT_FINGER);
        }
        /*else if(Item.Slot == Gameplay.EquipmentSlotType.HAND)
        {
            if((DstSlot == Gameplay.EquipmentSlotType.LEFT_HAND || DstSlot == Gameplay.EquipmentSlotType.RIGHT_HAND) &&
                !Slots[(int)DstSlot].LockedByOtherSlot)
            {
                List.Add(DstSlot);
            }
        }
        else if(Item.Slot == Gameplay.EquipmentSlotType.FINGER)
        {
            if((DstSlot == Gameplay.EquipmentSlotType.LEFT_FINGER || DstSlot == Gameplay.EquipmentSlotType.RIGHT_FINGER) &&
                !Slots[(int)DstSlot].LockedByOtherSlot)
            {
                List.Add(DstSlot);
            }
        }
        else if(!Slots[(int)DstSlot].LockedByOtherSlot)
        {
            List.Add(DstSlot);
        }*/

        return List;
    }
 protected virtual void OnItemClick(GameplayItem Item)
 {
 }
    //Returns list of slots to remove from equipment
    public List<Gameplay.EquipmentSlotType> SetItem(Gameplay.EquipmentSlotType Slot, GameplayItem Item, List<Gameplay.EquipmentSlotType> SlotsToLock)
    {
        if(SlotsToLock == null)
            return null; //no slots
        if(!CanSetItem(Slot, Item))
            return null;

        //If this item needs other items to remove
        List<Gameplay.EquipmentSlotType> RemSlots = new List<Gameplay.EquipmentSlotType>();
        foreach(Gameplay.EquipmentSlotType CurrSlot in SlotsToLock)
        {
            if(Slots[(int)CurrSlot].Item != null)
            {
                RemSlots.Add(CurrSlot);
            }
        }

        //Check if unit's inventory has room for removed items
        if(m_Unit.Inventory.FreeSlotCount < RemSlots.Count)
        {
            //No room for items from equipment
            RemSlots.Clear();
            return null;
        }

        Slots[(int)Slot].Item = Item;
        Slots[(int)Slot].LockedByOtherSlot = false;

        return RemSlots;
    }
Example #13
0
 public void SetGameplayItem(GameplayItem Item)
 {
     m_GameplayItem = Item;
     UpdateForGameplay();
 }
    string ReadItems(BinaryReader Reader, ref Dictionary<string, GameplayItem> Map)
    {
        try
        {
            for (int i = 0; i < m_itemCount; ++i)
            {
                GameplayItem Item = new GameplayItem();
                Item.Type = (Gameplay.ItemType)Reader.ReadInt32();
                Item.SubType = (Gameplay.ItemSubType)Reader.ReadInt32();
                Item.Slot = (Gameplay.EquipmentSlotType)Reader.ReadInt32();
                Item.Dragable = Reader.ReadBoolean();
                Item.IconPath = Reader.ReadString();
                Item.Inventory = Reader.ReadBoolean();
                Item.PrefabPath = Reader.ReadString();
                Item.Usable = Reader.ReadBoolean();
                Item.ScriptPath = Reader.ReadString();

                //Attributes
                Item.Name = Reader.ReadString();
                Item.Weight = Reader.ReadSingle();

                //Components
                short componentCount = Reader.ReadInt16();
                for(short c = 0; c < componentCount; ++c)
                {
                    GameplayItemComponent Cmp = ReadComponent(Reader);
                    if(Cmp != null)
                    {
                        Item.AddComponent(Cmp);
                    }
                }

                Debug.Log("Read item from db: " + Item);
                Map.Add(Item.Name, Item);
            }
        }
        catch (System.Exception Ex)
        {
            Debug.LogError(Ex.Message);
            return Ex.Message;
        }
        return string.Empty;
    }
 public void AddItem(GameplayItem Item)
 {
     if(ContainedItems.Contains(Item))
         return;
     ContainedItems.Add(Item);
 }
 public void RemoveItem(GameplayItem Item)
 {
     ContainedItems.Remove(Item);
 }
    void WndFunc(int wndId)
    {
        int currRect = 0;
        ItemSlotGUI Slot;

        for (int y = 0; y < m_rowWidth; ++y)
        {
            for (int x = 0; x < m_colHeight; ++x)
            {
                Slot = m_ItemSlots[currRect];

                GUI.SetNextControlName(m_controlName);

                Slot.Draw();
                if (Slot.MouseOver)
                {
                    if (Slot.Item != null)
                    {
                        m_SelectedItem = Slot.Item;
                        m_tooltipItemId = currRect;
                    }

                    OnMouseOverItemSlot(Slot);

                    if (Slot.MouseDown)
                    {
                        LootItemClicked(x, y, currRect, Event.current.button);
                    }
                }

                currRect++;
            }
        }

        if(GUI.Button(m_CloseBtnRect, "X", GameGUI.Singleton.CloseButtonStyle))
        {
            this.Show(false);
        }

        GUI.DragWindow(m_WndDragRect);
    }
 protected virtual void OnItemHover(GameplayItem Item)
 {
 }
 protected virtual bool OnGetItem(GameplayItem Item)
 {
     return true;
 }
    void OnGUI()
    {
        EditorGUILayout.BeginHorizontal();
        m_searchText = EditorGUILayout.TextField(m_searchText);
        if(GUILayout.Button("Search"))
        {
            SetItem(SearchItem());
        }
        EditorGUILayout.EndHorizontal();
        m_vecScrollView = EditorGUILayout.BeginScrollView(m_vecScrollView);
        //EditorGUILayout.TextField("Item Name:", "");
        //m_SelectedType = (Gameplay.ItemType)EditorGUILayout.EnumPopup("Item Type:", m_SelectedType);
        //if (m_SelectedType == Gameplay.ItemType._COUNT)
        //    m_SelectedType = Gameplay.ItemType.NONE;
        //m_SelectedSubType = (Gameplay.ItemSubType)EditorGUILayout.EnumPopup("Item SubType:", m_SelectedSubType);
        //if (m_SelectedSubType == Gameplay.ItemSubType._COUNT)
        //    m_SelectedSubType = Gameplay.ItemSubType.NONE;

        //m_SelectedType = Gameplay.CheckItemType(m_SelectedSubType);
        if (m_Item == null)
            m_Item = System.Activator.CreateInstance(typeof(GameplayItem)) as GameplayItem;
        if (m_Item == null)
            Debug.LogError("null");
        object obj = (object)m_Item;
        //Debug.Log(obj.GetType());
        GUIDrawObject(m_Item);

        GUIItemComponents();

        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Edit"))
        {
            EditItem();
        }
        if (GUILayout.Button("Create"))
        {
            CreateNewItem();
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.EndScrollView();
    }
 public virtual void CopyFrom(GameplayItemComponent Other)
 {
     m_Item = Other.Item;
 }
 public List<Gameplay.EquipmentSlotType> SetItem(Gameplay.EquipmentSlotType Slot, GameplayItem Item)
 {
     List<Gameplay.EquipmentSlotType> List = CheckItemSlots(Slot, Item);
       	return SetItem (Slot, Item, List);
 }
 public void _Create(GameplayItem Item)
 {
     m_Item = Item;
     OnCreate();
 }
 protected override void OnHide()
 {
     m_Tex = null;
     m_Item = null;
 }
 protected override void OnDraw()
 {
     GUI.SetNextControlName(this.m_controlName);
     MainWndRect = GUI.Window(this.MainWndID, MainWndRect, WndFunc, WindowTitle);
     if(m_SelectedItem != null)
     {
         m_ItemTooltip.Show(m_SelectedItem, Event.current.mousePosition.x + 1, Event.current.mousePosition.y + 1);
         m_SelectedItem = null; //show only one time per frame
     }
     else
     {
         m_ItemTooltip.Show(false);
     }
 }
    void SetItem(GameplayItem Item)
    {
        if (Item == null)
        {
            m_Item = new GameplayItem();
            return;
        }

        m_Item = Item;
        m_ItemComponentGUIs.Clear();
        foreach (GameplayItemComponent Cmp in m_Item.Components)
        {
            m_ItemComponentGUIs.Add(new ItemComponentGUI());
        }

        if (m_Item.Prefab == null && m_Item.PrefabPath != string.Empty)
        {
            m_Item.Prefab = ResourceManager.Singleton.LoadPrefab(m_Item.PrefabPath);
        }

        if (m_Item.Icon == null && m_Item.IconPath != string.Empty)
        {
            m_Item.Icon = ResourceManager.Singleton.LoadIcon(m_Item.IconPath);
        }
    }
 protected virtual bool OnDropItem(BaseGUI Src, GameplayItem Item)
 {
     return true;
 }