Files
fnl/Assets/Scripts/ShopItemController.cs
2026-02-21 16:40:15 -08:00

132 lines
5.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class ShopItemController : MonoBehaviour {
[SerializeField] public TextMeshProUGUI itemTitle;
[SerializeField] public TextMeshProUGUI itemCost;
[SerializeField] public TextMeshProUGUI itemDescription;
[SerializeField] public Image itemIcon;
[SerializeField] public Image soldIcon;
[SerializeField] public Image lockedIcon;
// The ID of the item you get for making the purchase.
[SerializeField] public Body body = Body.None;
[SerializeField] public Hair hair = Hair.None;
[SerializeField] public Food food = Food.None;
[SerializeField] public bool persist = true;
[SerializeField] public Michsky.MUIP.ButtonManager buyButton;
public VNObjectController assets;
ItemInfo itemInfo;
public void TryBuy() {
if (food != Food.None) {
if (GameData.GLOBAL.boughtFood) {
GameObject.FindWithTag("Notifier").GetComponent<NotifierController>().Notify(
"Purchase Failed",
"You've already fed her for now.");
return;
} else if (GameData.GLOBAL.hunger == 0) {
GameObject.FindWithTag("Notifier").GetComponent<NotifierController>().Notify(
"Purchase Failed",
"She's not hungry.");
return;
}
}
if (GameData.GLOBAL.money >= itemInfo.cost) {
GameData.GLOBAL.money -= itemInfo.cost;
if (body != Body.None) {
GameData.GLOBAL.unlockedOutfits.Add(body);
//UnlockSelectorController selector = GameObject.FindWithTag("OutfitSelector").GetComponent<UnlockSelectorController>();
GameObject.FindWithTag("Notifier").GetComponent<NotifierController>().Notify(
"New Outfit",
"Purchased outfit: " + itemInfo.name);
GameData.GLOBAL.affection += itemInfo.affection;
buyButton.gameObject.SetActive(false);
soldIcon.gameObject.SetActive(true);
//selector.UpdateUnlockedOutfits();
// TODO: Dialogue interact for buying outfit
// TODO: Auto-equip new outfit
}
if (hair != Hair.None) {
GameData.GLOBAL.unlockedHairs.Add(hair);
//UnlockSelectorController selector = GameObject.FindWithTag("HairSelector").GetComponent<UnlockSelectorController>();
GameObject.FindWithTag("Notifier").GetComponent<NotifierController>().Notify(
"New Hairstyle",
"Purchased hairstyle: " + itemInfo.name);
GameData.GLOBAL.affection += itemInfo.affection;
buyButton.gameObject.SetActive(false);
soldIcon.gameObject.SetActive(true);
//selector.UpdateUnlockedHairs();
// TODO: Dialogue interact for buying hairstyle
// TODO: Auto-equip new hairstyle
}
if (food != Food.None) {
// TODO: Do a food response thing
GameObject.FindWithTag("Notifier").GetComponent<NotifierController>().Notify(
"Gulp!",
"You fed her: " + itemInfo.name);
GameData.GLOBAL.boughtFood = true;
GameData.GLOBAL.Feed(food);
// TODO: Dialogue interact for buying food
GameObject.FindWithTag("Notifier").GetComponent<ManagerController>().FoodPurchased();
}
// TODO: some sort of buying animation and sound
if (!persist) {
Destroy(gameObject);
}
} else {
GameObject.FindWithTag("Notifier").GetComponent<NotifierController>().Notify(
"Purchase Failed",
"You can't afford that.");
}
}
void SetFields(ItemInfo info) {
itemInfo = info;
itemTitle.SetText(info.name);
itemCost.SetText("$" + info.cost.ToString());
}
public void SetFields(ItemInfo info, Body body) {
SetFields(info);
this.body = body;
itemDescription.SetText("");
bool sold = GameData.GLOBAL.unlockedOutfits.Contains(body);
bool forSale = !sold && GameData.GLOBAL.forSaleOutfits.Contains(body);
buyButton.gameObject.SetActive(!sold && forSale);
lockedIcon.gameObject.SetActive(!sold && !forSale);
soldIcon.gameObject.SetActive(sold);
itemIcon.sprite = assets.outfitIcons[(int)body - 1];
}
public void SetFields(ItemInfo info, Hair hair) {
SetFields(info);
this.hair = hair;
itemDescription.SetText("");
bool sold = GameData.GLOBAL.unlockedHairs.Contains(hair);
bool forSale = !sold && GameData.GLOBAL.forSaleHairs.Contains(hair);
buyButton.gameObject.SetActive(!sold && forSale);
lockedIcon.gameObject.SetActive(!sold && !forSale);
soldIcon.gameObject.SetActive(sold);
itemIcon.sprite = assets.hairIcons[(int)hair - 1];
}
public void SetFields(ItemInfo info, Food food) {
SetFields(info);
this.food = food;
itemDescription.SetText(info.description);
buyButton.gameObject.SetActive(true);
lockedIcon.gameObject.SetActive(false);
soldIcon.gameObject.SetActive(false);
// TODO: Set itemIcon.sprite
persist = true;
}
}