Skip to content
Snippets Groups Projects
Commit 11c39c2b authored by Robin Halseth Sandvik's avatar Robin Halseth Sandvik
Browse files

Improved commenting and code readability.

parent 17ad2e6d
No related branches found
No related tags found
1 merge request!53ToolTips, new ability parameter system & misc clean ups.
......@@ -14,48 +14,57 @@ namespace BigSock.UI
public ItemPref item;
public Inventory inventory;
// Indicates if the special update code has ran yet.
bool firstRan = false;
public void Start() {
// Set the change indicator to false.
transform.hasChanged = false;
if(transform.hasChanged) {
//Debug.Log($"[ItemSlot.Start({GetInstanceID()})] {transform.position}");
}
}
public void Update() {
// If it hasn't ran before, and the position has changed, update the ItemPref.
/*
If it hasn't ran before, and the position has changed, update the ItemPref.
- This is to move the item to the item slot when it starts
- This has to be this way because the item slot is hoisted in the corner until this point.
*/
if(!firstRan && transform.hasChanged) {
transform.hasChanged = false;
firstRan = true;
if(item != null) {
//Debug.Log($"[ItemSlot.Update({GetInstanceID()})] Item: {item?.transform?.position}, Slot: {transform.position}");
if(item != null)
item.transform.position = transform.position;
}
}
}
public void OnDrop(PointerEventData eventData)
{
if (eventData.pointerDrag != null)
{
var itemPref = eventData.pointerDrag.GetComponent<ItemPref>();
if (itemPref != null)
{
var didMove = inventory.MoveItem(itemPref.item, itemPref.itemSlot.inventoryType,
itemPref.itemSlot.position, inventoryType, position);
if (didMove)
{
itemPref.itemSlot.item = null;
itemPref.itemSlot = this;
item = itemPref;
eventData.pointerDrag.transform.position = transform.position;
itemPref.position = null;
}
}
}
/*
When the user drops an item on this slot, try to move them
*/
public void OnDrop(PointerEventData eventData) {
// Get the item prefab that was dropped.
var itemPref = eventData?.pointerDrag?.GetComponent<ItemPref>();
// Cancel if we didn't move an item prefab, or it was empty.
if(itemPref?.item == null) return;
// Try to move the item in the inventory.
var didMove = inventory.MoveItem(
itemPref.item, itemPref.itemSlot.inventoryType,
itemPref.itemSlot.position, inventoryType,
position
);
// If we successfully moved the item in the inventory: update the gui.
if (didMove) {
itemPref.itemSlot.item = null; // Remove this from the other slot.
itemPref.itemSlot = this; // Make this its new slot.
item = itemPref; // Make it the item in this slot.
// Place the item centered over this slot.
eventData.pointerDrag.transform.position = transform.position;
itemPref.position = null;
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment