Skip to content

Commit

Permalink
Cleanup|libcommon: Moved G_MapTitle, G_MapAuthor and G_MapTitlePatch …
Browse files Browse the repository at this point in the history
…to g_game.cpp
  • Loading branch information
danij-deng committed Jul 1, 2014
1 parent 1b2f062 commit cdb3835
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 143 deletions.
6 changes: 6 additions & 0 deletions doomsday/plugins/common/include/g_common.h
Expand Up @@ -126,6 +126,12 @@ de::String G_MapAuthor(de::Uri const *mapUri, bool supressGameAuthor = false);
*/
de::String G_MapTitle(de::Uri const *mapUri);

/**
* @param mapUri Identifier of the map to lookup the title of. Can be @c 0 in which
* case the title for the @em current map will be returned (if set).
*/
patchid_t G_MapTitlePatch(de::Uri const *mapUri);

extern "C" {
#endif

Expand Down
6 changes: 0 additions & 6 deletions doomsday/plugins/common/include/p_mapsetup.h
Expand Up @@ -52,12 +52,6 @@ void P_SetupMap(Uri const *uri);
*/
void P_ResetWorldState();

/**
* @param mapUri Identifier of the map to lookup the title of. Can be @c 0 in which
* case the title for the @em current map will be returned (if set).
*/
patchid_t P_MapTitlePatch(Uri const *mapUri);

#if __JDOOM__ || __JDOOM64__ || __JHERETIC__
void P_FindSecrets(void);
#endif
Expand Down
166 changes: 136 additions & 30 deletions doomsday/plugins/common/src/g_game.cpp
Expand Up @@ -2392,37 +2392,7 @@ uint G_MapNumberFor(de::Uri const &mapUri)
return 0;
}

static int quitGameConfirmed(msgresponse_t response, int /*userValue*/, void * /*userPointer*/)
{
if(response == MSG_YES)
{
G_SetGameAction(GA_QUIT);
}
return true;
}

void G_QuitGame()
{
if(G_QuitInProgress()) return;

if(Hu_IsMessageActiveWithCallback(quitGameConfirmed))
{
// User has re-tried to quit with "quit" when the question is already on
// the screen. Apparently we should quit...
DD_Execute(true, "quit!");
return;
}

char const *endString;
#if __JDOOM__ || __JDOOM64__
endString = endmsg[((int) GAMETIC % (NUM_QUITMESSAGES + 1))];
#else
endString = GET_TXT(TXT_QUITMSG);
#endif

Con_Open(false);
Hu_MsgStart(MSG_YESNO, endString, quitGameConfirmed, 0, NULL);
}

uint G_LogicalMapNumber(uint episode, uint map)
{
Expand Down Expand Up @@ -2668,6 +2638,110 @@ uint G_NextLogicalMapNumber(dd_bool secretExit)
return G_GetNextMap(gameEpisode, gameMap, secretExit);
}

String G_MapTitle(de::Uri const *mapUri)
{
if(!mapUri) mapUri = &gameMapUri;

String title;

// Perhaps a MapInfo definition exists for the map?
ddmapinfo_t mapInfo;
if(Def_Get(DD_DEF_MAP_INFO, mapUri->compose().toUtf8().constData(), &mapInfo))
{
if(mapInfo.name[0])
{
// Perhaps the title string is a reference to a Text definition?
void *ptr;
if(Def_Get(DD_DEF_TEXT, mapInfo.name, &ptr) != -1)
{
title = (char const *) ptr; // Yes, use the resolved text string.
}
else
{
title = mapInfo.name;
}
}
}

#if __JHEXEN__
// In Hexen we can also look in MAPINFO for the map title.
if(title.isEmpty())
{
if(mapinfo_t const *mapInfo = P_MapInfo(mapUri))
{
title = mapInfo->title;
}
}
#endif

// Skip the "ExMx" part, if present.
int idSuffixAt = title.indexOf(':');
if(idSuffixAt >= 0)
{
int subStart = idSuffixAt + 1;
while(subStart < title.length() && title.at(subStart).isSpace()) { subStart++; }

return title.substr(subStart);
}

return title;
}

String G_MapAuthor(de::Uri const *mapUri, bool supressGameAuthor)
{
if(!mapUri) mapUri = &gameMapUri;

String mapUriAsText = mapUri->resolved();
if(mapUriAsText.isEmpty()) return ""; // Huh??

// Perhaps a MapInfo definition exists for the map?
ddmapinfo_t mapInfo;
String author;
if(Def_Get(DD_DEF_MAP_INFO, mapUriAsText.toUtf8().constData(), &mapInfo))
{
author = mapInfo.author;
}

if(!author.isEmpty())
{
// Should we suppress the author?
/// @todo Do not do this here.
GameInfo gameInfo;
DD_GameInfo(&gameInfo);
if(supressGameAuthor || P_MapIsCustom(mapUriAsText.toUtf8().constData()))
{
if(!author.compareWithoutCase(Str_Text(gameInfo.author)))
return "";
}
}

return author;
}

patchid_t G_MapTitlePatch(de::Uri const *mapUri)
{
if(!mapUri) mapUri = &gameMapUri;

#if __JDOOM__ || __JDOOM64__
uint map = G_MapNumberFor(*mapUri);
# if __JDOOM__
if(!(gameModeBits & (GM_ANY_DOOM2|GM_DOOM_CHEX)))
{
uint episode = G_EpisodeNumberFor(*mapUri);
map = (episode * 9) + map;
}
# endif
if(map < pMapNamesSize)
{
return pMapNames[map];
}
#else
DENG2_UNUSED(mapUri);
#endif

return 0;
}

