Re3/src/extras/frontendoption.cpp

183 lines
5.6 KiB
C++
Raw Normal View History

#include "common.h"
#ifdef CUSTOM_FRONTEND_OPTIONS
2020-10-27 22:11:34 -04:00
#include "Frontend.h"
2020-08-24 15:42:26 -04:00
#include "Text.h"
2020-10-27 22:11:34 -04:00
int lastOgScreen = MENUPAGES; // means no new pages
2020-10-27 22:11:34 -04:00
int numCustomFrontendOptions = 0;
2020-08-24 15:42:26 -04:00
int numCustomFrontendScreens = 0;
int optionCursor = -2;
int currentMenu;
bool optionOverwrite = false;
void ChangeScreen(int screen, int option, bool fadeIn)
{
FrontEndMenuManager.m_nPrevScreen = FrontEndMenuManager.m_nCurrScreen;
FrontEndMenuManager.m_nCurrScreen = screen;
FrontEndMenuManager.m_nCurrOption = option;
if (fadeIn)
FrontEndMenuManager.m_nMenuFadeAlpha = 0;
}
void GoBack(bool fadeIn)
{
int screen = !FrontEndMenuManager.m_bGameNotLoaded ?
aScreens[FrontEndMenuManager.m_nCurrScreen].m_PreviousPage[1] : aScreens[FrontEndMenuManager.m_nCurrScreen].m_PreviousPage[0];
2020-10-27 22:11:34 -04:00
int option = FrontEndMenuManager.GetPreviousPageOption();
FrontEndMenuManager.ThingsToDoBeforeGoingBack();
2020-08-24 15:42:26 -04:00
ChangeScreen(screen, option, fadeIn);
}
uint8
GetNumberOfMenuOptions(int screen)
{
uint8 Rows = 0;
for (int i = 0; i < NUM_MENUROWS; i++) {
if (aScreens[screen].m_aEntries[i].m_Action == MENUACTION_NOTHING)
break;
++Rows;
}
return Rows;
}
2020-08-24 15:42:26 -04:00
uint8
GetLastMenuScreen()
{
int8 page = -1;
2020-08-24 15:42:26 -04:00
for (int i = 0; i < MENUPAGES; i++) {
2020-10-27 22:11:34 -04:00
if (strcmp(aScreens[i].m_ScreenName, "") == 0 && aScreens[i].m_PreviousPage[0] == MENUPAGE_NONE)
2020-08-24 15:42:26 -04:00
break;
++page;
}
return page;
}
2020-10-27 22:11:34 -04:00
int8 RegisterNewScreen(const char *name, int prevPage, ReturnPrevPageFunc returnPrevPageFunc)
2020-08-24 15:42:26 -04:00
{
if (lastOgScreen == MENUPAGES)
lastOgScreen = GetLastMenuScreen();
numCustomFrontendScreens++;
int id = lastOgScreen + numCustomFrontendScreens;
assert(id < MENUPAGES && "No room for new custom frontend screens! Increase MENUPAGES");
strncpy(aScreens[id].m_ScreenName, name, 8);
aScreens[id].m_PreviousPage[0] = aScreens[id].m_PreviousPage[1] = prevPage;
2020-10-27 22:11:34 -04:00
aScreens[id].returnPrevPageFunc = returnPrevPageFunc;
2020-08-24 15:42:26 -04:00
return id;
}
2020-08-24 15:42:26 -04:00
int8 RegisterNewOption()
{
numCustomFrontendOptions++;
2020-08-24 15:42:26 -04:00
uint8 numOptions = GetNumberOfMenuOptions(currentMenu);
uint8 curIdx;
if (optionCursor < 0) {
2020-08-24 15:42:26 -04:00
optionCursor = curIdx = numOptions + optionCursor + 1;
} else
curIdx = optionCursor;
if (!optionOverwrite) {
if (aScreens[currentMenu].m_aEntries[curIdx].m_Action != MENUACTION_NOTHING) {
for (int i = numOptions - 1; i >= curIdx; i--) {
2020-10-27 22:11:34 -04:00
memcpy(&aScreens[currentMenu].m_aEntries[i + 1], &aScreens[currentMenu].m_aEntries[i], sizeof(CMenuScreenCustom::CMenuEntry));
}
}
2020-08-24 15:42:26 -04:00
}
optionCursor++;
return curIdx;
}
2020-08-24 15:42:26 -04:00
void FrontendOptionSetCursor(int screen, int8 option, bool overwrite)
{
currentMenu = screen;
optionCursor = option;
2020-08-24 15:42:26 -04:00
optionOverwrite = overwrite;
}
2020-10-27 22:11:34 -04:00
void FrontendOptionAddBuiltinAction(const char* gxtKey, int action, int targetMenu, int saveSlot) {
2020-08-24 15:42:26 -04:00
int8 screenOptionOrder = RegisterNewOption();
2020-10-27 22:11:34 -04:00
CMenuScreenCustom::CMenuEntry &option = aScreens[currentMenu].m_aEntries[screenOptionOrder];
2020-08-24 15:42:26 -04:00
2020-10-27 22:11:34 -04:00
// We can't use custom text on those :shrug:
2020-08-24 15:42:26 -04:00
switch (action) {
case MENUACTION_SCREENRES:
2020-10-27 22:11:34 -04:00
strcpy(option.m_EntryName, "FED_RES");
2020-08-24 15:42:26 -04:00
break;
case MENUACTION_AUDIOHW:
2020-10-27 22:11:34 -04:00
strcpy(option.m_EntryName, "FEA_3DH");
break;
default:
strncpy(option.m_EntryName, gxtKey, 8);
2020-08-24 15:42:26 -04:00
break;
}
2020-10-27 22:11:34 -04:00
option.m_Action = action;
option.m_SaveSlot = saveSlot;
option.m_TargetMenu = targetMenu;
}
2021-01-14 20:40:34 -05:00
void FrontendOptionAddSelect(const char* gxtKey, const char** rightTexts, int8 numRightTexts, int8 *var, bool onlyApplyOnEnter, ChangeFunc changeFunc, const char* saveCat, const char* saveKey, bool disableIfGameLoaded)
2020-10-27 22:11:34 -04:00
{
2020-08-24 15:42:26 -04:00
int8 screenOptionOrder = RegisterNewOption();
2020-10-27 22:11:34 -04:00
CMenuScreenCustom::CMenuEntry &option = aScreens[currentMenu].m_aEntries[screenOptionOrder];
option.m_Action = MENUACTION_CFO_SELECT;
strncpy(option.m_EntryName, gxtKey, 8);
option.m_CFOSelect = new CCFOSelect();
option.m_CFOSelect->rightTexts = (char**)malloc(numRightTexts * sizeof(char*));
memcpy(option.m_CFOSelect->rightTexts, rightTexts, numRightTexts * sizeof(char*));
option.m_CFOSelect->numRightTexts = numRightTexts;
option.m_CFOSelect->value = var;
if (var) {
option.m_CFOSelect->displayedValue = *var;
option.m_CFOSelect->lastSavedValue = *var;
}
2021-01-14 20:40:34 -05:00
option.m_CFOSelect->saveCat = saveCat;
option.m_CFOSelect->save = saveKey;
2020-10-27 22:11:34 -04:00
option.m_CFOSelect->onlyApplyOnEnter = onlyApplyOnEnter;
option.m_CFOSelect->changeFunc = changeFunc;
2021-01-04 08:03:54 -05:00
option.m_CFOSelect->disableIfGameLoaded = disableIfGameLoaded;
}
2021-01-14 20:40:34 -05:00
void FrontendOptionAddDynamic(const char* gxtKey, DrawFunc drawFunc, int8 *var, ButtonPressFunc buttonPressFunc, const char* saveCat, const char* saveKey)
{
2020-08-24 15:42:26 -04:00
int8 screenOptionOrder = RegisterNewOption();
2020-10-27 22:11:34 -04:00
CMenuScreenCustom::CMenuEntry &option = aScreens[currentMenu].m_aEntries[screenOptionOrder];
option.m_Action = MENUACTION_CFO_DYNAMIC;
strncpy(option.m_EntryName, gxtKey, 8);
option.m_CFODynamic = new CCFODynamic();
option.m_CFODynamic->drawFunc = drawFunc;
option.m_CFODynamic->buttonPressFunc = buttonPressFunc;
option.m_CFODynamic->value = var;
2021-01-14 20:40:34 -05:00
option.m_CFODynamic->saveCat = saveCat;
option.m_CFODynamic->save = saveKey;
2020-08-24 15:42:26 -04:00
}
2020-09-29 11:43:34 -04:00
uint8 FrontendScreenAdd(const char* gxtKey, eMenuSprites sprite, int prevPage, int columnWidth, int headerHeight, int lineHeight,
2020-08-24 15:42:26 -04:00
int8 font, float fontScaleX, float fontScaleY, int8 alignment, bool showLeftRightHelper, ReturnPrevPageFunc returnPrevPageFunc) {
2020-10-27 22:11:34 -04:00
uint8 screenOrder = RegisterNewScreen(gxtKey, prevPage, returnPrevPageFunc);
CCustomScreenLayout *screen = new CCustomScreenLayout();
aScreens[screenOrder].layout = screen;
screen->sprite = sprite;
screen->columnWidth = columnWidth;
screen->headerHeight = headerHeight;
screen->lineHeight = lineHeight;
screen->font = font;
screen->fontScaleX = fontScaleX;
screen->fontScaleY = fontScaleY;
screen->alignment = alignment;
2020-08-24 15:42:26 -04:00
return screenOrder;
}
#endif