/// <summary> /// Read PAD settings from INI file. /// </summary> /// <param name="padSectionName">INI section.</param> /// <param name="s">Settings.</param> /// <param name="p">PAD Settings.</param> /// <remarks>use 'ref' to indicate that objects will be updated inside.</remarks> void ReadWritePadSettings(string padSectionName, ref Setting s, ref PadSetting p, bool write) { s = new Setting(); p = new PadSetting(); // Get PAD1 settings data as a reference. var items = SettingsMap.Where(x => x.MapTo == MapTo.Controller1).ToArray(); var sProps = s.GetType().GetProperties(); var pProps = p.GetType().GetProperties(); var ini2 = new Ini(IniFileName); foreach (var item in items) { string key = item.IniPath.Split('\\')[1]; // Try to find property inside Settings object. var sProp = sProps.FirstOrDefault(x => x.Name == item.PropertyName); if (sProp != null) { if (write) { var sv = (string)sProp.GetValue(s, null) ?? ""; // Write value to INI file. ini2.SetValue(padSectionName, key, sv); } else { // Read value from INI file. var sv = ini2.GetValue(padSectionName, key) ?? ""; sProp.SetValue(s, sv, null); } continue; } // Try to find property inside PAD Settings object. var pProp = pProps.FirstOrDefault(x => x.Name == item.PropertyName); if (pProp != null) { if (write) { var pv = (string)pProp.GetValue(p, null) ?? ""; // Write value to INI file. ini2.SetValue(padSectionName, key, pv); } else { // Read value from INI file. var pv = ini2.GetValue(padSectionName, key) ?? ""; sProp.SetValue(s, pv, null); } continue; } // Property was not found. var message = string.Format("ReadWritePadSettings: Property '{0}' was not found", item.PropertyName); // Inform developer with the message. MessageBoxForm.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Create a new PadSetting object. /// </summary> /// <param name="padSettingChecksum">Initial value of the PadSettingChecksum property.</param> /// <param name="axisToDPadDeadZone">Initial value of the AxisToDPadDeadZone property.</param> /// <param name="axisToDPadEnabled">Initial value of the AxisToDPadEnabled property.</param> /// <param name="axisToDPadOffset">Initial value of the AxisToDPadOffset property.</param> /// <param name="buttonA">Initial value of the ButtonA property.</param> /// <param name="buttonB">Initial value of the ButtonB property.</param> /// <param name="buttonBig">Initial value of the ButtonBig property.</param> /// <param name="buttonBack">Initial value of the ButtonBack property.</param> /// <param name="buttonGuide">Initial value of the ButtonGuide property.</param> /// <param name="buttonStart">Initial value of the ButtonStart property.</param> /// <param name="buttonX">Initial value of the ButtonX property.</param> /// <param name="buttonY">Initial value of the ButtonY property.</param> /// <param name="dPad">Initial value of the DPad property.</param> /// <param name="dPadDown">Initial value of the DPadDown property.</param> /// <param name="dPadLeft">Initial value of the DPadLeft property.</param> /// <param name="dPadRight">Initial value of the DPadRight property.</param> /// <param name="dPadUp">Initial value of the DPadUp property.</param> /// <param name="forceEnable">Initial value of the ForceEnable property.</param> /// <param name="forceOverall">Initial value of the ForceOverall property.</param> /// <param name="forceSwapMotor">Initial value of the ForceSwapMotor property.</param> /// <param name="forceType">Initial value of the ForceType property.</param> /// <param name="gamePadType">Initial value of the GamePadType property.</param> /// <param name="leftMotorPeriod">Initial value of the LeftMotorPeriod property.</param> /// <param name="leftShoulder">Initial value of the LeftShoulder property.</param> /// <param name="leftThumbAntiDeadZoneX">Initial value of the LeftThumbAntiDeadZoneX property.</param> /// <param name="leftThumbAntiDeadZoneY">Initial value of the LeftThumbAntiDeadZoneY property.</param> /// <param name="leftThumbAxisX">Initial value of the LeftThumbAxisX property.</param> /// <param name="leftThumbAxisY">Initial value of the LeftThumbAxisY property.</param> /// <param name="leftThumbButton">Initial value of the LeftThumbButton property.</param> /// <param name="leftThumbDeadZoneX">Initial value of the LeftThumbDeadZoneX property.</param> /// <param name="leftThumbDeadZoneY">Initial value of the LeftThumbDeadZoneY property.</param> /// <param name="leftThumbDown">Initial value of the LeftThumbDown property.</param> /// <param name="leftThumbLeft">Initial value of the LeftThumbLeft property.</param> /// <param name="leftThumbRight">Initial value of the LeftThumbRight property.</param> /// <param name="leftThumbUp">Initial value of the LeftThumbUp property.</param> /// <param name="leftTrigger">Initial value of the LeftTrigger property.</param> /// <param name="leftTriggerDeadZone">Initial value of the LeftTriggerDeadZone property.</param> /// <param name="passThrough">Initial value of the PassThrough property.</param> /// <param name="rightMotorPeriod">Initial value of the RightMotorPeriod property.</param> /// <param name="rightShoulder">Initial value of the RightShoulder property.</param> /// <param name="rightThumbAntiDeadZoneX">Initial value of the RightThumbAntiDeadZoneX property.</param> /// <param name="rightThumbAntiDeadZoneY">Initial value of the RightThumbAntiDeadZoneY property.</param> /// <param name="rightThumbAxisX">Initial value of the RightThumbAxisX property.</param> /// <param name="rightThumbAxisY">Initial value of the RightThumbAxisY property.</param> /// <param name="rightThumbButton">Initial value of the RightThumbButton property.</param> /// <param name="rightThumbDeadZoneX">Initial value of the RightThumbDeadZoneX property.</param> /// <param name="rightThumbDeadZoneY">Initial value of the RightThumbDeadZoneY property.</param> /// <param name="rightThumbDown">Initial value of the RightThumbDown property.</param> /// <param name="rightThumbLeft">Initial value of the RightThumbLeft property.</param> /// <param name="rightThumbRight">Initial value of the RightThumbRight property.</param> /// <param name="rightThumbUp">Initial value of the RightThumbUp property.</param> /// <param name="rightTrigger">Initial value of the RightTrigger property.</param> /// <param name="rightTriggerDeadZone">Initial value of the RightTriggerDeadZone property.</param> /// <param name="leftThumbLinearX">Initial value of the LeftThumbLinearX property.</param> /// <param name="leftThumbLinearY">Initial value of the LeftThumbLinearY property.</param> /// <param name="rightThumbLinearX">Initial value of the RightThumbLinearX property.</param> /// <param name="rightThumbLinearY">Initial value of the RightThumbLinearY property.</param> /// <param name="leftMotorStrength">Initial value of the LeftMotorStrength property.</param> /// <param name="rightMotorStrength">Initial value of the RightMotorStrength property.</param> /// <param name="leftMotorDirection">Initial value of the LeftMotorDirection property.</param> /// <param name="rightMotorDirection">Initial value of the RightMotorDirection property.</param> /// <param name="buttonADeadZone">Initial value of the ButtonADeadZone property.</param> /// <param name="buttonBDeadZone">Initial value of the ButtonBDeadZone property.</param> /// <param name="buttonBackDeadZone">Initial value of the ButtonBackDeadZone property.</param> /// <param name="buttonStartDeadZone">Initial value of the ButtonStartDeadZone property.</param> /// <param name="buttonXDeadZone">Initial value of the ButtonXDeadZone property.</param> /// <param name="buttonYDeadZone">Initial value of the ButtonYDeadZone property.</param> /// <param name="leftThumbButtonDeadZone">Initial value of the LeftThumbButtonDeadZone property.</param> /// <param name="rightThumbButtonDeadZone">Initial value of the RightThumbButtonDeadZone property.</param> /// <param name="leftShoulderDeadZone">Initial value of the LeftShoulderDeadZone property.</param> /// <param name="rightShoulderDeadZone">Initial value of the RightShoulderDeadZone property.</param> /// <param name="dPadDownDeadZone">Initial value of the DPadDownDeadZone property.</param> /// <param name="dPadLeftDeadZone">Initial value of the DPadLeftDeadZone property.</param> /// <param name="dPadRightDeadZone">Initial value of the DPadRightDeadZone property.</param> /// <param name="dPadUpDeadZone">Initial value of the DPadUpDeadZone property.</param> public static PadSetting CreatePadSetting(global::System.Guid padSettingChecksum, global::System.String axisToDPadDeadZone, global::System.String axisToDPadEnabled, global::System.String axisToDPadOffset, global::System.String buttonA, global::System.String buttonB, global::System.String buttonBig, global::System.String buttonBack, global::System.String buttonGuide, global::System.String buttonStart, global::System.String buttonX, global::System.String buttonY, global::System.String dPad, global::System.String dPadDown, global::System.String dPadLeft, global::System.String dPadRight, global::System.String dPadUp, global::System.String forceEnable, global::System.String forceOverall, global::System.String forceSwapMotor, global::System.String forceType, global::System.String gamePadType, global::System.String leftMotorPeriod, global::System.String leftShoulder, global::System.String leftThumbAntiDeadZoneX, global::System.String leftThumbAntiDeadZoneY, global::System.String leftThumbAxisX, global::System.String leftThumbAxisY, global::System.String leftThumbButton, global::System.String leftThumbDeadZoneX, global::System.String leftThumbDeadZoneY, global::System.String leftThumbDown, global::System.String leftThumbLeft, global::System.String leftThumbRight, global::System.String leftThumbUp, global::System.String leftTrigger, global::System.String leftTriggerDeadZone, global::System.String passThrough, global::System.String rightMotorPeriod, global::System.String rightShoulder, global::System.String rightThumbAntiDeadZoneX, global::System.String rightThumbAntiDeadZoneY, global::System.String rightThumbAxisX, global::System.String rightThumbAxisY, global::System.String rightThumbButton, global::System.String rightThumbDeadZoneX, global::System.String rightThumbDeadZoneY, global::System.String rightThumbDown, global::System.String rightThumbLeft, global::System.String rightThumbRight, global::System.String rightThumbUp, global::System.String rightTrigger, global::System.String rightTriggerDeadZone, global::System.String leftThumbLinearX, global::System.String leftThumbLinearY, global::System.String rightThumbLinearX, global::System.String rightThumbLinearY, global::System.String leftMotorStrength, global::System.String rightMotorStrength, global::System.String leftMotorDirection, global::System.String rightMotorDirection, global::System.String buttonADeadZone, global::System.String buttonBDeadZone, global::System.String buttonBackDeadZone, global::System.String buttonStartDeadZone, global::System.String buttonXDeadZone, global::System.String buttonYDeadZone, global::System.String leftThumbButtonDeadZone, global::System.String rightThumbButtonDeadZone, global::System.String leftShoulderDeadZone, global::System.String rightShoulderDeadZone, global::System.String dPadDownDeadZone, global::System.String dPadLeftDeadZone, global::System.String dPadRightDeadZone, global::System.String dPadUpDeadZone) { PadSetting padSetting = new PadSetting(); padSetting.PadSettingChecksum = padSettingChecksum; padSetting.AxisToDPadDeadZone = axisToDPadDeadZone; padSetting.AxisToDPadEnabled = axisToDPadEnabled; padSetting.AxisToDPadOffset = axisToDPadOffset; padSetting.ButtonA = buttonA; padSetting.ButtonB = buttonB; padSetting.ButtonBig = buttonBig; padSetting.ButtonBack = buttonBack; padSetting.ButtonGuide = buttonGuide; padSetting.ButtonStart = buttonStart; padSetting.ButtonX = buttonX; padSetting.ButtonY = buttonY; padSetting.DPad = dPad; padSetting.DPadDown = dPadDown; padSetting.DPadLeft = dPadLeft; padSetting.DPadRight = dPadRight; padSetting.DPadUp = dPadUp; padSetting.ForceEnable = forceEnable; padSetting.ForceOverall = forceOverall; padSetting.ForceSwapMotor = forceSwapMotor; padSetting.ForceType = forceType; padSetting.GamePadType = gamePadType; padSetting.LeftMotorPeriod = leftMotorPeriod; padSetting.LeftShoulder = leftShoulder; padSetting.LeftThumbAntiDeadZoneX = leftThumbAntiDeadZoneX; padSetting.LeftThumbAntiDeadZoneY = leftThumbAntiDeadZoneY; padSetting.LeftThumbAxisX = leftThumbAxisX; padSetting.LeftThumbAxisY = leftThumbAxisY; padSetting.LeftThumbButton = leftThumbButton; padSetting.LeftThumbDeadZoneX = leftThumbDeadZoneX; padSetting.LeftThumbDeadZoneY = leftThumbDeadZoneY; padSetting.LeftThumbDown = leftThumbDown; padSetting.LeftThumbLeft = leftThumbLeft; padSetting.LeftThumbRight = leftThumbRight; padSetting.LeftThumbUp = leftThumbUp; padSetting.LeftTrigger = leftTrigger; padSetting.LeftTriggerDeadZone = leftTriggerDeadZone; padSetting.PassThrough = passThrough; padSetting.RightMotorPeriod = rightMotorPeriod; padSetting.RightShoulder = rightShoulder; padSetting.RightThumbAntiDeadZoneX = rightThumbAntiDeadZoneX; padSetting.RightThumbAntiDeadZoneY = rightThumbAntiDeadZoneY; padSetting.RightThumbAxisX = rightThumbAxisX; padSetting.RightThumbAxisY = rightThumbAxisY; padSetting.RightThumbButton = rightThumbButton; padSetting.RightThumbDeadZoneX = rightThumbDeadZoneX; padSetting.RightThumbDeadZoneY = rightThumbDeadZoneY; padSetting.RightThumbDown = rightThumbDown; padSetting.RightThumbLeft = rightThumbLeft; padSetting.RightThumbRight = rightThumbRight; padSetting.RightThumbUp = rightThumbUp; padSetting.RightTrigger = rightTrigger; padSetting.RightTriggerDeadZone = rightTriggerDeadZone; padSetting.LeftThumbLinearX = leftThumbLinearX; padSetting.LeftThumbLinearY = leftThumbLinearY; padSetting.RightThumbLinearX = rightThumbLinearX; padSetting.RightThumbLinearY = rightThumbLinearY; padSetting.LeftMotorStrength = leftMotorStrength; padSetting.RightMotorStrength = rightMotorStrength; padSetting.LeftMotorDirection = leftMotorDirection; padSetting.RightMotorDirection = rightMotorDirection; padSetting.ButtonADeadZone = buttonADeadZone; padSetting.ButtonBDeadZone = buttonBDeadZone; padSetting.ButtonBackDeadZone = buttonBackDeadZone; padSetting.ButtonStartDeadZone = buttonStartDeadZone; padSetting.ButtonXDeadZone = buttonXDeadZone; padSetting.ButtonYDeadZone = buttonYDeadZone; padSetting.LeftThumbButtonDeadZone = leftThumbButtonDeadZone; padSetting.RightThumbButtonDeadZone = rightThumbButtonDeadZone; padSetting.LeftShoulderDeadZone = leftShoulderDeadZone; padSetting.RightShoulderDeadZone = rightShoulderDeadZone; padSetting.DPadDownDeadZone = dPadDownDeadZone; padSetting.DPadLeftDeadZone = dPadLeftDeadZone; padSetting.DPadRightDeadZone = dPadRightDeadZone; padSetting.DPadUpDeadZone = dPadUpDeadZone; return padSetting; }
/// <summary> /// Deprecated Method for adding a new object to the PadSettings EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToPadSettings(PadSetting padSetting) { base.AddObject("PadSettings", padSetting); }
public string SaveSetting(Setting s, PadSetting ps) { var checksum = ps.GetCheckSum(); var db = new x360ceModelContainer(); var s1 = db.Settings.FirstOrDefault(x => x.InstanceGuid == s.InstanceGuid && x.FileName == s.FileName && x.FileProductName == s.FileProductName); var n = DateTime.Now; if (s1 == null) { s1 = new Setting(); s1.SettingId = Guid.NewGuid(); s1.DateCreated = n; db.Settings.AddObject(s1); } s1.Comment = s.Comment; s1.DateUpdated = n; s1.DateSelected = n; s1.DeviceType = s.DeviceType; s1.FileName = s.FileName; s1.FileProductName = s.FileProductName; s1.InstanceGuid = s.InstanceGuid; s1.InstanceName = s.InstanceName; s1.ProductGuid = s.ProductGuid; s1.ProductName = s.ProductName; s1.IsEnabled = s.IsEnabled; s1.PadSettingChecksum = checksum; // Save Pad Settings. var p1 = db.PadSettings.FirstOrDefault(x => x.PadSettingChecksum == checksum); if (p1 == null) { p1 = new PadSetting(); p1.PadSettingChecksum = checksum; db.PadSettings.AddObject(p1); } p1.AxisToDPadDeadZone = ps.AxisToDPadDeadZone; p1.AxisToDPadEnabled = ps.AxisToDPadEnabled; p1.AxisToDPadOffset = ps.AxisToDPadOffset; p1.ButtonA = ps.ButtonA; p1.ButtonB = ps.ButtonB; p1.ButtonBig = string.IsNullOrEmpty(ps.ButtonBig) ? "" : ps.ButtonBig; p1.ButtonGuide = string.IsNullOrEmpty(ps.ButtonGuide) ? "" : ps.ButtonGuide; p1.ButtonBack = ps.ButtonBack; p1.ButtonStart = ps.ButtonStart; p1.ButtonX = ps.ButtonX; p1.ButtonY = ps.ButtonY; p1.DPad = ps.DPad; p1.DPadDown = ps.DPadDown; p1.DPadLeft = ps.DPadLeft; p1.DPadRight = ps.DPadRight; p1.DPadUp = ps.DPadUp; p1.ForceEnable = ps.ForceEnable; p1.ForceOverall = ps.ForceOverall; p1.ForceSwapMotor = ps.ForceSwapMotor; p1.ForceType = ps.ForceType; p1.GamePadType = ps.GamePadType; p1.LeftMotorPeriod = ps.LeftMotorPeriod; p1.LeftMotorStrength = string.IsNullOrEmpty(ps.LeftMotorStrength) ? "100" : ps.LeftMotorStrength; p1.LeftShoulder = ps.LeftShoulder; p1.LeftThumbAntiDeadZoneX = ps.LeftThumbAntiDeadZoneX; p1.LeftThumbAntiDeadZoneY = ps.LeftThumbAntiDeadZoneY; p1.LeftThumbAxisX = ps.LeftThumbAxisX; p1.LeftThumbAxisY = ps.LeftThumbAxisY; p1.LeftThumbButton = ps.LeftThumbButton; p1.LeftThumbDeadZoneX = ps.LeftThumbDeadZoneX; p1.LeftThumbDeadZoneY = ps.LeftThumbDeadZoneY; p1.LeftThumbLinearX = string.IsNullOrEmpty(ps.LeftThumbLinearX) ? "" : ps.LeftThumbLinearX; p1.LeftThumbLinearY = string.IsNullOrEmpty(ps.LeftThumbLinearY) ? "" : ps.LeftThumbLinearY; p1.LeftThumbDown = ps.LeftThumbDown; p1.LeftThumbLeft = ps.LeftThumbLeft; p1.LeftThumbRight = ps.LeftThumbRight; p1.LeftThumbUp = ps.LeftThumbUp; p1.LeftTrigger = ps.LeftTrigger; p1.LeftTriggerDeadZone = ps.LeftTriggerDeadZone; p1.PassThrough = ps.PassThrough; p1.RightMotorPeriod = ps.RightMotorPeriod; p1.RightMotorStrength = string.IsNullOrEmpty(ps.RightMotorStrength) ? "100" : ps.RightMotorStrength; p1.RightShoulder = ps.RightShoulder; p1.RightThumbAntiDeadZoneX = ps.RightThumbAntiDeadZoneX; p1.RightThumbAntiDeadZoneY = ps.RightThumbAntiDeadZoneY; p1.RightThumbLinearX = string.IsNullOrEmpty(ps.RightThumbLinearX) ? "" : ps.RightThumbLinearX; p1.RightThumbLinearY = string.IsNullOrEmpty(ps.RightThumbLinearY) ? "" : ps.RightThumbLinearY; p1.RightThumbAxisX = ps.RightThumbAxisX; p1.RightThumbAxisY = ps.RightThumbAxisY; p1.RightThumbButton = ps.RightThumbButton; p1.RightThumbDeadZoneX = ps.RightThumbDeadZoneX; p1.RightThumbDeadZoneY = ps.RightThumbDeadZoneY; p1.RightThumbDown = ps.RightThumbDown; p1.RightThumbLeft = ps.RightThumbLeft; p1.RightThumbRight = ps.RightThumbRight; p1.RightThumbUp = ps.RightThumbUp; p1.RightTrigger = ps.RightTrigger; p1.RightTriggerDeadZone = ps.RightTriggerDeadZone; db.SaveChanges(); db.Dispose(); db = null; return ""; }
public void SaveSettingAsync(Setting s, PadSetting ps, object userState = null) { InvokeAsync("SaveSetting", SaveSettingCompleted, userState, new object[] { s, ps }); }
public string SaveSetting(Setting s, PadSetting ps) { object[] results = Invoke("SaveSetting", new object[] { s, ps }); return (string)results[0]; }
/// <summary> /// Calculate map completion percent based on user device (controller) capabilities. /// </summary> public static int GetCompletionPoints(PadSetting ps, UserDevice ud = null) { // Xbox 360 Controller have 6 axis. Use device count if less. var maxAxis = ud != null && ud.CapAxeCount > 0 && ud.CapAxeCount < 6m ? ud.CapAxeCount : 6m; // Xbox 360 Controller have 14 buttons. Use device count if less. var maxButtons = ud != null && ud.CapButtonCount > 0 && ud.CapButtonCount < 14m ? ud.CapButtonCount : 14m; // Use device motor count. var maxMotors = ud != null ? ud.DiActuatorMask : 0m; var motorPoints = 0m; // If force feedback enabled then... if (ps.ForceEnable == "1") { // Give all available points. motorPoints = maxMotors; } // Count axis points (maximum 6 points). var axisPoints = 0m; axisPoints += GetAxisMapPoints(ps.LeftThumbAxisX, ps.LeftThumbLeft, ps.LeftThumbRight); axisPoints += GetAxisMapPoints(ps.LeftThumbAxisY, ps.LeftThumbUp, ps.LeftThumbDown); axisPoints += GetAxisMapPoints(ps.RightThumbAxisX, ps.RightThumbLeft, ps.RightThumbRight); axisPoints += GetAxisMapPoints(ps.RightThumbAxisY, ps.RightThumbUp, ps.RightThumbDown); axisPoints += GetAxisMapPoints(ps.LeftTrigger); axisPoints += GetAxisMapPoints(ps.RightTrigger); // Count button points (maximum 14 points). var buttonPoints = 0m; MapType type; int index; if (SettingsConverter.TryParseIniValue(ps.ButtonA, out type, out index)) { buttonPoints += 1m; } if (SettingsConverter.TryParseIniValue(ps.ButtonB, out type, out index)) { buttonPoints += 1m; } if (SettingsConverter.TryParseIniValue(ps.ButtonX, out type, out index)) { buttonPoints += 1m; } if (SettingsConverter.TryParseIniValue(ps.ButtonY, out type, out index)) { buttonPoints += 1m; } if (SettingsConverter.TryParseIniValue(ps.ButtonBack, out type, out index)) { buttonPoints += 1m; } if (SettingsConverter.TryParseIniValue(ps.ButtonStart, out type, out index)) { buttonPoints += 1m; } // If DPad is properly mapped to POV then... if (SettingsConverter.TryParseIniValue(ps.DPadDown, out type, out index) && type == MapType.POV) { // Add 4 points. buttonPoints += 4m; } else { // Add point for each button. if (SettingsConverter.TryParseIniValue(ps.DPadUp, out type, out index)) { buttonPoints += 1m; } if (SettingsConverter.TryParseIniValue(ps.DPadDown, out type, out index)) { buttonPoints += 1m; } if (SettingsConverter.TryParseIniValue(ps.DPadLeft, out type, out index)) { buttonPoints += 1m; } if (SettingsConverter.TryParseIniValue(ps.DPadRight, out type, out index)) { buttonPoints += 1m; } } if (SettingsConverter.TryParseIniValue(ps.LeftThumbButton, out type, out index)) { buttonPoints += 1m; } if (SettingsConverter.TryParseIniValue(ps.RightThumbButton, out type, out index)) { buttonPoints += 1m; } if (SettingsConverter.TryParseIniValue(ps.LeftShoulder, out type, out index)) { buttonPoints += 1m; } if (SettingsConverter.TryParseIniValue(ps.RightShoulder, out type, out index)) { buttonPoints += 1m; } // Calculate completion percent. var completion = (int)(100m * ( (axisPoints + buttonPoints + motorPoints) / (maxAxis + maxButtons + maxMotors) )); return(completion); }
/// <summary> /// Set INI settings from PadSetting object by device Instance GUID. /// </summary> /// <param name="instanceGuid">Instance GUID.</param> /// <returns>PadSettings object.</returns> public void SetPadSetting(string padSectionName, PadSetting ps) { var ini2 = new Ini(IniFileName); //ps.PadSettingChecksum = Guid.Empty; ini2.SetValue(padSectionName, SettingName.AxisToDPadDeadZone, ps.AxisToDPadDeadZone); ini2.SetValue(padSectionName, SettingName.AxisToDPadEnabled, ps.AxisToDPadEnabled); ini2.SetValue(padSectionName, SettingName.AxisToDPadOffset, ps.AxisToDPadOffset); ini2.SetValue(padSectionName, SettingName.ButtonA, ps.ButtonA); ini2.SetValue(padSectionName, SettingName.ButtonB, ps.ButtonB); ini2.SetValue(padSectionName, SettingName.ButtonGuide, ps.ButtonBig); ini2.SetValue(padSectionName, SettingName.ButtonBack, ps.ButtonBack); ini2.SetValue(padSectionName, SettingName.ButtonStart, ps.ButtonStart); ini2.SetValue(padSectionName, SettingName.ButtonX, ps.ButtonX); ini2.SetValue(padSectionName, SettingName.ButtonY, ps.ButtonY); ini2.SetValue(padSectionName, SettingName.DPad, ps.DPad); ini2.SetValue(padSectionName, SettingName.DPadDown, ps.DPadDown); ini2.SetValue(padSectionName, SettingName.DPadLeft, ps.DPadLeft); ini2.SetValue(padSectionName, SettingName.DPadRight, ps.DPadRight); ini2.SetValue(padSectionName, SettingName.DPadUp, ps.DPadUp); ini2.SetValue(padSectionName, SettingName.ForceEnable, ps.ForceEnable); ini2.SetValue(padSectionName, SettingName.ForceOverall, ps.ForceOverall); ini2.SetValue(padSectionName, SettingName.ForceSwapMotor, ps.ForceSwapMotor); ini2.SetValue(padSectionName, SettingName.ForceType, ps.ForceType); ini2.SetValue(padSectionName, SettingName.DeviceSubType, ps.GamePadType); ini2.SetValue(padSectionName, SettingName.LeftMotorPeriod, ps.LeftMotorPeriod); ini2.SetValue(padSectionName, SettingName.LeftMotorStrength, ps.LeftMotorStrength); ini2.SetValue(padSectionName, SettingName.LeftShoulder, ps.LeftShoulder); ini2.SetValue(padSectionName, SettingName.LeftThumbAntiDeadZoneX, ps.LeftThumbAntiDeadZoneX); ini2.SetValue(padSectionName, SettingName.LeftThumbAntiDeadZoneY, ps.LeftThumbAntiDeadZoneY); ini2.SetValue(padSectionName, SettingName.LeftThumbLinearX, ps.LeftThumbLinearX); ini2.SetValue(padSectionName, SettingName.LeftThumbLinearY, ps.LeftThumbLinearY); ini2.SetValue(padSectionName, SettingName.LeftThumbAxisX, ps.LeftThumbAxisX); ini2.SetValue(padSectionName, SettingName.LeftThumbAxisY, ps.LeftThumbAxisY); ini2.SetValue(padSectionName, SettingName.LeftThumbButton, ps.LeftThumbButton); ini2.SetValue(padSectionName, SettingName.LeftThumbDeadZoneX, ps.LeftThumbDeadZoneX); ini2.SetValue(padSectionName, SettingName.LeftThumbDeadZoneY, ps.LeftThumbDeadZoneY); ini2.SetValue(padSectionName, SettingName.LeftThumbDown, ps.LeftThumbDown); ini2.SetValue(padSectionName, SettingName.LeftThumbLeft, ps.LeftThumbLeft); ini2.SetValue(padSectionName, SettingName.LeftThumbRight, ps.LeftThumbRight); ini2.SetValue(padSectionName, SettingName.LeftThumbUp, ps.LeftThumbUp); ini2.SetValue(padSectionName, SettingName.LeftTrigger, ps.LeftTrigger); ini2.SetValue(padSectionName, SettingName.LeftTriggerDeadZone, ps.LeftTriggerDeadZone); ini2.SetValue(padSectionName, SettingName.PassThrough, ps.PassThrough); ini2.SetValue(padSectionName, SettingName.RightMotorPeriod, ps.RightMotorPeriod); ini2.SetValue(padSectionName, SettingName.RightMotorStrength, ps.RightMotorStrength); ini2.SetValue(padSectionName, SettingName.RightShoulder, ps.RightShoulder); ini2.SetValue(padSectionName, SettingName.RightThumbAntiDeadZoneX, ps.RightThumbAntiDeadZoneX); ini2.SetValue(padSectionName, SettingName.RightThumbAntiDeadZoneY, ps.RightThumbAntiDeadZoneY); ini2.SetValue(padSectionName, SettingName.RightThumbLinearX, ps.RightThumbLinearX); ini2.SetValue(padSectionName, SettingName.RightThumbLinearY, ps.RightThumbLinearY); ini2.SetValue(padSectionName, SettingName.RightThumbAxisX, ps.RightThumbAxisX); ini2.SetValue(padSectionName, SettingName.RightThumbAxisY, ps.RightThumbAxisY); ini2.SetValue(padSectionName, SettingName.RightThumbButton, ps.RightThumbButton); ini2.SetValue(padSectionName, SettingName.RightThumbDeadZoneX, ps.RightThumbDeadZoneX); ini2.SetValue(padSectionName, SettingName.RightThumbDeadZoneY, ps.RightThumbDeadZoneY); ini2.SetValue(padSectionName, SettingName.RightThumbDown, ps.RightThumbDown); ini2.SetValue(padSectionName, SettingName.RightThumbLeft, ps.RightThumbLeft); ini2.SetValue(padSectionName, SettingName.RightThumbRight, ps.RightThumbRight); ini2.SetValue(padSectionName, SettingName.RightThumbUp, ps.RightThumbUp); ini2.SetValue(padSectionName, SettingName.RightTrigger, ps.RightTrigger); ini2.SetValue(padSectionName, SettingName.RightTriggerDeadZone, ps.RightTriggerDeadZone); }
/// <summary> /// Get PadSetting object from INI by device Instance GUID. /// </summary> /// <param name="instanceGuid">Instance GUID.</param> /// <returns>PadSettings object.</returns> public PadSetting GetPadSetting(string padSectionName) { var ini2 = new Ini(IniFileName); var ps = new PadSetting(); ps.PadSettingChecksum = Guid.Empty; ps.AxisToDPadDeadZone = ini2.GetValue(padSectionName, SettingName.AxisToDPadDeadZone); ps.AxisToDPadEnabled = ini2.GetValue(padSectionName, SettingName.AxisToDPadEnabled); ps.AxisToDPadOffset = ini2.GetValue(padSectionName, SettingName.AxisToDPadOffset); ps.ButtonA = ini2.GetValue(padSectionName, SettingName.ButtonA); ps.ButtonB = ini2.GetValue(padSectionName, SettingName.ButtonB); ps.ButtonGuide = ini2.GetValue(padSectionName, SettingName.ButtonGuide); ps.ButtonBig = ini2.GetValue(padSectionName, SettingName.ButtonBig); ps.ButtonBack = ini2.GetValue(padSectionName, SettingName.ButtonBack); ps.ButtonStart = ini2.GetValue(padSectionName, SettingName.ButtonStart); ps.ButtonX = ini2.GetValue(padSectionName, SettingName.ButtonX); ps.ButtonY = ini2.GetValue(padSectionName, SettingName.ButtonY); ps.DPad = ini2.GetValue(padSectionName, SettingName.DPad); ps.DPadDown = ini2.GetValue(padSectionName, SettingName.DPadDown); ps.DPadLeft = ini2.GetValue(padSectionName, SettingName.DPadLeft); ps.DPadRight = ini2.GetValue(padSectionName, SettingName.DPadRight); ps.DPadUp = ini2.GetValue(padSectionName, SettingName.DPadUp); ps.ForceEnable = ini2.GetValue(padSectionName, SettingName.ForceEnable); ps.ForceOverall = ini2.GetValue(padSectionName, SettingName.ForceOverall); ps.ForceSwapMotor = ini2.GetValue(padSectionName, SettingName.ForceSwapMotor); ps.ForceType = ini2.GetValue(padSectionName, SettingName.ForceType); ps.GamePadType = ini2.GetValue(padSectionName, SettingName.DeviceSubType); ps.LeftMotorPeriod = ini2.GetValue(padSectionName, SettingName.LeftMotorPeriod); ps.LeftMotorStrength = ini2.GetValue(padSectionName, SettingName.LeftMotorStrength); ps.LeftShoulder = ini2.GetValue(padSectionName, SettingName.LeftShoulder); ps.LeftThumbAntiDeadZoneX = ini2.GetValue(padSectionName, SettingName.LeftThumbAntiDeadZoneX); ps.LeftThumbAntiDeadZoneY = ini2.GetValue(padSectionName, SettingName.LeftThumbAntiDeadZoneY); ps.LeftThumbLinearX = ini2.GetValue(padSectionName, SettingName.LeftThumbLinearX); ps.LeftThumbLinearY = ini2.GetValue(padSectionName, SettingName.LeftThumbLinearY); ps.LeftThumbAxisX = ini2.GetValue(padSectionName, SettingName.LeftThumbAxisX); ps.LeftThumbAxisY = ini2.GetValue(padSectionName, SettingName.LeftThumbAxisY); ps.LeftThumbButton = ini2.GetValue(padSectionName, SettingName.LeftThumbButton); ps.LeftThumbDeadZoneX = ini2.GetValue(padSectionName, SettingName.LeftThumbDeadZoneX); ps.LeftThumbDeadZoneY = ini2.GetValue(padSectionName, SettingName.LeftThumbDeadZoneY); ps.LeftThumbDown = ini2.GetValue(padSectionName, SettingName.LeftThumbDown); ps.LeftThumbLeft = ini2.GetValue(padSectionName, SettingName.LeftThumbLeft); ps.LeftThumbRight = ini2.GetValue(padSectionName, SettingName.LeftThumbRight); ps.LeftThumbUp = ini2.GetValue(padSectionName, SettingName.LeftThumbUp); ps.LeftTrigger = ini2.GetValue(padSectionName, SettingName.LeftTrigger); ps.LeftTriggerDeadZone = ini2.GetValue(padSectionName, SettingName.LeftTriggerDeadZone); ps.PassThrough = ini2.GetValue(padSectionName, SettingName.PassThrough); ps.RightMotorPeriod = ini2.GetValue(padSectionName, SettingName.RightMotorPeriod); ps.RightMotorStrength = ini2.GetValue(padSectionName, SettingName.RightMotorStrength); ps.RightShoulder = ini2.GetValue(padSectionName, SettingName.RightShoulder); ps.RightThumbAntiDeadZoneX = ini2.GetValue(padSectionName, SettingName.RightThumbAntiDeadZoneX); ps.RightThumbAntiDeadZoneY = ini2.GetValue(padSectionName, SettingName.RightThumbAntiDeadZoneY); ps.RightThumbAxisX = ini2.GetValue(padSectionName, SettingName.RightThumbAxisX); ps.RightThumbAxisY = ini2.GetValue(padSectionName, SettingName.RightThumbAxisY); ps.RightThumbButton = ini2.GetValue(padSectionName, SettingName.RightThumbButton); ps.RightThumbDeadZoneX = ini2.GetValue(padSectionName, SettingName.RightThumbDeadZoneX); ps.RightThumbDeadZoneY = ini2.GetValue(padSectionName, SettingName.RightThumbDeadZoneY); ps.RightThumbLinearX = ini2.GetValue(padSectionName, SettingName.RightThumbLinearX); ps.RightThumbLinearY = ini2.GetValue(padSectionName, SettingName.RightThumbLinearY); ps.RightThumbDown = ini2.GetValue(padSectionName, SettingName.RightThumbDown); ps.RightThumbLeft = ini2.GetValue(padSectionName, SettingName.RightThumbLeft); ps.RightThumbRight = ini2.GetValue(padSectionName, SettingName.RightThumbRight); ps.RightThumbUp = ini2.GetValue(padSectionName, SettingName.RightThumbUp); ps.RightTrigger = ini2.GetValue(padSectionName, SettingName.RightTrigger); ps.RightTriggerDeadZone = ini2.GetValue(padSectionName, SettingName.RightTriggerDeadZone); return ps; }
/// <summary> /// Read PAD settings from INI file. /// </summary> /// <param name="padSectionName">INI section.</param> /// <param name="s">Settings.</param> /// <param name="p">PAD Settings.</param> public void ReadPadSettingsFromIni(string padSectionName, out Setting s, out PadSetting p) { s = new Setting(); p = new PadSetting(); ReadWritePadSettings(padSectionName, ref s, ref p, false); }
/// <summary> /// Write PAD settings to INI file. /// </summary> /// <param name="padSectionName">INI section.</param> /// <param name="s">Settings.</param> /// <param name="p">PAD Settings.</param> public void WritePadSettingsToIni(string padSectionName, Setting s, PadSetting p) { ReadWritePadSettings(padSectionName, ref s, ref p, true); }
public void Load(PadSetting source) { var names = new string[] { // GamePad. nameof(PassThrough), nameof(GamePadType), // Force Feedback. nameof(ForceEnable), nameof(ForceType), nameof(ForceSwapMotor), nameof(ForceOverall), nameof(LeftMotorPeriod), nameof(LeftMotorDirection), nameof(LeftMotorStrength), nameof(RightMotorPeriod), nameof(RightMotorDirection), nameof(RightMotorStrength), // D-PAD nameof(AxisToDPadDeadZone), nameof(AxisToDPadEnabled), nameof(AxisToDPadOffset), // Buttons. nameof(ButtonA), nameof(ButtonB), nameof(ButtonGuide), nameof(ButtonBack), nameof(ButtonStart), nameof(ButtonX), nameof(ButtonY), nameof(DPad), nameof(DPadDown), nameof(DPadLeft), nameof(DPadRight), nameof(DPadUp), nameof(LeftShoulder), nameof(LeftThumbButton), nameof(RightShoulder), nameof(RightThumbButton), // Right Trigger. nameof(RightTrigger), nameof(RightTriggerDeadZone), nameof(RightTriggerAntiDeadZone), nameof(RightTriggerLinear), // Left Thumb Virtual Buttons. nameof(LeftThumbUp), nameof(LeftThumbRight), nameof(LeftThumbDown), nameof(LeftThumbLeft), // Left Thumb Axis X nameof(LeftThumbAxisX), nameof(LeftThumbDeadZoneX), nameof(LeftThumbAntiDeadZoneX), nameof(LeftThumbLinearX), // Left Thumb Axis Y nameof(LeftThumbAxisY), nameof(LeftThumbDeadZoneY), nameof(LeftThumbAntiDeadZoneY), nameof(LeftThumbLinearY), // Left Trigger. nameof(LeftTrigger), nameof(LeftTriggerDeadZone), nameof(LeftTriggerAntiDeadZone), nameof(LeftTriggerLinear), // Right Thumb Virtual Buttons. nameof(RightThumbUp), nameof(RightThumbRight), nameof(RightThumbDown), nameof(RightThumbLeft), // Right Thumb Axis X nameof(RightThumbAxisX), nameof(RightThumbDeadZoneX), nameof(RightThumbAntiDeadZoneX), nameof(RightThumbLinearX), // Right Thumb Axis Y nameof(RightThumbAxisY), nameof(RightThumbDeadZoneY), nameof(RightThumbAntiDeadZoneY), nameof(RightThumbLinearY), // Axis to Button dead-zones. nameof(ButtonADeadZone), nameof(ButtonBDeadZone), nameof(ButtonBackDeadZone), nameof(ButtonStartDeadZone), nameof(ButtonXDeadZone), nameof(ButtonYDeadZone), nameof(LeftThumbButtonDeadZone), nameof(RightThumbButtonDeadZone), nameof(LeftShoulderDeadZone), nameof(RightShoulderDeadZone), nameof(DPadDownDeadZone), nameof(DPadLeftDeadZone), nameof(DPadRightDeadZone), nameof(DPadUpDeadZone), }; lock (_PropertiesLock) { if (_Properties == null) { var t = GetType(); _Properties = names.Select(x => t.GetProperty(x)).ToArray(); } } foreach (var pi in _Properties) { var value = pi.GetValue(source); pi.SetValue(this, value ?? ""); } }