Пример #1
0
	public GridItemData(Item item, int colPos, int rowPos, GridItemOrient orientation, int quantity)
	{
		ColumnPos = colPos;
		RowPos = rowPos;
		Orientation = orientation;
		Item = item;
		Quantity = quantity;
	}
Пример #2
0
 public GridItemData(Item item, int colPos, int rowPos, GridItemOrient orientation, int quantity)
 {
     ColumnPos   = colPos;
     RowPos      = rowPos;
     Orientation = orientation;
     Item        = item;
     Quantity    = quantity;
 }
Пример #3
0
	public void AddGridItem(Item item, int colPos, int rowPos, GridItemOrient orientation, int quantity)
	{
		//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);
	}
Пример #4
0
    public void ToggleOrientation()
    {
        if (Orientation == GridItemOrient.Landscape)
        {
            Sprite.transform.localEulerAngles = new Vector3(0, 0, 90);
            if (State == GridItemState.None)
            {
                Sprite.pivot = UIWidget.Pivot.TopLeft;
            }
            else
            {
                Sprite.pivot = UIWidget.Pivot.Center;
            }

            Boundary.transform.localEulerAngles = new Vector3(0, 0, 90);
            Boundary.pivot = UIWidget.Pivot.TopLeft;

            int temp = ColumnSize;
            ColumnSize = RowSize;
            RowSize    = temp;

            Orientation = GridItemOrient.Portrait;
        }
        else
        {
            Sprite.transform.localEulerAngles = new Vector3(0, 0, 0);
            if (State == GridItemState.None)
            {
                Sprite.pivot = UIWidget.Pivot.BottomLeft;
            }
            else
            {
                Sprite.pivot = UIWidget.Pivot.Center;
            }

            Boundary.transform.localEulerAngles = new Vector3(0, 0, 0);
            Boundary.pivot = UIWidget.Pivot.BottomLeft;

            int temp = ColumnSize;
            ColumnSize = RowSize;
            RowSize    = temp;

            Orientation = GridItemOrient.Landscape;
        }

        NGUITools.AddWidgetCollider(gameObject);
    }
Пример #5
0
    public GridItem LoadGridItem(string itemID, GridItemOrient orientation)
    {
        GameObject o      = GameObject.Instantiate(Resources.Load("ItemSprite_" + itemID)) as GameObject;
        UISprite   sprite = o.GetComponent <UISprite>();
        GridItem   item   = o.GetComponent <GridItem>();

        o.transform.parent = transform;

        sprite.MakePixelPerfect();
        sprite.depth = (int)InventoryItemDepth.Normal;
        sprite.pivot = UIWidget.Pivot.Center;
        sprite.transform.localPosition = Vector3.zero;

        item.Sprite = sprite;

        //apply boundary
        o = GameObject.Instantiate(Resources.Load("ItemBoundary")) as GameObject;
        UISprite boundary = o.GetComponent <UISprite>();

        boundary.transform.parent = transform;
        boundary.MakePixelPerfect();
        boundary.width  = sprite.width;
        boundary.height = sprite.height;
        boundary.pivot  = UIWidget.Pivot.Center;
        boundary.transform.localPosition = Vector3.zero;

        item.Boundary = boundary;

        //quantity label
        o = GameObject.Instantiate(Resources.Load("ItemQuantity")) as GameObject;
        o.transform.parent     = transform;
        o.transform.localScale = new Vector3(1, 1, 1);
        item.Quantity          = o.GetComponent <UILabel>();;



        if (orientation == GridItemOrient.Portrait)
        {
            item.ToggleOrientation();
        }

        item.IsPlayerOwned = true;

        return(item);
    }
Пример #6
0
	public GridItem LoadGridItem(string itemID, GridItemOrient orientation)
	{
		GameObject o = GameObject.Instantiate(Resources.Load("ItemSprite_" + itemID)) as GameObject;
		UISprite sprite = o.GetComponent<UISprite>();
		GridItem item = o.GetComponent<GridItem>();
		o.transform.parent = transform;

		sprite.MakePixelPerfect();
		sprite.depth = (int)InventoryItemDepth.Normal;
		sprite.pivot = UIWidget.Pivot.Center;
		sprite.transform.localPosition = Vector3.zero;

		item.Sprite = sprite;

		//apply boundary
		o = GameObject.Instantiate(Resources.Load("ItemBoundary")) as GameObject;
		UISprite boundary = o.GetComponent<UISprite>();
		boundary.transform.parent = transform;
		boundary.MakePixelPerfect();
		boundary.width = sprite.width;
		boundary.height = sprite.height;
		boundary.pivot = UIWidget.Pivot.Center;
		boundary.transform.localPosition = Vector3.zero;

		item.Boundary = boundary;

		//quantity label
		o = GameObject.Instantiate(Resources.Load("ItemQuantity")) as GameObject;
		o.transform.parent = transform;
		o.transform.localScale = new Vector3(1, 1, 1);
		item.Quantity = o.GetComponent<UILabel>();;



		if(orientation == GridItemOrient.Portrait)
		{
			item.ToggleOrientation();
		}



		return item;

	}
