Code:
template<typename A, typename B>
bool AddEditorOption(bool ExecOnArrowPress, CONST PCHAR Spec, A ToDisplay, B* Value, B Min, B Max, B Accuracy, CONST PCHAR Format, ...) {
bool ReturnValue = false;
CHAR Buf[128];
va_list Args;
va_start(Args, Format);
vsprintf(Buf, Format, Args);
va_end(Args);
CHAR Editor[128];
sprintf_s(Editor, Spec, ToDisplay);
MenuContextOptionCount++;
if (MenuContextCurrentOption <= MenuContextMaxOptions && MenuContextOptionCount <= MenuContextMaxOptions) {
DrawText(Buf, MenuBannerPosX - (MenuBannerSizeX / 2.0f) + MenuTextPadding, MenuBannerPosY + (MenuBannerSizeY / 2.0f) + (MenuIncrement / 2.0f) + (MenuContextOptionCount * MenuIncrement) - MenuTextOffset, (MenuContextCurrentOption == MenuContextOptionCount) ? MenuSelectedOptionTextColour : MenuOptionTextColour, false, false, false);
DrawText(Editor, MenuBannerPosX + (MenuBannerSizeX / 2.0f) - ((MenuContextCurrentOption == MenuContextOptionCount) ? (MenuTextPadding * 4.5f) : MenuTextPadding), MenuBannerPosY + (MenuBannerSizeY / 2.0f) + (MenuIncrement / 2.0f) + (MenuContextOptionCount * MenuIncrement) - MenuTextOffset, (MenuContextCurrentOption == MenuContextOptionCount) ? MenuSelectedOptionTextColour : MenuOptionTextColour, false, true, false);
if (MenuContextCurrentOption == MenuContextOptionCount) {
DrawSprite("commonmenu", "arrowright", MenuBannerPosX + (MenuBannerSizeX / 2.0f) - (MenuTextPadding * 2.0f), MenuBannerPosY + (MenuBannerSizeY / 2.0f) + (MenuIncrement / 2.0f) + (MenuContextOptionCount * MenuIncrement), 0.0f, MenuVariableArrowColour);
DrawSprite("commonmenu", "arrowleft", MenuBannerPosX + (MenuBannerSizeX / 2.0f) - (MenuTextPadding * 3.5f), MenuBannerPosY + (MenuBannerSizeY / 2.0f) + (MenuIncrement / 2.0f) + (MenuContextOptionCount * MenuIncrement), 0.0f, MenuVariableArrowColour);
}
}
else if ((MenuContextOptionCount > (MenuContextCurrentOption - MenuContextMaxOptions)) && MenuContextOptionCount <= MenuContextCurrentOption) {
DrawText(Buf, MenuBannerPosX - (MenuBannerSizeX / 2.0f) + MenuTextPadding, MenuBannerPosY + (MenuBannerSizeY / 2.0f) + (MenuIncrement / 2.0f) + ((MenuContextOptionCount - (MenuContextCurrentOption - MenuContextMaxOptions)) * MenuIncrement) - MenuTextOffset, (MenuContextCurrentOption == MenuContextOptionCount) ? MenuSelectedOptionTextColour : MenuOptionTextColour, false, false, false);
DrawText(Editor, MenuBannerPosX + (MenuBannerSizeX / 2.0f) - ((MenuContextCurrentOption == MenuContextOptionCount) ? (MenuTextPadding * 4.5f) : MenuTextPadding), MenuBannerPosY + (MenuBannerSizeY / 2.0f) + (MenuIncrement / 2.0f) + ((MenuContextOptionCount - (MenuContextCurrentOption - MenuContextMaxOptions)) * MenuIncrement) - MenuTextOffset, (MenuContextCurrentOption == MenuContextOptionCount) ? MenuSelectedOptionTextColour : MenuOptionTextColour, false, true, false);
if (MenuContextCurrentOption == MenuContextOptionCount) {
DrawSprite("commonmenu", "arrowright", MenuBannerPosX + (MenuBannerSizeX / 2.0f) - (MenuTextPadding * 2.0f), MenuBannerPosY + (MenuBannerSizeY / 2.0f) + (MenuIncrement / 2.0f) + ((MenuContextOptionCount - (MenuContextCurrentOption - MenuContextMaxOptions)) * MenuIncrement), 0.0f, MenuVariableArrowColour);
DrawSprite("commonmenu", "arrowleft", MenuBannerPosX + (MenuBannerSizeX / 2.0f) - (MenuTextPadding * 3.5f), MenuBannerPosY + (MenuBannerSizeY / 2.0f) + (MenuIncrement / 2.0f) + ((MenuContextOptionCount - (MenuContextCurrentOption - MenuContextMaxOptions)) * MenuIncrement), 0.0f, MenuVariableArrowColour);
}
}
if (MenuContextCurrentOption == MenuContextOptionCount) {
if (OptionLeftPressed) {
*Value -= Accuracy;
if (*Value < Min)
*Value = Max;
ExecOnArrowPress ? ReturnValue = true : ReturnValue = false;
}
if (OptionRightPressed) {
*Value += Accuracy;
if (*Value > Max)
*Value = Min;
ExecOnArrowPress ? ReturnValue = true : ReturnValue = false;
}
if (OptionSelectPressed) {
ExecOnArrowPress ? ReturnValue = false : ReturnValue = true;
}
}
return ReturnValue;
}