2022-07-12 14:33:21 +02:00

97 lines
2.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.Scripts
{
public class QuestLog : MonoBehaviour
{
public Dictionary<string, List<Quest>> quests;
public GameObject content;
public Scrollbar scrollBar;
System.Random rand = new System.Random();
public GameObject quest;
public Texture finished;
public GameObject uiHandler;
// Start is called before the first frame update
void Start()
{
quests = new Dictionary<string, List<Quest>>();
quests.Add("main", new List<Quest>());
GameObject newQuest = Instantiate(quest);
newQuest.transform.SetParent(content.transform, false);
quests["main"].Add(new Quest("main", newQuest));
for (int i = 0; i < 20; i++)
{
addQuest();
}
}
// Update is called once per frame
void Update()
{
}
public void updateQuests()
{
foreach (string key in quests.Keys)
{
foreach (Quest quest in quests[key])
{
quest.update(key);
}
}
}
public void addQuest()
{
int index = rand.Next(4);
string type = "";
switch (index)
{
case 0:
type = "collect";
break;
case 1:
type = "find";
break;
case 2:
type = "kill";
break;
case 3:
type = "craft";
break;
}
if (!quests.ContainsKey(type))
{
quests.Add(type, new List<Quest>());
}
GameObject newQuest = Instantiate(quest);
newQuest.transform.SetParent(content.transform, false);
quests[type].Add(new Quest(type, newQuest));
}
public void showQuests()
{
content.GetComponent<RectTransform>().sizeDelta = new Vector2(0, 10);
updateQuests();
float y = -37.5f;
foreach (string key in quests.Keys)
{
foreach (Quest quest in quests[key])
{
quest.show(y);
y = y - 75;
content.GetComponent<RectTransform>().sizeDelta = new Vector2(0, content.GetComponent<RectTransform>().sizeDelta.y + 75);
}
}
scrollBar.value = 0;
content.transform.localPosition = new Vector3(0,0,0);
}
}
}