Skip to content

Commit

Permalink
add global pademu to controller settings
Browse files Browse the repository at this point in the history
  • Loading branch information
KrahJohlito committed Jul 4, 2021
1 parent e76c30f commit 5202986
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 28 deletions.
1 change: 1 addition & 0 deletions include/dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ enum UI_ITEMS {
NETUPD_BTN_START,
NETUPD_BTN_CANCEL,
#ifdef PADEMU
PADEMU_GLOBAL_BUTTON,
PADCFG_PADEMU_SOURCE,
PADCFG_PADEMU_CONFIG,
PADCFG_PADEMU_ENABLE,
Expand Down
6 changes: 5 additions & 1 deletion include/guigame.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ void guiGameShowVMCMenu(int id, item_list_t *support);
void guiGameShowCompatConfig(int id, item_list_t *support, config_set_t *configSet);
void guiGameShowGSConfig(void);
void guiGameShowCheatConfig(void);
void guiGameShowPadEmuConfig(void);

#ifdef PADEMU
void guiGameShowPadEmuConfig(int forceGlobal);
void guiGameSavePadEmuGlobalConfig(config_set_t *configGame);
#endif

void guiGameLoadConfig(item_list_t *support, config_set_t *configSet);
int guiGameSaveConfig(config_set_t *configSet, item_list_t *support);
Expand Down
6 changes: 5 additions & 1 deletion src/dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,11 @@ struct UIItem diaControllerConfig[] = {
{UI_SPACER},
{UI_ENUM, CFG_SELECTBUTTON, 1, 1, -1, 0, 0, {.intvalue = {0, 0}}},
{UI_BREAK},

#ifdef PADEMU
{UI_BREAK},
{UI_BUTTON, PADEMU_GLOBAL_BUTTON, 1, 1, -1, 0, 0, {.label = {NULL, _STR_PADEMUCONFIG}}},
{UI_BREAK},
#endif
// buttons
{UI_OK, 0, 1, 1, -1, 0, 0, {.label = {NULL, _STR_OK}}},
{UI_BREAK},
Expand Down
5 changes: 4 additions & 1 deletion src/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,10 @@ void guiShowControllerConfig(void)
gSelectButton = value == 0 ? KEY_CIRCLE : KEY_CROSS;
else
gSelectButton = KEY_CIRCLE;

#ifdef PADEMU
if (result == PADEMU_GLOBAL_BUTTON)
guiGameShowPadEmuConfig(1);
#endif
applyConfig(-1, -1);
}
}
Expand Down
73 changes: 49 additions & 24 deletions src/guigame.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ static int dgmacset = 0;
static int dg_discon = 0;
static int ver_set = 0, feat_set = 0;

static int forceGlobalPadEmu;

static char *bdaddr_to_str(u8 *bdaddr, char *addstr)
{
snprintf(addstr, 18, "%02X:%02X:%02X:%02X:%02X:%02X", bdaddr[0], bdaddr[1], bdaddr[2], bdaddr[3], bdaddr[4], bdaddr[5]);
Expand Down Expand Up @@ -662,13 +664,19 @@ static int guiGamePadEmuInfoUpdater(int modified)
return 0;
}

void guiGameShowPadEmuConfig(void)
void guiGameShowPadEmuConfig(int forceGlobal)
{
const char *settingsSource[] = {_l(_STR_GLOBAL_SETTINGS), _l(_STR_PERGAME_SETTINGS), NULL};
const char *PadEmuModes[] = {_l(_STR_DS34USB_MODE), _l(_STR_DS34BT_MODE), NULL};

int PadEmuMtap, PadEmuMtapPort, i;

forceGlobalPadEmu = forceGlobal;
diaSetEnabled(diaPadEmuConfig, PADCFG_PADEMU_SOURCE, !forceGlobalPadEmu);

if (forceGlobalPadEmu)
guiGameLoadPadEmuConfig(NULL, configGetByType(CONFIG_GAME));

diaSetEnum(diaPadEmuConfig, PADCFG_PADEMU_SOURCE, settingsSource);
diaSetEnum(diaPadEmuConfig, PADCFG_PADEMU_MODE, PadEmuModes);

Expand Down Expand Up @@ -731,6 +739,36 @@ void guiGameShowPadEmuConfig(void)
break;
}
}

static int guiGameSavePadEmuGameConfig(config_set_t *configSet, int result)
{
if (gPadEmuSource == SETTINGS_PERGAME) {
diaGetInt(diaPadEmuConfig, PADCFG_PADEMU_ENABLE, &EnablePadEmu);

result = configSetInt(configSet, CONFIG_ITEM_PADEMUSOURCE, gPadEmuSource);
if (EnablePadEmu != 0)
result = configSetInt(configSet, CONFIG_ITEM_ENABLEPADEMU, EnablePadEmu);
else
configRemoveKey(configSet, CONFIG_ITEM_ENABLEPADEMU);

if (PadEmuSettings != 0)
result = configSetInt(configSet, CONFIG_ITEM_PADEMUSETTINGS, PadEmuSettings);
else
configRemoveKey(configSet, CONFIG_ITEM_PADEMUSETTINGS);
}

return result;
}

