Exemplo n.º 1
0
        /// <summary>
        /// Called when recording is in progress.
        /// </summary>
        /// <param name="state">Current direct input activity.</param>
        /// <returns>True if recording stopped, otherwise false.</returns>
        public bool StopRecording(CustomDiState state = null)
        {
            lock (recordingLock)
            {
                // If recording is not in progress then return false.
                if (!Recording)
                {
                    recordingSnapshot = null;
                    return(false);
                }
                // Must stop recording if null state passed i.e. probably ESC key was pressed.
                var    stop   = state == null;
                string action = null;
                var    map    = CurrentMap;
                var    code   = map.Code;
                var    box    = (ComboBox)map.Control;
                if (state != null)
                {
                    // If recording snapshot was not created yet then...
                    if (recordingSnapshot == null)
                    {
                        // Make snapshot out of the first state during recording.
                        recordingSnapshot = state;
                        return(false);
                    }
                    var actions = state == null
                                                  ? Array.Empty <string>()
                                  // Get actions by comparing initial snapshot with current state.
                                                  : Recorder.CompareTo(recordingSnapshot, state, map.Code);

                    // if recording and at least one action was recorded then...
                    if (!stop && actions.Length > 0)
                    {
                        MapType type;
                        int     index;
                        SettingsConverter.TryParseTextValue(actions[0], out type, out index);
                        // If this is Thumb Up, Left, Right, Down and axis was mapped.
                        if (SettingsConverter.ThumbDirections.Contains(code) && SettingsConverter.IsAxis(type))
                        {
                            // Make full axis.
                            type = SettingsConverter.ToFull(type);
                            var isUp =
                                code == MapCode.LeftThumbUp ||
                                code == MapCode.RightThumbUp;
                            var isLeft =
                                code == MapCode.LeftThumbLeft ||
                                code == MapCode.RightThumbLeft;
                            var isRight =
                                code == MapCode.LeftThumbRight ||
                                code == MapCode.RightThumbRight;
                            var isDown =
                                code == MapCode.LeftThumbDown ||
                                code == MapCode.RightThumbDown;
                            // Invert.
                            if (isLeft || isDown)
                            {
                                type = SettingsConverter.Invert(type);
                            }
                            var newCode     = code;
                            var isLeftThumb = SettingsConverter.LeftThumbCodes.Contains(code);
                            if (isRight || isLeft)
                            {
                                newCode = isLeftThumb
                                                                        ? MapCode.LeftThumbAxisX
                                                                        : MapCode.RightThumbAxisX;
                            }
                            if (isUp || isDown)
                            {
                                newCode = isLeftThumb
                                                                        ? MapCode.LeftThumbAxisY
                                                                        : MapCode.RightThumbAxisY;
                            }
                            // Change destination control.
                            var rMap = SettingsManager.Current.SettingsMap.First(x => x.MapTo == map.MapTo && x.Code == newCode);
                            box    = (ComboBox)rMap.Control;
                            action = SettingsConverter.ToTextValue(type, index);
                            stop   = true;
                        }
                        // If this is DPad ComboBox then...
                        else if (code == MapCode.DPad)
                        {
                            // Get first action suitable for DPad
                            Regex dPadRx     = new Regex("(POV [0-9]+)");
                            var   dPadAction = actions.FirstOrDefault(x => dPadRx.IsMatch(x));
                            if (dPadAction != null)
                            {
                                action = dPadRx.Match(dPadAction).Groups[0].Value;
                                stop   = true;
                            }
                        }
                        else
                        {
                            // Get first recorded action.
                            action = actions[0];
                            stop   = true;
                        }
                    }
                }
                // If recording must stop then...
                if (stop)
                {
                    Recording  = false;
                    CurrentMap = null;
                    // If stop was initiated before action was recorded then...
                    if (string.IsNullOrEmpty(action))
                    {
                        box.Items.Clear();
                    }
                    else
                    {
                        // If suitable action was recorded then...
                        SettingsManager.Current.SetComboBoxValue(box, action);
                        // Save setting and notify if value changed.
                        SettingsManager.Current.RaiseSettingsChanged(box);
                    }
                    //box.ForeColor = SystemColors.WindowText;
                }
                return(stop);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Read setting from INI file into windows form control.
 /// </summary>
 public void ReadSettingTo(Control control, string key, string value)
 {
     if (key == SettingName.HookMode ||
         key.EndsWith(SettingName.GamePadType) ||
         key.EndsWith(SettingName.ForceType) ||
         key.EndsWith(SettingName.LeftMotorDirection) ||
         key.EndsWith(SettingName.RightMotorDirection) ||
         key.EndsWith(SettingName.PassThroughIndex) ||
         key.EndsWith(SettingName.CombinedIndex))
     {
         var cbx = (ComboBox)control;
         for (int i = 0; i < cbx.Items.Count; i++)
         {
             if (cbx.Items[i] is KeyValuePair)
             {
                 var kv = (KeyValuePair)cbx.Items[i];
                 if (kv.Value == value)
                 {
                     cbx.SelectedIndex = i;
                     break;
                 }
             }
             else
             {
                 var kv = System.Convert.ToInt32(cbx.Items[i]);
                 if (kv.ToString() == value)
                 {
                     cbx.SelectedIndex = i;
                     break;
                 }
             }
         }
     }
     // If Di menu strip attached.
     else if (control is ComboBox)
     {
         var cbx = (ComboBox)control;
         if (control.ContextMenuStrip == null)
         {
             control.Text = value;
         }
         else
         {
             var text = SettingsConverter.ToTextValue(value);
             SetComboBoxValue(cbx, text);
         }
     }
     else if (control is TextBox)
     {
         // if setting is read-only.
         if (key == SettingName.ProductName)
         {
             return;
         }
         if (key == SettingName.ProductGuid)
         {
             return;
         }
         if (key == SettingName.InstanceGuid)
         {
             return;
         }
         if (key == SettingName.InternetDatabaseUrl && string.IsNullOrEmpty(value))
         {
             value = SettingName.DefaultInternetDatabaseUrl;
         }
         // Always override version.
         if (key == SettingName.Version)
         {
             value = SettingName.DefaultVersion;
         }
         control.Text = value;
     }
     else if (control is ListBox)
     {
         var lbx = (ListBox)control;
         lbx.Items.Clear();
         if (string.IsNullOrEmpty(value))
         {
             var folders = new List <string>();
             if (Environment.Is64BitOperatingSystem)
             {
                 var pf = Environment.GetEnvironmentVariable("ProgramW6432");
                 if (System.IO.Directory.Exists(pf))
                 {
                     folders.Add(pf);
                 }
             }
             var pf86 = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
             if (System.IO.Directory.Exists(pf86))
             {
                 folders.Add(pf86);
             }
             lbx.Items.AddRange(folders.ToArray());
         }
         else
         {
             lbx.Items.AddRange(value.Split(','));
         }
     }
     else if (control is NumericUpDown)
     {
         var     nud = (NumericUpDown)control;
         decimal n   = 0;
         decimal.TryParse(value, out n);
         if (n < nud.Minimum)
         {
             n = nud.Minimum;
         }
         if (n > nud.Maximum)
         {
             n = nud.Maximum;
         }
         nud.Value = n;
     }
     else if (control is TrackBar)
     {
         TrackBar tc = (TrackBar)control;
         int      n  = 0;
         int.TryParse(value, out n);
         // convert 256  to 100%
         if (key == SettingName.AxisToDPadDeadZone || key == SettingName.AxisToDPadOffset || key == SettingName.LeftTriggerDeadZone || key == SettingName.RightTriggerDeadZone)
         {
             if (key == SettingName.AxisToDPadDeadZone && value == "")
             {
                 n = 256;
             }
             n = System.Convert.ToInt32((float)n / 256F * 100F);
         }
         // Convert 500 to 100%
         else if (key == SettingName.LeftMotorPeriod || key == SettingName.RightMotorPeriod)
         {
             n = System.Convert.ToInt32((float)n / 500F * 100F);
         }
         // Convert 32767 to 100%
         else if (key == SettingName.LeftThumbDeadZoneX || key == SettingName.LeftThumbDeadZoneY || key == SettingName.RightThumbDeadZoneX || key == SettingName.RightThumbDeadZoneY)
         {
             n = System.Convert.ToInt32((float)n / ((float)Int16.MaxValue) * 100F);
         }
         if (n < tc.Minimum)
         {
             n = tc.Minimum;
         }
         if (n > tc.Maximum)
         {
             n = tc.Maximum;
         }
         tc.Value = n;
     }
     else if (control is CheckBox)
     {
         CheckBox tc = (CheckBox)control;
         int      n  = 0;
         int.TryParse(value, out n);
         tc.Checked = n != 0;
     }
 }
Exemplo n.º 3
0
        ///// <summary>
        ///// Load PAD settings from INI file to form.
        ///// </summary>
        ///// <param name="file">INI file name.</param>
        ///// <param name="iniSection">Source INI pad section.</param>
        ///// <param name="padIndex">Destination pad index.</param>
        //public void LoadPadSettings(string file, string iniSection, int padIndex)
        //{
        //	var ini2 = new Ini(file);
        //	var pad = string.Format("PAD{0}", padIndex + 1);
        //	var paths = SettingsMap.Select(x => x.IniPath).ToArray();
        //	foreach (string path in paths)
        //	{
        //		string section = path.Split('\\')[0];
        //		if (section != pad) continue;
        //		string key = path.Split('\\')[1];

        //		Control control = SettingsMap.FirstOrDefault(x => x.IniPath == path).Control;
        //		string dstPath = string.Format("{0}\\{1}", pad, key);
        //		control = SettingsMap.FirstOrDefault(x => x.IniPath == dstPath).Control;


        //		string v = ini2.GetValue(iniSection, key);
        //		LoadSetting(control, key, v);
        //	}
        //	loadCount++;
        //	if (ConfigLoaded != null) ConfigLoaded(this, new SettingEventArgs(ini2.File.Name, loadCount));
        //}

        /// <summary>
        /// Read setting from INI file into windows form control.
        /// </summary>
        public void LoadSetting(Control control, string key = null, string value = null)
        {
            if (key != null && (
                    key == SettingName.HookMode ||
                    key.EndsWith(SettingName.GamePadType) ||
                    key.EndsWith(SettingName.ForceType) ||
                    key.EndsWith(SettingName.LeftMotorDirection) ||
                    key.EndsWith(SettingName.RightMotorDirection) ||
                    key.EndsWith(SettingName.PassThroughIndex) ||
                    key.EndsWith(SettingName.CombinedIndex)
                    )
                )
            {
                var cbx = (ComboBox)control;
                for (int i = 0; i < cbx.Items.Count; i++)
                {
                    if (cbx.Items[i] is KeyValuePair)
                    {
                        var kv = (KeyValuePair)cbx.Items[i];
                        if (kv.Value == value)
                        {
                            cbx.SelectedIndex = i;
                            break;
                        }
                    }
                    else
                    {
                        var kv = System.Convert.ToInt32(cbx.Items[i]);
                        if (kv.ToString() == value)
                        {
                            cbx.SelectedIndex = i;
                            break;
                        }
                    }
                }
            }
            // If Di menu strip attached.
            else if (control is ComboBox)
            {
                var cbx = (ComboBox)control;
                if (control.ContextMenuStrip == null)
                {
                    control.Text = value;
                }
                else
                {
                    var text = SettingsConverter.ToTextValue(value);
                    SetComboBoxValue(cbx, text);
                }
            }
            else if (control is TextBox)
            {
                // if setting is read-only.
                if (key == SettingName.ProductName)
                {
                    return;
                }
                if (key == SettingName.ProductGuid)
                {
                    return;
                }
                if (key == SettingName.InstanceGuid)
                {
                    return;
                }
                // Always override version.
                if (key == SettingName.Version)
                {
                    value = SettingName.DefaultVersion;
                }
                control.Text = value;
            }
            else if (control is NumericUpDown)
            {
                var     nud = (NumericUpDown)control;
                decimal n   = 0;
                decimal.TryParse(value, out n);
                if (n < nud.Minimum)
                {
                    n = nud.Minimum;
                }
                if (n > nud.Maximum)
                {
                    n = nud.Maximum;
                }
                nud.Value = n;
            }
            else if (control is TrackBar)
            {
                TrackBar tc = (TrackBar)control;
                int      n  = 0;
                int.TryParse(value, out n);
                // convert 256  to 100%
                if (key == SettingName.AxisToDPadDeadZone || key == SettingName.AxisToDPadOffset || key == SettingName.LeftTriggerDeadZone || key == SettingName.RightTriggerDeadZone)
                {
                    if (key == SettingName.AxisToDPadDeadZone && value == "")
                    {
                        n = 256;
                    }
                    n = System.Convert.ToInt32((float)n / 256F * 100F);
                }
                // Convert 500 to 100%
                else if (key == SettingName.LeftMotorPeriod || key == SettingName.RightMotorPeriod)
                {
                    n = System.Convert.ToInt32((float)n / 500F * 100F);
                }
                // Convert 32767 to 100%
                else if (key == SettingName.LeftThumbDeadZoneX || key == SettingName.LeftThumbDeadZoneY || key == SettingName.RightThumbDeadZoneX || key == SettingName.RightThumbDeadZoneY)
                {
                    n = System.Convert.ToInt32((float)n / ((float)Int16.MaxValue) * 100F);
                }
                if (n < tc.Minimum)
                {
                    n = tc.Minimum;
                }
                if (n > tc.Maximum)
                {
                    n = tc.Maximum;
                }
                tc.Value = n;
            }
            else if (control is CheckBox)
            {
                CheckBox tc = (CheckBox)control;
                int      n  = 0;
                int.TryParse(value, out n);
                tc.Checked = n != 0;
            }
        }