summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/TaskAdderGame.cs
blob: b40a7158041ea71e5d8aa3f769e7367a78b9f297 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

public class TaskAdderGame : Minigame
{
	public TextRenderer PathText;

	public TaskFolder RootFolderPrefab;

	public TaskAddButton TaskPrefab;

	public Transform TaskParent;

	public List<TaskFolder> Heirarchy = new List<TaskFolder>();

	public List<Transform> ActiveItems = new List<Transform>();

	public TaskAddButton InfectedButton;

	public float folderWidth;

	public float fileWidth;

	public float lineWidth;

	public float lineHeight;

	private TaskFolder Root;

	public override void Begin(PlayerTask t)
	{
		base.Begin(t);
		this.Root = UnityEngine.Object.Instantiate<TaskFolder>(this.RootFolderPrefab, base.transform);
		this.Root.gameObject.SetActive(false);
		Dictionary<SystemTypes, TaskFolder> folders = new Dictionary<SystemTypes, TaskFolder>();
		this.PopulateRoot(this.Root, folders, ShipStatus.Instance.CommonTasks);
		this.PopulateRoot(this.Root, folders, ShipStatus.Instance.LongTasks);
		this.PopulateRoot(this.Root, folders, ShipStatus.Instance.NormalTasks);
		this.Root.SubFolders = (from f in this.Root.SubFolders
		orderby f.FolderName
		select f).ToList<TaskFolder>();
		this.ShowFolder(this.Root);
	}

	private void PopulateRoot(TaskFolder rootFolder, Dictionary<SystemTypes, TaskFolder> folders, NormalPlayerTask[] taskList)
	{
		foreach (NormalPlayerTask normalPlayerTask in taskList)
		{
			SystemTypes systemTypes = normalPlayerTask.StartAt;
			if (normalPlayerTask is DivertPowerTask)
			{
				systemTypes = ((DivertPowerTask)normalPlayerTask).TargetSystem;
			}
			if (systemTypes == SystemTypes.LowerEngine)
			{
				systemTypes = SystemTypes.UpperEngine;
			}
			TaskFolder taskFolder;
			if (!folders.TryGetValue(systemTypes, out taskFolder))
			{
				taskFolder = (folders[systemTypes] = UnityEngine.Object.Instantiate<TaskFolder>(this.RootFolderPrefab, base.transform));
				taskFolder.gameObject.SetActive(false);
				if (systemTypes == SystemTypes.UpperEngine)
				{
					taskFolder.FolderName = "Engines";
				}
				else
				{
					taskFolder.FolderName = DestroyableSingleton<TranslationController>.Instance.GetString(systemTypes);
				}
				rootFolder.SubFolders.Add(taskFolder);
			}
			taskFolder.Children.Add(normalPlayerTask);
		}
	}

	public void GoToRoot()
	{
		this.Heirarchy.Clear();
		this.ShowFolder(this.Root);
	}

	public void GoUpOne()
	{
		if (this.Heirarchy.Count > 1)
		{
			TaskFolder taskFolder = this.Heirarchy[this.Heirarchy.Count - 2];
			this.Heirarchy.RemoveAt(this.Heirarchy.Count - 1);
			this.Heirarchy.RemoveAt(this.Heirarchy.Count - 1);
			this.ShowFolder(taskFolder);
		}
	}

	public void ShowFolder(TaskFolder taskFolder)
	{
		StringBuilder stringBuilder = new StringBuilder(64);
		this.Heirarchy.Add(taskFolder);
		for (int i = 0; i < this.Heirarchy.Count; i++)
		{
			stringBuilder.Append(this.Heirarchy[i].FolderName);
			stringBuilder.Append("\\");
		}
		this.PathText.Text = stringBuilder.ToString();
		for (int j = 0; j < this.ActiveItems.Count; j++)
		{
			UnityEngine.Object.Destroy(this.ActiveItems[j].gameObject);
		}
		this.ActiveItems.Clear();
		float num = 0f;
		float num2 = 0f;
		for (int k = 0; k < taskFolder.SubFolders.Count; k++)
		{
			TaskFolder taskFolder2 = UnityEngine.Object.Instantiate<TaskFolder>(taskFolder.SubFolders[k], this.TaskParent);
			taskFolder2.gameObject.SetActive(true);
			taskFolder2.Parent = this;
			taskFolder2.transform.localPosition = new Vector3(num, num2, 0f);
			taskFolder2.transform.localScale = Vector3.one;
			num += this.folderWidth;
			if (num > this.lineWidth)
			{
				num = 0f;
				num2 += this.lineHeight;
			}
			this.ActiveItems.Add(taskFolder2.transform);
		}
		List<PlayerTask> list = (from t in taskFolder.Children
		orderby t.TaskType.ToString()
		select t).ToList<PlayerTask>();
		for (int l = 0; l < list.Count; l++)
		{
			TaskAddButton taskAddButton = UnityEngine.Object.Instantiate<TaskAddButton>(this.TaskPrefab);
			taskAddButton.MyTask = list[l];
			if (taskAddButton.MyTask.TaskType == TaskTypes.DivertPower)
			{
				SystemTypes targetSystem = ((DivertPowerTask)taskAddButton.MyTask).TargetSystem;
				taskAddButton.Text.Text = DestroyableSingleton<TranslationController>.Instance.GetString(StringNames.DivertPowerTo, Array.Empty<object>()) + " " + DestroyableSingleton<TranslationController>.Instance.GetString(targetSystem);
			}
			else
			{
				taskAddButton.Text.Text = DestroyableSingleton<TranslationController>.Instance.GetString(taskAddButton.MyTask.TaskType);
			}
			this.AddFileAsChild(taskAddButton, ref num, ref num2);
		}
		if (this.Heirarchy.Count == 1)
		{
			TaskAddButton taskAddButton2 = UnityEngine.Object.Instantiate<TaskAddButton>(this.InfectedButton);
			taskAddButton2.Text.Text = "Be_Impostor.exe";
			this.AddFileAsChild(taskAddButton2, ref num, ref num2);
		}
	}

	private void AddFileAsChild(TaskAddButton item, ref float xCursor, ref float yCursor)
	{
		item.transform.SetParent(this.TaskParent);
		item.transform.localPosition = new Vector3(xCursor, yCursor, 0f);
		item.transform.localScale = Vector3.one;
		xCursor += this.fileWidth;
		if (xCursor > this.lineWidth)
		{
			xCursor = 0f;
			yCursor -= this.lineHeight;
		}
		this.ActiveItems.Add(item.transform);
	}
}