From 90c5ea6acc3e6e6a53f49e71223d62e8a19c209b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 29 Nov 2019 01:28:13 +0100 Subject: [PATCH] - updated option menu code to latest scripted version This mainly means being able to use the generic font. This also adds more generalization to the menu sound handling, plus an option to turn menu sound off. This is motivated by the pig sounds which RR uses in the menu. --- source/build/include/baselayer.h | 8 +- source/common/menu/listmenu.cpp | 10 +- source/common/menu/loadsavemenu.cpp | 10 +- source/common/menu/menu.cpp | 20 ++- source/common/menu/menu.h | 28 +++- source/common/menu/messagebox.cpp | 3 +- source/common/menu/optionmenu.cpp | 82 ++++++---- source/common/menu/optionmenuitems.h | 223 ++++++++++++++++----------- source/duke3d/src/d_menu.cpp | 16 +- source/rr/src/d_menu.cpp | 15 +- source/rr/src/duke3d.h | 2 +- 11 files changed, 255 insertions(+), 162 deletions(-) diff --git a/source/build/include/baselayer.h b/source/build/include/baselayer.h index 10d4dd547..3525930ba 100644 --- a/source/build/include/baselayer.h +++ b/source/build/include/baselayer.h @@ -185,14 +185,10 @@ struct FSavegameInfo int currentsavever; }; +enum EMenuSounds : int; + struct GameInterface { - enum EMenuSounds - { - SelectSound, - ChooseSound - }; - virtual ~GameInterface() {} virtual void faketimerhandler() {} // This is a remnant of older versions, but Blood backend has not updated yet. virtual int app_main() = 0; diff --git a/source/common/menu/listmenu.cpp b/source/common/menu/listmenu.cpp index 26d7429ca..4d7c67f38 100644 --- a/source/common/menu/listmenu.cpp +++ b/source/common/menu/listmenu.cpp @@ -133,7 +133,7 @@ bool DListMenu::Responder (event_t *ev) { mDesc->mSelectedItem = i; SelectionChanged(); - gi->MenuSound(GameInterface::SelectSound); + M_MenuSound(CursorSound); return true; } } @@ -143,7 +143,7 @@ bool DListMenu::Responder (event_t *ev) { mDesc->mSelectedItem = i; SelectionChanged(); - gi->MenuSound(GameInterface::SelectSound); + M_MenuSound(CursorSound); return true; } } @@ -171,7 +171,7 @@ bool DListMenu::MenuEvent (int mkey, bool fromcontroller) } while (!mDesc->mItems[mDesc->mSelectedItem]->Selectable() && mDesc->mSelectedItem != startedAt); SelectionChanged(); - gi->MenuSound(GameInterface::SelectSound); + M_MenuSound(CursorSound); return true; case MKEY_Down: @@ -181,13 +181,13 @@ bool DListMenu::MenuEvent (int mkey, bool fromcontroller) } while (!mDesc->mItems[mDesc->mSelectedItem]->Selectable() && mDesc->mSelectedItem != startedAt); SelectionChanged(); - gi->MenuSound(GameInterface::SelectSound); + M_MenuSound(CursorSound); return true; case MKEY_Enter: if (mDesc->mSelectedItem >= 0 && mDesc->mItems[mDesc->mSelectedItem]->Activate(mDesc->mMenuName)) { - gi->MenuSound(GameInterface::ChooseSound); + M_MenuSound(AdvanceSound); } return true; diff --git a/source/common/menu/loadsavemenu.cpp b/source/common/menu/loadsavemenu.cpp index f5ed87171..e9422a23c 100644 --- a/source/common/menu/loadsavemenu.cpp +++ b/source/common/menu/loadsavemenu.cpp @@ -99,16 +99,16 @@ protected: DLoadSaveMenu(DMenu *parent = NULL, FListMenuDescriptor *desc = NULL); void Init(DMenu* parent, FListMenuDescriptor* desc) override; - void Destroy(); + void Destroy() override; int RemoveSaveSlot (int index); void UnloadSaveData (); void ClearSaveStuff (); void ExtractSaveData (int index); - void Drawer (); - bool MenuEvent (int mkey, bool fromcontroller); - bool MouseEvent(int type, int x, int y); - bool Responder(event_t *ev); + void Drawer () override; + bool MenuEvent (int mkey, bool fromcontroller) override; + bool MouseEvent(int type, int x, int y) override; + bool Responder(event_t *ev) override; public: static void NotifyNewSave (const char *file, const char *title, bool okForQuicksave); diff --git a/source/common/menu/menu.cpp b/source/common/menu/menu.cpp index 051241b92..f147477a6 100644 --- a/source/common/menu/menu.cpp +++ b/source/common/menu/menu.cpp @@ -195,8 +195,8 @@ bool DMenu::MenuEvent (int mkey, bool fromcontroller) { if (scriptID != 0) { + M_MenuSound(DMenu::CurrentMenu->mParentMenu? BackSound : CloseSound); Close(); - //S_Sound (CHAN_VOICE | CHAN_UI, DMenu::CurrentMenu != NULL? "menu/backup" : "menu/clear", snd_menuvolume, ATTN_NONE); return true; } } @@ -473,15 +473,15 @@ bool M_SetMenu(FName menu, int param, FName caller) const char *msg = AllSkills[param].MustConfirmText; if (*msg==0) msg = GStrings("NIGHTMARE"); - M_StartMessage (msg, 0, NAME_StartgameConfirmed); + M_StartMessage (msg, 0, -1, NAME_StartgameConfirmed); return; } case NAME_Savegamemenu: - if (!usergame || (players[consoleplayer].health <= 0 && !multiplayer) || gamestate != GS_LEVEL) + if (gi->canSave()) { // cannot save outside the game. - M_StartMessage (GStrings("SAVEDEAD"), 1); + M_StartMessage (GStrings("SAVEDEAD"), 1, -1); return; } #endif @@ -860,6 +860,18 @@ void Menu_Close(int playerid) { M_ClearMenus(); } +//============================================================================= +// +// +// +//============================================================================= +CVAR(Bool, menu_sounds, true, CVAR_ARCHIVE) // added mainly because RR's sounds are so supremely annoying. + +void M_MenuSound(EMenuSounds snd) +{ + if (menu_sounds) gi->MenuSound(snd); +} + //============================================================================= // // diff --git a/source/common/menu/menu.h b/source/common/menu/menu.h index fdc4590f6..488580e45 100644 --- a/source/common/menu/menu.h +++ b/source/common/menu/menu.h @@ -92,10 +92,20 @@ enum EMenuState : int MENU_OnNoPause, // Menu is opened but does not pause the game }; +enum EMenuSounds : int +{ + CursorSound, + AdvanceSound, + BackSound, + CloseSound, + PageSound + ChangeSound +}; + struct event_t; class FTexture; class FFont; -enum EColorRange; +enum EColorRange : int; class FPlayerClass; class FKeyBindings; @@ -570,7 +580,14 @@ protected: FString mLabel; bool mCentered = false; - void drawLabel(int indent, int y, EColorRange color, bool grayed = false); + void drawText(int x, int y, int color, const char * text, bool grayed = false); + + int drawLabel(int indent, int y, EColorRange color, bool grayed = false); + void drawValue(int indent, int y, int color, const char *text, bool grayed = false); + + int CursorSpace(); + + public: FOptionMenuItem(const char *text, FName action = NAME_None, bool center = false) @@ -651,6 +668,10 @@ public: } }; +FFont *OptionFont(); +int OptionHeight(); +int OptionWidth(const char * s); +void DrawOptionText(int x, int y, int color, const char *text, bool grayed = false); //============================================================================= // @@ -726,8 +747,9 @@ int M_GetDefaultSkill(); void M_StartControlPanel (bool makeSound); bool M_SetMenu(FName menu, int param = -1, FName callingMenu = NAME_None); void M_NotifyNewSave (const char *file, const char *title, bool okForQuicksave); -void M_StartMessage(const char *message, int messagemode, FName action = NAME_None); +void M_StartMessage(const char *message, int messagemode, int scriptId, FName action = NAME_None); void M_UnhideCustomMenu(int menu, int itemmask); +void M_MenuSound(EMenuSounds snd); void I_SetMouseCapture(); diff --git a/source/common/menu/messagebox.cpp b/source/common/menu/messagebox.cpp index 99cc86160..b299f62df 100644 --- a/source/common/menu/messagebox.cpp +++ b/source/common/menu/messagebox.cpp @@ -345,7 +345,7 @@ bool DMessageBoxMenu::MouseEvent(int type, int x, int y) // //============================================================================= -void M_StartMessage(const char *message, int messagemode, FName action) +void M_StartMessage(const char *message, int messagemode, int scriptId, FName action) { if (DMenu::CurrentMenu == NULL) { @@ -354,6 +354,7 @@ void M_StartMessage(const char *message, int messagemode, FName action) } DMenu *newmenu = new DMessageBoxMenu(DMenu::CurrentMenu, message, messagemode, false, action); newmenu->mParentMenu = DMenu::CurrentMenu; + newmenu->scriptID = scriptId; M_ActivateMenu(newmenu); } diff --git a/source/common/menu/optionmenu.cpp b/source/common/menu/optionmenu.cpp index 38dddb82b..6e0c595f4 100644 --- a/source/common/menu/optionmenu.cpp +++ b/source/common/menu/optionmenu.cpp @@ -53,15 +53,27 @@ // //============================================================================= -void M_DrawConText (int color, int x, int y, const char *str) +FFont *OptionFont() { - DrawText (&twod, ConFont, color, x, y, str, - DTA_CellX, 8 * CleanXfac_1, - DTA_CellY, 8 * CleanYfac_1, - TAG_DONE); + return NewSmallFont; } +int OptionHeight() +{ + return OptionFont()->GetHeight(); +} +int OptionWidth(const char * s) +{ + return OptionFont()->StringWidth(s); +} + +void DrawOptionText(int x, int y, int color, const char *text, bool grayed) +{ + text = *text == '$'? GStrings(text+1) : text; + PalEntry overlay = grayed? PalEntry(96,48,0,0) : PalEntry(0,0,0); + DrawText (&twod, OptionFont(), color, x, y, text, DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay); +} //============================================================================= // @@ -323,7 +335,7 @@ bool DOptionMenu::MenuEvent (int mkey, bool fromcontroller) if (mDesc->mSelectedItem != startedAt) { - //S_Sound (CHAN_VOICE | CHAN_UI, "menu/cursor", snd_menuvolume, ATTN_NONE); + M_MenuSound(CursorSound); } return true; } @@ -355,7 +367,8 @@ bool DOptionMenu::MouseEvent(int type, int x, int y) if (yline != mDesc->mSelectedItem) { mDesc->mSelectedItem = yline; - //S_Sound (CHAN_VOICE | CHAN_UI, "menu/cursor", snd_menuvolume, ATTN_NONE); + //M_MenuSound(CursorSound); too noisy + } mDesc->mItems[yline]->MouseEvent(type, x, y); return true; @@ -390,21 +403,9 @@ void DOptionMenu::Drawer () { int y = mDesc->mPosition; - if (y <= 0) + if (mDesc->mTitle.IsNotEmpty()) { - if (BigFont && mDesc->mTitle.IsNotEmpty()) - { - const char *tt = mDesc->mTitle; - if (*tt == '$') tt = GStrings(tt+1); - DrawText (&twod, BigFont, OptionSettings.mTitleColor, - (screen->GetWidth() - BigFont->StringWidth(tt) * CleanXfac_1) / 2, 10*CleanYfac_1, - tt, DTA_CleanNoMove_1, true, TAG_DONE); - y = -y + BigFont->GetHeight(); - } - else - { - y = -y; - } + gi->DrawMenuCaption(origin, mDesc->mTitle); } mDesc->mDrawTop = y; int fontheight = OptionSettings.mLinespacing * CleanYfac_1; @@ -445,7 +446,8 @@ void DOptionMenu::Drawer () { if ((((DMenu::MenuTime>>2)%8) < 6) || DMenu::CurrentMenu != this) { - M_DrawConText(OptionSettings.mFontColorSelection, cur_indent + 3 * CleanXfac_1, y+fontheight-9*CleanYfac_1, "\xd"); + DrawOptionText(cur_indent + 3 * CleanXfac_1, y, OptionSettings.mFontColorSelection, "◄"); + //M_DrawConText(OptionSettings.mFontColorSelection, cur_indent + 3 * CleanXfac_1, y+fontheight-9*CleanYfac_1, "\xd"); } } } @@ -456,11 +458,13 @@ void DOptionMenu::Drawer () if (CanScrollUp) { - M_DrawConText(CR_ORANGE, 3 * CleanXfac_1, ytop, "\x1a"); + DrawOptionText(screen->GetWidth() - 11 * CleanXfac_1, ytop, OptionSettings.mFontColorSelection, "▲"); + //M_DrawConText(CR_ORANGE, 3 * CleanXfac_1, ytop, "\x1a"); } if (CanScrollDown) { - M_DrawConText(CR_ORANGE, 3 * CleanXfac_1, y - 8*CleanYfac_1, "\x1b"); + DrawOptionText(screen->GetWidth() - 11 * CleanXfac_1 , y - 8*CleanYfac_1, OptionSettings.mFontColorSelection, "▼"); + //M_DrawConText(CR_ORANGE, 3 * CleanXfac_1, y - 8*CleanYfac_1, "\x1b"); } Super::Drawer(); } @@ -497,30 +501,40 @@ bool FOptionMenuItem::MouseEvent(int type, int x, int y) int FOptionMenuItem::GetIndent() { - if (mCentered) - { - return 0; - } + if (mCentered) return 0; + if (screen->GetWidth() < 640) return screen->GetWidth() / 2; const char *label = mLabel; if (*label == '$') label = GStrings(label+1); - return SmallFont->StringWidth(label); + return OptionWidth(label); } -void FOptionMenuItem::drawLabel(int indent, int y, EColorRange color, bool grayed) +void FOptionMenuItem::drawText(int x, int y, int color, const char * text, bool grayed) +{ + DrawOptionText(x, y, color, text, grayed); +} + +int FOptionMenuItem::drawLabel(int indent, int y, EColorRange color, bool grayed) { const char *label = mLabel; if (*label == '$') label = GStrings(label+1); - int overlay = grayed? MAKEARGB(96,48,0,0) : 0; - int x; - int w = SmallFont->StringWidth(label) * CleanXfac_1; + int w = OptionWidth(label) * CleanXfac_1; if (!mCentered) x = indent - w; else x = (screen->GetWidth() - w) / 2; - DrawText (&twod, SmallFont, color, x, y, label, DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay, TAG_DONE); + DrawOptionText(x, y, color, label, grayed); + return x; } +void FOptionMenuItem::drawValue(int indent, int y, int color, const char *text, bool grayed) +{ + DrawOptionText(indent + CursorSpace(), y, color, text, grayed); +} +int FOptionMenuItem::CursorSpace() +{ + return (14 * CleanXfac_1); +} void FOptionMenuDescriptor::CalcIndent() { diff --git a/source/common/menu/optionmenuitems.h b/source/common/menu/optionmenuitems.h index fd115b398..c97e53236 100644 --- a/source/common/menu/optionmenuitems.h +++ b/source/common/menu/optionmenuitems.h @@ -57,21 +57,48 @@ public: mParam = param; } - int Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) + int Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) override { drawLabel(indent, y, selected? OptionSettings.mFontColorSelection : OptionSettings.mFontColorMore); return indent; } - bool Activate() + bool Activate(FName caller) override { - //S_Sound (CHAN_VOICE | CHAN_UI, "menu/choose", snd_menuvolume, ATTN_NONE); + M_MenuSound(CursorSound); M_SetMenu(mAction, mParam); return true; } }; +//============================================================================= +// +// opens a submenu, command is a submenu name +// +//============================================================================= + +class FOptionMenuItemLabeledSubmenu : public FOptionMenuItemSubmenu +{ + FBaseCVar *mLabelCVar; + FOptionMenuItemLabeledSubmenu(const char * label, FBaseCVar *labelcvar, FName command, int param = 0) + : FOptionMenuItemSubmenu(label, command, param) + { + mLabelCVar = labelcvar; + } + + int Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) override + { + drawLabel(indent, y, selected? OptionSettings.mFontColorSelection : OptionSettings.mFontColor); + + auto text = mLabelCVar->GetHumanString(); + if (text[0] == 0) text = GStrings("notset"); + drawValue(indent, y, OptionSettings.mFontColorValue, text); + return indent; + } +}; + + //============================================================================= // // Executes a CCMD, action is a CCMD name @@ -86,9 +113,9 @@ public: { } - bool Activate() + bool Activate(FName caller) override { - //S_Sound (CHAN_VOICE | CHAN_UI, "menu/choose", snd_menuvolume, ATTN_NONE); + M_MenuSound(AdvanceSound); C_DoCommand(mAction); return true; } @@ -104,13 +131,17 @@ public: class FOptionMenuItemSafeCommand : public FOptionMenuItemCommand { // action is a CCMD + FString mPrompt; + int mScriptId; // shouldn't be used, but just in case. public: - FOptionMenuItemSafeCommand(const char *label, const char *menu) + FOptionMenuItemSafeCommand(const char *label, const char *menu, const char *prompt = nullptr, int scriptid = INT_MAX) : FOptionMenuItemCommand(label, menu) { + mPrompt = prompt; + mScriptId = scriptid; } - bool MenuEvent (int mkey, bool fromcontroller) + bool MenuEvent (int mkey, bool fromcontroller) override { if (mkey == MKEY_MBYes) { @@ -120,9 +151,15 @@ public: return FOptionMenuItemCommand::MenuEvent(mkey, fromcontroller); } - bool Activate() + bool Activate(FName caller) override { - M_StartMessage("Do you really want to do this?", 0); + auto msg = mPrompt.IsNotEmpty()? mPrompt.GetChars() : "$SAFEMESSAGE"; + if (*msg == '$') msg = GStrings(msg+1); + auto actionLabel = mLabel.GetChars(); + if (*actionLabel == '$') actionLabel = GStrings(actionLabel+1); + + FStringf FullString("%s%s%s\n\n%s", TEXTCOLOR_WHITE, actionLabel, TEXTCOLOR_NORMAL, msg); + M_StartMessage(FullString, 0, mScriptId); return true; } }; @@ -155,7 +192,7 @@ public: mCenter = center; } - bool SetString(int i, const char *newtext) + bool SetString(int i, const char *newtext) override { if (i == OP_VALUES) { @@ -179,19 +216,16 @@ public: virtual void SetSelection(int Selection) = 0; //============================================================================= - int Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) + int Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) override { - bool grayed = mGrayCheck != NULL && !(mGrayCheck->GetGenericRep(CVAR_Bool).Bool); - if (mCenter) { indent = (screen->GetWidth() / 2); } - drawLabel(indent, y, selected? OptionSettings.mFontColorSelection : OptionSettings.mFontColor, grayed); + drawLabel(indent, y, selected? OptionSettings.mFontColorSelection : OptionSettings.mFontColor, isGrayed()); - int overlay = grayed? MAKEARGB(96,48,0,0) : 0; - const char *text; int Selection = GetSelection(); + const char *text; FOptionValues **opt = OptionValues.CheckKey(mValues); if (Selection < 0 || opt == NULL || *opt == NULL) { @@ -202,13 +236,13 @@ public: text = (*opt)->mValues[Selection].Text; } if (*text == '$') text = GStrings(text + 1); - DrawText(&twod,SmallFont, OptionSettings.mFontColorValue, indent + CURSORSPACE, y, - text, DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay, TAG_DONE); + + drawValue(indent, y, OptionSettings.mFontColorValue, text, isGrayed()); return indent; } //============================================================================= - bool MenuEvent (int mkey, bool fromcontroller) + bool MenuEvent (int mkey, bool fromcontroller) override { FOptionValues **opt = OptionValues.CheckKey(mValues); if (opt != NULL && *opt != NULL && (*opt)->mValues.Size() > 0) @@ -228,14 +262,19 @@ public: return FOptionMenuItem::MenuEvent(mkey, fromcontroller); } SetSelection(Selection); - //S_Sound (CHAN_VOICE | CHAN_UI, "menu/change", snd_menuvolume, ATTN_NONE); + M_MenuSound(ChangeSound); } return true; } - bool Selectable() + virtual bool isGrayed() { - return !(mGrayCheck != NULL && !(mGrayCheck->GetGenericRep(CVAR_Bool).Bool)); + return mGrayCheck != NULL && !(mGrayCheck->GetGenericRep(CVAR_Bool).Bool); + } + + bool Selectable() override + { + return !isGrayed(); } }; @@ -258,7 +297,7 @@ public: } //============================================================================= - int GetSelection() + int GetSelection() override { int Selection = -1; FOptionValues **opt = OptionValues.CheckKey(mValues); @@ -292,7 +331,7 @@ public: return Selection; } - void SetSelection(int Selection) + void SetSelection(int Selection) override { UCVarValue value; FOptionValues **opt = OptionValues.CheckKey(mValues); @@ -333,27 +372,25 @@ public: menuactive = MENU_WaitKey; // There should be a better way to disable GUI capture... } - bool TranslateKeyboardEvents() + bool TranslateKeyboardEvents() override { return false; } void SetMenuMessage(int which) { - /* - if (mParentMenu->IsKindOf(RUNTIME_CLASS(DOptionMenu))) + DOptionMenu *m = static_cast(mParentMenu); + if (m) { - DOptionMenu *m = static_cast(mParentMenu); FListMenuItem *it = m->GetItem(NAME_Controlmessage); if (it != NULL) { it->SetValue(0, which); } } - */ } - bool Responder(event_t *ev) + bool Responder(event_t *ev) override { if (ev->type == EV_KeyDown) { @@ -367,7 +404,7 @@ public: return false; } - void Drawer() + void Drawer() override { mParentMenu->Drawer(); } @@ -395,27 +432,27 @@ public: //============================================================================= - int Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) + int Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) override { - drawLabel(indent, y, mWaiting? OptionSettings.mFontColorHighlight: + drawLabel(indent, y, mWaiting? OptionSettings.mFontColorHighlight: (selected? OptionSettings.mFontColorSelection : OptionSettings.mFontColor)); - auto keys = mBindings->GetKeysForCommand(mAction); - auto description = C_NameKeys(keys.Data(), keys.Size()); - if (description.IsNotEmpty()) + auto binds = mBindings->GetKeysForCommand(mAction); + auto description = C_NameKeys(binds.Data(), binds.Size()); + + if (description.Len() > 0) { - M_DrawConText(CR_WHITE, indent + CURSORSPACE, y + (OptionSettings.mLinespacing-8)*CleanYfac_1, description); + drawValue(indent, y, CR_WHITE, description); } else { - DrawText(&twod,SmallFont, CR_BLACK, indent + CURSORSPACE, y + (OptionSettings.mLinespacing-8)*CleanYfac_1, "---", - DTA_CleanNoMove_1, true, TAG_DONE); + drawValue(indent, y, CR_BLACK, "---"); } return indent; } //============================================================================= - bool MenuEvent(int mkey, bool fromcontroller) + bool MenuEvent(int mkey, bool fromcontroller) override { if (mkey == MKEY_Input) { @@ -436,9 +473,9 @@ public: return false; } - bool Activate() + bool Activate(FName caller) override { - //S_Sound (CHAN_VOICE | CHAN_UI, "menu/choose", snd_menuvolume, ATTN_NONE); + M_MenuSound(AdvanceSound); mWaiting = true; DMenu *input = new DEnterKey(DMenu::CurrentMenu, &mInput); M_ActivateMenu(input); @@ -456,19 +493,19 @@ class FOptionMenuItemStaticText : public FOptionMenuItem { EColorRange mColor; public: - FOptionMenuItemStaticText(const char *label, bool header) + FOptionMenuItemStaticText(const char *label, EColorRange color = CR_UNDEFINED) : FOptionMenuItem(label, NAME_None, true) { - mColor = header? OptionSettings.mFontColorHeader : OptionSettings.mFontColor; + mColor = color == CR_UNDEFINED? (EColorRange)OptionSettings.mFontColor : color; } - int Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) + int Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) override { drawLabel(indent, y, mColor); return -1; } - bool Selectable() + bool Selectable() override { return false; } @@ -488,25 +525,25 @@ class FOptionMenuItemStaticTextSwitchable : public FOptionMenuItem int mCurrent; public: - FOptionMenuItemStaticTextSwitchable(const char *label, const char *label2, FName action, bool header) + FOptionMenuItemStaticTextSwitchable(const char *label, const char *label2, FName action, EColorRange color = CR_UNDEFINED) : FOptionMenuItem(label, action, true) { - mColor = header? OptionSettings.mFontColorHeader : OptionSettings.mFontColor; + mColor = color == CR_UNDEFINED? (EColorRange)OptionSettings.mFontColor : color; mAltText = label2; mCurrent = 0; } - int Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) + int Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) override { const char *txt = mCurrent? mAltText.GetChars() : mLabel.GetChars(); if (*txt == '$') txt = GStrings(txt + 1); - int w = SmallFont->StringWidth(txt) * CleanXfac_1; + int w = OptionWidth(txt) * CleanXfac_1; int x = (screen->GetWidth() - w) / 2; - DrawText(&twod,SmallFont, mColor, x, y, txt, DTA_CleanNoMove_1, true, TAG_DONE); + drawText(x, y, mColor, txt); return -1; } - bool SetValue(int i, int val) + bool SetValue(int i, int val) override { if (i == 0) { @@ -516,7 +553,7 @@ public: return false; } - bool SetString(int i, const char *newtext) + bool SetString(int i, const char *newtext) override { if (i == 0) { @@ -526,7 +563,7 @@ public: return false; } - bool Selectable() + bool Selectable() override { return false; } @@ -547,8 +584,8 @@ class FOptionMenuSliderBase : public FOptionMenuItem int mSliderShort; public: - FOptionMenuSliderBase(const char *label, double min, double max, double step, int showval) - : FOptionMenuItem(label, NAME_None) + FOptionMenuSliderBase(const char *label, double min, double max, double step, int showval, FName command = NAME_None) + : FOptionMenuItem(label, command) { mMin = min; mMax = max; @@ -566,6 +603,11 @@ public: // Draw a slider. Set fracdigits negative to not display the current value numerically. // //============================================================================= + + void DrawSliderElement (int color, int x, int y, const char * str) + { + DrawText (&twod, ConFont, color, x, y, str, DTA_CellX, 16 * CleanXfac_1, DTA_CellY, 16 * CleanYfac_1); + } void DrawSlider (int x, int y, double min, double max, double cur, int fracdigits, int indent) { @@ -588,36 +630,36 @@ public: if (!mSliderShort) { - M_DrawConText(CR_WHITE, x, cy, "\x10\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x12"); - M_DrawConText(CR_ORANGE, x + int((5 + ((ccur * 78) / range)) * CleanXfac_1), cy, "\x13"); + DrawSliderElement(CR_WHITE, x, cy, "\x10\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x12"); + DrawSliderElement(CR_ORANGE, x + int((5 + ((ccur * 78) / range)) * CleanXfac_1), cy, "\x13"); } else { // On 320x200 we need a shorter slider - M_DrawConText(CR_WHITE, x, cy, "\x10\x11\x11\x11\x11\x11\x12"); - M_DrawConText(CR_ORANGE, x + int((5 + ((ccur * 38) / range)) * CleanXfac_1), cy, "\x13"); + DrawSliderElement(CR_WHITE, x, cy, "\x10\x11\x11\x11\x11\x11\x12"); + DrawSliderElement(CR_ORANGE, x + int((5 + ((ccur * 38) / range)) * CleanXfac_1), cy, "\x13"); right -= 5*8*CleanXfac_1; } if (fracdigits >= 0 && right + maxlen <= screen->GetWidth()) { snprintf(textbuf, countof(textbuf), "%.*f", fracdigits, cur); - DrawText(&twod,SmallFont, CR_DARKGRAY, right, y, textbuf, DTA_CleanNoMove_1, true, TAG_DONE); + drawText(right, y, CR_DARKGRAY, textbuf); } } //============================================================================= - int Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) + int Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) override { drawLabel(indent, y, selected? OptionSettings.mFontColorSelection : OptionSettings.mFontColor); - mDrawX = indent + CURSORSPACE; + mDrawX = indent + CursorSpace(); DrawSlider (mDrawX, y, mMin, mMax, GetSliderValue(), mShowValue, indent); return indent; } //============================================================================= - bool MenuEvent (int mkey, bool fromcontroller) + bool MenuEvent (int mkey, bool fromcontroller) override { double value = GetSliderValue(); @@ -634,11 +676,11 @@ public: return FOptionMenuItem::MenuEvent(mkey, fromcontroller); } SetSliderValue(clamp(value, mMin, mMax)); - //S_Sound (CHAN_VOICE | CHAN_UI, "menu/change", snd_menuvolume, ATTN_NONE); + M_MenuSound(ChangeSound); return true; } - bool MouseEvent(int type, int x, int y) + bool MouseEvent(int type, int x, int y) override { DOptionMenu *lm = static_cast(DMenu::CurrentMenu); if (type != DMenu::MOUSE_Click) @@ -651,7 +693,7 @@ public: } int slide_left = mDrawX+8*CleanXfac_1; - int slide_right = slide_left + (10*8*CleanXfac_1 >> mSliderShort); // 12 char cells with 8 pixels each. + int slide_right = slide_left + (10*8*CleanXfac_1 >> mSliderShort); // 10 char cells with 8 pixels each. if (type == DMenu::MOUSE_Click) { @@ -663,7 +705,7 @@ public: if (v != GetSliderValue()) { SetSliderValue(v); - ////S_Sound (CHAN_VOICE | CHAN_UI, "menu/change", snd_menuvolume, ATTN_NONE); + M_MenuSound(ChangeSound); } if (type == DMenu::MOUSE_Click) { @@ -690,7 +732,7 @@ public: mCVar = FindCVar(menu, NULL); } - double GetSliderValue() + double GetSliderValue() override { if (mCVar != NULL) { @@ -702,7 +744,7 @@ public: } } - void SetSliderValue(double val) + void SetSliderValue(double val) override { if (mCVar != NULL) { @@ -730,12 +772,12 @@ public: mPVal = pVal; } - double GetSliderValue() + double GetSliderValue() override { return *mPVal; } - void SetSliderValue(double val) + void SetSliderValue(double val) override { *mPVal = (float)val; } @@ -771,18 +813,15 @@ public: return GetCVarString(); } - int Draw ( FOptionMenuDescriptor*, int y, int indent, bool selected ) + int Draw ( FOptionMenuDescriptor*, int y, int indent, bool selected ) override { bool grayed = mGrayCheck != NULL && !( mGrayCheck->GetGenericRep( CVAR_Bool ).Bool ); - drawLabel( indent, y, selected ? OptionSettings.mFontColorSelection : OptionSettings.mFontColor, grayed ); - int overlay = grayed? MAKEARGB( 96, 48, 0, 0 ) : 0; - - DrawText(&twod, SmallFont, OptionSettings.mFontColorValue, indent + CURSORSPACE, y, - Represent().GetChars(), DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay, TAG_DONE ); + drawLabel(indent, y, selected ? OptionSettings.mFontColorSelection : OptionSettings.mFontColor, grayed); + drawValue(indent, y, OptionSettings.mFontColorValue, Represent(), grayed); return indent; } - bool GetString ( int i, char* s, int len ) + bool GetString ( int i, char* s, int len ) override { if ( i == 0 ) { @@ -794,7 +833,7 @@ public: return false; } - bool SetString ( int i, const char* s ) + bool SetString ( int i, const char* s ) override { if ( i == 0 ) { @@ -832,9 +871,9 @@ public: FOptionMenuFieldBase ( label, menu, graycheck ), mEntering ( false ) {} - FString Represent() + FString Represent() override { - FString text = mEntering ? mEditName : GetCVarString(); + FString text = mEntering ? mEditName : FString(GetCVarString()); if ( mEntering ) text += '_'; @@ -842,28 +881,28 @@ public: return text; } - int Draw(FOptionMenuDescriptor*desc, int y, int indent, bool selected) + int Draw(FOptionMenuDescriptor*desc, int y, int indent, bool selected) override { if (mEntering) { // reposition the text so that the cursor is visible when in entering mode. FString text = Represent(); int tlen = SmallFont->StringWidth(text) * CleanXfac_1; - int newindent = screen->GetWidth() - tlen - CURSORSPACE; + int newindent = screen->GetWidth() - tlen - CursorSpace(); if (newindent < indent) indent = newindent; } return FOptionMenuFieldBase::Draw(desc, y, indent, selected); } - bool MenuEvent ( int mkey, bool fromcontroller ) + bool MenuEvent ( int mkey, bool fromcontroller ) override { if ( mkey == MKEY_Enter ) { - //S_Sound( CHAN_VOICE | CHAN_UI, "menu/choose", snd_menuvolume, ATTN_NONE ); - strcpy( mEditName, GetCVarString() ); + M_MenuSound(AdvanceSound); + mEditName = GetCVarString(); mEntering = true; - //DMenu* input = new DTextEnterMenu ( DMenu::CurrentMenu, mEditName, sizeof mEditName, 2, fromcontroller ); - //M_ActivateMenu( input ); + DMenu* input = new DTextEnterMenu ( DMenu::CurrentMenu, mEditName, sizeof mEditName, 2, fromcontroller ); + M_ActivateMenu( input ); return true; } else if ( mkey == MKEY_Input ) @@ -889,7 +928,7 @@ public: private: bool mEntering; - char mEditName[128]; + FString mEditName; }; //============================================================================= @@ -918,7 +957,7 @@ public: mStep = 1; } - bool MenuEvent ( int mkey, bool fromcontroller ) + bool MenuEvent ( int mkey, bool fromcontroller ) override { if ( mCVar ) { @@ -944,7 +983,7 @@ public: UCVarValue vval; vval.Float = value; mCVar->SetGenericRep( vval, CVAR_Float ); - //S_Sound( CHAN_VOICE | CHAN_UI, "menu/change", snd_menuvolume, ATTN_NONE ); + M_MenuSound(ChangeSound); } return true; diff --git a/source/duke3d/src/d_menu.cpp b/source/duke3d/src/d_menu.cpp index e7365d722..1fb3e4438 100644 --- a/source/duke3d/src/d_menu.cpp +++ b/source/duke3d/src/d_menu.cpp @@ -38,6 +38,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "gstrings.h" #include "version.h" #include "namesdyn.h" +#include "menus.h" #include "../../glbackend/glbackend.h" BEGIN_DUKE_NS @@ -429,17 +430,21 @@ void GameInterface::MenuOpened() } } -void GameInterface::MenuSound(::GameInterface::EMenuSounds snd) +void GameInterface::MenuSound(EMenuSounds snd) { switch (snd) { - case SelectSound: + case CursorSound: S_PlaySound(KICK_HIT); break; - case ChooseSound: + case AdvanceSound: S_PlaySound(PISTOL_BODYHIT); break; + + case CloseSound: + S_PlaySound(EXITMENUSOUND); + break; default: return; @@ -449,7 +454,6 @@ void GameInterface::MenuSound(::GameInterface::EMenuSounds snd) void GameInterface::MenuClosed() { - S_PlaySound(EXITMENUSOUND); if (!ud.pause_on) S_PauseSounds(false); } @@ -473,6 +477,8 @@ void GameInterface::CustomMenuSelection(int menu, int item) VM_OnEventWithReturn(EVENT_NEWGAMECUSTOM, -1, myconnectindex, menu); } +EXTERN_CVAR(Bool, menu_sounds) + void GameInterface::StartGame(FGameStartup& gs) { int32_t skillsound = PISTOL_BODYHIT; @@ -494,7 +500,7 @@ void GameInterface::StartGame(FGameStartup& gs) } ud.m_player_skill = gs.Skill + 1; - ud.skill_voice = S_PlaySound(skillsound); + if (menu_sounds) ud.skill_voice = S_PlaySound(skillsound); ud.m_respawn_monsters = (gs.Skill == 3); ud.m_monsters_off = ud.monsters_off = 0; ud.m_respawn_items = 0; diff --git a/source/rr/src/d_menu.cpp b/source/rr/src/d_menu.cpp index 017c03485..186429bb2 100644 --- a/source/rr/src/d_menu.cpp +++ b/source/rr/src/d_menu.cpp @@ -357,27 +357,29 @@ void GameInterface::MenuOpened() } } -void GameInterface::MenuSound(::GameInterface::EMenuSounds snd) +void GameInterface::MenuSound(EMenuSounds snd) { switch (snd) { - case SelectSound: + case CursorSound: S_PlaySound(RR ? 335 : KICK_HIT); break; - case ChooseSound: + case AdvanceSound: S_PlaySound(RR? 341 : PISTOL_BODYHIT); break; + + case CloseSound: + S_PlaySound(EXITMENUSOUND); + break; default: return; } } - void GameInterface::MenuClosed() { - S_PlaySound(EXITMENUSOUND); if (!ud.pause_on) S_PauseSounds(false); } @@ -394,6 +396,7 @@ bool GameInterface::CanSave() return true; } +EXTERN_CVAR(Bool, menu_sounds) void GameInterface::StartGame(FGameStartup& gs) { int32_t skillsound = PISTOL_BODYHIT; @@ -418,7 +421,7 @@ void GameInterface::StartGame(FGameStartup& gs) } ud.m_player_skill = gs.Skill + 1; - g_skillSoundVoice = S_PlaySound(skillsound); + if (menu_sounds) g_skillSoundVoice = S_PlaySound(skillsound); ud.m_respawn_monsters = (gs.Skill == 3); ud.m_monsters_off = ud.monsters_off = 0; ud.m_respawn_items = 0; diff --git a/source/rr/src/duke3d.h b/source/rr/src/duke3d.h index 108d565f7..324b6c2a7 100644 --- a/source/rr/src/duke3d.h +++ b/source/rr/src/duke3d.h @@ -160,7 +160,7 @@ struct GameInterface : ::GameInterface GameStats getStats() override; void DrawNativeMenuText(int fontnum, int state, int xpos, int ypos, float fontscale, const char* text, int flags); void MenuOpened() override; - void MenuSound(::GameInterface::EMenuSounds snd) override; + void MenuSound(EMenuSounds snd) override; void MenuClosed() override; bool CanSave() override; void StartGame(FGameStartup& gs) override;