-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathExampleMod.cs
More file actions
81 lines (67 loc) · 2.38 KB
/
ExampleMod.cs
File metadata and controls
81 lines (67 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using MagicUI.Core;
using Modding;
using System.Collections.Generic;
namespace MagicUIExamples
{
public class MagicUIExamples : Mod, ITogglableMod, IMenuMod
{
internal static MagicUIExamples? Instance;
public override string GetVersion() => GetType().Assembly.GetName().Version.ToString();
public bool ToggleButtonInsideMenu => true;
private LayoutRoot? layout;
private bool debugBoundStatePersistent = false;
private void SetDebugBoundState(bool value)
{
debugBoundStatePersistent = value;
if (layout != null)
{
layout.RenderDebugLayoutBounds = value;
}
}
public override void Initialize()
{
Log("Initializing");
Instance = this;
On.HeroController.Awake += OnSaveOpened;
Log("Initialized");
}
private void OnSaveOpened(On.HeroController.orig_Awake orig, HeroController self)
{
if (layout == null)
{
layout = new(true, "Persistent layout");
layout.RenderDebugLayoutBounds = debugBoundStatePersistent;
// comment out examples as needed to see only the specific ones you want
SimpleLayoutExample.Setup(layout);
InteractivityAndDynamicSizingExample.Setup(layout);
ComplexLayoutExample.Setup(layout);
NonPersistentLayoutExample.Setup(layout);
//GridExample.Setup(layout);
}
orig(self);
}
public void Unload()
{
On.HeroController.Awake -= OnSaveOpened;
layout?.Destroy();
layout = null;
}
public List<IMenuMod.MenuEntry> GetMenuData(IMenuMod.MenuEntry? toggleButtonEntry)
{
List<IMenuMod.MenuEntry> items = new()
{
new IMenuMod.MenuEntry {
Name = "Show Debug Bounds",
Values = new string[] {"On", "Off"},
Saver = opt => SetDebugBoundState(opt == 0),
Loader = () => debugBoundStatePersistent ? 0 : 1
}
};
if (toggleButtonEntry != null)
{
items.Insert(0, (IMenuMod.MenuEntry)toggleButtonEntry);
}
return items;
}
}
}