Пример #7
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);
    }
Пример #8
0
    private GridItem LoadGridItem(string itemID, GridItemOrient orientation)
    {
        GameObject o      = GameObject.Instantiate(Resources.Load("ItemSprite_" + itemID)) as GameObject;
        UISprite   sprite = o.GetComponent <UISprite>();
        GridItem   item   = o.GetComponent <GridItem>();

        o.transform.parent = transform;


        sprite.MakePixelPerfect();
        sprite.width  = BlockSize * item.ColumnSize;
        sprite.height = BlockSize * item.RowSize;
        sprite.depth  = (int)InventoryItemDepth.Normal;
        item.Sprite   = sprite;

        //apply boundary
        o = GameObject.Instantiate(Resources.Load("ItemBoundary")) as GameObject;
        UISprite boundary = o.GetComponent <UISprite>();

        boundary.transform.parent = transform;
        boundary.MakePixelPerfect();
        boundary.width  = sprite.width;
        boundary.height = sprite.height;
        item.Boundary   = boundary;

        //quantity label
        o = GameObject.Instantiate(Resources.Load("ItemQuantity")) as GameObject;
        o.transform.parent     = transform;
        o.transform.localScale = new Vector3(1, 1, 1);
        item.Quantity          = o.GetComponent <UILabel>();
        item.Quantity.depth    = item.Sprite.depth + 1;

        if (orientation == GridItemOrient.Portrait)
        {
            item.ToggleOrientation();
        }



        return(item);
    }
Пример #9
0
	public bool FitItemInBackpack(Item item, out int colPos, out int rowPos, out GridItemOrient orientation)
	{
		int [,] grid = new int[BackpackCols, BackpackRows];

		//first fill the grid with information on which block has been occupied already by existing items
		foreach(GridItemData itemData in Backpack)
		{
			int cols = itemData.Item.GridCols;
			int rows = itemData.Item.GridRows;

			if(cols != rows && itemData.Orientation == GridItemOrient.Portrait)
			{
				cols = itemData.Item.GridRows;
				rows = itemData.Item.GridCols;
			}

			for(int x=0; x < cols; x++)
			{
				for(int y=0; y < rows; y++)
				{
					grid[itemData.ColumnPos + x, itemData.RowPos + y] = 1;
				}
			}
		}

		//check each block, if it's not occupied, see if it can fit the item in either orientation
		for(int i=0; i < BackpackCols; i++)
		{
			for(int j=0; j < BackpackRows; j++)
			{
				if(grid[i,j] == 0)
				{
					bool isOccupied = false;
					for(int x=0; x < item.GridCols; x++)
					{
						if(isOccupied || (i+x) >= BackpackCols)
						{
							isOccupied = true;
							break;
						}
						for(int y=0; y < item.GridRows; y++)
						{
							if((j+y) >= BackpackRows || grid[i+x, j+y] == 1)
							{
								isOccupied = true;
								break;
							}
						}
					}

					if(!isOccupied)
					{
						orientation = GridItemOrient.Landscape;
						colPos = i;
						rowPos = j;
						return true;
					}

					//if not square, check portrait
					isOccupied = false;
					if(item.GridCols != item.GridRows)
					{
						for(int x=0; x < item.GridRows; x++)
						{
							if(isOccupied || (i+x) >= BackpackCols)
							{
								isOccupied = true;
								break;
							}
							for(int y=0; y < item.GridCols; y++)
							{
								if((j+y) >= BackpackRows || grid[i+x, j+y] == 1)
								{
									//Debug.Log(" " + (i+x) + ", " + (j+y) + " is occupied");
									isOccupied = true;
									break;
								}
							}
						}

						if(!isOccupied)
						{
							orientation = GridItemOrient.Portrait;
							colPos = i;
							rowPos = j;
							return true;
						}
					}
				}
			}
		}

		colPos = 0;
		rowPos = 0;
		orientation = GridItemOrient.Landscape;
		return false;
	}
