Skip to content

Commit

Permalink
libcommon: Use the now public ded_t API to lookup Text definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Nov 30, 2014
1 parent 52273d7 commit 28423fb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
14 changes: 8 additions & 6 deletions doomsday/plugins/common/src/g_game.cpp
Expand Up @@ -2076,11 +2076,12 @@ String G_EpisodeTitle(String episodeId)
if(Record const *episodeDef = Defs().episodes.tryFind("id", episodeId))
{
title = episodeDef->gets("title");

// Perhaps the title string is a reference to a Text definition?
void *ptr;
if(Def_Get(DD_DEF_TEXT, title.toUtf8().constData(), &ptr) != -1)
int textIdx = Defs().getTextNumForName(title.toUtf8().constData());
if(textIdx >= 0)
{
title = (char const *) ptr; // Yes, use the resolved text string.
title = Defs().text[textIdx].text; // Yes, use the resolved text string.
}
}
return title;
Expand All @@ -2094,11 +2095,12 @@ String G_MapTitle(de::Uri const &mapUri)
if(Record const *mapInfo = Defs().mapInfos.tryFind("id", mapUri.compose()))
{
title = mapInfo->gets("title");

// Perhaps the title string is a reference to a Text definition?
void *ptr;
if(Def_Get(DD_DEF_TEXT, title.toUtf8().constData(), &ptr) != -1)
int textIdx = Defs().getTextNumForName(title.toUtf8().constData());
if(textIdx >= 0)
{
title = (char const *) ptr; // Yes, use the resolved text string.
title = Defs().text[textIdx].text; // Yes, use the resolved text string.
}
}

Expand Down
12 changes: 4 additions & 8 deletions doomsday/plugins/common/src/hu_menu.cpp
Expand Up @@ -1802,13 +1802,9 @@ void Hu_MenuInitEpisodePage()
for(auto const &pair : episodesById)
{
Record const &episodeDef = *pair.second->as<RecordValue>().record();
String const episodeId = episodeDef.gets("id");

String title = episodeDef.gets("title");
// Perhaps a Text definition?
int textIdx = Defs().getTextNumForName(title.toUtf8().constData());
if(textIdx >= 0) title = String(Defs().text[textIdx].text); // Yes, use the resolved text string.

auto *btn = new ButtonWidget(title);
auto *btn = new ButtonWidget(G_EpisodeTitle(episodeId));
btn->setFixedY(y);

// Has a menu image been specified?
Expand Down Expand Up @@ -1841,7 +1837,7 @@ void Hu_MenuInitEpisodePage()
if(P_MapExists(startMap.compose().toUtf8().constData()))
{
btn->setAction(Widget::Deactivated, Hu_MenuSelectEpisode);
btn->setUserValue(episodeDef.gets("id"));
btn->setUserValue(episodeId);
}
else
{
Expand All @@ -1864,7 +1860,7 @@ void Hu_MenuInitEpisodePage()
btn->setFlags(Widget::Disabled);
LOG_RES_WARNING("Failed to locate the starting map \"%s\" for episode '%s'."
" This episode will not be selectable from the menu")
<< startMap << episodeDef.gets("id");
<< startMap << episodeId;
}
}

Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/common/src/p_inventory.cpp
Expand Up @@ -303,9 +303,9 @@ void P_InitInventory()
continue;

data->type = type;
data->niceName = textenum_t(Def_Get(DD_DEF_TEXT, (char *) def->niceName, NULL));
data->niceName = textenum_t(Defs().getTextNumForName(def->niceName));
data->action = getActionPtr(def->action);
data->useSnd = sfxenum_t(Def_Get(DD_DEF_SOUND, (char *) def->useSnd, NULL));
data->useSnd = sfxenum_t(Defs().getSoundNum(def->useSnd));
data->patchId = R_DeclarePatch(def->patch);
}

Expand Down

0 comments on commit 28423fb

Please sign in to comment.