From 62138decfee14cf3d0615fe69b078745f38e3e5f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 7 Oct 2020 18:29:34 +0200 Subject: [PATCH] - use Raze's layout for load and save game menus. This has a lot less black void on screen. --- src/common/2d/v_draw.cpp | 13 +++++ wadsrc/static/menudef.txt | 8 +-- wadsrc/static/zscript/base.zs | 4 +- wadsrc/static/zscript/ui/menu/listmenu.zs | 9 ++- .../static/zscript/ui/menu/listmenuitems.zs | 30 +++++++++- wadsrc/static/zscript/ui/menu/loadsavemenu.zs | 55 ++++++++++--------- wadsrc/static/zscript/ui/menu/menu.zs | 10 +++- .../static/zscript/ui/menu/menucustomize.zs | 17 +++++- wadsrc/static/zscript/ui/menu/optionmenu.zs | 3 +- 9 files changed, 109 insertions(+), 40 deletions(-) diff --git a/src/common/2d/v_draw.cpp b/src/common/2d/v_draw.cpp index c7dcd83d4..c6ca5188b 100644 --- a/src/common/2d/v_draw.cpp +++ b/src/common/2d/v_draw.cpp @@ -1529,6 +1529,19 @@ void DrawFrame(F2DDrawer* twod, PalEntry color, int left, int top, int width, in twod->AddColorOnlyQuad(right, top - offset, offset, height + 2 * offset, color); } +DEFINE_ACTION_FUNCTION(_Screen, DrawLineFrame) +{ + PARAM_PROLOGUE; + PARAM_COLOR(color); + PARAM_INT(left); + PARAM_INT(top); + PARAM_INT(width); + PARAM_INT(height); + PARAM_INT(thickness); + DrawFrame(twod, color, left, top, width, height, thickness); + return 0; +} + void V_CalcCleanFacs(int designwidth, int designheight, int realwidth, int realheight, int* cleanx, int* cleany, int* _cx1, int* _cx2) { if (designheight < 240 && realheight >= 480) designheight = 240; diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index f94f7a261..8210d28d9 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -285,8 +285,8 @@ ListMenu "LoadGameMenu" { NetgameMessage "$CLOADNET" } - StaticTextCentered 160, -10, "$MNU_LOADGAME" - Position 80,54 + CaptionItem "$MNU_LOADGAME" + Position 80,40 Class "LoadMenu" // uses its own implementation Size Clean } @@ -299,8 +299,8 @@ ListMenu "LoadGameMenu" ListMenu "SaveGameMenu" { - StaticTextCentered 160, -10, "$MNU_SAVEGAME" - Position 80,54 + CaptionItem "$MNU_SAVEGAME" + Position 80,40 Class "SaveMenu" // uses its own implementation Size Clean } diff --git a/wadsrc/static/zscript/base.zs b/wadsrc/static/zscript/base.zs index b595c2242..17f9e680f 100644 --- a/wadsrc/static/zscript/base.zs +++ b/wadsrc/static/zscript/base.zs @@ -230,7 +230,7 @@ struct TexMan NOT_FLAT = 24 }; - native static TextureID CheckForTexture(String name, int usetype, int flags = TryAny); + native static TextureID CheckForTexture(String name, int usetype = Type_Any, int flags = TryAny); native static String GetName(TextureID tex); native static int, int GetSize(TextureID tex); native static Vector2 GetScaledSize(TextureID tex); @@ -389,6 +389,7 @@ struct Screen native native static vararg void DrawChar(Font font, int normalcolor, double x, double y, int character, ...); native static vararg void DrawText(Font font, int normalcolor, double x, double y, String text, ...); native static void DrawLine(int x0, int y0, int x1, int y1, Color color, int alpha = 255); + native static void DrawLineFrame(Color color, int x0, int y0, int w, int h, int thickness = 1); native static void DrawThickLine(int x0, int y0, int x1, int y1, double thickness, Color color, int alpha = 255); native static Vector2, Vector2 VirtualToRealCoords(Vector2 pos, Vector2 size, Vector2 vsize, bool vbottom=false, bool handleaspect=true); native static double GetAspectRatio(); @@ -482,6 +483,7 @@ struct Font native native static Font FindFont(Name fontname); native static Font GetFont(Name fontname); native BrokenLines BreakLines(String text, int maxlen); + native int GetGlyphHeight(int code); } struct Console native diff --git a/wadsrc/static/zscript/ui/menu/listmenu.zs b/wadsrc/static/zscript/ui/menu/listmenu.zs index 24f10c49e..917fe270c 100644 --- a/wadsrc/static/zscript/ui/menu/listmenu.zs +++ b/wadsrc/static/zscript/ui/menu/listmenu.zs @@ -172,7 +172,7 @@ class ListMenu : Menu case MKEY_Enter: if (mDesc.mSelectedItem >= 0 && mDesc.mItems[mDesc.mSelectedItem].Activate()) { - MenuSound("menu/choose"); + MenuSound("menu/advance"); } return true; @@ -265,10 +265,13 @@ class ListMenu : Menu { for(int i=0;i 0) mDesc.mItems[i].Draw(mDesc.mSelectedItem == i, mDesc); + if (mDesc.mItems[i].mEnabled) mDesc.mItems[i].Draw(mDesc.mSelectedItem == i, mDesc); } if (mDesc.mSelectedItem >= 0 && mDesc.mSelectedItem < mDesc.mItems.Size()) - mDesc.mItems[mDesc.mSelectedItem].DrawSelector(mDesc.mSelectOfsX, mDesc.mSelectOfsY, mDesc.mSelector, mDesc); + { + if (!menuDelegate.DrawSelector(mDesc)) + mDesc.mItems[mDesc.mSelectedItem].DrawSelector(mDesc.mSelectOfsX, mDesc.mSelectOfsY, mDesc.mSelector, mDesc); + } Super.Drawer(); } diff --git a/wadsrc/static/zscript/ui/menu/listmenuitems.zs b/wadsrc/static/zscript/ui/menu/listmenuitems.zs index 368bcc3b8..13d96281c 100644 --- a/wadsrc/static/zscript/ui/menu/listmenuitems.zs +++ b/wadsrc/static/zscript/ui/menu/listmenuitems.zs @@ -219,7 +219,7 @@ class ListMenuItemSelectable : ListMenuItem override bool CheckCoordinate(int x, int y) { - return mEnabled && y >= mYpos && y < mYpos + mHeight; // no x check here + return mEnabled > 0 && y >= mYpos && y < mYpos + mHeight; // no x check here } override bool Selectable() @@ -340,3 +340,31 @@ class ListMenuItemPatchItem : ListMenuItemSelectable } +//============================================================================= +// +// caption - draws a text using the customizer's caption hook +// +//============================================================================= + +class ListMenuItemCaptionItem : ListMenuItem +{ + String mText; + Font mFont; + + void Init(ListMenuDescriptor desc, String text, String fnt = "BigFont") + { + Super.Init(0, 0); + mText = text; + mFont = Font.FindFont(fnt); + } + + override void Draw(bool selected, ListMenuDescriptor desc) + { + let font = generic_ui || !desc.mFont ? NewSmallFont : desc.mFont; + if (font && mText.Length() > 0) + { + menuDelegate.DrawCaption(mText, font, 0, true); + } + } +} + diff --git a/wadsrc/static/zscript/ui/menu/loadsavemenu.zs b/wadsrc/static/zscript/ui/menu/loadsavemenu.zs index eb9b71436..837970a9c 100644 --- a/wadsrc/static/zscript/ui/menu/loadsavemenu.zs +++ b/wadsrc/static/zscript/ui/menu/loadsavemenu.zs @@ -91,14 +91,11 @@ class LoadSaveMenu : ListMenu int listboxRows; int listboxHeight; int listboxRight; - int listboxBottom; int commentLeft; int commentTop; int commentWidth; int commentHeight; - int commentRight; - int commentBottom; int commentRows; bool mEntering; @@ -118,33 +115,34 @@ class LoadSaveMenu : ListMenu override void Init(Menu parent, ListMenuDescriptor desc) { Super.Init(parent, desc); + bool aspect43 = true; + int Width43 = screen.GetHeight() * 4 / 3; + int Left43 = (screen.GetWidth() - Width43) / 2; + manager = SavegameManager.GetManager(); manager.ReadSaveStrings(); + double wScale = Width43 / 640.; - savepicLeft = 10; - savepicTop = 54*CleanYfac; - savepicWidth = 216*screen.GetWidth() / 640; - savepicHeight = 135*screen.GetHeight() / 400; + savepicLeft = Left43 + int(20 * wScale); + savepicTop = mDesc.mYpos * screen.GetHeight() / 200 ; + savepicWidth = int(240 * wScale); + savepicHeight = int(180 * wScale); FontScale = max(screen.GetHeight() / 480, 1); rowHeight = int(max((NewConsoleFont.GetHeight() + 1) * FontScale, 1)); - listboxLeft = savepicLeft + savepicWidth + 14; + listboxLeft = savepicLeft + savepicWidth + int(20*wScale); listboxTop = savepicTop; - listboxWidth = screen.GetWidth() - listboxLeft - 10; - int listboxHeight1 = screen.GetHeight() - listboxTop - 10; + listboxWidth = Width43 + Left43 - listboxLeft - int(30 * wScale); + int listboxHeight1 = screen.GetHeight() - listboxTop - int(20*wScale); listboxRows = (listboxHeight1 - 1) / rowHeight; listboxHeight = listboxRows * rowHeight + 1; listboxRight = listboxLeft + listboxWidth; - listboxBottom = listboxTop + listboxHeight; commentLeft = savepicLeft; - commentTop = savepicTop + savepicHeight + 16; + commentTop = savepicTop + savepicHeight + int(16 * wScale); commentWidth = savepicWidth; - //commentHeight = (51+(screen.GetHeight()>200?10:0))*CleanYfac; - commentHeight = listboxHeight - savepicHeight - 16; - commentRight = commentLeft + commentWidth; - commentBottom = commentTop + commentHeight; + commentHeight = listboxHeight - savepicHeight - int(16 * wScale); commentRows = commentHeight / rowHeight; } @@ -167,6 +165,12 @@ class LoadSaveMenu : ListMenu // //============================================================================= + virtual void DrawFrame(int left, int top, int width, int height) + { + let framecolor = Color(255, 80, 80, 80); + Screen.DrawLineFrame(framecolor, left, top, width, height, screen.GetHeight() / 240); + } + override void Drawer () { Super.Drawer(); @@ -182,24 +186,25 @@ class LoadSaveMenu : ListMenu return; } - Screen.DrawFrame (savepicLeft, savepicTop, savepicWidth, savepicHeight); + DrawFrame(savepicLeft, savepicTop, savepicWidth, savepicHeight); if (!manager.DrawSavePic(savepicLeft, savepicTop, savepicWidth, savepicHeight)) { - screen.Clear (savepicLeft, savepicTop, savepicLeft+savepicWidth, savepicTop+savepicHeight, 0, 0); + screen.Dim(0, 0.6, savepicLeft, savepicTop, savepicWidth, savepicHeight); if (manager.SavegameCount() > 0) { + if (Selected >= manager.SavegameCount()) Selected = 0; String text = (Selected == -1 || !manager.GetSavegame(Selected).bOldVersion)? Stringtable.Localize("$MNU_NOPICTURE") : Stringtable.Localize("$MNU_DIFFVERSION"); - int textlen = NewSmallFont.StringWidth(text) * CleanXfac; + int textlen = NewSmallFont.StringWidth(text); - screen.DrawText (NewSmallFont, Font.CR_GOLD, savepicLeft+(savepicWidth-textlen)/2, - savepicTop+(savepicHeight-rowHeight)/2, text, DTA_CleanNoMove, true); + screen.DrawText (NewSmallFont, Font.CR_GOLD, (savepicLeft+(savepicWidth-textlen)/2) / FontScale, + (savepicTop+(savepicHeight-rowHeight)/2) / FontScale, text, DTA_VirtualWidthF, screen.GetWidth() / FontScale, DTA_VirtualHeightF, screen.GetHeight() / FontScale); } } // Draw comment area - Screen.DrawFrame (commentLeft, commentTop, commentWidth, commentHeight); - screen.Clear (commentLeft, commentTop, commentRight, commentBottom, 0, 0); + DrawFrame (commentLeft, commentTop, commentWidth, commentHeight); + screen.Dim(0, 0.6, commentLeft, commentTop, commentWidth, commentHeight); int numlinestoprint = min(commentRows, BrokenSaveComment? BrokenSaveComment.Count() : 0); for(int i = 0; i < numlinestoprint; i++) @@ -210,8 +215,8 @@ class LoadSaveMenu : ListMenu // Draw file area - Screen.DrawFrame (listboxLeft, listboxTop, listboxWidth, listboxHeight); - screen.Clear (listboxLeft, listboxTop, listboxRight, listboxBottom, 0, 0); + DrawFrame (listboxLeft, listboxTop, listboxWidth, listboxHeight); + screen.Dim(0, 0.6, listboxLeft, listboxTop, listboxWidth, listboxHeight); if (manager.SavegameCount() == 0) { diff --git a/wadsrc/static/zscript/ui/menu/menu.zs b/wadsrc/static/zscript/ui/menu/menu.zs index a11e301e8..10b7adb58 100644 --- a/wadsrc/static/zscript/ui/menu/menu.zs +++ b/wadsrc/static/zscript/ui/menu/menu.zs @@ -129,10 +129,14 @@ class Menu : Object native ui version("2.4") switch (mkey) { case MKEY_Back: + { Close(); - MenuSound (GetCurrentMenu() != null? "menu/backup" : "menu/clear"); + let m = GetCurrentMenu(); + MenuSound(m != null ? "menu/backup" : "menu/clear"); + if (!m) menuDelegate.MenuDismissed(); return true; } + } return false; } @@ -283,9 +287,9 @@ class Menu : Object native ui version("2.4") // //============================================================================= - static void MenuSound(Sound snd) + static void MenuSound(Name snd) { - S_StartSound (snd, CHAN_VOICE, CHANF_MAYBE_LOCAL|CHAN_UI, snd_menuvolume, ATTN_NONE); + menuDelegate.PlaySound(snd); } deprecated("4.0") static void DrawConText (int color, int x, int y, String str) diff --git a/wadsrc/static/zscript/ui/menu/menucustomize.zs b/wadsrc/static/zscript/ui/menu/menucustomize.zs index da946f6d4..35d330d6a 100644 --- a/wadsrc/static/zscript/ui/menu/menucustomize.zs +++ b/wadsrc/static/zscript/ui/menu/menucustomize.zs @@ -5,6 +5,21 @@ class MenuDelegateBase virtual int DrawCaption(String title, Font fnt, int y, bool drawit) { screen.DrawText(fnt, OptionMenuSettings.mTitleColor, (screen.GetWidth() - fnt.StringWidth(title) * CleanXfac_1) / 2, 10 * CleanYfac_1, title, DTA_CleanNoMove_1, true); - return y + fnt.GetHeight(); + return (y + fnt.GetHeight()) * CleanYfac_1; // return is spacing in screen pixels. } + + virtual void PlaySound(Name sound) + { + } + + virtual bool DrawSelector(ListMenuDescriptor desc) + { + return false; + } + + virtual void MenuDismissed() + { + // overriding this allows to execute special actions when the menu closes + } + } diff --git a/wadsrc/static/zscript/ui/menu/optionmenu.zs b/wadsrc/static/zscript/ui/menu/optionmenu.zs index 2ae7564c7..6392adf3f 100644 --- a/wadsrc/static/zscript/ui/menu/optionmenu.zs +++ b/wadsrc/static/zscript/ui/menu/optionmenu.zs @@ -456,9 +456,8 @@ class OptionMenu : Menu { y = DrawCaption(mDesc.mTitle, -y, true); } - mDesc.mDrawTop = y; + mDesc.mDrawTop = y / CleanYfac_1; // mouse checks are done in clean space. int fontheight = OptionMenuSettings.mLinespacing * CleanYfac_1; - y *= CleanYfac_1; int indent = GetIndent();