Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
UIMapPreview.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Threading;
4using UnityEngine;
5using UnityEngine.UI;
6
7public class UIMapPreview : EMono
8{
9 public class GenThread : EClass
10 {
12
13 public Map map;
14
15 public bool done = true;
16
17 public void Init()
18 {
19 bp = new ZoneBlueprint();
20 bp.Create();
21 Reset();
22 }
23
24 public void Reset()
25 {
26 done = false;
27 }
28
29 public void Start()
30 {
31 done = true;
32 }
33 }
34
36
38
40
42
44
46
48
50
52
54
55 public RawImage image;
56
58
59 private Texture texDefault;
60
61 private Texture2D tex;
62
63 private Color[] px;
64
65 private Cell[,] cells;
66
67 [NonSerialized]
68 public int Size;
69
70 [NonSerialized]
71 public int offsetX;
72
73 [NonSerialized]
74 public int offsetZ;
75
76 public FilterMode filter = FilterMode.Bilinear;
77
78 public Map map;
79
80 public bool monoColor;
81
82 public bool createNewMaterial;
83
84 public bool limitBounds;
85
87
88 public float voidAlpha;
89
90 public float minColor;
91
92 public float maxColor;
93
94 private void Awake()
95 {
96 if ((bool)image)
97 {
98 texDefault = image.texture;
99 }
100 }
101
103 {
104 if (thread == null)
105 {
106 thread = new GenThread();
107 thread.Init();
108 }
109 else
110 {
111 if (!thread.done)
112 {
113 return;
114 }
115 image.texture = texDefault;
116 thread.Reset();
117 }
118 thread.bp.genSetting = bp.genSetting;
119 thread.bp.zoneProfile = bp.zoneProfile;
120 thread.bp.genSetting.seed = EMono.rnd(20000);
121 ThreadPool.QueueUserWorkItem(delegate
122 {
123 thread.Start();
124 });
125 CancelInvoke();
126 InvokeRepeating("CheckThread", 0f, 0.1f);
127 }
128
129 public void CheckThread()
130 {
131 if (thread.done)
132 {
134 CancelInvoke();
135 }
136 }
137
138 public void SetMap(Map _map)
139 {
140 map = _map;
141 if (_map == null)
142 {
143 image.texture = texDefault;
144 return;
145 }
146 cells = map.cells;
147 int num = (Size = ((!limitBounds) ? map.Size : ((map.bounds.Width > map.bounds.Height) ? map.bounds.Width : map.bounds.Height)));
148 offsetX = ((map.bounds.Width <= map.bounds.Height) ? ((num - _map.bounds.Width) / 2) : 0);
149 offsetZ = ((map.bounds.Width > map.bounds.Height) ? ((num - _map.bounds.Height) / 2) : 0);
150 px = new Color[Size * Size];
151 if ((bool)tex)
152 {
153 UnityEngine.Object.DestroyImmediate(tex);
154 }
155 tex = new Texture2D(Size, Size)
156 {
157 filterMode = filter,
158 wrapMode = TextureWrapMode.Clamp
159 };
160 for (int i = 0; i < Size * Size; i++)
161 {
162 px[i].a = voidAlpha;
163 }
164 tex.SetPixels(px);
165 if (limitBounds)
166 {
167 for (int j = 0; j < map.bounds.Height; j++)
168 {
169 for (int k = 0; k < map.bounds.Width; k++)
170 {
171 _RefreshPoint(map.bounds.x + k, map.bounds.z + j, apply: false);
172 }
173 }
174 }
175 else
176 {
177 for (int l = 0; l < Size; l++)
178 {
179 for (int m = 0; m < Size; m++)
180 {
181 _RefreshPoint(m, l, apply: false);
182 }
183 }
184 }
185 tex.SetPixels(px);
186 tex.Apply();
187 if ((bool)matMap)
188 {
189 matMap.SetTexture("_MainTex", tex);
190 }
191 if ((bool)image)
192 {
193 image.texture = tex;
194 }
195 }
196
197 public void UpdateMap(int x, int z)
198 {
199 _RefreshPoint(x, z);
200 tex.Apply();
201 }
202
203 public void UpdateMap(List<Cell> newPoints)
204 {
205 foreach (Cell newPoint in newPoints)
206 {
207 _RefreshPoint(newPoint.x, newPoint.z);
208 }
209 tex.Apply();
210 }
211
212 public void _RefreshPoint(int x, int z, bool apply = true)
213 {
214 if (x >= EMono._map.Size || z >= EMono._map.Size)
215 {
216 return;
217 }
218 Cell cell = cells[x, z];
219 int num = x;
220 int num2 = z;
221 if (limitBounds)
222 {
223 num = x - EMono._map.bounds.x + offsetX;
224 num2 = z - EMono._map.bounds.z + offsetZ;
225 }
226 int num3 = num2 * Size + num;
227 if (num3 >= px.Length || num3 < 0)
228 {
229 return;
230 }
231 if (monoColor)
232 {
233 if (!cell.isSeen)
234 {
235 px[num3] = colorSurround;
236 }
237 else if (cell.isSurrounded)
238 {
239 px[num3] = colorSurround;
240 }
241 else if (cell.IsTopWater)
242 {
243 px[num3] = colorWater;
244 }
245 else if (cell.HasBlock)
246 {
247 px[num3] = colorEdge;
248 }
249 else
250 {
251 px[num3] = colorDefault;
252 }
253 }
254 else if (!cell.isSeen)
255 {
256 px[num3] = colorSurround;
257 }
258 else if (cell.HasZoneStairs())
259 {
260 px[num3] = colorStairs;
261 }
262 else if (cell.isSurrounded)
263 {
264 px[num3] = colorSurround;
265 }
266 else if (cell.HasBlock)
267 {
268 px[num3] = cell.matBlock.GetColor();
269 }
270 else
271 {
272 SourceMaterial.Row row = ((cell.bridgeHeight != 0) ? cell.matBridge : cell.matFloor);
273 if (!Application.isEditor && !EMono._zone.IsRegion && cell.IsSnowTile)
274 {
275 row = MATERIAL.sourceSnow;
276 }
277 Color color = (cell.IsSky ? colorSky : row.GetColor());
278 if (row.id == 0 && EMono._zone.IsRegion)
279 {
280 color = colorVoidWorld;
281 }
282 if (color.r > maxColor)
283 {
284 color.r = maxColor;
285 }
286 else if (color.r < minColor)
287 {
288 color.r = minColor;
289 }
290 if (color.g > maxColor)
291 {
292 color.g = maxColor;
293 }
294 else if (color.g < minColor)
295 {
296 color.g = minColor;
297 }
298 if (color.b > maxColor)
299 {
300 color.b = maxColor;
301 }
302 else if (color.b < minColor)
303 {
304 color.b = minColor;
305 }
306 px[num3] = color;
307 }
308 if (cell.isSeen)
309 {
310 if (cell.HasBlock)
311 {
312 px[num3] *= 0.4f;
313 }
314 else if (cell.room != null)
315 {
316 px[num3] *= 0.9f;
317 }
318 }
319 if (!EMono._map.bounds.Contains(x, z))
320 {
321 px[num3].a = voidAlpha;
322 }
323 else
324 {
325 px[num3].a = 1f;
326 }
327 if (apply)
328 {
329 tex.SetPixel(num, num2, px[num3]);
330 }
331 }
332}
Definition: Cell.cs:7
Room room
Definition: Cell.cs:102
bool IsSnowTile
Definition: Cell.cs:782
SourceMaterial.Row matBlock
Definition: Cell.cs:1030
bool HasBlock
Definition: Cell.cs:643
SourceMaterial.Row matBridge
Definition: Cell.cs:1034
bool IsTopWater
Definition: Cell.cs:700
byte z
Definition: Cell.cs:58
SourceMaterial.Row matFloor
Definition: Cell.cs:1032
bool isSeen
Definition: Cell.cs:282
bool isSurrounded
Definition: Cell.cs:234
byte x
Definition: Cell.cs:56
bool HasZoneStairs(bool includeLocked=true)
Definition: Cell.cs:1713
Definition: EClass.cs:5
Definition: EMono.cs:4
static Zone _zone
Definition: EMono.cs:19
static int rnd(int a)
Definition: EMono.cs:47
static Map _map
Definition: EMono.cs:17
static SourceMaterial.Row sourceSnow
Definition: MATERIAL.cs:33
int Size
Definition: MapBounds.cs:20
int Width
Definition: MapBounds.cs:26
int x
Definition: MapBounds.cs:8
int Height
Definition: MapBounds.cs:28
bool Contains(int dx, int dz)
Definition: MapBounds.cs:38
Definition: Map.cs:13
Cell[,] cells
Definition: Map.cs:85
MapBounds bounds
Definition: Map.cs:52
virtual bool IsRegion
Definition: Spatial.cs:501
void CheckThread()
Color colorSurround
Definition: UIMapPreview.cs:39
float maxColor
Definition: UIMapPreview.cs:92
FilterMode filter
Definition: UIMapPreview.cs:76
void Awake()
Definition: UIMapPreview.cs:94
void _RefreshPoint(int x, int z, bool apply=true)
void UpdateMap(List< Cell > newPoints)
void SetMap(Map _map)
RawImage image
Definition: UIMapPreview.cs:55
Color colorDefault
Definition: UIMapPreview.cs:35
Color colorEdge
Definition: UIMapPreview.cs:41
Cell[,] cells
Definition: UIMapPreview.cs:65
Texture texDefault
Definition: UIMapPreview.cs:59
bool limitBounds
Definition: UIMapPreview.cs:84
Material matMap
Definition: UIMapPreview.cs:53
bool createNewMaterial
Definition: UIMapPreview.cs:82
Color colorStairs
Definition: UIMapPreview.cs:47
GenThread thread
Definition: UIMapPreview.cs:86
void GenerateMap(ZoneBlueprint bp)
Color colorSky
Definition: UIMapPreview.cs:45
UIButton button
Definition: UIMapPreview.cs:57
Color colorVoidWorld
Definition: UIMapPreview.cs:51
void UpdateMap(int x, int z)
Color[] px
Definition: UIMapPreview.cs:63
Color colorWater
Definition: UIMapPreview.cs:37
Color colorVoid
Definition: UIMapPreview.cs:49
float voidAlpha
Definition: UIMapPreview.cs:88
Texture2D tex
Definition: UIMapPreview.cs:61
float minColor
Definition: UIMapPreview.cs:90
Color colorFog
Definition: UIMapPreview.cs:43
ZoneProfile zoneProfile
MapGenSetting genSetting