public void dropItem() { if (grabbedSlot != null) { grabbedSlot.getItem().release(); grabbedSlot.releaseItem(null); grabbedSlot = null; } }
public void swapWith(MenuSlot releaseTo) { MenuSlotItem meTemp = this.getItem(); MenuSlotItem youTemp = releaseTo.getItem(); bool changedInventory = false; //If the two items can't be combined if (!combineSuccess(releaseTo)) { //Maybe add/remove the items to the home inventories //tip to future William: only use one | so the evaluation doesn't short curcuit changedInventory = changedInventory | maybeAddToInventory(releaseTo); changedInventory = changedInventory | maybeRemoveFromInventory(releaseTo); changedInventory = changedInventory | releaseTo.maybeAddToInventory(this); changedInventory = changedInventory | releaseTo.maybeRemoveFromInventory(this); //Swap them this.setItem(youTemp); releaseTo.setItem(meTemp); } if (changedInventory && releaseTo.type != SlotType.DisplaySlot) { HomeBaseUIController hbuic = GetComponentInParent <HomeBaseUIController>(); hbuic.updateInventoryItemCount(); } }
//Shifts all the flowers to the next slot in the list public void reSortFlowerList() { if (currentTab == TabType.Flowers) { int ii = 0; MenuSlotItem previousItem = null; while (ii < homeFlowerSlots.Count) { MenuSlot fromSlot = homeFlowerSlots[ii].GetComponent <MenuSlot>(); MenuSlotItem tempItem = fromSlot.getItem(); fromSlot.setItemNoSort(previousItem); previousItem = tempItem; //Break out of the lop if (previousItem == null) { break; } ii += 1; } if (previousItem != null) { Destroy(previousItem.gameObject); } } }
//Gathers all the items in the player inventory and stores them in the home inventory public void storeAllItems() { dropItem(); //get the 0th home inventory slot //MenuSlot storeSlot = homeFlowerSlots[0].GetComponent<MenuSlot>(); //Loop through the inventory for (int ii = 0; ii < fpc.inventorySize; ii += 1) { //Store the item if it's not null MenuSlot storeItemSlot = playerInventoryContainer.GetChild(ii).GetComponent <MenuSlot>(); MenuSlotItem storeItem = storeItemSlot.getItem(); if (storeItem != null) { storeItemSlot.storeItem(false); } } updateInventoryItemCount(); //If the player is in the flower tab then refresh the tab if (currentTab == TabType.Flowers) { SetFlowersTab(); } }
private void sellDecoration(uint id, int count) { if (grabbedSlot == null) { int toSell = count; try { if (homeDecorationsBought[id] < toSell) { toSell = homeDecorationsBought[id]; } homeDecorationsBought[id] -= toSell; fpc.money += (int)(toSell * decorationValue[(uint)id] * 0.75f); } catch { } //todo decrease item's count by count MenuSlot sellSlot = GameObject.Find("sellFlowerSlot").GetComponent <MenuSlot>(); //Reduce flower count by "adding" a negative value addHomeInventoryItem(id, -count, false); sellSlot.setCount(sellSlot.getCount() - count);//this is neg for some reason updateMoneyText(); updateFlowerDisplaySlot(sellSlot.getItem()); } }
private bool combineSuccess(MenuSlot releaseTo) { MenuSlotItem meTemp = this.getItem(); MenuSlotItem youTemp = releaseTo.getItem(); //If the two items should be merged if (this.getItem() != null && releaseTo.getItem() != null && meTemp.id == youTemp.id && meTemp.isFlower == youTemp.isFlower) { HomeBaseUIController hbuic = GetComponentInParent <HomeBaseUIController>(); if (releaseTo.type == SlotType.PlayerInventory)//if moving to inventory { hbuic.addHomeInventoryItem(releaseTo.getItem().id, -releaseTo.getItem().count, releaseTo.getItem().isFlower); } else if (this.type == SlotType.PlayerInventory)//if moving out of inventory { hbuic.addHomeInventoryItem(this.getItem().id, this.getItem().count, this.getItem().isFlower); } //Set the other item's count int oldCount = releaseTo.getItem().count; //Destroy the item in the other slot because the grabbed item will be stored GameObject.Destroy(releaseTo.getItem().gameObject); //Set the other slot to the grabbed item releaseTo.setItem(this.getItem()); releaseTo.setCount(oldCount + this.getItem().count); //Clear the item in the grabbed slot this.setItem(null); //It was successful so return true return(true); } return(false); }
//When the mouse is being held down public void ClickSlot(GameObject slot) { clickedOn = slot; //Debug.Log("Home base clicked: " + data.pointerCurrentRaycast.gameObject.name); MenuSlot slotClicked = clickedOn.GetComponent <MenuSlot>(); if (grabbedSlot == null) { //Grab the selected item if nothing is currently being selected if (slotClicked != null) { //If there's something in the slot to grab if (slotClicked.getItem() != null) { if (slotClicked.getItem().count > 0) { //If it's a slot with an item then grab it slotClicked.grabItem(); grabbedSlot = slotClicked; grabbedSlot.getItem().grab(); } } } } else { if (slotClicked.gameObject.name == "sellFlowerSlot" && grabbedSlot.getItem().isFlower != (currentTab == TabType.Flowers)) { } else { grabbedSlot.getItem().release(); grabbedSlot.releaseItem(slotClicked); grabbedSlot = null; } } }
//Sell the flower the given number of times private void sellFlower(uint flowerID, int sellAmount) { if (grabbedSlot == null) { MenuSlot sellSlot = GameObject.Find("sellFlowerSlot").GetComponent <MenuSlot>(); //this was for multiple sells since processflowersell allways sells one //fpc.money += HomeBaseController.instance.getFlowerValue(flowerID) * (sellAmount-1); HomeBaseController.instance.processFlowerSell(flowerID); //Reduce flower count by "adding" a negative value addHomeInventoryItem(flowerID, -sellAmount, true); sellSlot.setCount(sellSlot.getCount() - sellAmount); updateMoneyText(); updateFlowerDisplaySlot(sellSlot.getItem()); } }
/// <summary> /// Syncs the player inventory with the flowers in the player inventory home base panel /// </summary> private void PlayerInventorySync() { FlowerProperties fp = GameObject.Find("World").GetComponent <FlowerProperties>(); UIControllerScript uic = otherCanvas.GetComponent <UIControllerScript>(); //Now fill the other canvas and the UI inventory with the right items //Loop through the entire inventory for (int ii = 0; ii < fpc.inventorySize; ii++) { MenuSlot hInventoryItem = playerInventoryContainer.GetChild(ii).GetComponent <MenuSlot>(); Placeable slotPlaceable = uic.getInventoryDataAtSlot(ii); uint currentSlotID = 0; bool currentSlotIsFlower = false; if (slotPlaceable != null) { currentSlotID = slotPlaceable.id; currentSlotIsFlower = slotPlaceable.isFlower; } //If there's an item in the home base player inventory if (hInventoryItem.getItem() != null) { uic.inventoryClearSlot(ii); GameObject newObj; //Create a placeable based on the slot's id if (hInventoryItem.getItem().isFlower) { //Make a flower newObj = Instantiate(Resources.Load("Prefabs/FlowerPrefab", typeof(GameObject)) as GameObject); FlowerObj p = newObj.GetComponent <FlowerObj>(); p.id = hInventoryItem.getItem().id; int[] petal = new int[2] { fp.getPetalIndexFromIndex(p.id), fp.getPetalColorIndexFromIndex(p.id) }; int[] pistil = new int[2] { fp.getPistilIndexFromIndex(p.id), fp.getPistilColorIndexFromIndex(p.id) }; int[] leaf = new int[2] { fp.getLeafIndexFromIndex(p.id), fp.getLeafColorIndexFromIndex(p.id) }; int[] stem = new int[2] { fp.getStemIndexFromIndex(p.id), fp.getStemColorIndexFromIndex(p.id) }; int[] position = new int[2] { -1, -1 }; p.init(petal, stem, pistil, leaf, position, transform.root); p.alive = true; uic.setSlot(ii, p); uic.setSlotCount(ii, hInventoryItem.getItem().count); Destroy(newObj); } else { //Make a decoration newObj = Instantiate(fp.getDecorationObject(hInventoryItem.getItem().id)); Placeable p = newObj.GetComponent <Placeable>(); p.id = hInventoryItem.getItem().id; p.isFlower = hInventoryItem.getItem().isFlower; p.flowerGridPos = new int[2] { -1, -1 }; uic.setSlot(ii, p); uic.setSlotCount(ii, hInventoryItem.getItem().count); Destroy(newObj); } } else //If there's not an item in the home base player inventory slot { //Check to see if the player has an item in the inventory slot if (uic.getInventoryDataAtSlot(ii) != null) { //The player had an item in the slot but moved it to the home base //So clear the slot uic.inventoryClearSlot(ii); } } } }