Пример #1
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();
        }