示例#1
0
        public void SetupSGUI()
        {
            Logger.Debug("SetupSGUI()");

            GUIRoot = SGUIRoot.Setup();
            SGUIIMBackend.GetFont = (SGUIIMBackend backend) => {
                if (Patches.MainMenuFoyerController.Instance?.VersionLabel == null)
                {
                    return(null);
                }
                return(GungeonFont ?? (GungeonFont = FontConverter.DFFontToUnityFont((dfFont)Patches.MainMenuFoyerController.Instance.VersionLabel.Font, 2)));
            };
        }
示例#2
0
        public override void PreGameManagerAlive()
        {
            Logger.Info("Initializing SGUI");

            GUIRoot = SGUIRoot.Setup();
            SGUIIMBackend.GetFont = (SGUIIMBackend backend) => {
                System.Console.WriteLine($"GETFONT INSTANCE: {CorePatches.MainMenuFoyerController.Instance}");
                if (CorePatches.MainMenuFoyerController.Instance?.VersionLabel == null)
                {
                    return(null);
                }
                return(FontCache.GungeonFont ?? (FontCache.GungeonFont = FontConverter.DFFontToUnityFont((dfFont)CorePatches.MainMenuFoyerController.Instance.VersionLabel.Font, 2)));
            };

            _GameObject = new GameObject("GUI");
            DontDestroyOnLoad(_GameObject);

            Logger.Info("Initializing menu controller");
            MenuController = _GameObject.AddComponent <MenuController>();
            DontDestroyOnLoad(MenuController);

            Logger.Info("Initializing notification controller");
            NotificationController = _GameObject.AddComponent <NotificationController>();
            DontDestroyOnLoad(NotificationController);

            _Bullet = UnityUtil.LoadTexture2D(Path.Combine(Paths.ResourcesFolder, "bullet.png"));

            AppDomain.CurrentDomain.UnhandledException += (obj, e) => {
                NotificationController.Notify(new Notification(
                                                  title: "An unhandled error has occured",
                                                  content: "More information in the log."
                                                  )
                {
                    BackgroundColor = UnityUtil.NewColorRGB(57, 7, 7)
                });
            };

            ModTheGungeon.ModLoader.LuaError += (info, method, e) => {
                NotificationController.Notify(new Notification(
                                                  title: $"An error has occured while loading mod {info.Name}",
                                                  content: $"The '{method}' method had raised an error. More information in the log."
                                                  )
                {
                    BackgroundColor = UnityUtil.NewColorRGB(57, 7, 7)
                });
            };

            ModTheGungeon.ErrorLoadingMod += (filename, e) => {
                NotificationController.Notify(new Notification(
                                                  title: $"An error has occured while loading '{filename}'",
                                                  content: "More information in the log."
                                                  )
                {
                    BackgroundColor = UnityUtil.NewColorRGB(57, 7, 7)
                });
            };

            ModTheGungeon.ErrorCreatingModsDirectory += (e) => {
                NotificationController.Notify(new Notification(
                                                  title: $"An error has occured while trying to create the Mods directory",
                                                  content: "More information in the log."
                                                  )
                {
                    BackgroundColor = UnityUtil.NewColorRGB(57, 7, 7)
                });
            };

            ModTheGungeon.ModsReloaded += (manual) => {
                if (manual)
                {
                    NotificationController.Notify(new Notification(
                                                      title: $"Reloaded!",
                                                      content: "All mods have been reloaded as a result of pressing the F5 key."
                                                      ));
                }
                else
                {
                    NotificationController.Notify(new Notification(
                                                      title: $"Reloaded!",
                                                      content: "All mods have been reloaded automatically as a result of at least one of them being modified."
                                                      ));
                }
            };
        }