Пример #10
0
    public bool FitItemInBackpack(Item item, out int colPos, out int rowPos, out GridItemOrient orientation)
    {
        int [,] grid = new int[BackpackCols, BackpackRows];

        //first fill the grid with information on which block has been occupied already by existing items
        foreach (GridItemData itemData in Backpack)
        {
            int cols = itemData.Item.GridCols;
            int rows = itemData.Item.GridRows;

            if (cols != rows && itemData.Orientation == GridItemOrient.Portrait)
            {
                cols = itemData.Item.GridRows;
                rows = itemData.Item.GridCols;
            }

            for (int x = 0; x < cols; x++)
            {
                for (int y = 0; y < rows; y++)
                {
                    grid[itemData.ColumnPos + x, itemData.RowPos + y] = 1;
                }
            }
        }

        //check each block, if it's not occupied, see if it can fit the item in either orientation
        for (int i = 0; i < BackpackCols; i++)
        {
            for (int j = 0; j < BackpackRows; j++)
            {
                if (grid[i, j] == 0)
                {
                    bool isOccupied = false;
                    for (int x = 0; x < item.GridCols; x++)
                    {
                        if (isOccupied || (i + x) >= BackpackCols)
                        {
                            isOccupied = true;
                            break;
                        }
                        for (int y = 0; y < item.GridRows; y++)
                        {
                            if ((j + y) >= BackpackRows || grid[i + x, j + y] == 1)
                            {
                                isOccupied = true;
                                break;
                            }
                        }
                    }

                    if (!isOccupied)
                    {
                        orientation = GridItemOrient.Landscape;
                        colPos      = i;
                        rowPos      = j;
                        return(true);
                    }

                    //if not square, check portrait
                    isOccupied = false;
                    if (item.GridCols != item.GridRows)
                    {
                        for (int x = 0; x < item.GridRows; x++)
                        {
                            if (isOccupied || (i + x) >= BackpackCols)
                            {
                                isOccupied = true;
                                break;
                            }
                            for (int y = 0; y < item.GridCols; y++)
                            {
                                if ((j + y) >= BackpackRows || grid[i + x, j + y] == 1)
                                {
                                    //Debug.Log(" " + (i+x) + ", " + (j+y) + " is occupied");
                                    isOccupied = true;
                                    break;
                                }
                            }
                        }

                        if (!isOccupied)
                        {
                            orientation = GridItemOrient.Portrait;
                            colPos      = i;
                            rowPos      = j;
                            return(true);
                        }
                    }
                }
            }
        }

        colPos      = 0;
        rowPos      = 0;
        orientation = GridItemOrient.Landscape;
        return(false);
    }
Пример #11
0
	public void ToggleOrientation()
	{
		if(Orientation == GridItemOrient.Landscape)
		{
			Sprite.transform.localEulerAngles = new Vector3(0, 0, 90);
			if(State == GridItemState.None)
			{
				Sprite.pivot = UIWidget.Pivot.TopLeft;
			}
			else
			{
				Sprite.pivot = UIWidget.Pivot.Center;
			}

			Boundary.transform.localEulerAngles = new Vector3(0, 0, 90);
			Boundary.pivot = UIWidget.Pivot.TopLeft;

			int temp = ColumnSize;
			ColumnSize = RowSize;
			RowSize = temp;

			Orientation = GridItemOrient.Portrait;
		}
		else
		{
			Sprite.transform.localEulerAngles = new Vector3(0, 0, 0);
			if(State == GridItemState.None)
			{
				Sprite.pivot = UIWidget.Pivot.BottomLeft;
			}
			else
			{
				Sprite.pivot = UIWidget.Pivot.Center;
			}

			Boundary.transform.localEulerAngles = new Vector3(0, 0, 0);
			Boundary.pivot = UIWidget.Pivot.BottomLeft;

			int temp = ColumnSize;
			ColumnSize = RowSize;
			RowSize = temp;

			Orientation = GridItemOrient.Landscape;
		}

		NGUITools.AddWidgetCollider(gameObject);
	}
Пример #12
0
	private GridItem LoadGridItem(string itemID, GridItemOrient orientation)
	{
		GameObject o = GameObject.Instantiate(Resources.Load("ItemSprite_" + itemID)) as GameObject;
		UISprite sprite = o.GetComponent<UISprite>();
		GridItem item = o.GetComponent<GridItem>();
		o.transform.parent = transform;

		sprite.MakePixelPerfect();
		sprite.width = BlockSize * item.ColumnSize;
		sprite.height = BlockSize * item.RowSize;
		sprite.depth = (int)InventoryItemDepth.Normal;
		item.Sprite = sprite;

		//apply boundary
		o = GameObject.Instantiate(Resources.Load("ItemBoundary")) as GameObject;
		UISprite boundary = o.GetComponent<UISprite>();
		boundary.transform.parent = transform;
		boundary.MakePixelPerfect();
		boundary.width = sprite.width;
		boundary.height = sprite.height;
		item.Boundary = boundary;

		//quantity label
		o = GameObject.Instantiate(Resources.Load("ItemQuantity")) as GameObject;
		o.transform.parent = transform;
		o.transform.localScale = new Vector3(1, 1, 1);
		item.Quantity = o.GetComponent<UILabel>();
		item.Quantity.depth = item.Sprite.depth + 1;

		if(orientation == GridItemOrient.Portrait)
		{
			item.ToggleOrientation();
		}



		return item;

	}