private void ResetToDefaults() { extraSounds = true; sprayParticles = true; spraySoundVolume = 0.8f; selectColorZigZag = false; hidePaletteWithHUD = true; paletteScreenPos = paletteScreenPosDefault; paletteScale = paletteScaleDefault; paletteBackgroundOpacity = -1; aimInfoScreenPos = aimInfoScreenPosDefault; aimInfoScale = aimInfoScaleDefault; aimInfoBackgroundOpacity = -1; requireCtrlForColorCycle = false; hideSkinsFromPalette.Clear(); colorPickMode1 = default_colorPickMode1; colorPickMode2 = default_colorPickMode2; instantColorPick1 = default_instantColorPick1; instantColorPick2 = default_instantColorPick2; replaceColorMode1 = default_replaceColorMode1; replaceColorMode2 = default_replaceColorMode2; }
protected override void UpdateTitle() { string titleColored = (Item.Interactable ? Title : "<color=gray>" + Title); ControlCombination value = Getter(); string valStr = "(none)"; if (value != null && value.combination.Count > 0) { valStr = value.combinationString; } string valueColored = (Item.Interactable ? Utils.ColorTag(ValueColor, valStr) : valStr); string defaultColored = ""; string comboValue = value?.combinationString ?? ""; string comboDefault = DefaultValue?.combinationString ?? ""; if (comboDefault == comboValue) { defaultColored = (Item.Interactable ? Utils.ColorTag(Color.Gray, "[default]") : "[default]"); } Item.Text = $"{titleColored}: {valueColored} {defaultColored}"; }
public ItemInput(MenuCategoryBase category, string title, Func <ControlCombination> getter, Action <ControlCombination> setter, ControlCombination defaultValue) : base(category) { Title = title; Getter = getter; Setter = setter; DefaultValue = defaultValue; Item = new MenuKeybindInput(string.Empty, category, "Press a key to bind.\nCan be combined with alt/ctrl/shift.\nUnbind by confirming without a key.", OnSubmit); UpdateTitle(); }
protected override void RegisterComponent() { // assign defaults default_colorPickMode1 = ControlCombination.CreateFrom("shift c.landinggear", true); default_colorPickMode2 = ControlCombination.CreateFrom("g.lb g.rb", true); default_instantColorPick1 = ControlCombination.CreateFrom("shift c.secondaryaction", true); default_instantColorPick2 = null; default_replaceColorMode1 = ControlCombination.CreateFrom("shift c.cubesizemode", true); default_replaceColorMode2 = null; // load the settings if they exist if (!Load()) { firstLoad = true; // config didn't exist, assume it's the first time the mod is loaded } Save(); // refresh config in case of any missing or extra settings }
private static bool TryGetCombination(MyKeys key, bool alt, bool ctrl, bool shift, out ControlCombination combination) { combination = null; if (key == MyKeys.None) // unbind { return(true); } string input = InputHandler.inputNames.GetValueOrDefault(key, null); if (input == null) { MyAPIGateway.Utilities.ShowNotification($"Unknown key: {key.ToString()}", 5000, MyFontEnum.Red); return(false); } string combinationString = (alt ? "alt " : "") + (ctrl ? "ctrl " : "") + (shift ? "shift " : "") + input; combination = ControlCombination.CreateFrom(combinationString); MyAPIGateway.Utilities.ShowNotification($"Bound succesfully to: {combination.GetFriendlyString()}", 3000, MyFontEnum.Green); return(true); }
private void ReadSettings(TextReader file) { try { string line; string[] args; int i; bool b; float f; int prevConfigVersion = 0; while ((line = file.ReadLine()) != null) { if (line.Length == 0) { continue; } i = line.IndexOf("//", StringComparison.Ordinal); if (i > -1) { line = (i == 0 ? "" : line.Substring(0, i)); } if (line.Length == 0) { continue; } args = line.Split(CHARS, 2); if (args.Length != 2) { Log.Error("Unknown " + FileName + " line: " + line + "\nMaybe is missing the '=' ?"); continue; } string key = args[0].Trim().ToLower(); string value = args[1]; switch (key) { case "configversion": if (int.TryParse(value, out i)) { prevConfigVersion = i; } else { Log.Error("Invalid " + key + " value: " + value); } continue; case "extrasounds": if (bool.TryParse(value, out b)) { extraSounds = b; } else { Log.Error("Invalid " + key + " value: " + value); } continue; case "sprayparticles": if (bool.TryParse(value, out b)) { sprayParticles = b; } else { Log.Error("Invalid " + key + " value: " + value); } continue; case "spraysoundvolume": if (float.TryParse(value, out f)) { spraySoundVolume = MathHelper.Clamp(f, 0, 1); } else { Log.Error("Invalid " + key + " value: " + value); } continue; case "selectcolorzigzag": if (bool.TryParse(value, out b)) { selectColorZigZag = b; } else { Log.Error("Invalid " + key + " value: " + value); } continue; case "hidepalettewithhud": if (bool.TryParse(value, out b)) { hidePaletteWithHUD = b; } else { Log.Error("Invalid " + key + " value: " + value); } continue; case "palettescreenpos": case "aiminfoscreenpos": string[] vars = value.Split(SEPARATOR); double x, y; if (vars.Length == 2 && double.TryParse(vars[0], out x) && double.TryParse(vars[1], out y)) { Vector2D vec = new Vector2D(x, y); if (key == "aiminfoscreenpos") { aimInfoScreenPos = vec; } else { if (prevConfigVersion < CFG_VERSION_NEWHUDDEFAULTS && x == 0.29d && y == -0.73d) // reset to default if config is older and had default setting { paletteScreenPos = paletteScreenPosDefault; } else { paletteScreenPos = vec; } } } else { Log.Error("Invalid " + key + " value: " + value); } continue; case "palettescale": case "aiminfoscale": if (float.TryParse(value, out f)) { f = MathHelper.Clamp(f, -100, 100); if (key == "aiminfoscale") { aimInfoScale = f; } else { if (prevConfigVersion < CFG_VERSION_NEWHUDDEFAULTS && f == 1f) // reset to default if config is older and had default setting { paletteScale = paletteScaleDefault; } else { paletteScale = f; } } } else { Log.Error("Invalid " + key + " value: " + value); } continue; case "palettebackgroundopacity": case "aiminfobackgroundopacity": { if (value.Trim().Equals("hud", StringComparison.CurrentCultureIgnoreCase)) { f = -1; } else if (float.TryParse(value, out f)) { f = MathHelper.Clamp(f, 0, 1); } else { Log.Error("Invalid " + key + " value: " + value); continue; } if (key == "aiminfoscale") { aimInfoScale = f; } else { if (prevConfigVersion < CFG_VERSION_HUDBKOPACITYDEFAULTS) { paletteBackgroundOpacity = -1; } else { paletteBackgroundOpacity = f; } } continue; } case "requirectrlforcolorcycle": if (bool.TryParse(value, out b)) { requireCtrlForColorCycle = b; } else { Log.Error("Invalid " + key + " value: " + value); } continue; case "pickcolorinput1": // backwards compatibility case "pickcolorinput2": // backwards compatibility case "pickcolormode-input1": case "pickcolormode-input2": { ControlCombination obj = ControlCombination.CreateFrom(value, true); if (value.Length == 0 || obj != null) { if (key.EndsWith("1")) { colorPickMode1 = obj; } else { colorPickMode2 = obj; } } else { Log.Error("Invalid " + key + " value: " + value); } continue; } case "instantpickcolor-input1": case "instantpickcolor-input2": { ControlCombination obj = ControlCombination.CreateFrom(value, true); if (value.Length == 0 || obj != null) { if (key.EndsWith("1")) { instantColorPick1 = obj; } else { instantColorPick2 = obj; } } else { Log.Error("Invalid " + key + " value: " + value); } continue; } case "replacecolormode-input1": case "replacecolormode-input2": case "replacemodeinput1": // backwards compatibility case "replacemodeinput2": // backwards compatibility { ControlCombination obj = ControlCombination.CreateFrom(value, true); if (value.Length == 0 || obj != null) { if (key.EndsWith("1")) { replaceColorMode1 = obj; } else { replaceColorMode2 = obj; } } else { Log.Error("Invalid " + key + " value: " + value); } continue; } case "hideskinsfrompalette": { string[] values = value.Split(SEPARATOR, StringSplitOptions.RemoveEmptyEntries); hideSkinsFromPalette.Clear(); foreach (string val in values) { hideSkinsFromPalette.Add(val.Trim()); } continue; } } } Log.Info("Loaded settings:\n" + GetSettingsString(false)); } catch (Exception e) { Log.Error(e); } }
private void ReadSettings(TextReader file) { try { string line; string[] args; int i; bool b; float f; while((line = file.ReadLine()) != null) { if(line.Length == 0) continue; i = line.IndexOf("//", StringComparison.Ordinal); if(i > -1) line = (i == 0 ? "" : line.Substring(0, i)); if(line.Length == 0) continue; args = line.Split(CHARS, 2); if(args.Length != 2) { Log.Error("Unknown " + FILE + " line: " + line + "\nMaybe is missing the '=' ?"); continue; } args[0] = args[0].Trim().ToLower(); args[1] = args[1].Trim().ToLower(); switch(args[0]) { case "extrasounds": if(bool.TryParse(args[1], out b)) extraSounds = b; else Log.Error("Invalid " + args[0] + " value: " + args[1]); continue; case "sprayparticles": if(bool.TryParse(args[1], out b)) sprayParticles = b; else Log.Error("Invalid " + args[0] + " value: " + args[1]); continue; case "spraysoundvolume": if(float.TryParse(args[1], out f)) spraySoundVolume = MathHelper.Clamp(f, 0, 1); else Log.Error("Invalid " + args[0] + " value: " + args[1]); continue; case "selectcolorzigzag": if(bool.TryParse(args[1], out b)) selectColorZigZag = b; else Log.Error("Invalid " + args[0] + " value: " + args[1]); continue; case "hidepalettewithhud": if(bool.TryParse(args[1], out b)) hidePaletteWithHud = b; else Log.Error("Invalid " + args[0] + " value: " + args[1]); continue; case "palettescreenpos": var vars = args[1].Split(','); double x, y; if(vars.Length == 2 && double.TryParse(vars[0].Trim(), out x) && double.TryParse(vars[1].Trim(), out y)) { paletteScreenPos = new Vector3D(x, y, 0); continue; } Log.Error("Invalid " + args[0] + " value: " + args[1]); continue; case "palettescale": if(float.TryParse(args[1], out f)) paletteScale = MathHelper.Clamp(f, -100, 100); else Log.Error("Invalid " + args[0] + " value: " + args[1]); continue; case "pickcolorinput1": case "pickcolorinput2": case "replacemodeinput1": case "replacemodeinput2": if(args[1].Length == 0) continue; var obj = ControlCombination.CreateFrom(args[1]); if(obj != null) { if(args[0].StartsWith("pick", StringComparison.Ordinal)) { if(args[0].EndsWith("1", StringComparison.Ordinal)) pickColor1 = obj; else pickColor2 = obj; } else { if(args[0].EndsWith("1", StringComparison.Ordinal)) replaceMode1 = obj; else replaceMode2 = obj; } } else Log.Error("Invalid " + args[0] + " value: " + args[1]); continue; } } Log.Info("Loaded settings:\n" + GetSettingsString(false)); } catch(Exception e) { Log.Error(e); } }