Example #1
0
        public static void BuildCustomRegionScene(MenuScene self, string regionID, string sceneFolder)
        {
            if (self.flatMode)
            {
                self.AddIllustration(new MenuIllustration(self.menu, self, self.sceneFolder,
                                                          $"Landscape - {regionID} - Flat", new Vector2(683f, 384f), false, true));
            }
            else
            {
                Vector2 posVector = new Vector2(0, 0);

                string[] fileEntries = Directory.GetFiles(sceneFolder);
                Array.Sort(fileEntries);
                List <MenuDepthIllustration> illu = new List <MenuDepthIllustration>();
                foreach (string fileName in fileEntries)
                {
                    if (fileName.Contains(".png") && !fileName.ToLower().Contains("flat") && !fileName.ToLower().Contains("meta"))
                    {
                        string name = Path.GetFileNameWithoutExtension(fileName);
                        //CustomWorldMod.CustomWorldLog($"Custom Regions: Loading {name}");

                        /* int number = name[name.Length - 1];
                         * if (number < positions.Length)
                         * {
                         *   posVector.x = float.Parse(positions[number].Split(new string[] { ",", " " }, StringSplitOptions.RemoveEmptyEntries)[0]);
                         *   posVector.y = float.Parse(positions[number].Split(new string[] { ",", " " }, StringSplitOptions.RemoveEmptyEntries)[1]);
                         * }*/
                        //self.AddIllustration(new MenuDepthIllustration(self.menu, self, self.sceneFolder, $"{name}", posVector, 4 + number, MenuDepthIllustration.MenuShader.Normal));
                        CustomWorldMod.Log($"Custom Regions: Loading MenuDepthIllustration - Name [{name}] - Position[{posVector}]");
                        illu.Add(new MenuDepthIllustration(self.menu, self, self.sceneFolder, name, posVector, 1f, MenuDepthIllustration.MenuShader.Normal));
                    }
                }
                illu.Reverse();
                foreach (MenuDepthIllustration depthIllustration in illu)
                {
                    CustomWorldMod.Log($"Custom Regions: Adding MenuDepthIllustration - Name [{depthIllustration.fileName}]");
                    self.AddIllustration(depthIllustration);
                }

                // Load positions
                LoadScenePositionSettings(self, sceneFolder, regionID);
            }
            string packFolder = CustomWorldMod.installedPacks.First(x => x.Value.regions.Contains(regionID)).Value.folderName;

            /*
             * string path = CustomWorldMod.resourcePath + packName + Path.DirectorySeparatorChar;
             * string titleFolderName = path + "Assets" + Path.DirectorySeparatorChar + "Futile" + Path.DirectorySeparatorChar + "Resources" + Path.DirectorySeparatorChar + "Illustrations"+ Path.DirectorySeparatorChar;
             */
            string titleFolderName = CRExtras.BuildPath(packFolder, CRExtras.CustomFolder.Illustrations, includeRoot: false);

            if (Directory.Exists(titleFolderName))
            {
                if (self.menu.ID == ProcessManager.ProcessID.FastTravelScreen || self.menu.ID == ProcessManager.ProcessID.RegionsOverviewScreen)
                {
                    CustomWorldMod.Log($"Custom Regions: Adding Title - Name [{$"Title_{regionID}"}], path [{titleFolderName}]");
                    self.AddIllustration(new MenuIllustration(self.menu, self, titleFolderName, $"Title_{regionID}_Shadow", new Vector2(0.01f, 0.01f), true, false));
                    self.AddIllustration(new MenuIllustration(self.menu, self, titleFolderName, $"Title_{regionID}", new Vector2(0.01f, 0.01f), true, false));
                    self.flatIllustrations[self.flatIllustrations.Count - 1].sprite.shader = self.menu.manager.rainWorld.Shaders["MenuText"];
                }
            }

            else
            {
                CustomWorldMod.Log($"Error finding Title directory for [{regionID}] - at [{titleFolderName}]", true);
            }
        }
        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);
            }
        }