Skip to content
Snippets Groups Projects
Commit f48abc44 authored by DESKTOP-OVNO2Q1\alexa's avatar DESKTOP-OVNO2Q1\alexa
Browse files

Added tool tip to chest display items. Also cleaned up code and fixed bug

parent c8ccd2a6
No related branches found
No related tags found
2 merge requests!75Main,!65Added tool tip to chest display items. Also cleaned up code and fixed bug
...@@ -38,13 +38,12 @@ namespace BigSock.Service { ...@@ -38,13 +38,12 @@ namespace BigSock.Service {
} }
public List<IItem> Get3Random() { public List<IItem> Get3Random() {
List<IItem> tempItemList = _itemList;
List<IItem> returnList = new List<IItem>(); List<IItem> returnList = new List<IItem>();
var num = 0; while (returnList.Count < 3) {
for(int i = 0; i < 3; i++) { IItem random = _itemList[_rnd.Next(_itemList.Count)];
num = _rnd.Next(tempItemList.Count); if(!returnList.Contains(random)) {
returnList.Add(tempItemList[num]); returnList.Add(random);
tempItemList.Remove(tempItemList[num]); }
} }
return returnList; return returnList;
} }
......
...@@ -13,62 +13,53 @@ using UnityEditor; ...@@ -13,62 +13,53 @@ using UnityEditor;
namespace BigSock.UI { namespace BigSock.UI {
public class ChestDisplay : MonoBehaviour public class ChestDisplay : MonoBehaviour
{ {
public Button item1Button, item2Button, item3Button, closeButton; public Button closeButton;
public IItem item1, item2, item3;
public List<IItem> items; public List<IItem> items;
public List<Button> buttons;
public GameObject other; public GameObject other;
public GameObject chest; public GameObject chest;
PlayerController player; PlayerController player;
// Update is called once per frame
void Start() { void Start() {
var itemButtonLocation = transform.Find("ItemBox").Find("ItemBoxBackground"); var itemButtonLocation = transform.Find("ItemBox").Find("ItemBoxBackground");
buttons = new List<Button>();
item1Button = itemButtonLocation.transform.Find("ButtonItem1").GetComponent<Button>(); // Gets button gameobjects and adds onClick listener
item1Button.onClick.AddListener(ItemPicked1); for (int i = 0; i < 3; i++) {
var button = itemButtonLocation.transform.Find("ButtonItem"+(i+1).ToString()).GetComponent<Button>();
item2Button = itemButtonLocation.transform.Find("ButtonItem2").GetComponent<Button>(); button.onClick.AddListener(delegate {ItemPicked(i+1); });
item2Button.onClick.AddListener(ItemPicked2); buttons.Add(button);
}
item3Button = itemButtonLocation.transform.Find("ButtonItem3").GetComponent<Button>();
item3Button.onClick.AddListener(ItemPicked3);
// The X button :)
closeButton = transform.Find("CloseButton").GetComponent<Button>(); closeButton = transform.Find("CloseButton").GetComponent<Button>();
closeButton.onClick.AddListener(manuallyCloseWindow); closeButton.onClick.AddListener(manuallyCloseWindow);
// list of random items
items = chest.transform.GetComponent<Chest>().GetChestItems(); items = chest.transform.GetComponent<Chest>().GetChestItems();
item1 = items[0];
item2 = items[1];
item3 = items[2];
item1Button.gameObject.transform.Find("Item").GetComponent<Image>().sprite = ItemService.SINGLETON.Get(item1.Id).Icon; // Sets Item icon and name
item1Button.gameObject.transform.Find("ItemName").GetComponent<TMPro.TMP_Text>().text = ItemService.SINGLETON.Get(item1.Id).Name; for (int i = 0; i < buttons.Count; i++) {
buttons[i].gameObject.transform.Find("Item").GetComponent<Image>().sprite = ItemService.SINGLETON.Get(items[i].Id).Icon;
item2Button.gameObject.transform.Find("Item").GetComponent<Image>().sprite = ItemService.SINGLETON.Get(item2.Id).Icon; buttons[i].gameObject.transform.Find("ItemName").GetComponent<TMPro.TMP_Text>().text = ItemService.SINGLETON.Get(items[i].Id).Name;
item2Button.gameObject.transform.Find("ItemName").GetComponent<TMPro.TMP_Text>().text = ItemService.SINGLETON.Get(item2.Id).Name; }
item3Button.gameObject.transform.Find("Item").GetComponent<Image>().sprite = ItemService.SINGLETON.Get(item3.Id).Icon;
item3Button.gameObject.transform.Find("ItemName").GetComponent<TMPro.TMP_Text>().text = ItemService.SINGLETON.Get(item3.Id).Name;
this.other = GameObject.FindWithTag("Player"); this.other = GameObject.FindWithTag("Player");
player = other.GetComponent<PlayerController>(); player = other.GetComponent<PlayerController>();
if (player.Inventory.AddItem(null) == -1) { if (player.Inventory.AddItem(null) == -1) {
item1Button.interactable = false; for (int i = 0; i < buttons.Count; i++) {
item2Button.interactable = false; buttons[i].interactable = false;
item3Button.interactable = false; }
transform.Find("Banner").Find("BannerBackground").Find("BannerExtraText").GetComponent<TMPro.TMP_Text>().text = "Inventory is full, free up some space to select an item"; transform.Find("Banner").Find("BannerBackground").Find("BannerExtraText").GetComponent<TMPro.TMP_Text>().text = "Inventory is full, free up some space to select an item";
} }
} }
public void ShowItemDescription(GameObject button) { public void ShowItemDescription(GameObject button) {
string[] buttonNumber = button.name.Split("ButtonItem"); string[] buttonNumber = button.name.Split("ButtonItem");
button.transform.Find("ItemDescription").GetComponent<TMPro.TMP_Text>().text = items[int.Parse(buttonNumber[1])-1].Description; button.transform.Find("ItemDescription").GetComponent<TMPro.TMP_Text>().text = items[int.Parse(buttonNumber[1])-1].GetToolTip();
button.transform.Find("Item").GetComponent<Image>().color = Color.grey; button.transform.Find("Item").GetComponent<Image>().color = Color.clear;
} }
public void HideItemDescription(GameObject button) { public void HideItemDescription(GameObject button) {
...@@ -76,10 +67,6 @@ namespace BigSock.UI { ...@@ -76,10 +67,6 @@ namespace BigSock.UI {
button.transform.Find("Item").GetComponent<Image>().color = Color.white; button.transform.Find("Item").GetComponent<Image>().color = Color.white;
} }
private void OnPointerEnter() {
}
private void Update() { private void Update() {
if (Input.GetKeyDown(KeyCode.Escape)){ //|| Input.GetKeyDown(KeyCode.Mouse1)) { if (Input.GetKeyDown(KeyCode.Escape)){ //|| Input.GetKeyDown(KeyCode.Mouse1)) {
manuallyCloseWindow(); manuallyCloseWindow();
...@@ -91,30 +78,15 @@ namespace BigSock.UI { ...@@ -91,30 +78,15 @@ namespace BigSock.UI {
Destroy(this.gameObject); Destroy(this.gameObject);
} }
// Gets the chest element the display belongs to
public void setChestObject(GameObject chestInstance) { public void setChestObject(GameObject chestInstance) {
chest = chestInstance; chest = chestInstance;
} }
void showItemDescription() {
}
void ItemPicked1() {
ItemPicked(1);
}
void ItemPicked2() {
ItemPicked(2);
}
void ItemPicked3() {
ItemPicked(3);
}
void ItemPicked(int number) { void ItemPicked(int number) {
if (number == 1) {player.TryPickUpItem(ItemService.SINGLETON.Get(item1.Id));} if (number == 1) {player.TryPickUpItem(ItemService.SINGLETON.Get(items[number-1].Id));}
else if (number == 2) {player.TryPickUpItem(ItemService.SINGLETON.Get(item2.Id));} else if (number == 2) {player.TryPickUpItem(ItemService.SINGLETON.Get(items[number-1].Id));}
else if (number == 3) {player.TryPickUpItem(ItemService.SINGLETON.Get(item3.Id));} else if (number == 3) {player.TryPickUpItem(ItemService.SINGLETON.Get(items[number-1].Id));}
Destroy(this.gameObject); Destroy(this.gameObject);
} }
} }
......
...@@ -370,8 +370,8 @@ RectTransform: ...@@ -370,8 +370,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1} m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: -25} m_AnchoredPosition: {x: 0, y: -27.5}
m_SizeDelta: {x: -40, y: -90} m_SizeDelta: {x: -40, y: -95}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &8214718043214627680 --- !u!222 &8214718043214627680
CanvasRenderer: CanvasRenderer:
...@@ -428,8 +428,8 @@ MonoBehaviour: ...@@ -428,8 +428,8 @@ MonoBehaviour:
m_faceColor: m_faceColor:
serializedVersion: 2 serializedVersion: 2
rgba: 4294967295 rgba: 4294967295
m_fontSize: 24 m_fontSize: 16
m_fontSizeBase: 24 m_fontSizeBase: 16
m_fontWeight: 400 m_fontWeight: 400
m_enableAutoSizing: 0 m_enableAutoSizing: 0
m_fontSizeMin: 18 m_fontSizeMin: 18
...@@ -1426,8 +1426,8 @@ RectTransform: ...@@ -1426,8 +1426,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1} m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: -25} m_AnchoredPosition: {x: 0, y: -27.5}
m_SizeDelta: {x: -40, y: -90} m_SizeDelta: {x: -40, y: -95}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &540216411197347177 --- !u!222 &540216411197347177
CanvasRenderer: CanvasRenderer:
...@@ -1484,8 +1484,8 @@ MonoBehaviour: ...@@ -1484,8 +1484,8 @@ MonoBehaviour:
m_faceColor: m_faceColor:
serializedVersion: 2 serializedVersion: 2
rgba: 4294967295 rgba: 4294967295
m_fontSize: 24 m_fontSize: 16
m_fontSizeBase: 24 m_fontSizeBase: 16
m_fontWeight: 400 m_fontWeight: 400
m_enableAutoSizing: 0 m_enableAutoSizing: 0
m_fontSizeMin: 18 m_fontSizeMin: 18
...@@ -1637,8 +1637,8 @@ RectTransform: ...@@ -1637,8 +1637,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1} m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: -25} m_AnchoredPosition: {x: 0, y: -27.5}
m_SizeDelta: {x: -40, y: -90} m_SizeDelta: {x: -40, y: -95}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &2545237751018405972 --- !u!222 &2545237751018405972
CanvasRenderer: CanvasRenderer:
...@@ -1695,8 +1695,8 @@ MonoBehaviour: ...@@ -1695,8 +1695,8 @@ MonoBehaviour:
m_faceColor: m_faceColor:
serializedVersion: 2 serializedVersion: 2
rgba: 4294967295 rgba: 4294967295
m_fontSize: 24 m_fontSize: 16
m_fontSizeBase: 24 m_fontSizeBase: 16
m_fontWeight: 400 m_fontWeight: 400
m_enableAutoSizing: 0 m_enableAutoSizing: 0
m_fontSizeMin: 18 m_fontSizeMin: 18
......
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