Skip to content

Commit

Permalink
libcommon: Added 'menuHelpInfo' and 'menuShortcut' to EpisodeInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jul 22, 2014
1 parent fbb0baa commit 48fb339
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 73 deletions.
73 changes: 24 additions & 49 deletions doomsday/plugins/common/src/hu_menu.cpp
Expand Up @@ -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.
*/
Expand All @@ -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"));

Expand All @@ -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__
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions doomsday/plugins/common/src/mapinfo.cpp
Expand Up @@ -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.
}

/**
Expand Down
94 changes: 70 additions & 24 deletions doomsday/plugins/common/src/p_start.cpp
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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__
Expand Down

0 comments on commit 48fb339

Please sign in to comment.