char const *G_InFine(char const *scriptId)
{
ddfinale_t fin;
Expand Down Expand Up @@ -2779,6 +2853,38 @@ int Hook_DemoStop(int /*hookType*/, int val, void * /*context*/)
return true;
}

static int quitGameConfirmed(msgresponse_t response, int /*userValue*/, void * /*userPointer*/)
{
if(response == MSG_YES)
{
G_SetGameAction(GA_QUIT);
}
return true;
}

void G_QuitGame()
{
if(G_QuitInProgress()) return;

if(Hu_IsMessageActiveWithCallback(quitGameConfirmed))
{
// User has re-tried to quit with "quit" when the question is already on
// the screen. Apparently we should quit...
DD_Execute(true, "quit!");
return;
}

char const *endString;
#if __JDOOM__ || __JDOOM64__
endString = endmsg[((int) GAMETIC % (NUM_QUITMESSAGES + 1))];
#else
endString = GET_TXT(TXT_QUITMSG);
#endif

Con_Open(false);
Hu_MsgStart(MSG_YESNO, endString, quitGameConfirmed, 0, NULL);
}

D_CMD(OpenLoadMenu)
{
DENG2_UNUSED3(src, argc, argv);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/common/src/hu_stuff.cpp
Expand Up @@ -1474,7 +1474,7 @@ int Hu_MapTitleFirstLineHeight()
{
int y = 0;
patchinfo_t patchInfo;
if(R_GetPatchInfo(P_MapTitlePatch(0/*current map*/), &patchInfo))
if(R_GetPatchInfo(G_MapTitlePatch(0/*current map*/), &patchInfo))
{
y = patchInfo.geometry.size.height + 2;
}
Expand Down Expand Up @@ -1516,7 +1516,7 @@ void Hu_DrawMapTitle(float alpha, dd_bool mapIdInsteadOfAuthor)
FR_SetColorAndAlpha(defFontRGB[0], defFontRGB[1], defFontRGB[2], alpha);

#if __JDOOM__ || __JDOOM64__
patchid_t patchId = P_MapTitlePatch(0/*current map*/);
patchid_t patchId = G_MapTitlePatch(0/*current map*/);
WI_DrawPatchXY3(patchId, Hu_ChoosePatchReplacement2(PRM_ALLOW_TEXT, patchId, title.toUtf8().constData()),
0, 0, ALIGN_TOP, 0, DTF_ONLY_SHADOW);

Expand Down
105 changes: 0 additions & 105 deletions doomsday/plugins/common/src/p_mapsetup.cpp
Expand Up @@ -1102,111 +1102,6 @@ void P_ResetWorldState()
#endif
}

String G_MapTitle(de::Uri const *mapUri)
{
if(!mapUri) mapUri = &gameMapUri;

String title;

// Perhaps a MapInfo definition exists for the map?
ddmapinfo_t mapInfo;
if(Def_Get(DD_DEF_MAP_INFO, mapUri->compose().toUtf8().constData(), &mapInfo))
{
if(mapInfo.name[0])
{
// Perhaps the title string is a reference to a Text definition?
void *ptr;
if(Def_Get(DD_DEF_TEXT, mapInfo.name, &ptr) != -1)
{
title = (char const *) ptr; // Yes, use the resolved text string.
}
else
{
title = mapInfo.name;
}
}
}

#if __JHEXEN__
// In Hexen we can also look in MAPINFO for the map title.
if(title.isEmpty())
{
if(mapinfo_t const *mapInfo = P_MapInfo(mapUri))
{
title = mapInfo->title;
}
}
#endif

// Skip the "ExMx" part, if present.
int idSuffixAt = title.indexOf(':');
if(idSuffixAt >= 0)
{
int subStart = idSuffixAt + 1;
while(subStart < title.length() && title.at(subStart).isSpace()) { subStart++; }

return title.substr(subStart);
}

return title;
}

String G_MapAuthor(de::Uri const *mapUri, bool supressGameAuthor)
{
if(!mapUri) mapUri = &gameMapUri;

String mapUriAsText = mapUri->resolved();
if(mapUriAsText.isEmpty()) return ""; // Huh??

// Perhaps a MapInfo definition exists for the map?
ddmapinfo_t mapInfo;
String author;
if(Def_Get(DD_DEF_MAP_INFO, mapUriAsText.toUtf8().constData(), &mapInfo))
{
author = mapInfo.author;
}

if(!author.isEmpty())
{
// Should we suppress the author?
/// @todo Do not do this here.
GameInfo gameInfo;
DD_GameInfo(&gameInfo);
if(supressGameAuthor || P_MapIsCustom(mapUriAsText.toUtf8().constData()))
{
if(!author.compareWithoutCase(Str_Text(gameInfo.author)))
return "";
}
}

return author;
}

patchid_t P_MapTitlePatch(uri_s const *mapUri_)
{
de::Uri const *mapUri = reinterpret_cast<de::Uri const *>(mapUri_);
if(!mapUri) mapUri = &gameMapUri;

#if __JDOOM__ || __JDOOM64__
uint map = G_MapNumberFor(*mapUri);
# if __JDOOM__
if(!(gameModeBits & (GM_ANY_DOOM2|GM_DOOM_CHEX)))
{
uint episode = G_EpisodeNumberFor(*mapUri);
map = (episode * 9) + map;
}
# endif
if(map < pMapNamesSize)
{
return pMapNames[map];
}
#else
DENG2_UNUSED(mapUri);
#endif

return 0;
}

#if __JDOOM__ || __JDOOM64__ || __JHERETIC__
void P_FindSecrets()
{
Expand Down

0 comments on commit cdb3835

Please sign in to comment.