Skip to content
Snippets Groups Projects
Portrait.cs 4.76 KiB
Newer Older
Michael LaFreniere's avatar
Michael LaFreniere committed
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

Jordan's avatar
Jordan committed

Michael LaFreniere's avatar
Michael LaFreniere committed
// ** Can potentially merge with the money script.

Michael LaFreniere's avatar
Michael LaFreniere committed
// script to change the top left player portrait based on the player appearance and toggle the inventory panel.
Michael LaFreniere's avatar
Michael LaFreniere committed
public class Portrait : MonoBehaviour {

    private setAppearance appearance;
Michael LaFreniere's avatar
Michael LaFreniere committed
    private PlayerStats stats; // to access name
Michael LaFreniere's avatar
Michael LaFreniere committed
    public Text playerName;
    public Image face;
    public Image head;
    private Color characterColor;
    public Text healthBar;
    public Image healthBarRed;
Michael LaFreniere's avatar
Michael LaFreniere committed
    private CanvasGroup inventory; // to toggle the panel on and off
    private GameObject[] buttons; // to turn + buttons on/off
    public CanvasGroup helpText; // the 'CLICK HERE' below portrait
Michael LaFreniere's avatar
Michael LaFreniere committed

    // fields used to set the inventory panel information
    // stats
    public Text vitality;
    public Text strength;
    public Text defense;
    public Text agility;
    public Text luck;
    public Text unallocated;
    public static int unallocatedStats;
    // poitions
    public Text healthPotCount;
    public Text strengthPotCount;
    public Text defensePotCount;
    public Text agilityPotCount;
    // blessings
    public Image offenseBlessing;
    public Image defenseBlessing;
    public Image luckBlessing;


Michael LaFreniere's avatar
Michael LaFreniere committed
	void Start () {
Michael LaFreniere's avatar
Michael LaFreniere committed
        stats = GameObject.Find("Player").GetComponent<PlayerStats>();
        appearance = GameObject.Find("Player").GetComponent<setAppearance>();
Michael LaFreniere's avatar
Michael LaFreniere committed
        inventory = GameObject.Find("inventoryPanel").GetComponent<CanvasGroup>();
        buttons = GameObject.FindGameObjectsWithTag("incrementStat");
        healthBarRed = GameObject.Find("healthBarFullp").GetComponent<Image>();
        characterColor = appearance.getColor();
Michael LaFreniere's avatar
Michael LaFreniere committed
        playerName.text = stats.getName();
        face.sprite = appearance.getFace();
        head.sprite = appearance.getHead();
        head.color = characterColor;
        offenseBlessing.color = Color.white;
        defenseBlessing.color = Color.white;
        luckBlessing.color = Color.white;
        setInventory();
Michael LaFreniere's avatar
Michael LaFreniere committed
        // inventory initially invisible
        inventory.alpha = 0;
        inventory.interactable = false;
        inventory.blocksRaycasts = false;
        helpText.interactable = false;
        helpText.blocksRaycasts = false;
        if (ArenaCombatControl.winCount > 0) {
            helpText.alpha = 0;
        }
Michael LaFreniere's avatar
Michael LaFreniere committed
    }
    void Update() {
        if (PlayerStats.curHealth <= 0) {
            healthBarRed.enabled = false;
        }
        else {
            healthBarRed.enabled = true;
        }
        healthBar.text = PlayerStats.curHealth.ToString() + " / " + PlayerStats.maxHealth.ToString();
        healthBarRed.fillAmount = (float)PlayerStats.curHealth / PlayerStats.maxHealth;

        // to make + buttons appear when buying stats
        if (unallocatedStats > 0) {
            for (int i = 0; i < buttons.Length; i++) {
                buttons[i].SetActive(true);
            }
        }
        else {
            for (int i = 0; i < buttons.Length; i++) {
                buttons[i].SetActive(false);
            }
        }
    }

    public void setInventory() {
        // get stats
        vitality.text = PlayerStats.vitality.ToString();
        strength.text = PlayerStats.strength.ToString();
        defense.text = PlayerStats.defense.ToString();
        agility.text = PlayerStats.agility.ToString();
        luck.text = PlayerStats.luck.ToString();
        unallocated.text = unallocatedStats.ToString();
        stats.setMaxHealth();

        // get potions
        healthPotCount.text = PlayerStats.healthPotions.ToString();
        strengthPotCount.text = PlayerStats.strengthPotions.ToString();
        defensePotCount.text = PlayerStats.defensePotions.ToString();
        agilityPotCount.text = PlayerStats.agilityPotions.ToString();

        // get blessings
        if (PlayerStats.offenseBlessing == true) {
            offenseBlessing.color = Color.green; // show the blessing as active
        }
        if (PlayerStats.defenseBlessing == true) {
            defenseBlessing.color = Color.green; // show the blessing as active
        }
        if (PlayerStats.luckBlessing == true) {
            luckBlessing.color = Color.green; // show the blessing as active
        }
    }
Michael LaFreniere's avatar
Michael LaFreniere committed
	
    // when clicking the player's portrait
Michael LaFreniere's avatar
Michael LaFreniere committed
	public void OnClick() {
        if (inventory.alpha == 1) { // if the inventory screen is up
            inventory.alpha = 0; // hide
            inventory.interactable = false;
            inventory.blocksRaycasts = false;
        }
        else if (inventory.alpha == 0) { // if the inventory screen is hidden
            setInventory();
Michael LaFreniere's avatar
Michael LaFreniere committed
            inventory.alpha = 1; // show
            inventory.interactable = true;
            inventory.blocksRaycasts = true;
            // remove the helper text (CLICK HERE)
            helpText.alpha = 0;
Michael LaFreniere's avatar
Michael LaFreniere committed
}