Skip to content

Commit 0377928

Browse files
authored
TurboMacro: add "Action" column that summarizes a given row's action. (#892)
* TurboMacro: add "Action" column that summarizes a given row's action. * re-arrange columns in table
1 parent 0b09481 commit 0377928

File tree

6 files changed

+171
-4
lines changed

6 files changed

+171
-4
lines changed

SerialPrograms/Source/Controllers/ControllerStateTable.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "ControllerTypeStrings.h"
1212
#include "ControllerStateTable.h"
1313

14+
#include "NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h"
1415
#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProControllerTable.h"
1516
#include "NintendoSwitch/Controllers/Joycon/NintendoSwitch_JoyconTable.h"
1617

@@ -367,6 +368,46 @@ EnumDropdownDatabase<ControllerClass> ControllerCommandTables::make_database(
367368

368369

369370

371+
std::string get_joystick_direction(uint8_t x, uint8_t y){
372+
std::string direction = "";
373+
if (x > NintendoSwitch::STICK_CENTER){
374+
if (y > NintendoSwitch::STICK_CENTER){
375+
// right-down
376+
direction = "\u2198";
377+
}else if (y == NintendoSwitch::STICK_CENTER){
378+
// right
379+
direction = "\u2192";
380+
}else{ // y < STICK_CENTER
381+
// right-up
382+
direction = "\u2197";
383+
}
384+
}else if (x == NintendoSwitch::STICK_CENTER){
385+
if (y > NintendoSwitch::STICK_CENTER){
386+
// down
387+
direction = "\u2193";
388+
}else if (y == NintendoSwitch::STICK_CENTER){
389+
// neutral
390+
direction = "neutral";
391+
}else{ // y < STICK_CENTER
392+
// up
393+
direction = "\u2191";
394+
}
395+
396+
}else { // x < STICK_CENTER
397+
if (y > NintendoSwitch::STICK_CENTER){
398+
// left-down
399+
direction = "\u2199";
400+
}else if (y == NintendoSwitch::STICK_CENTER){
401+
// left
402+
direction = "\u2190";
403+
}else{ // y < STICK_CENTER
404+
// left-up
405+
direction = "\u2196";
406+
}
407+
}
408+
409+
return direction;
410+
}
370411

371412

372413

SerialPrograms/Source/Controllers/ControllerStateTable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class ControllerCommandTables : public GroupOption, public ConfigOption::Listene
122122
};
123123

124124

125-
125+
std::string get_joystick_direction(uint8_t x, uint8_t y);
126126

127127

128128

