Esempio n. 1
0
        private static void MenuScene_BuildScene(On.Menu.MenuScene.orig_BuildScene orig, MenuScene self)
        {
            // Automatically override scenes if the current character has a scene by the same name
            SlugBaseCharacter currentPlayer;

            if (PlayerManager.UsingCustomCharacter)
            {
                currentPlayer = PlayerManager.CurrentCharacter;
            }
            else
            {
                int index;
                if (self.menu.manager.currentMainLoop is RainWorldGame rwg)
                {
                    index = rwg.StoryCharacter;
                }
                else
                {
                    index = self.menu.manager.rainWorld.progression.PlayingAsSlugcat;
                }
                currentPlayer = PlayerManager.GetCustomPlayer(index);
            }

            if (currentPlayer != null)
            {
                string sceneName = self.sceneID.ToString();
                if (sceneOverride == null && currentPlayer.HasScene(sceneName))
                {
                    OverrideNextScene(currentPlayer, sceneName);
                }
            }

            if (sceneOverride != null)
            {
                try
                {
                    self.sceneFolder = resourceFolderName;

                    // Check for flatmode support
                    bool hasFlatmode = false;
                    foreach (var img in sceneOverride.Images)
                    {
                        if (img.HasTag("FLATMODE"))
                        {
                            hasFlatmode = true;
                            break;
                        }
                    }

                    // Load all images into the scene
                    for (int imgIndex = 0; imgIndex < sceneOverride.Images.Count; imgIndex++)
                    {
                        var img = sceneOverride.Images[imgIndex];

                        // Hide disabled images
                        if (!img.Enabled)
                        {
                            continue;
                        }

                        // Allow images to use their own sprites
                        if (!img.OnBuild(self))
                        {
                            continue;
                        }

                        // Skip this image if it is flatmode only and flatmode is disabled, and vice versa
                        bool flat         = img.depth < 0f;
                        bool flatmodeOnly = hasFlatmode && img.HasTag("flatmode");
                        if (hasFlatmode && (self.flatMode != flatmodeOnly))
                        {
                            continue;
                        }

                        // Parse alpha
                        float alpha = img.GetProperty <float?>("alpha") ?? 1f;

                        string  assetPath  = $"{sceneOverride.Owner.Name}\\Scenes\\{sceneOverride.Name}\\{img.assetName}";
                        Vector2 pos        = img.Pos;
                        bool    crisp      = img.HasTag("CRISP");
                        string  shaderName = img.GetProperty <string>("shader");
                        FShader shader     = null;

                        MenuIllustration illust;
                        if (flat)
                        {
                            // It's Friday

                            // Parse shader
                            if (shaderName != null)
                            {
                                if (!self.menu.manager.rainWorld.Shaders.TryGetValue(shaderName, out shader))
                                {
                                    shader = null;
                                }
                            }

                            // Add a flat illustration
                            illust = new MenuIllustration(self.menu, self, self.sceneFolder, assetPath, pos, crisp, false);
                            if (shader != null)
                            {
                                illust.sprite.shader = shader;
                            }
                        }
                        else
                        {
                            // Parse shader
                            MenuDepthIllustration.MenuShader menuShader = MenuDepthIllustration.MenuShader.Normal;
                            if (shaderName != null)
                            {
                                try
                                {
                                    menuShader = Custom.ParseEnum <MenuDepthIllustration.MenuShader>(shaderName);
                                    shader     = null;
                                }
                                catch
                                {
                                    if (!self.menu.manager.rainWorld.Shaders.TryGetValue(shaderName, out shader))
                                    {
                                        shader = null;
                                    }
                                    menuShader = MenuDepthIllustration.MenuShader.Normal;
                                }
                            }

                            // Add an illustration with depth
                            illust = new MenuDepthIllustration(self.menu, self, self.sceneFolder, assetPath, pos, img.Depth, menuShader);

                            // Apply crisp pixels
                            if (crisp)
                            {
                                illust.sprite.element.atlas.texture.filterMode = FilterMode.Point;
                            }
                        }

                        // Add idle depths
                        if (self is InteractiveMenuScene ims)
                        {
                            ims.idleDepths = new List <float>();
                            List <object> depths = sceneOverride.GetProperty <List <object> >("idledepths");
                            if (depths != null)
                            {
                                for (int i = 0; i < depths.Count; i++)
                                {
                                    if (depths[i] is double depth)
                                    {
                                        ims.idleDepths.Add((float)depth);
                                    }
                                }
                            }
                        }

                        // Apply tags
                        if (shader != null)
                        {
                            illust.sprite.shader = shader;
                        }
                        illust.setAlpha = alpha;
                        self.AddIllustration(illust);

                        // Link back to the custom scene image
                        customRep[illust] = img;
                    }
                }
                finally { ClearSceneOverride(); }
            }
            else
            {
                orig(self);
            }
        }
