Elin Decompiled Documentation EA 23.130 Nightly
Loading...
Searching...
No Matches
LayerLoadGame.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.IO;
4using Ionic.Zip;
5using UnityEngine;
6
7public class LayerLoadGame : ELayer
8{
9 public UIList list;
10
11 public GameObject goInfo;
12
13 public GameObject goNoInfo;
14
15 public GameObject goInfo2;
16
17 public GameObject goCloudWarn;
18
19 public UINote note;
20
22
24
26
28
30
32
34
35 public List<GameIndex> worlds;
36
38
40
42
44
46
48
50
52
53 private string pathRoot;
54
55 private string idDest;
56
57 private string pathBackup;
58
59 private bool backup;
60
61 private bool cloud => ELayer.core.config.cloud;
62
63 public void Init(bool _backup, string _pathBackup = "", string _idDest = "")
64 {
65 backup = _backup;
66 pathBackup = _pathBackup;
67 idDest = _idDest;
68 if (backup)
69 {
70 for (int i = 0; i < 2; i++)
71 {
72 Vector2 anchoredPosition = windows[i].Rect().anchoredPosition;
73 windows[i].Rect().anchoredPosition = new Vector2(anchoredPosition.x + 40f, anchoredPosition.y - 30f);
74 }
75 }
76 if (!backup && Application.isEditor)
77 {
78 FileInfo[] files = new DirectoryInfo("D:\\Download").GetFiles();
79 foreach (FileInfo fileInfo in files)
80 {
81 if (fileInfo.Name.StartsWith("world") && fileInfo.Name.EndsWith(".zip"))
82 {
83 string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.Name);
84 string path = CorePath.RootSave + fileNameWithoutExtension;
85 if (!Directory.Exists(path))
86 {
87 Directory.CreateDirectory(path);
88 new StreamWriter(new MemoryStream());
89 ReadOptions options = new ReadOptions();
90 ZipFile.Read(fileInfo.FullName, options).ExtractAll(path);
91 }
92 }
93 }
94 }
96 if (!backup)
97 {
98 windows[0].ClearBottomButtons();
99 windows[0].AddBottomButton("toggleCloud", delegate
100 {
101 ELayer.core.config.cloud = !ELayer.core.config.cloud;
102 SE.Tab();
103 RefreshList();
104 });
105 }
106 }
107
108 public void RefreshList(string id = null)
109 {
110 if (!backup)
111 {
112 windows[0].SetCaption("saveList".lang() + (cloud ? (" " + "isCloud".lang()) : ""));
113 }
114 pathRoot = (backup ? pathBackup : (cloud ? CorePath.RootSaveCloud : CorePath.RootSave));
116 goCloudWarn.SetActive(cloud && !backup);
117 goInfo.SetActive(value: false);
118 goNoInfo.SetActive(value: true);
119 list.Clear();
120 list.callbacks = new UIList.Callback<GameIndex, UIButton>
121 {
122 onInstantiate = delegate(GameIndex a, UIButton b)
123 {
124 FontColor c = (ELayer.core.version.IsSaveCompatible(a.version) ? FontColor.Good : FontColor.Bad);
125 string s = a.Title + ((ELayer.core.IsGameStarted && a.id == Game.id) ? "currentSave".lang() : "") + Environment.NewLine;
126 b.mainText.SetText(s, c);
127 b.subText.SetText(a.RealDate ?? "");
128 b.subText2.SetText((a.permaDeath ? "★" : "") + a.pcName + " (" + a.zoneName + ")", c);
129 b.GetComponent<UIItem>().text1.SetText(a.version.GetText() + (cloud ? (" " + "isCloud".lang()) : ""));
130 },
131 onClick = delegate(GameIndex a, UIButton b)
132 {
133 RefreshInfo(a);
134 }
135 };
136 foreach (GameIndex world in worlds)
137 {
138 list.Add(world);
139 }
140 list.Refresh();
141 if (list.items.Count == 0)
142 {
143 buttonLoad.SetActive(enable: false);
144 buttonDelete.SetActive(enable: false);
145 goNoInfo.SetActive(value: true);
146 }
147 if (id == null)
148 {
149 return;
150 }
151 list.Select((GameIndex a) => a.id == id);
152 foreach (GameIndex world2 in worlds)
153 {
154 if (world2.id == id)
155 {
156 RefreshInfo(world2);
157 }
158 }
159 }
160
161 public void RefreshInfo(GameIndex i)
162 {
163 goInfo.SetActive(value: true);
164 goNoInfo.SetActive(value: false);
165 note.Clear();
166 note.AddTopic("version".lang(), i.version.GetText());
167 note.AddTopic("date_real".lang(), i.RealDate);
168 note.AddTopic("date_game".lang(), i.GameData);
169 note.AddTopic("ID", i.id);
171 goInfo2.SetActive(flag);
172 if (i.IsCorrupted)
173 {
174 note.Space();
175 note.AddText("corrupted_folder".lang(), FontColor.Bad);
176 }
177 else if (!flag)
178 {
179 note.Space();
180 note.AddText("incompatible".lang(), FontColor.Bad);
181 }
182 else
183 {
184 note.AddTopic("currentZone".lang(), i.zoneName);
185 }
188 textDays.SetText("infoHire".lang(i.days.ToString() ?? ""));
189 textDeepest.SetText("deepestLv2".lang(i.deepest.ToString() ?? ""));
190 textRace.SetText(ELayer.sources.races.map.TryGetValue(i.idRace)?.GetName().ToTitleCase() ?? "");
191 textJob.SetText(ELayer.sources.jobs.map.TryGetValue(i.idJob)?.GetName().ToTitleCase() ?? "");
192 if (!i.idPortrait.IsEmpty())
193 {
194 portrait.SetActive(enable: true);
195 Color color = Color.white;
196 ColorUtility.TryParseHtmlString("#" + i.color, out color);
198 }
199 else
200 {
201 portrait.SetActive(enable: false);
202 }
203 note.Build();
204 int num = 0;
205 if (!backup)
206 {
208 }
209 buttonListBackup.mainText.SetText("listBackup".lang() + " (" + num + ")");
210 buttonListBackup.SetActive(!backup && num > 0);
212 buttonBackup.SetActive(!backup && (!ELayer.core.IsGameStarted || i.id == Game.id));
213 buttonOpen.SetActive(backup);
214 buttonMove.SetActive(!backup && !ELayer.core.IsGameStarted);
215 buttonMove.mainText.SetText((cloud ? "fromCloud" : "toCloud").lang());
216 buttonRename.SetActive(!backup && !cloud && !ELayer.core.IsGameStarted);
217 buttonRename.SetOnClick(delegate
218 {
219 Dialog.InputName("dialogTeleportId", i.id, delegate(bool cancel, string text)
220 {
221 if (!cancel && !text.IsEmpty())
222 {
223 try
224 {
225 if (Directory.Exists(CorePath.RootSave + text))
226 {
227 throw new Exception(text + " already exists.");
228 }
229 Directory.Move(CorePath.RootSave + i.id, CorePath.RootSave + text);
230 if (Directory.Exists(CorePath.PathBackup + i.id))
231 {
232 if (Directory.Exists(CorePath.PathBackup + text))
233 {
234 throw new Exception("Backup/" + text + " already exists.");
235 }
236 Directory.Move(CorePath.PathBackup + i.id, CorePath.PathBackup + text);
237 }
238 RefreshList(text);
239 }
240 catch (Exception ex2)
241 {
242 ELayer.ui.Say(ex2.Message);
243 }
244 }
245 });
246 });
247 buttonMove.SetOnClick(delegate
248 {
249 Dialog.YesNo("dialog_switchCloud", delegate
250 {
251 string sourceDirName = (cloud ? CorePath.RootSaveCloud : CorePath.RootSave) + i.id;
252 string text2 = (cloud ? CorePath.RootSave : CorePath.RootSaveCloud) + i.id;
253 string text3 = (cloud ? CorePath.PathBackupCloud : CorePath.PathBackup) + i.id;
254 string text4 = (cloud ? CorePath.PathBackup : CorePath.PathBackupCloud) + i.id;
255 bool flag2 = Directory.Exists(text3);
256 if (Directory.Exists(text2) || Directory.Exists(text4))
257 {
258 SE.Beep();
259 ELayer.ui.Say("cloud_conflict");
260 }
261 else
262 {
263 SE.Play("mutation");
264 try
265 {
266 if (flag2)
267 {
268 Debug.Log("Converting Backup files:");
269 Directory.Move(text3, text4);
270 foreach (GameIndex game in GameIO.GetGameList(((!cloud) ? CorePath.PathBackupCloud : CorePath.PathBackup) + i.id + "/"))
271 {
272 Debug.Log("Processing:" + game.id + ": " + game.path);
273 if (!cloud)
274 {
275 GameIO.PrepareSteamCloud(game.id, game.path);
276 }
277 }
278 }
279 Debug.Log("Converting Current World:");
280 Directory.Move(sourceDirName, text2);
281 i.path = text2;
282 i.cloud = !cloud;
283 GameIO.UpdateGameIndex(i);
284 if (i.cloud)
285 {
286 GameIO.PrepareSteamCloud(i.id);
287 }
288 }
289 catch (Exception ex)
290 {
291 ELayer.ui.Say(ex.Message);
292 }
293 RefreshList();
294 }
295 });
296 });
297 buttonLoad.onClick.RemoveAllListeners();
298 buttonDelete.onClick.RemoveAllListeners();
299 buttonLoad.SetOnClick(delegate
300 {
302 if (backup)
303 {
304 Dialog.YesNo("dialog_restoreWarning", delegate
305 {
306 GameIO.DeleteGame(idDest, cloud, deleteBackup: false);
307 IO.CopyDir(pathRoot + "/" + i.id, (cloud ? CorePath.RootSaveCloud : CorePath.RootSave) + "/" + idDest);
308 SE.WriteJournal();
309 Close();
310 Game.TryLoad(idDest, cloud, delegate
311 {
312 Game.Load(idDest, cloud);
313 });
314 });
315 }
316 else
317 {
318 if (!i.madeBackup && i.version.IsBelow(ELayer.core.version))
319 {
321 ELayer.ui.Say("backupDone");
322 i.madeBackup = true;
324 }
325 Game.TryLoad(i.id, cloud, delegate
326 {
327 Game.Load(i.id, cloud);
328 });
329 }
330 });
331 buttonDelete.SetOnClick(delegate
332 {
333 Dialog.YesNo("dialogDeleteGame", delegate
334 {
335 GameIO.DeleteGame(i.id, cloud);
336 worlds = null;
337 RefreshList();
338 SE.Trash();
339 });
340 });
341 buttonListBackup.SetOnClick(delegate
342 {
343 ELayer.ui.AddLayer<LayerLoadGame>().Init(_backup: true, (cloud ? CorePath.PathBackupCloud : CorePath.PathBackup) + i.id + "/", i.id);
344 });
345 buttonBackup.SetOnClick(delegate
346 {
348 {
349 ELayer.game.backupTime = 0.0;
350 ELayer.game.Save();
351 }
352 i.cloud = cloud;
354 ELayer.ui.Say("backupDone");
355 SE.WriteJournal();
356 RefreshInfo(i);
357 });
358 buttonOpen.SetOnClick(delegate
359 {
360 Util.ShowExplorer(i.path);
361 });
362 buttonLoad.SetActive(flag);
363 }
364}
FontColor
Definition: FontColor.cs:2
if(item3.idFile==idFirstFile &&item3.id==idFirstTopic)
Definition: UIBook.cs:627
Version version
Definition: BaseCore.cs:17
bool cloud
Definition: CoreConfig.cs:588
static string RootSave
Definition: CorePath.cs:206
static string RootSaveCloud
Definition: CorePath.cs:208
static string PathBackup
Definition: CorePath.cs:216
static string PathBackupCloud
Definition: CorePath.cs:218
bool IsGameStarted
Definition: Core.cs:84
CoreConfig config
Definition: Core.cs:70
Definition: Dialog.cs:7
static Dialog YesNo(string langDetail, Action actionYes, Action actionNo=null, string langYes="yes", string langNo="no")
Definition: Dialog.cs:244
static Dialog InputName(string langDetail, string text, Action< bool, string > onClose, InputType inputType=InputType.Default)
Definition: Dialog.cs:528
Definition: ELayer.cs:4
static World world
Definition: ELayer.cs:39
static Core core
Definition: ELayer.cs:7
static SourceManager sources
Definition: ELayer.cs:37
static Game game
Definition: ELayer.cs:9
static UI ui
Definition: ELayer.cs:21
Definition: GameIO.cs:10
static void DeleteGame(string id, bool cloud, bool deleteBackup=true)
Definition: GameIO.cs:264
static void UpdateGameIndex(GameIndex i)
Definition: GameIO.cs:249
static List< GameIndex > GetGameList(string path, bool sortByName=false, bool includeEmptyFolder=false)
Definition: GameIO.cs:286
static void MakeBackup(GameIndex index, string suffix="")
Definition: GameIO.cs:112
string RealDate
Definition: GameIndex.cs:52
string pcName
Definition: GameIndex.cs:27
bool IsCorrupted
Definition: GameIndex.cs:59
string id
Definition: GameIndex.cs:13
int deepest
Definition: GameIndex.cs:19
string idJob
Definition: GameIndex.cs:35
string idRace
Definition: GameIndex.cs:33
string aka
Definition: GameIndex.cs:29
bool permaDeath
Definition: GameIndex.cs:43
int days
Definition: GameIndex.cs:17
Version version
Definition: GameIndex.cs:21
string color
Definition: GameIndex.cs:15
string zoneName
Definition: GameIndex.cs:23
string GameData
Definition: GameIndex.cs:54
string idPortrait
Definition: GameIndex.cs:31
Definition: Game.cs:8
static void Load(string id, bool cloud)
Definition: Game.cs:313
static bool TryLoad(string id, bool cloud, Action onLoad)
Definition: Game.cs:302
static string id
Definition: Game.cs:147
bool Save(bool isAutoSave=false, bool silent=false)
Definition: Game.cs:944
Definition: IO.cs:11
static void CopyDir(string sourceDirectory, string targetDirectory, Func< string, bool > funcExclude=null)
Definition: IO.cs:233
GameObject goNoInfo
UIButton buttonRename
void RefreshInfo(GameIndex i)
UIButton buttonOpen
UIButton buttonBackup
string pathBackup
UIButton buttonLoad
void Init(bool _backup, string _pathBackup="", string _idDest="")
UIButton buttonDelete
UIButton buttonListBackup
Portrait portrait
GameObject goInfo
GameObject goInfo2
List< GameIndex > worlds
void RefreshList(string id=null)
UIText textDeepest
UIButton buttonMove
GameObject goCloudWarn
static void KillActor()
Definition: LayerTitle.cs:191
List< Window > windows
Definition: Layer.cs:116
void SetPortrait(string id, Color colorOverlay=default(Color), bool applyColorMod=true)
Definition: Portrait.cs:213
SourceRace races
SourceJob jobs
UIText subText2
Definition: UIButton.cs:106
UIText subText
Definition: UIButton.cs:104
UIText mainText
Definition: UIButton.cs:102
Definition: UIItem.cs:5
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
virtual void Refresh(bool highlightLast=false)
Definition: UIList.cs:424
Definition: UINote.cs:6
void Clear()
Definition: UINote.cs:35
UIItem AddTopic(string id, string text, string value=null)
Definition: UINote.cs:144
UIItem AddText(string text, FontColor color=FontColor.DontChange)
Definition: UINote.cs:113
void Space(int sizeY=0, int sizeX=1)
Definition: UINote.cs:62
void Build()
Definition: UINote.cs:49
Definition: UIText.cs:6
void SetText(string s)
Definition: UIText.cs:159
Definition: Util.cs:10
static void ShowExplorer(string itemPath, bool selectFirstFile=false)
Definition: Util.cs:228
string GetText()
Definition: Version.cs:16
bool IsSaveCompatible(Version v)
Definition: Version.cs:82