Elin Decompiled Documentation EA 23.102 Nightly
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Pages
LayerTextureViewer.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using UnityEngine;
3using UnityEngine.UI;
4
6{
7 public RawImage imageTex;
8
9 public Image highlight;
10
11 public Image moldMarker;
12
14
16
17 public Scrollbar scrollbarH;
18
19 public Scrollbar scrollvarV;
20
22
23 public Transform transMask;
24
25 public float scale;
26
27 public float highlightSize;
28
29 public List<Image> markers = new List<Image>();
30
31 public Vector2 markerFix;
32
34
36
38
39 public int sizeX;
40
41 public int sizeY;
42
43 public bool fixZoom;
44
45 public bool snow;
46
47 public Vector2 test;
48
49 private bool zoom;
50
51 public override void OnInit()
52 {
53 windows[0].AddBottomSpace();
54 windows[0].AddBottomButton("openUser", delegate
55 {
56 Util.ShowExplorer(CorePath.user + "Texture Replace/dummy.txt");
57 });
58 windows[0].AddBottomButton("toggleSnowTexture", delegate
59 {
60 SE.Tab();
61 snow = !snow;
63 });
64 }
65
66 public override void OnSwitchContent(Window window)
67 {
68 data = ELayer.core.textures.texMap.TryGetValue(window.CurrentTab.idLang + (snow ? "Snow" : "")) ?? ELayer.core.textures.texMap[window.CurrentTab.idLang];
70 scrollbarH.value = 0f;
71 scrollvarV.value = 1f;
72 }
73
74 public void RefreshPage()
75 {
76 scale = 0.5f;
77 switch (data.id)
78 {
79 case "objS":
80 case "objSS":
81 case "objSSnow":
82 case "objSSSnow":
83 scale = 1f;
84 break;
85 }
86 if (zoom)
87 {
88 scale *= 2f;
89 }
90 if (fixZoom)
91 {
92 scale /= ELayer.ui.canvasScaler.scaleFactor;
93 }
94 imageTex.texture = null;
95 imageTex.texture = data.tex;
96 imageTex.rectTransform.sizeDelta = new Vector2((float)data.tex.width * scale, (float)data.tex.height * scale);
97 imageTex.RebuildLayoutTo<Layer>();
98 foreach (Image marker in markers)
99 {
100 Object.Destroy(marker.gameObject);
101 }
102 markers.Clear();
103 foreach (TextureReplace value in data.dictReplace.Values)
104 {
105 Image image = Util.Instantiate(moldMarker, imageTex.transform.parent);
106 image.rectTransform.sizeDelta = new Vector2(((float)Mathf.Max(value.w, data.tileW) + highlightSize * 2f) * scale, ((float)Mathf.Max(value.h, data.tileH) + highlightSize * 2f) * scale);
107 SetPos(image, value.index % 100, value.index / 100 * -1, highlightSize, markerFix);
108 image.color = ((value.source == TextureReplace.Source.Local) ? colorLocal : ((value.source == TextureReplace.Source.User) ? colorUser : colorMod));
109 markers.Add(image);
110 }
111 }
112
113 public void SetPos(Component r, int x, int y, float size = 0f, Vector2 posFix = default(Vector2))
114 {
115 r.Rect().anchoredPosition = new Vector2((float)(x * data.tileW) * scale * test.x - highlightSize * scale, (float)(y * data.tileH) * scale * test.y + highlightSize * scale) + posFix;
116 }
117
118 private void Update()
119 {
120 _ = imageTex.rectTransform;
121 RectTransformUtility.ScreenPointToLocalPointInRectangle(imageTex.rectTransform, Input.mousePosition, ELayer.ui.canvas.worldCamera, out var localPoint);
122 int num = (int)localPoint.x / (int)((float)data.tileW * scale);
123 int num2 = (int)localPoint.y / (int)((float)data.tileH * scale);
124 if (EInput.axis != Vector2.zero)
125 {
126 sizeX = Mathf.Clamp(sizeX + (int)EInput.axis.x, 1, 5);
127 sizeY = Mathf.Clamp(sizeY + (int)EInput.axis.y * -1, 1, 5);
128 EInput.requireAxisReset = true;
129 }
131 {
132 SE.Tab();
133 zoom = !zoom;
134 RefreshPage();
135 }
137 highlight.SetActive(flag);
138 if (!flag)
139 {
140 return;
141 }
142 highlight.rectTransform.sizeDelta = new Vector2(((float)(data.tileW * sizeX) + highlightSize * 2f) * scale, ((float)(data.tileH * sizeY) + highlightSize * 2f) * scale);
143 SetPos(highlight, num, num2, highlightSize);
144 string text = data.id + "_";
145 int index = Mathf.Abs(num2) * 100 + num;
146 text += index;
147 textHint.text = text + ((sizeX == 1 && sizeY == 1) ? "" : ("(" + sizeX + "x" + sizeY + ")"));
149 {
150 return;
151 }
152 UIContextMenu uIContextMenu = ELayer.ui.CreateContextMenuInteraction();
153 TextureReplace replace = data.dictReplace.TryGetValue(index);
154 if (replace != null)
155 {
156 uIContextMenu.AddButton("open_replace", delegate
157 {
158 Util.Run(replace.file.FullName);
159 });
160 if (replace.source != TextureReplace.Source.Mod)
161 {
162 uIContextMenu.AddButton("delete_replace", delegate
163 {
164 try
165 {
166 data.DeleteReplace(replace);
168 }
169 catch
170 {
171 }
172 SE.Trash();
173 RefreshPage();
174 });
175 }
176 }
177 else
178 {
179 uIContextMenu.AddButton("create_replace", delegate
180 {
181 data.CreateReplace(index, CorePath.user + "Texture Replace/", TextureReplace.Source.User, sizeX, sizeY);
182 SE.Change();
183 RefreshPage();
184 });
185 }
186 if (ELayer._zone.isMapSaved && (replace == null || replace.source != TextureReplace.Source.Local))
187 {
188 uIContextMenu.AddButton("create_replaceLocal", delegate
189 {
190 string text2 = ELayer._zone.pathSave + "Texture Replace";
191 IO.CreateDirectory(text2);
192 data.CreateReplace(index, text2 + "/", TextureReplace.Source.Local, sizeX, sizeY);
193 SE.Change();
194 RefreshPage();
195 });
196 }
197 uIContextMenu.Show();
198 }
199}
bool clicked
Definition: ButtonState.cs:37
static string user
Definition: CorePath.cs:160
TextureManager textures
Definition: Core.cs:45
Definition: EInput.cs:8
static ButtonState middleMouse
Definition: EInput.cs:353
static Vector2 axis
Definition: EInput.cs:331
static ButtonState leftMouse
Definition: EInput.cs:349
Definition: ELayer.cs:4
static Core core
Definition: ELayer.cs:7
static UI ui
Definition: ELayer.cs:21
static Zone _zone
Definition: ELayer.cs:25
static bool IsPointerOver(Component c)
override void OnInit()
void SetPos(Component r, int x, int y, float size=0f, Vector2 posFix=default(Vector2))
override void OnSwitchContent(Window window)
Definition: Layer.cs:9
List< Window > windows
Definition: Layer.cs:116
bool isMapSaved
Definition: Spatial.cs:358
Texture2D tex
Definition: TextureData.cs:39
Dictionary< int, TextureReplace > dictReplace
Definition: TextureData.cs:57
void ForceRefresh()
Definition: TextureData.cs:98
void CreateReplace(int index, string path, TextureReplace.Source source, int sizeX, int sizeY)
Definition: TextureData.cs:174
void DeleteReplace(TextureReplace r)
Definition: TextureData.cs:214
string id
Definition: TextureData.cs:33
Dictionary< string, TextureData > texMap
void Show(UIItem i)
void AddButton(Func< string > funcText, UnityAction action=null)
Definition: UIText.cs:6
Definition: Window.cs:13
Setting.Tab CurrentTab
Definition: Window.cs:787