- fixed issues with text entering

* entering a savegame description did not work anymore
* the length check was too restrictive and always underestimated the available space
* use the console font for entering a savegame description. This has more characters and better contrast for this content.
* the interface to the text enterer used bad measurements.
This commit is contained in:
Christoph Oelckers 2019-02-19 00:08:23 +01:00
parent c5a6c72719
commit b29975503d
5 changed files with 54 additions and 29 deletions

View file

@ -119,7 +119,7 @@ class LoadSaveMenu : ListMenu
savepicHeight = 135*screen.GetHeight()/400; savepicHeight = 135*screen.GetHeight()/400;
manager.WindowSize = savepicWidth / CleanXfac; manager.WindowSize = savepicWidth / CleanXfac;
rowHeight = (SmallFont.GetHeight() + 1) * CleanYfac; rowHeight = (ConFont.GetHeight() + 1) * CleanYfac;
listboxLeft = savepicLeft + savepicWidth + 14; listboxLeft = savepicLeft + savepicWidth + 14;
listboxTop = savepicTop; listboxTop = savepicTop;
listboxWidth = screen.GetWidth() - listboxLeft - 10; listboxWidth = screen.GetWidth() - listboxLeft - 10;
@ -227,24 +227,29 @@ class LoadSaveMenu : ListMenu
colr = Font.CR_TAN; colr = Font.CR_TAN;
} }
screen.SetClipRect(listboxLeft, listboxTop+rowHeight*i, listboxRight, listboxTop+rowHeight*(i+1));
if (j == Selected) if (j == Selected)
{ {
screen.Clear (listboxLeft, listboxTop+rowHeight*i, listboxRight, listboxTop+rowHeight*(i+1), mEntering ? Color(255,255,0,0) : Color(255,0,0,255)); screen.Clear (listboxLeft, listboxTop+rowHeight*i, listboxRight, listboxTop+rowHeight*(i+1), mEntering ? Color(255,255,0,0) : Color(255,0,0,255));
didSeeSelected = true; didSeeSelected = true;
if (!mEntering) if (!mEntering)
{ {
screen.DrawText (SmallFont, colr, listboxLeft+1, listboxTop+rowHeight*i+CleanYfac, node.SaveTitle, DTA_CleanNoMove, true); screen.DrawText (ConFont, colr, listboxLeft+1, listboxTop+rowHeight*i+CleanYfac, node.SaveTitle, DTA_CleanNoMove, true);
} }
else else
{ {
String s = mInput.GetText() .. SmallFont.GetCursor(); String s = mInput.GetText() .. ConFont.GetCursor();
screen.DrawText (SmallFont, Font.CR_WHITE, listboxLeft+1, listboxTop+rowHeight*i+CleanYfac, s, DTA_CleanNoMove, true); int length = ConFont.StringWidth(s) * CleanXFac;
int displacement = min(0, listboxWidth - 2 - length);
screen.DrawText (ConFont, Font.CR_WHITE, listboxLeft + 1 + displacement, listboxTop+rowHeight*i+CleanYfac, s, DTA_CleanNoMove, true);
} }
} }
else else
{ {
screen.DrawText (SmallFont, colr, listboxLeft+1, listboxTop+rowHeight*i+CleanYfac, node.SaveTitle, DTA_CleanNoMove, true); screen.DrawText (ConFont, colr, listboxLeft+1, listboxTop+rowHeight*i+CleanYfac, node.SaveTitle, DTA_CleanNoMove, true);
} }
screen.ClearClipRect();
j++; j++;
} }
} }
@ -475,7 +480,7 @@ class SaveMenu : LoadSaveMenu
if (mkey == MKEY_Enter) if (mkey == MKEY_Enter)
{ {
String SavegameString = (Selected != 0)? manager.GetSavegame(Selected).SaveTitle : ""; String SavegameString = (Selected != 0)? manager.GetSavegame(Selected).SaveTitle : "";
mInput = TextEnterMenu.Open(self, SavegameString, -1, 1, fromcontroller); mInput = TextEnterMenu.OpenTextEnter(self, ConFont, SavegameString, -1, fromcontroller);
mInput.ActivateMenu(); mInput.ActivateMenu();
mEntering = true; mEntering = true;
} }

