public KeyBindComponent(string name, KeyWithModifier key) { Key = key; Name = new LabelControl() { Text = name, Color = new ByteColor(255, 255, 255), FontStyle = System.Drawing.FontStyle.Bold }; input = new InputKeyCatchControl() { Text = key.Modifier == System.Windows.Forms.Keys.None ? key.MainKey.ToString() : key.MainKey.ToString() + " + " + key.Modifier.ToString() }; }
public void SaveChange() { List <ParamRow> Parameters = new List <ParamRow>(); object Parameter; Type reflectedType; PropertyInfo[] pi; bool _restartNeeded = false; //Saving Graphical Parameters ======================================================== if (_graphSettingsPanel != null) { Parameters = this._graphSettingsPanel.Parameters; //Saving the Graphical changes Parameter = ClientSettings.Current.Settings.GraphicalParameters; reflectedType = Parameter.GetType(); pi = reflectedType.GetProperties(); foreach (ParamRow row in Parameters) { var piTmp = pi.First(x => x.Name == row.FieldData.Name); var previousValue = piTmp.GetValue(Parameter, null); ParameterAttribute attrib = (ParameterAttribute)piTmp.GetCustomAttributes(typeof(ParameterAttribute), true)[0]; if (row.FieldData.Value.GetType() != piTmp.PropertyType) { var castedValue = piTmp.PropertyType.InvokeMember("Parse", BindingFlags.InvokeMethod, null, piTmp.PropertyType, new object[] { row.FieldData.Value }); if (previousValue.ToString() != castedValue.ToString()) { if (attrib.NeedRestartAfterChange) { _restartNeeded = true; } piTmp.SetValue(Parameter, castedValue, null); } } else { if (previousValue.ToString() != row.FieldData.Value.ToString()) { piTmp.SetValue(Parameter, row.FieldData.Value, null); if (attrib.NeedRestartAfterChange) { _restartNeeded = true; } } switch (row.FieldData.Name) { case "TexturePack": //Refresh TexturePackConfig value TexturePackConfig.Current = new XmlSettingsManager <TexturePackSetting>(@"TexturePackConfig.xml", SettingsStorage.CustomPath, @"TexturesPacks\" + ClientSettings.Current.Settings.GraphicalParameters.TexturePack + @"\"); TexturePackConfig.Current.Load(); break; case "VSync": ChangeVSync((bool)row.FieldData.Value); break; case "StaticEntityViewSize": ChangeVisibleStaticEntities((int)row.FieldData.Value); break; case "LandscapeFog": ChangeLandscapeFog((string)row.FieldData.Value); break; default: break; } } } } //Saving Core Engine Parameters ======================================================== if (_coreEngineSetingsPanel != null) { Parameters = this._coreEngineSetingsPanel.Parameters; //Saving the Graphical changes Parameter = ClientSettings.Current.Settings.EngineParameters; reflectedType = ClientSettings.Current.Settings.EngineParameters.GetType(); pi = reflectedType.GetProperties(); foreach (ParamRow row in Parameters) { var piTmp = pi.First(x => x.Name == row.FieldData.Name); var previousValue = piTmp.GetValue(Parameter, null); ParameterAttribute attrib = (ParameterAttribute)piTmp.GetCustomAttributes(typeof(ParameterAttribute), true)[0]; if (row.FieldData.Value.GetType() != piTmp.PropertyType) { var castedValue = piTmp.PropertyType.InvokeMember("Parse", BindingFlags.InvokeMethod, null, piTmp.PropertyType, new object[] { row.FieldData.Value }); if (previousValue.ToString() != castedValue.ToString()) { if (attrib.NeedRestartAfterChange) { _restartNeeded = true; } piTmp.SetValue(Parameter, castedValue, null); } } else { if (previousValue.ToString() != row.FieldData.Value.ToString()) { if (attrib.NeedRestartAfterChange) { _restartNeeded = true; } piTmp.SetValue(Parameter, row.FieldData.Value, null); switch (row.FieldData.Name) { case "AllocatedThreadsModifier": ChangeAllocatedThreads((int)row.FieldData.Value); break; default: break; } } } } } //Saving Sound Engine Parameters ======================================================== if (_soundSettingsPanel != null) { Parameters = this._soundSettingsPanel.Parameters; //Saving the Graphical changes Parameter = ClientSettings.Current.Settings.SoundParameters; reflectedType = ClientSettings.Current.Settings.SoundParameters.GetType(); pi = reflectedType.GetProperties(); foreach (ParamRow row in Parameters) { var piTmp = pi.First(x => x.Name == row.FieldData.Name); var previousValue = piTmp.GetValue(Parameter, null); ParameterAttribute attrib = (ParameterAttribute)piTmp.GetCustomAttributes(typeof(ParameterAttribute), true)[0]; if (row.FieldData.Value.GetType() != piTmp.PropertyType) { var castedValue = piTmp.PropertyType.InvokeMember("Parse", BindingFlags.InvokeMethod, null, piTmp.PropertyType, new object[] { row.FieldData.Value }); if (previousValue.ToString() != castedValue.ToString()) { if (attrib.NeedRestartAfterChange) { _restartNeeded = true; } piTmp.SetValue(Parameter, castedValue, null); } } else { if (previousValue.ToString() != row.FieldData.Value.ToString()) { if (attrib.NeedRestartAfterChange) { _restartNeeded = true; } piTmp.SetValue(Parameter, row.FieldData.Value, null); switch (row.FieldData.Name) { case "GlobalFXVolume": SetGlobalFXVol((int)row.FieldData.Value); break; case "GlobalMusicVolume": SetGlobalMusicVol((int)row.FieldData.Value); break; default: break; } } } } } //Saving Key binding Parameters ======================================================== if (_keyBindingSettingsPanel != null) { bool isBindingChanged = false; string[] bindings; KeyWithModifier kwm; FieldInfo[] fi; //For each move key binded reflectedType = ClientSettings.Current.Settings.KeyboardMapping.Move.GetType(); fi = reflectedType.GetFields(); foreach (KeyBindingSettingsPanel.KeyBindComponent keyBinding in _keyBindingSettingsPanel.MoveKeys) { bindings = keyBinding.input.Text.Split(new string[] { " + " }, StringSplitOptions.RemoveEmptyEntries); kwm = new KeyWithModifier(); kwm.MainKey = (Keys)Enum.Parse(typeof(Keys), bindings[0]); kwm.Info = keyBinding.Key.Info; if (bindings.Length > 1) { kwm.Modifier = (Keys)Enum.Parse(typeof(Keys), bindings[1]); } FieldInfo field = fi.First(x => x.Name == keyBinding.Name.Text); KeyWithModifier oldVvalue = (KeyWithModifier)field.GetValue(ClientSettings.Current.Settings.KeyboardMapping.Move); if (oldVvalue != kwm) { field.SetValue(ClientSettings.Current.Settings.KeyboardMapping.Move, kwm); isBindingChanged = true; } } //For each Game key binded reflectedType = ClientSettings.Current.Settings.KeyboardMapping.Game.GetType(); fi = reflectedType.GetFields(); foreach (KeyBindingSettingsPanel.KeyBindComponent keyBinding in _keyBindingSettingsPanel.GameKeys) { bindings = keyBinding.input.Text.Split(new string[] { " + " }, StringSplitOptions.RemoveEmptyEntries); kwm = new KeyWithModifier(); kwm.MainKey = (Keys)Enum.Parse(typeof(Keys), bindings[0]); kwm.Info = keyBinding.Key.Info; if (bindings.Length > 1) { kwm.Modifier = (Keys)Enum.Parse(typeof(Keys), bindings[1]); } FieldInfo field = fi.First(x => x.Name == keyBinding.Name.Text); KeyWithModifier oldVvalue = (KeyWithModifier)field.GetValue(ClientSettings.Current.Settings.KeyboardMapping.Game); if (oldVvalue != kwm) { field.SetValue(ClientSettings.Current.Settings.KeyboardMapping.Game, kwm); isBindingChanged = true; } } //For each System key binded reflectedType = ClientSettings.Current.Settings.KeyboardMapping.System.GetType(); fi = reflectedType.GetFields(); foreach (KeyBindingSettingsPanel.KeyBindComponent keyBinding in _keyBindingSettingsPanel.SystemKeys) { bindings = keyBinding.input.Text.Split(new string[] { " + " }, StringSplitOptions.RemoveEmptyEntries); kwm = new KeyWithModifier(); kwm.MainKey = (Keys)Enum.Parse(typeof(Keys), bindings[0]); kwm.Info = keyBinding.Key.Info; if (bindings.Length > 1) { kwm.Modifier = (Keys)Enum.Parse(typeof(Keys), bindings[1]); } FieldInfo field = fi.First(x => x.Name == keyBinding.Name.Text); KeyWithModifier oldVvalue = (KeyWithModifier)field.GetValue(ClientSettings.Current.Settings.KeyboardMapping.System); if (oldVvalue != kwm) { field.SetValue(ClientSettings.Current.Settings.KeyboardMapping.System, kwm); isBindingChanged = true; } } //Raised the KeyBinding Event if a key has been changed if (isBindingChanged) { if (KeyBindingChanged != null) { KeyBindingChanged(this, null); logger.Info("Keyboard binding Saved, KeyBindingChanged event raised"); } } } if (_restartNeeded) { _settingsStateLabel.IsVisible = true; } ClientSettings.Current.Save(); }