mirror of
https://github.com/halpz/re3.git
synced 2025-06-28 01:26:20 +00:00
Frontend cleanup, .INI, CFO, scrollable pages
This commit is contained in:
167
src/extras/frontendoption.cpp
Normal file
167
src/extras/frontendoption.cpp
Normal file
@ -0,0 +1,167 @@
|
||||
#include "common.h"
|
||||
|
||||
#ifdef CUSTOM_FRONTEND_OPTIONS
|
||||
#include "Frontend.h"
|
||||
#include "Text.h"
|
||||
|
||||
int lastOgScreen = MENUPAGES; // means no new pages
|
||||
|
||||
int numCustomFrontendOptions = 0;
|
||||
int numCustomFrontendScreens = 0;
|
||||
|
||||
int optionCursor = -2;
|
||||
int currentMenu;
|
||||
bool optionOverwrite = false;
|
||||
|
||||
void GoBack()
|
||||
{
|
||||
FrontEndMenuManager.SwitchToNewScreen(-1);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
uint8
|
||||
GetLastMenuScreen()
|
||||
{
|
||||
int8 page = -1;
|
||||
for (int i = 0; i < MENUPAGES; i++) {
|
||||
if (strcmp(aScreens[i].m_ScreenName, "") == 0 && aScreens[i].m_PreviousPage == MENUPAGE_NONE)
|
||||
break;
|
||||
|
||||
++page;
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
int8 RegisterNewScreen(const char *name, int prevPage, ReturnPrevPageFunc returnPrevPageFunc)
|
||||
{
|
||||
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 = prevPage;
|
||||
aScreens[id].returnPrevPageFunc = returnPrevPageFunc;
|
||||
return id;
|
||||
}
|
||||
|
||||
int8 RegisterNewOption()
|
||||
{
|
||||
numCustomFrontendOptions++;
|
||||
uint8 numOptions = GetNumberOfMenuOptions(currentMenu);
|
||||
uint8 curIdx;
|
||||
if (optionCursor < 0) {
|
||||
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--) {
|
||||
memcpy(&aScreens[currentMenu].m_aEntries[i + 1], &aScreens[currentMenu].m_aEntries[i], sizeof(CMenuScreenCustom::CMenuEntry));
|
||||
}
|
||||
}
|
||||
}
|
||||
optionCursor++;
|
||||
return curIdx;
|
||||
}
|
||||
|
||||
void FrontendOptionSetCursor(int screen, int8 option, bool overwrite)
|
||||
{
|
||||
currentMenu = screen;
|
||||
optionCursor = option;
|
||||
optionOverwrite = overwrite;
|
||||
}
|
||||
|
||||
void FrontendOptionAddBuiltinAction(const char* gxtKey, uint16 x, uint16 y, uint8 align, int action, int targetMenu, int saveSlot) {
|
||||
int8 screenOptionOrder = RegisterNewOption();
|
||||
|
||||
CMenuScreenCustom::CMenuEntry &option = aScreens[currentMenu].m_aEntries[screenOptionOrder];
|
||||
|
||||
// We can't use custom text on those :shrug:
|
||||
switch (action) {
|
||||
case MENUACTION_SCREENRES:
|
||||
strcpy(option.m_EntryName, "FED_RES");
|
||||
break;
|
||||
case MENUACTION_AUDIOHW:
|
||||
strcpy(option.m_EntryName, "FEA_3DH");
|
||||
break;
|
||||
default:
|
||||
strncpy(option.m_EntryName, gxtKey, 8);
|
||||
break;
|
||||
}
|
||||
option.m_X = x;
|
||||
option.m_Y = y;
|
||||
option.m_Align = align;
|
||||
option.m_Action = action;
|
||||
option.m_SaveSlot = saveSlot;
|
||||
option.m_TargetMenu = targetMenu;
|
||||
}
|
||||
|
||||
void FrontendOptionAddSelect(const char* gxtKey, uint16 x, uint16 y, uint8 align, const char** rightTexts, int8 numRightTexts, int8 *var, bool onlyApplyOnEnter, ChangeFunc changeFunc, const char* saveName)
|
||||
{
|
||||
int8 screenOptionOrder = RegisterNewOption();
|
||||
|
||||
CMenuScreenCustom::CMenuEntry &option = aScreens[currentMenu].m_aEntries[screenOptionOrder];
|
||||
option.m_Action = MENUACTION_CFO_SELECT;
|
||||
option.m_X = x;
|
||||
option.m_Y = y;
|
||||
option.m_Align = align;
|
||||
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;
|
||||
}
|
||||
option.m_CFOSelect->save = saveName;
|
||||
option.m_CFOSelect->onlyApplyOnEnter = onlyApplyOnEnter;
|
||||
option.m_CFOSelect->changeFunc = changeFunc;
|
||||
}
|
||||
|
||||
void FrontendOptionAddDynamic(const char* gxtKey, uint16 x, uint16 y, uint8 align, DrawFunc drawFunc, int8 *var, ButtonPressFunc buttonPressFunc, const char* saveName)
|
||||
{
|
||||
int8 screenOptionOrder = RegisterNewOption();
|
||||
|
||||
CMenuScreenCustom::CMenuEntry &option = aScreens[currentMenu].m_aEntries[screenOptionOrder];
|
||||
option.m_Action = MENUACTION_CFO_DYNAMIC;
|
||||
option.m_X = x;
|
||||
option.m_Y = y;
|
||||
option.m_Align = align;
|
||||
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;
|
||||
option.m_CFODynamic->save = saveName;
|
||||
}
|
||||
|
||||
// lineHeight = 0 means game will use MENU_DEFAULT_LINE_HEIGHT
|
||||
uint8 FrontendScreenAdd(const char* gxtKey, int prevPage, int lineHeight, bool showLeftRightHelper, ReturnPrevPageFunc returnPrevPageFunc) {
|
||||
|
||||
uint8 screenOrder = RegisterNewScreen(gxtKey, prevPage, returnPrevPageFunc);
|
||||
|
||||
CCustomScreenLayout *screen = new CCustomScreenLayout();
|
||||
aScreens[screenOrder].layout = screen;
|
||||
screen->lineHeight = lineHeight;
|
||||
screen->showLeftRightHelper = showLeftRightHelper;
|
||||
|
||||
return screenOrder;
|
||||
}
|
||||
#endif
|
86
src/extras/frontendoption.h
Normal file
86
src/extras/frontendoption.h
Normal file
@ -0,0 +1,86 @@
|
||||
#pragma once
|
||||
#include "common.h"
|
||||
|
||||
#ifdef CUSTOM_FRONTEND_OPTIONS
|
||||
|
||||
// ! There are 2 ways to use CFO,
|
||||
// 1st; by adding a new option to the array in MenuScreensCustom.cpp and passing attributes/CBs to it
|
||||
// 2nd; by calling the functions listed at the bottom of this file.
|
||||
|
||||
// -- Option types
|
||||
//
|
||||
// Static/select: You allocate the variable, pass it to function and game sets it from user input among the strings given to function,
|
||||
// optionally you can add post-change event via ChangeFunc(only called on enter if onlyApplyOnEnter set, or set immediately)
|
||||
// You can store the option in an INI file if you pass the key(as a char array) to corresponding parameter.
|
||||
//
|
||||
// Dynamic: Passing variable to function is only needed if you want to store it, otherwise you should do
|
||||
// all the operations with ButtonPressFunc, this includes allocating the variable.
|
||||
// Left-side text is passed while creating and static, but ofc right-side text is dynamic -
|
||||
// you should return it in DrawFunc, which is called on every draw.
|
||||
//
|
||||
// Built-in action: As the name suggests, any action that game has built-in. But as an extra you can set the option text,
|
||||
|
||||
// -- Returned via ButtonPressFunc() action param.
|
||||
#define FEOPTION_ACTION_LEFT 0
|
||||
#define FEOPTION_ACTION_RIGHT 1
|
||||
#define FEOPTION_ACTION_SELECT 2
|
||||
#define FEOPTION_ACTION_FOCUSLOSS 3
|
||||
|
||||
// -- Callbacks
|
||||
|
||||
// pretty much in everything I guess, and optional in all of them
|
||||
typedef void (*ReturnPrevPageFunc)();
|
||||
|
||||
// for static options
|
||||
typedef void (*ChangeFunc)(int8 before, int8 after); // called after updating the value.
|
||||
// only called on enter if onlyApplyOnEnter set, otherwise called on every value change
|
||||
|
||||
// for dynamic options
|
||||
typedef wchar* (*DrawFunc)(bool* disabled, bool userHovering); // you must return a pointer for right text.
|
||||
// you can also set *disabled if you want to gray it out.
|
||||
typedef void (*ButtonPressFunc)(int8 action); // see FEOPTION_ACTIONs above
|
||||
|
||||
// -- Internal things
|
||||
void CustomFrontendOptionsPopulate();
|
||||
extern int lastOgScreen; // for reloading
|
||||
extern int numCustomFrontendOptions;
|
||||
extern int numCustomFrontendScreens;
|
||||
|
||||
// -- To be used in ButtonPressFunc / ChangeFunc(this one would be weird):
|
||||
void GoBack(void);
|
||||
|
||||
uint8 GetNumberOfMenuOptions(int screen);
|
||||
|
||||
// !!! We're now moved to MenuScreensCustom.cpp, which houses an array that keeps all original+custom options.
|
||||
// But you can still use the APIs below, and manipulate aScreens while in game.
|
||||
|
||||
// Limits:
|
||||
// The code relies on that you won't use more then NUM_MENUROWS(18) options on one page, and won't exceed the MENUPAGES of pages.
|
||||
// Also congrats if you can make 18 options visible at once.
|
||||
|
||||
// Texts:
|
||||
// All text parameters accept char[8] GXT key.
|
||||
|
||||
// Execute direction:
|
||||
// All of the calls below eventually manipulate the aScreens array, so keep in mind to add/replace options in order,
|
||||
// i.e. don't set cursor to 8 first and then 3.
|
||||
|
||||
|
||||
// -- Placing the cursor to append/overwrite option
|
||||
//
|
||||
// Done via FrontendOptionSetCursor(screen, position, overwrite = false), parameters explained below:
|
||||
// Screen: as the name suggests. Also accepts the screen IDs returned from FrontendScreenAdd.
|
||||
// Option: if positive, next AddOption call will put the option to there and progress the cursor.
|
||||
// if negative, cursor will be placed on bottom-(pos+1), so -1 means the very bottom, -2 means before the back button etc.
|
||||
// Overwrite: Use to overwrite the options, not appending a new one. AddOption calls will still progress the cursor.
|
||||
|
||||
void FrontendOptionSetCursor(int screen, int8 option, bool overwrite = false);
|
||||
|
||||
// var is optional in AddDynamic, enables you to save them in an INI file(also needs passing char array to saveName param. obv), otherwise pass nil/0
|
||||
void FrontendOptionAddBuiltinAction(const char* gxtKey, uint16 x, uint16 y, uint8 align, int action, int targetMenu = MENUPAGE_NONE, int saveSlot = SAVESLOT_NONE);
|
||||
void FrontendOptionAddSelect(const char* gxtKey, uint16 x, uint16 y, uint8 align, const char** rightTexts, int8 numRightTexts, int8 *var, bool onlyApplyOnEnter, ChangeFunc changeFunc, const char* saveName = nil);
|
||||
void FrontendOptionAddDynamic(const char* gxtKey, uint16 x, uint16 y, uint8 align, DrawFunc rightTextDrawFunc, int8 *var, ButtonPressFunc buttonPressFunc, const char* saveName = nil);
|
||||
|
||||
// lineHeight = 0 means game will use MENU_DEFAULT_LINE_HEIGHT
|
||||
uint8 FrontendScreenAdd(const char* gxtKey, int prevPage, int lineHeight, bool showLeftRightHelper, ReturnPrevPageFunc returnPrevPageFunc = nil);
|
||||
#endif
|
Reference in New Issue
Block a user