- consolidate the dependencies on the font in the option menu.

This commit is contained in:
Christoph Oelckers 2019-03-17 16:58:10 +01:00
parent 2227c15010
commit 59f0a377d4
5 changed files with 65 additions and 37 deletions

View file

@ -287,6 +287,28 @@ class Menu : Object native ui version("2.4")
{ {
screen.DrawText (ConFont, color, x, y, str, DTA_CellX, 8 * CleanXfac, DTA_CellY, 8 * CleanYfac); screen.DrawText (ConFont, color, x, y, str, DTA_CellX, 8 * CleanXfac, DTA_CellY, 8 * CleanYfac);
} }
static int OptionColor(int color)
{
if (color != Font.CR_UNTRANSLATED) return color;
// This needs fixing for mods with custom fonts.
return gameinfo.gametype == GAME_Doom ? Font.CR_RED : gameinfo.gametype == GAME_Chex ? Font.CR_GREEN : gameinfo.gametype == GAME_Strife ? Font.CR_GOLD : Font.CR_GRAY;
}
static Font OptionFont()
{
return NewSmallFont;
}
static int OptionHeight()
{
return OptionFont().GetHeight();
}
static int OptionWidth(String s)
{
return OptionFont().StringWidth(s);
}
} }

View file

@ -451,7 +451,7 @@ class OptionMenu : Menu
} }
int ytop = y + mDesc.mScrollTop * 8 * CleanYfac_1; int ytop = y + mDesc.mScrollTop * 8 * CleanYfac_1;
int lastrow = screen.GetHeight() - NewSmallFont.GetHeight() * CleanYfac_1; int lastrow = screen.GetHeight() - OptionHeight() * CleanYfac_1;
int i; int i;
for (i = 0; i < mDesc.mItems.Size() && y <= lastrow; i++) for (i = 0; i < mDesc.mItems.Size() && y <= lastrow; i++)
@ -519,8 +519,8 @@ class GameplayMenu : OptionMenu
Super.Drawer(); Super.Drawer();
String s = String.Format("dmflags = %d dmflags2 = %d", dmflags, dmflags2); String s = String.Format("dmflags = %d dmflags2 = %d", dmflags, dmflags2);
screen.DrawText (NewSmallFont, OptionMenuSettings.mFontColorValue, screen.DrawText (OptionFont(), OptionMenuSettings.mFontColorValue,
(screen.GetWidth() - NewSmallFont.StringWidth (s) * CleanXfac_1) / 2, 0, s, (screen.GetWidth() - OptionWidth (s) * CleanXfac_1) / 2, 0, s,
DTA_CleanNoMove_1, true); DTA_CleanNoMove_1, true);
} }
} }
@ -532,8 +532,8 @@ class CompatibilityMenu : OptionMenu
Super.Drawer(); Super.Drawer();
String s = String.Format("compatflags = %d compatflags2 = %d", compatflags, compatflags2); String s = String.Format("compatflags = %d compatflags2 = %d", compatflags, compatflags2);
screen.DrawText (NewSmallFont, OptionMenuSettings.mFontColorValue, screen.DrawText (OptionFont(), OptionMenuSettings.mFontColorValue,
(screen.GetWidth() - NewSmallFont.StringWidth (s) * CleanXfac_1) / 2, 0, s, (screen.GetWidth() - OptionWidth (s) * CleanXfac_1) / 2, 0, s,
DTA_CleanNoMove_1, true); DTA_CleanNoMove_1, true);
} }
} }

View file

