Elin Decompiled Documentation EA 23.102 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
33 public List<GameIndex> worlds;
34
36
38
40
42
44
46
48
50
51 private string pathRoot;
52
53 private string idDest;
54
55 private string pathBackup;
56
57 private bool backup;
58
59 private bool cloud => ELayer.core.config.cloud;
60
61 public void Init(bool _backup, string _pathBackup = "", string _idDest = "")
62 {
63 backup = _backup;
64 pathBackup = _pathBackup;
65 idDest = _idDest;
66 if (backup)
67 {
68 for (int i = 0; i < 2; i++)
69 {
70 Vector2 anchoredPosition = windows[i].Rect().anchoredPosition;
71 windows[i].Rect().anchoredPosition = new Vector2(anchoredPosition.x + 40f, anchoredPosition.y - 30f);
72 }
73 }
74 if (!backup && Application.isEditor)
75 {
76 FileInfo[] files = new DirectoryInfo("D:\\Download").GetFiles();
77 foreach (FileInfo fileInfo in files)
78 {
79 if (fileInfo.Name.StartsWith("world") && fileInfo.Name.EndsWith(".zip"))
80 {
81 string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.Name);
82 string path = CorePath.RootSave + fileNameWithoutExtension;
83 if (!Directory.Exists(path))
84 {
85 Directory.CreateDirectory(path);
86 new StreamWriter(new MemoryStream());
87 ReadOptions options = new ReadOptions();
88 ZipFile.Read(fileInfo.FullName, options).ExtractAll(path);
89 }
90 }
91 }
92 }
94 if (!backup)
95 {
96 windows[0].ClearBottomButtons();
97 windows[0].AddBottomButton("toggleCloud", delegate
98 {
99 ELayer.core.config.cloud = !ELayer.core.config.cloud;
100 SE.Tab();
101 RefreshList();
102 });
103 }
104 }
105
106 public void RefreshList()
107 {
108 if (!backup)
109 {
110 windows[0].SetCaption("saveList".lang() + (cloud ? (" " + "isCloud".lang()) : ""));
111 }
112 pathRoot = (backup ? pathBackup : (cloud ? CorePath.RootSaveCloud : CorePath.RootSave));
114 goCloudWarn.SetActive(cloud && !backup);
115 goInfo.SetActive(value: false);
116 goNoInfo.SetActive(value: true);
117 list.Clear();
118 list.callbacks = new UIList.Callback<GameIndex, UIButton>
119 {
120 onInstantiate = delegate(GameIndex a, UIButton b)
121 {
122 FontColor c = (ELayer.core.version.IsSaveCompatible(a.version) ? FontColor.Good : FontColor.Bad);
123 string s = a.Title + ((ELayer.core.IsGameStarted && a.id == Game.id) ? "currentSave".lang() : "") + Environment.NewLine;
124 b.mainText.SetText(s, c);
125 b.subText.SetText(a.RealDate ?? "");
126 b.subText2.SetText((a.permaDeath ? "★" : "") + a.pcName + " (" + a.zoneName + ")", c);
127 b.GetComponent<UIItem>().text1.SetText(a.version.GetText() + (cloud ? (" " + "isCloud".lang()) : ""));
128 },
129 onClick = delegate(GameIndex a, UIButton b)
130 {
131 RefreshInfo(a);
132 }
133 };
134 foreach (GameIndex world in worlds)
135 {
136 list.Add(world);
137 }
138 list.Refresh();
139 if (list.items.Count == 0)
140 {
141 buttonLoad.SetActive(enable: false);
142 buttonDelete.SetActive(enable: false);
143 goNoInfo.SetActive(value: true);
144 }
145 }
146
147 public void RefreshInfo(GameIndex i)
148 {
149 goInfo.SetActive(value: true);
150 goNoInfo.SetActive(value: false);
151 note.Clear();
152 note.AddTopic("version".lang(), i.version.GetText());
153 note.AddTopic("date_real".lang(), i.RealDate);
154 note.AddTopic("date_game".lang(), i.GameData);
155 note.AddTopic("ID", i.id);
157 goInfo2.SetActive(flag);
158 if (i.IsCorrupted)
159 {
160 note.Space();
161 note.AddText("corrupted_folder".lang(), FontColor.Bad);
162 }
163 else if (!flag)
164 {
165 note.Space();
166 note.AddText("incompatible".lang(), FontColor.Bad);
167 }
168 else
169 {
170 note.AddTopic("currentZone".lang(), i.zoneName);
171 }
174 textDays.SetText("infoHire".lang(i.days.ToString() ?? ""));
175 textDeepest.SetText("deepestLv2".lang(i.deepest.ToString() ?? ""));
176 textRace.SetText(ELayer.sources.races.map.TryGetValue(i.idRace)?.GetName().ToTitleCase() ?? "");
177 textJob.SetText(ELayer.sources.jobs.map.TryGetValue(i.idJob)?.GetName().ToTitleCase() ?? "");
178 if (!i.idPortrait.IsEmpty())
179 {
180 portrait.SetActive(enable: true);
181 Color color = Color.white;
182 ColorUtility.TryParseHtmlString("#" + i.color, out color);
184 }
185 else
186 {
187 portrait.SetActive(enable: false);
188 }
189 note.Build();
190 buttonListBackup.SetActive(!backup);
192 buttonBackup.SetActive(!backup && (!ELayer.core.IsGameStarted || i.id == Game.id));
193 buttonOpen.SetActive(backup);
194 buttonMove.SetActive(!backup && !ELayer.core.IsGameStarted);
195 buttonMove.mainText.SetText((cloud ? "fromCloud" : "toCloud").lang());
196 buttonMove.SetOnClick(delegate
197 {
198 Dialog.YesNo("dialog_switchCloud", delegate
199 {
200 string sourceDirName = (cloud ? CorePath.RootSaveCloud : CorePath.RootSave) + i.id;
201 string text = (cloud ? CorePath.RootSave : CorePath.RootSaveCloud) + i.id;
202 string text2 = (cloud ? CorePath.PathBackupCloud : CorePath.PathBackup) + i.id;
203 string text3 = (cloud ? CorePath.PathBackup : CorePath.PathBackupCloud) + i.id;
204 bool flag2 = Directory.Exists(text2);
205 if (Directory.Exists(text) || Directory.Exists(text3))
206 {
207 SE.Beep();
208 ELayer.ui.Say("cloud_conflict");
209 }
210 else
211 {
212 SE.Play("mutation");
213 try
214 {
215 if (flag2)
216 {
217 Debug.Log("Converting Backup files:");
218 Directory.Move(text2, text3);
219 foreach (GameIndex game in GameIO.GetGameList(((!cloud) ? CorePath.PathBackupCloud : CorePath.PathBackup) + i.id + "/"))
220 {
221 Debug.Log("Processing:" + game.id + ": " + game.path);
222 if (!cloud)
223 {
224 GameIO.PrepareSteamCloud(game.id, game.path);
225 }
226 }
227 }
228 Debug.Log("Converting Current World:");
229 Directory.Move(sourceDirName, text);
230 i.path = text;
231 i.cloud = !cloud;
232 GameIO.UpdateGameIndex(i);
233 if (i.cloud)
234 {
235 GameIO.PrepareSteamCloud(i.id);
236 }
237 }
238 catch (Exception ex)
239 {
240 ELayer.ui.Say(ex.Message);
241 }
242 RefreshList();
243 }
244 });
245 });
246 buttonLoad.onClick.RemoveAllListeners();
247 buttonDelete.onClick.RemoveAllListeners();
248 buttonLoad.SetOnClick(delegate
249 {
251 if (backup)
252 {
253 Dialog.YesNo("dialog_restoreWarning", delegate
254 {
255 GameIO.DeleteGame(idDest, cloud, deleteBackup: false);
257 SE.WriteJournal();
258 Close();
259 Game.TryLoad(idDest, cloud, delegate
260 {
262 });
263 });
264 }
265 else
266 {
267 if (!i.madeBackup && i.version.IsBelow(ELayer.core.version))
268 {
270 ELayer.ui.Say("backupDone");
271 i.madeBackup = true;
273 }
274 Game.TryLoad(i.id, cloud, delegate
275 {
276 Game.Load(i.id, cloud);
277 });
278 }
279 });
280 buttonDelete.SetOnClick(delegate
281 {
282 Dialog.YesNo("dialogDeleteGame", delegate
283 {
284 GameIO.DeleteGame(i.id, cloud);
285 worlds = null;
286 RefreshList();
287 SE.Trash();
288 });
289 });
290 buttonListBackup.SetOnClick(delegate
291 {
292 ELayer.ui.AddLayer<LayerLoadGame>().Init(_backup: true, (cloud ? CorePath.PathBackupCloud : CorePath.PathBackup) + i.id + "/", i.id);
293 });
294 buttonBackup.SetOnClick(delegate
295 {
297 {
298 ELayer.game.backupTime = 0.0;
299 ELayer.game.Save();
300 }
301 i.cloud = cloud;
303 ELayer.ui.Say("backupDone");
304 SE.WriteJournal();
305 });
306 buttonOpen.SetOnClick(delegate
307 {
308 Util.ShowExplorer(i.path);
309 });
310 buttonLoad.SetActive(flag);
311 }
312}
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:586
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
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:960
Definition: IO.cs:11
static void CopyDir(string sourceDirectory, string targetDirectory, Func< string, bool > funcExclude=null)
Definition: IO.cs:233
GameObject goNoInfo
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
UIText textDeepest
void RefreshList()
UIButton buttonMove
GameObject goCloudWarn
static void KillActor()
Definition: LayerTitle.cs:191
List< Window > windows
Definition: Layer.cs:116
virtual void Close()
Definition: Layer.cs:463
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
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:73