Elin Decompiled Documentation EA 23.356.1 Nightly
Loading...
Searching...
No Matches
RenderRow.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using UnityEngine;
4using UnityEngine.UI;
5
6public class RenderRow : SourceData.BaseRow, IRenderSource
7{
8 public static Dictionary<string, RenderData> DictRenderData = new Dictionary<string, RenderData>();
9
10 public int[] tiles;
11
12 public int[] _tiles;
13
14 public int[] skins;
15
16 public int colorMod;
17
18 public int sort;
19
20 public int value;
21
22 public int LV;
23
24 public int chance;
25
26 public int tempChance;
27
28 public int snowTile;
29
30 public string name;
31
32 public string name_JP;
33
34 public string detail;
35
36 public string detail_JP;
37
38 public string _idRenderData;
39
40 public string _tileType;
41
42 public string defMat;
43
44 public string colorType;
45
46 public string category;
47
48 public string idSound;
49
50 public string aliasPref;
51
52 public string[] components;
53
54 public string[] factory;
55
56 public string[] recipeKey;
57
58 public string[] tag;
59
60 public int W = 1;
61
62 public int H = 1;
63
64 public bool multisize;
65
66 public bool fixedMaterial;
67
69
70 [NonSerialized]
72
73 [NonSerialized]
74 public Sprite[,] sprites;
75
76 [NonSerialized]
78
79 [NonSerialized]
80 public bool useAltColor;
81
82 [NonSerialized]
83 public bool useRandomColor;
84
85 [NonSerialized]
86 public bool useDyeColor;
87
88 [NonSerialized]
90
91 [NonSerialized]
93
94 [NonSerialized]
95 public string _nameSearch;
96
97 [NonSerialized]
98 public string _nameSearchJP;
99
100 [NonSerialized]
102
103 [NonSerialized]
104 private string _recipeCat;
105
106 public virtual string idString => "";
107
108 public virtual string RecipeID => "";
109
110 public virtual string pathRenderData => "Scene/Render/Data/";
111
112 public virtual string idRenderData => _idRenderData;
113
115
116 public virtual string pathSprite => "Scene/Render/Data/";
117
118 public virtual string idSprite => "";
119
120 public virtual string prefabName => "ThingActor";
121
123 {
124 get
125 {
126 if (_category == null && !sources.categories.map.TryGetValue(category, out _category))
127 {
128 Debug.LogError("#source unknown category '" + category + "' for " + GetType().DeclaringType?.Name + " " + RecipeID + ", using 'obj'");
129 _category = sources.categories.map["obj"];
130 }
131 return _category;
132 }
133 }
134
135 public string RecipeCat => _recipeCat ?? (_recipeCat = Category.recipeCat);
136
138
139 public bool HasTag(CTAG _tag)
140 {
141 return tag.Contains(_tag.ToString());
142 }
143
144 public virtual string GetSearchName(bool jp)
145 {
146 object obj;
147 if (!jp)
148 {
149 obj = _nameSearch;
150 if (obj == null)
151 {
152 return _nameSearch = name.ToLower();
153 }
154 }
155 else
156 {
157 obj = _nameSearchJP ?? (_nameSearchJP = GetText().ToLower());
158 }
159 return (string)obj;
160 }
161
162 public bool ContainsTag(string _tag)
163 {
164 return tag.Contains(_tag);
165 }
166
167 public override void OnImportData(SourceData data)
168 {
169 base.OnImportData(data);
170 _tiles = new int[0];
171 SetTiles();
172 if (defMat.Length > 0 && defMat[0] == '!')
173 {
174 fixedMaterial = true;
175 defMat = defMat.Substring(1, defMat.Length - 1);
176 }
177 else
178 {
179 fixedMaterial = false;
180 }
181 }
182
183 public void SetRenderData()
184 {
185 replacer = new SpriteReplacer();
186 if (idRenderData.IsEmpty())
187 {
188 this.renderData = defaultRenderData;
189 }
190 else if (idRenderData[0] == '@')
191 {
192 string[] array = idRenderData.Replace("@", "").Split('#');
193 string text = array[0];
194 if (array.Length > 1)
195 {
196 aliasPref = array[1];
197 }
198 this.renderData = DictRenderData.TryGetValue(text);
199 if (this.renderData == null)
200 {
202 if (this is SourceChara.Row)
203 {
204 renderData.offset.x += renderData.pass.pmesh.size.x * 0.5f;
205 renderData.offset.y += renderData.pass.pmesh.size.y * 0.5f;
206 }
207 else
208 {
209 float num = renderData.pass.pmesh.size.x * 0.5f + renderData.pass.pmesh.pos.x;
210 float num2 = renderData.pass.pmesh.size.y * 0.5f + renderData.pass.pmesh.pos.y;
211 renderData.offset.x += num;
212 renderData.offset.y += num2;
213 renderData.offsetBack.x += num;
214 renderData.offsetBack.y += num2;
215 renderData.heldPos.x += num * 0.7f;
216 renderData.heldPos.y += num2 * 0.7f;
217 }
218 renderData.pass = null;
219 this.renderData = renderData;
221 }
222 }
223 else
224 {
226 }
227 if (!Application.isEditor && !aliasPref.IsEmpty())
228 {
230 }
231 if (pref == null)
232 {
233 pref = new SourcePref();
234 }
235 if (!this.renderData.initialized)
236 {
237 this.renderData.Init();
238 }
239 SetTiles();
240 switch (colorType?.Split('/').TryGet(0))
241 {
242 case "alt":
243 useAltColor = true;
244 break;
245 case "random":
246 useRandomColor = true;
247 break;
248 case "dye":
249 useDyeColor = true;
250 break;
251 }
252 Dictionary<string, SourceMaterial.Row> alias = sources.materials.alias;
253 if (!alias.TryGetValue(defMat.IsEmpty("granite"), out var defaultMaterial))
254 {
255 defaultMaterial = alias["granite"];
256 Debug.LogError($"#source failed to set def mat '{defMat}' - {ModUtil.FindSourceRowPackage(this)}");
257 }
258 DefaultMaterial = defaultMaterial;
259 }
260
261 public virtual void SetTiles()
262 {
263 if (!renderData || !renderData.pass)
264 {
265 return;
266 }
267 if (tiles == null || tiles.Length == 0)
268 {
269 _tiles = new int[1];
270 }
271 else if (_tiles.Length != tiles.Length)
272 {
273 _tiles = new int[tiles.Length];
274 for (int i = 0; i < tiles.Length; i++)
275 {
276 _tiles[i] = tiles[i] / 100 * (int)renderData.pass.pmesh.tiling.x + tiles[i] % 100;
277 }
278 }
279 }
280
281 public int ConvertTile(int tile)
282 {
283 return renderData.ConvertTile(tile);
284 }
285
286 public Sprite GetSprite(int dir = 0, int skin = 0, bool snow = false)
287 {
288 bool flag = this is SourceChara.Row;
290 {
291 Sprite sprite = replacer.GetSprite(dir, skin, snow);
292 if ((bool)sprite)
293 {
294 return sprite;
295 }
296 }
297 int[] array = null ?? _tiles;
298 if (sprites == null)
299 {
300 sprites = new Sprite[(skins == null) ? 1 : (skins.Length + 1), (array.Length == 0) ? 1 : array.Length];
301 }
302 if (flag)
303 {
304 dir = skin;
305 skin = 0;
306 }
307 if (skin != 0 && skin >= sprites.GetLength(0))
308 {
309 skin = 0;
310 }
311 if (dir < 0)
312 {
313 dir *= -1;
314 }
315 if (dir >= array.Length)
316 {
317 dir = 0;
318 }
319 if (!sprites[skin, dir])
320 {
321 MeshPass pass = renderData.pass;
322 if ((bool)pass)
323 {
324 Texture2D texture2D = pass.mat.GetTexture("_MainTex") as Texture2D;
325 ProceduralMesh pmesh = pass.pmesh;
326 int num = 0;
327 num = ((skin != 0) ? Mathf.Abs(array[dir] + (skins[skin - 1] / 100 * (int)renderData.pass.pmesh.tiling.x + skins[skin - 1] % 100) * ((array[dir] > 0) ? 1 : (-1))) : Mathf.Abs(array[dir]));
328 int num2 = (int)((float)texture2D.width / pmesh.tiling.x);
329 int num3 = (int)((float)texture2D.height / pmesh.tiling.y);
330 int num4 = (int)((float)num % pmesh.tiling.x);
331 int num5 = (int)((float)num / pmesh.tiling.x);
332 sprites[skin, dir] = Sprite.Create(texture2D, new Rect(num4 * num2, texture2D.height - (num5 + 1) * num3, num2, num3 * ((!renderData.multiSize) ? 1 : 2)), Vector2.zero, 100f, 0u, SpriteMeshType.FullRect);
333 }
334 else
335 {
336 sprites[skin, dir] = SpriteSheet.Get(idSprite);
337 if (!sprites[skin, dir])
338 {
339 sprites[skin, dir] = Resources.Load<Sprite>(pathSprite + idSprite) ?? Resources.Load<Sprite>(pathSprite + idSprite + "_0");
340 }
341 }
342 if (!sprites[skin, dir])
343 {
344 sprites[skin, dir] = Core.Instance.refs.spriteNull;
345 }
346 }
347 return sprites[skin, dir];
348 }
349
350 public void SetSpriteRenderer(SpriteRenderer sr, Sprite sprite = null, int matCol = 0, bool setTransform = true, int dir = 0, int idSkin = 0)
351 {
352 sr.sprite = sprite ?? GetSprite(dir, idSkin);
354 {
355 sr.sprite = EClass.core.refs.spriteThingActor;
356 }
357 int num = ((matCol == 0) ? 104025 : matCol);
358 float num2 = (float)(num / 262144) * 0.01f;
359 float num3 = 0.02f;
360 float num4 = 0.3f;
361 if (num2 != 0f)
362 {
363 num3 *= num2;
364 }
365 Color color = new Color(num3 * (float)(num % 262144 / 4096) + num4, num3 * (float)(num % 4096 / 64) + num4, num3 * (float)(num % 64) + num4, 1f);
366 sr.color = color;
367 if (setTransform)
368 {
369 float num5 = sr.bounds.max.x - sr.bounds.min.x;
370 _ = sr.bounds.max;
371 _ = sr.bounds.min;
372 sr.transform.localPosition = new Vector3(-0.5f * num5, 0f, 0f);
373 }
374 }
375
376 public virtual SourcePref GetPref()
377 {
378 return pref;
379 }
380
381 public void SetImage(Image image, Sprite sprite = null, int matCol = 0, bool setNativeSize = true, int dir = 0, int idSkin = 0, Card card = null)
382 {
383 bool num = card != null && card.isChara && card.Chara.spriteReplacer != null && !card.HasHost;
384 SourcePref sourcePref = ((card != null) ? card.Pref : GetPref());
385 RenderData renderData = (num ? card.renderer.data : this.renderData);
386 SetImage(image, sprite, matCol, setNativeSize, dir, idSkin, renderData, sourcePref);
387 }
388
389 public void SetImage(Image image, Sprite sprite, int matCol, bool setNativeSize, int dir, int idSkin, RenderData _renderData, SourcePref _pref)
390 {
391 image.sprite = sprite ?? GetSprite(dir, idSkin);
392 int num = ((matCol == 0) ? 104025 : matCol);
393 float num2 = 0.02f;
394 Color color = new Color(num2 * (float)(num % 262144 / 4096), num2 * (float)(num % 4096 / 64), num2 * (float)(num % 64), (float)(num / 262144) * 0.01f);
395 color.a = 1f;
396 image.color = color;
397 RectTransform rectTransform = image.Rect();
398 rectTransform.pivot = _renderData.imagePivot - new Vector2(0.01f * (float)_pref.pivotX, 0.01f * (float)_pref.pivotY);
399 float x = Mathf.Abs(image.transform.localScale.x) * (float)((_tiles == null || _tiles.Length == 0 || _tiles[dir % _tiles.Length] >= 0) ? 1 : (-1));
400 float y = image.transform.localScale.y;
401 image.transform.localScale = new Vector3(x, y, image.transform.localScale.z);
402 _pref.Validate();
403 if (setNativeSize)
404 {
405 image.SetNativeSize();
406 if (_renderData.imageScale.x != 1f || _renderData.imageScale.y != 1f || _pref.scaleIcon != 0)
407 {
408 rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x * (_renderData.imageScale.x + (float)_pref.scaleIcon * 0.01f), rectTransform.sizeDelta.y * (_renderData.imageScale.y + (float)_pref.scaleIcon * 0.01f));
409 }
410 }
411 }
412
413 public void SetRenderParam(RenderParam p, SourceMaterial.Row mat, int dir)
414 {
415 p.tile = GetTile(mat ?? DefaultMaterial, dir);
416 p.matColor = GetColorInt(mat ?? DefaultMaterial);
417 p.mat = mat ?? DefaultMaterial;
418 p.liquidLv = 0;
419 p.dir = dir;
420 p.cell = null;
421 }
422
423 public virtual RenderParam GetRenderParam(SourceMaterial.Row mat, int dir, Point point = null, int bridgeHeight = -1)
424 {
426 shared.tile = GetTile(mat, dir);
427 shared.matColor = GetColorInt(mat);
428 shared.mat = mat;
429 shared.liquidLv = 0;
430 shared.dir = dir;
431 shared.cell = null;
432 Vector3 vector;
433 if (point == null)
434 {
435 shared.color = 11010048f;
438 {
439 vector.y -= 0.8f;
440 }
441 }
442 else
443 {
444 shared.color = 10485760f;
446 vector = point.Position(bridgeHeight);
447 }
448 shared.x = vector.x;
449 shared.y = vector.y;
450 shared.z = vector.z;
451 return shared;
452 }
453
454 public virtual int GetTile(SourceMaterial.Row mat, int dir = 0)
455 {
456 return _tiles[dir % _tiles.Length];
457 }
458
460 {
461 if (useAltColor)
462 {
463 if (colorMod != 0)
464 {
465 return BaseTileMap.GetColorInt(ref mat.altColor, colorMod);
466 }
467 return 104025;
468 }
469 if (colorMod != 0)
470 {
471 return BaseTileMap.GetColorInt(ref mat.matColor, colorMod);
472 }
473 return 104025;
474 }
475}
CTAG
Definition: CTAG.cs:2
BaseTileMap tileMap
static int GetColorInt(ref Color matColor, int p)
Vector3 renderPos
Definition: Card.cs:11
Sprite spriteThingActor
Definition: CoreRef.cs:404
Sprite spriteNull
Definition: CoreRef.cs:394
Definition: Core.cs:14
CoreRef refs
Definition: Core.cs:51
SourceManager sources
Definition: Core.cs:33
static new Core Instance
Definition: Core.cs:15
Scene scene
Definition: Core.cs:65
BaseGameScreen screen
Definition: Core.cs:67
Definition: EClass.cs:6
static Core core
Definition: EClass.cs:7
ProceduralMesh pmesh
Definition: MeshPass.cs:25
Material mat
Definition: MeshPass.cs:21
Definition: Point.cs:9
bool initialized
Definition: RenderData.cs:54
Vector2 imageScale
Definition: RenderData.cs:29
void Init()
Definition: RenderData.cs:95
int ConvertTile(int tile)
Definition: RenderData.cs:111
bool multiSize
Definition: RenderData.cs:33
MeshPass pass
Definition: RenderData.cs:17
static RenderParam shared
Definition: RenderParam.cs:5
virtual SourcePref GetPref()
Definition: RenderRow.cs:376
virtual string idSprite
Definition: RenderRow.cs:118
virtual string idString
Definition: RenderRow.cs:106
string detail_JP
Definition: RenderRow.cs:36
SpriteReplacer replacer
Definition: RenderRow.cs:92
void SetRenderParam(RenderParam p, SourceMaterial.Row mat, int dir)
Definition: RenderRow.cs:413
SourceManager sources
Definition: RenderRow.cs:137
int GetColorInt(SourceMaterial.Row mat)
Definition: RenderRow.cs:459
bool multisize
Definition: RenderRow.cs:64
string[] tag
Definition: RenderRow.cs:58
virtual string pathSprite
Definition: RenderRow.cs:116
RenderData renderData
Definition: RenderRow.cs:71
int sort
Definition: RenderRow.cs:18
string[] factory
Definition: RenderRow.cs:54
string detail
Definition: RenderRow.cs:34
SourceCategory.Row Category
Definition: RenderRow.cs:123
Sprite[,] sprites
Definition: RenderRow.cs:74
virtual string pathRenderData
Definition: RenderRow.cs:110
string idSound
Definition: RenderRow.cs:48
SourcePref pref
Definition: RenderRow.cs:68
virtual RenderData defaultRenderData
Definition: RenderRow.cs:114
virtual string prefabName
Definition: RenderRow.cs:120
bool ContainsTag(string _tag)
Definition: RenderRow.cs:162
string _tileType
Definition: RenderRow.cs:40
string defMat
Definition: RenderRow.cs:42
bool HasTag(CTAG _tag)
Definition: RenderRow.cs:139
bool useAltColor
Definition: RenderRow.cs:80
string _nameSearch
Definition: RenderRow.cs:95
virtual string RecipeID
Definition: RenderRow.cs:108
string category
Definition: RenderRow.cs:46
string _idRenderData
Definition: RenderRow.cs:38
string name
Definition: RenderRow.cs:30
bool useRandomColor
Definition: RenderRow.cs:83
void SetImage(Image image, Sprite sprite, int matCol, bool setNativeSize, int dir, int idSkin, RenderData _renderData, SourcePref _pref)
Definition: RenderRow.cs:389
TileType tileType
Definition: RenderRow.cs:77
string[] components
Definition: RenderRow.cs:52
string _recipeCat
Definition: RenderRow.cs:104
int ConvertTile(int tile)
Definition: RenderRow.cs:281
virtual string GetSearchName(bool jp)
Definition: RenderRow.cs:144
int[] skins
Definition: RenderRow.cs:14
int[] _tiles
Definition: RenderRow.cs:12
virtual string idRenderData
Definition: RenderRow.cs:112
void SetImage(Image image, Sprite sprite=null, int matCol=0, bool setNativeSize=true, int dir=0, int idSkin=0, Card card=null)
Definition: RenderRow.cs:381
int tempChance
Definition: RenderRow.cs:26
string RecipeCat
Definition: RenderRow.cs:135
void SetRenderData()
Definition: RenderRow.cs:183
int[] tiles
Definition: RenderRow.cs:10
string[] recipeKey
Definition: RenderRow.cs:56
string _nameSearchJP
Definition: RenderRow.cs:98
Sprite GetSprite(int dir=0, int skin=0, bool snow=false)
Definition: RenderRow.cs:286
bool useDyeColor
Definition: RenderRow.cs:86
void SetSpriteRenderer(SpriteRenderer sr, Sprite sprite=null, int matCol=0, bool setTransform=true, int dir=0, int idSkin=0)
Definition: RenderRow.cs:350
int value
Definition: RenderRow.cs:20
static Dictionary< string, RenderData > DictRenderData
Definition: RenderRow.cs:8
int chance
Definition: RenderRow.cs:24
string colorType
Definition: RenderRow.cs:44
virtual int GetTile(SourceMaterial.Row mat, int dir=0)
Definition: RenderRow.cs:454
virtual void SetTiles()
Definition: RenderRow.cs:261
string aliasPref
Definition: RenderRow.cs:50
virtual RenderParam GetRenderParam(SourceMaterial.Row mat, int dir, Point point=null, int bridgeHeight=-1)
Definition: RenderRow.cs:423
SourceCategory.Row _category
Definition: RenderRow.cs:101
SourceMaterial.Row DefaultMaterial
Definition: RenderRow.cs:89
int colorMod
Definition: RenderRow.cs:16
int LV
Definition: RenderRow.cs:22
int snowTile
Definition: RenderRow.cs:28
bool fixedMaterial
Definition: RenderRow.cs:66
override void OnImportData(SourceData data)
Definition: RenderRow.cs:167
string name_JP
Definition: RenderRow.cs:32
CameraSupport camSupport
Definition: Scene.cs:41
Dictionary< string, CardRow > map
Definition: SourceCard.cs:9
string GetText(string id="name", bool returnNull=false)
Definition: SourceData.cs:688
SourceMaterial materials
SourceCard cards
SourceCategory categories
int scaleIcon
Definition: SourcePref.cs:293
void Validate()
Definition: SourcePref.cs:385
bool HasSprite(string id, RenderData renderData=null)
Sprite GetSprite(string suffix="")
static Sprite Get(string id)
Definition: SpriteSheet.cs:28