@ -44,19 +44,32 @@ class OptionMenuItem : MenuItemBase
mCentered = center; mCentered = center;
} }
protected int drawLabel(int indent, int y, int color, bool grayed = false) protected void drawText(int x, int y, int color, String text, bool grayed = false)
{ {
String label = Stringtable.Localize(mLabel); String label = Stringtable.Localize(mLabel);
int overlay = grayed? Color(96,48,0,0) : 0; int overlay = grayed? Color(96,48,0,0) : 0;
screen.DrawText (Menu.OptionFont(), Menu.OptionColor(color), x, y, text, DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay);
}
protected int drawLabel(int indent, int y, int color, bool grayed = false)
{
String label = Stringtable.Localize(mLabel);
int x; int x;
int w = NewSmallFont.StringWidth(label) * CleanXfac_1; int w = Menu.OptionWidth(label) * CleanXfac_1;
if (!mCentered) x = indent - w; if (!mCentered) x = indent - w;
else x = (screen.GetWidth() - w) / 2; else x = (screen.GetWidth() - w) / 2;
screen.DrawText (NewSmallFont, color, x, y, label, DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay); DrawText(x, y, color, label, grayed);
return x; return x;
} }
protected void drawValue(int indent, int y, int color, String text, bool grayed = false)
{
DrawText(indent + CursorSpace(), y, color, text, grayed);
}
int CursorSpace() int CursorSpace()
{ {
@ -71,11 +84,11 @@ class OptionMenuItem : MenuItemBase
override int GetIndent() override int GetIndent()
{ {
if (mCentered) return 0; if (mCentered) return 0;
return NewSmallFont.StringWidth(Stringtable.Localize(mLabel)); return Menu.OptionWidth(Stringtable.Localize(mLabel));
} }
override bool MouseEvent(int type, int x, int y) override bool MouseEvent(int type, int x, int y)
{ {
if (Selectable() && type == Menu.MOUSE_Release) if (Selectable() && type == Menu.MOUSE_Release)
{ {
return Menu.GetCurrentMenu().MenuEvent(Menu.MKEY_Enter, true); return Menu.GetCurrentMenu().MenuEvent(Menu.MKEY_Enter, true);
@ -140,8 +153,7 @@ class OptionMenuItemLabeledSubmenu : OptionMenuItemSubmenu
String text = mLabelCVar.GetString(); String text = mLabelCVar.GetString();
if (text.Length() == 0) text = Stringtable.Localize("$notset"); if (text.Length() == 0) text = Stringtable.Localize("$notset");
screen.DrawText (NewSmallFont, OptionMenuSettings.mFontColorValue, indent + CursorSpace(), y, text, DTA_CleanNoMove_1, true); drawValue(indent, y, OptionMenuSettings.mFontColorValue, text);
return indent; return indent;
} }
} }
@ -286,19 +298,16 @@ class OptionMenuItemOptionBase : OptionMenuItem
//============================================================================= //=============================================================================
override int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected) override int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected)
{ {
bool grayed = isGrayed();
if (mCenter) if (mCenter)
{ {
indent = (screen.GetWidth() / 2); indent = (screen.GetWidth() / 2);
} }
drawLabel(indent, y, selected? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor, grayed); drawLabel(indent, y, selected? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor, isGrayed());
int overlay = grayed? Color(96,48,0,0) : 0;
int Selection = GetSelection(); int Selection = GetSelection();
String text = StringTable.Localize(OptionValues.GetText(mValues, Selection)); String text = StringTable.Localize(OptionValues.GetText(mValues, Selection));
if (text.Length() == 0) text = "Unknown"; if (text.Length() == 0) text = "Unknown";
screen.DrawText (NewSmallFont, OptionMenuSettings.mFontColorValue, indent + CursorSpace(), y, text, DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay); drawValue(indent, y, OptionMenuSettings.mFontColorValue, text, isGrayed());
return indent; return indent;
} }
@ -502,11 +511,11 @@ class OptionMenuItemControlBase : OptionMenuItem
description = KeyBindings.NameKeys (Key1, Key2); description = KeyBindings.NameKeys (Key1, Key2);
if (description.Length() > 0) if (description.Length() > 0)
{ {
screen.DrawText(NewSmallFont, Font.CR_WHITE, indent + CursorSpace(), y, description, DTA_CleanNoMove_1, true); drawValue(indent, y, Font.CR_WHITE, description);
} }
else else
{ {
screen.DrawText(NewSmallFont, Font.CR_BLACK, indent + CursorSpace(), y, "---", DTA_CleanNoMove_1, true); drawValue(indent, y, Font.CR_BLACK, "---");
} }
return indent; return indent;
} }
@ -644,9 +653,9 @@ class OptionMenuItemStaticTextSwitchable : OptionMenuItem
override int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected) override int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected)
{ {
String txt = StringTable.Localize(mCurrent? mAltText : mLabel); String txt = StringTable.Localize(mCurrent? mAltText : mLabel);
int w = NewSmallFont.StringWidth(txt) * CleanXfac_1; int w = Menu.OptionWidth(txt) * CleanXfac_1;
int x = (screen.GetWidth() - w) / 2; int x = (screen.GetWidth() - w) / 2;
screen.DrawText (NewSmallFont, mColor, x, y, txt, DTA_CleanNoMove_1, true); drawText(x, y, mColor, txt);
return -1; return -1;
} }
@ -731,7 +740,7 @@ class OptionMenuSliderBase : OptionMenuItem
if (fracdigits >= 0) if (fracdigits >= 0)
{ {
textbuf = String.format(formater, max); textbuf = String.format(formater, max);
maxlen = NewSmallFont.StringWidth(textbuf) * CleanXfac_1; maxlen = Menu.OptionWidth(textbuf) * CleanXfac_1;
} }
mSliderShort = right + maxlen > screen.GetWidth(); mSliderShort = right + maxlen > screen.GetWidth();
@ -752,7 +761,7 @@ class OptionMenuSliderBase : OptionMenuItem
if (fracdigits >= 0 && right + maxlen <= screen.GetWidth()) if (fracdigits >= 0 && right + maxlen <= screen.GetWidth())
{ {
textbuf = String.format(formater, cur); textbuf = String.format(formater, cur);
screen.DrawText(NewSmallFont, Font.CR_DARKGRAY, right, y, textbuf, DTA_CleanNoMove_1, true); drawText(right, y, Font.CR_DARKGRAY, textbuf);
} }
} }
@ -971,9 +980,7 @@ class OptionMenuFieldBase : OptionMenuItem
{ {
bool grayed = mGrayCheck != null && !mGrayCheck.GetInt(); bool grayed = mGrayCheck != null && !mGrayCheck.GetInt();
drawLabel(indent, y, selected ? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor, grayed); drawLabel(indent, y, selected ? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor, grayed);
int overlay = grayed? Color(96, 48, 0, 0) : 0; drawValue(indent, y, OptionMenuSettings.mFontColorValue, Represent(), grayed);
screen.DrawText(NewSmallFont, OptionMenuSettings.mFontColorValue, indent + CursorSpace(), y, Represent(), DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay);
return indent; return indent;
} }
@ -1022,7 +1029,7 @@ class OptionMenuItemTextField : OptionMenuFieldBase
override String Represent() override String Represent()
{ {
if (mEnter) return mEnter.GetText() .. NewSmallFont.GetCursor(); if (mEnter) return mEnter.GetText() .. Menu.OptionFont().GetCursor();
else return GetCVarString(); else return GetCVarString();
} }
@ -1032,7 +1039,7 @@ class OptionMenuItemTextField : OptionMenuFieldBase
{ {
// reposition the text so that the cursor is visible when in entering mode. // reposition the text so that the cursor is visible when in entering mode.
String text = Represent(); String text = Represent();
int tlen = NewSmallFont.StringWidth(text) * CleanXfac_1; int tlen = Menu.OptionWidth(text) * CleanXfac_1;
int newindent = screen.GetWidth() - tlen - CursorSpace(); int newindent = screen.GetWidth() - tlen - CursorSpace();
if (newindent < indent) indent = newindent; if (newindent < indent) indent = newindent;
} }
@ -1044,7 +1051,7 @@ class OptionMenuItemTextField : OptionMenuFieldBase
if (mkey == Menu.MKEY_Enter) if (mkey == Menu.MKEY_Enter)
{ {
Menu.MenuSound("menu/choose"); Menu.MenuSound("menu/choose");
mEnter = TextEnterMenu.OpenTextEnter(Menu.GetCurrentMenu(), NewSmallFont, GetCVarString(), -1, fromcontroller); mEnter = TextEnterMenu.OpenTextEnter(Menu.GetCurrentMenu(), Menu.OptionFont(), GetCVarString(), -1, fromcontroller);
mEnter.ActivateMenu(); mEnter.ActivateMenu();
return true; return true;
} }
@ -1156,7 +1163,7 @@ class OptionMenuItemScaleSlider : OptionMenuItemSlider
if ((Selection == 0 || Selection == -1) && mClickVal <= 0) if ((Selection == 0 || Selection == -1) && mClickVal <= 0)
{ {
String text = Selection == 0? TextZero : Selection == -1? TextNegOne : ""; String text = Selection == 0? TextZero : Selection == -1? TextNegOne : "";
screen.DrawText (NewSmallFont, OptionMenuSettings.mFontColorValue, indent + CursorSpace(), y, text, DTA_CleanNoMove_1, true); drawValue(indent, y, OptionMenuSettings.mFontColorValue, text);
} }
else else
{ {

View file

@ -132,8 +132,7 @@ class OptionMenuItemReverbSelect : OptionMenuItemSubMenu
int x = drawLabel(indent, y, selected? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor); int x = drawLabel(indent, y, selected? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor);
String text = ReverbEdit.GetSelectedEnvironment(); String text = ReverbEdit.GetSelectedEnvironment();
screen.DrawText (NewSmallFont, OptionMenuSettings.mFontColorValue, indent + CursorSpace(), y, text, DTA_CleanNoMove_1, true); drawValue(indent, y, OptionMenuSettings.mFontColorValue, text);
return indent; return indent;
} }
} }
@ -210,7 +209,7 @@ class OptionMenuItemSliderReverbEditOption : OptionMenuSliderBase
virtual String Represent() virtual String Represent()
{ {
return mEnter.GetText() .. NewSmallFont.GetCursor(); return mEnter.GetText() .. Menu.OptionFont().GetCursor();
} }
//============================================================================= //=============================================================================
@ -221,7 +220,7 @@ class OptionMenuItemSliderReverbEditOption : OptionMenuSliderBase
mDrawX = indent + CursorSpace(); mDrawX = indent + CursorSpace();
if (mEnter) if (mEnter)
{ {
screen.DrawText(NewSmallFont, OptionMenuSettings.mFontColorValue, mDrawX, y, Represent(), DTA_CleanNoMove_1, true); drawText(mDrawX, y, OptionMenuSettings.mFontColorValue, Represent());
} }
else else
{ {
@ -235,7 +234,7 @@ class OptionMenuItemSliderReverbEditOption : OptionMenuSliderBase
if (mkey == Menu.MKEY_Enter) if (mkey == Menu.MKEY_Enter)
{ {
Menu.MenuSound("menu/choose"); Menu.MenuSound("menu/choose");
mEnter = TextEnterMenu.OpenTextEnter(Menu.GetCurrentMenu(), NewSmallFont, String.Format("%.3f", GetSliderValue()), -1, fromcontroller); mEnter = TextEnterMenu.OpenTextEnter(Menu.GetCurrentMenu(), Menu.OptionFont(), String.Format("%.3f", GetSliderValue()), -1, fromcontroller);
mEnter.ActivateMenu(); mEnter.ActivateMenu();
return true; return true;
} }

View file

@ -84,7 +84,7 @@ class TextEnterMenu : Menu
deprecated("3.8") static TextEnterMenu Open(Menu parent, String textbuffer, int maxlen, int sizemode, bool showgrid = false, bool allowcolors = false) 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, NewSmallFont, textbuffer, maxlen*8, showgrid, allowcolors); me.Init(parent, Menu.OptionFont(), textbuffer, maxlen*8, showgrid, allowcolors);
return me; return me;
} }