void guiGameSavePadEmuGlobalConfig(config_set_t *configGame)
{
if (gPadEmuSource == SETTINGS_GLOBAL) {
diaGetInt(diaPadEmuConfig, PADCFG_PADEMU_ENABLE, &EnablePadEmu);

configSetInt(configGame, CONFIG_ITEM_ENABLEPADEMU, EnablePadEmu);
configSetInt(configGame, CONFIG_ITEM_PADEMUSETTINGS, PadEmuSettings);
}
}
#endif

void guiGameShowCompatConfig(int id, item_list_t *support, config_set_t *configSet)
Expand Down Expand Up @@ -861,23 +899,8 @@ int guiGameSaveConfig(config_set_t *configSet, item_list_t *support)

#ifdef PADEMU
/// PADEMU ///
diaGetInt(diaPadEmuConfig, PADCFG_PADEMU_ENABLE, &EnablePadEmu);

if (gPadEmuSource == SETTINGS_PERGAME) {
result = configSetInt(configSet, CONFIG_ITEM_PADEMUSOURCE, gPadEmuSource);
if (EnablePadEmu != 0)
result = configSetInt(configSet, CONFIG_ITEM_ENABLEPADEMU, EnablePadEmu);
else
configRemoveKey(configSet, CONFIG_ITEM_ENABLEPADEMU);

if (PadEmuSettings != 0)
result = configSetInt(configSet, CONFIG_ITEM_PADEMUSETTINGS, PadEmuSettings);
else
configRemoveKey(configSet, CONFIG_ITEM_PADEMUSETTINGS);
} else if (gPadEmuSource == SETTINGS_GLOBAL) {
configSetInt(configGame, CONFIG_ITEM_ENABLEPADEMU, EnablePadEmu);
configSetInt(configGame, CONFIG_ITEM_PADEMUSETTINGS, PadEmuSettings);
}
result = guiGameSavePadEmuGameConfig(configSet, result);
guiGameSavePadEmuGlobalConfig(configGame);
#endif

diaGetString(diaCompatConfig, COMPAT_GAMEID, hexid, sizeof(hexid));
Expand Down Expand Up @@ -1039,12 +1062,14 @@ static void guiGameLoadPadEmuConfig(config_set_t *configSet, config_set_t *confi
configGetInt(configGame, CONFIG_ITEM_PADEMUSETTINGS, &PadEmuSettings);

// override global with per-game settings if available and selected.
configGetInt(configSet, CONFIG_ITEM_PADEMUSOURCE, &gPadEmuSource);
if (gPadEmuSource == SETTINGS_PERGAME) {
if (!configGetInt(configSet, CONFIG_ITEM_ENABLEPADEMU, &EnablePadEmu))
EnablePadEmu = 0;
if (!configGetInt(configSet, CONFIG_ITEM_PADEMUSETTINGS, &PadEmuSettings))
PadEmuSettings = 0;
if (!forceGlobalPadEmu) {
configGetInt(configSet, CONFIG_ITEM_PADEMUSOURCE, &gPadEmuSource);
if (gPadEmuSource == SETTINGS_PERGAME) {
if (!configGetInt(configSet, CONFIG_ITEM_ENABLEPADEMU, &EnablePadEmu))
EnablePadEmu = 0;
if (!configGetInt(configSet, CONFIG_ITEM_PADEMUSETTINGS, &PadEmuSettings))
PadEmuSettings = 0;
}
}
// set gui settings.
int PadEmuMtap = (PadEmuSettings >> 24) & 1;
Expand Down
6 changes: 5 additions & 1 deletion src/menusys.c
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,10 @@ void menuHandleInputMenu()
} else if (id == MENU_SAVE_CHANGES) {
if (menuCheckParentalLock() == 0) {
saveConfig(CONFIG_OPL | CONFIG_NETWORK, 1);
#ifdef PADEMU
guiGameSavePadEmuGlobalConfig(configGetByType(CONFIG_GAME));
saveConfig(CONFIG_GAME, 0);
#endif
menuSetParentalLockCheckState(1); // Re-enable parental lock check.
}
} else if (id == MENU_EXIT) {
Expand Down Expand Up @@ -1067,7 +1071,7 @@ void menuHandleInputGameMenu()
guiGameShowVMCMenu(selected_item->item->current->item.id, selected_item->item->userdata);
#ifdef PADEMU
} else if (menuID == GAME_PADEMU_SETTINGS) {
guiGameShowPadEmuConfig();
guiGameShowPadEmuConfig(0);
#endif
} else if (menuID == GAME_SAVE_CHANGES) {
if (guiGameSaveConfig(itemConfig, selected_item->item->userdata))
Expand Down

0 comments on commit 5202986

Please sign in to comment.