106 lines
3.2 KiB
C#
106 lines
3.2 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);
|
|
FindQuest main = new FindQuest(newQuest);
|
|
main.generateCityQuest();
|
|
quests["main"].Add(main);
|
|
for (int i = 0; i < 20; i++)
|
|
{
|
|
addQuest();
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
public void updateQuests(string key, object obj, int amount)
|
|
{
|
|
foreach (Quest quest in quests[key])
|
|
{
|
|
quest.update(obj, amount);
|
|
}
|
|
}
|
|
|
|
public void addQuest()
|
|
{
|
|
GameObject newQuest = Instantiate(quest);
|
|
newQuest.transform.SetParent(content.transform, false);
|
|
int index = rand.Next(4);
|
|
string type = "";
|
|
Quest questItem;
|
|
switch (index)
|
|
{
|
|
case 0:
|
|
type = "collect";
|
|
questItem = new CollectQuest(newQuest);
|
|
break;
|
|
case 1:
|
|
type = "kill";
|
|
questItem = new KillQuest(newQuest);
|
|
break;
|
|
case 2:
|
|
type = "find";
|
|
questItem = new FindQuest(newQuest);
|
|
break;
|
|
/*case 3:
|
|
type = "craft";
|
|
break;*/
|
|
case 3:
|
|
type = "explore";
|
|
questItem = new ExploreQuest(newQuest);
|
|
break;
|
|
default:
|
|
questItem = new Quest(newQuest);
|
|
break;
|
|
}
|
|
if (!quests.ContainsKey(type))
|
|
{
|
|
quests.Add(type, new List<Quest>());
|
|
}
|
|
quests[type].Add(questItem);
|
|
}
|
|
|
|
public void showQuests()
|
|
{
|
|
content.GetComponent<RectTransform>().sizeDelta = new Vector2(0, 10);
|
|
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);
|
|
}
|
|
}
|
|
|
|
}
|