Skip to content

Commit 89285dc

Browse files
committed
Disable the right side of the keyboard mapping table by default.
1 parent 77dfb5b commit 89285dc

File tree

4 files changed

+118
-31
lines changed

4 files changed

+118
-31
lines changed

SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_VirtualController.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ VirtualController::VirtualController(
3939
, m_last_known_state(ProgramState::STOPPED)
4040
, m_stop(false)
4141
{
42-
std::vector<std::shared_ptr<EditableTableRow>> mapping = ConsoleSettings::instance().KEYBOARD_MAPPINGS.current_refs();
42+
std::vector<std::shared_ptr<EditableTableRow>> mapping =
43+
ConsoleSettings::instance().KEYBOARD_MAPPINGS.TABLE.current_refs();
4344
for (const auto& deltas : mapping){
4445
const KeyMapTableRow& row = static_cast<const KeyMapTableRow&>(*deltas);
4546
m_mapping[(Qt::Key)(uint32_t)row.key] += row.snapshot();

SerialPrograms/Source/NintendoSwitch/NintendoSwitch_KeyboardMapping.cpp

Lines changed: 85 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ namespace NintendoSwitch{
1919
KeyMapTableRow::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
}
4842
KeyMapTableRow::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
}
6762
std::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
}
8176
ControllerDeltas 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

101114
KeyboardMappingTable::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
{}
123123
std::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

138144
std::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

SerialPrograms/Source/NintendoSwitch/NintendoSwitch_KeyboardMapping.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#define PokemonAutomation_NintendoSwitch_KeyboardMapping_H
99

1010
#include <Qt>
11+
#include "Common/Cpp/Options/BatchOption.h"
12+
#include "Common/Cpp/Options/StaticTextOption.h"
13+
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
1114
#include "Common/Cpp/Options/SimpleIntegerOption.h"
1215
#include "Common/Cpp/Options/StringOption.h"
1316
#include "Common/Cpp/Options/EditableTableOption.h"
@@ -23,19 +26,24 @@ struct ControllerDeltas;
2326

2427
class KeyMapTableRow : public EditableTableRow{
2528
public:
26-
~KeyMapTableRow();
2729
KeyMapTableRow(EditableTableOption& parent_table);
2830
KeyMapTableRow(
2931
EditableTableOption& parent_table,
32+
bool advanced_mode,
3033
std::string description,
3134
Qt::Key key,
3235
const ControllerDeltas& deltas
3336
);
3437
virtual std::unique_ptr<EditableTableRow> clone() const override;
3538
ControllerDeltas snapshot() const;
3639

40+
void set_advanced_mode(bool enabled);
41+
3742
// virtual void value_changed(void* object) override;
3843

44+
private:
45+
std::atomic<bool> m_advanced_mode;
46+
3947
public:
4048
StringCell label;
4149
// SimpleIntegerCell<uint32_t> qt_key;
@@ -55,15 +63,36 @@ class KeyboardMappingTable : public EditableTableOption_t<KeyMapTableRow>{
5563
KeyboardMappingTable();
5664
virtual std::vector<std::string> make_header() const override;
5765

66+
bool advanced_mode() const{ return m_advanced_mode.load(std::memory_order_relaxed); }
67+
void set_advanced_mode(bool enabled);
68+
5869
std::unique_ptr<EditableTableRow> make_mapping(
5970
std::string description,
6071
Qt::Key key,
6172
const ControllerDeltas& deltas
6273
);
6374
std::vector<std::unique_ptr<EditableTableRow>> make_defaults();
75+
76+
private:
77+
std::atomic<bool> m_advanced_mode;
6478
};
6579

6680

81+
class KeyboardMappingOption : public BatchOption, private ConfigOption::Listener{
82+
public:
83+
~KeyboardMappingOption();
84+
KeyboardMappingOption();
85+
86+
private:
87+
virtual void load_json(const JsonValue& json) override;
88+
virtual void value_changed(void* object) override;
89+
90+
public:
91+
StaticTextOption DESCRIPTION;
92+
BooleanCheckBoxOption ADVANCED_MODE;
93+
KeyboardMappingTable TABLE;
94+
};
95+
6796

6897

6998
}

SerialPrograms/Source/NintendoSwitch/NintendoSwitch_Settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ConsoleSettings : public BatchOption{
3636
BooleanCheckBoxOption TOLERATE_SYSTEM_UPDATE_MENU_SLOW;
3737

3838
SectionDividerOption KEYBOARD_SECTION;
39-
KeyboardMappingTable KEYBOARD_MAPPINGS;
39+
KeyboardMappingOption KEYBOARD_MAPPINGS;
4040

4141
};
4242

0 commit comments

Comments
 (0)