Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
PartialMapMenu.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.IO;
3using System.Linq;
4using UnityEngine;
5
6public class PartialMapMenu : EMono
7{
8 public static PartialMapMenu Instance;
9
10 public static DirectoryInfo lastDir;
11
12 public static DirectoryInfo lastDirSub;
13
14 public GameObject goMain;
15
16 public GameObject goCat;
17
18 public GameObject goOption;
19
21
23
25
26 public CanvasGroup cg;
27
29
31
33
35
37
38 public Dictionary<string, Sprite> dictSprite = new Dictionary<string, Sprite>();
39
40 public DirectoryInfo rootDir;
41
43
44 public DirectoryInfo dir => am.dir;
45
46 public bool IsEditor => MapPiece.IsEditor;
47
49
50 public static void Activate()
51 {
52 if (!Instance)
53 {
54 Instance = Util.Instantiate<PartialMapMenu>("UI/BuildMenu/PartialMapMenu", EMono.ui);
55 Instance.Init();
56 }
58 MapPiece.CacheMap.Clear();
59 }
60
61 public void Init()
62 {
63 rootDir = new DirectoryInfo(CorePath.MapPieceSaveUser);
64 goCat.SetActive(IsEditor);
66 if (!IsEditor)
67 {
68 return;
69 }
71 if (lastDir != null)
72 {
73 listCat.Select((DirectoryInfo a) => a.FullName == lastDir.FullName);
74 am.dir = lastDir;
75 }
76 if (lastDirSub != null)
77 {
79 listCatSub.Select((DirectoryInfo a) => a.FullName == lastDirSub.FullName);
80 am.dir = lastDirSub;
81 }
82 }
83
84 public void Deactivate()
85 {
87 Object.DestroyImmediate(Instance.gameObject);
88 }
89
90 public void SetVisible(bool visible)
91 {
93 goMain.SetActive(visible);
94 }
95
96 public void DestorySprites()
97 {
98 foreach (Sprite value in dictSprite.Values)
99 {
100 Object.Destroy(value.texture);
101 Object.Destroy(value);
102 }
103 dictSprite.Clear();
104 }
105
106 public void RefreshOptions()
107 {
108 goOption.SetActive(IsEditor && partial != null);
109 if (partial != null)
110 {
111 toggleRotate.SetToggle(partial.allowRotate, delegate(bool on)
112 {
113 partial.allowRotate = on;
114 partial.Update();
115 });
117 {
118 partial.ignoreBlock = on;
119 partial.Update();
120 });
121 }
122 }
123
124 public void Refresh()
125 {
126 list.callbacks = new UIList.Callback<MapMetaData, ButtonGrid>
127 {
128 onClick = delegate(MapMetaData a, ButtonGrid b)
129 {
130 SE.Click();
131 am.Import(a.path);
132 am.partialMap.name = a.name;
133 },
134 onRedraw = delegate(MapMetaData a, ButtonGrid b, int i)
135 {
136 string path = a.path.GetFullFileNameWithoutExtension() + ".txt";
137 if (File.Exists(path))
138 {
139 string str = File.ReadAllText(path);
140 if (!str.IsEmpty())
141 {
142 a.name = str;
143 }
144 }
145 if (a.name.IsEmpty())
146 {
147 a.name = "unknown";
148 }
149 b.mainText.SetText(IsEditor ? new FileInfo(a.path).Name : a.name);
150 b.subText.text = Lang._currency(a.partial.value);
151 Sprite sprite = dictSprite.TryGetValue(a.path);
152 if (!sprite)
153 {
154 string path2 = a.path.GetFullFileNameWithoutExtension() + ".jpg";
155 if (File.Exists(path2))
156 {
157 Texture2D texture2D = new Texture2D(1, 1);
158 byte[] source = File.ReadAllBytes(path2);
159 texture2D.LoadImage(source.ToArray());
160 sprite = Sprite.Create(texture2D, new Rect(0f, 0f, texture2D.width, texture2D.height), new Vector2(0.5f, 0.5f));
161 b.icon.sprite = sprite;
162 dictSprite[a.path] = sprite;
163 }
164 }
165 if ((bool)sprite)
166 {
167 b.icon.sprite = sprite;
168 }
169 UIButton componentInDirectChildren = b.GetComponentInDirectChildren<UIButton>();
170 componentInDirectChildren.SetActive(IsEditor);
171 componentInDirectChildren.SetOnClick(delegate
172 {
173 SE.Click();
174 am.overwritePath = a.path;
175 am.RefreshMenu(show: false);
176 });
177 },
178 onList = delegate
179 {
180 foreach (FileInfo item in dir.GetFiles().Concat(MOD.listPartialMaps))
181 {
182 if (item.Name.EndsWith(".mp"))
183 {
184 MapMetaData metaData = Map.GetMetaData(item.FullName);
185 if (metaData != null && metaData.partial != null)
186 {
187 list.Add(metaData);
188 }
189 }
190 }
191 }
192 };
193 list.List();
194 }
195
196 public void RefreshCategory(DirectoryInfo dir = null)
197 {
198 UIList _listCat = listCat;
199 bool isMain = true;
200 if (dir == null)
201 {
202 dir = rootDir;
203 }
204 if (dir.FullName != rootDir.FullName)
205 {
206 _listCat = listCatSub;
207 isMain = false;
208 }
209 _listCat.Clear();
210 _listCat.callbacks = new UIList.Callback<DirectoryInfo, UIButton>
211 {
212 onClick = delegate(DirectoryInfo a, UIButton b)
213 {
214 SE.Click();
215 _listCat.Select(a);
216 am.dir = a;
217 if (isMain)
218 {
219 lastDir = (lastDirSub = a);
221 }
222 else
223 {
224 lastDirSub = a;
225 }
226 Refresh();
227 },
228 onInstantiate = delegate(DirectoryInfo a, UIButton b)
229 {
230 int num = 0;
231 FileInfo[] files = a.GetFiles("*.mp", SearchOption.AllDirectories);
232 for (int j = 0; j < files.Length; j++)
233 {
234 _ = files[j];
235 num++;
236 }
237 b.mainText.text = ((a == dir && !isMain) ? "(Root)" : (a.Name + "(" + num + ")"));
238 },
239 onList = delegate
240 {
241 _listCat.Add(isMain ? rootDir : dir);
242 DirectoryInfo[] array = (isMain ? new DirectoryInfo(CorePath.MapPieceSave).GetDirectories() : dir.GetDirectories());
243 foreach (DirectoryInfo o in array)
244 {
245 _listCat.Add(o);
246 }
247 }
248 };
249 _listCat.List();
250 listCatSub.SetActive(listCatSub.items.Count > 1);
251 }
252
253 public void OpenFolder()
254 {
255 Util.ShowExplorer(CorePath.MapPieceSave + "Test");
256 }
257}
PartialMap partialMap
Definition: AM_Copy.cs:16
void Import(string path)
Definition: AM_Copy.cs:242
DirectoryInfo dir
Definition: AM_Copy.cs:18
void RefreshMenu(bool show)
Definition: AM_Copy.cs:260
static AM_Copy Copy
Definition: ActionMode.cs:45
static string MapPieceSaveUser
Definition: CorePath.cs:202
static string MapPieceSave
Definition: CorePath.cs:200
Definition: EMono.cs:4
static UI ui
Definition: EMono.cs:15
Definition: Lang.cs:6
static string _currency(object a, string IDCurrency)
Definition: Lang.cs:162
Definition: MOD.cs:7
static List< FileInfo > listPartialMaps
Definition: MOD.cs:22
string name
Definition: MapMetaData.cs:7
PartialMap partial
Definition: MapMetaData.cs:19
string path
Definition: MapMetaData.cs:21
static Dictionary< string, PartialMap > CacheMap
Definition: MapPiece.cs:43
static bool IsEditor
Definition: MapPiece.cs:47
Definition: Map.cs:13
static MapMetaData GetMetaData(string pathZip)
Definition: Map.cs:732
void DestorySprites()
GameObject goCat
static DirectoryInfo lastDir
UIButton toggleRotate
UIButton buttonEdit
void RefreshCategory(DirectoryInfo dir=null)
CanvasGroup cg
GameObject goOption
Dictionary< string, Sprite > dictSprite
UIButton toggleIgnoreBlock
static DirectoryInfo lastDirSub
UIButton buttonSave
DirectoryInfo dir
PartialMap partial
UIButton buttonDelete
static void Activate()
void SetVisible(bool visible)
static PartialMapMenu Instance
DirectoryInfo rootDir
UIDynamicList list
GameObject goMain
bool allowRotate
Definition: PartialMap.cs:55
bool ignoreBlock
Definition: PartialMap.cs:58
void Update()
Definition: PartialMap.cs:403
UIText mainText
Definition: UIButton.cs:102
void SetToggle(bool isOn, Action< bool > onToggle=null)
Definition: UIButton.cs:341
override void List()
override void Add(object o)
Definition: UIList.cs:9
List< object > items
Definition: UIList.cs:241
override void Clear()
Definition: UIList.cs:349
void Select(int index=0, bool invoke=false)
Definition: UIList.cs:644
override void Add(object item)
Definition: UIList.cs:302
override void List()
Definition: UIList.cs:717
void SetText(string s)
Definition: UIText.cs:159