Esempio n. 2
0
 public MarkImage(CustomScene owner, float depth) : base(owner)
 {
     Pos   = new Vector2(owner.GetProperty <float?>("markx") ?? 683f, owner.GetProperty <float?>("marky") ?? 484f);
     Depth = depth;
 }
Esempio n. 3
0
 public GlowImage(CustomScene owner, float depth) : base(owner)
 {
     Pos = new Vector2(owner.GetProperty <float?>("glowx") ?? 683f, owner.GetProperty <float?>("glowy") ?? 484f);
     Debug.Log($"Glow is at {Pos}");
     Depth = depth;
 }
Esempio n. 4
0
        // Override select scenes for SlugBase characters
        private static void SlugcatPage_AddImage(On.Menu.SlugcatSelectMenu.SlugcatPage.orig_AddImage orig, SlugcatSelectMenu.SlugcatPage self, bool ascended)
        {
            SlugBaseCharacter ply = PlayerManager.GetCustomPlayer(self.slugcatNumber);

            // Do not modify scenes for any non-SlugBase slugcats
            if (ply == null)
            {
                orig(self, ascended);
                return;
            }

            // Use Survivor's default scenes on the select menu
            string sceneName = ascended ? "SelectMenuAscended" : "SelectMenu";

            if (!ply.HasScene(sceneName))
            {
                orig(self, ascended);

                // Fix the scene position being off
                if (self.sceneOffset == default(Vector2))
                {
                    self.sceneOffset = new Vector2(-10f, 100f);
                }

                // Fix the wrong scene loading in when ascended
                if (ascended && self.slugcatImage.sceneID == MenuScene.SceneID.Slugcat_White)
                {
                    self.slugcatImage.RemoveSprites();
                    self.RemoveSubObject(self.slugcatImage);

                    self.slugcatImage = new InteractiveMenuScene(self.menu, self, MenuScene.SceneID.Ghost_White);
                    self.subObjects.Add(self.slugcatImage);
                }

                return;
            }

            // Make sure it doesn't crash if the mark or glow is missing
            self.markSquare = new FSprite("pixel")
            {
                isVisible = false
            };
            self.markGlow = new FSprite("pixel")
            {
                isVisible = false
            };
            self.glowSpriteA = new FSprite("pixel")
            {
                isVisible = false
            };
            self.glowSpriteB = new FSprite("pixel")
            {
                isVisible = false
            };


            // This function intentionally does not call the original
            // If this mod has claimed a slot, it seems best to not let other mods try to change this screen

            // Taken from SlugcatPage.AddImage
            self.imagePos    = new Vector2(683f, 484f);
            self.sceneOffset = new Vector2(0f, 0f);


            // Load a custom character's select screen from resources
            CustomScene scene = OverrideNextScene(ply, sceneName, img =>
            {
                if (img.HasTag("MARK") && !self.HasMark)
                {
                    return(false);
                }
                if (img.HasTag("GLOW") && !self.HasGlow)
                {
                    return(false);
                }
                return(true);
            });

            // Parse selectmenux and selectmenuy
            self.sceneOffset.x = scene.GetProperty <float?>("selectmenux") ?? 0f;
            self.sceneOffset.y = scene.GetProperty <float?>("selectmenuy") ?? 0f;
            Debug.Log($"Scene offset for {ply.Name}: {self.sceneOffset}");

            // Slugcat depth, used for positioning the glow and mark
            self.slugcatDepth = scene.GetProperty <float?>("slugcatdepth") ?? 3f;

            // Add mark
            MarkImage mark = new MarkImage(scene, self.slugcatDepth + 0.1f);

            scene.InsertImage(mark);

            // Add glow
            GlowImage glow = new GlowImage(scene, self.slugcatDepth + 0.1f);

            scene.InsertImage(glow);

            try
            {
                self.slugcatImage = new InteractiveMenuScene(self.menu, self, MenuScene.SceneID.Slugcat_White); // This scene will be immediately overwritten
            } finally { ClearSceneOverride(); }
            self.subObjects.Add(self.slugcatImage);

            // Find the relative mark and glow positions
            self.markOffset = mark.Pos - new Vector2(self.MidXpos, self.imagePos.y + 150f) + self.sceneOffset;
            self.glowOffset = glow.Pos - new Vector2(self.MidXpos, self.imagePos.y) + self.sceneOffset;
        }