-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cs
80 lines (69 loc) · 2.05 KB
/
Main.cs
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
using System.IO;
using System.Linq;
using Il2CppAssets.Scripts.Database;
using MelonLoader;
using Tomlet;
using UnityEngine;
using UnityEngine.UI;
using static QuickSwitchCombination.Save;
namespace QuickSwitchCombination;
internal class Main : MelonMod
{
private static GameObject GameObject { get; set; }
internal static int ClickIndex { get; set; } = 0;
internal static bool SetKey { get; set; }
public override void OnInitializeMelon()
{
Load();
LoggerInstance.Msg("QuickSwitchCombination is loaded!");
}
public override void OnDeinitializeMelon()
{
File.WriteAllText(Path.Combine("UserData", "QuickSwitchCombination.cfg"), TomletMain.TomlStringFrom(Settings));
}
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
if (sceneName == "UISystem_PC")
{
GameObject = new GameObject("QuickSwitchCombination");
Object.DontDestroyOnLoad(GameObject);
GameObject.AddComponent<Menu>();
}
else
{
Object.Destroy(GameObject);
}
}
public override void OnGUI()
{
if (!Input.anyKeyDown)
{
return;
}
var e = Event.current;
if (!e.isKey || e.keyCode == KeyCode.None)
{
return;
}
if (e.keyCode == Settings.MenuKey)
{
Menu.ShowMenu = !Menu.ShowMenu;
return;
}
if (SetKey)
{
Settings.Data[ClickIndex].Key = e.keyCode;
ConstantVariables.ContentTransform.GetChild(ClickIndex).GetChild(2).GetChild(0).gameObject.GetComponent<Text>().text =
Settings.Data[ClickIndex].Key.ToString();
SetKey = false;
return;
}
var combination = Settings.Data.FirstOrDefault(x => x.Key == e.keyCode);
if (combination is null)
{
return;
}
DataHelper.selectedRoleIndex = combination.Character;
DataHelper.selectedElfinIndex = combination.Elfin;
}
}