public static void DrawLanguageOption(Rect rect) { if (Game.Mode == GameMode.Entry) { var lang = LanguageDatabase.activeLanguage; if (lang.icon.NullOrBad()) { // Try fix bas flag texture var fileInfo = new FileInfo(Path.Combine("Mods", Path.Combine("Core", Path.Combine("Languages", Path.Combine(lang.folderName.ToString(), "LangIcon.png"))))); if (fileInfo.Exists) { LanguageDatabase.activeLanguage.icon = ModContentLoader <Texture2D> .LoadItem(fileInfo.FullName).contentItem; } } if ( Widgets.ImageButton( rect, LanguageDatabase.activeLanguage.icon) ) { var languageOptions = new List <FloatMenuOption>(); foreach (LoadedLanguage selectedLanguage in LanguageDatabase.AllLoadedLanguages) { languageOptions.Add( new FloatMenuOption( selectedLanguage.FriendlyNameNative, () => { if (selectedLanguage != Verse.LanguageDatabase.activeLanguage) { // Only reload if it changed LanguageDatabase.SelectLanguage(selectedLanguage); Prefs.Save(); } }, MenuOptionPriority.Medium) ); } Find.WindowStack.Add((Window) new FloatMenu(languageOptions, false)); } } }
public static bool LoadUserShow(UserShowDef userShow, bool addToDefDatabase = true) { // Get images in path IEnumerable <string> filePaths = Enumerable.Empty <string>(); if (!Directory.Exists(userShow.path)) { Log.Message($"RimFlix {userShow.defName} : {userShow.label}: Path <{userShow.path}> does not exist."); return(false); } try { DirectoryInfo dirInfo = new DirectoryInfo(userShow.path); filePaths = from file in dirInfo.GetFiles() where file.Name.ToLower().EndsWith(".jpg") || file.Name.ToLower().EndsWith(".png") where (file.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden select file.FullName; } catch { Log.Message($"RimFlix {userShow.defName} : {userShow.label}: Error trying to load files from <{userShow.path}>."); return(false); } if (!filePaths.Any()) { Log.Message($"RimFlix {userShow.defName} : {userShow.label}: No images found in <{userShow.path}>."); // User may want to keep a show with an empty directory for future use. //return false; } // Load textures for images userShow.frames = new List <GraphicData>(); foreach (string filePath in filePaths) { // RimWorld sets internalPath to filePath without extension // This causes problems with files that have same name but different extension (file.jpg, file.png) string internalPath = filePath.Replace('\\', '/'); if (!RimFlixContent.contentList.ContainsKey(internalPath)) { string path = Path.GetDirectoryName(filePath); string file = Path.GetFileName(filePath); VirtualFile virtualFile = AbstractFilesystem.GetDirectory(path).GetFile(file); LoadedContentItem <Texture2D> loadedContentItem = ModContentLoader <Texture2D> .LoadItem(virtualFile); RimFlixContent.contentList.Add(internalPath, loadedContentItem.contentItem); } userShow.frames.Add(new GraphicData { texPath = internalPath, graphicClass = typeof(Graphic_Single) }); } // Create televisionDefs list userShow.televisionDefs = new List <ThingDef>(); foreach (string televisionDefString in userShow.televisionDefStrings) { userShow.televisionDefs.Add(ThingDef.Named(televisionDefString)); } // Add user show to def database if (!DefDatabase <ShowDef> .AllDefs.Contains(userShow)) { DefDatabase <ShowDef> .Add(userShow); } return(true); }