- 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;
manager.WindowSize = savepicWidth / CleanXfac;
rowHeight = (SmallFont.GetHeight() + 1) * CleanYfac;
rowHeight = (ConFont.GetHeight() + 1) * CleanYfac;
listboxLeft = savepicLeft + savepicWidth + 14;
listboxTop = savepicTop;
listboxWidth = screen.GetWidth() - listboxLeft - 10;
@ -227,24 +227,29 @@ class LoadSaveMenu : ListMenu
colr = Font.CR_TAN;
}
screen.SetClipRect(listboxLeft, listboxTop+rowHeight*i, listboxRight, listboxTop+rowHeight*(i+1));
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));
didSeeSelected = true;
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
{
String s = mInput.GetText() .. SmallFont.GetCursor();
screen.DrawText (SmallFont, Font.CR_WHITE, listboxLeft+1, listboxTop+rowHeight*i+CleanYfac, s, DTA_CleanNoMove, true);
String s = mInput.GetText() .. ConFont.GetCursor();
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
{
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++;
}
}
@ -475,7 +480,7 @@ class SaveMenu : LoadSaveMenu
if (mkey == MKEY_Enter)
{
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();
mEntering = true;
}

View File

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

View File

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

View File

@ -235,7 +235,7 @@ class OptionMenuItemSliderReverbEditOption : OptionMenuSliderBase
if (mkey == Menu.MKEY_Enter)
{
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();
return true;
}

View File

@ -44,10 +44,10 @@ class TextEnterMenu : Menu
String mEnterString;
int mEnterSize;
int mEnterPos;
int mSizeMode; // 1: size is length in chars. 2: also check string width
bool mInputGridOkay;
int InputGridX;
int InputGridY;
int CursorSize;
bool AllowColors;
Font displayFont;
@ -58,12 +58,11 @@ class TextEnterMenu : Menu
//=============================================================================
// [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);
mEnterString = textbuffer;
mEnterSize = maxlen < 0 ? 0x7fffffff : maxlen;
mSizeMode = sizemode;
mEnterSize = maxlen;
mInputGridOkay = (showgrid && (m_showinputgrid == 0)) || (m_showinputgrid >= 1);
if (mEnterString.Length() > 0)
{
@ -77,16 +76,26 @@ class TextEnterMenu : Menu
InputGridY = 0;
}
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");
me.Init(parent, textbuffer, maxlen, sizemode, showgrid, allowcolors);
me.Init(parent, SmallFont, textbuffer, maxlen*8, showgrid, allowcolors);
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)
{
mInputGridOkay = false;
if (mEnterString.Length() < mEnterSize &&
(mSizeMode == 2/*entering player name*/ || displayFont.StringWidth(mEnterString) < (mEnterSize-1)*8))
{
mEnterString.AppendCharacter(ev.KeyChar);
}
AppendChar(ev.KeyChar);
return true;
}
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)
{
String InputGridChars = Chars;
@ -251,8 +273,7 @@ class TextEnterMenu : Menu
case MKEY_Enter:
if (mInputGridOkay)
{
String c = InputGridChars.CharAt(InputGridX + InputGridY * INPUTGRID_WIDTH);
int ch = c.CharCodeAt(0);
int ch = InputGridChars.CharCodeAt(InputGridX + InputGridY * INPUTGRID_WIDTH);
if (ch == 0) // end
{
if (mEnterString.Length() > 0)
@ -267,13 +288,12 @@ class TextEnterMenu : Menu
{
if (mEnterString.Length() > 0)
{
mEnterString.Truncate(mEnterString.Length() - 1);
mEnterString.DeleteLastCharacter();
}
}
else if (mEnterString.Length() < mEnterSize &&
(mSizeMode == 2/*entering player name*/ || displayFont.StringWidth(mEnterString) < (mEnterSize-1)*8))
else
{
mEnterString = mEnterString .. c;
AppendChar(ch);
}
}
return true;