Added images for left and right hand, added new item-hover display, added item drag animation, v1.3.0
This commit is contained in:
@@ -14,10 +14,12 @@ namespace Assets.Scripts
|
||||
int currentBag = 0;
|
||||
public ItemPlace place;
|
||||
Item equip;
|
||||
Inventory inventory;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
tooltip = GameObject.Find("TooltipHandler").GetComponent<TooltipHandler>();
|
||||
inventory = GameObject.Find("Inventory").GetComponent<Inventory>();
|
||||
loadImages();
|
||||
}
|
||||
|
||||
@@ -26,15 +28,15 @@ namespace Assets.Scripts
|
||||
this.currentBag = currentBag;
|
||||
}
|
||||
|
||||
public void setItem(Item item)
|
||||
public void setItem(Item item, int bag)
|
||||
{
|
||||
items[currentBag] = item;
|
||||
itemRemoved[currentBag] = false;
|
||||
items[bag] = item;
|
||||
itemRemoved[bag] = false;
|
||||
}
|
||||
|
||||
public Item getItem()
|
||||
public Item getItem(int bag)
|
||||
{
|
||||
return items[currentBag];
|
||||
return items[bag];
|
||||
}
|
||||
|
||||
public void removeItem()
|
||||
@@ -45,52 +47,82 @@ namespace Assets.Scripts
|
||||
|
||||
public void showTooltip()
|
||||
{
|
||||
Item item = getItemForTooltip();
|
||||
if (item != null)
|
||||
{
|
||||
inventory.itemDisplay.transform.Find("itemImage").GetComponent<RawImage>().texture = item.image;
|
||||
inventory.itemDisplay.transform.Find("itemImage").GetComponent<RawImage>().color = item.rarityColor;
|
||||
inventory.itemDisplay.transform.Find("itemName").GetComponent<Text>().text = item.getName();
|
||||
string text = "Stats:\r\n";
|
||||
Dictionary<string, int> attributes = item.getAttributes();
|
||||
foreach (string key in attributes.Keys)
|
||||
{
|
||||
text = text + key + ": " + attributes[key] + "\r\n";
|
||||
}
|
||||
inventory.itemDisplay.transform.Find("itemStats").GetComponent<Text>().text = text;
|
||||
int changeY = 0;
|
||||
if (inventory.itemDisplay.transform.localScale == new Vector3(0,0,0))
|
||||
{
|
||||
if (Input.mousePosition.y < Screen.height / 2)
|
||||
{
|
||||
changeY = -150;
|
||||
}
|
||||
inventory.itemDisplay.transform.position = new Vector3(Input.mousePosition.x - 175, Input.mousePosition.y - changeY, 0);
|
||||
}
|
||||
inventory.itemDisplay.transform.localScale = new Vector3(1, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private Item getItemForTooltip()
|
||||
{
|
||||
Item item = null;
|
||||
if (place == ItemPlace.BAG)
|
||||
{
|
||||
if (items[currentBag] != null)
|
||||
{
|
||||
string text = items[currentBag].getDisplayText();
|
||||
Item equip = GameObject.Find("Inventory").GetComponent<Inventory>().getEquip(items[currentBag].getPlace());
|
||||
if (equip != null)
|
||||
{
|
||||
text = "(Current)\r\n" + equip.getDisplayText() + "----------\r\n" + text;
|
||||
}
|
||||
tooltip.showTooltip(text);
|
||||
}
|
||||
item = items[currentBag];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (equip != null)
|
||||
{
|
||||
tooltip.showTooltip(equip.getDisplayText());
|
||||
}
|
||||
item = equip;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public void hideTooltip()
|
||||
{
|
||||
tooltip.hideToolTip();
|
||||
}
|
||||
|
||||
public void onClick()
|
||||
{
|
||||
removeItem();
|
||||
tooltip.hideToolTip();
|
||||
inventory.itemDisplay.transform.localScale = new Vector3(0,0,0);
|
||||
}
|
||||
|
||||
public void OnMouseDrag()
|
||||
{
|
||||
GameObject.Find("Inventory").GetComponent<Inventory>().setDrag(gameObject);
|
||||
inventory.setDrag(gameObject);
|
||||
Item toMove;
|
||||
if (place == ItemPlace.BAG)
|
||||
{
|
||||
toMove = items[currentBag];
|
||||
}
|
||||
else
|
||||
{
|
||||
toMove = equip;
|
||||
}
|
||||
if (toMove != null)
|
||||
{
|
||||
inventory.dragImage.GetComponent<RawImage>().color = toMove.rarityColor;
|
||||
inventory.dragImage.GetComponent<RawImage>().texture = toMove.image;
|
||||
inventory.dragImage.transform.position = new Vector3(Input.mousePosition.x - 50, Input.mousePosition.y - 50, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMouseUp()
|
||||
{
|
||||
GameObject startDrag = GameObject.Find("Inventory").GetComponent<Inventory>().getDrag();
|
||||
inventory.dragImage.GetComponent<RawImage>().color = new Color(0,0,0,0);
|
||||
inventory.dragImage.GetComponent<RawImage>().texture = null;
|
||||
inventory.dragImage.transform.position = new Vector3(0,0,0);
|
||||
GameObject startDrag = inventory.getDrag();
|
||||
Item item;
|
||||
bool isSwap = false;
|
||||
if (startDrag.GetComponent<InventorySlot>().place == ItemPlace.BAG)
|
||||
{
|
||||
item = startDrag.GetComponent<InventorySlot>().getItem();
|
||||
item = startDrag.GetComponent<InventorySlot>().getItem(currentBag);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -106,10 +138,19 @@ namespace Assets.Scripts
|
||||
{
|
||||
if (items[currentBag] != null)
|
||||
{
|
||||
startDrag.GetComponent<InventorySlot>().setItem(items[currentBag]);
|
||||
if (startDrag.GetComponent<InventorySlot>().place == ItemPlace.BAG)
|
||||
{
|
||||
startDrag.GetComponent<InventorySlot>().setItem(items[currentBag], currentBag);
|
||||
}
|
||||
else
|
||||
{
|
||||
startDrag.GetComponent<InventorySlot>().setEquip(items[currentBag]);
|
||||
inventory.calculateStatBoost(item.getAttributes(), false);
|
||||
inventory.calculateStatBoost(items[currentBag].getAttributes(), true);
|
||||
}
|
||||
isSwap = true;
|
||||
}
|
||||
setItem(item);
|
||||
setItem(item, currentBag);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -117,20 +158,23 @@ namespace Assets.Scripts
|
||||
{
|
||||
if (startDrag.GetComponent<InventorySlot>().place == ItemPlace.BAG)
|
||||
{
|
||||
startDrag.GetComponent<InventorySlot>().setItem(equip);
|
||||
startDrag.GetComponent<InventorySlot>().setItem(equip, currentBag);
|
||||
isSwap = true;
|
||||
inventory.calculateStatBoost(equip.getAttributes(), false);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
inventory.calculateStatBoost(item.getAttributes(), true);
|
||||
setEquip(item);
|
||||
}
|
||||
if (!isSwap)
|
||||
{
|
||||
if (startDrag.GetComponent<InventorySlot>().place != ItemPlace.BAG)
|
||||
{
|
||||
inventory.calculateStatBoost(startDrag.GetComponent<InventorySlot>().getEquip().getAttributes(), false);
|
||||
startDrag.GetComponent<InventorySlot>().removeEquip();
|
||||
}
|
||||
else
|
||||
@@ -174,7 +218,7 @@ namespace Assets.Scripts
|
||||
image = Resources.Load<Texture>("Equipment/Inv_Boots");
|
||||
break;
|
||||
case ItemPlace.SHOULDER:
|
||||
image = Resources.Load<Texture>("Equipment/Inv_Shoulder");
|
||||
image = Resources.Load<Texture>("Equipment/Inv_Shoulders");
|
||||
break;
|
||||
case ItemPlace.AMULET:
|
||||
image = Resources.Load<Texture>("Equipment/Inv_Amulet");
|
||||
|
||||
Reference in New Issue
Block a user