145 lines
5.2 KiB
C#
145 lines
5.2 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)
|
|
{
|
|
if (!abilitySlotsDropdowns[dropdownIndex].interactable) return;
|
|
|
|
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);
|
|
|
|
allClassAbilities = BuildLibrary.Instance.GetAllClassAbilities(buildManager.CharacterClass);
|
|
|
|
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].SetValueWithoutNotify(possibleAbilities.IndexOf(buildManager.SelectedBuildSlots[i].ability));
|
|
}
|
|
|
|
CheckForSlotUnlockables();
|
|
}
|
|
|
|
bool needsRefresh = false;
|
|
private void CheckForSlotUnlockables()
|
|
{
|
|
needsRefresh = false;
|
|
|
|
abilitySlotsDropdowns[0].interactable = true;
|
|
|
|
abilitySlotsDropdowns[1].interactable = playerCharacter.level.currentLevel >= GameConstants.GameBalancing.AbilitySlot_II_LevelRequired;
|
|
|
|
UnlockAbilityInCaseSlotIsAvailableButNotEnoughAbilitiesLearned(1);
|
|
|
|
abilitySlotsDropdowns[2].interactable = playerCharacter.level.currentLevel >= GameConstants.GameBalancing.AbilitySlot_III_LevelRequired;
|
|
|
|
UnlockAbilityInCaseSlotIsAvailableButNotEnoughAbilitiesLearned(2);
|
|
|
|
//abilitySlotsDropdowns[3].interactable = playerCharacter.level.currentLevel >= GameConstants.GameBalancing.AbilitySlot_IV_LevelRequired;
|
|
|
|
//UnlockAbilityInCaseSlotIsAvailableButNotEnoughAbilitiesLearned(3);
|
|
|
|
if (needsRefresh)
|
|
{
|
|
InitializeDropdowns();
|
|
needsRefresh = false;
|
|
}
|
|
}
|
|
|
|
List<BaseAbility> allClassAbilities = new List<BaseAbility>();
|
|
|
|
private void UnlockAbilityInCaseSlotIsAvailableButNotEnoughAbilitiesLearned(int index)
|
|
{
|
|
|
|
if (abilitySlotsDropdowns[index].interactable)
|
|
{
|
|
if (allClassAbilities.Count <= index) return;
|
|
|
|
if (!PlayerDataHandler.Instance.AbilityTomeUnlocked(PlayerDataHandler.Instance.currentPlayerName.Value, AbilityIndexer.Instance.Abilities.IndexOf(allClassAbilities[index])))
|
|
{
|
|
PlayerDataHandler.Instance.SaveAbilityTomeProgress(PlayerDataHandler.Instance.currentPlayerName.Value, AbilityIndexer.Instance.Abilities.IndexOf(allClassAbilities[index]), 10);
|
|
needsRefresh = true;
|
|
}
|
|
}
|
|
}
|
|
}
|