Exemplo n.º 1
0
    void Start()
    {
        m_Rows = (int)Mathf.Ceil(m_Container.size / (float)m_Columns);
        float width  = m_SlotMargin.x * 2 + (m_SlotSize.x + m_SlotSpacing.x) * m_Columns - m_SlotSpacing.x;
        float height = m_SlotMargin.y * 2 + (m_SlotSize.y + m_SlotSpacing.y) * m_Rows    - m_SlotSpacing.y + m_Skin.window.padding.vertical;

        m_Rect = new Rect(50
                         ,Screen.height*0.5f - height*0.5f
                         ,width
                         ,height);

        int i = 0;
        for (int y = 0; y < m_Rows; y++)
        {
            for (int x = 0; x < m_Columns; x++)
            {
                if (i >= m_Container.size)
                    break;

                CRItem item = m_Container.GetItem(i);
                Rect slotRect = new Rect(m_SlotMargin.x + (m_SlotSpacing.x + m_SlotSize.x)* x,
                                         m_SlotMargin.y + (m_SlotSpacing.y + m_SlotSize.y)* y + m_Skin.window.padding.vertical,
                                         m_SlotSize.x,
                                         m_SlotSize.y);

                GUIItemSlot slot = new GUIItemSlot(slotRect, item, i);

                m_Slots.Add(slot);

                i++;
            }
        }
    }
Exemplo n.º 2
0
 public virtual void DrawTooltip(GUIItemSlot slot)
 {
     if (slot.item)
     {
         GUILayout.Label("Test");
     }
 }
Exemplo n.º 3
0
 public void OnMouseDown(GUIItemSlot slot)
 {
     if (slot!=null && !cgui.dragging)
     {
         slot.grayed = true;
         cgui.SelectSlot(slot);
     }
 }
Exemplo n.º 4
0
    public void OnHoverOut(GUIItemSlot slot)
    {
        if (cgui.selectedSlot == slot && cgui.mouseDown && !cgui.dragging && slot.item != null)
        {
            cgui.Drag(slot, this);
        }
        else
        {
            slot.showBorder = false;
        }

        cgui.ClearHover();
    }
Exemplo n.º 5
0
    public void Initialize()
    {
        m_listItemSlots = new List <GUIItemSlot>(m_nMaxSlot);

        for (int i = 0; i < m_nMaxSlot; i++)
        {
            GameObject prefap   = Resources.Load <GameObject>("Prefaps/ItemSlot");
            GameObject instance = Instantiate(prefap);
            instance.transform.SetParent(m_tranformContent);
            GUIItemSlot cItemSlot = instance.GetComponent <GUIItemSlot>();

            cItemSlot.Delete(m_spriteSlotNone);
            m_listItemSlots.Add(cItemSlot);
        }
    }
Exemplo n.º 6
0
    public void OnReleaseMouse(GUIItemSlot dst)
    {
        //clean the slot color of the slot we landed on
        if (dst != null)
        {

            if (!cgui.dragging && cgui.hoverSlot == cgui.selectedSlot && dst.item != null)
            {
                cgui.Drag(dst, this);
                return;
            }
            else
            {
                dst.grayed = false;
            }
        }

        //cache the dragged variables and clean cgui for next use
        GUIItemSlot src = cgui.dragSlot;
        GUIItemContainer dragContainer = cgui.dragContainer;
        cgui.ClearDrag();

        //nothing is held by the mouse, exit
        if (src == null)
            return;

        //clean color of the source slot
        src.grayed = false;

        //we were not droppped on a gui slot
        if (dst == null)
        {
            if (dragContainer != this)
            {
                //if (m_Container.AddItem(src.item))
                {
                    //dragContainer.container.RemoveItem(src.item);
                }
            }
            return;
        }

        //we have a source slot and destination slot, perfrom swap or move
        CRItem srcItem = src.item;

        if (srcItem == null)
            Debug.LogError("Trying to move a null item");

        CRItemContainer srcContainer = dragContainer.container;
        CRItemContainer dstContainer = m_Container;

        src.RebuildTexture();
        dst.RebuildTexture();

        if (srcContainer == dstContainer)
        {
            //this is a local move/swap
            if (dstContainer.IsSlotOccupied(dst.index))
            {
                dstContainer.GetComponent<CRItemContainerBinding>().NetworkSwapItem(src.index, dst.index);
            }
            else
            {
                dstContainer.GetComponent<CRItemContainerBinding>().NetworkMoveItem(src.index, dst.index);
            }
        }
        else
        {
            if (dstContainer.IsSlotOccupied(dst.index))
            {
                dstContainer.GetComponent<CRItemContainerBinding>().NetworkSwapItemFromContainer(srcContainer.networkView.viewID, src.index, dst.index);
            }
            else
            {
                dstContainer.GetComponent<CRItemContainerBinding>().NetworkMoveItemFromContainer(srcContainer.networkView.viewID, src.index, dst.index);
            }
        }
    }
Exemplo n.º 7
0
 public void OnUse(GUIItemSlot slot)
 {
     if (slot != null && slot.item != null)
     {
         Debug.Log ("Use " + slot.item + " from " + this);
     }
 }
Exemplo n.º 8
0
 public void ClearHover()
 {
     m_HoverSlot = null;
     m_Hovering = false;
 }
Exemplo n.º 9
0
 public void ClearDrag()
 {
     m_DragSlot = null;
     m_DragContainer = null;
     m_Dragging = false;
 }
Exemplo n.º 10
0
 public void SelectSlot(GUIItemSlot slot)
 {
     m_SelectedSlot = slot;
 }
Exemplo n.º 11
0
 public void Hover(GUIItemSlot slot)
 {
     m_HoverSlot = slot;
     m_Hovering = true;
 }
Exemplo n.º 12
0
 public void Drag(GUIItemSlot slot, GUIItemContainer container)
 {
     m_DragSlot = slot;
     m_DragContainer = container;
     m_Dragging = true;
 }