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