|
|
|
|
using MS;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Add list of achievements to screen
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class AchievenmentListIngame : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public GameObject scrollContent;
|
|
|
|
|
public GameObject prefab;
|
|
|
|
|
public Popup Menu;
|
|
|
|
|
public Dropdown Filter;
|
|
|
|
|
public Text CountText;
|
|
|
|
|
public Text CompleteText;
|
|
|
|
|
public Scrollbar Scrollbar;
|
|
|
|
|
private bool MenuOpen = false;
|
|
|
|
|
|
|
|
|
|
[Tooltip("Key used to open UI menu. Set to \"None\" to prevent menu from opening with any key press")]
|
|
|
|
|
// public KeyCode OpenMenuKey; //Key to open in-game menu
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds all achievements to the UI based on a filter
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Filter">Filter to use (All, Achieved or Unachieved)</param>
|
|
|
|
|
private void AddAchievements(string Filter)
|
|
|
|
|
{
|
|
|
|
|
foreach (Transform child in scrollContent.transform)
|
|
|
|
|
{
|
|
|
|
|
Destroy(child.gameObject);
|
|
|
|
|
}
|
|
|
|
|
AchievementManager AM = AchievementManager.instance;
|
|
|
|
|
int AchievedCount = AM.GetAchievedCount();
|
|
|
|
|
|
|
|
|
|
if (CountText)
|
|
|
|
|
CountText.text = "" + AchievedCount + " / " + AM.States.Count;
|
|
|
|
|
if (CompleteText)
|
|
|
|
|
CompleteText.text = "Complete (" + AM.GetAchievedPercentage() + "%)";
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < AM.AchievementList.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if ((Filter.Equals("All")) || (Filter.Equals("Achieved") && AM.States[i].Achieved) || (Filter.Equals("Unachieved") && !AM.States[i].Achieved))
|
|
|
|
|
{
|
|
|
|
|
AddAchievementToUI(AM.AchievementList[i], AM.States[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Scrollbar.value = 1;
|
|
|
|
|
}
|
|
|
|
|
public List<UIAchievement> Stack;
|
|
|
|
|
public void AddAchievementToUI(AchievementInfromation Achievement, AchievementState State)
|
|
|
|
|
{
|
|
|
|
|
UIAchievement UIAchievement = Instantiate(prefab, new Vector3(0f, 0f, 0f), Quaternion.identity).GetComponent<UIAchievement>();
|
|
|
|
|
Stack.Add(UIAchievement);
|
|
|
|
|
UIAchievement.Set(Achievement, State);
|
|
|
|
|
UIAchievement.transform.SetParent(scrollContent.transform);
|
|
|
|
|
UIAchievement.GetComponent<RectTransform>().localScale = Vector3.one;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Filter out a set of locked or unlocked achievements
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void ChangeFilter()
|
|
|
|
|
{
|
|
|
|
|
AddAchievements(Filter.options[Filter.value].text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Closes the UI window.
|
|
|
|
|
/// </summary>
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
AddAchievements("All");
|
|
|
|
|
Invoke(nameof(Starter), 0.5f);
|
|
|
|
|
}
|
|
|
|
|
public void Starter()
|
|
|
|
|
{
|
|
|
|
|
if (AchievementManager.instance.achievementListIngame == null)
|
|
|
|
|
{
|
|
|
|
|
AchievementManager.instance.achievementListIngame = this;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void CloseWindow()
|
|
|
|
|
{
|
|
|
|
|
MenuOpen = false;
|
|
|
|
|
Menu.Close();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Opens the UI window.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void OpenWindow()
|
|
|
|
|
{
|
|
|
|
|
MenuOpen = true;
|
|
|
|
|
Menu.Open();
|
|
|
|
|
Setter();
|
|
|
|
|
//AddAchievements("All");
|
|
|
|
|
}
|
|
|
|
|
void Setter()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < Stack.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (PlayerPrefs.GetInt("UIAchievement" + i + "Claimable") == 1)
|
|
|
|
|
{
|
|
|
|
|
PlayerPrefs.SetInt("UIAchievement" + i + "Claimable", 0);
|
|
|
|
|
Stack[i].ClaimButton.gameObject.SetActive(true);
|
|
|
|
|
Stack[i].CompleteToClaimButton.SetActive(false);
|
|
|
|
|
int numofCoinsToAdd = PlayerPrefs.GetInt("TotalCoinsForReward" + i);
|
|
|
|
|
Stack[i].ClaimButton.onClick.RemoveAllListeners();
|
|
|
|
|
Stack[i].ClaimButton.onClick.AddListener(() =>
|
|
|
|
|
{
|
|
|
|
|
AchievementManager.instance.AddCoins(numofCoinsToAdd);
|
|
|
|
|
PlayerPrefs.SetInt("TotalCoinsForReward" + i, 0);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Toggles the state of the UI window open or closed
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void ToggleWindow()
|
|
|
|
|
{
|
|
|
|
|
if (MenuOpen)
|
|
|
|
|
{
|
|
|
|
|
CloseWindow();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
OpenWindow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// private void Update()
|
|
|
|
|
// {
|
|
|
|
|
// if(Input.GetKeyDown(OpenMenuKey))
|
|
|
|
|
// {
|
|
|
|
|
// ToggleWindow();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
}
|