Пример #1
0
 protected override void WriteObject(AssetsWriter writer)
 {
     AnchorMin.Write(writer);
     AnchorMax.Write(writer);
     AnchoredPosition.Write(writer);
     SizeDelta.Write(writer);
     Pivot.Write(writer);
 }
 // Due to the lifecycle of the UIManager object, The `EditMenus` event has to be used to create custom menus.
 // This event is called every time a UIManager is created,
 // and will also call the added action if the UIManager has already started.
 internal void InitMenuCreation()
 {
     Patch.UIManager.BeforeHideDynamicMenu += ToggleMods;
     Patch.UIManager.EditMenus             += () =>
     {
         ModScreens = new Dictionary <IMod, MenuScreen>();
         var builder = new MenuBuilder("ModListMenu");
         this.screen = builder.Screen;
         builder.CreateTitle("Mods", MenuTitleStyle.vanillaStyle)
         .SetDefaultNavGraph(new ChainedNavGraph())
         .CreateContentPane(RectTransformData.FromSizeAndPos(
                                new RelVector2(new Vector2(1920f, 903f)),
                                new AnchoredPosition(
                                    new Vector2(0.5f, 0.5f),
                                    new Vector2(0.5f, 0.5f),
                                    new Vector2(0f, -60f)
                                    )
                                ))
         .CreateControlPane(RectTransformData.FromSizeAndPos(
                                new RelVector2(new Vector2(1920f, 259f)),
                                new AnchoredPosition(
                                    new Vector2(0.5f, 0.5f),
                                    new Vector2(0.5f, 0.5f),
                                    new Vector2(0f, -502f)
                                    )
                                ))
         .AddContent(
             new NullContentLayout(),
             c => c.AddScrollPaneContent(
                 new ScrollbarConfig
         {
             CancelAction = _ => this.ApplyChanges(),
             Navigation   = new Navigation {
                 mode = Navigation.Mode.Explicit
             },
             Position = new AnchoredPosition
             {
                 ChildAnchor  = new Vector2(0f, 1f),
                 ParentAnchor = new Vector2(1f, 1f),
                 Offset       = new Vector2(-310f, 0f)
             },
             SelectionPadding = _ => (-60, 0)
         },
                 new RelLength(0f),
                 RegularGridLayout.CreateVerticalLayout(105f),
                 c =>
         {
             foreach (var modInst in ModLoader.ModInstances)
             {
                 if (modInst.Error != null)
                 {
                     continue;
                 }
                 ModToggleDelegates?toggleDels = null;
                 if (modInst.Mod is ITogglableMod itmod)
                 {
                     try
                     {
                         if (
                             modInst.Mod is not(
                                 IMenuMod {
                             ToggleButtonInsideMenu: true
                         } or
                                 ICustomMenuMod {
                             ToggleButtonInsideMenu: true
                         }
                                 )
                             )
                         {
                             var rt       = c.ContentObject.GetComponent <RectTransform>();
                             rt.sizeDelta = new Vector2(0f, rt.sizeDelta.y + 105f);
                             c.AddHorizontalOption(
                                 modInst.Name,
                                 new HorizontalOptionConfig
                             {
                                 ApplySetting = (self, ind) =>
                                 {
                                     changedMods[modInst] = ind == 1;
                                 },
                                 CancelAction = _ => this.ApplyChanges(),
                                 Label        = modInst.Name,
                                 Options      = new string[] {
                                     Lang.Get("MOH_OFF", "MainMenu"),
                                     Lang.Get("MOH_ON", "MainMenu")
                                 },
                                 RefreshSetting = (self, apply) => self.optionList.SetOptionTo(
                                     modInst.Enabled ? 1 : 0
                                     ),
                                 Style       = HorizontalOptionStyle.VanillaStyle,
                                 Description = new DescriptionInfo
                                 {
                                     Text = $"v{modInst.Mod.GetVersion()}"
                                 }
                             },
                                 out var opt
                                 );
                             opt.menuSetting.RefreshValueFromGameSettings();
                         }
                         else
                         {
                             toggleDels = new ModToggleDelegates
                             {
                                 SetModEnabled = enabled =>
                                 {
                                     changedMods[modInst] = enabled;
                                 },
                                 GetModEnabled = () => modInst.Enabled,
                                             #pragma warning disable CS0618
                                 // Kept for backwards compatability.
                                 ApplyChange = () => {  }
                                             #pragma warning restore CS0618
                             };
                         }
                     }
                     catch (Exception e)
                     {
                         Logger.APILogger.LogError(e);
                     }
                 }