- added VGA font support to the MessageBoxMenu class

This is optional, of course.
This commit is contained in:
Christoph Oelckers 2019-04-10 01:33:02 +02:00
parent f1105f2e13
commit 939815d6bf
1 changed files with 36 additions and 18 deletions

View File

@ -41,6 +41,10 @@ class MessageBoxMenu : Menu
int mMouseLeft, mMouseRight, mMouseY; int mMouseLeft, mMouseRight, mMouseY;
Name mAction; Name mAction;
Font textFont, arrowFont;
int destWidth, destHeight;
String selector;
native static void CallHandler(voidptr hnd); native static void CallHandler(voidptr hnd);
@ -57,11 +61,29 @@ class MessageBoxMenu : Menu
messageSelection = 0; messageSelection = 0;
mMouseLeft = 140; mMouseLeft = 140;
mMouseY = 0x80000000; mMouseY = 0x80000000;
int mr1 = 170 + SmallFont.StringWidth(Stringtable.Localize("$TXT_YES"));
int mr2 = 170 + SmallFont.StringWidth(Stringtable.Localize("$TXT_NO")); if (generic_hud)
{
arrowFont = textFont = NewSmallFont;
int factor = (CleanXfac+1) / 2;
destWidth = screen.GetWidth() / factor;
destHeight = screen.GetHeight() / factor;
selector = "▶";
}
else
{
textFont = SmallFont;
arrowFont = ConFont;
destWidth = CleanWidth;
destHeight = CleanHeight;
selector = "\xd";
}
int mr1 = destWidth/2 + 10 + textFont.StringWidth(Stringtable.Localize("$TXT_YES"));
int mr2 = destWidth/2 + 10 + textFont.StringWidth(Stringtable.Localize("$TXT_NO"));
mMouseRight = MAX(mr1, mr2); mMouseRight = MAX(mr1, mr2);
mParentMenu = parent; mParentMenu = parent;
mMessage = SmallFont.BreakLines(Stringtable.Localize(message), 300); mMessage = textFont.BreakLines(Stringtable.Localize(message), generic_hud? 600 : 300);
mMessageMode = messagemode; mMessageMode = messagemode;
if (playsound) if (playsound)
{ {
@ -79,18 +101,16 @@ class MessageBoxMenu : Menu
override void Drawer () override void Drawer ()
{ {
int i, y; int i, y;
int fontheight = textFont.GetHeight();
int fontheight = SmallFont.GetHeight(); y = destHeight / 2;
y = 100;
int c = mMessage.Count(); int c = mMessage.Count();
for (i = 0; i < c; i++) y -= c * fontHeight / 2;
y -= SmallFont.GetHeight () / 2;
for (i = 0; i < c; i++) for (i = 0; i < c; i++)
{ {
screen.DrawText (SmallFont, Font.CR_UNTRANSLATED, 160 - mMessage.StringWidth(i)/2, y, mMessage.StringAt(i), DTA_Clean, true); screen.DrawText (textFont, Font.CR_UNTRANSLATED, destWidth/2 - mMessage.StringWidth(i)/2, y, mMessage.StringAt(i), DTA_VirtualWidth, destWidth, DTA_VirtualHeight, destHeight, DTA_KeepRatio, true);
y += fontheight; y += fontheight;
} }
@ -98,17 +118,15 @@ class MessageBoxMenu : Menu
{ {
y += fontheight; y += fontheight;
mMouseY = y; mMouseY = y;
screen.DrawText(SmallFont, messageSelection == 0? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor, 160, y, Stringtable.Localize("$TXT_YES"), DTA_Clean, true); screen.DrawText(textFont, messageSelection == 0? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor, destWidth / 2, y, Stringtable.Localize("$TXT_YES"), DTA_VirtualWidth, destWidth, DTA_VirtualHeight, destHeight, DTA_KeepRatio, true);
screen.DrawText(SmallFont, messageSelection == 1? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor, 160, y + fontheight + 1, Stringtable.Localize("$TXT_NO"), DTA_Clean, true); screen.DrawText(textFont, messageSelection == 1? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor, destWidth / 2, y + fontheight, Stringtable.Localize("$TXT_NO"), DTA_VirtualWidth, destWidth, DTA_VirtualHeight, destHeight, DTA_KeepRatio, true);
if (messageSelection >= 0) if (messageSelection >= 0)
{ {
if ((MenuTime() % 8) < 6) if ((MenuTime() % 8) < 6)
{ {
screen.DrawText(ConFont, OptionMenuSettings.mFontColorSelection, screen.DrawText(arrowFont, OptionMenuSettings.mFontColorSelection,
(150 - 160) * CleanXfac + screen.GetWidth() / 2, destWidth/2 - 11, y + fontheight * messageSelection, selector, DTA_VirtualWidth, destWidth, DTA_VirtualHeight, destHeight, DTA_KeepRatio, true);
(y + (fontheight + 1) * messageSelection - 100 + fontheight/2 - 5) * CleanYfac + screen.GetHeight() / 2,
"\xd", DTA_CellX, 8 * CleanXfac, DTA_CellY, 8 * CleanYfac);
} }
} }
} }
@ -268,11 +286,11 @@ class MessageBoxMenu : Menu
else else
{ {
int sel = -1; int sel = -1;
int fh = SmallFont.GetHeight() + 1; int fh = textFont.GetHeight() + 1;
// convert x/y from screen to virtual coordinates, according to CleanX/Yfac use in DrawTexture // convert x/y from screen to virtual coordinates, according to CleanX/Yfac use in DrawTexture
x = ((x - (screen.GetWidth() / 2)) / CleanXfac) + 160; x = x * destWidth / screen.GetWidth();
y = ((y - (screen.GetHeight() / 2)) / CleanYfac) + 100; y = y * destHeight / screen.GetHeight();
if (x >= mMouseLeft && x <= mMouseRight && y >= mMouseY && y < mMouseY + 2 * fh) if (x >= mMouseLeft && x <= mMouseRight && y >= mMouseY && y < mMouseY + 2 * fh)
{ {