/// <summary> /// Create a tuningOptionID from devClass and xmlInstance (jsN for joysticks, 1 for gamepad) /// </summary> /// <param name="deviceClass">Joysstick or Gamepad class name</param> /// <param name="instance">The xml instance number or 1 for gamepad</param> /// <returns>An ID or a dummy ID if the instance is not found</returns> public static string TuneOptionIDfromJsN(string deviceClass, int instance) { // only search for joysticks if (JoystickCls.IsDeviceClass(deviceClass)) { for (int i = 0; i < m_jsMap.Length; i++) { if (m_jsMap[i] == instance) { return(string.Format("{0}{1}{2}", deviceClass, ID_Delimiter, i.ToString( ))); } } // not found return return(string.Format("{0}{1}{2}", deviceClass, ID_Delimiter, -1)); // will not be found in the collection } else if (GamepadCls.IsDeviceClass(deviceClass)) { // gamepad return(string.Format("{0}{1}{2}", deviceClass, ID_Delimiter, instance)); } else if (MouseCls.IsDeviceClass(deviceClass)) { // mouse return(string.Format("{0}{1}{2}", deviceClass, ID_Delimiter, instance)); } else { return(string.Format("{0}{1}{2}", deviceClass, ID_Delimiter, instance)); } }
/// <summary> /// Query the devices if the input is disabled /// </summary> /// <param name="input">The input command</param> /// <returns>True if disabled input</returns> static public bool IsDisabledInput(string input) { bool disabledInput = false; disabledInput = DeviceCls.IsDisabledInput(input); // generic if (disabledInput) { return(disabledInput); } disabledInput = JoystickCls.IsDisabledInput(input); if (disabledInput) { return(disabledInput); } disabledInput = GamepadCls.IsDisabledInput(input); if (disabledInput) { return(disabledInput); } disabledInput = KeyboardCls.IsDisabledInput(input); if (disabledInput) { return(disabledInput); } disabledInput = MouseCls.IsDisabledInput(input); if (disabledInput) { return(disabledInput); } // others.. return(disabledInput); }
/// <summary> /// Try to derive the device class from the devInput string (mo1_, kb1_, xi1_, jsN_) /// </summary> /// <param name="devInput">The input command string dev_input format</param> /// <returns>A proper DeviceClass string</returns> static public string DeviceClassFromInput(string devInput) { string deviceClass = DeviceCls.DeviceClass; deviceClass = JoystickCls.DeviceClassFromInput(devInput); if (!DeviceCls.IsUndefined(deviceClass)) { return(deviceClass); } deviceClass = GamepadCls.DeviceClassFromInput(devInput); if (!DeviceCls.IsUndefined(deviceClass)) { return(deviceClass); } deviceClass = KeyboardCls.DeviceClassFromInput(devInput); if (!DeviceCls.IsUndefined(deviceClass)) { return(deviceClass); } deviceClass = MouseCls.DeviceClassFromInput(devInput); if (!DeviceCls.IsUndefined(deviceClass)) { return(deviceClass); } // others.. return(deviceClass); }
/// <summary> /// Format an XML -options- node from the tuning contents /// </summary> /// <returns>The XML string or an empty string</returns> public string Options_toXML() { if ((/*SensitivityUsed ||*/ ExponentUsed || InvertUsed || NonLinCurveUsed) == false) { return(""); // not used } if (DevInstanceNo < 1) { return(""); // no device to assign it to.. } string tmp = ""; // again we have to translate from internal deviceClass mouse to CIG type keyboard ... string type = m_devClass; if (MouseCls.IsDeviceClass(type)) { type = KeyboardCls.DeviceClass; } tmp += $"\t<options type=\"{type}\" instance=\"{m_devInstanceNo.ToString( )}\" Product=\"{m_deviceRef.DevName + " " + m_deviceRef.DevGUID}\">\n";// 3.5 do we need Product here ?? tmp += string.Format("\t\t<{0} ", m_option); if (InvertUsed) { tmp += string.Format("invert=\"1\" "); } /* * if ( SensitivityUsed ) { * tmp += string.Format( "sensitivity=\"{0}\" ", Sensitivity ); * } */ if (NonLinCurveUsed) { // add exp to avoid merge of things... tmp += string.Format("exponent=\"1.00\" > \n"); // CIG get to default expo 2.something if not set to 1 here tmp += string.Format("\t\t\t<nonlinearity_curve>\n"); tmp += string.Format("\t\t\t\t<point in=\"{0}\" out=\"{1}\"/>\n", m_PtsIn[0], m_PtsOut[0]); tmp += string.Format("\t\t\t\t<point in=\"{0}\" out=\"{1}\"/>\n", m_PtsIn[1], m_PtsOut[1]); tmp += string.Format("\t\t\t\t<point in=\"{0}\" out=\"{1}\"/>\n", m_PtsIn[2], m_PtsOut[2]); tmp += string.Format("\t\t\t</nonlinearity_curve>\n"); tmp += string.Format("\t\t</{0}> \n", m_option); } else if (ExponentUsed) { // only exp used tmp += string.Format("exponent=\"{0}\" /> \n", Exponent); } else { // neither exp or curve tmp += string.Format(" /> \n");// nothing... } tmp += string.Format("\t</options>\n \n"); return(tmp); }
/// <summary> /// Read an action from XML - do some sanity checks /// </summary> /// <param name="xml">the XML action fragment</param> /// <returns>True if an action was decoded</returns> public bool fromXML(XElement actionNode) { ActionName = (string)actionNode.Attribute("name"); // mandadory foreach (XElement bindingNode in actionNode.Nodes( )) { string binding = bindingNode.Name.ToString( ); string input = "", actModeName = "", multi = ""; input = (string)bindingNode.Attribute("input"); // mandadory if (string.IsNullOrEmpty(input)) { input = ""; } actModeName = (string)bindingNode.Attribute("ActivationMode"); multi = (string)bindingNode.Attribute("multiTap"); string device = (string)bindingNode.Attribute("device"); //process input = DeviceCls.fromXML(input); // move from external to internal blend if (!string.IsNullOrEmpty(device)) { // AC1 style - need to reformat mouse and keyboard according to AC2 style now if (KeyboardCls.IsDeviceClass(device)) { input = KeyboardCls.FromAC1(input); } else if (MouseCls.IsDeviceClass(device)) { input = MouseCls.FromAC1(input); } else if (GamepadCls.IsDeviceClass(device)) { input = GamepadCls.FromAC1(input); } } Device = Act.DeviceClassFromInput(input); ActivationMode actMode = null; if (!string.IsNullOrEmpty(actModeName)) { actMode = ActivationModes.Instance.ActivationModeByName(actModeName); // should be a valid ActivationMode for this action } else { actMode = new ActivationMode(ActivationMode.Default); // no specific name given, use default if (!string.IsNullOrEmpty(multi)) { actMode.MultiTap = int.Parse(multi); // modify with given multiTap } } if (binding == "rebind") { Key = Act.DevTag(Device) + ActionName; // unique id of the action ActionDevice = Act.ADevice(Device); // get the enum of the input device } AddCommand(input, actMode); }//foreach return(true); }
/// <summary> /// Extends the input to a device input if not already done /// </summary> /// <param name="input">An input</param> /// <param name="aDevice">The ActionDevice</param> /// <returns>A valid devInput (dev_input) format</returns> static public string DevInput(string input, ActionDevice aDevice) { switch (aDevice) { case ActionDevice.AD_Gamepad: return(GamepadCls.DevInput(input)); case ActionDevice.AD_Joystick: return(JoystickCls.DevInput(input)); case ActionDevice.AD_Keyboard: return(KeyboardCls.DevInput(input)); case ActionDevice.AD_Mouse: return(MouseCls.DevInput(input)); default: return(input); } }
/// <summary> /// Return the color of a device /// </summary> /// <param name="devInput">The devinput (determine JS colors)</param> /// <param name="aDevice">The ActionDevice</param> /// <returns>The device color</returns> static public System.Drawing.Color DeviceColor(string devInput) { // background is along the input ActionDevice aDevice = ADeviceFromInput(devInput); switch (aDevice) { case ActionDevice.AD_Gamepad: return(GamepadCls.XiColor( )); case ActionDevice.AD_Joystick: return(JoystickCls.JsNColor(JoystickCls.JSNum(devInput)));// need to know which JS case ActionDevice.AD_Keyboard: return(KeyboardCls.KbdColor( )); case ActionDevice.AD_Mouse: return(MouseCls.MouseColor( )); default: return(MyColors.UnassignedColor); } }