From 48fb339442ab8fd9e271d917efcec989d5b413fd Mon Sep 17 00:00:00 2001 From: danij Date: Wed, 23 Jul 2014 00:00:42 +0100 Subject: [PATCH] libcommon: Added 'menuHelpInfo' and 'menuShortcut' to EpisodeInfo --- doomsday/plugins/common/src/hu_menu.cpp | 73 +++++++------------ doomsday/plugins/common/src/mapinfo.cpp | 2 + doomsday/plugins/common/src/p_start.cpp | 94 ++++++++++++++++++------- 3 files changed, 96 insertions(+), 73 deletions(-) diff --git a/doomsday/plugins/common/src/hu_menu.cpp b/doomsday/plugins/common/src/hu_menu.cpp index fe4f7c345e..a4a418acba 100644 --- a/doomsday/plugins/common/src/hu_menu.cpp +++ b/doomsday/plugins/common/src/hu_menu.cpp @@ -3038,41 +3038,6 @@ void Hu_MenuInitSoundOptionsPage() #if __JDOOM__ || __JHERETIC__ -#if __JHERETIC__ -static String composeNotDesignedForMessage(char const *gameModeName) -{ - DENG2_ASSERT(gameModeName != 0); - - String msg; - - char tmp[2]; - tmp[1] = 0; - - // Get the message template. - char const *in = GET_TXT(TXT_NOTDESIGNEDFOR); - - for(; *in; in++) - { - if(in[0] == '%') - { - if(in[1] == '1') - { - msg += gameModeName; - in++; - continue; - } - - if(in[1] == '%') - in++; - } - tmp[0] = *in; - msg += tmp; - } - - return msg; -} -#endif - /** * Construct the episode selection menu. */ @@ -3084,7 +3049,7 @@ void Hu_MenuInitEpisodePage() Point2Raw const origin(80, 50); #endif - Page *page = Hu_MenuNewPage("Episode", &origin, MPF_LAYOUT_FIXED|MPF_NEVER_SCROLL, Hu_MenuPageTicker, Hu_MenuDrawEpisodePage, NULL, NULL); + Page *page = Hu_MenuNewPage("Episode", &origin, MPF_LAYOUT_FIXED|MPF_NEVER_SCROLL, Hu_MenuPageTicker, Hu_MenuDrawEpisodePage); page->setPredefinedFont(MENU_FONT1, FID(GF_FONTB)); page->setPreviousPage(Hu_MenuFindPageByName("GameType")); @@ -3095,21 +3060,37 @@ void Hu_MenuInitEpisodePage() EpisodeInfo const &info = it->second; ButtonWidget *btn = new ButtonWidget; - btn->_origin.y = y; - btn->setText(info.gets("title")); - if(!btn->text().isEmpty() && btn->text().first().isLetterOrNumber()) - { - btn->setShortcut(btn->text().first().toLower().toLatin1()); - } + + btn->setText(info.gets("title")) + .setFixedY(y); + + // Has a menu image been specified? de::Uri image(info.gets("menuImage"), RC_NULL); if(!image.path().isEmpty()) { + // Presently only patches are supported. if(!image.scheme().compareWithoutCase("Patches")) { btn->setPatch(R_DeclarePatch(image.path().toUtf8().constData())); } } + // Has a menu shortcut/hotkey been specified? + /// @todo Validate symbolic dday key names. + String const shortcut = info.gets("menuShortcut"); + if(!shortcut.isEmpty() && shortcut.first().isLetterOrNumber()) + { + btn->setShortcut(shortcut.first().toLower().toLatin1()); + } + + // Has a menu help/info text been specified? + String const helpInfo = info.gets("menuHelpInfo"); + if(!helpInfo.isEmpty()) + { + // Inform the user that this episode is not designed for singleplayer. + btn->setHelpInfo(helpInfo); + } + de::Uri startMap(info.gets("startMap"), RC_NULL); if( #if __JHERETIC__ @@ -3125,14 +3106,8 @@ void Hu_MenuInitEpisodePage() { btn->actions[Widget::MNA_ACTIVEOUT].callback = Hu_MenuActionSetActivePage; btn->data1 = (void *)"Skill"; -#if __JHERETIC__ - if(gameMode == heretic_extended && startMap.path() == "E6M1") - { - // Inform the user that this episode is not designed for singleplayer. - btn->setHelpInfo(composeNotDesignedForMessage(GET_TXT(TXT_SINGLEPLAYER))); - } -#endif } + btn->actions[Widget::MNA_FOCUS].callback = Hu_MenuFocusEpisode; btn->data2 = n; btn->_pageFontIdx = MENU_FONT1; diff --git a/doomsday/plugins/common/src/mapinfo.cpp b/doomsday/plugins/common/src/mapinfo.cpp index b8b03a807b..6540089a7a 100644 --- a/doomsday/plugins/common/src/mapinfo.cpp +++ b/doomsday/plugins/common/src/mapinfo.cpp @@ -113,7 +113,9 @@ void EpisodeInfo::resetToDefaults() // Add all expected fields with their default values. addText("startMap", "Maps:"); // URI. Unknown. addText("title", "Untitled"); + addText("menuHelpInfo", ""); // None. addText("menuImage", ""); // URI. None. + addText("menuShortcut", ""); // Key name. None. } /** diff --git a/doomsday/plugins/common/src/p_start.cpp b/doomsday/plugins/common/src/p_start.cpp index 6d739a876e..63732484f6 100644 --- a/doomsday/plugins/common/src/p_start.cpp +++ b/doomsday/plugins/common/src/p_start.cpp @@ -186,6 +186,41 @@ void P_Init() P_Update(); } +#if __JHERETIC__ +static String composeNotDesignedForMessage(char const *gameModeName) +{ + DENG2_ASSERT(gameModeName != 0); + + String msg; + + char tmp[2]; + tmp[1] = 0; + + // Get the message template. + char const *in = GET_TXT(TXT_NOTDESIGNEDFOR); + + for(; *in; in++) + { + if(in[0] == '%') + { + if(in[1] == '1') + { + msg += gameModeName; + in++; + continue; + } + + if(in[1] == '%') + in++; + } + tmp[0] = *in; + msg += tmp; + } + + return msg; +} +#endif + #if __JHEXEN__ static void readOneMapInfoDefinition(MapInfoParser &parser, AutoStr const &buffer, String sourceFile) { @@ -241,62 +276,73 @@ static void readMapInfoDefinitions() { { EpisodeInfo &info = hexDefs.episodeInfos["1"]; - info.set("startMap", "Maps:E1M1"); - info.set("title", GET_TXT(TXT_EPISODE1)); - info.set("menuImage", "Patches:M_EPI1"); + info.set("startMap", "Maps:E1M1"); + info.set("title", GET_TXT(TXT_EPISODE1)); + info.set("menuImage", "Patches:M_EPI1"); + info.set("menuShortcut", "k"); } { EpisodeInfo &info = hexDefs.episodeInfos["2"]; - info.set("startMap", "Maps:E2M1"); - info.set("title", GET_TXT(TXT_EPISODE2)); - info.set("menuImage", "Patches:M_EPI2"); + info.set("startMap", "Maps:E2M1"); + info.set("title", GET_TXT(TXT_EPISODE2)); + info.set("menuImage", "Patches:M_EPI2"); + info.set("menuShortcut", "s"); } { EpisodeInfo &info = hexDefs.episodeInfos["3"]; - info.set("startMap", "Maps:E3M1"); - info.set("title", GET_TXT(TXT_EPISODE3)); - info.set("menuImage", "Patches:M_EPI3"); + info.set("startMap", "Maps:E3M1"); + info.set("title", GET_TXT(TXT_EPISODE3)); + info.set("menuImage", "Patches:M_EPI3"); + info.set("menuShortcut", "i"); } if(gameMode == doom_ultimate) { EpisodeInfo &info = hexDefs.episodeInfos["4"]; - info.set("startMap", "Maps:E3M1"); - info.set("title", GET_TXT(TXT_EPISODE4)); - info.set("menuImage", "Patches:M_EPI4"); + info.set("startMap", "Maps:E3M1"); + info.set("title", GET_TXT(TXT_EPISODE4)); + info.set("menuImage", "Patches:M_EPI4"); + info.set("menuShortcut", "f"); } } #elif __JHERETIC__ { EpisodeInfo &info = hexDefs.episodeInfos["1"]; - info.set("startMap", "Maps:E1M1"); - info.set("title", GET_TXT(TXT_EPISODE1)); + info.set("startMap", "Maps:E1M1"); + info.set("title", GET_TXT(TXT_EPISODE1)); + info.set("menuShortcut", "c"); } { EpisodeInfo &info = hexDefs.episodeInfos["2"]; - info.set("startMap", "Maps:E2M1"); - info.set("title", GET_TXT(TXT_EPISODE2)); + info.set("startMap", "Maps:E2M1"); + info.set("title", GET_TXT(TXT_EPISODE2)); + info.set("menuShortcut", "h"); } { EpisodeInfo &info = hexDefs.episodeInfos["3"]; - info.set("startMap", "Maps:E3M1"); - info.set("title", GET_TXT(TXT_EPISODE3)); + info.set("startMap", "Maps:E3M1"); + info.set("title", GET_TXT(TXT_EPISODE3)); + info.set("menuShortcut", "d"); } if(gameMode == heretic_extended) { { EpisodeInfo &info = hexDefs.episodeInfos["4"]; - info.set("startMap", "Maps:E4M1"); - info.set("title", GET_TXT(TXT_EPISODE4)); + info.set("startMap", "Maps:E4M1"); + info.set("title", GET_TXT(TXT_EPISODE4)); + info.set("menuShortcut", "o"); } { EpisodeInfo &info = hexDefs.episodeInfos["5"]; - info.set("startMap", "Maps:E5M1"); - info.set("title", GET_TXT(TXT_EPISODE5)); + info.set("startMap", "Maps:E5M1"); + info.set("title", GET_TXT(TXT_EPISODE5)); + info.set("menuShortcut", "s"); } { EpisodeInfo &info = hexDefs.episodeInfos["6"]; - info.set("startMap", "Maps:E6M1"); - info.set("title", GET_TXT(TXT_EPISODE6)); + info.set("startMap", "Maps:E6M1"); + info.set("title", GET_TXT(TXT_EPISODE6)); + info.set("menuShortcut", "f"); + info.set("menuHelpInfo", composeNotDesignedForMessage(GET_TXT(TXT_SINGLEPLAYER))); } } #else // __JHEXEN__ || __JDOOM64__