From 7a9138cde0a2f58709c8dc49cf3d6bc53f2f9432 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 5 Dec 2019 23:17:55 +0100 Subject: [PATCH] - made the confirmation screen functional. This works but still needs a bit of visual work. --- source/blood/src/blood.h | 1 + source/blood/src/d_menu.cpp | 10 ++ source/build/include/baselayer.h | 2 +- source/common/menu/menu.cpp | 12 +-- source/common/menu/messagebox.cpp | 158 ++++++++++++++---------------- source/duke3d/src/d_menu.cpp | 4 +- source/duke3d/src/duke3d.h | 2 +- source/rr/src/d_menu.cpp | 4 +- source/rr/src/duke3d.h | 2 +- source/sw/src/d_menu.cpp | 18 +++- source/sw/src/game.h | 2 +- 11 files changed, 113 insertions(+), 102 deletions(-) diff --git a/source/blood/src/blood.h b/source/blood/src/blood.h index 5328b470b..776b4e319 100644 --- a/source/blood/src/blood.h +++ b/source/blood/src/blood.h @@ -98,6 +98,7 @@ struct GameInterface : ::GameInterface bool SaveGame(FSaveGameNode*) override; bool LoadGame(FSaveGameNode*) override; void DoPrintMessage(int prio, const char*) override; + void DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool bg); }; diff --git a/source/blood/src/d_menu.cpp b/source/blood/src/d_menu.cpp index 66f088d5a..107c2a933 100644 --- a/source/blood/src/d_menu.cpp +++ b/source/blood/src/d_menu.cpp @@ -280,6 +280,16 @@ void GameInterface::DrawMenuCaption(const DVector2& origin, const char* text) viewDrawText(1, text, 160, 20 - height / 2, -128, 0, 1, false); } +void GameInterface::DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool bg) +{ + if (text) + { + int width; + viewGetFontInfo(0, text, &width, NULL); + int x = 160 - width / 2; + viewDrawText(0, text, x, 100, 0, 0, 0, false); + } +} END_BLD_NS diff --git a/source/build/include/baselayer.h b/source/build/include/baselayer.h index c3a878b33..5c39c6bab 100644 --- a/source/build/include/baselayer.h +++ b/source/build/include/baselayer.h @@ -223,7 +223,7 @@ struct GameInterface virtual void StartGame(FGameStartup& gs) {} virtual FSavegameInfo GetSaveSig() { return { "", 0, 0}; } virtual bool DrawSpecialScreen(const DVector2 &origin, int tilenum) { return false; } - virtual void DrawCenteredTextScreen(const DVector2& origin, const char* text, int position) {} + virtual void DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool withbg = true) {} virtual void DrawMenuCaption(const DVector2& origin, const char* text) {} virtual bool SaveGame(FSaveGameNode*) { return false; } virtual bool LoadGame(FSaveGameNode*) { return false; } diff --git a/source/common/menu/menu.cpp b/source/common/menu/menu.cpp index a001ea575..ee1191f0e 100644 --- a/source/common/menu/menu.cpp +++ b/source/common/menu/menu.cpp @@ -480,23 +480,23 @@ bool M_SetMenu(FName menu, int param, FName caller) M_StartMessage (msg, 0, -1, NAME_StartgameConfirmed); return; } +#endif - case NAME_Savegamemenu: - if (gi->canSave()) + case NAME_SaveGameMenu: + if (!gi->CanSave()) { // cannot save outside the game. M_StartMessage (GStrings("SAVEDEAD"), 1, -1); - return; + return true; } -#endif case NAME_QuitMenu: - // The separate menu class no longer exists but the name still needs support for existing mods. + // This is no separate class C_DoCommand("menu_quit"); return true; case NAME_EndgameMenu: - // The separate menu class no longer exists but the name still needs support for existing mods. + // This is no separate class C_DoCommand("memnu_endgame"); return true; } diff --git a/source/common/menu/messagebox.cpp b/source/common/menu/messagebox.cpp index 9326dd6ae..a40343405 100644 --- a/source/common/menu/messagebox.cpp +++ b/source/common/menu/messagebox.cpp @@ -46,6 +46,7 @@ extern FSaveGameNode *quickSaveSlot; class DMessageBoxMenu : public DMenu { using Super = DMenu; + FString mFullMessage; TArray mMessage; int mMessageMode; int messageSelection; @@ -99,6 +100,7 @@ void DMessageBoxMenu::Init(DMenu *parent, const char *message, int messagemode, mParentMenu = parent; if (message != NULL) { + mFullMessage = message; mMessage = V_BreakLines(SmallFont, 300, GStrings.localize(message)); } mMessageMode = messagemode; @@ -168,8 +170,9 @@ void DMessageBoxMenu::HandleResult(bool res) // // //============================================================================= +CVAR(Bool, m_generic_messagebox, false, CVAR_ARCHIVE) -void DMessageBoxMenu::Drawer () +void DMessageBoxMenu::Drawer() { int y; PalEntry fade = 0; @@ -180,43 +183,51 @@ void DMessageBoxMenu::Drawer () y = 100; - if (mMessage.Size()) + if (m_generic_messagebox) { - for (unsigned i = 0; i < mMessage.Size(); i++) - y -= SmallFont->GetHeight () / 2; - - for (unsigned i = 0; i < mMessage.Size(); i++) + if (mMessage.Size()) { - DrawText(&twod, SmallFont, CR_UNTRANSLATED, 160 - mMessage[i].Width/2, y, mMessage[i].Text, - DTA_Clean, true, TAG_DONE); - y += fontheight; - } - } + for (unsigned i = 0; i < mMessage.Size(); i++) + y -= SmallFont->GetHeight() / 2; - if (mMessageMode == 0) - { - y += fontheight; - mMouseY = y; - DrawText(&twod, SmallFont, - messageSelection == 0? OptionSettings.mFontColorSelection : OptionSettings.mFontColor, - 160, y, GStrings["TXT_YES"], DTA_Clean, true, TAG_DONE); - DrawText(&twod, SmallFont, - messageSelection == 1? OptionSettings.mFontColorSelection : OptionSettings.mFontColor, - 160, y + fontheight + 1, GStrings["TXT_NO"], DTA_Clean, true, TAG_DONE); - - if (messageSelection >= 0) - { - if (((DMenu::MenuTime>>2)%8) < 6) + for (unsigned i = 0; i < mMessage.Size(); i++) { - DrawText(&twod, ConFont, OptionSettings.mFontColorSelection, - (150 - 160) * CleanXfac + screen->GetWidth() / 2, - (y + (fontheight + 1) * messageSelection - 100 + fontheight/2 - 5) * CleanYfac + screen->GetHeight() / 2, - "\xd", - DTA_CellX, 8 * CleanXfac, - DTA_CellY, 8 * CleanYfac, - TAG_DONE); + DrawText(&twod, SmallFont, CR_UNTRANSLATED, 160 - mMessage[i].Width / 2, y, mMessage[i].Text, + DTA_Clean, true, TAG_DONE); + y += fontheight; } } + + if (mMessageMode == 0) + { + y += fontheight; + mMouseY = y; + DrawText(&twod, NewSmallFont, + messageSelection == 0 ? OptionSettings.mFontColorSelection : OptionSettings.mFontColor, + 160, y, GStrings["TXT_YES"], DTA_Clean, true, TAG_DONE); + DrawText(&twod, NewSmallFont, + messageSelection == 1 ? OptionSettings.mFontColorSelection : OptionSettings.mFontColor, + 160, y + fontheight + 1, GStrings["TXT_NO"], DTA_Clean, true, TAG_DONE); + + if (messageSelection >= 0) + { + if (((DMenu::MenuTime >> 2) % 8) < 6) + { + DrawText(&twod, NewSmallFont, OptionSettings.mFontColorSelection, + (150 - 160) * CleanXfac + screen->GetWidth() / 2, + (y + (fontheight + 1) * messageSelection - 100 + fontheight / 2 - 5) * CleanYfac + screen->GetHeight() / 2, + "\xd", + DTA_CellX, 8 * CleanXfac, + DTA_CellY, 8 * CleanYfac, + TAG_DONE); + } + } + } + } + else + { + twod.AddColorOnlyQuad(0, 0, xdim, ydim, 0xa0000000); + gi->DrawCenteredTextScreen(origin, mFullMessage, 100, false); } } @@ -269,7 +280,7 @@ bool DMessageBoxMenu::MenuEvent(int mkey, bool fromcontroller) { if (mMessageMode == 0) { - if (mkey == MKEY_Up || mkey == MKEY_Down) + if ((mkey == MKEY_Up || mkey == MKEY_Down) && m_generic_messagebox) { //S_Sound (CHAN_VOICE | CHAN_UI, "menu/cursor", snd_menuvolume, ATTN_NONE); messageSelection = !messageSelection; @@ -304,7 +315,7 @@ bool DMessageBoxMenu::MenuEvent(int mkey, bool fromcontroller) bool DMessageBoxMenu::MouseEvent(int type, int x, int y) { - if (mMessageMode == 1) + if (mMessageMode == 1 || m_generic_messagebox) { if (type == MOUSE_Click) { @@ -327,7 +338,7 @@ bool DMessageBoxMenu::MouseEvent(int type, int x, int y) } if (sel != -1 && sel != messageSelection) { - //S_Sound (CHAN_VOICE | CHAN_UI, "menu/cursor", snd_menuvolume, ATTN_NONE); + gi->MenuSound(CursorSound); } messageSelection = sel; if (type == MOUSE_Release) @@ -379,36 +390,38 @@ DMenu* CreateMessageBoxMenu(DMenu* parent, const char* message, int messagemode, } -#if 0 void ActivateEndGameMenu() { - FString tempstring = GStrings(netgame ? "NETEND" : "ENDGAME"); - DMenu *newmenu = CreateMessageBoxMenu(CurrentMenu, tempstring, 0, false, NAME_None, []() - { - M_ClearMenus(); - if (!netgame) - { - if (demorecording) - G_CheckDemoStatus(); - D_StartTitle(); - } - }); - - M_ActivateMenu(newmenu); } CCMD (menu_endgame) { // F7 - if (!usergame) + if (!gi->CanSave()) { - S_Sound (CHAN_VOICE | CHAN_UI, "menu/invalid", snd_menuvolume, ATTN_NONE); return; } - //M_StartControlPanel (true); - S_Sound (CHAN_VOICE | CHAN_UI, "menu/activate", snd_menuvolume, ATTN_NONE); + M_StartControlPanel (true); + FString tempstring = GStrings("ENDGAME"); + DMenu* newmenu = CreateMessageBoxMenu(DMenu::CurrentMenu, tempstring, 0, 501, false, NAME_None, [](bool res) + { + if (res) + { + M_ClearMenus(); + /*/ + if (!netgame) + { + if (demorecording) + G_CheckDemoStatus(); + D_StartTitle(); + } + */ - ActivateEndGameMenu(); + //gi->ReturnToTitle(); + } + }); + + M_ActivateMenu(newmenu); } //============================================================================= @@ -419,47 +432,18 @@ CCMD (menu_endgame) CCMD (menu_quit) { // F10 - if (m_quickexit) - { - ST_Endoom(); - } M_StartControlPanel (true); - const size_t messageindex = static_cast(gametic) % gameinfo.quitmessages.Size(); - FString EndString; - const char *msg = gameinfo.quitmessages[messageindex]; - if (msg[0] == '$') - { - if (msg[1] == '*') - { - EndString = GStrings(msg + 2); - } - else - { - EndString.Format("%s\n\n%s", GStrings(msg + 1), GStrings("DOSY")); - } - } - else EndString = gameinfo.quitmessages[messageindex]; + FString EndString = GStrings("CONFIRM_QUITMSG"); + EndString << "\n[Y/N]"; - DMenu *newmenu = CreateMessageBoxMenu(CurrentMenu, EndString, 0, false, NAME_None, []() + DMenu *newmenu = CreateMessageBoxMenu(DMenu::CurrentMenu, EndString, 0, 500, false, NAME_None, [](bool res) { - if (!netgame) - { - if (gameinfo.quitSound.IsNotEmpty()) - { - S_Sound(CHAN_VOICE | CHAN_UI, gameinfo.quitSound, snd_menuvolume, ATTN_NONE); - I_WaitVBL(105); - } - } - ST_Endoom(); + if (res) throw ExitEvent(0); }); - M_ActivateMenu(newmenu); } - - -#endif diff --git a/source/duke3d/src/d_menu.cpp b/source/duke3d/src/d_menu.cpp index 9dff0969f..0167ae340 100644 --- a/source/duke3d/src/d_menu.cpp +++ b/source/duke3d/src/d_menu.cpp @@ -751,9 +751,9 @@ bool GameInterface::DrawSpecialScreen(const DVector2 &origin, int tilenum) } -void GameInterface::DrawCenteredTextScreen(const DVector2 &origin, const char *text, int position) +void GameInterface::DrawCenteredTextScreen(const DVector2 &origin, const char *text, int position, bool bg) { - Menu_DrawBackground(origin); + if (bg) Menu_DrawBackground(origin); mgametextcenter(int(origin.X * 65536), int((origin.Y + position) * 65536), text); } diff --git a/source/duke3d/src/duke3d.h b/source/duke3d/src/duke3d.h index 231aa76f2..baa49d0a6 100644 --- a/source/duke3d/src/duke3d.h +++ b/source/duke3d/src/duke3d.h @@ -164,7 +164,7 @@ struct GameInterface : ::GameInterface void StartGame(FGameStartup& gs) override; FSavegameInfo GetSaveSig() override; bool DrawSpecialScreen(const DVector2 &origin, int tilenum) override; - void DrawCenteredTextScreen(const DVector2 &origin, const char *text, int position) override; + void DrawCenteredTextScreen(const DVector2 &origin, const char *text, int position, bool bg) override; void DrawMenuCaption(const DVector2& origin, const char* text) override; bool SaveGame(FSaveGameNode*) override; bool LoadGame(FSaveGameNode*) override; diff --git a/source/rr/src/d_menu.cpp b/source/rr/src/d_menu.cpp index ec69acf1b..2bf67e573 100644 --- a/source/rr/src/d_menu.cpp +++ b/source/rr/src/d_menu.cpp @@ -466,9 +466,9 @@ void GameInterface::DrawMenuCaption(const DVector2& origin, const char* text) Menu_DrawTopBarCaption(text, origin); } -void GameInterface::DrawCenteredTextScreen(const DVector2 &origin, const char *text, int position) +void GameInterface::DrawCenteredTextScreen(const DVector2 &origin, const char *text, int position, bool bg) { - Menu_DrawBackground(origin); + if (bg) Menu_DrawBackground(origin); G_ScreenText(MF_Bluefont.tilenum, int((origin.X + 160) * 65536), int((origin.Y + position) * 65536), MF_Bluefont.zoom, 0, 0, text, 0, MF_Bluefont.pal, 2 | 8 | 16 | ROTATESPRITE_FULL16, 0, MF_Bluefont.emptychar.x, MF_Bluefont.emptychar.y, MF_Bluefont.between.x, MF_Bluefont.between.y, MF_Bluefont.textflags | TEXT_XCENTER, 0, 0, xdim - 1, ydim - 1); diff --git a/source/rr/src/duke3d.h b/source/rr/src/duke3d.h index 523cf612c..4430c56db 100644 --- a/source/rr/src/duke3d.h +++ b/source/rr/src/duke3d.h @@ -164,7 +164,7 @@ struct GameInterface : ::GameInterface bool CanSave() override; void StartGame(FGameStartup& gs) override; FSavegameInfo GetSaveSig() override; - void DrawCenteredTextScreen(const DVector2& origin, const char* text, int position) override; + void DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool bg) override; void DrawMenuCaption(const DVector2& origin, const char* text) override; bool SaveGame(FSaveGameNode*) override; bool LoadGame(FSaveGameNode*) override; diff --git a/source/sw/src/d_menu.cpp b/source/sw/src/d_menu.cpp index abd344ce1..f7f4548b1 100644 --- a/source/sw/src/d_menu.cpp +++ b/source/sw/src/d_menu.cpp @@ -254,8 +254,24 @@ void GameInterface::DrawMenuCaption(const DVector2& origin, const char* text) MNU_DrawString(TEXT_XCENTER(w), 5, text, 1, 16); } -void GameInterface::DrawCenteredTextScreen(const DVector2 &origin, const char *text, int position) +void GameInterface::DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool bg) { + if (text) + { + short width, height = 0; + MNU_MeasureString("T", &width, &height); + + auto lines = FString(text).Split("\n"); + int y = 100 - (height * lines.Size() / 2); + for (auto& l : lines) + { + short lheight = 0; + MNU_MeasureString(text, &width, &lheight); + int x = 160 - width / 2; + MNU_DrawString(x, y, l, 0, 0); + y += height; + } + } } diff --git a/source/sw/src/game.h b/source/sw/src/game.h index 50005d389..a7c6de29a 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -2384,7 +2384,7 @@ struct GameInterface : ::GameInterface void StartGame(FGameStartup& gs) override; FSavegameInfo GetSaveSig() override; void DrawMenuCaption(const DVector2& origin, const char* text) override; - void DrawCenteredTextScreen(const DVector2& origin, const char* text, int position) override; + void DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool bg) override; bool LoadGame(FSaveGameNode* sv) override; bool SaveGame(FSaveGameNode* sv) override; void DoPrintMessage(int prio, const char* text) override;