- ported GZDoom's subtitle drawer to the cutscene framework.

For later use, this isn't used yet.
This commit is contained in:
Christoph Oelckers 2021-05-22 10:26:53 +02:00
parent d2ed4e703d
commit 5337513044
6 changed files with 69 additions and 5 deletions

View file

@ -51,6 +51,8 @@
#include "s_music.h"
#include "m_argv.h"
CVAR(Bool, inter_subtitles, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
DObject* runner;
PClass* runnerclass;
PType* runnerclasstype;

View file

@ -6,6 +6,9 @@
#include "s_soundinternal.h"
#include "gamestate.h"
#include "zstring.h"
#include "c_cvars.h"
EXTERN_CVAR(Bool, inter_subtitles)
using CompletionFunc = std::function<void(bool)>;

View file

@ -50,6 +50,7 @@
#include "flatvertices.h"
#include "version.h"
#include "hw_material.h"
#include "v_2ddrawer.h"
#include <chrono>
#include <thread>
@ -291,16 +292,19 @@ FMaterial* DFrameBuffer::CreateMaterial(FGameTexture* tex, int scaleflags)
//
//==========================================================================
DEFINE_ACTION_FUNCTION(_Screen, GetWidth)
static int ScreenGetWidth() { return twod->GetWidth(); }
static int ScreenGetHeight() { return twod->GetHeight(); }
DEFINE_ACTION_FUNCTION_NATIVE(_Screen, GetWidth, ScreenGetWidth)
{
PARAM_PROLOGUE;
ACTION_RETURN_INT(screen->GetWidth());
ACTION_RETURN_INT(twod->GetWidth());
}
DEFINE_ACTION_FUNCTION(_Screen, GetHeight)
DEFINE_ACTION_FUNCTION_NATIVE(_Screen, GetHeight, ScreenGetHeight)
{
PARAM_PROLOGUE;
ACTION_RETURN_INT(screen->GetHeight());
ACTION_RETURN_INT(twod->GetHeight());
}
DEFINE_ACTION_FUNCTION(_Screen, PaletteColor)

View file

@ -1528,6 +1528,11 @@ DEFINE_ACTION_FUNCTION(_MapRecord, GetCluster)
ACTION_RETURN_POINTER(FindCluster(self->cluster));
}
DEFINE_ACTION_FUNCTION(_Screen, GetTextScreenSize)
{
ACTION_RETURN_VEC2(DVector2(640, 480));
}
extern bool demoplayback;
DEFINE_GLOBAL(multiplayer)
DEFINE_GLOBAL(netgame)

View file

@ -410,6 +410,7 @@ struct Screen native
native static Color PaletteColor(int index);
native static int GetWidth();
native static int GetHeight();
native static Vector2 GetTextScreenSize();
native static void Clear(int left, int top, int right, int bottom, Color color, int palcolor = -1);
native static void Dim(Color col, double amount, int x, int y, int w, int h);

View file

@ -60,7 +60,6 @@ class ScreenJob : Object
if (flags & stopmusic) System.StopMusic();
if (flags & stopsound) System.StopAllSounds();
}
}
//---------------------------------------------------------------------------
@ -534,6 +533,56 @@ class ScreenJobRunner : Object
if (snd > 0) sounds.Pushv(1, snd);
Append(MoviePlayerJob.CreateWithSoundInfo(fn, sounds, 0, framerate));
}
//==========================================================================
//
// This also gets used by the title loop.
//
//==========================================================================
void DrawFullscreenSubtitle(String text, int cr)
{
if (text.length() == 0 || !inter_subtitles) return;
// This uses the same scaling as regular HUD messages
let screensize = Screen.GetTextScreenSize();
let hudwidth = screensize.X;
let hudheight = screensize.Y;
let hscale = screen.GetWidth() / hudwidth;
let vscale = screen.GetHeight() / hudheight;
let font = generic_ui? NewSmallFont : SmallFont;
let linelen = hudwidth < 640 ? hudwidth * 0.9 - 40 : 560;
let lines = font.BreakLines(text, linelen);
int count = lines.Count();
int height = 20 + font.GetHeight() * count;
double x, y, w;
if (linelen < 560)
{
x = hudwidth / 20;
w = hudwidth - 2 * x;
}
else
{
x = (hudwidth * 0.5) - 300;
w = 600;
}
y = hudheight * 0.9 - height;
if (y < 0) y = 0;
Screen.Dim(0, 0.5f, x * hscale, y * vscale, w * hscale, height * vscale);
x += 20;
y += 10;
for (int i = 0; i < count; i++)
{
Screen.DrawText(font, cr, x, y, lines.StringAt(i), DTA_KeepRatio, true, DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight);
y += font.GetHeight();
}
}
}
//---------------------------------------------------------------------------