• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

luttje / Key2Joy / 6602669847

22 Oct 2023 08:23AM UTC coverage: 44.094% (-8.4%) from 52.519%
6602669847

push

github

web-flow
Add XInput in preparation for gamepad triggers + add xmldoc (#50)

* Add XInput in preparation for gamepad triggers + add xmldoc

* add parent-child relation between mapped options

* add remove child mappings option + remove debug context menu

* x86 > AnyCPU (gives more sensible errors in WinForms Designer) - Fixed Designer failing on MappingForm

* Fix polling gamepad

* Add gamepad input trigger and config control + Fix mapping list not updating correctly

* remove broken and quite useless test

* update readme with warning regarding #46 + update readme special thanks

* add warning on same gamepad id trigger and action

* attempt to give github actions more time before timeout (tests sometimes fail)

* use current default mapping profile from app (so we dont have to copy it to tests everytime manually)

* Add gamepad button trigger

* Add multi-property edit mode

* Show physical gamepad connection warning

* give even more time for tests so they dont fail

* Block arming mappings if simulated gamepad index collides with physical gamepad

* Cleanup + add GamePad Trigger Trigger

* Fix combined trigger remove not working

* Separate stick action and allow custom scaling

* improve stick feeling

* fix parent picker

* update default mappings

* add trigger and try work out conflicts between physical and simulated devices (no luck yet)

* Fix simulated gamepad recognized as physical

* Show gamepad devices in UI

* fix mapping form + add more multi-edit type support

* make reverse mapping tool more useful

* easily setup/update reverse mappings while creating/updating a mapping

* update readme screenshots + prefer 'Arm' terminology for enabling profile

* support more nullable types in mapping profile

* simplify groups

* add configurable grouping

* prevent wonky sorting across groups

* Add easy switch group option

* Fix being able to create corrupt profile

* fail loading ... (continued)

762 of 2383 branches covered (0.0%)

Branch coverage included in aggregate %.

3060 of 3060 new or added lines in 106 files covered. (100.0%)

3897 of 8183 relevant lines covered (47.62%)

12635.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/Key2Joy.Gui/ConfigForm.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Reflection;
4
using System.Windows.Forms;
5
using CommonServiceLocator;
6
using Key2Joy.Config;
7

8
namespace Key2Joy.Gui;
9

10
public partial class ConfigForm : Form
11
{
12
    private readonly ConfigState configState;
13

14
    public ConfigForm()
×
15
    {
16
        this.configState = ServiceLocator.Current
×
17
            .GetInstance<IConfigManager>()
×
18
            .GetConfigState();
×
19

20
        this.InitializeComponent();
×
21

22
        var configs = ConfigControlAttribute.GetAllProperties(typeof(ConfigState), new AttributeProvider());
×
23

24
        foreach (var kvp in configs)
×
25
        {
26
            var property = kvp.Key;
×
27
            var attribute = kvp.Value;
×
28

29
            Panel controlParent = new();
×
30
            var value = property.GetValue(this.configState);
×
31
            var control = this.MakeControl(attribute, value, controlParent);
×
32
            control.Tag = kvp;
×
33
            control.Dock = DockStyle.Bottom;
×
34

35
            controlParent.AutoSize = true;
×
36
            controlParent.Padding = new Padding(10, 10, 10, 0);
×
37
            controlParent.Controls.Add(control);
×
38

39
            this.pnlConfigurations.Controls.Add(controlParent);
×
40
            controlParent.Dock = DockStyle.Bottom;
×
41
        }
42

43
        this.PerformLayout();
×
44
    }
×
45

46
    private void BtnSave_Click(object sender, EventArgs e)
47
    {
48
        foreach (Panel parents in this.pnlConfigurations.Controls)
×
49
        {
50
            foreach (Control control in parents.Controls)
×
51
            {
52
                if (control.Tag == null)
×
53
                {
54
                    continue;
55
                }
56

57
                var kvp = (KeyValuePair<PropertyInfo, ConfigControlAttribute>)control.Tag;
×
58
                var property = kvp.Key;
×
59
                var attribute = kvp.Value;
×
60
                var value = this.GetControlValue(attribute, control);
×
61

62
                value = Convert.ChangeType(value, property.PropertyType);
×
63

64
                property.SetValue(this.configState, value);
×
65
            }
66
        }
67

68
        MessageBox.Show("Configurations successfully saved!", "Configurations saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
×
69
        this.Close();
×
70
    }
×
71

72
    private Control MakeControl(ConfigControlAttribute attribute, object value, Panel controlParent)
73
    {
74
        void CreateLabel()
75
        {
76
            Label label = new()
×
77
            {
×
78
                AutoSize = true,
×
79
                Dock = DockStyle.Bottom,
×
80
                Text = $"{attribute.Text}: "
×
81
            };
×
82
            controlParent.Controls.Add(label);
×
83
        }
×
84

85
        switch (attribute)
86
        {
87
            case BooleanConfigControlAttribute booleanConfigControlAttribute:
88
            {
89
                CheckBox control = new()
×
90
                {
×
91
                    Text = booleanConfigControlAttribute.Text,
×
92
                    Checked = (bool)value
×
93
                };
×
94

95
                return control;
×
96
            }
97
            case NumericConfigControlAttribute numericConfigControlAttribute:
98
            {
99
                CreateLabel();
×
100
                NumericUpDown control = new()
×
101
                {
×
102
                    Minimum = (decimal)numericConfigControlAttribute.Minimum,
×
103
                    Maximum = (decimal)numericConfigControlAttribute.Maximum,
×
104
                    Value = (decimal)Convert.ChangeType(value, typeof(decimal))
×
105
                };
×
106

107
                return control;
×
108
            }
109
            case TextConfigControlAttribute textConfigControlAttribute:
110
            {
111
                CreateLabel();
×
112
                TextBox control = new()
×
113
                {
×
114
                    Text = value.ToString(),
×
115
                    MaxLength = textConfigControlAttribute.MaxLength
×
116
                };
×
117

118
                return control;
×
119
            }
120
            case EnumConfigControlAttribute enumConfigControlAttribute:
121
            {
122
                CreateLabel();
×
123
                var enumValues = Enum.GetValues(enumConfigControlAttribute.EnumType);
×
124
                var selected = Enum.Parse(enumConfigControlAttribute.EnumType, value.ToString());
×
125
                ComboBox control = new()
×
126
                {
×
127
                    DropDownStyle = ComboBoxStyle.DropDownList,
×
128
                };
×
129

130
                foreach (var enumValue in enumValues)
×
131
                {
132
                    control.Items.Add(enumValue);
×
133
                }
134

135
                control.SelectedIndex = Array.IndexOf(enumValues, selected);
×
136

137
                return control;
×
138
            }
139

140
            default:
141
                break;
142
        }
143

144
        throw new NotImplementedException("ConfigControlAttribute type not implemented: " + attribute.GetType().Name);
×
145
    }
146

147
    private object GetControlValue(ConfigControlAttribute attribute, Control control)
148
    {
149
        switch (attribute)
150
        {
151
            case BooleanConfigControlAttribute:
152
            {
153
                var checkbox = (CheckBox)control;
×
154
                return checkbox.Checked;
×
155
            }
156
            case NumericConfigControlAttribute:
157
            {
158
                var numeric = (NumericUpDown)control;
×
159
                return numeric.Value;
×
160
            }
161
            case TextConfigControlAttribute:
162
            {
163
                var textbox = (TextBox)control;
×
164
                return textbox.Text;
×
165
            }
166
            case EnumConfigControlAttribute:
167
            {
168
                var combobox = (ComboBox)control;
×
169
                return combobox.SelectedItem;
×
170
            }
171

172
            default:
173
                break;
174
        }
175

176
        throw new NotImplementedException("ConfigControlAttribute type not implemented: " + attribute.GetType().Name);
×
177
    }
178
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc