Add optional button combo to change screen mode

This commit is contained in:
Maschell 2024-05-05 18:26:17 +02:00
parent 835b89e8c0
commit 11dd5cde0a
7 changed files with 97 additions and 34 deletions

View File

@ -35,6 +35,10 @@ Via the plugin config menu (press L, DPAD Down and Minus on the GamePad, Pro Con
- Determines if the screen can be swapped with a button combo.
- Swap screen: (Default is the "TV" button)
- Button combo to swap the TV and GamePad screen.
- Enable swap screen button combo: (Default is false)
- Determines if the screen can be changed with a button combo.
- Change screen: (Default is "right stick button"/R3)
- Button combo to change screen mode.
- Enable change audio mode button combo: (Default is false)
- Determines if the audio mode can be changed via a button combo.
- Change audio: (Default is "left stick button"/L3)

View File

@ -89,6 +89,22 @@ DECL_FUNCTION(void, GX2CopyColorBufferToScanBuffer, GX2ColorBuffer *colorBuffer,
real_GX2CopyColorBufferToScanBuffer(colorBuffer, scan_target);
}
const char *screenModeToStr(SwipSwapScreenMode mode) {
switch (mode) {
case SCREEN_MODE_NONE:
return "Screen mode: Normal";
case SCREEN_MODE_SWAP:
return "Screen mode: Swapping TV and GamePad";
case SCREEN_MODE_MIRROR_TV:
return "Screen mode: Mirror TV to GamePad";
case SCREEN_MODE_MIRROR_DRC:
return "Screen mode: Mirror GamePad to TV";
case SCREEN_MODE_MAX_VALUE:
break;
}
return "Invalid screen mode";
}
void SwapScreens() {
if (gCurScreenMode == SCREEN_MODE_SWAP) {
gCurScreenMode = SCREEN_MODE_NONE;
@ -97,11 +113,19 @@ void SwapScreens() {
}
if (gShowNotifications && gNotificationModuleInitDone) {
if (gCurScreenMode) {
NotificationModule_AddInfoNotification("Swapping TV and GamePad screen");
} else {
NotificationModule_AddInfoNotification("Stop swapping TV and GamePad screen");
NotificationModule_AddInfoNotification(screenModeToStr(gCurScreenMode));
}
}
void ChangeScreens() {
auto val = (uint32_t) gCurScreenMode;
val++;
if (val >= SCREEN_MODE_MAX_VALUE) {
val = 0;
}
gCurScreenMode = static_cast<SwipSwapScreenMode>(val);
if (gShowNotifications && gNotificationModuleInitDone) {
NotificationModule_AddInfoNotification(screenModeToStr(gCurScreenMode));
}
}
@ -109,6 +133,7 @@ void SwapVoices();
extern "C" uint32_t VPADGetButtonProcMode(VPADChan chan);
static uint32_t sSwapScreenWasHoldForXFrameGamePad = 0;
static uint32_t sChangeScreenWasHoldForXFrameGamePad = 0;
static uint32_t sSwapVoicesWasHoldForXFrameGamePad = 0;
DECL_FUNCTION(int32_t, VPADRead, VPADChan chan, VPADStatus *buffer, uint32_t buffer_size, VPADReadError *error) {
VPADReadError real_error;
@ -132,6 +157,13 @@ DECL_FUNCTION(int32_t, VPADRead, VPADChan chan, VPADStatus *buffer, uint32_t buf
sSwapScreenWasHoldForXFrameGamePad)) {
SwapScreens();
}
if (gChangeScreenModeButtonComboEnabled && checkButtonComboVPAD(buffer,
checkFullBuffer ? result : 1,
gChangeScreenButtonCombo,
sChangeScreenWasHoldForXFrameGamePad)) {
ChangeScreens();
}
}
}
@ -141,7 +173,7 @@ DECL_FUNCTION(int32_t, VPADRead, VPADChan chan, VPADStatus *buffer, uint32_t buf
return result;
}
const char *modeToStr(SwipSwapAudioMode mode) {
const char *audioModeToStr(SwipSwapAudioMode mode) {
switch (mode) {
case AUDIO_MODE_NONE:
return "Audio mode: Normal";
@ -167,7 +199,7 @@ void SwapVoices() {
}
gCurAudioMode = static_cast<SwipSwapAudioMode>(val);
if (gShowNotifications && gNotificationModuleInitDone) {
NotificationModule_AddInfoNotification(modeToStr(gCurAudioMode));
NotificationModule_AddInfoNotification(audioModeToStr(gCurAudioMode));
}
}

View File

@ -74,6 +74,9 @@ INITIALIZE_PLUGIN() {
if ((err = WUPSStorageAPI::GetOrStoreDefault(ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING, gChangeAudioModeButtonComboEnabled, DEFAULT_ENABLED_CHANGE_AUDIO_COMBO_CONFIG_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\": %s (%d)", ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING, WUPSStorageAPI_GetStatusStr(err), err);
}
if ((err = WUPSStorageAPI::GetOrStoreDefault(ENABLED_CHANGE_SCREEN_COMBO_CONFIG_STRING, gChangeAudioModeButtonComboEnabled, DEFAULT_ENABLED_CHANGE_SCREEN_COMBO_CONFIG_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\": %s (%d)", ENABLED_CHANGE_SCREEN_COMBO_CONFIG_STRING, WUPSStorageAPI_GetStatusStr(err), err);
}
if ((err = WUPSStorageAPI::GetOrStoreDefault(ENABLE_NOTIFICATIONS_CONFIG_STRING, gShowNotifications, DEFAULT_ENABLE_NOTIFICATIONS_CONFIG_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\": %s (%d)", ENABLE_NOTIFICATIONS_CONFIG_STRING, WUPSStorageAPI_GetStatusStr(err), err);
}
@ -83,11 +86,13 @@ INITIALIZE_PLUGIN() {
if ((err = WUPSStorageAPI::GetOrStoreDefault(CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING, gSwapAudioButtonCombo, (uint32_t) DEFAULT_CHANGE_AUDIO_BUTTON_COMBO_CONFIG_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\": %s (%d)", CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING, WUPSStorageAPI_GetStatusStr(err), err);
}
if ((err = WUPSStorageAPI::GetOrStoreDefault(CHANGE_SCREEN_BUTTON_COMBO_CONFIG_STRING, gSwapAudioButtonCombo, (uint32_t) DEFAULT_CHANGE_SCREEN_BUTTON_COMBO_CONFIG_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\": %s (%d)", CHANGE_SCREEN_BUTTON_COMBO_CONFIG_STRING, WUPSStorageAPI_GetStatusStr(err), err);
}
if ((err = WUPSStorageAPI::GetOrStoreDefault(AUDIO_MODE_CONFIG_STRING, gCurAudioMode, DEFAULT_AUDIO_MODE_CONFIG_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\": %s (%d)", AUDIO_MODE_CONFIG_STRING, WUPSStorageAPI_GetStatusStr(err), err);
}
if ((err = WUPSStorageAPI::SaveStorage()) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to save storage: %s (%d)", WUPSStorageAPI_GetStatusStr(err), err);
}

View File

@ -4,8 +4,10 @@
bool gEnabled = DEFAULT_ENABLED_CONFIG_VALUE;
uint32_t gSwapScreenButtonCombo = DEFAULT_SWAP_SCREEN_BUTTON_COMBO_CONFIG_VALUE;
uint32_t gSwapAudioButtonCombo = DEFAULT_CHANGE_AUDIO_BUTTON_COMBO_CONFIG_VALUE;
uint32_t gChangeScreenButtonCombo = DEFAULT_CHANGE_SCREEN_BUTTON_COMBO_CONFIG_VALUE;
bool gSwapScreenButtonComboEnabled = DEFAULT_ENABLED_SWAP_SCREENS_COMBO_CONFIG_VALUE;
bool gChangeAudioModeButtonComboEnabled = DEFAULT_ENABLED_CHANGE_AUDIO_COMBO_CONFIG_VALUE;
bool gChangeScreenModeButtonComboEnabled = DEFAULT_ENABLED_CHANGE_SCREEN_COMBO_CONFIG_VALUE;
bool gShowNotifications = DEFAULT_ENABLE_NOTIFICATIONS_CONFIG_VALUE;
SwipSwapScreenMode gCurScreenMode = DEFAULT_SCREEN_MODE_CONFIG_VALUE;

View File

@ -21,8 +21,10 @@ typedef enum SwipSwapScreenMode {
extern uint32_t gSwapScreenButtonCombo;
extern uint32_t gSwapAudioButtonCombo;
extern uint32_t gChangeScreenButtonCombo;
extern bool gSwapScreenButtonComboEnabled;
extern bool gChangeAudioModeButtonComboEnabled;
extern bool gChangeScreenModeButtonComboEnabled;
extern bool gEnabled;
extern bool gShowNotifications;
extern bool gNotificationModuleInitDone;

View File

@ -19,6 +19,8 @@ static void boolItemChangedConfig(ConfigItemBoolean *item, bool newValue) {
gSwapScreenButtonComboEnabled = newValue;
} else if (std::string_view(ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING) == item->identifier) {
gChangeAudioModeButtonComboEnabled = newValue;
} else if (std::string_view(ENABLED_CHANGE_SCREEN_COMBO_CONFIG_STRING) == item->identifier) {
gChangeScreenModeButtonComboEnabled = newValue;
} else if (std::string_view(ENABLE_NOTIFICATIONS_CONFIG_STRING) == item->identifier) {
gShowNotifications = newValue;
} else {
@ -41,6 +43,8 @@ static void buttonComboItemChanged(ConfigItemButtonCombo *item, uint32_t newValu
gSwapScreenButtonCombo = newValue;
} else if (std::string_view(CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING) == item->identifier) {
gSwapAudioButtonCombo = newValue;
} else if (std::string_view(CHANGE_SCREEN_BUTTON_COMBO_CONFIG_STRING) == item->identifier) {
gChangeScreenButtonCombo = newValue;
} else {
DEBUG_FUNCTION_LINE_WARN("Unexpected button combo item: %s", item->identifier);
return;
@ -117,7 +121,7 @@ WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle ro
auto buttonCombos = WUPSConfigCategory::Create("Button Combos");
buttonCombos.add(WUPSConfigItemBoolean::Create(ENABLED_SWAP_SCREENS_COMBO_CONFIG_STRING,
"Enable change swap screen button combo",
"Enable swap screen button combo",
DEFAULT_ENABLED_SWAP_SCREENS_COMBO_CONFIG_VALUE, gSwapScreenButtonComboEnabled,
&boolItemChangedConfig));
@ -126,6 +130,16 @@ WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle ro
DEFAULT_SWAP_SCREEN_BUTTON_COMBO_CONFIG_VALUE, gSwapScreenButtonCombo,
&buttonComboItemChanged));
buttonCombos.add(WUPSConfigItemBoolean::Create(ENABLED_CHANGE_SCREEN_COMBO_CONFIG_STRING,
"Enable change screen button combo",
DEFAULT_ENABLED_CHANGE_SCREEN_COMBO_CONFIG_VALUE, gChangeScreenModeButtonComboEnabled,
&boolItemChangedConfig));
buttonCombos.add(WUPSConfigItemButtonCombo::Create(CHANGE_SCREEN_BUTTON_COMBO_CONFIG_STRING,
"Change screen",
DEFAULT_CHANGE_SCREEN_BUTTON_COMBO_CONFIG_VALUE, gChangeScreenButtonCombo,
&buttonComboItemChanged));
buttonCombos.add(WUPSConfigItemBoolean::Create(ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING,
"Enable change audio mode button combo",
DEFAULT_ENABLED_CHANGE_AUDIO_COMBO_CONFIG_VALUE, gChangeAudioModeButtonComboEnabled,

View File

@ -8,10 +8,12 @@
#define DEFAULT_ENABLED_CONFIG_VALUE true
#define DEFAULT_ENABLED_SWAP_SCREENS_COMBO_CONFIG_VALUE true
#define DEFAULT_ENABLED_CHANGE_SCREEN_COMBO_CONFIG_VALUE false
#define DEFAULT_ENABLED_CHANGE_AUDIO_COMBO_CONFIG_VALUE false
#define DEFAULT_ENABLE_NOTIFICATIONS_CONFIG_VALUE true
#define DEFAULT_SWAP_SCREEN_BUTTON_COMBO_CONFIG_VALUE VPAD_BUTTON_TV
#define DEFAULT_CHANGE_AUDIO_BUTTON_COMBO_CONFIG_VALUE VPAD_BUTTON_STICK_L
#define DEFAULT_CHANGE_SCREEN_BUTTON_COMBO_CONFIG_VALUE VPAD_BUTTON_STICK_R
#define DEFAULT_SCREEN_MODE_CONFIG_VALUE SCREEN_MODE_NONE
#define DEFAULT_AUDIO_MODE_CONFIG_VALUE AUDIO_MODE_MATCH_SCREEN
@ -20,9 +22,11 @@
#define SWAP_SCREENS_CONFIG_STRING_DEPRECATED "swapScreens"
#define SCREEN_MODE_CONFIG_STRING "screenMode"
#define ENABLED_SWAP_SCREENS_COMBO_CONFIG_STRING "swapScreensComboEnabled"
#define ENABLED_CHANGE_SCREEN_COMBO_CONFIG_STRING "changeScreenComboEnabled"
#define ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING "changeAudioComboEnabled"
#define ENABLE_NOTIFICATIONS_CONFIG_STRING "notificationsEnabled"
#define SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING "screenButtonCombo"
#define CHANGE_SCREEN_BUTTON_COMBO_CONFIG_STRING "screenChangeButtonCombo"
#define CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING "audioButtonCombo"
#define AUDIO_MODE_CONFIG_STRING "audioMode"