Skip to content

Commit

Permalink
game menu: add default global config for game settings
Browse files Browse the repository at this point in the history
  • Loading branch information
KrahJohlito committed Oct 29, 2019
1 parent 81a94ed commit e380881
Show file tree
Hide file tree
Showing 18 changed files with 496 additions and 145 deletions.
7 changes: 6 additions & 1 deletion include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ enum CONFIG_INDEX {
CONFIG_INDEX_LAST,
CONFIG_INDEX_APPS,
CONFIG_INDEX_NETWORK,
CONFIG_INDEX_GAME,

CONFIG_INDEX_COUNT
};
Expand All @@ -16,13 +17,14 @@ enum CONFIG_INDEX {
#define CONFIG_LAST (1 << CONFIG_INDEX_LAST)
#define CONFIG_APPS (1 << CONFIG_INDEX_APPS)
#define CONFIG_NETWORK (1 << CONFIG_INDEX_NETWORK)
#define CONFIG_GAME (1 << CONFIG_INDEX_GAME)
#define CONFIG_ALL 0xFF

#define CONFIG_SOURCE_DEFAULT 0
#define CONFIG_SOURCE_USER 1
#define CONFIG_SOURCE_DLOAD 2 //Downloaded from the network

//Items for game config files.
//Items for per-game config files.
#define CONFIG_ITEM_NAME "#Name"
#define CONFIG_ITEM_LONGNAME "#LongName"
#define CONFIG_ITEM_SIZE "#Size"
Expand All @@ -37,16 +39,19 @@ enum CONFIG_INDEX {
#define CONFIG_ITEM_CONFIGSOURCE "$ConfigSource"

//Per-Game GSM keys. -Bat-
#define CONFIG_ITEM_GSMSOURCE "$GSMSource"
#define CONFIG_ITEM_ENABLEGSM "$EnableGSM"
#define CONFIG_ITEM_GSMVMODE "$GSMVMode"
#define CONFIG_ITEM_GSMXOFFSET "$GSMXOffset"
#define CONFIG_ITEM_GSMYOFFSET "$GSMYOffset"
#define CONFIG_ITEM_GSMFIELDFIX "$GSMFIELDFix"

//Per-Game CHEAT keys. -Bat-
#define CONFIG_ITEM_CHEATSSOURCE "$CheatsSource"
#define CONFIG_ITEM_ENABLECHEAT "$EnableCheat"
#define CONFIG_ITEM_CHEATMODE "$CheatMode"

#define CONFIG_ITEM_PADEMUSOURCE "$PADEMUSource"
#define CONFIG_ITEM_ENABLEPADEMU "$EnablePadEmu"
#define CONFIG_ITEM_PADEMUSETTINGS "$PadEmuSettings"

Expand Down
3 changes: 3 additions & 0 deletions include/dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ enum UI_ITEMS {
NETCFG_RECONNECT,
NETCFG_OK,

CHTCFG_CHEATSOURCE,
CHTCFG_CHEATCFG,
CHTCFG_ENABLECHEAT,
CHTCFG_CHEATMODE,

GSMCFG_GSMSOURCE,
GSMCFG_GSCONFIG,
GSMCFG_ENABLEGSM,
GSMCFG_GSMVMODE,
Expand Down Expand Up @@ -128,6 +130,7 @@ enum UI_ITEMS {
NETUPD_BTN_START,
NETUPD_BTN_CANCEL,
#ifdef PADEMU
PADCFG_PADEMU_SOURCE,
PADCFG_PADEMU_CONFIG,
PADCFG_PADEMU_ENABLE,
PADCFG_PADEMU_MODE,
Expand Down
4 changes: 4 additions & 0 deletions include/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ void guiCheckNotifications(int checkTheme, int checkLang);
*/
void guiHandleDeferedIO(int *ptr, const unsigned char *message, int type, void *data);

void guiGameHandleDeferedIO(int *ptr, struct UIItem *ui, int type, void *data);

/** Renders a single frame with a specified message on the screen
*/
void guiRenderTextScreen(const unsigned char *message);
Expand All @@ -151,4 +153,6 @@ void guiWarning(const char *text, int count);

int guiConfirmVideoMode(void);

int guiGameShowRemoveSettings(config_set_t *configSet, config_set_t *configGame);

#endif
9 changes: 7 additions & 2 deletions include/guigame.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ifndef __GUIGAME_H
#define __GUIGAME_H

#define SETTINGS_GLOBAL 0
#define SETTINGS_PERGAME 1

int guiGameAltStartupNameHandler(char *text, int maxLen);

char *gameConfigSource(void);
Expand All @@ -13,7 +16,9 @@ void guiGameShowCheatConfig(void);
void guiGameShowPadEmuConfig(void);

void guiGameLoadConfig(item_list_t *support, config_set_t *configSet);
void guiGameSaveConfig(config_set_t *configSet, item_list_t *support);
void guiGameRemoveSettings(config_set_t *configSet);
int guiGameSaveConfig(config_set_t *configSet, item_list_t *support);
void guiGameTestSettings(int id, item_list_t *support, config_set_t *configSet);

void guiGameRemoveSettings(config_set_t *configSet);
void guiGameRemoveGlobalSettings(config_set_t *configGame);
#endif
5 changes: 5 additions & 0 deletions include/lang.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ enum _STR_IDS {
_STR_GAME_SETTINGS_SAVED,
_STR_GAME_SETTINGS_REMOVED,
_STR_NET_UPDATE_HINT,
_STR_SETTINGS_SOURCE,
_STR_GLOBAL_SETTINGS,
_STR_PERGAME_SETTINGS,
_STR_ALL_SETTINGS,
_STR_GAME_SETTINGS_PROMPT,

LANG_STR_COUNT
};
Expand Down
2 changes: 2 additions & 0 deletions include/menusys.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <gsToolkit.h>
#include "include/config.h"
#include "include/dia.h"

/// a single submenu item
typedef struct submenu_item
Expand Down Expand Up @@ -94,6 +95,7 @@ void submenuSort(submenu_list_t **submenu);
char *submenuItemGetText(submenu_item_t *it);
char *menuItemGetText(menu_item_t *it);
config_set_t *menuLoadConfig();
config_set_t *gameMenuLoadConfig(struct UIItem *ui);
void menuSaveConfig();

void menuRenderMain();
Expand Down
4 changes: 4 additions & 0 deletions include/opl.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ int gEnableBootSND;
int gSFXVolume;
int gBootSndVolume;

int gCheatSource;
int gGSMSource;
int gPadEmuSource;

int gFadeDelay;
int toggleSfx;

Expand Down
9 changes: 7 additions & 2 deletions lng/lang_English.lng
Original file line number Diff line number Diff line change
Expand Up @@ -288,5 +288,10 @@ Enable Notifications
%s loaded from %s
Game Menu
Game settings saved.
Game settings removed.
Overwrites existing game compatibility settings when enabled.
%s settings removed.
Overwrites existing game compatibility settings when enabled.
Settings Mode
Global
Per Game
All
Select settings to remove.
16 changes: 13 additions & 3 deletions src/cheatman.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,24 @@ static int gCheatList[MAX_CHEATLIST]; //Store hooks/codes addr+val pairs

void InitCheatsConfig(config_set_t *configSet)
{
config_set_t *configGame = configGetByType(CONFIG_GAME);

//Default values.
gCheatSource = 0;
gEnableCheat = 0;
gCheatMode = 0;
memset(gCheatList, 0, sizeof(gCheatList));

//Load the rest of the per-game CHEAT configuration if CHEAT is enabled.
if (configGetInt(configSet, CONFIG_ITEM_ENABLECHEAT, &gEnableCheat) && gEnableCheat) {
configGetInt(configSet, CONFIG_ITEM_CHEATMODE, &gCheatMode);
if (configGetInt(configSet, CONFIG_ITEM_CHEATSSOURCE, &gCheatSource)) {
//Load the rest of the per-game CHEAT configuration if CHEAT is enabled.
if (configGetInt(configSet, CONFIG_ITEM_ENABLECHEAT, &gEnableCheat) && gEnableCheat) {
configGetInt(configSet, CONFIG_ITEM_CHEATMODE, &gCheatMode);
}
}
else {
if (configGetInt(configGame, CONFIG_ITEM_ENABLECHEAT, &gEnableCheat) && gEnableCheat) {
configGetInt(configGame, CONFIG_ITEM_CHEATMODE, &gCheatMode);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ static const char *configFilenames[CONFIG_INDEX_COUNT] = {
"conf_last.cfg",
"conf_apps.cfg",
"conf_network.cfg",
"conf_game.cfg",
};

static int strToColor(const char *string, unsigned char *color)
Expand Down
21 changes: 19 additions & 2 deletions src/dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,12 @@ struct UIItem diaGSConfig[] = {
{UI_LABEL, 0, 1, 1, -1, 0, 0, {.label = {NULL, _STR_GSM_SETTINGS}}},
{UI_SPLITTER},

{UI_LABEL, 0, 1, 1, -1, -40, 0, {.label = {NULL, _STR_SETTINGS_SOURCE}}},
{UI_SPACER},
{UI_ENUM, GSMCFG_GSMSOURCE, 1, 1, -1, 0, 0, {.intvalue = {0, 0}}},
{UI_BREAK},
{UI_BREAK},

{UI_LABEL, 0, 1, 1, -1, -40, 0, {.label = {NULL, _STR_ENABLEGSM}}},
{UI_SPACER},
{UI_BOOL, GSMCFG_ENABLEGSM, 1, 1, _STR_HINT_ENABLEGSM, 0, 0, {.intvalue = {1, 1}}},
Expand Down Expand Up @@ -489,6 +495,12 @@ struct UIItem diaCheatConfig[] = {
{UI_LABEL, 0, 1, 1, -1, 0, 0, {.label = {NULL, _STR_CHEAT_SETTINGS}}},
{UI_SPLITTER},

{UI_LABEL, 0, 1, 1, -1, -40, 0, {.label = {NULL, _STR_SETTINGS_SOURCE}}},
{UI_SPACER},
{UI_ENUM, CHTCFG_CHEATSOURCE, 1, 1, -1, 0, 0, {.intvalue = {0, 0}}},
{UI_BREAK},
{UI_BREAK},

{UI_LABEL, 0, 1, 1, -1, -40, 0, {.label = {NULL, _STR_ENABLECHEAT}}},
{UI_SPACER},
{UI_BOOL, CHTCFG_ENABLECHEAT, 1, 1, _STR_HINT_ENABLECHEAT, 0, 0, {.intvalue = {1, 1}}},
Expand All @@ -508,10 +520,15 @@ struct UIItem diaCheatConfig[] = {

#ifdef PADEMU
struct UIItem diaPadEmuConfig[] = {
{UI_LABEL, 0, 1, 1, -1, 0, 0, {.label = {NULL, _STR_PADEMU_SETTINGS}}}, {UI_SPACER},

{UI_LABEL, 0, 1, 1, -1, 0, 0, {.label = {NULL, _STR_PADEMU_SETTINGS}}},
{UI_SPLITTER},

{UI_LABEL, 0, 1, 1, -1, -45, 0, {.label = {NULL, _STR_SETTINGS_SOURCE}}},
{UI_SPACER},
{UI_ENUM, PADCFG_PADEMU_SOURCE, 1, 1, -1, 0, 0, {.intvalue = {0, 0}}},
{UI_BREAK},
{UI_BREAK},

{UI_LABEL, 0, 1, 1, -1, -45, 0, {.label = {NULL, _STR_PADEMU_ENABLE}}},
{UI_SPACER},
{UI_BOOL, PADCFG_PADEMU_ENABLE, 1, 1, _STR_HINT_PADEMU_ENABLE, 0, 0, {.intvalue = {1, 1}}},
Expand Down
25 changes: 19 additions & 6 deletions src/gsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,32 @@ static int gGSMFIELDFix; // Enables/disables the FIELD flipping emulation option

void InitGSMConfig(config_set_t *configSet)
{
config_set_t *configGame = configGetByType(CONFIG_GAME);

//Default values.
gGSMSource = 0;
gEnableGSM = 0;
gGSMVMode = 0;
gGSMXOffset = 0;
gGSMYOffset = 0;
gGSMFIELDFix = 0;

//Load the rest of the per-game GSM configuration, only if GSM is enabled.
if (configGetInt(configSet, CONFIG_ITEM_ENABLEGSM, &gEnableGSM) && gEnableGSM) {
configGetInt(configSet, CONFIG_ITEM_GSMVMODE, &gGSMVMode);
configGetInt(configSet, CONFIG_ITEM_GSMXOFFSET, &gGSMXOffset);
configGetInt(configSet, CONFIG_ITEM_GSMYOFFSET, &gGSMYOffset);
configGetInt(configSet, CONFIG_ITEM_GSMFIELDFIX, &gGSMFIELDFix);
if (configGetInt(configSet, CONFIG_ITEM_GSMSOURCE, &gGSMSource)) {
//Load the rest of the per-game GSM configuration, only if GSM is enabled.
if (configGetInt(configSet, CONFIG_ITEM_ENABLEGSM, &gEnableGSM) && gEnableGSM) {
configGetInt(configSet, CONFIG_ITEM_GSMVMODE, &gGSMVMode);
configGetInt(configSet, CONFIG_ITEM_GSMXOFFSET, &gGSMXOffset);
configGetInt(configSet, CONFIG_ITEM_GSMYOFFSET, &gGSMYOffset);
configGetInt(configSet, CONFIG_ITEM_GSMFIELDFIX, &gGSMFIELDFix);
}
}
else {
if (configGetInt(configGame, CONFIG_ITEM_ENABLEGSM, &gEnableGSM) && gEnableGSM) {
configGetInt(configGame, CONFIG_ITEM_GSMVMODE, &gGSMVMode);
configGetInt(configGame, CONFIG_ITEM_GSMXOFFSET, &gGSMXOffset);
configGetInt(configGame, CONFIG_ITEM_GSMYOFFSET, &gGSMYOffset);
configGetInt(configGame, CONFIG_ITEM_GSMFIELDFIX, &gGSMFIELDFix);
}
}
}

Expand Down
79 changes: 76 additions & 3 deletions src/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "include/pggsm.h"
#include "include/cheatman.h"
#include "include/sound.h"
#include "include/guigame.h"

#include <limits.h>
#include <stdlib.h>
Expand Down Expand Up @@ -1244,14 +1245,14 @@ int guiAlignSubMenuHints(int hintCount, int *textID, int *iconID, int font, int
void guiDrawSubMenuHints(void)
{
int subMenuHints[2] = {_STR_SELECT, _STR_GAMES_LIST};
int subMenuIcons[2] = {CROSS_ICON, CIRCLE_ICON};
int subMenuIcons[2] = {CIRCLE_ICON, CROSS_ICON};

int x = guiAlignSubMenuHints(2, subMenuHints, subMenuIcons, gTheme->fonts[0], 12, 2);
int y = gTheme->usedHeight - 32;

x = guiDrawIconAndText(gSelectButton == KEY_CIRCLE ? subMenuIcons[1] : subMenuIcons[0], subMenuHints[0], gTheme->fonts[0], x, y, gTheme->textColor);
x = guiDrawIconAndText(gSelectButton == KEY_CIRCLE ? subMenuIcons[0] : subMenuIcons[1], subMenuHints[0], gTheme->fonts[0], x, y, gTheme->textColor);
x += 12;
x = guiDrawIconAndText(gSelectButton == KEY_CIRCLE ? subMenuIcons[0] : subMenuIcons[1], subMenuHints[1], gTheme->fonts[0], x, y, gTheme->textColor);
x = guiDrawIconAndText(gSelectButton == KEY_CIRCLE ? subMenuIcons[1] : subMenuIcons[0], subMenuHints[1], gTheme->fonts[0], x, y, gTheme->textColor);
}

static void guiDrawOverlays()
Expand Down Expand Up @@ -1536,6 +1537,20 @@ void guiHandleDeferedIO(int *ptr, const unsigned char *message, int type, void *
guiRenderTextScreen(message);
}

void guiGameHandleDeferedIO(int *ptr, struct UIItem *ui, int type, void *data)
{
ioPutRequest(type, data);

while (*ptr) {
guiStartFrame();
if (ui)
diaRenderUI(ui, screenHandler->inMenu, NULL, 0);
else
guiShow();
guiEndFrame();
}
}

void guiRenderTextScreen(const unsigned char *message)
{
guiStartFrame();
Expand Down Expand Up @@ -1616,3 +1631,61 @@ int guiConfirmVideoMode(void)

return terminate - 1;
}

int guiGameShowRemoveSettings(config_set_t *configSet, config_set_t *configGame)
{
int terminate = 0;
char message[128];

sfxPlay(SFX_MESSAGE);

while (!terminate) {
guiStartFrame();

readPads();

if (getKeyOn(gSelectButton == KEY_CIRCLE ? KEY_CROSS : KEY_CIRCLE))
terminate = 1;
else if (getKeyOn(gSelectButton))
terminate = 2;
else if (getKeyOn(KEY_SQUARE))
terminate = 3;
else if (getKeyOn(KEY_TRIANGLE))
terminate = 4;

guiShow();

rmDrawRect(0, 0, screenWidth, screenHeight, gColDarker);

rmDrawLine(50, 75, screenWidth - 50, 75, gColWhite);
rmDrawLine(50, 410, screenWidth - 50, 410, gColWhite);

fntRenderString(gTheme->fonts[0], screenWidth >> 1, gTheme->usedHeight >> 1, ALIGN_CENTER, 0, 0, _l(_STR_GAME_SETTINGS_PROMPT), gTheme->textColor);

guiDrawIconAndText(gSelectButton == KEY_CIRCLE ? CROSS_ICON : CIRCLE_ICON, _STR_BACK, gTheme->fonts[0], 500, 417, gTheme->selTextColor);
guiDrawIconAndText(SQUARE_ICON, _STR_GLOBAL_SETTINGS, gTheme->fonts[0], 213, 417, gTheme->selTextColor);
guiDrawIconAndText(TRIANGLE_ICON, _STR_ALL_SETTINGS, gTheme->fonts[0], 356, 417, gTheme->selTextColor);
guiDrawIconAndText(gSelectButton == KEY_CIRCLE ? CIRCLE_ICON : CROSS_ICON, _STR_PERGAME_SETTINGS, gTheme->fonts[0], 70, 417, gTheme->selTextColor);

guiEndFrame();
}

if (terminate == 1) {
sfxPlay(SFX_CANCEL);
return 0;
} else if (terminate == 2) {
guiGameRemoveSettings(configSet);
snprintf(message, sizeof(message), _l(_STR_GAME_SETTINGS_REMOVED), _l(_STR_PERGAME_SETTINGS));
} else if (terminate == 3) {
guiGameRemoveGlobalSettings(configGame);
snprintf(message, sizeof(message), _l(_STR_GAME_SETTINGS_REMOVED), _l(_STR_GLOBAL_SETTINGS));
} else if (terminate == 4) {
guiGameRemoveSettings(configSet);
guiGameRemoveGlobalSettings(configGame);
snprintf(message, sizeof(message), _l(_STR_GAME_SETTINGS_REMOVED), _l(_STR_ALL_SETTINGS));
}
sfxPlay(SFX_CONFIRM);
guiMsgBox(message, 0, NULL);

return 1;
}

0 comments on commit e380881

Please sign in to comment.