View file

@ -1044,7 +1044,7 @@ class OptionMenuItemTextField : OptionMenuFieldBase
if (mkey == Menu.MKEY_Enter) if (mkey == Menu.MKEY_Enter)
{ {
Menu.MenuSound("menu/choose"); Menu.MenuSound("menu/choose");
mEnter = TextEnterMenu.Open(Menu.GetCurrentMenu(), GetCVarString(), -1, 2, fromcontroller); mEnter = TextEnterMenu.OpenTextEnter(Menu.GetCurrentMenu(), SmallFont, GetCVarString(), -1, fromcontroller);
mEnter.ActivateMenu(); mEnter.ActivateMenu();
return true; return true;
} }

View file

@ -187,7 +187,7 @@ class ListMenuItemPlayerNameBox : ListMenuItemSelectable
if (mkey == Menu.MKEY_Enter) if (mkey == Menu.MKEY_Enter)
{ {
Menu.MenuSound ("menu/choose"); Menu.MenuSound ("menu/choose");
mEnter = TextEnterMenu.Open(Menu.GetCurrentMenu(), mPlayerName, -1, 2, fromcontroller); mEnter = TextEnterMenu.OpenTextEnter(Menu.GetCurrentMenu(), SmallFont, mPlayerName, 128, fromcontroller);
mEnter.ActivateMenu(); mEnter.ActivateMenu();
return true; return true;
} }

View file

@ -235,7 +235,7 @@ class OptionMenuItemSliderReverbEditOption : OptionMenuSliderBase
if (mkey == Menu.MKEY_Enter) if (mkey == Menu.MKEY_Enter)
{ {
Menu.MenuSound("menu/choose"); Menu.MenuSound("menu/choose");
mEnter = TextEnterMenu.Open(Menu.GetCurrentMenu(), String.Format("%.3f", GetSliderValue()), -1, 2, fromcontroller); mEnter = TextEnterMenu.OpenTextEnter(Menu.GetCurrentMenu(), SmallFont, String.Format("%.3f", GetSliderValue()), -1, fromcontroller);
mEnter.ActivateMenu(); mEnter.ActivateMenu();
return true; return true;
} }

View file

