Exemplo n.º 1
0
    private void PlaceItemInTempSlot(GridItem item)
    {
        AddItemToTempSlot(item, FocusedTempSlot);
        NGUITools.MarkParentAsChanged(_windowPanel.gameObject);
        SelectedItem    = null;
        FocusedTempSlot = null;

        GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("PlaceItemBackpack"), 0.2f);
    }
Exemplo n.º 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;
        item.IsPlayerOwned = true;
        item.ClearParentGrid();
    }
Exemplo n.º 3
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 &&
                !slot.TakeOnly)
            {
                tempSlot = slot;
                return(true);
            }
        }

        return(false);
    }
Exemplo n.º 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.IsPlayerOwned))
            {
                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;
                }
            }
        }
    }
Exemplo n.º 5
0
    public void OnPlaceItem(GridItem item)
    {
        if (SelectedItem == item && item.Boundary.alpha == 1)
        {
            if (FocusedTempSlot != null)
            {
                //place in temp slot
                GridItem existingItem = null;
                TempSlot temp         = FocusedTempSlot;
                if (FocusedTempSlot.Items.Count > 0)
                {
                    existingItem = FocusedTempSlot.Items[0];
                }
                FocusedTempSlot.Items.Clear();

                PlaceItemInTempSlot(item);

                if (_selectedItemLastList != null && _selectedItemLastList != temp.Items)
                {
                    _selectedItemLastList.Remove(item);
                    _selectedItemLastList = null;
                }

                if (existingItem != null && existingItem != item)
                {
                    PickupItem(existingItem);
                }
            }
            else if (FocusedBodySlot != null)
            {
                //place in body slot
                GridItem existingItem = null;
                BodySlot temp         = FocusedBodySlot;
                if (FocusedBodySlot.Items.Count > 0)
                {
                    existingItem = FocusedBodySlot.Items[0];
                }


                if (item.Item.Type == ItemType.Ammo && (FocusedBodySlot.AllowedItemType == ItemType.PrimaryWeapon || FocusedBodySlot.AllowedItemType == ItemType.SideArm))
                {
                    if (existingItem != null && (int)existingItem.Item.GetAttributeByName("_LoadedAmmos").Value <= 0 &&
                        (string)item.Item.GetAttributeByName("_Caliber").Value == (string)existingItem.Item.GetAttributeByName("_Caliber").Value)
                    {
                        existingItem.Item.SetAttribute("_LoadedAmmoID", item.Item.ID);
                        GameManager.Inst.UIManager.SetConsoleText("The weapon is now loading " + item.Item.Name);
                        GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("LoadAmmo"), 0.05f);
                    }
                    else if ((int)existingItem.Item.GetAttributeByName("_LoadedAmmos").Value > 0)
                    {
                        GameManager.Inst.UIManager.SetConsoleText("Weapon is still loaded, unload ammo first.");
                        GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("Error1"), 0.05f);
                    }
                    else if ((string)item.Item.GetAttributeByName("_Caliber").Value != (string)existingItem.Item.GetAttributeByName("_Caliber").Value)
                    {
                        GameManager.Inst.UIManager.SetConsoleText("Caliber doesn't match!");
                        GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("Error1"), 0.05f);
                    }
                }
                else
                {
                    FocusedBodySlot.Items.Clear();
                    PlaceItemInBodySlot(item);

                    if (_selectedItemLastList != null && _selectedItemLastList != temp.Items)
                    {
                        _selectedItemLastList.Remove(item);
                        _selectedItemLastList = null;
                    }


                    if (existingItem != null && existingItem != item)
                    {
                        PickupItem(existingItem);
                    }
                }
            }
            else if (FocusedGrid != null)
            {
                PlaceItem(item);

                if (_selectedItemLastList != null)
                {
                    _selectedItemLastList.Remove(item);
                    _selectedItemLastList = null;
                }

                if (ReplaceItem != null)
                {
                    Debug.Log("Replace item is not null");
                    //if replace item is same as item then try to combine the two
                    if (ReplaceItem.Item.ID == item.Item.ID && item.Item.MaxStackSize > 1)
                    {
                        int fill = item.Item.MaxStackSize - item.GetQuantity();
                        if (fill < ReplaceItem.GetQuantity())
                        {
                            item.SetQuantity(item.Item.MaxStackSize);
                            ReplaceItem.SetQuantity(ReplaceItem.GetQuantity() - fill);

                            PickupItem(ReplaceItem);
                            ReplaceItem.Sprite.alpha = 1;
                            ReplaceItem = null;
                        }
                        else
                        {
                            item.SetQuantity(item.GetQuantity() + ReplaceItem.GetQuantity());
                            FocusedGrid.Items.Remove(ReplaceItem);
                            DestroyItem(ReplaceItem);
                        }

                        RefreshItemTotals();

                        return;
                    }

                    //if replace item is not the same, but selected item is ammo and replace item is an empty gun that can use the ammo
                    //then load the gun with ammo
                    if (item.Item.Type == ItemType.Ammo && (ReplaceItem.Item.Type == ItemType.PrimaryWeapon || ReplaceItem.Item.Type == ItemType.SideArm))
                    {
                        if ((bool)ReplaceItem.Item.GetAttributeByName("_IsRanged").Value == true)
                        {
                            if ((int)ReplaceItem.Item.GetAttributeByName("_LoadedAmmos").Value <= 0 &&
                                (string)item.Item.GetAttributeByName("_Caliber").Value == (string)ReplaceItem.Item.GetAttributeByName("_Caliber").Value)
                            {
                                ReplaceItem.Item.SetAttribute("_LoadedAmmoID", item.Item.ID);
                                GameManager.Inst.UIManager.SetConsoleText("The weapon is now loading " + item.Item.Name);
                                GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("LoadAmmo"), 0.05f);
                            }
                            else if ((int)ReplaceItem.Item.GetAttributeByName("_LoadedAmmos").Value > 0)
                            {
                                GameManager.Inst.UIManager.SetConsoleText("Weapon is still loaded, unload ammo first.");
                                GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("Error1"), 0.05f);
                            }
                            else if ((string)item.Item.GetAttributeByName("_Caliber").Value != (string)ReplaceItem.Item.GetAttributeByName("_Caliber").Value)
                            {
                                GameManager.Inst.UIManager.SetConsoleText("Caliber doesn't match!");
                                GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("Error1"), 0.05f);
                            }

                            PickupItem(item);
                            RefreshItemTotals();
                            return;
                        }
                    }


                    PickupItem(ReplaceItem);
                    ReplaceItem.Sprite.alpha = 1;
                    ReplaceItem = null;
                }
            }
        }

        RefreshItemTotals();
    }
Exemplo n.º 6
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;
	}
Exemplo n.º 7
0
	private void PlaceItemInTempSlot(GridItem item)
	{
		AddItemToTempSlot(item, FocusedTempSlot);
		NGUITools.MarkParentAsChanged(_windowPanel.gameObject);
		SelectedItem = null;
		FocusedTempSlot = null;
	}
Exemplo n.º 8
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;
	}
Exemplo n.º 9
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;
				}
			}

		}


	}