From 5337513044ca0cf3b325e7ad7aacae1b1eed8aa4 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 22 May 2021 10:26:53 +0200 Subject: [PATCH] - ported GZDoom's subtitle drawer to the cutscene framework. For later use, this isn't used yet. --- source/common/cutscenes/screenjob.cpp | 2 + source/common/cutscenes/screenjob.h | 3 ++ source/common/rendering/v_framebuffer.cpp | 12 ++++-- source/core/gamecontrol.cpp | 5 +++ wadsrc/static/zscript/engine/base.zs | 1 + wadsrc/static/zscript/engine/screenjob.zs | 51 ++++++++++++++++++++++- 6 files changed, 69 insertions(+), 5 deletions(-) diff --git a/source/common/cutscenes/screenjob.cpp b/source/common/cutscenes/screenjob.cpp index 305710eb5..b983c3e81 100644 --- a/source/common/cutscenes/screenjob.cpp +++ b/source/common/cutscenes/screenjob.cpp @@ -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; diff --git a/source/common/cutscenes/screenjob.h b/source/common/cutscenes/screenjob.h index be39bd25f..eaf6a10a9 100644 --- a/source/common/cutscenes/screenjob.h +++ b/source/common/cutscenes/screenjob.h @@ -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; diff --git a/source/common/rendering/v_framebuffer.cpp b/source/common/rendering/v_framebuffer.cpp index 747a37c6e..30192e4a3 100644 --- a/source/common/rendering/v_framebuffer.cpp +++ b/source/common/rendering/v_framebuffer.cpp @@ -50,6 +50,7 @@ #include "flatvertices.h" #include "version.h" #include "hw_material.h" +#include "v_2ddrawer.h" #include #include @@ -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) diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index cae67657d..e4539ce5a 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -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) diff --git a/wadsrc/static/zscript/engine/base.zs b/wadsrc/static/zscript/engine/base.zs index 5deef7ec0..db626e169 100644 --- a/wadsrc/static/zscript/engine/base.zs +++ b/wadsrc/static/zscript/engine/base.zs @@ -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); diff --git a/wadsrc/static/zscript/engine/screenjob.zs b/wadsrc/static/zscript/engine/screenjob.zs index fef98ffca..dac794f32 100644 --- a/wadsrc/static/zscript/engine/screenjob.zs +++ b/wadsrc/static/zscript/engine/screenjob.zs @@ -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(); + } + } } //---------------------------------------------------------------------------