@ -44,10 +44,10 @@ class TextEnterMenu : Menu
String mEnterString; String mEnterString;
int mEnterSize; int mEnterSize;
int mEnterPos; int mEnterPos;
int mSizeMode; // 1: size is length in chars. 2: also check string width
bool mInputGridOkay; bool mInputGridOkay;
int InputGridX; int InputGridX;
int InputGridY; int InputGridY;
int CursorSize;
bool AllowColors; bool AllowColors;
Font displayFont; Font displayFont;
@ -58,12 +58,11 @@ class TextEnterMenu : Menu
//============================================================================= //=============================================================================
// [TP] Added allowcolors // [TP] Added allowcolors
private void Init(Menu parent, String textbuffer, int maxlen, int sizemode, bool showgrid, bool allowcolors) private void Init(Menu parent, Font dpf, String textbuffer, int maxlen, bool showgrid, bool allowcolors)
{ {
Super.init(parent); Super.init(parent);
mEnterString = textbuffer; mEnterString = textbuffer;
mEnterSize = maxlen < 0 ? 0x7fffffff : maxlen; mEnterSize = maxlen;
mSizeMode = sizemode;
mInputGridOkay = (showgrid && (m_showinputgrid == 0)) || (m_showinputgrid >= 1); mInputGridOkay = (showgrid && (m_showinputgrid == 0)) || (m_showinputgrid >= 1);
if (mEnterString.Length() > 0) if (mEnterString.Length() > 0)
{ {
@ -77,16 +76,26 @@ class TextEnterMenu : Menu
InputGridY = 0; InputGridY = 0;
} }
AllowColors = allowcolors; // [TP] AllowColors = allowcolors; // [TP]
displayFont = SmallFont; displayFont = dpf;
CursorSize = displayFont.StringWidth(displayFont.GetCursor());
} }
static TextEnterMenu Open(Menu parent, String textbuffer, int maxlen, int sizemode, bool showgrid = false, bool allowcolors = false) // This had to be deprecated because the unit for maxlen is 8 pixels.
deprecated("3.8") static TextEnterMenu Open(Menu parent, String textbuffer, int maxlen, int sizemode, bool showgrid = false, bool allowcolors = false)
{ {
let me = new("TextEnterMenu"); let me = new("TextEnterMenu");
me.Init(parent, textbuffer, maxlen, sizemode, showgrid, allowcolors); me.Init(parent, SmallFont, textbuffer, maxlen*8, showgrid, allowcolors);
return me; return me;
} }
static TextEnterMenu OpenTextEnter(Menu parent, Font displayfnt, String textbuffer, int maxlen, bool showgrid = false, bool allowcolors = false)
{
let me = new("TextEnterMenu");
me.Init(parent, displayfnt, textbuffer, maxlen, showgrid, allowcolors);
return me;
}
//============================================================================= //=============================================================================
// //
// //
@ -116,11 +125,7 @@ class TextEnterMenu : Menu
if (ev.Type == UIEvent.Type_Char) if (ev.Type == UIEvent.Type_Char)
{ {
mInputGridOkay = false; mInputGridOkay = false;
if (mEnterString.Length() < mEnterSize && AppendChar(ev.KeyChar);
(mSizeMode == 2/*entering player name*/ || displayFont.StringWidth(mEnterString) < (mEnterSize-1)*8))
{
mEnterString.AppendCharacter(ev.KeyChar);
}
return true; return true;
} }
int ch = ev.KeyChar; int ch = ev.KeyChar;
@ -202,6 +207,23 @@ class TextEnterMenu : Menu
// //
//============================================================================= //=============================================================================
private void AppendChar(int ch)
{
String newstring = mEnterString;
newstring.AppendCharacter(ch);
newstring = newstring .. displayFont.GetCursor();
if (mEnterSize < 0 || displayFont.StringWidth(newstring) < mEnterSize)
{
mEnterString.AppendCharacter(ch);
}
}
//=============================================================================
//
//
//
//=============================================================================
override bool MenuEvent (int key, bool fromcontroller) override bool MenuEvent (int key, bool fromcontroller)
{ {
String InputGridChars = Chars; String InputGridChars = Chars;
@ -251,8 +273,7 @@ class TextEnterMenu : Menu
case MKEY_Enter: case MKEY_Enter:
if (mInputGridOkay) if (mInputGridOkay)
{ {
String c = InputGridChars.CharAt(InputGridX + InputGridY * INPUTGRID_WIDTH); int ch = InputGridChars.CharCodeAt(InputGridX + InputGridY * INPUTGRID_WIDTH);
int ch = c.CharCodeAt(0);
if (ch == 0) // end if (ch == 0) // end
{ {
if (mEnterString.Length() > 0) if (mEnterString.Length() > 0)
@ -267,13 +288,12 @@ class TextEnterMenu : Menu
{ {
if (mEnterString.Length() > 0) if (mEnterString.Length() > 0)
{ {
mEnterString.Truncate(mEnterString.Length() - 1); mEnterString.DeleteLastCharacter();
} }
} }
else if (mEnterString.Length() < mEnterSize && else
(mSizeMode == 2/*entering player name*/ || displayFont.StringWidth(mEnterString) < (mEnterSize-1)*8))
{ {
mEnterString = mEnterString .. c; AppendChar(ch);
} }
} }
return true; return true;