bool IsReady() { if (!dfUnity) { dfUnity = DaggerfallUnity.Instance; } if (itemHelper == null) { itemHelper = new ItemHelper(); } if (!dfUnity.IsReady || string.IsNullOrEmpty(dfUnity.Arena2Path)) { return(false); } if (factionFile == null) { factionFile = new FactionFile(Path.Combine(dfUnity.Arena2Path, FactionFile.Filename), FileUsage.UseMemory, true); } if (saveGames == null || saveTrees == null || saveNames == null) { saveGames = new SaveGames(); saveNames = new GUIContent[6]; saveTrees = new SaveTree[6]; saveVars = new SaveVars[6]; saveTextures = new Texture2D[6]; if (saveGames.OpenSavesPath(Path.GetDirectoryName(DaggerfallUnity.Instance.Arena2Path))) { for (int i = 0; i < 6; i++) { if (saveGames.HasSave(i)) { saveGames.OpenSave(i); saveTrees[i] = saveGames.SaveTree; saveVars[i] = saveGames.SaveVars; saveNames[i] = new GUIContent(saveGames.SaveName); saveTextures[i] = TextureReader.CreateFromAPIImage(saveGames.SaveImage); saveTextures[i].filterMode = FilterMode.Point; } else { saveTrees[i] = null; saveVars[i] = null; saveTextures[i] = null; saveNames[i] = new GUIContent("Empty"); } } } } return(true); }
bool IsReady() { if (!dfUnity) { dfUnity = DaggerfallUnity.Instance; } if (itemHelper == null) { itemHelper = new ItemHelper(); } if (!dfUnity.IsReady || string.IsNullOrEmpty(dfUnity.Arena2Path)) { return(false); } if (factionFile == null) { factionFile = new FactionFile(dfUnity.ContentReader.GetFactionFilePath(), FileUsage.UseMemory, true); } if (saveGames == null || saveTrees == null || saveNames == null) { saveGames = new SaveGames(); saveNames = new GUIContent[6]; saveTrees = new SaveTree[6]; saveVars = new SaveVars[6]; saveTextures = new Texture2D[6]; if (saveGames.OpenSavesPath(Path.GetDirectoryName(DaggerfallUnity.Instance.Arena2Path))) { for (int i = 0; i < 6; i++) { if (saveGames.HasSave(i)) { saveGames.OpenSave(i, false); saveTrees[i] = saveGames.SaveTree; saveVars[i] = saveGames.SaveVars; saveNames[i] = new GUIContent(saveGames.SaveName); saveTextures[i] = TextureReader.CreateFromAPIImage(saveGames.SaveImage); saveTextures[i].filterMode = FilterMode.Point; } else { saveTrees[i] = null; saveVars[i] = null; saveTextures[i] = null; saveNames[i] = new GUIContent("Empty"); } } } // Prevent duplicate names so save games aren't automatically removed from the Save Select GUI for (int i = 0; i < saveNames.Length; i++) { int duplicateCount = 0; for (int j = i + 1; j < saveNames.Length; j++) { if (saveNames[j].text == saveNames[i].text) { bool unique = false; while (!unique) { unique = true; string replaceText = saveNames[j].text + "(" + ++duplicateCount + ")"; for (int k = 0; k < saveNames.Length; k++) { if (saveNames[k].text == replaceText) { unique = false; break; } } if (unique) { saveNames[j].text = replaceText; } } } } } } return(true); }