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); } }