示例#1
0
    private void PlaceItem(GridItem item)
    {
        if (item.Orientation == GridItemOrient.Landscape)
        {
            item.Sprite.pivot = UIWidget.Pivot.BottomLeft;
        }
        else
        {
            item.Sprite.pivot = UIWidget.Pivot.TopLeft;
        }

        item.Sprite.transform.parent = item.Boundary.transform.parent;
        item.Sprite.depth            = (int)InventoryItemDepth.Normal;

        item.transform.localPosition = item.Boundary.transform.localPosition;
        InventoryGrid grid = item.transform.parent.GetComponent <InventoryGrid>();

        grid.GetColumnRowFromLocalPos(item.transform.localPosition, out item.ColumnPos, out item.RowPos);

        item.Quantity.transform.parent        = item.Sprite.transform.parent;
        item.Quantity.transform.localPosition = item.Sprite.transform.localPosition + new Vector3(4, 4, 0);

        NGUITools.AddWidgetCollider(item.gameObject);
        NGUITools.MarkParentAsChanged(_windowPanel.gameObject);
        //item.State = GridItemState.None;
        item.Initialize(FocusedGrid);
        FocusedGrid.Items.Add(item);

        SelectedItem    = null;
        FocusedBodySlot = null;

        GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("PlaceItemBackpack"), 0.2f);
    }
示例#2
0
    public GridItem AddGridItem(Item item, int colPos, int rowPos, GridItemOrient orientation, int quantity)
    {
        //don't allow rubles to show up in non player owned inventory
        if (item.ID == "rubles" && ParentPanel == GameManager.Inst.UIManager.WindowPanel.TraderItemPanel)
        {
            return(null);
        }

        //check if similar item already here
        foreach (GridItem i in Items)
        {
            if (i.Item.ID == item.ID)
            {
                int existingQuantity = i.GetQuantity();
                if (quantity <= i.Item.MaxStackSize - existingQuantity)
                {
                    i.SetQuantity(quantity + existingQuantity);
                    return(i);
                }
                else
                {
                    quantity = quantity - (i.Item.MaxStackSize - existingQuantity);
                    i.SetQuantity(i.Item.MaxStackSize);
                }
            }
        }

        //Debug.Log("orientation is " + orientation);
        GridItem item1 = LoadGridItem(item.SpriteName, orientation);

        item1.ColumnPos = colPos;
        item1.RowPos    = rowPos;
        item1.Sprite.transform.localPosition   = new Vector3(BlockSize * item1.ColumnPos, BlockSize * item1.RowPos, 0);
        item1.Boundary.transform.localPosition = item1.Sprite.transform.localPosition;
        item1.Quantity.transform.localPosition = item1.Sprite.transform.localPosition + new Vector3(4, 4, 0);
        item1.SetQuantity(quantity);
        item1.Item = item;
        Items.Add(item1);
        item1.Initialize(this);
        item1.IsPlayerOwned = IsPlayerOwned;

        return(item1);
    }