mirror of
https://github.com/wiiu-env/SwipSwapMe.git
synced 2024-11-24 13:39:15 +01:00
WUPS 0.8.0 support
This commit is contained in:
parent
0fad651cd2
commit
68da7df659
@ -1,6 +1,6 @@
|
|||||||
FROM ghcr.io/wiiu-env/devkitppc:20230621
|
FROM ghcr.io/wiiu-env/devkitppc:20231112
|
||||||
|
|
||||||
COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:20230719 /artifacts $DEVKITPRO
|
COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:0.8.0-dev-20231221-ca17105 /artifacts $DEVKITPRO
|
||||||
COPY --from=ghcr.io/wiiu-env/libnotifications:20230621 /artifacts $DEVKITPRO
|
COPY --from=ghcr.io/wiiu-env/libnotifications:20230621 /artifacts $DEVKITPRO
|
||||||
COPY --from=ghcr.io/wiiu-env/libmappedmemory:20230621 /artifacts $DEVKITPRO
|
COPY --from=ghcr.io/wiiu-env/libmappedmemory:20230621 /artifacts $DEVKITPRO
|
||||||
|
|
||||||
|
2
Makefile
2
Makefile
@ -34,7 +34,7 @@ CFLAGS := -Wall -O2 -ffunction-sections \
|
|||||||
|
|
||||||
CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -D__WUPS__
|
CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -D__WUPS__
|
||||||
|
|
||||||
CXXFLAGS := $(CFLAGS) -std=c++20 -fno-exceptions -fno-rtti
|
CXXFLAGS := $(CFLAGS) -std=c++20
|
||||||
|
|
||||||
ASFLAGS := -g $(ARCH)
|
ASFLAGS := -g $(ARCH)
|
||||||
LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -T$(WUMS_ROOT)/share/libmappedmemory.ld $(WUPSSPECS)
|
LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -T$(WUMS_ROOT)/share/libmappedmemory.ld $(WUPSSPECS)
|
||||||
|
73
src/main.cpp
73
src/main.cpp
@ -20,7 +20,6 @@
|
|||||||
#include "utils/config.h"
|
#include "utils/config.h"
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
#include <notifications/notifications.h>
|
#include <notifications/notifications.h>
|
||||||
#include <string>
|
|
||||||
#include <wups.h>
|
#include <wups.h>
|
||||||
|
|
||||||
// Mandatory plugin information.
|
// Mandatory plugin information.
|
||||||
@ -46,25 +45,40 @@ INITIALIZE_PLUGIN() {
|
|||||||
DEBUG_FUNCTION_LINE_ERR("Failed to init notification lib");
|
DEBUG_FUNCTION_LINE_ERR("Failed to init notification lib");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open storage to read values
|
if (WUPSStorageAPI::GetOrStoreDefault(ENABLED_CONFIG_STRING, gEnabled, DEFAULT_ENABLED_CONFIG_VALUE) != WUPS_STORAGE_ERROR_SUCCESS) {
|
||||||
WUPSStorageError storageRes = WUPS_OpenStorage();
|
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\"", ENABLED_CONFIG_STRING);
|
||||||
if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) {
|
|
||||||
DEBUG_FUNCTION_LINE_ERR("Failed to open storage %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes);
|
|
||||||
} else {
|
|
||||||
LOAD_BOOL_FROM_STORAGE(ENABLED_CONFIG_STRING, gEnabled);
|
|
||||||
LOAD_BOOL_FROM_STORAGE(SWAP_SCREENS_CONFIG_STRING, gDoScreenSwap);
|
|
||||||
LOAD_BOOL_FROM_STORAGE(ENABLED_SWAP_SCREENS_COMBO_CONFIG_STRING, gSwapScreenButtonComboEnabled);
|
|
||||||
LOAD_BOOL_FROM_STORAGE(ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING, gChangeAudioModeButtonComboEnabled);
|
|
||||||
LOAD_BOOL_FROM_STORAGE(ENABLE_NOTIFICATIONS_CONFIG_STRING, gShowNotifications);
|
|
||||||
LOAD_INT_FROM_STORAGE(SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING, gSwapScreenButtonCombo);
|
|
||||||
LOAD_INT_FROM_STORAGE(CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING, gSwapAudioButtonCombo);
|
|
||||||
LOAD_INT_FROM_STORAGE(SCREEN_MODE_CONFIG_STRING, gCurAudioMode);
|
|
||||||
|
|
||||||
// Close storage
|
|
||||||
if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
|
|
||||||
DEBUG_FUNCTION_LINE_ERR("Failed to close storage");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (WUPSStorageAPI::GetOrStoreDefault(SWAP_SCREENS_CONFIG_STRING, gDoScreenSwap, DEFAULT_SWAP_SCREENS_CONFIG_VALUE) != WUPS_STORAGE_ERROR_SUCCESS) {
|
||||||
|
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\"", SWAP_SCREENS_CONFIG_STRING);
|
||||||
|
}
|
||||||
|
if (WUPSStorageAPI::GetOrStoreDefault(ENABLED_SWAP_SCREENS_COMBO_CONFIG_STRING, gSwapScreenButtonComboEnabled, DEFAULT_ENABLED_SWAP_SCREENS_COMBO_CONFIG_VALUE) != WUPS_STORAGE_ERROR_SUCCESS) {
|
||||||
|
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\"", ENABLED_SWAP_SCREENS_COMBO_CONFIG_STRING);
|
||||||
|
}
|
||||||
|
if (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\"", ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING);
|
||||||
|
}
|
||||||
|
if (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\"", ENABLE_NOTIFICATIONS_CONFIG_STRING);
|
||||||
|
}
|
||||||
|
if (WUPSStorageAPI::GetOrStoreDefault(SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING, gSwapScreenButtonCombo, (uint32_t) DEFAULT_SWAP_SCREEN_BUTTON_COMBO_CONFIG_VALUE) != WUPS_STORAGE_ERROR_SUCCESS) {
|
||||||
|
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\"", SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING);
|
||||||
|
}
|
||||||
|
if (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\"", CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING);
|
||||||
|
}
|
||||||
|
if (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\"", AUDIO_MODE_CONFIG_STRING);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WUPSStorageAPI::SaveStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
|
||||||
|
DEBUG_FUNCTION_LINE_ERR("Failed to save storage");
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSConfigAPIOptionsV1 configOptions = {.name = "Swip Swap Me"};
|
||||||
|
if (WUPSConfigAPI_Init(configOptions, ConfigMenuOpenedCallback, ConfigMenuClosedCallback) != WUPSCONFIG_API_RESULT_SUCCESS) {
|
||||||
|
DEBUG_FUNCTION_LINE_ERR("Failed to init config api");
|
||||||
|
}
|
||||||
|
|
||||||
deinitLogging();
|
deinitLogging();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,18 +95,15 @@ ON_APPLICATION_START() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ON_APPLICATION_REQUESTS_EXIT() {
|
ON_APPLICATION_REQUESTS_EXIT() {
|
||||||
// Open storage to write current config
|
if (WUPSStorageAPI::Store(AUDIO_MODE_CONFIG_STRING, gCurAudioMode) != WUPS_STORAGE_ERROR_SUCCESS) {
|
||||||
WUPSStorageError storageRes = WUPS_OpenStorage();
|
DEBUG_FUNCTION_LINE_ERR("Failed to store screen mode to storage");
|
||||||
if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) {
|
|
||||||
DEBUG_FUNCTION_LINE_ERR("Failed to open storage %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes);
|
|
||||||
} else {
|
|
||||||
WUPS_StoreInt(nullptr, SCREEN_MODE_CONFIG_STRING, (int32_t) gCurAudioMode);
|
|
||||||
WUPS_StoreBool(nullptr, SWAP_SCREENS_CONFIG_STRING, (int32_t) gDoScreenSwap);
|
|
||||||
|
|
||||||
// Close storage
|
|
||||||
if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
|
|
||||||
DEBUG_FUNCTION_LINE_ERR("Failed to close storage");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (WUPSStorageAPI::Store(SWAP_SCREENS_CONFIG_STRING, gDoScreenSwap) != WUPS_STORAGE_ERROR_SUCCESS) {
|
||||||
|
DEBUG_FUNCTION_LINE_ERR("Failed to store screen mode to storage");
|
||||||
|
}
|
||||||
|
if (WUPSStorageAPI::SaveStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
|
||||||
|
DEBUG_FUNCTION_LINE_ERR("Failed to save storage");
|
||||||
|
}
|
||||||
|
|
||||||
deinitLogging();
|
deinitLogging();
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
#include "retain_vars.hpp"
|
#include "retain_vars.hpp"
|
||||||
#include <vpad/input.h>
|
#include "utils/config.h"
|
||||||
|
|
||||||
uint32_t gSwapScreenButtonCombo = VPAD_BUTTON_TV;
|
bool gEnabled = DEFAULT_ENABLED_CONFIG_VALUE;
|
||||||
uint32_t gSwapAudioButtonCombo = VPAD_BUTTON_STICK_L;
|
bool gDoScreenSwap = DEFAULT_SWAP_SCREENS_CONFIG_VALUE;
|
||||||
bool gSwapScreenButtonComboEnabled = true;
|
uint32_t gSwapScreenButtonCombo = DEFAULT_SWAP_SCREEN_BUTTON_COMBO_CONFIG_VALUE;
|
||||||
bool gChangeAudioModeButtonComboEnabled = false;
|
uint32_t gSwapAudioButtonCombo = DEFAULT_CHANGE_AUDIO_BUTTON_COMBO_CONFIG_VALUE;
|
||||||
bool gEnabled = true;
|
bool gSwapScreenButtonComboEnabled = DEFAULT_ENABLED_SWAP_SCREENS_COMBO_CONFIG_VALUE;
|
||||||
bool gDoScreenSwap = false;
|
bool gChangeAudioModeButtonComboEnabled = DEFAULT_ENABLED_CHANGE_AUDIO_COMBO_CONFIG_VALUE;
|
||||||
bool gShowNotifications = true;
|
bool gShowNotifications = DEFAULT_ENABLE_NOTIFICATIONS_CONFIG_VALUE;
|
||||||
bool gNotificationModuleInitDone = true;
|
SwipSwapAudioMode gCurAudioMode = DEFAULT_AUDIO_MODE_CONFIG_VALUE;
|
||||||
SwipSwapAudioMode gCurAudioMode = AUDIO_MODE_MATCH_SCREEN;
|
|
||||||
|
bool gNotificationModuleInitDone = true;
|
@ -10,7 +10,7 @@
|
|||||||
#include <vpad/input.h>
|
#include <vpad/input.h>
|
||||||
#include <wups.h>
|
#include <wups.h>
|
||||||
|
|
||||||
const char *getButtonChar(VPADButtons value) {
|
static const char *getButtonChar(VPADButtons value) {
|
||||||
std::string combo;
|
std::string combo;
|
||||||
if (value & VPAD_BUTTON_A) {
|
if (value & VPAD_BUTTON_A) {
|
||||||
return "\ue000";
|
return "\ue000";
|
||||||
@ -69,7 +69,7 @@ const char *getButtonChar(VPADButtons value) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getComboAsString(uint32_t value) {
|
static std::string getComboAsString(uint32_t value) {
|
||||||
char comboString[60];
|
char comboString[60];
|
||||||
memset(comboString, 0, sizeof(comboString));
|
memset(comboString, 0, sizeof(comboString));
|
||||||
|
|
||||||
@ -90,22 +90,20 @@ std::string getComboAsString(uint32_t value) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t WUPSConfigItemButtonCombo_getCurrentValueDisplay(void *context, char *out_buf, int32_t out_size) {
|
static int32_t WUPSConfigItemButtonCombo_getCurrentValueDisplay(void *context, char *out_buf, int32_t out_size) {
|
||||||
auto *item = (ConfigItemButtonCombo *) context;
|
auto *item = (ConfigItemButtonCombo *) context;
|
||||||
snprintf(out_buf, out_size, "%s", getComboAsString(item->value).c_str());
|
snprintf(out_buf, out_size, "%s", getComboAsString(item->value).c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WUPSConfigItemButtonCombo_callCallback(void *context) {
|
static void WUPSConfigItemButtonCombo_onCloseCallback(void *context) {
|
||||||
auto *item = (ConfigItemButtonCombo *) context;
|
auto *item = (ConfigItemButtonCombo *) context;
|
||||||
if (item->callback != nullptr) {
|
if (item->valueAtCreation != item->value && item->valueChangedCallback != nullptr) {
|
||||||
((ButtonComboValueChangedCallback) (item->callback))(item, item->value);
|
((ButtonComboValueChangedCallback) (item->valueChangedCallback))(item, item->value);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkForHold(ConfigItemButtonCombo *item) {
|
static void checkForHold(ConfigItemButtonCombo *item) {
|
||||||
uint32_t lastHold = 0;
|
uint32_t lastHold = 0;
|
||||||
uint32_t holdFor = 0;
|
uint32_t holdFor = 0;
|
||||||
uint32_t holdForTarget = item->holdDurationInMs >> 4;
|
uint32_t holdForTarget = item->holdDurationInMs >> 4;
|
||||||
@ -121,9 +119,8 @@ void checkForHold(ConfigItemButtonCombo *item) {
|
|||||||
while (true) {
|
while (true) {
|
||||||
uint32_t buttonsHold = 0;
|
uint32_t buttonsHold = 0;
|
||||||
VPADReadError vpad_error = VPAD_READ_UNINITIALIZED;
|
VPADReadError vpad_error = VPAD_READ_UNINITIALIZED;
|
||||||
VPADStatus vpad_data;
|
VPADStatus vpad_data = {};
|
||||||
VPADRead(VPAD_CHAN_0, &vpad_data, 1, &vpad_error);
|
if (VPADRead(VPAD_CHAN_0, &vpad_data, 1, &vpad_error) > 0 && vpad_error == VPAD_READ_SUCCESS) {
|
||||||
if (vpad_error == VPAD_READ_SUCCESS) {
|
|
||||||
buttonsHold = vpad_data.hold;
|
buttonsHold = vpad_data.hold;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,20 +162,16 @@ void checkForHold(ConfigItemButtonCombo *item) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WUPSConfigItemButtonCombo_onButtonPressed(void *context, WUPSConfigButtons buttons) {
|
static void WUPSConfigItemButtonCombo_onInput(void *context, WUPSConfigSimplePadData input) {
|
||||||
auto *item = (ConfigItemButtonCombo *) context;
|
auto *item = (ConfigItemButtonCombo *) context;
|
||||||
if (item->state == BUTTON_COMBO_STATE_NONE) {
|
if (item->state == BUTTON_COMBO_STATE_NONE) {
|
||||||
if ((buttons & WUPS_CONFIG_BUTTON_A) == WUPS_CONFIG_BUTTON_A) {
|
if ((input.buttons_d & WUPS_CONFIG_BUTTON_A) == WUPS_CONFIG_BUTTON_A) {
|
||||||
item->state = BUTTON_COMBO_STATE_PREPARE_FOR_HOLD;
|
item->state = BUTTON_COMBO_STATE_PREPARE_FOR_HOLD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WUPSConfigItemButtonCombo_isMovementAllowed(void *context) {
|
static int32_t WUPSConfigItemButtonCombo_getCurrentValueSelectedDisplay(void *context, char *out_buf, int32_t out_size) {
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t WUPSConfigItemButtonCombo_getCurrentValueSelectedDisplay(void *context, char *out_buf, int32_t out_size) {
|
|
||||||
auto *item = (ConfigItemButtonCombo *) context;
|
auto *item = (ConfigItemButtonCombo *) context;
|
||||||
if (item->state == BUTTON_COMBO_STATE_PREPARE_FOR_HOLD || item->state == BUTTON_COMBO_STATE_WAIT_FOR_HOLD) {
|
if (item->state == BUTTON_COMBO_STATE_PREPARE_FOR_HOLD || item->state == BUTTON_COMBO_STATE_WAIT_FOR_HOLD) {
|
||||||
if (item->state == BUTTON_COMBO_STATE_PREPARE_FOR_HOLD) {
|
if (item->state == BUTTON_COMBO_STATE_PREPARE_FOR_HOLD) {
|
||||||
@ -194,72 +187,112 @@ int32_t WUPSConfigItemButtonCombo_getCurrentValueSelectedDisplay(void *context,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WUPSConfigItemButtonCombo_restoreDefault(void *context) {
|
static void WUPSConfigItemButtonCombo_restoreDefault(void *context) {
|
||||||
auto *item = (ConfigItemButtonCombo *) context;
|
auto *item = (ConfigItemButtonCombo *) context;
|
||||||
item->value = item->defaultValue;
|
item->value = item->defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WUPSConfigItemButtonCombo_onSelected(void *context, bool isSelected) {
|
static void WUPSConfigItemButtonCombo_Cleanup(ConfigItemButtonCombo *item) {
|
||||||
}
|
if (!item) {
|
||||||
|
return;
|
||||||
void WUPSConfigItemButtonCombo_onDelete(void *context) {
|
|
||||||
auto *item = (ConfigItemButtonCombo *) context;
|
|
||||||
if (item->configId) {
|
|
||||||
free(item->configId);
|
|
||||||
}
|
}
|
||||||
|
free((void *) item->identifier);
|
||||||
free(item);
|
free(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" bool
|
static void WUPSConfigItemButtonCombo_onDelete(void *context) {
|
||||||
WUPSConfigItemButtonComboAddToCategoryEx(WUPSConfigCategoryHandle cat, const char *configID, const char *displayName, uint32_t defaultComboInVPADButtons, uint32_t holdDurationInMs, VPADButtons abortButton, uint32_t abortButtonHoldDurationInMs, ButtonComboValueChangedCallback callback) {
|
WUPSConfigItemButtonCombo_Cleanup((ConfigItemButtonCombo *) context);
|
||||||
if (cat == 0) {
|
}
|
||||||
return false;
|
|
||||||
|
extern "C" WUPSConfigAPIStatus
|
||||||
|
WUPSConfigItemButtonCombo_CreateEx(const char *identifier,
|
||||||
|
const char *displayName,
|
||||||
|
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
|
||||||
|
uint32_t holdDurationInMs,
|
||||||
|
VPADButtons abortButton,
|
||||||
|
uint32_t abortButtonHoldDurationInMs,
|
||||||
|
ButtonComboValueChangedCallback callback,
|
||||||
|
WUPSConfigItemHandle *outHandle) {
|
||||||
|
if (outHandle == nullptr) {
|
||||||
|
return WUPSCONFIG_API_RESULT_INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
auto *item = (ConfigItemButtonCombo *) malloc(sizeof(ConfigItemButtonCombo));
|
auto *item = (ConfigItemButtonCombo *) malloc(sizeof(ConfigItemButtonCombo));
|
||||||
if (item == nullptr) {
|
if (item == nullptr) {
|
||||||
OSReport("WUPSConfigItemButtonComboAddToCategoryEx: Failed to allocate memory for item data.\n");
|
OSReport("WUPSConfigItemButtonComboAddToCategoryEx: Failed to allocate memory for item data.\n");
|
||||||
return false;
|
return WUPSCONFIG_API_RESULT_INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configID != nullptr) {
|
if (identifier != nullptr) {
|
||||||
item->configId = strdup(configID);
|
item->identifier = strdup(identifier);
|
||||||
} else {
|
} else {
|
||||||
item->configId = nullptr;
|
item->identifier = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
item->abortButton = abortButton;
|
item->abortButton = abortButton;
|
||||||
item->abortButtonHoldDurationInMs = abortButtonHoldDurationInMs;
|
item->abortButtonHoldDurationInMs = abortButtonHoldDurationInMs;
|
||||||
item->holdDurationInMs = holdDurationInMs;
|
item->holdDurationInMs = holdDurationInMs;
|
||||||
item->defaultValue = defaultComboInVPADButtons;
|
item->defaultValue = defaultComboInVPADButtons;
|
||||||
item->value = defaultComboInVPADButtons;
|
item->value = currentComboInVPADButtons;
|
||||||
item->callback = (void *) callback;
|
item->valueAtCreation = currentComboInVPADButtons;
|
||||||
|
item->valueChangedCallback = (void *) callback;
|
||||||
item->state = BUTTON_COMBO_STATE_NONE;
|
item->state = BUTTON_COMBO_STATE_NONE;
|
||||||
|
|
||||||
WUPSConfigCallbacks_t callbacks = {
|
WUPSConfigAPIItemCallbacksV2 callbacks = {
|
||||||
.getCurrentValueDisplay = &WUPSConfigItemButtonCombo_getCurrentValueDisplay,
|
.getCurrentValueDisplay = &WUPSConfigItemButtonCombo_getCurrentValueDisplay,
|
||||||
.getCurrentValueSelectedDisplay = &WUPSConfigItemButtonCombo_getCurrentValueSelectedDisplay,
|
.getCurrentValueSelectedDisplay = &WUPSConfigItemButtonCombo_getCurrentValueSelectedDisplay,
|
||||||
.onSelected = &WUPSConfigItemButtonCombo_onSelected,
|
.onSelected = nullptr,
|
||||||
.restoreDefault = &WUPSConfigItemButtonCombo_restoreDefault,
|
.restoreDefault = &WUPSConfigItemButtonCombo_restoreDefault,
|
||||||
.isMovementAllowed = &WUPSConfigItemButtonCombo_isMovementAllowed,
|
.isMovementAllowed = nullptr,
|
||||||
.callCallback = &WUPSConfigItemButtonCombo_callCallback,
|
.onCloseCallback = &WUPSConfigItemButtonCombo_onCloseCallback,
|
||||||
.onButtonPressed = &WUPSConfigItemButtonCombo_onButtonPressed,
|
.onInput = &WUPSConfigItemButtonCombo_onInput,
|
||||||
.onDelete = &WUPSConfigItemButtonCombo_onDelete};
|
.onInputEx = nullptr,
|
||||||
|
.onDelete = &WUPSConfigItemButtonCombo_onDelete,
|
||||||
|
};
|
||||||
|
|
||||||
if (WUPSConfigItem_Create(&item->handle, configID, displayName, callbacks, item) < 0) {
|
WUPSConfigAPIItemOptionsV2 options = {
|
||||||
|
.displayName = displayName,
|
||||||
|
.context = item,
|
||||||
|
.callbacks = callbacks,
|
||||||
|
};
|
||||||
|
|
||||||
|
WUPSConfigAPIStatus err;
|
||||||
|
if ((err = WUPSConfigAPI_Item_Create(options, &item->handle)) != WUPSCONFIG_API_RESULT_SUCCESS) {
|
||||||
OSReport("WUPSConfigItemButtonComboAddToCategoryEx: Failed to create config item.\n");
|
OSReport("WUPSConfigItemButtonComboAddToCategoryEx: Failed to create config item.\n");
|
||||||
free(item);
|
WUPSConfigItemButtonCombo_Cleanup(item);
|
||||||
return false;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WUPSConfigCategory_AddItem(cat, item->handle) < 0) {
|
*outHandle = item->handle;
|
||||||
OSReport("WUPSConfigItemButtonComboAddToCategoryEx: Failed to add item to category.\n");
|
return WUPSCONFIG_API_RESULT_SUCCESS;
|
||||||
WUPSConfigItem_Destroy(item->handle);
|
}
|
||||||
return false;
|
|
||||||
|
|
||||||
|
extern "C" WUPSConfigAPIStatus
|
||||||
|
WUPSConfigItemButtonCombo_AddToCategoryEx(WUPSConfigCategoryHandle cat,
|
||||||
|
const char *identifier,
|
||||||
|
const char *displayName,
|
||||||
|
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
|
||||||
|
uint32_t holdDurationInMs, VPADButtons abortButton, uint32_t abortButtonHoldDurationInMs,
|
||||||
|
ButtonComboValueChangedCallback callback) {
|
||||||
|
WUPSConfigItemHandle itemHandle;
|
||||||
|
WUPSConfigAPIStatus res;
|
||||||
|
if ((res = WUPSConfigItemButtonCombo_CreateEx(identifier,
|
||||||
|
displayName,
|
||||||
|
defaultComboInVPADButtons, currentComboInVPADButtons,
|
||||||
|
holdDurationInMs, abortButton, abortButtonHoldDurationInMs,
|
||||||
|
callback, &itemHandle)) != WUPSCONFIG_API_RESULT_SUCCESS) {
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
if ((res = WUPSConfigAPI_Category_AddItem(cat, itemHandle)) != WUPSCONFIG_API_RESULT_SUCCESS) {
|
||||||
|
|
||||||
|
WUPSConfigAPI_Item_Destroy(itemHandle);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
return WUPSCONFIG_API_RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" bool
|
extern "C" bool
|
||||||
WUPSConfigItemButtonComboAddToCategory(WUPSConfigCategoryHandle cat, const char *configID, const char *displayName, uint32_t defaultComboInVPADButtons, ButtonComboValueChangedCallback callback) {
|
WUPSConfigItemButtonComboAddToCategory(WUPSConfigCategoryHandle cat, const char *displayName, uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons, ButtonComboValueChangedCallback callback) {
|
||||||
return WUPSConfigItemButtonComboAddToCategoryEx(cat, configID, displayName, defaultComboInVPADButtons, 2000, VPAD_BUTTON_B, 250, callback);
|
return WUPSConfigItemButtonComboAddToCategoryEx(cat, displayName, defaultComboInVPADButtons, currentComboInVPADButtons, 2000, VPAD_BUTTON_B, 250, callback);
|
||||||
}
|
}
|
@ -13,31 +13,82 @@ typedef enum ButtonComboState {
|
|||||||
} ButtonComboState;
|
} ButtonComboState;
|
||||||
|
|
||||||
typedef struct ConfigItemButtonCombo {
|
typedef struct ConfigItemButtonCombo {
|
||||||
char *configId;
|
const char *identifier;
|
||||||
WUPSConfigItemHandle handle;
|
WUPSConfigItemHandle handle;
|
||||||
uint32_t defaultValue;
|
uint32_t defaultValue;
|
||||||
uint32_t value;
|
uint32_t value;
|
||||||
|
uint32_t valueAtCreation;
|
||||||
uint32_t holdDurationInMs;
|
uint32_t holdDurationInMs;
|
||||||
VPADButtons abortButton;
|
VPADButtons abortButton;
|
||||||
uint32_t abortButtonHoldDurationInMs;
|
uint32_t abortButtonHoldDurationInMs;
|
||||||
void *callback;
|
|
||||||
ButtonComboState state;
|
ButtonComboState state;
|
||||||
|
void *valueChangedCallback;
|
||||||
} ConfigItemButtonCombo;
|
} ConfigItemButtonCombo;
|
||||||
|
|
||||||
typedef void (*ButtonComboValueChangedCallback)(ConfigItemButtonCombo *item, uint32_t buttonComboInVPADButtons);
|
typedef void (*ButtonComboValueChangedCallback)(ConfigItemButtonCombo *item, uint32_t buttonComboInVPADButtons);
|
||||||
|
|
||||||
bool WUPSConfigItemButtonComboAddToCategory(WUPSConfigCategoryHandle cat, const char *configId, const char *displayName, uint32_t defaultComboInVPADButtons, ButtonComboValueChangedCallback callback);
|
extern "C" WUPSConfigAPIStatus
|
||||||
|
WUPSConfigItemButtonCombo_CreateEx(const char *identifier,
|
||||||
|
const char *displayName,
|
||||||
|
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
|
||||||
|
uint32_t holdDurationInMs, VPADButtons abortButton, uint32_t abortButtonHoldDurationInMs,
|
||||||
|
ButtonComboValueChangedCallback callback,
|
||||||
|
WUPSConfigItemHandle *outHandle);
|
||||||
|
|
||||||
bool WUPSConfigItemButtonComboAddToCategoryEx(WUPSConfigCategoryHandle cat, const char *configId, const char *displayName, uint32_t defaultComboInVPADButtons, uint32_t holdDurationInMs, VPADButtons abortButton, uint32_t abortButtonHoldDurationInMs, ButtonComboValueChangedCallback callback);
|
bool WUPSConfigItemButtonComboAddToCategory(WUPSConfigCategoryHandle cat,
|
||||||
|
const char *displayName,
|
||||||
|
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
|
||||||
|
ButtonComboValueChangedCallback callback);
|
||||||
|
|
||||||
#define WUPSConfigItemButtonCombo_AddToCategoryHandled(__config__, __cat__, __configID__, __displayName__, __defaultComboInVPADButtons__, __callback__) \
|
bool WUPSConfigItemButtonComboAddToCategoryEx(WUPSConfigCategoryHandle cat,
|
||||||
do { \
|
const char *displayName,
|
||||||
if (!WUPSConfigItemButtonComboAddToCategory(__cat__, __configID__, __displayName__, __defaultComboInVPADButtons__, __callback__)) { \
|
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
|
||||||
WUPSConfig_Destroy(__config__); \
|
uint32_t holdDurationInMs,
|
||||||
return 0; \
|
VPADButtons abortButton,
|
||||||
} \
|
uint32_t abortButtonHoldDurationInMs,
|
||||||
} while (0)
|
ButtonComboValueChangedCallback callback);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
#include <wups/config/WUPSConfigItem.h>
|
||||||
|
#include <wups/config_api.h>
|
||||||
|
|
||||||
|
class WUPSConfigItemButtonCombo : public WUPSConfigItem {
|
||||||
|
public:
|
||||||
|
static std::optional<WUPSConfigItemButtonCombo> CreateEx(std::optional<std::string> identifier,
|
||||||
|
std::string_view displayName,
|
||||||
|
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
|
||||||
|
uint32_t holdDurationInMs, VPADButtons abortButton, uint32_t abortButtonHoldDurationInMs,
|
||||||
|
ButtonComboValueChangedCallback callback,
|
||||||
|
WUPSConfigAPIStatus &err) noexcept;
|
||||||
|
|
||||||
|
static WUPSConfigItemButtonCombo CreateEx(std::optional<std::string> identifier,
|
||||||
|
std::string_view displayName,
|
||||||
|
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
|
||||||
|
uint32_t holdDurationInMs, VPADButtons abortButton, uint32_t abortButtonHoldDurationInMs,
|
||||||
|
ButtonComboValueChangedCallback callback);
|
||||||
|
|
||||||
|
static std::optional<WUPSConfigItemButtonCombo> Create(std::optional<std::string> identifier,
|
||||||
|
std::string_view displayName,
|
||||||
|
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
|
||||||
|
ButtonComboValueChangedCallback callback,
|
||||||
|
WUPSConfigAPIStatus &err) noexcept;
|
||||||
|
|
||||||
|
static WUPSConfigItemButtonCombo Create(std::optional<std::string> identifier,
|
||||||
|
std::string_view displayName,
|
||||||
|
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
|
||||||
|
ButtonComboValueChangedCallback callback);
|
||||||
|
|
||||||
|
private:
|
||||||
|
explicit WUPSConfigItemButtonCombo(WUPSConfigItemHandle itemHandle) : WUPSConfigItem(itemHandle) {
|
||||||
|
}
|
||||||
|
};
|
||||||
#endif
|
#endif
|
52
src/utils/WUPSConfigItemButtonComboCpp.cpp
Normal file
52
src/utils/WUPSConfigItemButtonComboCpp.cpp
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#include "WUPSConfigItemButtonCombo.h"
|
||||||
|
|
||||||
|
std::optional<WUPSConfigItemButtonCombo> WUPSConfigItemButtonCombo::CreateEx(std::optional<std::string> identifier,
|
||||||
|
std::string_view displayName,
|
||||||
|
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
|
||||||
|
uint32_t holdDurationInMs, VPADButtons abortButton, uint32_t abortButtonHoldDurationInMs,
|
||||||
|
ButtonComboValueChangedCallback callback,
|
||||||
|
WUPSConfigAPIStatus &err) noexcept {
|
||||||
|
WUPSConfigItemHandle itemHandle;
|
||||||
|
if ((err = WUPSConfigItemButtonCombo_CreateEx(identifier ? identifier->data() : nullptr,
|
||||||
|
displayName.data(),
|
||||||
|
defaultComboInVPADButtons, currentComboInVPADButtons,
|
||||||
|
holdDurationInMs, abortButton, abortButtonHoldDurationInMs,
|
||||||
|
callback,
|
||||||
|
&itemHandle)) != WUPSCONFIG_API_RESULT_SUCCESS) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
return WUPSConfigItemButtonCombo(itemHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSConfigItemButtonCombo WUPSConfigItemButtonCombo::CreateEx(std::optional<std::string> identifier,
|
||||||
|
std::string_view displayName,
|
||||||
|
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
|
||||||
|
uint32_t holdDurationInMs, VPADButtons abortButton, uint32_t abortButtonHoldDurationInMs,
|
||||||
|
ButtonComboValueChangedCallback callback) {
|
||||||
|
WUPSConfigAPIStatus err;
|
||||||
|
auto result = CreateEx(std::move(identifier), displayName, defaultComboInVPADButtons, currentComboInVPADButtons, holdDurationInMs, abortButton, abortButtonHoldDurationInMs, callback, err);
|
||||||
|
if (!result) {
|
||||||
|
throw std::runtime_error(std::string("Failed to create WUPSConfigItemButtonCombo: ").append(WUPSConfigAPI_GetStatusStr(err)));
|
||||||
|
}
|
||||||
|
return std::move(*result);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<WUPSConfigItemButtonCombo> WUPSConfigItemButtonCombo::Create(std::optional<std::string> identifier,
|
||||||
|
std::string_view displayName,
|
||||||
|
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
|
||||||
|
ButtonComboValueChangedCallback callback,
|
||||||
|
WUPSConfigAPIStatus &err) noexcept {
|
||||||
|
return CreateEx(std::move(identifier), displayName, defaultComboInVPADButtons, currentComboInVPADButtons, 2000, VPAD_BUTTON_B, 250, callback, err);
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPSConfigItemButtonCombo WUPSConfigItemButtonCombo::Create(std::optional<std::string> identifier,
|
||||||
|
std::string_view displayName,
|
||||||
|
uint32_t defaultComboInVPADButtons, uint32_t currentComboInVPADButtons,
|
||||||
|
ButtonComboValueChangedCallback callback) {
|
||||||
|
WUPSConfigAPIStatus err = WUPSCONFIG_API_RESULT_UNKNOWN_ERROR;
|
||||||
|
auto res = Create(std::move(identifier), displayName, defaultComboInVPADButtons, currentComboInVPADButtons, callback, err);
|
||||||
|
if (!res) {
|
||||||
|
throw std::runtime_error(std::string("Failed to create WUPSConfigItemButtonCombo: ").append(WUPSConfigAPI_GetStatusStr(err)));
|
||||||
|
}
|
||||||
|
return std::move(*res);
|
||||||
|
}
|
@ -3,102 +3,126 @@
|
|||||||
#include "retain_vars.hpp"
|
#include "retain_vars.hpp"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <wups/config/WUPSConfigItemMultipleValues.h>
|
#include <wups/config/WUPSConfigItemMultipleValues.h>
|
||||||
|
|
||||||
extern void UpdateAudioMode();
|
extern void UpdateAudioMode();
|
||||||
|
|
||||||
void boolItemChangedConfig(ConfigItemBoolean *item, bool newValue) {
|
void boolItemChangedConfig(ConfigItemBoolean *item, bool newValue) {
|
||||||
if (std::string_view(item->configId) == ENABLED_CONFIG_STRING) {
|
if (std::string_view(ENABLED_CONFIG_STRING) == item->identifier) {
|
||||||
DEBUG_FUNCTION_LINE("New value in %s: %d", ENABLED_CONFIG_STRING, newValue);
|
DEBUG_FUNCTION_LINE("New value in %s: %d", ENABLED_CONFIG_STRING, newValue);
|
||||||
gEnabled = newValue;
|
gEnabled = newValue;
|
||||||
WUPS_StoreInt(nullptr, ENABLED_CONFIG_STRING, gEnabled);
|
WUPSStorageAPI::Store(ENABLED_CONFIG_STRING, gEnabled);
|
||||||
UpdateAudioMode();
|
UpdateAudioMode();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PROCESS_BOOL_ITEM_CHANGED(SWAP_SCREENS_CONFIG_STRING, gDoScreenSwap);
|
|
||||||
PROCESS_BOOL_ITEM_CHANGED(ENABLED_SWAP_SCREENS_COMBO_CONFIG_STRING, gSwapScreenButtonComboEnabled);
|
if (std::string_view(SWAP_SCREENS_CONFIG_STRING) == item->identifier) {
|
||||||
PROCESS_BOOL_ITEM_CHANGED(ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING, gChangeAudioModeButtonComboEnabled);
|
gDoScreenSwap = newValue;
|
||||||
PROCESS_BOOL_ITEM_CHANGED(ENABLE_NOTIFICATIONS_CONFIG_STRING, gShowNotifications);
|
WUPSStorageAPI::Store(item->identifier, gDoScreenSwap);
|
||||||
|
} else if (std::string_view(ENABLED_SWAP_SCREENS_COMBO_CONFIG_STRING) == item->identifier) {
|
||||||
|
gSwapScreenButtonComboEnabled = newValue;
|
||||||
|
WUPSStorageAPI::Store(item->identifier, gSwapScreenButtonComboEnabled);
|
||||||
|
} else if (std::string_view(ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING) == item->identifier) {
|
||||||
|
gChangeAudioModeButtonComboEnabled = newValue;
|
||||||
|
WUPSStorageAPI::Store(item->identifier, gChangeAudioModeButtonComboEnabled);
|
||||||
|
} else if (std::string_view(ENABLE_NOTIFICATIONS_CONFIG_STRING) == item->identifier) {
|
||||||
|
gShowNotifications = newValue;
|
||||||
|
WUPSStorageAPI::Store(item->identifier, gShowNotifications);
|
||||||
|
} else {
|
||||||
|
DEBUG_FUNCTION_LINE_ERR("Unexpected boolean item: %s", item->identifier);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void buttonComboItemChanged(ConfigItemButtonCombo *item, uint32_t newValue) {
|
void buttonComboItemChanged(ConfigItemButtonCombo *item, uint32_t newValue) {
|
||||||
if (item && item->configId) {
|
if (item && item->identifier) {
|
||||||
if (std::string_view(item->configId) == SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING) {
|
if (std::string_view(SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING) == item->identifier) {
|
||||||
gSwapScreenButtonCombo = newValue;
|
gSwapScreenButtonCombo = newValue;
|
||||||
WUPS_StoreInt(nullptr, item->configId, (int32_t) gSwapScreenButtonCombo);
|
WUPSStorageAPI::Store(item->identifier, (int32_t) gSwapScreenButtonCombo);
|
||||||
} else if (std::string_view(item->configId) == CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING) {
|
} else if (std::string_view(CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING) == item->identifier) {
|
||||||
gSwapAudioButtonCombo = newValue;
|
gSwapAudioButtonCombo = newValue;
|
||||||
WUPS_StoreInt(nullptr, item->configId, (int32_t) gSwapAudioButtonCombo);
|
WUPSStorageAPI::Store(item->identifier, (int32_t) gSwapAudioButtonCombo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void getConfigInfoForMap(std::map<SwipSwapAudioMode, const char *> &curMap, ConfigItemMultipleValuesPair *pair, uint32_t default_lang, uint32_t *default_index, uint32_t *len) {
|
|
||||||
uint32_t i = 0;
|
|
||||||
for (auto &curEntry : curMap) {
|
|
||||||
if (default_lang == curEntry.first) {
|
|
||||||
*default_index = i;
|
|
||||||
}
|
|
||||||
pair[i].value = curEntry.first;
|
|
||||||
pair[i].valueName = (char *) curEntry.second;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
*len = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
void default_audio_mode_changed(ConfigItemMultipleValues *item, uint32_t newValue) {
|
||||||
|
DEBUG_FUNCTION_LINE("New value in %s changed: %d", item->identifier, newValue);
|
||||||
|
|
||||||
void default_lang_changed(ConfigItemMultipleValues *item, uint32_t newValue) {
|
if (std::string_view(AUDIO_MODE_CONFIG_STRING) == item->identifier) {
|
||||||
DEBUG_FUNCTION_LINE("New value in %s changed: %d", item->configId, newValue);
|
|
||||||
|
|
||||||
if (strcmp(item->configId, SCREEN_MODE_CONFIG_STRING) == 0) {
|
|
||||||
gCurAudioMode = static_cast<SwipSwapAudioMode>(newValue);
|
gCurAudioMode = static_cast<SwipSwapAudioMode>(newValue);
|
||||||
WUPS_StoreInt(nullptr, item->configId, (int32_t) gCurAudioMode);
|
WUPSStorageAPI::Store(item->identifier, (int32_t) gCurAudioMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WUPS_GET_CONFIG() {
|
|
||||||
// We open the storage, so we can persist the configuration the user did.
|
WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle rootHandle) {
|
||||||
if (WUPS_OpenStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
|
try {
|
||||||
DEBUG_FUNCTION_LINE_ERR("Failed to open storage");
|
WUPSConfigCategory root = WUPSConfigCategory(rootHandle);
|
||||||
return 0;
|
|
||||||
|
auto settings = WUPSConfigCategory::Create("Settings");
|
||||||
|
|
||||||
|
|
||||||
|
settings.add(WUPSConfigItemBoolean::Create(ENABLED_CONFIG_STRING,
|
||||||
|
"Plugin enabled",
|
||||||
|
DEFAULT_ENABLED_CONFIG_VALUE, gEnabled,
|
||||||
|
&boolItemChangedConfig));
|
||||||
|
settings.add(WUPSConfigItemBoolean::Create(ENABLE_NOTIFICATIONS_CONFIG_STRING,
|
||||||
|
"Show notifications",
|
||||||
|
DEFAULT_ENABLE_NOTIFICATIONS_CONFIG_VALUE, gShowNotifications,
|
||||||
|
&boolItemChangedConfig));
|
||||||
|
settings.add(WUPSConfigItemBoolean::Create(SWAP_SCREENS_CONFIG_STRING,
|
||||||
|
"Swap screens",
|
||||||
|
DEFAULT_SWAP_SCREENS_CONFIG_VALUE, gDoScreenSwap,
|
||||||
|
&boolItemChangedConfig));
|
||||||
|
|
||||||
|
constexpr WUPSConfigItemMultipleValues::ValuePair audioModeMap[] = {
|
||||||
|
{AUDIO_MODE_NONE, "Normal"},
|
||||||
|
{AUDIO_MODE_SWAP, "Swap TV and GamePad sound"},
|
||||||
|
{AUDIO_MODE_MATCH_SCREEN, "Sound matches screen"},
|
||||||
|
{AUDIO_MODE_COMBINE, "Combine TV and GamePad sound"},
|
||||||
|
{AUDIO_MODE_LEFT_TV_RIGHT_DRC, "Left: TV; Right: GamePad"}};
|
||||||
|
|
||||||
|
settings.add(WUPSConfigItemMultipleValues::CreateFromValue(AUDIO_MODE_CONFIG_STRING,
|
||||||
|
"Audio mode:",
|
||||||
|
DEFAULT_AUDIO_MODE_CONFIG_VALUE, gCurAudioMode,
|
||||||
|
audioModeMap,
|
||||||
|
&default_audio_mode_changed));
|
||||||
|
|
||||||
|
root.add(std::move(settings));
|
||||||
|
|
||||||
|
auto buttonCombos = WUPSConfigCategory::Create("Button Combos");
|
||||||
|
|
||||||
|
buttonCombos.add(WUPSConfigItemBoolean::Create(ENABLED_SWAP_SCREENS_COMBO_CONFIG_STRING,
|
||||||
|
"Enable swap screen button combo",
|
||||||
|
DEFAULT_ENABLED_SWAP_SCREENS_COMBO_CONFIG_VALUE, gSwapScreenButtonComboEnabled,
|
||||||
|
&boolItemChangedConfig));
|
||||||
|
|
||||||
|
buttonCombos.add(WUPSConfigItemButtonCombo::Create(SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING,
|
||||||
|
"Swap screen",
|
||||||
|
DEFAULT_SWAP_SCREEN_BUTTON_COMBO_CONFIG_VALUE, gSwapScreenButtonCombo,
|
||||||
|
&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,
|
||||||
|
&boolItemChangedConfig));
|
||||||
|
|
||||||
|
buttonCombos.add(WUPSConfigItemButtonCombo::Create(CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING,
|
||||||
|
"Change audio",
|
||||||
|
DEFAULT_CHANGE_AUDIO_BUTTON_COMBO_CONFIG_VALUE, gSwapAudioButtonCombo,
|
||||||
|
&buttonComboItemChanged));
|
||||||
|
root.add(std::move(buttonCombos));
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
OSReport("Exception T_T : %s\n", e.what());
|
||||||
|
return WUPSCONFIG_API_CALLBACK_RESULT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
WUPSConfigHandle config;
|
return WUPSCONFIG_API_CALLBACK_RESULT_SUCCESS;
|
||||||
WUPSConfig_CreateHandled(&config, "SwipSwapMe");
|
|
||||||
|
|
||||||
WUPSConfigCategoryHandle setting;
|
|
||||||
WUPSConfig_AddCategoryByNameHandled(config, "Settings", &setting);
|
|
||||||
WUPSConfigCategoryHandle combos;
|
|
||||||
WUPSConfig_AddCategoryByNameHandled(config, "Button combos", &combos);
|
|
||||||
|
|
||||||
std::map<SwipSwapAudioMode, const char *> audioModeMap{
|
|
||||||
{AUDIO_MODE_NONE, "Normal"},
|
|
||||||
{AUDIO_MODE_SWAP, "Swap TV and GamePad sound"},
|
|
||||||
{AUDIO_MODE_MATCH_SCREEN, "Sound matches screen"},
|
|
||||||
{AUDIO_MODE_COMBINE, "Combine TV and GamePad sound"},
|
|
||||||
{AUDIO_MODE_LEFT_TV_RIGHT_DRC, "Left: TV; Right: GamePad"}};
|
|
||||||
|
|
||||||
ConfigItemMultipleValuesPair audioModePairs[audioModeMap.size()];
|
|
||||||
|
|
||||||
uint32_t number_values = 0;
|
|
||||||
uint32_t default_index = 0;
|
|
||||||
getConfigInfoForMap(audioModeMap, audioModePairs, gCurAudioMode, &default_index, &number_values);
|
|
||||||
|
|
||||||
WUPSConfigItemBoolean_AddToCategoryHandled(config, setting, ENABLED_CONFIG_STRING, "Plugin enabled", gEnabled, &boolItemChangedConfig);
|
|
||||||
WUPSConfigItemBoolean_AddToCategoryHandled(config, setting, ENABLE_NOTIFICATIONS_CONFIG_STRING, "Show notifications", gShowNotifications, &boolItemChangedConfig);
|
|
||||||
WUPSConfigItemBoolean_AddToCategoryHandled(config, setting, SWAP_SCREENS_CONFIG_STRING, "Swap screens", gDoScreenSwap, &boolItemChangedConfig);
|
|
||||||
WUPSConfigItemMultipleValues_AddToCategoryHandled(config, setting, SCREEN_MODE_CONFIG_STRING, "Audio mode:", default_index, audioModePairs, number_values,
|
|
||||||
&default_lang_changed);
|
|
||||||
|
|
||||||
WUPSConfigItemBoolean_AddToCategoryHandled(config, combos, ENABLED_SWAP_SCREENS_COMBO_CONFIG_STRING, "Enable swap screen button combo", gSwapScreenButtonComboEnabled, &boolItemChangedConfig);
|
|
||||||
WUPSConfigItemButtonCombo_AddToCategoryHandled(config, combos, SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING, "Swap screen", gSwapScreenButtonCombo, &buttonComboItemChanged);
|
|
||||||
WUPSConfigItemBoolean_AddToCategoryHandled(config, combos, ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING, "Enable change audio mode button combo", gChangeAudioModeButtonComboEnabled, &boolItemChangedConfig);
|
|
||||||
WUPSConfigItemButtonCombo_AddToCategoryHandled(config, combos, CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING, "Change audio", gSwapAudioButtonCombo, &buttonComboItemChanged);
|
|
||||||
|
|
||||||
return config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WUPS_CONFIG_CLOSED() {
|
void ConfigMenuClosedCallback() {
|
||||||
// Save all changes
|
// Save all changes
|
||||||
if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
|
if (WUPSStorageAPI::SaveStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
|
||||||
DEBUG_FUNCTION_LINE_ERR("Failed to close storage");
|
DEBUG_FUNCTION_LINE_ERR("Failed to close storage");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,53 +1,29 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "retain_vars.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vpad/input.h>
|
||||||
#include <wups/config/WUPSConfigItemBoolean.h>
|
#include <wups/config/WUPSConfigItemBoolean.h>
|
||||||
#include <wups/storage.h>
|
#include <wups/storage.h>
|
||||||
|
|
||||||
#define ENABLED_CONFIG_STRING "enabled"
|
#define DEFAULT_ENABLED_CONFIG_VALUE true
|
||||||
#define SWAP_SCREENS_CONFIG_STRING "swapScreens"
|
#define DEFAULT_SWAP_SCREENS_CONFIG_VALUE false
|
||||||
#define ENABLED_SWAP_SCREENS_COMBO_CONFIG_STRING "swapScreensComboEnabled"
|
#define DEFAULT_ENABLED_SWAP_SCREENS_COMBO_CONFIG_VALUE true
|
||||||
#define ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING "changeAudioComboEnabled"
|
#define DEFAULT_ENABLED_CHANGE_AUDIO_COMBO_CONFIG_VALUE false
|
||||||
#define ENABLE_NOTIFICATIONS_CONFIG_STRING "notificationsEnabled"
|
#define DEFAULT_ENABLE_NOTIFICATIONS_CONFIG_VALUE true
|
||||||
#define SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING "screenButtonCombo"
|
#define DEFAULT_SWAP_SCREEN_BUTTON_COMBO_CONFIG_VALUE VPAD_BUTTON_TV
|
||||||
#define CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING "audioButtonCombo"
|
#define DEFAULT_CHANGE_AUDIO_BUTTON_COMBO_CONFIG_VALUE VPAD_BUTTON_STICK_L
|
||||||
#define SCREEN_MODE_CONFIG_STRING "audioMode"
|
#define DEFAULT_AUDIO_MODE_CONFIG_VALUE AUDIO_MODE_MATCH_SCREEN
|
||||||
|
|
||||||
#define LOAD_BOOL_FROM_STORAGE(config_name, __variable__) \
|
#define ENABLED_CONFIG_STRING "enabled"
|
||||||
if ((storageRes = WUPS_GetBool(nullptr, config_name, &__variable__)) == WUPS_STORAGE_ERROR_NOT_FOUND) { \
|
#define SWAP_SCREENS_CONFIG_STRING "swapScreens"
|
||||||
if (WUPS_StoreBool(nullptr, config_name, __variable__) != WUPS_STORAGE_ERROR_SUCCESS) { \
|
#define ENABLED_SWAP_SCREENS_COMBO_CONFIG_STRING "swapScreensComboEnabled"
|
||||||
DEBUG_FUNCTION_LINE_WARN("Failed to store bool"); \
|
#define ENABLED_CHANGE_AUDIO_COMBO_CONFIG_STRING "changeAudioComboEnabled"
|
||||||
} \
|
#define ENABLE_NOTIFICATIONS_CONFIG_STRING "notificationsEnabled"
|
||||||
} else if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { \
|
#define SWAP_SCREEN_BUTTON_COMBO_CONFIG_STRING "screenButtonCombo"
|
||||||
DEBUG_FUNCTION_LINE_WARN("Failed to get bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); \
|
#define CHANGE_AUDIO_BUTTON_COMBO_CONFIG_STRING "audioButtonCombo"
|
||||||
} \
|
#define AUDIO_MODE_CONFIG_STRING "audioMode"
|
||||||
while (0)
|
|
||||||
|
|
||||||
#define LOAD_STRING_FROM_STORAGE(config_name, __string, __string_length) \
|
WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle rootHandle);
|
||||||
if ((storageRes = WUPS_GetString(nullptr, config_name, __string, __string_length)) == WUPS_STORAGE_ERROR_NOT_FOUND) { \
|
|
||||||
if (WUPS_StoreString(nullptr, config_name, __string) != WUPS_STORAGE_ERROR_SUCCESS) { \
|
|
||||||
DEBUG_FUNCTION_LINE_WARN("Failed to store string"); \
|
|
||||||
} \
|
|
||||||
} else if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { \
|
|
||||||
DEBUG_FUNCTION_LINE_WARN("Failed to get bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); \
|
|
||||||
} \
|
|
||||||
while (0)
|
|
||||||
|
|
||||||
#define LOAD_INT_FROM_STORAGE(config_name, __intValue) \
|
void ConfigMenuClosedCallback();
|
||||||
if ((storageRes = WUPS_GetInt(nullptr, config_name, (int32_t *) &__intValue)) == WUPS_STORAGE_ERROR_NOT_FOUND) { \
|
|
||||||
if (WUPS_StoreInt(nullptr, config_name, (int32_t) __intValue) != WUPS_STORAGE_ERROR_SUCCESS) { \
|
|
||||||
DEBUG_FUNCTION_LINE_WARN("Failed to store int"); \
|
|
||||||
} \
|
|
||||||
} else if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { \
|
|
||||||
DEBUG_FUNCTION_LINE_WARN("Failed to get int %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); \
|
|
||||||
} \
|
|
||||||
while (0)
|
|
||||||
|
|
||||||
#define PROCESS_BOOL_ITEM_CHANGED(__config__name, __variable__) \
|
|
||||||
if (std::string_view(item->configId) == __config__name) { \
|
|
||||||
DEBUG_FUNCTION_LINE_ERR("New value in %s: %d", __config__name, newValue); \
|
|
||||||
__variable__ = newValue; \
|
|
||||||
WUPS_StoreInt(nullptr, __config__name, __variable__); \
|
|
||||||
return; \
|
|
||||||
} \
|
|
||||||
while (0)
|
|
Loading…
Reference in New Issue
Block a user