示例#3
0
        public static void Init()
        {
            if (Root != null)
            {
                return;
            }

            Root = SGUIRoot.Setup();
            GameObject.Find("SGUI Root").tag = "DoNotPause";

            ModEvents.OnUpdate += Update;
            SceneManager.activeSceneChanged += (sceneA, sceneB) => {
                ShowGameGUI();
            };

            Root.Background = new Color(
                0.17f,
                0.21f,
                0.23f,
                Root.Background.a
                );

            MainGroup = new SGroup()
            {
                Visible = false,

                OnUpdateStyle = elem => {
                    elem.Fill(0);
                },

                Children =
                {
                    new SLabel($"Yooka-Laylee Mod {ModAPI.UIVersion}")
                    {
                        Background = HeaderBackground,
                        Foreground = HeaderForeground
                    },

                    new SLabel("Help:")
                    {
                        OnUpdateStyle = elem =>          {
                            elem.Position = new Vector2(elem.Previous.Position.x, elem.Previous.Position.y + elem.Previous.Size.y + Padding);
                        }
                    },

                    (HelpGroup = new SGroup              {
                        ScrollDirection = SGroup.EDirection.Vertical,
                        AutoLayout = elem => elem.AutoLayoutVertical,
                        AutoLayoutPadding = PaddingColumnElements,
                        OnUpdateStyle = elem =>          {
                            elem.Position = new Vector2(elem.Previous.Position.x, elem.Previous.Position.y + elem.Previous.Size.y + Padding);
                            elem.Size = new Vector2(512, elem.Parent.Size.y - elem.Position.y - Padding);
                        },
                        With =                           { new SGroupForceScrollModifier()            },
                        Children =
                        {
                            new SGroup()
                            {
                                Background = new Color(0f, 0f, 0f, 0f),
                                AutoLayout = elem => elem.AutoLayoutVertical,
                                AutoLayoutVerticalStretch = false,
                                AutoLayoutPadding = 0f,
                                OnUpdateStyle = SegmentGroupUpdateStyle,
                                Children =
                                {
                                    new SLabel("Debug Log:")
                                    {
                                        Background = HeaderBackground,
                                        Foreground = HeaderForeground
                                    },
                                    new SLabel("Keyboard:")
                                    {
                                        Background = HeaderBackground,
                                        Foreground = HeaderForeground
                                    },
                                    new SLabel("HOME / POS1: Toggle log"),
                                    new SLabel("PAGE UP / DOWN: Scroll")
                                }
                            },

                            new SGroup()
                            {
                                Background = new Color(0f, 0f, 0f, 0f),
                                AutoLayout = elem => elem.AutoLayoutVertical,
                                AutoLayoutVerticalStretch = false,
                                AutoLayoutPadding = 0f,
                                OnUpdateStyle = SegmentGroupUpdateStyle,
                                Children =
                                {
                                    new SLabel("Miscellaneous:")
                                    {
                                        Background = HeaderBackground,
                                        Foreground = HeaderForeground
                                    },
                                    new SLabel("Keyboard:")
                                    {
                                        Background = HeaderBackground,
                                        Foreground = HeaderForeground
                                    },
                                    new SLabel("F11: Toggle game GUI"),
                                }
                            }
                        }
                    }),

                    new SLabel("Settings:")
                    {
                        OnUpdateStyle = elem =>          {
                            elem.Position = new Vector2(elem.Previous.Previous.Position.x + elem.Previous.Size.x + Padding, elem.Previous.Previous.Position.y);
                        }
                    },

                    (SettingsGroup = new SGroup          {
                        ScrollDirection = SGroup.EDirection.Vertical,
                        AutoLayout = elem => elem.AutoLayoutVertical,
                        AutoLayoutPadding = PaddingColumnElements,
                        OnUpdateStyle = elem =>          {
                            elem.Position = new Vector2(elem.Previous.Position.x, elem.Previous.Position.y + elem.Previous.Size.y + Padding);
                            elem.Size = new Vector2(256, elem.Parent.Size.y - elem.Position.y - Padding);
                        },
                        With =                           { new SGroupForceScrollModifier()            },
                        Children =
                        {
                            new SGroup()
                            {
                                Background = new Color(0f, 0f, 0f, 0f),
                                AutoLayout = elem => elem.AutoLayoutVertical,
                                OnUpdateStyle = SegmentGroupUpdateStyle,
                                Children =
                                {
                                    new SLabel("YLMAPI-DEV TOOLS:")
                                    {
                                        Background = HeaderBackground,
                                        Foreground = HeaderForeground
                                    },

                                    new SButton("Clear loaded content mod cache")
                                    {
                                        Alignment = TextAnchor.MiddleLeft,
                                        OnClick = b =>   {
                                            ModContent.Cache.Clear();
                                        }
                                    },

                                    new SButton("Recreate content mod tree")
                                    {
                                        Alignment = TextAnchor.MiddleLeft,
                                        OnClick = b =>   {
                                            ModContent.Recrawl();
                                        }
                                    },

                                    new SButton("Patch content in scene")
                                    {
                                        Alignment = TextAnchor.MiddleLeft,
                                        OnClick = b =>   {
                                            ModContentPatcher.PatchContent(SceneManager.GetActiveScene()).StartGlobal();
                                        }
                                    },

                                    new SButton("Dump content in scene")
                                    {
                                        Alignment = TextAnchor.MiddleLeft,
                                        OnClick = b =>   {
                                            ModContentDumper.DumpContent(SceneManager.GetActiveScene()).StartGlobal();
                                        }
                                    }
                                }
                            },

                            new SGroup()
                            {
                                Background = new Color(0f, 0f, 0f, 0f),
                                AutoLayout = elem => elem.AutoLayoutVertical,
                                OnUpdateStyle = SegmentGroupUpdateStyle,
                                Children =
                                {
                                    new SLabel("General:")
                                    {
                                        Background = HeaderBackground,
                                        Foreground = HeaderForeground
                                    },

                                    new SButton("Show Game GUI")
                                    {
                                        Alignment = TextAnchor.MiddleLeft,
                                        With =           { new SCheckboxModifier()
                                                           {
                                                               GetValue = b => IsGameHUDVisible,
                                                               SetValue = (b, v) => {
                                                                   if (v)
                                                                   {
                                                                       ShowGameGUI();
                                                                   }
                                                                   else
                                                                   {
                                                                       HideGameGUI();
                                                                   }
                                                               }
                                                           } }
                                    },

                                    new SButton("Show Mod Log")
                                    {
                                        Alignment = TextAnchor.MiddleLeft,
                                        With =           { new SCheckboxModifier()
                                                           {
                                                               GetValue = b => LogGroup?.Visible ?? false,
                                                               SetValue = (b, v) => LogGroup.Visible = v
                                                           } }
                                    },

                                    new SButton("Fullscreen Log")
                                    {
                                        Alignment = TextAnchor.MiddleLeft,
                                        With =           { new SCheckboxModifier()
                                                           {
                                                               GetValue = b => IsLogBig,
                                                               SetValue = (b, v) => { IsLogBig = v; LogGroup?.UpdateStyle(); }
                                                           } }
                                    }
                                }
                            }
                        }
                    }),

                    new SLabel("Scenes:")
                    {
                        OnUpdateStyle = elem =>          {
                            elem.Position = new Vector2(elem.Previous.Previous.Position.x + elem.Previous.Size.x + Padding, elem.Previous.Previous.Position.y);
                        }
                    },

                    (ScenesGroup = new SGroup            {
                        ScrollDirection = SGroup.EDirection.Vertical,
                        AutoLayout = elem => elem.AutoLayoutVertical,
                        AutoLayoutPadding = Padding,
                        OnUpdateStyle = elem =>          {
                            elem.Position = new Vector2(elem.Previous.Position.x, elem.Previous.Position.y + elem.Previous.Size.y + Padding);
                            elem.Size = new Vector2(256, elem.Parent.Size.y - elem.Position.y - Padding);
                        },
                        With =                           { new SGroupForceScrollModifier()            }
                    }),
                }
            };

            LogGroup = new SGroup()
            {
                Visible           = false,
                ScrollDirection   = SGroup.EDirection.Vertical,
                AutoLayout        = elem => elem.AutoLayoutVertical,
                AutoLayoutPadding = 0f,

                OnUpdateStyle = elem => {
                    if (IsLogBig)
                    {
                        elem.Fill(0);
                    }
                    else
                    {
                        elem.Size     = new Vector2(512, 512);
                        elem.Position = elem.Root.Size - elem.Size;
                    }
                },

                Children =
                {
                    new SLabel($"Yooka-Laylee {File.ReadAllText(Path.Combine(Application.streamingAssetsPath, "subversion.txt")).Trim()}"),
                    new SLabel($"Yooka-Laylee Mod {ModAPI.UIVersion}"),
                    new SLabel("DEBUG LOG"),
                    new SLabel("Use HOME / POS 1 key on keyboard to hide / show."),
                    new SLabel("Use F2 to switch between cornered and full log."),
                    new SLabel("Use PAGE UP / DOWN to scroll."),
                    new SLabel(),
                    new SLabel("For all keybindings, hit F1."),
                    new SLabel()
                }
            };

            _ListScenes().StartGlobal();
        }