Example #1
0
	public bool FindNearestTempSlot(out TempSlot tempSlot, Vector3 centerPos, List<TempSlot> tempSlots)
	{
		tempSlot = null;

		foreach(TempSlot slot in tempSlots)
		{
			if(centerPos.x >= slot.transform.localPosition.x - slot.Background.width/2 && centerPos.x <= slot.transform.localPosition.x + slot.Background.width/2 &&
				centerPos.y >= slot.transform.localPosition.y - slot.Background.height/2 && centerPos.y <= slot.transform.localPosition.y + slot.Background.height/2)
			{
				tempSlot = slot;
				return true;
			}
		}

		return false;
	}
Example #2
0
	public void AddItemToTempSlot(GridItem item, TempSlot slot)
	{
		item.Sprite.pivot = UIWidget.Pivot.Center;

		item.Sprite.transform.parent = item.Boundary.transform.parent;

		if(item.IsRotatable)
		{
			if(item.Orientation == GridItemOrient.Portrait)
			{
				int temp = item.ColumnSize;
				item.ColumnSize = item.RowSize;
				item.RowSize = temp;

				item.Orientation = GridItemOrient.Landscape;
				item.transform.localEulerAngles = new Vector3(0, 0, 0);
			}

			if(item.Sprite.width > item.Sprite.height)
			{
				item.Sprite.width = slot.Background.width;
				item.Sprite.height = Mathf.FloorToInt(item.Sprite.width * ((item.RowSize * 1f) / item.ColumnSize));
			}
			else
			{
				item.Sprite.height = slot.Background.height;
				item.Sprite.width = Mathf.FloorToInt(item.Sprite.height * ((item.ColumnSize * 1f) / item.RowSize));
			}
		}
		else
		{
			item.Sprite.width = slot.Background.width;
			item.Sprite.height = item.Sprite.width;
		}

		item.Boundary.width = slot.Background.width - 10;
		item.Boundary.height = slot.Background.height - 10;

		item.Sprite.depth = (int)InventoryItemDepth.Normal;
		item.Quantity.depth = item.Sprite.depth + 1;
		item.transform.localPosition = item.Boundary.transform.localPosition;
		item.Quantity.transform.localPosition = slot.transform.localPosition - new Vector3(slot.Background.width/2f - 8, slot.Background.height/2f - 8, 0);
		NGUITools.AddWidgetCollider(item.gameObject);
		item.State = GridItemState.None;
		slot.Items.Add(item);
		slot.PrevColPos = item.ColumnPos;
		slot.PrevRowPos = item.RowPos;
		slot.Owner = GameManager.Inst.PlayerControl.SelectedPC;
	}
Example #3
0
	private void PlaceItemInTempSlot(GridItem item)
	{
		AddItemToTempSlot(item, FocusedTempSlot);
		NGUITools.MarkParentAsChanged(_windowPanel.gameObject);
		SelectedItem = null;
		FocusedTempSlot = null;
	}
Example #4
0
	public override void PerFrameUpdate ()
	{
		//make item sprite follow cursor
		if(SelectedItem != null)
		{
			Vector3 pos = Input.mousePosition;
			pos.x = Mathf.Clamp01(pos.x / Screen.width);
			pos.y = Mathf.Clamp01(pos.y / Screen.height);
			SelectedItem.Sprite.transform.position = GameManager.Inst.UIManager.UICamera.ViewportToWorldPoint(pos);
			SelectedItem.Quantity.transform.localPosition = SelectedItem.Sprite.transform.localPosition 
				- new Vector3(SelectedItem.ColumnSize * BackpackGrid.BlockSize / 2f - 4, SelectedItem.RowSize * BackpackGrid.BlockSize / 2f - 4);
			Vector3 centerPos = SelectedItem.Sprite.transform.localPosition;

			//find nearest fitting slot for selected item and move the boundary there
			int fitColumn = 0;
			int fitRow = 0;


			List<InventoryGrid> grids = _windowPanel.FindInventoryGrids();
			if(FindNearestGridSlot(grids, out fitColumn, out fitRow))
			{
				SelectedItem.Boundary.transform.parent = FocusedGrid.transform;
				if(SelectedItem.Orientation == GridItemOrient.Landscape)
				{
					SelectedItem.Boundary.pivot = UIWidget.Pivot.BottomLeft;
				}
				else
				{
					SelectedItem.Boundary.pivot = UIWidget.Pivot.TopLeft;
				}

				SelectedItem.Boundary.transform.localEulerAngles = SelectedItem.Sprite.transform.localEulerAngles;

				SelectedItem.Boundary.width = SelectedItem.Sprite.width;
				SelectedItem.Boundary.height = SelectedItem.Sprite.height;
				SelectedItem.Boundary.transform.localPosition = new Vector3(fitColumn * BackpackGrid.BlockSize, fitRow * BackpackGrid.BlockSize, 0);
				SelectedItem.Boundary.alpha = 1;
				SelectedItem.ColumnPos = fitColumn;
				SelectedItem.RowPos = fitRow;

				FocusedBodySlot = null;
			}
			else
			{
				SelectedItem.Boundary.alpha = 0;
				FocusedBodySlot = null;
				if(ReplaceItem != null)
				{
					ReplaceItem.Sprite.alpha = 1;
				}
			}

			List<BodySlot> bodySlots = _windowPanel.FindBodySlots();
			BodySlot fitSlot;
			if(bodySlots.Count > 0)
			{

				if(FindNearestBodySlot(out fitSlot, centerPos, bodySlots, SelectedItem.Item.Type))
				{
					FocusedBodySlot = fitSlot;
					SelectedItem.Boundary.transform.parent = FocusedBodySlot.transform;
					SelectedItem.Boundary.pivot = UIWidget.Pivot.Center;
					SelectedItem.Boundary.transform.localEulerAngles = Vector3.zero;

					SelectedItem.Boundary.width = FocusedBodySlot.Background.width - 10;
					SelectedItem.Boundary.height = FocusedBodySlot.Background.height - 10;
					SelectedItem.Boundary.transform.localPosition = Vector3.zero;


					SelectedItem.Boundary.alpha = 1;
				}
				else
				{
					FocusedBodySlot = null;
				}
			}

			List<TempSlot> tempSlots = _windowPanel.FindTempSlots();
			TempSlot tempSlot;
			if(tempSlots.Count > 0)
			{

				if(FindNearestTempSlot(out tempSlot, centerPos, tempSlots))
				{
					FocusedTempSlot = tempSlot;
					SelectedItem.Boundary.transform.parent = FocusedTempSlot.transform;
					SelectedItem.Boundary.pivot = UIWidget.Pivot.Center;
					SelectedItem.Boundary.transform.localEulerAngles = Vector3.zero;

					SelectedItem.Boundary.width = FocusedTempSlot.Background.width - 10;
					SelectedItem.Boundary.height = FocusedTempSlot.Background.height - 10;
					SelectedItem.Boundary.transform.localPosition = Vector3.zero;


					SelectedItem.Boundary.alpha = 1;
				}
				else
				{
					FocusedTempSlot = null;
				}
			}

		}


	}