SerialPrograms/Source/NintendoSwitch/Controllers/Joycon/NintendoSwitch_JoyconTable.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void register_joycon_tables(){
5353
ControllerCommandTable::make_row<JoyconStateRow>,
5454
{
5555
"Milliseconds",
56+
"Action",
5657
"Buttons",
5758
"Joystick (X)",
5859
"Joystick (Y)",
@@ -63,6 +64,7 @@ void register_joycon_tables(){
6364
ControllerCommandTable::make_row<JoyconStateRow>,
6465
{
6566
"Milliseconds",
67+
"Action",
6668
"Buttons",
6769
"Joystick (X)",
6870
"Joystick (Y)",
@@ -71,6 +73,12 @@ void register_joycon_tables(){
7173
}
7274

7375

76+
JoyconStateRow::~JoyconStateRow(){
77+
DURATION.remove_listener(*this);
78+
BUTTONS.remove_listener(*this);
79+
JOYSTICK_X.remove_listener(*this);
80+
JOYSTICK_Y.remove_listener(*this);
81+
}
7482

7583

7684

@@ -87,11 +95,19 @@ JoyconStateRow::JoyconStateRow(EditableTableOption& parent_table)
8795
)
8896
, JOYSTICK_X(LockMode::UNLOCK_WHILE_RUNNING, 128, 0, 255)
8997
, JOYSTICK_Y(LockMode::UNLOCK_WHILE_RUNNING, 128, 0, 255)
98+
, ACTION(false, LockMode::UNLOCK_WHILE_RUNNING, "", "")
9099
{
91100
PA_ADD_OPTION(DURATION);
101+
PA_ADD_OPTION(ACTION);
92102
PA_ADD_OPTION(BUTTONS);
93103
PA_ADD_OPTION(JOYSTICK_X);
94104
PA_ADD_OPTION(JOYSTICK_Y);
105+
106+
JoyconStateRow::on_config_value_changed(this);
107+
DURATION.add_listener(*this);
108+
BUTTONS.add_listener(*this);
109+
JOYSTICK_X.add_listener(*this);
110+
JOYSTICK_Y.add_listener(*this);
95111
}
96112

97113
std::unique_ptr<EditableTableRow> JoyconStateRow::clone() const{
@@ -145,7 +161,37 @@ std::unique_ptr<ControllerState> JoyconStateRow::get_state(Milliseconds& duratio
145161

146162

147163

164+
void JoyconStateRow::on_config_value_changed(void* object){
165+
JoyconState state;
166+
get_state(state);
167+
168+
ACTION.set(get_controller_action(state));
169+
}
170+
171+
172+
173+
std::string get_controller_action(JoyconState& state){
174+
std::string action = "";
148175

176+
if (state.buttons != BUTTON_NONE){
177+
action += "Button";
178+
}
179+
180+
if (state.joystick_x != STICK_CENTER || state.joystick_y != STICK_CENTER){
181+
if (action != ""){
182+
action += ", ";
183+
}
184+
action += "Joystick";
185+
action += " " + get_joystick_direction(state.joystick_x, state.joystick_y);
186+
187+
}
188+
189+
if (action == ""){
190+
return "Wait";
191+
}
192+
193+
return action;
194+
}
149195

150196

151197

SerialPrograms/Source/NintendoSwitch/Controllers/Joycon/NintendoSwitch_JoyconTable.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "Common/Cpp/Options/SimpleIntegerOption.h"
1111
#include "Common/Cpp/Options/TimeDurationOption.h"
1212
#include "Common/Cpp/Options/CheckboxDropdownOption.h"
13+
#include "Common/Cpp/Options/StringOption.h"
1314
#include "Controllers/ControllerStateTable.h"
1415
#include "NintendoSwitch_JoyconState.h"
1516

@@ -19,8 +20,9 @@ namespace NintendoSwitch{
1920

2021

2122

22-
class JoyconStateRow : public ControllerStateRow{
23+
class JoyconStateRow : public ControllerStateRow, public ConfigOption::Listener{
2324
public:
25+
~JoyconStateRow();
2426
JoyconStateRow(EditableTableOption& parent_table);
2527

2628
virtual std::unique_ptr<EditableTableRow> clone() const override;
@@ -31,16 +33,23 @@ class JoyconStateRow : public ControllerStateRow{
3133
void get_state(JoyconState& state) const;
3234
virtual std::unique_ptr<ControllerState> get_state(Milliseconds& duration) const override;
3335

36+
private:
37+
virtual void on_config_value_changed(void* object) override;
38+
39+
3440
private:
3541
MillisecondsCell DURATION;
3642
CheckboxDropdownCell<Button> BUTTONS;
3743
SimpleIntegerCell<uint8_t> JOYSTICK_X;
3844
SimpleIntegerCell<uint8_t> JOYSTICK_Y;
45+
StringCell ACTION;
3946
};
4047

4148

4249
void register_joycon_tables();
4350

51+
std::string get_controller_action(JoyconState& state);
52+
4453

4554

4655
}

SerialPrograms/Source/NintendoSwitch/Controllers/Procon/NintendoSwitch_ProControllerTable.cpp

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ void register_procon_tables(){
6060
ControllerCommandTable::make_row<ProControllerStateRow>,
6161
{
6262
"Milliseconds",
63+
"Action",
6364
"Buttons",
6465
"Dpad",
6566
"Left JS (X)",
@@ -70,7 +71,15 @@ void register_procon_tables(){
7071
);
7172
}
7273

73-
74+
ProControllerStateRow::~ProControllerStateRow(){
75+
DURATION.remove_listener(*this);
76+
BUTTONS.remove_listener(*this);
77+
DPAD.remove_listener(*this);
78+
LEFT_JOYSTICK_X.remove_listener(*this);
79+
LEFT_JOYSTICK_Y.remove_listener(*this);
80+
RIGHT_JOYSTICK_X.remove_listener(*this);
81+
RIGHT_JOYSTICK_Y.remove_listener(*this);
82+
}
7483

7584
ProControllerStateRow::ProControllerStateRow(EditableTableOption& parent_table)
7685
: ControllerStateRow(parent_table)
@@ -90,14 +99,27 @@ ProControllerStateRow::ProControllerStateRow(EditableTableOption& parent_table)
9099
, LEFT_JOYSTICK_Y(LockMode::UNLOCK_WHILE_RUNNING, 128, 0, 255)
91100
, RIGHT_JOYSTICK_X(LockMode::UNLOCK_WHILE_RUNNING, 128, 0, 255)
92101
, RIGHT_JOYSTICK_Y(LockMode::UNLOCK_WHILE_RUNNING, 128, 0, 255)
102+
, ACTION(false, LockMode::UNLOCK_WHILE_RUNNING, "", "")
93103
{
94104
PA_ADD_OPTION(DURATION);
105+
PA_ADD_OPTION(ACTION);
95106
PA_ADD_OPTION(BUTTONS);
96107
PA_ADD_OPTION(DPAD);
97108
PA_ADD_OPTION(LEFT_JOYSTICK_X);
98109
PA_ADD_OPTION(LEFT_JOYSTICK_Y);
99110
PA_ADD_OPTION(RIGHT_JOYSTICK_X);
100111
PA_ADD_OPTION(RIGHT_JOYSTICK_Y);
112+
113+
ProControllerStateRow::on_config_value_changed(this);
114+
DURATION.add_listener(*this);
115+
BUTTONS.add_listener(*this);
116+
DPAD.add_listener(*this);
117+
LEFT_JOYSTICK_X.add_listener(*this);
118+
LEFT_JOYSTICK_Y.add_listener(*this);
119+
RIGHT_JOYSTICK_X.add_listener(*this);
120+
RIGHT_JOYSTICK_Y.add_listener(*this);
121+
122+
// ACTION.set_visibility(ConfigOptionState::DISABLED);
101123
}
102124

103125
std::unique_ptr<EditableTableRow> ProControllerStateRow::clone() const{
@@ -158,6 +180,48 @@ std::unique_ptr<ControllerState> ProControllerStateRow::get_state(Milliseconds&
158180
return ret;
159181
}
160182

183+
void ProControllerStateRow::on_config_value_changed(void* object){
184+
ProControllerState state;
185+
get_state(state);
186+
187+
ACTION.set(get_controller_action(state));
188+
}
189+
190+
191+
std::string get_controller_action(ProControllerState& state){
192+
std::string action = "";
193+
194+
if (state.buttons != BUTTON_NONE){
195+
action += "Button";
196+
}
197+
if (state.dpad != DPAD_NONE){
198+
if (action != ""){
199+
action += ", ";
200+
}
201+
action += "Dpad";
202+
}
203+
if (state.left_x != STICK_CENTER || state.left_y != STICK_CENTER){
204+
if (action != ""){
205+
action += ", ";
206+
}
207+
action += "L-stick";
208+
action += " " + get_joystick_direction(state.left_x, state.left_y);
209+
210+
}
211+
if (state.right_x != STICK_CENTER || state.right_y != STICK_CENTER){
212+
if (action != ""){
213+
action += ", ";
214+
}
215+
action += "R-stick";
216+
action += " " + get_joystick_direction(state.right_x, state.right_y);
217+
}
218+
219+
if (action == ""){
220+
return "Wait";
221+
}
222+
223+
return action;
224+
}
161225

162226

163227

SerialPrograms/Source/NintendoSwitch/Controllers/Procon/NintendoSwitch_ProControllerTable.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "Common/Cpp/Options/EnumDropdownOption.h"
1212
#include "Common/Cpp/Options/TimeDurationOption.h"
1313
#include "Common/Cpp/Options/CheckboxDropdownOption.h"
14+
#include "Common/Cpp/Options/StringOption.h"
1415
#include "Controllers/ControllerStateTable.h"
1516
#include "NintendoSwitch_ProControllerState.h"
1617

@@ -19,8 +20,9 @@ namespace NintendoSwitch{
1920

2021

2122

22-
class ProControllerStateRow : public ControllerStateRow{
23+
class ProControllerStateRow : public ControllerStateRow, public ConfigOption::Listener{
2324
public:
25+
~ProControllerStateRow();
2426
ProControllerStateRow(EditableTableOption& parent_table);
2527

2628
virtual std::unique_ptr<EditableTableRow> clone() const override;
@@ -31,6 +33,9 @@ class ProControllerStateRow : public ControllerStateRow{
3133
void get_state(ProControllerState& state) const;
3234
virtual std::unique_ptr<ControllerState> get_state(Milliseconds& duration) const override;
3335

36+
private:
37+
virtual void on_config_value_changed(void* object) override;
38+
3439

3540
private:
3641
MillisecondsCell DURATION;
@@ -40,11 +45,13 @@ class ProControllerStateRow : public ControllerStateRow{
4045
SimpleIntegerCell<uint8_t> LEFT_JOYSTICK_Y;
4146
SimpleIntegerCell<uint8_t> RIGHT_JOYSTICK_X;
4247
SimpleIntegerCell<uint8_t> RIGHT_JOYSTICK_Y;
48+
StringCell ACTION;
4349
};
4450

4551

4652
void register_procon_tables();
4753

54+
std::string get_controller_action(ProControllerState& state);
4855

4956

5057
}

0 commit comments

Comments
 (0)