예제 #1
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);
        }
예제 #2
0
        private void DoShows(Rect rect)
        {
            // 864 x 418
            float cellHeight  = Text.LineHeight;
            float cellPadding = 2;
            float nameWidth   = 434;
            float framesWidth = 80;
            float timeWidth   = 80;
            float tubeWidth   = 40;
            float flatWidth   = 40;
            float megaWidth   = 40;
            float editWidth   = 60;
            float deleteWidth = 60;

            // Header row
            GUI.skin.GetStyle("Label").alignment = TextAnchor.MiddleCenter;
            Text.Anchor = TextAnchor.MiddleCenter;
            Rect headerRect = rect.TopPartPixels(cellHeight);

            //Widgets.DrawMenuSection(headerRect);
            Widgets.DrawLineHorizontal(headerRect.x, headerRect.y + cellHeight, headerRect.width);
            float x = headerRect.x;
            float y = headerRect.y;

            Rect nameRect = new Rect(x, y, nameWidth, cellHeight);

            TooltipHandler.TipRegion(nameRect, $"{"RimFlix_SortHeader".Translate()} {"RimFlix_NameHeader".Translate()}");
            if (GUI.Button(nameRect, $"RimFlix_NameHeader".Translate(), GUI.skin.GetStyle("Label")))
            {
                this.sortType = SortType.Name;
                this.shows    = GetSortedShows(true);
            }
            x += nameWidth + cellPadding;

            Rect framesRect = new Rect(x, y, framesWidth, cellHeight);

            TooltipHandler.TipRegion(framesRect, $"{"RimFlix_SortHeader".Translate()} {"RimFlix_FramesHeader".Translate()}");
            if (GUI.Button(framesRect, "RimFlix_FramesHeader".Translate(), GUI.skin.GetStyle("Label")))
            {
                this.sortType = SortType.Frames;
                this.shows    = GetSortedShows(true);
            }
            x += framesWidth + cellPadding;

            Rect timeRect = new Rect(x, y, framesWidth, cellHeight);

            TooltipHandler.TipRegion(timeRect, $"{"RimFlix_SortHeader".Translate()} {"RimFlix_SecFrameHeader".Translate()}");
            if (GUI.Button(timeRect, "RimFlix_SecFrameHeader".Translate(), GUI.skin.GetStyle("Label")))
            {
                this.sortType = SortType.Time;
                this.shows    = GetSortedShows(true);
            }
            x += timeWidth + cellPadding;

            Rect tubeRect = new Rect(x, y, tubeWidth, cellHeight);

            Widgets.DrawTextureFitted(tubeRect, this.TubeTex, 0.6f);
            TooltipHandler.TipRegion(tubeRect, ThingDef.Named("TubeTelevision").LabelCap);
            if (GUI.Button(tubeRect, "", GUI.skin.GetStyle("Label")))
            {
                this.sortType = SortType.Tube;
                this.shows    = GetSortedShows(true);
            }
            x += tubeWidth + cellPadding;

            Rect flatRect = new Rect(x, y, flatWidth, cellHeight);

            Widgets.DrawTextureFitted(flatRect, this.FlatTex, 0.55f);
            TooltipHandler.TipRegion(flatRect, ThingDef.Named("FlatscreenTelevision").LabelCap);
            if (GUI.Button(flatRect, "", GUI.skin.GetStyle("Label")))
            {
                this.sortType = SortType.Flat;
                this.shows    = GetSortedShows(true);
            }
            x += flatWidth + cellPadding;

            Rect megaRect = new Rect(x, y, megaWidth, cellHeight);

            Widgets.DrawTextureFitted(megaRect, this.MegaTex, 0.9f);
            TooltipHandler.TipRegion(megaRect, ThingDef.Named("MegascreenTelevision").LabelCap);
            if (GUI.Button(megaRect, "", GUI.skin.GetStyle("Label")))
            {
                this.sortType = SortType.Mega;
                this.shows    = GetSortedShows(true);
            }
            x += megaWidth + cellPadding;

            Rect actionRect = new Rect(x, y, editWidth + deleteWidth + cellPadding, cellHeight);

            //Widgets.Label(actionRect, "RimFlix_ActionsHeader".Translate());
            if (GUI.Button(actionRect, "RimFlix_ActionsHeader".Translate(), GUI.skin.GetStyle("Label")))
            {
                this.sortType = SortType.Action;
                this.shows    = GetSortedShows(true);
            }
            Rect editRect   = new Rect(x, y, editWidth, cellHeight);
            Rect deleteRect = new Rect(x + editWidth + cellPadding, y, deleteWidth, cellHeight);

            // Table rows
            Text.Anchor = TextAnchor.UpperLeft;
            Rect tableRect = rect.BottomPartPixels(rect.height - cellHeight - cellPadding);

            x = tableRect.x;
            y = tableRect.y + cellPadding;
            float viewHeight = this.Shows.Count * (cellHeight + cellPadding) + 50f;
            Rect  viewRect   = new Rect(x, y, tableRect.width - this.scrollBarWidth, viewHeight);
            Rect  rowRect    = new Rect(x, y, rect.width, cellHeight);

            Widgets.BeginScrollView(tableRect, ref this.scrollPos, viewRect, true);
            int index = 0;

            foreach (ShowDef show in this.Shows)
            {
                rowRect.y = nameRect.y = framesRect.y = timeRect.y = tubeRect.y = flatRect.y = megaRect.y = actionRect.y = editRect.y = deleteRect.y = y + (cellHeight + cellPadding) * index++;

                if (index % 2 == 1)
                {
                    //Widgets.DrawAltRect(rectRow);
                    Widgets.DrawAltRect(nameRect);
                    Widgets.DrawAltRect(framesRect);
                    Widgets.DrawAltRect(timeRect);
                    Widgets.DrawAltRect(tubeRect);
                    Widgets.DrawAltRect(flatRect);
                    Widgets.DrawAltRect(megaRect);
                    Widgets.DrawAltRect(editRect);
                    Widgets.DrawAltRect(deleteRect);
                }
                if (show.disabled)
                {
                    GUI.color = this.disabledTextColor;
                }
                Widgets.DrawHighlightIfMouseover(rowRect);

                Text.Anchor = TextAnchor.MiddleLeft;
                TooltipHandler.TipRegion(nameRect, show.description);
                Widgets.Label(nameRect, show.SortName);

                Text.Anchor = TextAnchor.MiddleRight;
                Widgets.Label(framesRect, $"{show.frames.Count} ");
                Widgets.Label(timeRect, $"{show.secondsBetweenFrames:F2} ");

                Text.Anchor = TextAnchor.MiddleCenter;
                TooltipHandler.TipRegion(tubeRect, ThingDef.Named("TubeTelevision").LabelCap);
                if (show.televisionDefs.Contains(ThingDef.Named("TubeTelevision")))
                {
                    Widgets.DrawTextureFitted(tubeRect, this.TubeTex, 0.6f);
                    TooltipHandler.TipRegion(tubeRect, ThingDef.Named("TubeTelevision").LabelCap);
                }

                TooltipHandler.TipRegion(flatRect, ThingDef.Named("FlatscreenTelevision").LabelCap);
                if (show.televisionDefs.Contains(ThingDef.Named("FlatscreenTelevision")))
                {
                    Widgets.DrawTextureFitted(flatRect, this.FlatTex, 0.55f);
                    TooltipHandler.TipRegion(flatRect, ThingDef.Named("FlatscreenTelevision").LabelCap);
                }

                TooltipHandler.TipRegion(megaRect, ThingDef.Named("MegascreenTelevision").LabelCap);
                if (show.televisionDefs.Contains(ThingDef.Named("MegascreenTelevision")))
                {
                    Widgets.DrawTextureFitted(megaRect, this.MegaTex, 0.9f);
                    TooltipHandler.TipRegion(megaRect, ThingDef.Named("MegascreenTelevision").LabelCap);
                }

                GUI.color = Color.white;
                if (show is UserShowDef userShow)
                {
                    if (Widgets.ButtonText(editRect, "RimFlix_EditButton".Translate()))
                    {
                        Find.WindowStack.Add(new Dialog_AddShow(userShow, this));
                    }
                    if (Widgets.ButtonText(deleteRect, "RimFlix_DeleteButton".Translate()))
                    {
                        Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation(
                                                 "RimFlix_ConfirmDelete".Translate(userShow.SortName), delegate
                        {
                            UserContent.RemoveUserShow(userShow);
                        }, true, null));
                    }
                }
                else
                {
                    if (show.disabled)
                    {
                        if (Widgets.ButtonText(actionRect, "RimFlix_EnableButton".Translate()))
                        {
                            show.disabled = false;
                            this.settings.DisabledShows.Remove(show.defName);
                            // We want to alert CompScreen of show update, but avoid messing up sort order by requerying here
                            this.ShowUpdateTime = RimFlixSettings.showUpdateTime = RimFlixSettings.TotalSeconds;
                        }
                    }
                    else
                    {
                        if (Widgets.ButtonText(actionRect, "RimFlix_DisableButton".Translate()))
                        {
                            show.disabled = true;
                            this.settings.DisabledShows.Add(show.defName);
                            // We want to alert CompScreen of show update, but avoid messing up sort order by requerying here
                            this.ShowUpdateTime = RimFlixSettings.showUpdateTime = RimFlixSettings.TotalSeconds;
                        }
                    }
                }

                if (show.disabled)
                {
                    GUI.DrawTexture(rowRect, this.DisabledTex);
                    Vector2 leftVec  = new Vector2(rowRect.x, rowRect.y + cellHeight / 2);
                    Vector2 rightVec = new Vector2(rowRect.x + rowRect.width - this.scrollBarWidth, rowRect.y + cellHeight / 2);
                    Widgets.DrawLine(leftVec, rightVec, this.disabledLineColor, 2f);
                }
            }
            Widgets.EndScrollView();
            GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperLeft;
            Text.Anchor = TextAnchor.UpperLeft;
        }