- ability unlocks (90% done) - class unlocks (working) - new human base class - bugfix small issues
106 lines
3.9 KiB
C#
106 lines
3.9 KiB
C#
using Kryz.CharacterStats.Examples;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class BuildManagerUIController : MonoBehaviour
|
|
{
|
|
[SerializeField] private List<TMP_Dropdown> abilitySlotsDropdowns = new List<TMP_Dropdown>();
|
|
|
|
[SerializeField] private GameEventListener_BuildManager onBuildManagerInitialized;
|
|
[SerializeField] private GameEventListener_Int onAbilityTomePageLearned;
|
|
|
|
BuildManager buildManager;
|
|
|
|
List<BaseAbility> possibleAbilities = new List<BaseAbility>();
|
|
List<TMP_Dropdown.OptionData> abilitiesOptions = new List<TMP_Dropdown.OptionData>();
|
|
|
|
TMP_Dropdown.OptionData optionData = new TMP_Dropdown.OptionData();
|
|
|
|
int pickedEntry;
|
|
string pickedEntryName;
|
|
BaseAbility ability;
|
|
PlayerCharacterStats playerCharacter;
|
|
|
|
private void Awake()
|
|
{
|
|
onBuildManagerInitialized.Response.AddListener(DependencyInjection);
|
|
|
|
onAbilityTomePageLearned.Response.AddListener((x) => InitializeDropdowns());
|
|
|
|
abilitySlotsDropdowns[0].onValueChanged.AddListener((x) => UpdateAbilitySlotOnDropdownValueChanged(0, x));
|
|
abilitySlotsDropdowns[1].onValueChanged.AddListener((x) => UpdateAbilitySlotOnDropdownValueChanged(1, x));
|
|
abilitySlotsDropdowns[2].onValueChanged.AddListener((x) => UpdateAbilitySlotOnDropdownValueChanged(2, x));
|
|
abilitySlotsDropdowns[3].onValueChanged.AddListener((x) => UpdateAbilitySlotOnDropdownValueChanged(3, x));
|
|
}
|
|
|
|
|
|
private void UpdateAbilitySlotOnDropdownValueChanged(int dropdownIndex, int pickedEntry)
|
|
{
|
|
ability = GetAbilityFromDropdown(dropdownIndex);
|
|
|
|
buildManager.UpdateBuildOnAbilitiesChanged(dropdownIndex, ability);
|
|
}
|
|
|
|
private BaseAbility GetAbilityFromDropdown(int dropdownIndex)
|
|
{
|
|
pickedEntry = abilitySlotsDropdowns[dropdownIndex].value;
|
|
|
|
return possibleAbilities[pickedEntry];
|
|
}
|
|
|
|
private void DependencyInjection(BuildManager buildManager)
|
|
{
|
|
this.buildManager = buildManager;
|
|
playerCharacter = buildManager.GetComponentInParent<PlayerCharacterStats>();
|
|
|
|
playerCharacter.level.OnLevelUpEvent.AddListener(CheckForSlotUnlockables);
|
|
|
|
InitializeDropdowns();
|
|
}
|
|
|
|
private void InitializeDropdowns()
|
|
{
|
|
possibleAbilities = BuildLibrary.Instance.GetUnlockedBaseAbilities(buildManager.CharacterClass);
|
|
|
|
abilitiesOptions.Clear();
|
|
|
|
for (int i = 0; i < possibleAbilities.Count; i++)
|
|
{
|
|
if (!PlayerDataHandler.Instance.AbilityTomeUnlocked(PlayerDataHandler.Instance.currentPlayerName.Value, AbilityIndexer.Instance.Abilities.IndexOf(possibleAbilities[i])))
|
|
{
|
|
continue;
|
|
}
|
|
optionData = new TMP_Dropdown.OptionData();
|
|
|
|
optionData.text = possibleAbilities[i].displayName;
|
|
optionData.image = possibleAbilities[i].Icon;
|
|
|
|
abilitiesOptions.Add(optionData);
|
|
}
|
|
|
|
for (int i = 0; i < abilitySlotsDropdowns.Count; i++)
|
|
{
|
|
abilitySlotsDropdowns[i].options.Clear();
|
|
|
|
abilitySlotsDropdowns[i].AddOptions(abilitiesOptions);
|
|
|
|
abilitySlotsDropdowns[i].RefreshShownValue();
|
|
|
|
abilitySlotsDropdowns[i].value = possibleAbilities.IndexOf(buildManager.SelectedBuildSlots[i].ability);
|
|
}
|
|
|
|
CheckForSlotUnlockables();
|
|
}
|
|
|
|
private void CheckForSlotUnlockables()
|
|
{
|
|
abilitySlotsDropdowns[0].interactable = true;
|
|
abilitySlotsDropdowns[1].interactable = playerCharacter.level.currentLevel >= GameConstants.GameBalancing.AbilitySlot_II_LevelRequired;
|
|
abilitySlotsDropdowns[2].interactable = playerCharacter.level.currentLevel >= GameConstants.GameBalancing.AbilitySlot_III_LevelRequired;
|
|
abilitySlotsDropdowns[3].interactable = playerCharacter.level.currentLevel >= GameConstants.GameBalancing.AbilitySlot_IV_LevelRequired;
|
|
}
|
|
}
|