public PuzzleSlide(int depth) { if (depth < 1) { depth = 1; } List <Dictionary <string, string> > options = new List <Dictionary <string, string> >(); TextAsset textAsset = (TextAsset)Resources.Load("slidepuzzles"); string puzzleText = textAsset.text; IniData puzzles = IniRead.ReadFromString(puzzleText); while (options.Count == 0) { foreach (Dictionary <string, string> p in puzzles.data.Values) { int moves = 1; int.TryParse(p["moves"], out moves); if (moves == depth) { options.Add(p); } } depth--; if (depth == 0) { ValkyrieDebug.Log("Error: Unable to find puzzle."); Application.Quit(); } } Loadpuzzle(options[Random.Range(0, options.Count)]); moves = 0; }
public void DownloadDictionary() { remoteManifest = IniRead.ReadFromString(download.text); string remoteDict = serverLocation + game.gameType.TypeName() + "/Localization.txt"; StartCoroutine(Download(remoteDict, delegate { ReadManifest(); })); }
public void DrawList() { localManifest = IniRead.ReadFromString(""); if (File.Exists(saveLocation() + "/manifest.ini")) { localManifest = IniRead.ReadFromIni(saveLocation() + "/manifest.ini"); } // Heading DialogBox db = new DialogBox(new Vector2(2, 1), new Vector2(UIScaler.GetWidthUnits() - 4, 3), "Download " + game.gameType.QuestName()); db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetLargeFont(); db.SetFont(game.gameType.GetHeaderFont()); TextButton tb; // Start here int offset = 5; // Loop through all available quests // FIXME: this isn't paged Dictionary<string, Dictionary<string, string>> data; foreach (KeyValuePair <string, Dictionary <string, string> > kv in remoteManifest.data) { string file = kv.Key + ".valkyrie"; // Size is 1.2 to be clear of characters with tails if (File.Exists(saveLocation() + "/" + file)) { int localVersion = 0; int remoteVersion = 0; int.TryParse(localManifest.Get(kv.Key, "version"), out localVersion); int.TryParse(remoteManifest.Get(kv.Key, "version"), out remoteVersion); if (localVersion < remoteVersion) { tb = new TextButton(new Vector2(2, offset), new Vector2(UIScaler.GetWidthUnits() - 4, 1.2f), " [Update] " + kv.Value["name"], delegate { Selection(file); }, Color.blue, offset); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); tb.button.GetComponent <UnityEngine.UI.Text>().alignment = TextAnchor.MiddleLeft; tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0, 0, 0.1f); } else { db = new DialogBox(new Vector2(2, offset), new Vector2(UIScaler.GetWidthUnits() - 4, 1.2f), " " + kv.Value["name"], Color.grey); db.AddBorder(); db.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0.05f, 0.05f, 0.05f); db.textObj.GetComponent <UnityEngine.UI.Text>().alignment = TextAnchor.MiddleLeft; } } else { tb = new TextButton(new Vector2(2, offset), new Vector2(UIScaler.GetWidthUnits() - 4, 1.2f), " " + kv.Value["name"], delegate { Selection(file); }, Color.white, offset); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); tb.button.GetComponent <UnityEngine.UI.Text>().alignment = TextAnchor.MiddleLeft; tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0, 0, 0.1f); } offset += 2; } tb = new TextButton(new Vector2(1, UIScaler.GetBottom(-3)), new Vector2(8, 2), "Back", delegate { Cancel(); }, Color.red); tb.SetFont(game.gameType.GetHeaderFont()); }
public static void Load() { Game game = Game.Get(); try { if (File.Exists(SaveFile())) { string data = File.ReadAllText(SaveFile()); IniData saveData = IniRead.ReadFromString(data); Destroyer.Dialog(); game.cd = new ContentData(game.gameType.DataDirectory()); // Check if we found anything if (game.cd.GetPacks().Count == 0) { Debug.Log("Error: Failed to find any content packs, please check that you have them present in: " + game.gameType.DataDirectory() + System.Environment.NewLine); Application.Quit(); } game.cd.LoadContentID(""); Dictionary <string, string> packs = saveData.Get("Packs"); foreach (KeyValuePair <string, string> kv in packs) { game.cd.LoadContentID(""); game.cd.LoadContentID(kv.Key); } new Quest(saveData); game.heroCanvas.SetupUI(); game.heroCanvas.UpdateImages(); game.heroCanvas.UpdateStatus(); if (game.gameType.DisplayMorale()) { game.moraleDisplay = new MoraleDisplay(); } if (!game.gameType.DisplayHeroes()) { game.heroCanvas.Clean(); } // Create the menu button new MenuButton(); new NextStageButton(); } } catch (System.Exception) { Debug.Log("Error: Unable to open save file: " + SaveFile()); Application.Quit(); } }
/// <summary> /// Parse downloaded ini data /// </summary> /// <param name="download">download object</param> /// <param name="call">Function to call after parse</param> public void IniFetched(WWW download, UnityEngine.Events.UnityAction call) { if (download.error == null) { IniData remoteManifest = IniRead.ReadFromString(download.text); data = remoteManifest.Get("Quest"); } else { iniError = true; } call(); }
/// <summary> /// Parse the downloaded remote manifest and start download of individual quest files /// </summary> public void DownloadManifest() { if (download.error != null) { Application.Quit(); } IniData remoteManifest = IniRead.ReadFromString(download.text); foreach (KeyValuePair <string, Dictionary <string, string> > kv in remoteManifest.data) { remoteQuests.Add(new RemoteQuest(kv)); } DownloadQuestFiles(); }
private void QuestsDownload_callback(string data, bool error, System.Uri uri) { if (error) { error_download = true; error_download_description = data; // Callback to display screen if (cb_download != null) { cb_download(false); } quest_list_mode = QuestListMode.ERROR_DOWNLOAD; return; } if (!force_local_quest) { quest_list_mode = QuestListMode.ONLINE; } // Parse ini IniData remoteManifest = IniRead.ReadFromString(data); foreach (KeyValuePair <string, Dictionary <string, string> > quest_kv in remoteManifest.data) { remote_quests_data.Add(quest_kv.Key, new QuestData.Quest(quest_kv.Key, quest_kv.Value)); } if (remote_quests_data.Count == 0) { Debug.Log("ERROR: Quest list is empty\n"); error_download = true; error_download_description = "ERROR: Quest list is empty"; if (cb_download != null) { cb_download(false); } return; } CheckLocalAvailability(); if (cb_download != null) { cb_download(true); } }
/// <summary> /// Parse the downloaded remote manifest and start download of individual quest files /// </summary> public void DownloadManifest_callback(string data, bool error) { if (error) { // Hide loading screen Destroyer.Dialog(); // draw error message float error_string_width = 0; UIElement ui = new UIElement(); if (data == "ERROR NETWORK") { StringKey ERROR_NETWORK = new StringKey("val", "ERROR_NETWORK"); ui.SetText(ERROR_NETWORK, Color.red); error_string_width = ui.GetStringWidth(ERROR_NETWORK, UIScaler.GetMediumFont()); } else { StringKey ERROR_HTTP = new StringKey("val", "ERROR_HTTP", game.stats.error_download_description); ui.SetText(ERROR_HTTP, Color.red); error_string_width = ui.GetStringWidth(ERROR_HTTP, UIScaler.GetMediumFont()); } ui.SetLocation(UIScaler.GetHCenter() - (error_string_width / 2f), UIScaler.GetVCenter(), error_string_width, 2.4f); ui.SetTextAlignment(TextAnchor.MiddleCenter); ui.SetFontSize(UIScaler.GetLargeFont()); ui.SetBGColor(Color.clear); // draw return button ui = new UIElement(); ui.SetLocation(1, UIScaler.GetBottom(-3), 8, 2); ui.SetText(CommonStringKeys.BACK, Color.red); ui.SetButton(delegate { Cancel(); }); ui.SetFont(game.gameType.GetHeaderFont()); ui.SetFontSize(UIScaler.GetMediumFont()); new UIElementBorder(ui, Color.red); return; } IniData remoteManifest = IniRead.ReadFromString(data); foreach (KeyValuePair <string, Dictionary <string, string> > kv in remoteManifest.data) { remoteQuests.Add(new RemoteQuest(kv)); } DownloadQuestFiles(); }
public void DownloadImages(Stack <string> images = null) { string remoteDict = serverLocation + game.gameType.TypeName() + "/Localization.txt"; if (images == null) { remoteManifest = IniRead.ReadFromString(download.text); images = new Stack <string>(); foreach (KeyValuePair <string, Dictionary <string, string> > kv in remoteManifest.data) { if (remoteManifest.Get(kv.Key, "image").Length > 0) { images.Push(remoteManifest.Get(kv.Key, "image")); } } if (images.Count == 0) { StartCoroutine(Download(remoteDict, delegate { ReadManifest(); })); return; } StartCoroutine(Download(serverLocation + game.gameType.TypeName() + "/" + images.Peek(), delegate { DownloadImages(images); })); return; } if (download.error == null) { textures.Add(images.Pop(), download.texture); } else { images.Pop(); } if (images.Count > 0) { StartCoroutine(Download(serverLocation + game.gameType.TypeName() + "/" + images.Peek(), delegate { DownloadImages(images); })); return; } StartCoroutine(Download(remoteDict, delegate { ReadManifest(); })); }
public void SetQuestAvailability(string key, bool isAvailable) { // update list of local quest IniData localManifest = IniRead.ReadFromString(""); string saveLocation = ContentData.DownloadPath(); if (File.Exists(saveLocation + "/manifest.ini")) { localManifest = IniRead.ReadFromIni(saveLocation + "/manifest.ini"); } if (isAvailable) { IniData downloaded_quest = IniRead.ReadFromString(remote_quests_data[key].ToString()); localManifest.Remove(key); localManifest.Add(key, downloaded_quest.data["Quest"]); } else { if (localManifest.Get(key) != null) { localManifest.Remove(key); } // we need to delete /temp and reload list UnloadLocalQuests(); } if (File.Exists(saveLocation + "/manifest.ini")) { File.Delete(saveLocation + "/manifest.ini"); } File.WriteAllText(saveLocation + "/manifest.ini", localManifest.ToString()); // update status quest remote_quests_data[key].downloaded = isAvailable; remote_quests_data[key].update_available = false; }
/// <summary> /// Draw download options screen /// </summary> public void DrawList() { Destroyer.Dialog(); localManifest = IniRead.ReadFromString(""); if (File.Exists(saveLocation() + "/manifest.ini")) { localManifest = IniRead.ReadFromIni(saveLocation() + "/manifest.ini"); } // Heading UIElement ui = new UIElement(); ui.SetLocation(2, 1, UIScaler.GetWidthUnits() - 4, 3); ui.SetText(new StringKey("val", "QUEST_NAME_DOWNLOAD", game.gameType.QuestName())); ui.SetFont(game.gameType.GetHeaderFont()); ui.SetFontSize(UIScaler.GetLargeFont()); UIElementScrollVertical scrollArea = new UIElementScrollVertical(); scrollArea.SetLocation(1, 5, UIScaler.GetWidthUnits() - 2f, 21f); new UIElementBorder(scrollArea); // Start here float offset = 0; // Loop through all available quests foreach (RemoteQuest rq in remoteQuests) { string file = rq.name + ".valkyrie"; string questName = rq.GetData("name." + game.currentLang); if (questName.Length == 0) { questName = rq.GetData("name." + rq.GetData("defaultlanguage")); } if (questName.Length == 0) { questName = rq.name; } int remoteFormat = 0; int.TryParse(rq.GetData("format"), out remoteFormat); bool formatOK = (remoteFormat >= QuestData.Quest.minumumFormat) && (remoteFormat <= QuestData.Quest.currentFormat); if (!formatOK) { continue; } bool exists = File.Exists(saveLocation() + "/" + file); bool update = true; if (exists) { string localHash = localManifest.Get(rq.name, "version"); string remoteHash = rq.GetData("version"); update = !localHash.Equals(remoteHash); } Color bg = Color.white; if (exists) { bg = new Color(0.7f, 0.7f, 1f); if (!update) { bg = new Color(0.1f, 0.1f, 0.1f); } } // Frame ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(0.95f, offset, UIScaler.GetWidthUnits() - 4.9f, 3.1f); ui.SetBGColor(bg); if (update) { ui.SetButton(delegate { Selection(rq); }); } offset += 0.05f; // Draw Image ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(1, offset, 3, 3); ui.SetBGColor(bg); if (update) { ui.SetButton(delegate { Selection(rq); }); } if (rq.image != null) { ui.SetImage(rq.image); } ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetBGColor(Color.clear); ui.SetLocation(4, offset, UIScaler.GetWidthUnits() - 8, 3f); ui.SetTextPadding(1.2f); if (update && exists) { ui.SetText(new StringKey("val", "QUEST_NAME_UPDATE", questName), Color.black); } else { ui.SetText(questName, Color.black); } if (update) { ui.SetButton(delegate { Selection(rq); }); } ui.SetTextAlignment(TextAnchor.MiddleLeft); ui.SetFontSize(Mathf.RoundToInt(UIScaler.GetSmallFont() * 1.3f)); // Duration int lengthMax = 0; int.TryParse(rq.GetData("lengthmax"), out lengthMax); if (lengthMax > 0) { int lengthMin = 0; int.TryParse(rq.GetData("lengthmin"), out lengthMin); ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(UIScaler.GetRight(-11), offset, 2, 1); ui.SetText(lengthMin.ToString(), Color.black); ui.SetBGColor(Color.clear); ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(UIScaler.GetRight(-9), offset, 1, 1); ui.SetText("-", Color.black); ui.SetBGColor(Color.clear); ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(UIScaler.GetRight(-8), offset, 2, 1); ui.SetText(lengthMax.ToString(), Color.black); ui.SetBGColor(Color.clear); } // Difficulty float difficulty = 0; float.TryParse(rq.GetData("difficulty"), out difficulty); if (difficulty != 0) { string symbol = "π"; // will if (game.gameType is MoMGameType) { symbol = new StringKey("val", "ICON_SUCCESS_RESULT").Translate(); } ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(UIScaler.GetRight(-13), offset + 1, 9, 2); ui.SetText(symbol + symbol + symbol + symbol + symbol, Color.black); ui.SetBGColor(Color.clear); ui.SetFontSize(UIScaler.GetMediumFont()); ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(UIScaler.GetRight(-11.95f) + (difficulty * 6.9f), offset + 1, (1 - difficulty) * 6.9f, 2); Color filter = bg; filter.a = 0.7f; ui.SetBGColor(filter); } // Size is 1.2 to be clear of characters with tails if (exists) { ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(((UIScaler.GetWidthUnits() - 3) / 2) - 4, offset + 2.5f, 8, 1.2f); ui.SetBGColor(new Color(0.7f, 0, 0)); ui.SetText(CommonStringKeys.DELETE, Color.black); ui.SetButton(delegate { Delete(file); }); offset += 0.5f; } offset += 4; } foreach (KeyValuePair <string, Dictionary <string, string> > kv in localManifest.data) { // Only looking for files missing from remote bool onRemote = false; foreach (RemoteQuest rq in remoteQuests) { if (rq.name.Equals(kv.Key)) { onRemote = true; } } if (onRemote) { continue; } string type = localManifest.Get(kv.Key, "type"); // Only looking for packages of this game type if (!game.gameType.TypeName().Equals(type)) { continue; } string file = kv.Key + ".valkyrie"; // Size is 1.2 to be clear of characters with tails if (File.Exists(saveLocation() + "/" + file)) { ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(1, offset, UIScaler.GetWidthUnits() - 8, 1.2f); ui.SetTextPadding(1.2f); ui.SetText(file, Color.black); ui.SetBGColor(new Color(0.1f, 0.1f, 0.1f)); ui.SetTextAlignment(TextAnchor.MiddleLeft); ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(UIScaler.GetWidthUnits() - 12, offset, 8, 1.2f); ui.SetText(CommonStringKeys.DELETE, Color.black); ui.SetTextAlignment(TextAnchor.MiddleLeft); ui.SetButton(delegate { Delete(file); }); ui.SetBGColor(new Color(0.7f, 0, 0)); offset += 2; } } scrollArea.SetScrollSize(offset); ui = new UIElement(); ui.SetLocation(1, UIScaler.GetBottom(-3), 8, 2); ui.SetText(CommonStringKeys.BACK, Color.red); ui.SetButton(delegate { Cancel(); }); ui.SetFont(game.gameType.GetHeaderFont()); ui.SetFontSize(UIScaler.GetMediumFont()); new UIElementBorder(ui, Color.red); }
// Load a saved game, does nothing if file does not exist public static void Load(int num = 0) { Game game = Game.Get(); try { if (File.Exists(SaveFile(num))) { if (!Directory.Exists(ContentData.TempValyriePath)) { Directory.CreateDirectory(ContentData.TempValyriePath); } string valkyrieLoadPath = Path.Combine(ContentData.TempValyriePath, "Load"); if (!Directory.Exists(valkyrieLoadPath)) { Directory.CreateDirectory(valkyrieLoadPath); } Directory.Delete(valkyrieLoadPath, true); ZipManager.Extract(valkyrieLoadPath, SaveFile(num), ZipManager.Extract_mode.ZIPMANAGER_EXTRACT_FULL); string savefile_content = File.ReadAllText(Path.Combine(valkyrieLoadPath, "save.ini")); IniData saveData = IniRead.ReadFromString(savefile_content); // when loading a quest, path should always be $TMP/load/quest/$subquest/quest.ini // Make sure it is when loading a quest saved for the first time, as in that case it is the original load path string questLoadPath = Path.GetDirectoryName(saveData.Get("Quest", "path")); string questOriginalPath = saveData.Get("Quest", "originalpath"); // loading a quest saved for the first time if (questLoadPath.Contains(questOriginalPath)) { questLoadPath = questLoadPath.Replace(questOriginalPath, ContentData.ValkyrieLoadQuestPath); } // Check that quest in save is valid QuestData.Quest q = new QuestData.Quest(questLoadPath); if (!q.valid) { ValkyrieDebug.Log("Error: save contains unsupported quest version." + Environment.NewLine); GameStateManager.MainMenu(); return; } saveData.data["Quest"]["path"] = Path.Combine(questLoadPath, "quest.ini"); if (VersionManager.VersionNewer(game.version, saveData.Get("Quest", "valkyrie"))) { ValkyrieDebug.Log("Error: save is from a future version." + Environment.NewLine); GameStateManager.MainMenu(); return; } if (!VersionManager.VersionNewerOrEqual(minValkyieVersion, saveData.Get("Quest", "valkyrie"))) { ValkyrieDebug.Log("Error: save is from an old unsupported version." + Environment.NewLine); GameStateManager.MainMenu(); return; } Destroyer.Dialog(); // Load content that the save game uses Dictionary <string, string> packs = saveData.Get("Packs"); foreach (KeyValuePair <string, string> kv in packs) { // Support for save games from 1.2 and older if (kv.Key.Equals("FA")) { game.ContentLoader.LoadContentID("FAI"); game.ContentLoader.LoadContentID("FAM"); game.ContentLoader.LoadContentID("FAT"); } if (kv.Key.Equals("CotW")) { game.ContentLoader.LoadContentID("CotWI"); game.ContentLoader.LoadContentID("CotWM"); game.ContentLoader.LoadContentID("CotWT"); } if (kv.Key.Equals("MoM1E")) { game.ContentLoader.LoadContentID("MoM1EI"); game.ContentLoader.LoadContentID("MoM1EM"); game.ContentLoader.LoadContentID("MoM1ET"); } else { game.ContentLoader.LoadContentID(kv.Key); } } // This loads the game new Quest(saveData); // Draw things on the screen game.heroCanvas.SetupUI(); game.heroCanvas.UpdateImages(); game.heroCanvas.UpdateStatus(); if (game.gameType.DisplayMorale()) { game.moraleDisplay = new MoraleDisplay(); } if (!game.gameType.DisplayHeroes()) { game.heroCanvas.Clean(); } // Create the menu button new MenuButton(); new LogButton(); new SkillButton(); new InventoryButton(); game.stageUI = new NextStageButton(); } } catch (IOException e) { ValkyrieDebug.Log("Error: Unable to open save file: " + SaveFile(num) + " " + e.Message); Application.Quit(); } }
public void DrawList() { localManifest = IniRead.ReadFromString(""); if (File.Exists(saveLocation() + "/manifest.ini")) { localManifest = IniRead.ReadFromIni(saveLocation() + "/manifest.ini"); } // Heading DialogBox db = new DialogBox( new Vector2(2, 1), new Vector2(UIScaler.GetWidthUnits() - 4, 3), new StringKey("val", "QUEST_NAME_DOWNLOAD", game.gameType.QuestName()) ); db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetLargeFont(); db.SetFont(game.gameType.GetHeaderFont()); db = new DialogBox(new Vector2(1, 5f), new Vector2(UIScaler.GetWidthUnits() - 2f, 21f), StringKey.NULL); db.AddBorder(); db.background.AddComponent <UnityEngine.UI.Mask>(); UnityEngine.UI.ScrollRect scrollRect = db.background.AddComponent <UnityEngine.UI.ScrollRect>(); GameObject scrollArea = new GameObject("scroll"); RectTransform scrollInnerRect = scrollArea.AddComponent <RectTransform>(); scrollArea.transform.parent = db.background.transform; scrollInnerRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, (UIScaler.GetWidthUnits() - 3f) * UIScaler.GetPixelsPerUnit()); scrollInnerRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, 1); GameObject scrollBarObj = new GameObject("scrollbar"); scrollBarObj.transform.parent = db.background.transform; RectTransform scrollBarRect = scrollBarObj.AddComponent <RectTransform>(); scrollBarRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, 21 * UIScaler.GetPixelsPerUnit()); scrollBarRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, (UIScaler.GetWidthUnits() - 3f) * UIScaler.GetPixelsPerUnit(), 1 * UIScaler.GetPixelsPerUnit()); UnityEngine.UI.Scrollbar scrollBar = scrollBarObj.AddComponent <UnityEngine.UI.Scrollbar>(); scrollBar.direction = UnityEngine.UI.Scrollbar.Direction.BottomToTop; scrollRect.verticalScrollbar = scrollBar; GameObject scrollBarHandle = new GameObject("scrollbarhandle"); scrollBarHandle.transform.parent = scrollBarObj.transform; //RectTransform scrollBarHandleRect = scrollBarHandle.AddComponent<RectTransform>(); scrollBarHandle.AddComponent <UnityEngine.UI.Image>(); scrollBarHandle.GetComponent <UnityEngine.UI.Image>().color = new Color(0.7f, 0.7f, 0.7f); scrollBar.handleRect = scrollBarHandle.GetComponent <RectTransform>(); scrollBar.handleRect.offsetMin = Vector2.zero; scrollBar.handleRect.offsetMax = Vector2.zero; scrollRect.content = scrollInnerRect; scrollRect.horizontal = false; TextButton tb; // Start here int offset = 5; // Loop through all available quests foreach (KeyValuePair <string, Dictionary <string, string> > kv in remoteManifest.data) { string file = kv.Key + ".valkyrie"; LocalizationRead.scenarioDict = localizationDict; string questName = new StringKey("qst", kv.Key + ".name").Translate(); int remoteFormat = 0; int.TryParse(remoteManifest.Get(kv.Key, "format"), out remoteFormat); bool formatOK = (remoteFormat >= QuestData.Quest.minumumFormat) && (remoteFormat <= QuestData.Quest.currentFormat); if (!formatOK) { continue; } // Size is 1.2 to be clear of characters with tails if (File.Exists(saveLocation() + "/" + file)) { string localHash = localManifest.Get(kv.Key, "version"); string remoteHash = remoteManifest.Get(kv.Key, "version"); if (!localHash.Equals(remoteHash)) { tb = new TextButton( new Vector2(2, offset), new Vector2(UIScaler.GetWidthUnits() - 8, 1.2f), //TODO: the name should be another key in near future. now is a nonLookup key new StringKey("val", "QUEST_NAME_UPDATE", questName), delegate { Selection(file); }, Color.black, offset); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); tb.button.GetComponent <UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial"); tb.button.GetComponent <UnityEngine.UI.Text>().alignment = TextAnchor.MiddleLeft; tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0.7f, 0.7f, 1f); tb.background.transform.parent = scrollArea.transform; tb = new TextButton( new Vector2(UIScaler.GetWidthUnits() - 6, offset), new Vector2(3, 1.2f), new StringKey("val", "DELETE"), delegate { Delete(file); }, Color.black, offset); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); tb.button.GetComponent <UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial"); tb.background.GetComponent <UnityEngine.UI.Image>().color = Color.red; tb.background.transform.parent = scrollArea.transform; } else { db = new DialogBox( new Vector2(2, offset), new Vector2(UIScaler.GetWidthUnits() - 8, 1.2f), new StringKey("val", "INDENT", questName), Color.black); db.AddBorder(); db.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0.07f, 0.07f, 0.07f); db.background.transform.parent = scrollArea.transform; db.textObj.GetComponent <UnityEngine.UI.Text>().alignment = TextAnchor.MiddleLeft; db.textObj.GetComponent <UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial"); tb = new TextButton( new Vector2(UIScaler.GetWidthUnits() - 6, offset), new Vector2(3, 1.2f), new StringKey("val", "DELETE"), delegate { Delete(file); }, Color.black, offset); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); tb.button.GetComponent <UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial"); tb.background.GetComponent <UnityEngine.UI.Image>().color = Color.red; tb.background.transform.parent = scrollArea.transform; } } else { tb = new TextButton( new Vector2(2, offset), new Vector2(UIScaler.GetWidthUnits() - 5, 1.2f), new StringKey("val", "INDENT", questName), delegate { Selection(file); }, Color.black, offset); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); tb.button.GetComponent <UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial"); tb.button.GetComponent <UnityEngine.UI.Text>().alignment = TextAnchor.MiddleLeft; tb.background.GetComponent <UnityEngine.UI.Image>().color = Color.white; tb.background.transform.parent = scrollArea.transform; } offset += 2; } foreach (KeyValuePair <string, Dictionary <string, string> > kv in localManifest.data) { // Only looking for files missing from remote if (remoteManifest.data.ContainsKey(kv.Key)) { continue; } string type = localManifest.Get(kv.Key, "type"); // Only looking for packages of this game type if (!game.gameType.TypeName().Equals(type)) { continue; } string file = kv.Key + ".valkyrie"; // Size is 1.2 to be clear of characters with tails if (File.Exists(saveLocation() + "/" + file)) { db = new DialogBox( new Vector2(2, offset), new Vector2(UIScaler.GetWidthUnits() - 8, 1.2f), new StringKey("val", "INDENT", file), Color.black); db.AddBorder(); db.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0.07f, 0.07f, 0.07f); db.background.transform.parent = scrollArea.transform; db.textObj.GetComponent <UnityEngine.UI.Text>().alignment = TextAnchor.MiddleLeft; db.textObj.GetComponent <UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial"); tb = new TextButton( new Vector2(UIScaler.GetWidthUnits() - 6, offset), new Vector2(3, 1.2f), new StringKey("val", "DELETE"), delegate { Delete(file); }, Color.black, offset); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); tb.button.GetComponent <UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial"); tb.background.GetComponent <UnityEngine.UI.Image>().color = Color.red; tb.background.transform.parent = scrollArea.transform; } } scrollInnerRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, (offset - 5) * UIScaler.GetPixelsPerUnit()); tb = new TextButton( new Vector2(1, UIScaler.GetBottom(-3)), new Vector2(8, 2), CommonStringKeys.BACK, delegate { Cancel(); }, Color.red); tb.SetFont(game.gameType.GetHeaderFont()); }
public void ReadManifest() { remoteManifest = IniRead.ReadFromString(download.text); DrawList(); }
/// <summary> /// Draw download options screen /// </summary> public void DrawList() { Destroyer.Dialog(); localManifest = IniRead.ReadFromString(""); if (File.Exists(saveLocation() + "/manifest.ini")) { localManifest = IniRead.ReadFromIni(saveLocation() + "/manifest.ini"); } // Heading UIElement ui = new UIElement(); ui.SetLocation(2, 1, UIScaler.GetWidthUnits() - 4, 3); ui.SetText(new StringKey("val", "QUEST_NAME_DOWNLOAD", game.gameType.QuestName())); ui.SetFont(game.gameType.GetHeaderFont()); ui.SetFontSize(UIScaler.GetLargeFont()); UIElementScrollVertical scrollArea = new UIElementScrollVertical(); scrollArea.SetLocation(1, 5, UIScaler.GetWidthUnits() - 2f, 21f); new UIElementBorder(scrollArea); // Start here float offset = 0; // Loop through all available quests foreach (RemoteQuest rq in remoteQuests) { string file = rq.name + ".valkyrie"; string questName = rq.GetData("name." + game.currentLang); if (questName.Length == 0) { questName = rq.GetData("name." + rq.GetData("defaultlanguage")); } if (questName.Length == 0) { questName = rq.name; } int remoteFormat = 0; int.TryParse(rq.GetData("format"), out remoteFormat); bool formatOK = (remoteFormat >= QuestData.Quest.minumumFormat) && (remoteFormat <= QuestData.Quest.currentFormat); if (!formatOK) { continue; } bool exists = File.Exists(saveLocation() + Path.DirectorySeparatorChar + file); bool update = true; if (exists) { string localHash = localManifest.Get(rq.name, "version"); string remoteHash = rq.GetData("version"); update = !localHash.Equals(remoteHash); } bool has_stats_bar = false; Color bg = Color.white; Color text_color = Color.black; if (exists) { if (update) { // light pink bg = new Color(0.7f, 0.7f, 1f); text_color = Color.black; } else { // dark grey bg = new Color(0.1f, 0.1f, 0.1f); text_color = Color.grey; } } // Frame ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(0.95f, offset, UIScaler.GetWidthUnits() - 4.9f, 3.6f); ui.SetBGColor(bg); if (update) { ui.SetButton(delegate { Selection(rq); }); } offset += 0.05f; new UIElementBorder(ui, Color.grey); // Draw Image ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(1, offset, 3.5f, 3.5f); ui.SetBGColor(bg); if (update) { ui.SetButton(delegate { Selection(rq); }); } if (rq.image != null) { ui.SetImage(rq.image); } ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetBGColor(Color.clear); ui.SetLocation(5, offset, UIScaler.GetWidthUnits() - 8, 2.5f); ui.SetTextPadding(1.2f); if (update && exists) { ui.SetText(new StringKey("val", "QUEST_NAME_UPDATE", questName), text_color); } else { ui.SetText(questName, text_color); } if (update) { ui.SetButton(delegate { Selection(rq); }); } ui.SetTextAlignment(TextAnchor.MiddleLeft); ui.SetFontSize(Mathf.RoundToInt(UIScaler.GetSmallFont() * 1.4f)); // Duration int lengthMax = 0; int.TryParse(rq.GetData("lengthmax"), out lengthMax); if (lengthMax > 0) { int lengthMin = 0; int.TryParse(rq.GetData("lengthmin"), out lengthMin); ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(7f, offset + 2.3f, 4, 1); ui.SetText(new StringKey("val", "DURATION"), text_color); ui.SetTextAlignment(TextAnchor.MiddleLeft); ui.SetBGColor(Color.clear); if (update) { ui.SetButton(delegate { Selection(rq); }); } ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(11f, offset + 2.3f, 5, 1); ui.SetText(lengthMin + " - " + lengthMax, text_color); ui.SetTextAlignment(TextAnchor.MiddleLeft); ui.SetBGColor(Color.clear); if (update) { ui.SetButton(delegate { Selection(rq); }); } } // Difficulty float difficulty = 0f; float.TryParse(rq.GetData("difficulty"), out difficulty); if (difficulty != 0) { ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(UIScaler.GetHCenter() - 5.5f, offset + 2.3f, 6, 1); ui.SetText(new StringKey("val", "DIFFICULTY"), text_color); if (update) { ui.SetButton(delegate { Selection(rq); }); } ui.SetTextAlignment(TextAnchor.MiddleRight); ui.SetBGColor(Color.clear); string symbol = "π"; // will if (game.gameType is MoMGameType) { symbol = new StringKey("val", "ICON_SUCCESS_RESULT").Translate(); } ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(UIScaler.GetHCenter(), offset + 1.8f, 9, 2); ui.SetText(symbol + symbol + symbol + symbol + symbol, text_color); ui.SetBGColor(Color.clear); ui.SetFontSize(UIScaler.GetMediumFont()); if (update) { ui.SetButton(delegate { Selection(rq); }); } ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(UIScaler.GetHCenter() + 1.05f + (difficulty * 6.9f), offset + 1.8f, (1 - difficulty) * 6.9f, 1.6f); Color filter = bg; filter.a = 0.7f; ui.SetBGColor(filter); if (update) { ui.SetButton(delegate { Selection(rq); }); } } // Statistics string filename = file.ToLower(); if (game.stats != null && game.stats.scenarios_stats != null && game.stats.scenarios_stats.ContainsKey(filename)) { ScenarioStats q_stats = game.stats.scenarios_stats[filename]; int win_ratio = (int)(q_stats.scenario_avg_win_ratio * 100); StringKey STATS_AVERAGE_WIN_RATIO = new StringKey("val", "STATS_AVERAGE_WIN_RATIO", win_ratio); StringKey STATS_NO_AVERAGE_WIN_RATIO = new StringKey("val", "STATS_NO_AVERAGE_WIN_RATIO", win_ratio); StringKey STATS_NB_USER_REVIEWS = new StringKey("val", "STATS_NB_USER_REVIEWS", q_stats.scenario_play_count); StringKey STATS_AVERAGE_DURATION = new StringKey("val", "STATS_AVERAGE_DURATION", (int)(q_stats.scenario_avg_duration)); StringKey STATS_NO_AVERAGE_DURATION = new StringKey("val", "STATS_NO_AVERAGE_DURATION"); // rating string symbol = "★"; if (game.gameType is MoMGameType) { symbol = new StringKey("val", "ICON_TENTACLE").Translate(); } float rating = q_stats.scenario_avg_rating / 10; float score_text_width = 0; ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetText(symbol + symbol + symbol + symbol + symbol, text_color); score_text_width = ui.GetStringWidth(symbol + symbol + symbol + symbol + symbol, (int)System.Math.Round(UIScaler.GetMediumFont() * 1.4f)) + 1; ui.SetLocation(UIScaler.GetRight(-12f), offset + 0.6f, score_text_width, 2); ui.SetBGColor(Color.clear); ui.SetFontSize((int)System.Math.Round(UIScaler.GetMediumFont() * 1.4f)); ui.SetTextAlignment(TextAnchor.MiddleLeft); if (update) { ui.SetButton(delegate { Selection(rq); }); } ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(UIScaler.GetRight(-12) + (rating * (score_text_width - 1)), offset + 0.6f, (1 - rating) * score_text_width, 2); Color filter = bg; filter.a = 0.7f; ui.SetBGColor(filter); if (update) { ui.SetButton(delegate { Selection(rq); }); } // Number of user reviews float user_review_text_width = 0; ui = new UIElement(scrollArea.GetScrollTransform()); user_review_text_width = ui.GetStringWidth(STATS_NB_USER_REVIEWS, UIScaler.GetSmallFont()) + 1; ui.SetText(STATS_NB_USER_REVIEWS, text_color); ui.SetLocation(UIScaler.GetRight(-12) + (score_text_width / 2) - (user_review_text_width / 2), offset + 2.3f, user_review_text_width, 1); ui.SetTextAlignment(TextAnchor.MiddleLeft); ui.SetBGColor(Color.clear); ui.SetFontSize(UIScaler.GetSmallFont()); if (update) { ui.SetButton(delegate { Selection(rq); }); } if (q_stats.scenario_avg_duration > 0 || win_ratio >= 0) { has_stats_bar = true; // Additional information in frame ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(3.5f + 1f, offset + 3.6f, UIScaler.GetWidthUnits() - 4.9f - 3.5f - 0.05f, 1.2f); if (exists) { ui.SetBGColor(bg); } else { ui.SetBGColor(new Color(0.8f, 0.8f, 0.8f)); } if (update) { ui.SetButton(delegate { Selection(rq); }); } // average duration ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(6f, offset + 3.8f, 14, 1); if (q_stats.scenario_avg_duration > 0) { ui.SetText(STATS_AVERAGE_DURATION, text_color); } else { ui.SetText(STATS_NO_AVERAGE_DURATION, text_color); } ui.SetTextAlignment(TextAnchor.MiddleLeft); ui.SetBGColor(Color.clear); if (update) { ui.SetButton(delegate { Selection(rq); }); } // average win ratio ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(UIScaler.GetHCenter() - 5.5f, offset + 3.8f, 15, 1); if (win_ratio >= 0) { ui.SetText(STATS_AVERAGE_WIN_RATIO, text_color); } else { ui.SetText(STATS_NO_AVERAGE_WIN_RATIO, text_color); } ui.SetBGColor(Color.clear); ui.SetTextAlignment(TextAnchor.MiddleCenter); if (update) { ui.SetButton(delegate { Selection(rq); }); } } } // Size is 1.2 to be clear of characters with tails if (exists) { float string_width = 0; if (update) { ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetText(CommonStringKeys.UPDATE, Color.black); string_width = ui.GetStringWidth(CommonStringKeys.UPDATE, UIScaler.GetSmallFont()) + 1.3f; ui.SetButton(delegate { Delete(file); Selection(rq); }); ui.SetLocation(0.95f, offset + 3.6f, string_width, 1.2f); ui.SetBGColor(new Color(0, 0.5f, 0.68f)); // 0080AF new UIElementBorder(ui, new Color(0, 0.3f, 0.43f)); // 00516f } ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetText(CommonStringKeys.DELETE, Color.black); string_width = ui.GetStringWidth(CommonStringKeys.DELETE, UIScaler.GetSmallFont()) + 1.3f; ui.SetButton(delegate { Delete(file); }); ui.SetLocation(0.95f + UIScaler.GetWidthUnits() - 4.9f - string_width, offset + 3.6f, string_width, 1.2f); ui.SetBGColor(new Color(0.7f, 0, 0)); new UIElementBorder(ui, new Color(0.45f, 0, 0)); } if (has_stats_bar || exists) { offset += 1.2f; } offset += 4.6f; } foreach (KeyValuePair <string, Dictionary <string, string> > kv in localManifest.data) { // Only looking for files missing from remote bool onRemote = false; foreach (RemoteQuest rq in remoteQuests) { if (rq.name.Equals(kv.Key)) { onRemote = true; } } if (onRemote) { continue; } string type = localManifest.Get(kv.Key, "type"); // Only looking for packages of this game type if (!game.gameType.TypeName().Equals(type)) { continue; } string file = kv.Key + ".valkyrie"; // Size is 1.2 to be clear of characters with tails if (File.Exists(saveLocation() + Path.DirectorySeparatorChar + file)) { ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(1, offset, UIScaler.GetWidthUnits() - 8, 1.2f); ui.SetTextPadding(1.2f); ui.SetText(file, Color.black); ui.SetBGColor(new Color(0.1f, 0.1f, 0.1f)); ui.SetTextAlignment(TextAnchor.MiddleLeft); ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(UIScaler.GetWidthUnits() - 12, offset, 8, 1.2f); ui.SetText(CommonStringKeys.DELETE, Color.black); ui.SetTextAlignment(TextAnchor.MiddleLeft); ui.SetButton(delegate { Delete(file); }); ui.SetBGColor(new Color(0.7f, 0, 0)); offset += 2; } } scrollArea.SetScrollSize(offset); ui = new UIElement(); ui.SetLocation(1, UIScaler.GetBottom(-3), 8, 2); ui.SetText(CommonStringKeys.BACK, Color.red); ui.SetButton(delegate { Cancel(); }); ui.SetFont(game.gameType.GetHeaderFont()); ui.SetFontSize(UIScaler.GetMediumFont()); new UIElementBorder(ui, Color.red); }
public SaveData(int num = 0) { Game game = Game.Get(); if (!File.Exists(SaveFile(num))) { return; } try { if (!Directory.Exists(ContentData.TempValyriePath)) { Directory.CreateDirectory(ContentData.TempValyriePath); } string valkyrieLoadPath = Path.Combine(ContentData.TempValyriePath, "Preload"); if (!Directory.Exists(valkyrieLoadPath)) { Directory.CreateDirectory(valkyrieLoadPath); } ZipManager.Extract(valkyrieLoadPath, SaveFile(num), ZipManager.Extract_mode.ZIPMANAGER_EXTRACT_SAVE_INI_PIC); image = ContentData.FileToTexture(Path.Combine(valkyrieLoadPath, "image.png")); string data = File.ReadAllText(Path.Combine(valkyrieLoadPath, "save.ini")); IniData saveData = IniRead.ReadFromString(data); // when loading a quest, path should always be $TMP/load/quest/$subquest/quest.ini // Make sure it is when loading a quest saved for the first time, as in that case it is the original load path string questLoadPath = Path.GetDirectoryName(saveData.Get("Quest", "path")); string questOriginalPath = saveData.Get("Quest", "originalpath"); // loading a quest saved for the first time if (questLoadPath.Contains(questOriginalPath)) { questLoadPath = questLoadPath.Replace(questOriginalPath, ContentData.ValkyrieLoadQuestPath); } // use preload path rather than load questLoadPath = questLoadPath.Replace(ContentData.ValkyrieLoadPath, ContentData.ValkyriePreloadPath); QuestData.Quest q = new QuestData.Quest(questLoadPath); if (!q.valid) { ValkyrieDebug.Log("Warning: Save " + num + " contains unsupported quest version." + Environment.NewLine); return; } quest_name = saveData.Get("Quest", "questname"); if (VersionManager.VersionNewer(game.version, saveData.Get("Quest", "valkyrie"))) { ValkyrieDebug.Log("Warning: Save " + num + " is from a future version." + Environment.NewLine); return; } if (!VersionManager.VersionNewerOrEqual(minValkyieVersion, saveData.Get("Quest", "valkyrie"))) { ValkyrieDebug.Log("Warning: Save " + num + " is from an old unsupported version." + Environment.NewLine); return; } saveTime = DateTime.Parse(saveData.Get("Quest", "time")); valid = true; } catch (Exception e) { ValkyrieDebug.Log("Warning: Unable to open save file: " + SaveFile(num) + "\nException: " + e.ToString()); } }
// Load a saved game, does nothing if file does not exist public static void Load(int num = 0) { Game game = Game.Get(); try { if (File.Exists(SaveFile(num))) { if (!Directory.Exists(Path.GetTempPath() + "/Valkyrie")) { Directory.CreateDirectory(Path.GetTempPath() + "/Valkyrie"); } if (!Directory.Exists(Path.GetTempPath() + "/Valkyrie/Load")) { Directory.CreateDirectory(Path.GetTempPath() + "/Valkyrie/Load"); } Directory.Delete(Path.GetTempPath() + "/Valkyrie/Load", true); ZipFile zip = ZipFile.Read(SaveFile(num)); zip.ExtractAll(Path.GetTempPath() + "/Valkyrie/Load"); zip.Dispose(); // Check that quest in save is valid QuestData.Quest q = new QuestData.Quest(Path.GetTempPath() + "/Valkyrie/Load/quest"); if (!q.valid) { ValkyrieDebug.Log("Error: save contains unsupported quest version." + System.Environment.NewLine); Destroyer.MainMenu(); return; } string data = File.ReadAllText(Path.GetTempPath() + "/Valkyrie/Load/save.ini"); IniData saveData = IniRead.ReadFromString(data); saveData.data["Quest"]["path"] = Path.GetTempPath() + "/Valkyrie/Load/quest/quest.ini"; saveData.Get("Quest", "valkyrie"); if (VersionNewer(game.version, saveData.Get("Quest", "valkyrie"))) { ValkyrieDebug.Log("Error: save is from a future version." + System.Environment.NewLine); Destroyer.MainMenu(); return; } if (!VersionNewerOrEqual(minValkyieVersion, saveData.Get("Quest", "valkyrie"))) { ValkyrieDebug.Log("Error: save is from an old unsupported version." + System.Environment.NewLine); Destroyer.MainMenu(); return; } Destroyer.Dialog(); // Restart contend data so we can select from save game.cd = new ContentData(game.gameType.DataDirectory()); // Check if we found anything if (game.cd.GetPacks().Count == 0) { ValkyrieDebug.Log("Error: Failed to find any content packs, please check that you have them present in: " + game.gameType.DataDirectory() + System.Environment.NewLine); Application.Quit(); } game.cd.LoadContentID(""); // Load the base content // Load content that the save game uses Dictionary <string, string> packs = saveData.Get("Packs"); foreach (KeyValuePair <string, string> kv in packs) { game.cd.LoadContentID(""); // Support for save games from 1.2 and older if (kv.Key.Equals("FA")) { game.cd.LoadContentID("FAI"); game.cd.LoadContentID("FAM"); game.cd.LoadContentID("FAT"); } if (kv.Key.Equals("CotW")) { game.cd.LoadContentID("CotWI"); game.cd.LoadContentID("CotWM"); game.cd.LoadContentID("CotWT"); } if (kv.Key.Equals("MoM1E")) { game.cd.LoadContentID("MoM1EI"); game.cd.LoadContentID("MoM1EM"); game.cd.LoadContentID("MoM1ET"); } else { game.cd.LoadContentID(kv.Key); } } // This loads the game new Quest(saveData); // Draw things on the screen game.heroCanvas.SetupUI(); game.heroCanvas.UpdateImages(); game.heroCanvas.UpdateStatus(); if (game.gameType.DisplayMorale()) { game.moraleDisplay = new MoraleDisplay(); } if (!game.gameType.DisplayHeroes()) { game.heroCanvas.Clean(); } // Create the menu button new MenuButton(); new LogButton(); new SkillButton(); new InventoryButton(); game.stageUI = new NextStageButton(); } } catch (System.Exception e) { ValkyrieDebug.Log("Error: Unable to open save file: " + SaveFile(num) + " " + e.Message); Application.Quit(); } }
// Construct a quest from save data string // Used for undo public Quest(string save) { LoadQuest(IniRead.ReadFromString(save)); }
public SaveData(int num = 0) { Game game = Game.Get(); if (!File.Exists(SaveFile(num))) { return; } try { if (!Directory.Exists(Path.GetTempPath() + "/Valkyrie")) { Directory.CreateDirectory(Path.GetTempPath() + "/Valkyrie"); } if (!Directory.Exists(Path.GetTempPath() + "/Valkyrie/Load")) { Directory.CreateDirectory(Path.GetTempPath() + "/Valkyrie/Load"); } Directory.Delete(Path.GetTempPath() + "/Valkyrie/Load", true); ZipFile zip = ZipFile.Read(SaveFile(num)); zip.ExtractAll(Path.GetTempPath() + "/Valkyrie/Load"); zip.Dispose(); image = ContentData.FileToTexture(Path.GetTempPath() + "/Valkyrie/Load/image.png"); // Check that quest in save is valid QuestData.Quest q = new QuestData.Quest(Path.GetTempPath() + "/Valkyrie/Load/quest"); if (!q.valid) { ValkyrieDebug.Log("Warning: Save " + num + " contains unsupported quest version." + System.Environment.NewLine); return; } DictionaryI18n tmpDict = LocalizationRead.selectDictionary("qst"); LocalizationRead.AddDictionary("qst", q.localizationDict); quest = q.name.Translate(); LocalizationRead.AddDictionary("qst", tmpDict); string data = File.ReadAllText(Path.GetTempPath() + "/Valkyrie/Load/save.ini"); IniData saveData = IniRead.ReadFromString(data); saveData.Get("Quest", "valkyrie"); if (VersionNewer(game.version, saveData.Get("Quest", "valkyrie"))) { ValkyrieDebug.Log("Warning: Save " + num + " is from a future version." + System.Environment.NewLine); return; } if (!VersionNewerOrEqual(minValkyieVersion, saveData.Get("Quest", "valkyrie"))) { ValkyrieDebug.Log("Warning: Save " + num + " is from an old unsupported version." + System.Environment.NewLine); return; } saveTime = System.DateTime.Parse(saveData.Get("Quest", "time")); valid = true; } catch (System.Exception e) { ValkyrieDebug.Log("Warning: Unable to open save file: " + SaveFile(num) + " " + e.Message); } }
public void DrawList() { localManifest = IniRead.ReadFromString(""); if (File.Exists(saveLocation() + "/manifest.ini")) { localManifest = IniRead.ReadFromIni(saveLocation() + "/manifest.ini"); } // Heading DialogBox db = new DialogBox(new Vector2(2, 1), new Vector2(UIScaler.GetWidthUnits() - 4, 3), "Download " + game.gameType.QuestName()); db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetLargeFont(); db.SetFont(game.gameType.GetHeaderFont()); db = new DialogBox(new Vector2(1, 5f), new Vector2(UIScaler.GetWidthUnits() - 2f, 21f), ""); db.AddBorder(); db.background.AddComponent <UnityEngine.UI.Mask>(); UnityEngine.UI.ScrollRect scrollRect = db.background.AddComponent <UnityEngine.UI.ScrollRect>(); GameObject scrollArea = new GameObject("scroll"); RectTransform scrollInnerRect = scrollArea.AddComponent <RectTransform>(); scrollArea.transform.parent = db.background.transform; scrollInnerRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, (UIScaler.GetWidthUnits() - 3f) * UIScaler.GetPixelsPerUnit()); scrollInnerRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, 1); scrollRect.content = scrollInnerRect; scrollRect.horizontal = false; TextButton tb; // Start here int offset = 5; // Loop through all available quests foreach (KeyValuePair <string, Dictionary <string, string> > kv in remoteManifest.data) { string file = kv.Key + ".valkyrie"; // Size is 1.2 to be clear of characters with tails if (File.Exists(saveLocation() + "/" + file)) { int localVersion = 0; int remoteVersion = 0; int.TryParse(localManifest.Get(kv.Key, "version"), out localVersion); int.TryParse(remoteManifest.Get(kv.Key, "version"), out remoteVersion); if (localVersion < remoteVersion) { tb = new TextButton(new Vector2(2, offset), new Vector2(UIScaler.GetWidthUnits() - 5, 1.2f), " [Update] " + kv.Value["name"], delegate { Selection(file); }, Color.black, offset); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); tb.button.GetComponent <UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial"); tb.button.GetComponent <UnityEngine.UI.Text>().alignment = TextAnchor.MiddleLeft; tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0.7f, 0.7f, 1f); tb.background.transform.parent = scrollArea.transform; } else { db = new DialogBox(new Vector2(2, offset), new Vector2(UIScaler.GetWidthUnits() - 5, 1.2f), " " + kv.Value["name"], Color.black); db.AddBorder(); db.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0.07f, 0.07f, 0.07f); db.background.transform.parent = scrollArea.transform; db.textObj.GetComponent <UnityEngine.UI.Text>().alignment = TextAnchor.MiddleLeft; db.textObj.GetComponent <UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial"); } } else { tb = new TextButton(new Vector2(2, offset), new Vector2(UIScaler.GetWidthUnits() - 5, 1.2f), " " + kv.Value["name"], delegate { Selection(file); }, Color.black, offset); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); tb.button.GetComponent <UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial"); tb.button.GetComponent <UnityEngine.UI.Text>().alignment = TextAnchor.MiddleLeft; tb.background.GetComponent <UnityEngine.UI.Image>().color = Color.white; tb.background.transform.parent = scrollArea.transform; } offset += 2; } scrollInnerRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, (offset - 5) * UIScaler.GetPixelsPerUnit()); tb = new TextButton(new Vector2(1, UIScaler.GetBottom(-3)), new Vector2(8, 2), "Back", delegate { Cancel(); }, Color.red); tb.SetFont(game.gameType.GetHeaderFont()); }