diff --git a/source/blood/src/endgame.cpp b/source/blood/src/endgame.cpp index 66c89f0dc..f7a7ebf29 100644 --- a/source/blood/src/endgame.cpp +++ b/source/blood/src/endgame.cpp @@ -87,7 +87,7 @@ static void drawTextScreenBackground(void) } } -// One these screens get scriptified this should use the version in menuCustomizerBlood. +// One these screens get scriptified this should use the version in BloodMenuDelegate. static void DrawCaption(const char* text) { double scalex = 1.; // Expand the box if the text is longer diff --git a/source/common/engine/namedef.h b/source/common/engine/namedef.h index e6bdcee92..d69f642c1 100644 --- a/source/common/engine/namedef.h +++ b/source/common/engine/namedef.h @@ -1086,3 +1086,11 @@ xx(wrapwidth) xx(scalefactorx) xx(scalefactory) xx(scalemode) + +xy(menu_cursor, "menu/cursor") +xy(menu_choose, "menu/choose") +xy(menu_backup, "menu/backup") +xy(menu_clear, "menu/clear") +xy(menu_dismiss, "menu/dismiss") +xy(menu_change, "menu/change") +xy(menu_advance, "menu/advance") diff --git a/source/common/menu/menu.cpp b/source/common/menu/menu.cpp index 7076d490d..41ef6d097 100644 --- a/source/common/menu/menu.cpp +++ b/source/common/menu/menu.cpp @@ -100,7 +100,7 @@ float BackbuttonAlpha; static bool MenuEnabled = true; DMenu *CurrentMenu; int MenuTime; -DObject* menuCustomizer; +DObject* menuDelegate; extern PClass *DefaultListMenuClass; @@ -192,7 +192,7 @@ void M_MarkMenus() GC::Mark(pair->Value); } GC::Mark(CurrentMenu); - GC::Mark(menuCustomizer); + GC::Mark(menuDelegate); } //============================================================================ @@ -888,7 +888,7 @@ DEFINE_GLOBAL(menuactive) DEFINE_GLOBAL(BackbuttonTime) DEFINE_GLOBAL(BackbuttonAlpha) DEFINE_GLOBAL(GameTicRate) -DEFINE_GLOBAL(menuCustomizer) +DEFINE_GLOBAL(menuDelegate) DEFINE_FIELD(DMenu, mParentMenu) DEFINE_FIELD(DMenu, mMouseCapture); diff --git a/source/common/menu/menu.h b/source/common/menu/menu.h index b92d22dfe..98cde2122 100644 --- a/source/common/menu/menu.h +++ b/source/common/menu/menu.h @@ -47,7 +47,7 @@ class DMenu; extern DMenu *CurrentMenu; extern int MenuTime; class DMenuItemBase; -extern DObject* menuCustomizer; +extern DObject* menuDelegate; //============================================================================= // diff --git a/source/common/menu/menudef.cpp b/source/common/menu/menudef.cpp index b9b97a760..bf9f52b9e 100644 --- a/source/common/menu/menudef.cpp +++ b/source/common/menu/menudef.cpp @@ -151,10 +151,10 @@ void DeinitMenus() } MenuDescriptors.Clear(); OptionValues.Clear(); - if (menuCustomizer) + if (menuDelegate) { - menuCustomizer->Destroy(); - menuCustomizer = nullptr; + menuDelegate->Destroy(); + menuDelegate = nullptr; } } diff --git a/source/common/utility/name.cpp b/source/common/utility/name.cpp index a34575df7..b1355a020 100644 --- a/source/common/utility/name.cpp +++ b/source/common/utility/name.cpp @@ -73,8 +73,10 @@ bool FName::NameManager::Inited; static const char *PredefinedNames[] = { #define xx(n) #n, +#define xy(n, s) s, #include "namedef.h" #undef xx +#undef xy }; // CODE -------------------------------------------------------------------- diff --git a/source/common/utility/name.h b/source/common/utility/name.h index 482e4f66f..de8984073 100644 --- a/source/common/utility/name.h +++ b/source/common/utility/name.h @@ -40,8 +40,10 @@ enum ENamedName { #define xx(n) NAME_##n, +#define xy(n, s) NAME_##n, #include "namedef.h" #undef xx +#undef xy }; class FString; diff --git a/source/core/menu/razemenu.cpp b/source/core/menu/razemenu.cpp index 4d6bc227c..4f6fef3fa 100644 --- a/source/core/menu/razemenu.cpp +++ b/source/core/menu/razemenu.cpp @@ -58,18 +58,7 @@ #include "gamecontrol.h" #include "raze_sound.h" #include "gamestruct.h" - -enum EMenuSounds : int -{ - ActivateSound, - CursorSound, - AdvanceSound, - BackSound, - CloseSound, - PageSound, - ChangeSound, - ChooseSound -}; +#include "razemenu.h" EXTERN_CVAR(Int, cl_gfxlocalization) EXTERN_CVAR(Bool, m_quickexit) @@ -173,17 +162,6 @@ bool M_SetSpecialMenu(FName& menu, int param) // //============================================================================= -void M_MenuSound(EMenuSounds snd) -{ - if (menu_sounds) gi->MenuSound(snd); -} - -//============================================================================= -// -// -// -//============================================================================= - void M_StartControlPanel(bool makeSound, bool) { static bool created = false; @@ -198,7 +176,7 @@ void M_StartControlPanel(bool makeSound, bool) } GSnd->SetSfxPaused(true, PAUSESFX_MENU); gi->MenuOpened(); - if (makeSound) M_MenuSound(ActivateSound); + if (makeSound && menu_sounds) gi->MenuSound(ActivateSound); M_DoStartControlPanel(false); } @@ -1149,13 +1127,13 @@ void SetDefaultMenuColors() OptionSettings.mFontColorHeader = CR_DARKGRAY; OptionSettings.mFontColorHighlight = CR_WHITE; OptionSettings.mFontColorSelection = CR_DARKRED; - cls = PClass::FindClass("MenuCustomizerBlood"); + cls = PClass::FindClass("BloodMenuDelegate"); } else if (g_gameType & GAMEFLAG_SW) { OptionSettings.mFontColorHeader = CR_DARKRED; OptionSettings.mFontColorHighlight = CR_WHITE; - cls = PClass::FindClass("MenuCustomizerSW"); + cls = PClass::FindClass("SWMenuDelegate"); } else if (g_gameType & GAMEFLAG_PSEXHUMED) { @@ -1163,7 +1141,7 @@ void SetDefaultMenuColors() OptionSettings.mFontColorHighlight = CR_SAPPHIRE; OptionSettings.mFontColorSelection = CR_ORANGE; OptionSettings.mFontColor = CR_FIRE; - cls = PClass::FindClass("MenuCustomizerExhumed"); + cls = PClass::FindClass("ExhumedMenuDelegate"); } else { @@ -1181,9 +1159,50 @@ void SetDefaultMenuColors() OptionSettings.mFontColorHighlight = CR_ORANGE; OptionSettings.mFontColorSelection = CR_TAN; } - cls = PClass::FindClass("MenuCustomizerDuke"); + cls = PClass::FindClass("DukeMenuDelegate"); } - if (!cls) cls = PClass::FindClass("MenuCustomize"); - if (cls) menuCustomizer = cls->CreateNew(); + if (!cls) cls = PClass::FindClass("RazeMenuDelegate"); + if (cls) menuDelegate = cls->CreateNew(); } + +// The sound system is not yet capable of resolving this properly. +DEFINE_ACTION_FUNCTION(_RazeMenuDelegate, PlaySound) +{ + PARAM_SELF_STRUCT_PROLOGUE(void); + PARAM_NAME(name); + EMenuSounds soundindex; + + switch (name.GetIndex()) + { + case NAME_menu_cursor: + soundindex = CursorSound; + break; + + case NAME_menu_choose: + soundindex = ChooseSound; + break; + + case NAME_menu_backup: + soundindex = BackSound; + break; + + case NAME_menu_clear: + case NAME_menu_dismiss: + soundindex = CloseSound; + break; + + case NAME_menu_change: + soundindex = ChangeSound; + break; + + case NAME_menu_advance: + soundindex = AdvanceSound; + break; + + default: + return 0; + } + gi->MenuSound(soundindex); + return 0; +} \ No newline at end of file diff --git a/wadsrc/static/zscript/base.zs b/wadsrc/static/zscript/base.zs index a33b3a40d..b79630b81 100644 --- a/wadsrc/static/zscript/base.zs +++ b/wadsrc/static/zscript/base.zs @@ -176,7 +176,7 @@ struct _ native // These are the global variables, the struct is only here to av native readonly @MusPlayingInfo musplaying; native readonly bool generic_ui; native readonly int GameTicRate; - native MenuCustomize menuCustomizer; + native MenuDelegateBase menuDelegate; native readonly int consoleplayer; } diff --git a/wadsrc/static/zscript/games/blood/ui/menu.zs b/wadsrc/static/zscript/games/blood/ui/menu.zs index 518bd6378..51f539dee 100644 --- a/wadsrc/static/zscript/games/blood/ui/menu.zs +++ b/wadsrc/static/zscript/games/blood/ui/menu.zs @@ -5,7 +5,7 @@ // //------------------------------------------------------------------------------------------- -class MenuCustomizerBlood : MenuCustomize +class BloodMenuDelegate : RazeMenuDelegate { override int DrawCaption(String title, Font fnt, int y, bool drawit) { diff --git a/wadsrc/static/zscript/games/duke/ui/menu.zs b/wadsrc/static/zscript/games/duke/ui/menu.zs index 0e5325897..27167bdeb 100644 --- a/wadsrc/static/zscript/games/duke/ui/menu.zs +++ b/wadsrc/static/zscript/games/duke/ui/menu.zs @@ -1,5 +1,5 @@ -class MenuCustomizerDuke : MenuCustomize +class DukeMenuDelegate : RazeMenuDelegate { override int DrawCaption(String title, Font fnt, int y, bool drawit) { diff --git a/wadsrc/static/zscript/games/exhumed/ui/menu.zs b/wadsrc/static/zscript/games/exhumed/ui/menu.zs index 141953e77..ea8953682 100644 --- a/wadsrc/static/zscript/games/exhumed/ui/menu.zs +++ b/wadsrc/static/zscript/games/exhumed/ui/menu.zs @@ -1,5 +1,5 @@ -class MenuCustomizerExhumed : MenuCustomize +class ExhumedMenuDelegate : RazeMenuDelegate { override int DrawCaption(String title, Font fnt, int y, bool drawit) { diff --git a/wadsrc/static/zscript/games/sw/ui/menu.zs b/wadsrc/static/zscript/games/sw/ui/menu.zs index 93cfc8306..2ae2c8766 100644 --- a/wadsrc/static/zscript/games/sw/ui/menu.zs +++ b/wadsrc/static/zscript/games/sw/ui/menu.zs @@ -1,5 +1,5 @@ -class MenuCustomizerSW : MenuCustomize +class SWMenuDelegate : RazeMenuDelegate { override int DrawCaption(String title, Font fnt, int y, bool drawit) { diff --git a/wadsrc/static/zscript/razebase.zs b/wadsrc/static/zscript/razebase.zs index 6d9460e38..f1693ba07 100644 --- a/wadsrc/static/zscript/razebase.zs +++ b/wadsrc/static/zscript/razebase.zs @@ -39,3 +39,9 @@ struct TileFiles native static TextureID GetTexture(int tile, bool animate = false); } */ + +class RazeMenuDelegate : MenuDelegateBase +{ + // Todo: Fix this so that it can be done outside the games' sound modules. + native override void PlaySound(name sname); +} diff --git a/wadsrc/static/zscript/ui/menu/listmenu.zs b/wadsrc/static/zscript/ui/menu/listmenu.zs index 786171e6a..917fe270c 100644 --- a/wadsrc/static/zscript/ui/menu/listmenu.zs +++ b/wadsrc/static/zscript/ui/menu/listmenu.zs @@ -172,7 +172,7 @@ class ListMenu : Menu case MKEY_Enter: if (mDesc.mSelectedItem >= 0 && mDesc.mItems[mDesc.mSelectedItem].Activate()) { - MenuSound("menu/choose"); + MenuSound("menu/advance"); } return true; @@ -269,7 +269,7 @@ class ListMenu : Menu } if (mDesc.mSelectedItem >= 0 && mDesc.mSelectedItem < mDesc.mItems.Size()) { - if (!menuCustomizer.DrawSelector(mDesc)) + if (!menuDelegate.DrawSelector(mDesc)) mDesc.mItems[mDesc.mSelectedItem].DrawSelector(mDesc.mSelectOfsX, mDesc.mSelectOfsY, mDesc.mSelector, mDesc); } Super.Drawer(); diff --git a/wadsrc/static/zscript/ui/menu/listmenuitems.zs b/wadsrc/static/zscript/ui/menu/listmenuitems.zs index 391195cfd..13d96281c 100644 --- a/wadsrc/static/zscript/ui/menu/listmenuitems.zs +++ b/wadsrc/static/zscript/ui/menu/listmenuitems.zs @@ -363,7 +363,7 @@ class ListMenuItemCaptionItem : ListMenuItem let font = generic_ui || !desc.mFont ? NewSmallFont : desc.mFont; if (font && mText.Length() > 0) { - menuCustomizer.DrawCaption(mText, font, 0, true); + menuDelegate.DrawCaption(mText, font, 0, true); } } } diff --git a/wadsrc/static/zscript/ui/menu/menu.zs b/wadsrc/static/zscript/ui/menu/menu.zs index a611a3296..92f30adcb 100644 --- a/wadsrc/static/zscript/ui/menu/menu.zs +++ b/wadsrc/static/zscript/ui/menu/menu.zs @@ -285,8 +285,7 @@ class Menu : Object native ui version("2.4") static void MenuSound(Name snd) { - // todo: Cannot use game specific IDs here - sound also may be set up too late by the games - //S_StartSound (snd, CHAN_VOICE, CHANF_MAYBE_LOCAL|CHAN_UI, snd_menuvolume, ATTN_NONE); + menuDelegate.PlaySound(snd); } deprecated("4.0") static void DrawConText (int color, int x, int y, String str) diff --git a/wadsrc/static/zscript/ui/menu/menucustomize.zs b/wadsrc/static/zscript/ui/menu/menucustomize.zs index de0b1357b..ccc437e7d 100644 --- a/wadsrc/static/zscript/ui/menu/menucustomize.zs +++ b/wadsrc/static/zscript/ui/menu/menucustomize.zs @@ -1,6 +1,6 @@ // This class allows global customization of certain menu aspects, e.g. replacing the menu caption. -class MenuCustomize +class MenuDelegateBase { virtual int DrawCaption(String title, Font fnt, int y, bool drawit) { diff --git a/wadsrc/static/zscript/ui/menu/optionmenu.zs b/wadsrc/static/zscript/ui/menu/optionmenu.zs index 87242f937..6392adf3f 100644 --- a/wadsrc/static/zscript/ui/menu/optionmenu.zs +++ b/wadsrc/static/zscript/ui/menu/optionmenu.zs @@ -433,7 +433,7 @@ class OptionMenu : Menu let font = generic_ui || !mDesc.mFont ? NewSmallFont : mDesc.mFont; if (font && mDesc.mTitle.Length() > 0) { - return menuCustomizer.DrawCaption(title, font, y, drawit); + return menuDelegate.DrawCaption(title, font, y, drawit); } else {