- DMessageBoxMenu::Drawer scriptified.

This commit is contained in:
Christoph Oelckers 2017-02-18 23:18:55 +01:00
parent aabcc1f92e
commit 62b594a499
2 changed files with 89 additions and 74 deletions

View file

@ -47,13 +47,34 @@
#include "g_game.h"
class DBrokenLines : public DObject
{
DECLARE_ABSTRACT_CLASS(DBrokenLines, DObject)
public:
FBrokenLines *mBroken;
unsigned int mCount;
DBrokenLines(FBrokenLines *broken, unsigned int count)
{
mBroken = broken;
mCount = count;
}
void OnDestroy() override
{
V_FreeBrokenLines(mBroken);
}
};
EXTERN_CVAR (Bool, saveloadconfirmation) // [mxd]
class DMessageBoxMenu : public DMenu
{
DECLARE_CLASS(DMessageBoxMenu, DMenu)
public:
FBrokenLines *mMessage;
DBrokenLines *mMessage;
int mMessageMode;
int messageSelection;
int mMouseLeft, mMouseRight, mMouseY;
@ -63,9 +84,7 @@ public:
public:
DMessageBoxMenu(DMenu *parent = NULL, const char *message = NULL, int messagemode = 0, bool playsound = false, FName action = NAME_None, void (*hnd)() = nullptr);
void OnDestroy() override;
void Init(DMenu *parent, const char *message, int messagemode, bool playsound = false, void(*hnd)() = nullptr);
void Drawer();
};
IMPLEMENT_CLASS(DMessageBoxMenu, false, false)
@ -102,7 +121,11 @@ void DMessageBoxMenu::Init(DMenu *parent, const char *message, int messagemode,
if (message != NULL)
{
if (*message == '$') message = GStrings(message+1);
mMessage = V_BreakLines(SmallFont, 300, message);
unsigned count;
auto Message = V_BreakLines(SmallFont, 300, message, true, &count);
mMessage = new DBrokenLines(Message, count);
GC::WriteBarrier(mMessage);
mMessage->ObjectFlags |= OF_Fixed;
}
else mMessage = NULL;
mMessageMode = messagemode;
@ -114,76 +137,6 @@ void DMessageBoxMenu::Init(DMenu *parent, const char *message, int messagemode,
Handler = hnd;
}
//=============================================================================
//
//
//
//=============================================================================
void DMessageBoxMenu::OnDestroy()
{
if (mMessage != NULL) V_FreeBrokenLines(mMessage);
mMessage = NULL;
Super::OnDestroy();
}
//=============================================================================
//
//
//
//=============================================================================
void DMessageBoxMenu::Drawer ()
{
int i, y;
PalEntry fade = 0;
int fontheight = SmallFont->GetHeight();
//V_SetBorderNeedRefresh();
//ST_SetNeedRefresh();
y = 100;
if (mMessage != NULL)
{
for (i = 0; mMessage[i].Width >= 0; i++)
y -= SmallFont->GetHeight () / 2;
for (i = 0; mMessage[i].Width >= 0; i++)
{
screen->DrawText (SmallFont, CR_UNTRANSLATED, 160 - mMessage[i].Width/2, y, mMessage[i].Text,
DTA_Clean, true, TAG_DONE);
y += fontheight;
}
}
if (mMessageMode == 0)
{
y += fontheight;
mMouseY = y;
screen->DrawText(SmallFont,
messageSelection == 0? OptionSettings.mFontColorSelection : OptionSettings.mFontColor,
160, y, GStrings["TXT_YES"], DTA_Clean, true, TAG_DONE);
screen->DrawText(SmallFont,
messageSelection == 1? OptionSettings.mFontColorSelection : OptionSettings.mFontColor,
160, y + fontheight + 1, GStrings["TXT_NO"], DTA_Clean, true, TAG_DONE);
if (messageSelection >= 0)
{
if ((MenuTime%8) < 6)
{
screen->DrawText(ConFont, OptionSettings.mFontColorSelection,
(150 - 160) * CleanXfac + screen->GetWidth() / 2,
(y + (fontheight + 1) * messageSelection - 100 + fontheight/2 - 5) * CleanYfac + screen->GetHeight() / 2,
"\xd",
DTA_CellX, 8 * CleanXfac,
DTA_CellY, 8 * CleanYfac,
TAG_DONE);
}
}
}
}
typedef void(*hfunc)();
DEFINE_ACTION_FUNCTION(DMessageBoxMenu, CallHandler)
{
@ -395,3 +348,4 @@ DEFINE_FIELD(DMessageBoxMenu, mMouseRight);
DEFINE_FIELD(DMessageBoxMenu, mMouseY);
DEFINE_FIELD(DMessageBoxMenu, mAction);
DEFINE_FIELD(DMessageBoxMenu, Handler);
DEFINE_FIELD(DMessageBoxMenu, mMessage);

View file

@ -34,6 +34,7 @@
class MessageBoxMenu : Menu native
{
native BrokenLines mMessage;
native voidptr Handler;
native int mMessageMode;
native int messageSelection;
@ -43,6 +44,66 @@ class MessageBoxMenu : Menu native
native static void CallHandler(voidptr hnd);
//=============================================================================
//
//
//
//=============================================================================
override void OnDestroy()
{
mMessage.Destroy(); // explicitly free the strings now.
Super.OnDestroy();
}
//=============================================================================
//
//
//
//=============================================================================
override void Drawer ()
{
int i, y;
int fontheight = SmallFont.GetHeight();
y = 100;
if (mMessage != NULL)
{
int c = mMessage.Count();
for (i = 0; i < c; i++)
y -= SmallFont.GetHeight () / 2;
for (i = 0; i < c; i++)
{
screen.DrawText (SmallFont, Font.CR_UNTRANSLATED, 160 - mMessage.StringWidth(i)/2, y, mMessage.StringAt(i), DTA_Clean, true);
y += fontheight;
}
}
if (mMessageMode == 0)
{
y += fontheight;
mMouseY = y;
screen.DrawText(SmallFont, messageSelection == 0? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor, 160, y, Stringtable.Localize("$TXT_YES"), DTA_Clean, true);
screen.DrawText(SmallFont, messageSelection == 1? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor, 160, y + fontheight + 1, Stringtable.Localize("$TXT_NO"), DTA_Clean, true);
if (messageSelection >= 0)
{
if ((MenuTime() % 8) < 6)
{
screen.DrawText(ConFont, OptionMenuSettings.mFontColorSelection,
(150 - 160) * CleanXfac + screen.GetWidth() / 2,
(y + (fontheight + 1) * messageSelection - 100 + fontheight/2 - 5) * CleanYfac + screen.GetHeight() / 2,
"\xd", DTA_CellX, 8 * CleanXfac, DTA_CellY, 8 * CleanYfac);
}
}
}
}
//=============================================================================
//
//