/// <summary> /// Add Header, blue title bar that can be used to separate settings. /// </summary> /// <param name="mod">Your mod instance</param> /// <param name="HeaderTitle">Title of your header</param> /// <param name="backgroundColor">Background color of header</param> /// <param name="textColor">Text Color of header</param> public static void AddHeader(Mod mod, string HeaderTitle, Color backgroundColor, Color textColor) { Keybind kb = new Keybind(null, HeaderTitle, KeyCode.None, KeyCode.None); kb.Mod = mod; kb.Vals = new object[3]; kb.Vals[0] = HeaderTitle; kb.Vals[1] = backgroundColor; kb.Vals[2] = textColor; Keybinds.Add(kb); }
public override void OnMenuLoad() { Keybind.Add(this, consoleKey); CreateConsoleUI(); console.controller = new ConsoleController(); ConsoleCommand.cc = console.controller; console.setVisibility(false); console.viewContainer.transform.GetChild(4).gameObject.GetComponent <ConsoleUIResizer>().LoadConsoleSize(); ConsoleCommand.Add(new CommandVersion()); ConsoleCommand.Add(new CommandLogAll()); }
public override void OnLoad() { Keybind.Add(this, consoleKey); //Keybind.Add(this, consoleSizeKey); CreateConsoleUI(); console.console = new ConsoleController(); ConsoleCommand.cc = console.console; console.setVisibility(false); UI.GetComponent <ConsoleView>().viewContainer.transform.GetChild(4).gameObject.GetComponent <ConsoleUIResizer>().LoadConsoleSize(); ConsoleCommand.Add(new CommandClear()); ConsoleCommand.Add(new CommandHelp()); ConsoleCommand.Add(new CommandLogAll()); }
// Load the keybinds. public override void OnLoad() { try { GameObject go = new GameObject(); ModSettingsUI ui = go.AddComponent <ModSettingsUI>(); ui.ms = this; ui.LoadUI(); } catch (Exception e) { ModConsole.Print(e.Message); //debug only } Keybind.Add(this, menuKey); LoadBinds(); }
void UpdateKeyCode(KeyCode kcode, bool modifier) { Keybind bind = Keybind.Keybinds.Find(x => x.Mod == mod && x.ID == id); if (modifier) { bind.Modifier = kcode; modifierDisplay.text = kcode.ToString(); } else { bind.Key = kcode; keyDisplay.text = kcode.ToString(); } ModSettings.SaveModBinds(mod); }
public void KeyBindsList(Keybind key) { GameObject keyBind = Instantiate(ms.KeyBind); keyBind.transform.GetChild(0).GetComponent <Text>().text = key.Name; keyBind.AddComponent <KeyBinding>().modifierButton = keyBind.transform.GetChild(1).gameObject; keyBind.GetComponent <KeyBinding>().modifierDisplay = keyBind.transform.GetChild(1).GetChild(0).GetComponent <Text>(); keyBind.GetComponent <KeyBinding>().keyButton = keyBind.transform.GetChild(3).gameObject; keyBind.GetComponent <KeyBinding>().keyDisplay = keyBind.transform.GetChild(3).GetChild(0).GetComponent <Text>(); keyBind.GetComponent <KeyBinding>().key = key.Key; keyBind.GetComponent <KeyBinding>().modifierKey = key.Modifier; keyBind.GetComponent <KeyBinding>().mod = key.Mod; keyBind.GetComponent <KeyBinding>().id = key.ID; keyBind.GetComponent <KeyBinding>().LoadBind(); keyBind.transform.SetParent(keybindsList.transform, false); }
// Load all keybinds. public static void LoadBinds() { Mod[] binds = ModLoader.LoadedMods.Where(mod => Keybind.Get(mod).Count > 0).ToArray(); for (int i = 0; i < binds.Length; i++) { // delete old xml file (if exists) string path = Path.Combine(ModLoader.GetModSettingsFolder(binds[i]), "keybinds.xml"); if (File.Exists(path)) { File.Delete(path); } // Check if there is custom keybinds file (if not, create) path = Path.Combine(ModLoader.GetModSettingsFolder(binds[i]), "keybinds.json"); if (!File.Exists(path)) { SaveModBinds(binds[i]); continue; } // Load and deserialize KeybindList keybinds = JsonConvert.DeserializeObject <KeybindList>(File.ReadAllText(path)); if (keybinds.keybinds.Count == 0) { continue; } for (int k = 0; k < keybinds.keybinds.Count; k++) { Keybind bind = Keybind.Keybinds.Find( x => x.Mod == binds[i] && x.ID == keybinds.keybinds[k].ID); if (bind == null) { continue; } bind.Key = keybinds.keybinds[k].Key; bind.Modifier = keybinds.keybinds[k].Modifier; } } }
// Reset keybinds public static void ResetBinds(Mod mod) { if (mod != null) { // Revert binds foreach (Keybind bind in Keybind.Get(mod)) { Keybind original = Keybind.GetDefault(mod).Find(x => x.ID == bind.ID); if (original != null) { bind.Key = original.Key; bind.Modifier = original.Modifier; } } // Save binds SaveModBinds(mod); } }
// Save keybind for a single mod to config file. public static void SaveModBinds(Mod mod) { KeybindList list = new KeybindList(); string path = Path.Combine(ModLoader.GetModSettingsFolder(mod), "keybinds.json"); foreach (Keybind bind in Keybind.Get(mod)) { Keybinds keybinds = new Keybinds { ID = bind.ID, Key = bind.Key, Modifier = bind.Modifier }; list.keybinds.Add(keybinds); } string serializedData = JsonConvert.SerializeObject(list, Formatting.Indented); File.WriteAllText(path, serializedData); }
// Reset keybinds public static void ResetBinds(Mod mod) { if (mod != null) { // Revert binds Keybind[] bind = Keybind.Get(mod).ToArray(); for (int i = 0; i < bind.Length; i++) { Keybind original = Keybind.GetDefault(mod).Find(x => x.ID == bind[i].ID); if (original != null) { bind[i].Key = original.Key; bind[i].Modifier = original.Modifier; } } // Save binds SaveModBinds(mod); } }
// Load all keybinds. public static void LoadBinds() { foreach (Mod mod in ModLoader.LoadedMods) { //delete old xml file (if exists) string path = Path.Combine(ModLoader.GetModSettingsFolder(mod), "keybinds.xml"); if (File.Exists(path)) { File.Delete(path); } // Check if there is custom keybinds file (if not, create) path = Path.Combine(ModLoader.GetModSettingsFolder(mod), "keybinds.json"); if (!File.Exists(path)) { SaveModBinds(mod); continue; } //Load and deserialize KeybindList keybinds = new KeybindList(); string serializedData = File.ReadAllText(path); keybinds = JsonConvert.DeserializeObject <KeybindList>(serializedData); if (keybinds.keybinds.Count == 0) { continue; } foreach (var kb in keybinds.keybinds) { Keybind bind = Keybind.Keybinds.Find(x => x.Mod == mod && x.ID == kb.ID); if (bind == null) { continue; } bind.Key = kb.Key; bind.Modifier = kb.Modifier; } } }
public override void ModSettings() { instance = this; Keybind.Add(this, menuKey); Settings.AddHeader(this, "Basic Settings", new Color32(0, 128, 0, 255)); //Settings.AddText(this, "All basic settings for MSCLoader"); //Settings.AddCheckBox(this, expWarning); //Settings.AddCheckBox(this, modPath); //Settings.AddCheckBox(this, modSetButton); Settings.AddCheckBox(this, forceMenuVsync); Settings.AddHeader(this, "Mod Update Check", new Color32(0, 128, 0, 255)); Settings.AddButton(this, updateButton, "Check for mod updates."); //Settings.AddHeader(this, "Experimental Scaling", new Color32(101, 34, 18, 255), new Color32(254, 254, 0, 255)); //Settings.AddText(this, "This option enables <color=orange>experimental UI scaling</color> for <color=orange>ultra-widescreen monitor setup</color>. Turn on this checkbox first, then run game in ultra-widescreen resolution. You can then tune scaling using slider below, but default value (1) should be ok."); //Settings.AddCheckBox(this, expUIScaling); //Settings.AddSlider(this, tuneScaling, 0f, 1f); LoadSettings(); }
public override void ModSettings() { instance = this; Keybind.Add(this, menuKey); if (ModLoader.devMode) { Settings.AddHeader(this, "DevMode Settings", new Color32(101, 34, 18, 255), new Color32(254, 254, 0, 255)); Settings.AddCheckBox(this, dm_disabler); Settings.AddCheckBox(this, dm_logST); Settings.AddCheckBox(this, dm_operr); Settings.AddCheckBox(this, dm_warn); Settings.AddCheckBox(this, dm_pcon); } Settings.AddHeader(this, "Basic Settings", new Color32(0, 128, 0, 255)); Settings.AddText(this, "All basic settings for MSCLoader"); Settings.AddCheckBox(this, expWarning); Settings.AddCheckBox(this, modPath); Settings.AddCheckBox(this, modSetButton); Settings.AddCheckBox(this, forceMenuVsync); Settings.AddCheckBox(this, openLinksOverlay); Settings.AddCheckBox(this, showCoreModsDf); Settings.AddCheckBox(this, skipGameIntro); Settings.AddText(this, $"If for whatever reason you want to save half a second of mods loading time, enable below option.{Environment.NewLine}(Loading progress <b>cannot</b> be displayed in synchronous mode)"); Settings.AddCheckBox(this, syncLoad); Settings.AddHeader(this, "Mod Update Check", new Color32(0, 128, 0, 255)); Settings.AddText(this, "Check for mod updates:"); Settings.AddCheckBox(this, checkLaunch, "cfmu_set"); Settings.AddCheckBox(this, checkDaily, "cfmu_set"); Settings.AddCheckBox(this, checkWeekly, "cfmu_set"); Settings.AddHeader(this, "Experimental Scaling", new Color32(101, 34, 18, 255), new Color32(254, 254, 0, 255)); Settings.AddText(this, "This option enables <color=orange>experimental UI scaling</color> for <color=orange>ultra-widescreen monitor setup</color>. Turn on this checkbox first, then run game in ultra-widescreen resolution. You can then tune scaling using slider below, but default value (1) should be ok."); Settings.AddCheckBox(this, expUIScaling); Settings.AddSlider(this, tuneScaling, 0f, 1f); }
// Reset keybinds public void ResetBinds(Mod mod) { if (mod != null) { // Delete file string path = Path.Combine(ModLoader.GetModSettingsFolder(mod), "keybinds.json"); // Revert binds foreach (Keybind bind in Keybind.Get(mod)) { Keybind original = Keybind.DefaultKeybinds.Find(x => x.Mod == mod && x.ID == bind.ID); if (original != null) { ModConsole.Print(original.Key.ToString() + " -> " + bind.Key.ToString()); bind.Key = original.Key; bind.Modifier = original.Modifier; } } // Save binds SaveModBinds(mod); } }
// Manage windows private void windowManager(int id) { if (id == 0) { if (menuState == 0) { // Main menu scrollPos = GUILayout.BeginScrollView(scrollPos); GUILayout.Label("Loaded mods"); GUILayout.Space(20); foreach (Mod mod in ModLoader.LoadedMods) { if (GUILayout.Button(mod.Name, GUILayout.Height(30))) { menuState = 1; selectedMod = mod; } } GUILayout.EndScrollView(); GUILayout.Space(20); if (GUILayout.Button("Close", GUILayout.Height(30))) { menuOpen = false; } } else if (menuState == 1) { // Mod info scrollPos = GUILayout.BeginScrollView(scrollPos); GUILayout.Space(20); if (selectedMod != null) { GUILayout.Label("ID: " + selectedMod.ID); GUILayout.Label("Name: " + selectedMod.Name); GUILayout.Label("Version: " + selectedMod.Version); GUILayout.Label("Author: " + selectedMod.Author); GUILayout.Space(20); if (GUILayout.Button("Keybinds", GUILayout.Height(30))) { menuState = 2; scrollPos = Vector2.zero; } } else { GUILayout.Label("Invalid mod"); } GUILayout.EndScrollView(); GUILayout.Space(20); if (GUILayout.Button("Back", GUILayout.Height(30))) { menuState = 0; selectedMod = null; scrollPos = Vector2.zero; } } else if (menuState == 2) { // Edit keybinds GUILayout.Label("Keybinds"); GUILayout.Space(20); scrollPos = GUILayout.BeginScrollView(scrollPos); if (selectedMod != null) { bool none = true; foreach (Keybind key in Keybind.Keybinds) { if (key.Mod == selectedMod) { GUILayout.Label(key.Name); string modStr = key.Modifier.ToString(); string keyStr = key.Key.ToString(); if (awaitingInput) { if (awaitingKeyID == 0) { modStr = "Press any key"; } else if (awaitingKeyID == 1) { keyStr = "Press any key"; } } if (GUILayout.Button("Modifier - " + modStr, GUILayout.Height(30))) { if (!awaitingInput) { awaitingInput = true; awaitingKeyID = 0; awaitingKey = key; } } if (GUILayout.Button("Key - " + keyStr, GUILayout.Height(30))) { if (!awaitingInput) { awaitingInput = true; awaitingKeyID = 1; awaitingKey = key; } } GUILayout.Space(10); none = false; } } if (none) { GUILayout.Label("This mod has no keybinds"); } } else { GUILayout.Label("Invalid mod"); } GUILayout.EndScrollView(); GUILayout.Space(20); if (GUILayout.Button("Reset", GUILayout.Height(30))) { resetBinds(); } if (GUILayout.Button("Back", GUILayout.Height(30))) { menuState = 1; scrollPos = Vector2.zero; } } } }
/// <summary> /// Open menu if the key is pressed. /// </summary> public override void Update() { // Open menu if (menuKey.IsDown()) { Toggle(); } // Rebinds if (awaitingInput) { // Cancel rebind if (Input.GetKeyDown(KeyCode.Escape)) { if (awaitingKeyID == 0) { awaitingKey.Modifier = KeyCode.None; } else if (awaitingKeyID == 1) { awaitingKey.Key = KeyCode.None; } awaitingInput = false; awaitingKeyID = -1; awaitingKey = null; } if (Input.anyKeyDown) { if (awaitingKeyID == 0) { if (Event.current.keyCode != KeyCode.None) { awaitingKey.Modifier = Event.current.keyCode; } else { if (Event.current.shift) { awaitingKey.Modifier = KeyCode.LeftShift; } } } else if (awaitingKeyID == 1) { string input = Input.inputString.ToUpper(); KeyCode code = KeyCode.None; try { code = (KeyCode)Enum.Parse(typeof(KeyCode), input); } catch (Exception e) { if (input == "`") { code = KeyCode.BackQuote; } else { ModConsole.Error("Invalid key"); } } awaitingKey.Key = code; } awaitingInput = false; awaitingKey = null; awaitingKeyID = -1; } } }
/// <summary> /// Load the keybinds. /// </summary> public override void OnLoad() { Keybind.Add(this, menuKey); }
/// <summary> /// Load all keybinds. /// </summary> public static void LoadBinds() { foreach (Mod mod in ModLoader.LoadedMods) { // Check if there are custom keybinds string path = Path.Combine(ModLoader.ConfigFolder, mod.ID + "\\keybinds.xml"); if (!File.Exists(path)) { SaveModBinds(mod); continue; } // Load XML XmlDocument doc = new XmlDocument(); doc.Load(path); foreach (XmlNode keybind in doc.GetElementsByTagName("Keybind")) { XmlNode id = keybind.SelectSingleNode("ID"); XmlNode key = keybind.SelectSingleNode("Key"); XmlNode modifier = keybind.SelectSingleNode("Modifier"); // Check if its valid and fetch if (id == null || key == null || modifier == null) { continue; } Keybind bind = Keybind.Keybinds.Find(x => x.Mod == mod && x.ID == id.InnerText); if (bind == null) { continue; } // Set bind try { KeyCode code = (KeyCode)Enum.Parse(typeof(KeyCode), key.InnerText); bind.Key = code; } catch (Exception e) { bind.Key = KeyCode.None; ModConsole.Error(e.Message); } try { KeyCode code = (KeyCode)Enum.Parse(typeof(KeyCode), modifier.InnerText); bind.Modifier = code; } catch (Exception e) { bind.Modifier = KeyCode.None; ModConsole.Error(e.Message); } } } }
public override void OnMenuLoad() { CreateSettingsUI(); Keybind.Add(this, menuKey); }
public void ModButton(string name, string version, string author, Mod mod) { GameObject modButton = Instantiate(ms.ModButton); if (mod.ID.StartsWith("MSCLoader_")) { modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().color = Color.cyan; modButton.transform.GetChild(1).GetChild(3).GetComponent <Text>().text = "<color=cyan>Core Module!</color>"; modButton.transform.GetChild(1) .GetChild(4) .GetChild(0) .GetComponent <Button>() .interactable = false; } else if (mod.isDisabled) { modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().color = Color.red; modButton.transform.GetChild(1).GetChild(3).GetComponent <Text>().text = "<color=red>Mod is disabled!</color>"; modButton.transform.GetChild(2).GetChild(1).gameObject.SetActive( true); // Add plugin Disabled icon modButton.transform.GetChild(2).GetChild(1).GetComponent <Image>().color = Color.red; } else if (!mod.LoadInMenu && ModLoader.GetCurrentScene() == CurrentScene.MainMenu) { modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().color = Color.yellow; modButton.transform.GetChild(1).GetChild(3).GetComponent <Text>().text = "<color=yellow>Ready to load</color>"; } else { modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().color = Color.green; } modButton.transform.GetChild(1) .GetChild(4) .GetChild(0) .GetComponent <Button>() .onClick.AddListener(() => ms.settings.ModDetailsShow(mod)); if (Settings.Get(mod).Count > 0) { modButton.transform.GetChild(1) .GetChild(4) .GetChild(1) .GetComponent <Button>() .interactable = true; modButton.transform.GetChild(1) .GetChild(4) .GetChild(1) .GetComponent <Button>() .onClick.AddListener(() => ms.settings.ModSettingsShow(mod)); } if (Keybind.Get(mod).Count > 0) { modButton.transform.GetChild(1) .GetChild(4) .GetChild(2) .GetComponent <Button>() .interactable = true; modButton.transform.GetChild(1) .GetChild(4) .GetChild(2) .GetComponent <Button>() .onClick.AddListener(() => ms.settings.ModKeybindsShow(mod)); } if (name.Length > 24) { modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().text = string.Format("{0}...", name.Substring(0, 22)); } else { modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().text = name; } modButton.transform.GetChild(1).GetChild(1).GetComponent <Text>().text = string.Format("by <color=orange>{0}</color>", author); modButton.transform.GetChild(1).GetChild(2).GetComponent <Text>().text = version; modButton.transform.SetParent(modView.transform, false); if (mod.metadata != null && mod.metadata.icon.iconFileName != null && mod.metadata.icon.iconFileName != string.Empty) { if (mod.metadata.icon.isIconRemote) { if (File.Exists(Path.Combine(ModLoader.ManifestsFolder, @"Mod Icons\" + mod.metadata.icon.iconFileName))) { try { Texture2D t2d = new Texture2D(1, 1); t2d.LoadImage(File.ReadAllBytes(Path.Combine(ModLoader.ManifestsFolder, @"Mod Icons\" + mod.metadata.icon.iconFileName))); modButton.transform.GetChild(0) .GetChild(0) .GetComponent <RawImage>() .texture = t2d; } catch (Exception e) { ModConsole.Error(e.Message); System.Console.WriteLine(e); } } } else if (mod.metadata.icon.isIconUrl) { try { WWW www = new WWW(mod.metadata.icon.iconFileName); modButton.transform.GetChild(0) .GetChild(0) .GetComponent <RawImage>() .texture = www.texture; } catch (Exception e) { ModConsole.Error(e.Message); System.Console.WriteLine(e); } } else { if (File.Exists(Path.Combine(ModLoader.GetModAssetsFolder(mod), mod.metadata.icon.iconFileName))) { try { Texture2D t2d = new Texture2D(1, 1); t2d.LoadImage( File.ReadAllBytes(Path.Combine(ModLoader.GetModAssetsFolder(mod), mod.metadata.icon.iconFileName))); modButton.transform.GetChild(0) .GetChild(0) .GetComponent <RawImage>() .texture = t2d; } catch (Exception e) { ModConsole.Error(e.Message); System.Console.WriteLine(e); } } } } if (mod.hasUpdate) { modButton.transform.GetChild(1).GetChild(3).GetComponent <Text>().text = "<color=lime>UPDATE AVAILABLE!</color>"; } if (mod.UseAssetsFolder) { modButton.transform.GetChild(2).GetChild(2).gameObject.SetActive( true); // Add assets icon } if (!mod.isDisabled) { modButton.transform.GetChild(2).GetChild(1).gameObject.SetActive( true); // Add plugin OK icon } if (mod.LoadInMenu) { modButton.transform.GetChild(2).GetChild(0).gameObject.SetActive( true); // Add Menu Icon } }