From cdb383576deca7979b8a0401b4bdd746189764ab Mon Sep 17 00:00:00 2001 From: danij Date: Tue, 1 Jul 2014 19:25:45 +0100 Subject: [PATCH] Cleanup|libcommon: Moved G_MapTitle, G_MapAuthor and G_MapTitlePatch to g_game.cpp --- doomsday/plugins/common/include/g_common.h | 6 + doomsday/plugins/common/include/p_mapsetup.h | 6 - doomsday/plugins/common/src/g_game.cpp | 166 +++++++++++++++---- doomsday/plugins/common/src/hu_stuff.cpp | 4 +- doomsday/plugins/common/src/p_mapsetup.cpp | 105 ------------ 5 files changed, 144 insertions(+), 143 deletions(-) diff --git a/doomsday/plugins/common/include/g_common.h b/doomsday/plugins/common/include/g_common.h index f8767d82a5..b171c89b0f 100644 --- a/doomsday/plugins/common/include/g_common.h +++ b/doomsday/plugins/common/include/g_common.h @@ -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 diff --git a/doomsday/plugins/common/include/p_mapsetup.h b/doomsday/plugins/common/include/p_mapsetup.h index 7c8893e286..79920d8199 100644 --- a/doomsday/plugins/common/include/p_mapsetup.h +++ b/doomsday/plugins/common/include/p_mapsetup.h @@ -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 diff --git a/doomsday/plugins/common/src/g_game.cpp b/doomsday/plugins/common/src/g_game.cpp index bf07fac55b..2f97aac44c 100644 --- a/doomsday/plugins/common/src/g_game.cpp +++ b/doomsday/plugins/common/src/g_game.cpp @@ -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) { @@ -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; @@ -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); diff --git a/doomsday/plugins/common/src/hu_stuff.cpp b/doomsday/plugins/common/src/hu_stuff.cpp index 9aac35aa2c..9d01411caf 100644 --- a/doomsday/plugins/common/src/hu_stuff.cpp +++ b/doomsday/plugins/common/src/hu_stuff.cpp @@ -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; } @@ -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); diff --git a/doomsday/plugins/common/src/p_mapsetup.cpp b/doomsday/plugins/common/src/p_mapsetup.cpp index 41b1cfb44e..561bbc40f4 100644 --- a/doomsday/plugins/common/src/p_mapsetup.cpp +++ b/doomsday/plugins/common/src/p_mapsetup.cpp @@ -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(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() {