-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapManager.cs
217 lines (200 loc) · 6.64 KB
/
MapManager.cs
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
using DG.Tweening;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using Utage;
public class MapManager : MonoBehaviour, IAdvSaveData, IBinaryIO
{
public Button[] areaButtons;
public Sprite[] avatars;
public RawImage cityImage;
public GameObject cityMap;
public Texture[] cityTextures;
private string currentMapData = string.Empty;
private AdvEngine engine;
public Button goCityButton;
public Button goSchoolButton;
public CanvasGroup mapCanvas;
public RawImage schoolImage;
public GameObject schoolMap;
public Texture[] schoolTextures;
private bool shown;
[HideInInspector]
public bool wait;
private void Awake()
{
this.goSchoolButton.get_onClick().RemoveAllListeners();
this.goSchoolButton.get_onClick().AddListener(new UnityAction(this, (IntPtr) this.SwitchToSchool));
this.goCityButton.get_onClick().RemoveAllListeners();
this.goCityButton.get_onClick().AddListener(new UnityAction(this, (IntPtr) this.SwitchToCity));
}
private void ClickArea(string clickJumpValue)
{
this.mapCanvas.set_blocksRaycasts(false);
this.engine.Param.TrySetParameter("mapControl", clickJumpValue);
this.wait = false;
}
private Sprite GetAvatarByName(string avatarName)
{
for (int i = 0; i < this.avatars.Length; i++)
{
if (this.avatars[i].get_name() == avatarName)
{
return this.avatars[i];
}
}
Debug.Log("Cannot find avatar: " + avatarName);
return null;
}
private string GetRandomMapData(string mapDatas)
{
char[] separator = new char[] { '|' };
string[] strArray = mapDatas.Split(separator);
Random.InitState(this.engine.Param.GetParameterInt("seed"));
int parameterInt = this.engine.Param.GetParameterInt("day");
int index = 0;
for (int i = 0; i < parameterInt; i++)
{
index = Random.Range(0, strArray.Length);
}
return strArray[index];
}
public void HideMap()
{
ShortcutExtensions46.DOFade(this.mapCanvas, 0f, 0.5f);
this.mapCanvas.set_blocksRaycasts(false);
this.shown = false;
}
public void OnClear()
{
this.wait = false;
this.mapCanvas.set_alpha(0f);
this.mapCanvas.set_blocksRaycasts(false);
this.shown = false;
foreach (Button button in this.areaButtons)
{
button.get_gameObject().SetActive(false);
}
}
public void OnRead(BinaryReader reader)
{
this.wait = reader.ReadBoolean();
this.shown = reader.ReadBoolean();
this.currentMapData = reader.ReadString();
this.engine = GameObject.Find("AdvEngine").GetComponent<AdvEngine>();
if (this.shown)
{
this.ShowMap(this.engine, this.currentMapData, true);
}
this.mapCanvas.set_blocksRaycasts(reader.ReadBoolean());
}
public void OnWrite(BinaryWriter writer)
{
writer.Write(this.wait);
writer.Write(this.shown);
writer.Write(this.currentMapData);
writer.Write(this.mapCanvas.get_blocksRaycasts());
}
public void ShowMap(AdvEngine advEngine, string mapDataName, bool onRead = false)
{
ShortcutExtensions46.DOFade(this.mapCanvas, 1f, !onRead ? 0.5f : 0f);
this.shown = true;
this.mapCanvas.set_blocksRaycasts(true);
this.engine = advEngine;
if (mapDataName.Contains("|"))
{
mapDataName = this.GetRandomMapData(mapDataName);
}
this.currentMapData = mapDataName;
if (mapDataName.Substring(0, 2).Contains("重"))
{
mapDataName = mapDataName.Substring(0, 2) + "/" + mapDataName;
}
string[][] arrayCollection = MyTool.ParseTSV(MyTool.LoadText("MapData/" + mapDataName));
string[] arrayByFirstElement = MyTool.GetArrayByFirstElement(arrayCollection, "Area");
int index = MyTool.ParseInt(MyTool.GetArrayByFirstElement(arrayCollection, "Mode")[2], 1) - 1;
List<string> list = new List<string>(arrayByFirstElement);
foreach (Button button in this.areaButtons)
{
bool flag = false;
string[] strArray3 = new string[0];
if (list.Contains(button.get_gameObject().get_name()))
{
flag = true;
strArray3 = MyTool.GetArrayByFirstElement(arrayCollection, button.get_gameObject().get_name());
}
button.get_gameObject().SetActive(flag);
if (flag)
{
<ShowMap>c__AnonStorey0 storey = new <ShowMap>c__AnonStorey0 {
$this = this,
clickLable = strArray3[1]
};
button.get_onClick().RemoveAllListeners();
button.get_onClick().AddListener(new UnityAction(storey, (IntPtr) this.<>m__0));
}
}
bool flag2 = MyTool.GetArrayByFirstElement(arrayCollection, "Mode")[1] == "school";
index = Mathf.Clamp(index, 0, this.schoolTextures.Length - 1);
this.schoolImage.set_texture(this.schoolTextures[index]);
this.cityImage.set_texture(this.cityTextures[index]);
if (flag2)
{
this.SwitchToSchool();
}
else
{
this.SwitchToCity();
}
}
private void SwitchToCity()
{
this.schoolMap.SetActive(false);
this.cityMap.SetActive(true);
}
private void SwitchToSchool()
{
this.schoolMap.SetActive(true);
this.cityMap.SetActive(false);
}
private void Update()
{
if (this.shown)
{
foreach (Button button in this.areaButtons)
{
if (button.get_gameObject().get_activeSelf())
{
ButtonEx ex = button as ButtonEx;
GameObject obj2 = ex.get_transform().Find("flag").get_gameObject();
if (ex.IsHover != obj2.get_activeSelf())
{
obj2.SetActive(ex.IsHover);
}
}
}
}
}
public string SaveKey
{
get
{
return "MapManager";
}
}
[CompilerGenerated]
private sealed class <ShowMap>c__AnonStorey0
{
internal MapManager $this;
internal string clickLable;
internal void <>m__0()
{
this.$this.ClickArea(this.clickLable);
}
}
}