@@ -19,8 +19,6 @@ namespace NintendoSwitch{
1919KeyMapTableRow::KeyMapTableRow (EditableTableOption& parent_table)
2020 : EditableTableRow(parent_table)
2121 , label(false , LockMode::UNLOCK_WHILE_RUNNING, " " , " " )
22- // , qt_key(LockMode::UNLOCK_WHILE_RUNNING, 0)
23- // , key(false, LockMode::READ_ONLY, "", "")
2422 , key(LockMode::UNLOCK_WHILE_RUNNING)
2523 , buttons(LockMode::UNLOCK_WHILE_RUNNING, 0 , 0 , ((uint16_t )1 << 14 ) - 1 )
2624 , dpad_x(LockMode::UNLOCK_WHILE_RUNNING, 0 , -1 , 1 )
@@ -31,7 +29,6 @@ KeyMapTableRow::KeyMapTableRow(EditableTableOption& parent_table)
3129 , right_stick_y(LockMode::UNLOCK_WHILE_RUNNING, 0 , -1 , 1 )
3230{
3331 add_option (label, " Description" );
34- // add_option(qt_key, "Qt::Key");
3532 add_option (key, " Key" );
3633 add_option (buttons, " Button Bit-Field" );
3734 add_option (dpad_x, " Dpad x" );
@@ -40,21 +37,18 @@ KeyMapTableRow::KeyMapTableRow(EditableTableOption& parent_table)
4037 add_option (left_stick_y, " Left-Stick y" );
4138 add_option (right_stick_x, " Right-Stick x" );
4239 add_option (right_stick_y, " Right-Stick y" );
43- // qt_key.add_listener(*this);
44- }
45- KeyMapTableRow::~KeyMapTableRow (){
46- // qt_key.remove_listener(*this);
40+ set_advanced_mode (static_cast <KeyboardMappingTable&>(parent_table).advanced_mode ());
4741}
4842KeyMapTableRow::KeyMapTableRow (
4943 EditableTableOption& parent_table,
44+ bool advanced_mode,
5045 std::string description,
5146 Qt::Key key,
5247 const ControllerDeltas& deltas
5348)
5449 : KeyMapTableRow(parent_table)
5550{
5651 label.set (std::move (description));
57- // qt_key.set(key);
5852 this ->key .set (key);
5953 buttons.set (deltas.buttons );
6054 dpad_x.set (deltas.dpad_x );
@@ -63,11 +57,11 @@ KeyMapTableRow::KeyMapTableRow(
6357 left_stick_y.set (deltas.left_y );
6458 right_stick_x.set (deltas.right_x );
6559 right_stick_y.set (deltas.right_y );
60+ set_advanced_mode (advanced_mode);
6661}
6762std::unique_ptr<EditableTableRow> KeyMapTableRow::clone () const {
6863 std::unique_ptr<KeyMapTableRow> ret (new KeyMapTableRow (parent ()));
6964 ret->label .set (label);
70- // ret->qt_key.set(qt_key);
7165 ret->key .set ((uint32_t )key);
7266 ret->buttons .set (buttons);
7367 ret->dpad_x .set (dpad_x);
@@ -76,6 +70,7 @@ std::unique_ptr<EditableTableRow> KeyMapTableRow::clone() const{
7670 ret->left_stick_y .set (left_stick_y);
7771 ret->right_stick_x .set (right_stick_x);
7872 ret->right_stick_y .set (right_stick_y);
73+ ret->set_advanced_mode (m_advanced_mode.load (std::memory_order_relaxed));
7974 return ret;
8075}
8176ControllerDeltas KeyMapTableRow::snapshot () const {
@@ -89,36 +84,41 @@ ControllerDeltas KeyMapTableRow::snapshot() const{
8984 .right_y = right_stick_y,
9085 };
9186}
92- // void KeyMapTableRow::value_changed(void* object){
93- // QKeySequence seq((Qt::Key)qt_key.current_value());
94- // key.set(seq.toString().toStdString());
95- // }
87+ void KeyMapTableRow::set_advanced_mode (bool enabled){
88+ m_advanced_mode.store (enabled, std::memory_order_relaxed);
89+ if (enabled){
90+ label.set_locked (false );
91+ buttons.set_visibility (ConfigOptionState::ENABLED);
92+ dpad_x.set_visibility (ConfigOptionState::ENABLED);
93+ dpad_y.set_visibility (ConfigOptionState::ENABLED);
94+ left_stick_x.set_visibility (ConfigOptionState::ENABLED);
95+ left_stick_y.set_visibility (ConfigOptionState::ENABLED);
96+ right_stick_x.set_visibility (ConfigOptionState::ENABLED);
97+ right_stick_y.set_visibility (ConfigOptionState::ENABLED);
98+ }else {
99+ label.set_locked (true );
100+ buttons.set_visibility (ConfigOptionState::DISABLED);
101+ dpad_x.set_visibility (ConfigOptionState::DISABLED);
102+ dpad_y.set_visibility (ConfigOptionState::DISABLED);
103+ left_stick_x.set_visibility (ConfigOptionState::DISABLED);
104+ left_stick_y.set_visibility (ConfigOptionState::DISABLED);
105+ right_stick_x.set_visibility (ConfigOptionState::DISABLED);
106+ right_stick_y.set_visibility (ConfigOptionState::DISABLED);
107+ }
108+ }
96109
97110
98111
99112
100113
101114KeyboardMappingTable::KeyboardMappingTable ()
102115 : EditableTableOption_t<KeyMapTableRow>(
103- " The following table is the mapping of keyboard keys to Switch controller presses. "
104- " If you wish to remap a key, click on the cell in the \" Key\" column and press the desired key. "
105- " You do not need to edit any of the other columns.<br><br>"
106- " <font color=\" orange\" >Note for keys that change behavior when combined with "
107- " SHIFT or CTRL, you should include all of those combinations as well. "
108- " For example, the default mapping for the Y button is both '/' and '?' "
109- " because they are treated as different keys depending on whether SHIFT "
110- " is held down. Letters are exempt from this as both lower and upper case "
111- " letters are considered the same.</font>"
112- " <br><br>"
113- " Advanced users are free to edit the rest of the table. You can create "
114- " new mappings or mappings that result in multiple buttons. "
115- " For example, there is a special mapping for pressing A + R "
116- " simultaneously that is useful for CFW users who are remotely "
117- " controlling the program over Team Viewer." ,
116+ " " ,
118117 LockMode::UNLOCK_WHILE_RUNNING,
119118 true ,
120119 make_defaults ()
121120 )
121+ , m_advanced_mode(false )
122122{}
123123std::vector<std::string> KeyboardMappingTable::make_header () const {
124124 return std::vector<std::string>{
@@ -133,6 +133,12 @@ std::vector<std::string> KeyboardMappingTable::make_header() const{
133133 " Right-Stick y" ,
134134 };
135135}
136+ void KeyboardMappingTable::set_advanced_mode (bool enabled){
137+ m_advanced_mode.store (enabled, std::memory_order_relaxed);
138+ run_on_all_rows ([enabled](KeyMapTableRow& row){
139+ row.set_advanced_mode (enabled);
140+ });
141+ }
136142
137143
138144std::unique_ptr<EditableTableRow> KeyboardMappingTable::make_mapping (
@@ -142,6 +148,7 @@ std::unique_ptr<EditableTableRow> KeyboardMappingTable::make_mapping(
142148){
143149 return std::make_unique<KeyMapTableRow>(
144150 *this ,
151+ m_advanced_mode.load (std::memory_order_relaxed),
145152 std::move (description),
146153 key,
147154 deltas
@@ -208,6 +215,56 @@ std::vector<std::unique_ptr<EditableTableRow>> KeyboardMappingTable::make_defaul
208215
209216
210217
218+ KeyboardMappingOption::~KeyboardMappingOption (){
219+ ADVANCED_MODE.remove_listener (*this );
220+ }
221+ KeyboardMappingOption::KeyboardMappingOption ()
222+ : BatchOption(LockMode::UNLOCK_WHILE_RUNNING)
223+ , DESCRIPTION(
224+ " The following table is the mapping of keyboard keys to Switch controller presses. "
225+ " If you wish to remap a key, click on the cell in the \" Key\" column and press the desired key. "
226+ " You do not need to edit any of the other columns.<br><br>"
227+ " <font color=\" orange\" >Note for keys that change behavior when combined with "
228+ " SHIFT or CTRL, you should include all of those combinations as well. "
229+ " For example, the default mapping for the Y button is both '/' and '?' "
230+ " because they are treated as different keys depending on whether SHIFT "
231+ " is held down. Letters are exempt from this as both lower and upper case "
232+ " letters are considered the same.</font>"
233+ " <br><br>"
234+ " Advanced users are free to edit the rest of the table. You can create "
235+ " new mappings or mappings that result in multiple buttons. "
236+ " For example, there is a special mapping for pressing A + R "
237+ " simultaneously that is useful for CFW users who are remotely "
238+ " controlling the program over Team Viewer."
239+ )
240+ , ADVANCED_MODE(
241+ " Unlock entire table (Advanced Mode):" ,
242+ LockMode::UNLOCK_WHILE_RUNNING,
243+ false
244+ )
245+ {
246+ PA_ADD_STATIC (DESCRIPTION);
247+ PA_ADD_OPTION (ADVANCED_MODE);
248+ PA_ADD_OPTION (TABLE);
249+ ADVANCED_MODE.add_listener (*this );
250+ }
251+
252+
253+ void KeyboardMappingOption::load_json (const JsonValue& json){
254+ BatchOption::load_json (json);
255+ KeyboardMappingOption::value_changed (this );
256+ }
257+ void KeyboardMappingOption::value_changed (void * object){
258+ TABLE.set_advanced_mode (ADVANCED_MODE);
259+ }
260+
261+
262+
263+
264+
265+
266+
267+
211268
212269
213270
0 commit comments