From b6862cfd700e7f9330bc98435672753f279128e3 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 5 Jan 2020 12:12:14 +0100 Subject: [PATCH] - fixed text input menu and y-positioning of option menus. --- source/common/menu/menu.h | 2 ++ source/common/menu/optionmenu.cpp | 9 +++++++-- source/common/menu/optionmenuitems.h | 23 +++++++++++++---------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/source/common/menu/menu.h b/source/common/menu/menu.h index 574eb7f02..3349c600d 100644 --- a/source/common/menu/menu.h +++ b/source/common/menu/menu.h @@ -647,6 +647,8 @@ class DOptionMenu : public DMenu protected: FOptionMenuDescriptor *mDesc; + int GetPosition(); + public: FOptionMenuItem *GetItem(FName name); DOptionMenu(DMenu *parent = NULL, FOptionMenuDescriptor *desc = NULL); diff --git a/source/common/menu/optionmenu.cpp b/source/common/menu/optionmenu.cpp index 28a9e99d5..869d0106b 100644 --- a/source/common/menu/optionmenu.cpp +++ b/source/common/menu/optionmenu.cpp @@ -74,6 +74,11 @@ void DrawOptionText(int x, int y, int color, const char *text, bool grayed) DrawText (twod, OptionFont(), color, x, y, text, DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay, TAG_END); } +int DOptionMenu::GetPosition() +{ + return mDesc->mPosition * screen->GetHeight() / 1080; // y position uses a 1920x1080 screen as reference but has to adjust to scaled 320x200 content. +} + //============================================================================= // // @@ -210,7 +215,7 @@ bool DOptionMenu::MenuEvent (int mkey, bool fromcontroller) if (mDesc->mSelectedItem < 0) { // Figure out how many lines of text fit on the menu - int y = mDesc->mPosition; + int y = GetPosition(); y *= CleanYfac_1; int rowheight = OptionSettings.mLinespacing * CleanYfac_1; @@ -394,7 +399,7 @@ int DOptionMenu::GetIndent() void DOptionMenu::Drawer () { - int y = mDesc->mPosition; + int y = GetPosition(); if (mDesc->mTitle.IsNotEmpty()) { diff --git a/source/common/menu/optionmenuitems.h b/source/common/menu/optionmenuitems.h index c92f86baa..b4cb5c4e2 100644 --- a/source/common/menu/optionmenuitems.h +++ b/source/common/menu/optionmenuitems.h @@ -876,12 +876,14 @@ public: FString Represent() override { - FString text = mEntering ? mEditName : FString(GetCVarString()); - - if ( mEntering ) + if (mEntering) + { + FString text; + text = mInput->GetText(); text += '_'; - - return text; + return text; + } + else return FString(GetCVarString()); } int Draw(FOptionMenuDescriptor*desc, int y, int indent, bool selected) override @@ -902,10 +904,9 @@ public: if ( mkey == MKEY_Enter ) { M_MenuSound(AdvanceSound); - mEditName = GetCVarString(); mEntering = true; - DMenu* input = new DTextEnterMenu(DMenu::CurrentMenu, NewSmallFont, mEditName, 256, fromcontroller ); - M_ActivateMenu( input ); + mInput = new DTextEnterMenu(DMenu::CurrentMenu, NewSmallFont, GetCVarString(), 256, fromcontroller ); + M_ActivateMenu( mInput ); return true; } else if ( mkey == MKEY_Input ) @@ -913,16 +914,18 @@ public: if ( mCVar ) { UCVarValue vval; - vval.String = mEditName; + vval.String = mInput->GetText(); mCVar->SetGenericRep( vval, CVAR_String ); } mEntering = false; + mInput = nullptr; return true; } else if ( mkey == MKEY_Abort ) { mEntering = false; + mInput = nullptr; return true; } @@ -931,7 +934,7 @@ public: private: bool mEntering; - FString mEditName; + DTextEnterMenu* mInput; }; //=============================================================================