示例#1
0
        public static bool RemoveUserShow(UserShowDef userShow)
        {
            // Remove from settings
            RimFlixSettings settings = LoadedModManager.GetMod <RimFlixMod>().GetSettings <RimFlixSettings>();

            if (!settings.UserShows.Contains(userShow))
            {
                Log.Message($"RimFlix: Could not find show {userShow.defName} : {userShow.label}");
                return(false);
            }
            bool result = settings.UserShows.Remove(userShow);

            // We can't delete from DefDatabase, so mark as deleted
            userShow.deleted = true;

            // Do not remove graphic data if there are other shows with same path
            IEnumerable <UserShowDef> twins = DefDatabase <UserShowDef> .AllDefs.Where(s => (s.path?.Equals(userShow.path) ?? false) && !s.deleted);

            if (!twins.Any())
            {
                foreach (GraphicData frame in userShow.frames)
                {
                    result = RimFlixContent.contentList.Remove(frame.texPath);
                }
            }
            RimFlixSettings.showUpdateTime = RimFlixSettings.TotalSeconds;
            return(true);
        }
示例#2
0
        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);
        }
示例#3
0
        public Dialog_AddShow(UserShowDef userShow = null, RimFlixMod mod = null)
        {
            // Window properties
            this.doCloseX                = true;
            this.doCloseButton           = false;
            this.forcePause              = true;
            this.absorbInputAroundWindow = true;

            // Initialize object
            this.settings   = LoadedModManager.GetMod <RimFlixMod>().GetSettings <RimFlixSettings>();
            this.refreshTex = ContentFinder <Texture2D> .Get("UI/Buttons/Refresh", true);

            Vector2 v1 = Text.CalcSize("RimFlix_TimeSeconds".Translate());
            Vector2 v2 = Text.CalcSize("RimFlix_TimeTicks".Translate());

            this.timeUnitWidth  = Math.Max(v1.x, v2.x) + this.padding * 2;
            this.timeInputWidth = this.optionsWidth - this.timeUnitWidth - this.padding * 2;
            this.timeUnitMenu   = new List <FloatMenuOption>
            {
                new FloatMenuOption("RimFlix_TimeSeconds".Translate(), delegate { this.timeUnit = TimeUnit.Second; }),
                new FloatMenuOption("RimFlix_TimeTicks".Translate(), delegate { this.timeUnit = TimeUnit.Tick; })
            };
            this.timeUnitLabels = new string[]
            {
                "RimFlix_TimeSeconds".Translate(),
                "RimFlix_TimeTicks".Translate()
            };
            string s = new string(Path.GetInvalidFileNameChars());

            this.pathValidator = new Regex(string.Format("[^{0}]*", Regex.Escape(s)));
            try
            {
                this.drives = Directory.GetLogicalDrives();
            }
            catch (Exception ex)
            {
                Log.Message($"RimFlix: Exception for GetLogicalDrives():\n{ex}");
                this.filesWidth += this.drivesWidth;
                this.drivesWidth = 0;
            }

            // Show properties
            if (userShow != null)
            {
                this.showName    = userShow.label;
                this.currentPath = userShow.path;
                this.timeValue   = userShow.secondsBetweenFrames;
                this.playTube    = userShow.televisionDefStrings.Contains("TubeTelevision");
                this.playFlat    = userShow.televisionDefStrings.Contains("FlatscreenTelevision");
                this.playMega    = userShow.televisionDefStrings.Contains("MegascreenTelevision");
            }
            else
            {
                this.showName    = "RimFlix_DefaultName".Translate();
                this.currentPath = Directory.Exists(this.settings.lastPath) ? this.settings.lastPath : this.settings.defaultPath;
                this.timeValue   = 10;
                this.playTube    = false;
                this.playFlat    = false;
                this.playMega    = false;
            }
            this.currentUserShow = userShow;
            this.mod             = mod;
        }
示例#4
0
        private bool CreateShow()
        {
            // Check if path contains images
            if (!Directory.Exists(this.currentPath))
            {
                Find.WindowStack.Add(new Dialog_MessageBox("RimFlix_DirNotFound".Translate(this.currentPath)));
                return(false);
            }

            // Check if name exists
            if (this.showName.NullOrEmpty())
            {
                Find.WindowStack.Add(new Dialog_MessageBox("RimFlix_NoShowName".Translate()));
                return(false);
            }

            // Check if at least one television type is selected
            if (!(this.playTube || this.playFlat || this.playMega))
            {
                Find.WindowStack.Add(new Dialog_MessageBox("RimFlix_NoTelevisionType".Translate()));
                return(false);
            }

            // Create or modify user show
            UserShowDef userShow = this.currentUserShow ?? new UserShowDef()
            {
                defName = UserContent.GetUniqueId()
            };

            userShow.path                 = this.currentPath;
            userShow.label                = this.showName;
            userShow.description          = $"{"RimFlix_CustomDescPrefix".Translate(this.currentPath, DateTime.Now.ToString())}";
            userShow.secondsBetweenFrames = (this.timeUnit == TimeUnit.Tick) ? this.timeValue / 60f : this.timeValue;
            userShow.televisionDefStrings = new List <string>();
            if (this.playTube)
            {
                userShow.televisionDefStrings.Add("TubeTelevision");
            }
            if (this.playFlat)
            {
                userShow.televisionDefStrings.Add("FlatscreenTelevision");
            }
            if (this.playMega)
            {
                userShow.televisionDefStrings.Add("MegascreenTelevision");
            }

            // Load show assets and add to def database
            if (!UserContent.LoadUserShow(userShow))
            {
                Log.Message($"RimFlix: Unable to load assets for {userShow.defName} : {userShow.label}");
                Find.WindowStack.Add(new Dialog_MessageBox($"{"RimFlix_LoadError".Translate()}"));
                return(false);
            }

            // Add show to settings
            if (this.currentUserShow == null)
            {
                this.settings.UserShows.Add(userShow);
            }

            // Mark shows as dirty
            RimFlixSettings.showUpdateTime = RimFlixSettings.TotalSeconds;

            // If editing a show, avoid requerying shows to keep sort order
            if (this.currentUserShow != null)
            {
                userShow.SortName  = $"{"RimFlix_UserShowLabel".Translate()} : {userShow.label}";
                mod.ShowUpdateTime = RimFlixSettings.showUpdateTime;
            }
            return(true);
        }