diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index c3e0c027c..665c8b8e1 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -1436,13 +1436,29 @@ DEFINE_ACTION_FUNCTION(_Screen, GetViewWindow) return MIN(numret, 4); } -DEFINE_ACTION_FUNCTION_NATIVE(_Build, ShadeToLight, shadeToLight) +DEFINE_ACTION_FUNCTION_NATIVE(_Raze, ShadeToLight, shadeToLight) { PARAM_PROLOGUE; PARAM_INT(shade); ACTION_RETURN_INT(shadeToLight(shade)); } +DEFINE_ACTION_FUNCTION_NATIVE(_Raze, StopAllSounds, FX_StopAllSounds) +{ + FX_StopAllSounds(); + return 0; +} + +DEFINE_ACTION_FUNCTION_NATIVE(_Raze, SoundEnabled, SoundEnabled) +{ + ACTION_RETURN_INT(SoundEnabled()); +} + +DEFINE_ACTION_FUNCTION_NATIVE(_Raze, MusicEnabled, MusicEnabled) +{ + ACTION_RETURN_INT(MusicEnabled()); +} + extern bool demoplayback; DEFINE_GLOBAL(multiplayer) DEFINE_GLOBAL(netgame) diff --git a/source/core/gamecontrol.h b/source/core/gamecontrol.h index fa2cab18a..6d6188af9 100644 --- a/source/core/gamecontrol.h +++ b/source/core/gamecontrol.h @@ -70,12 +70,12 @@ extern UserConfig userConfig; extern int nomusic; extern bool nosound; -inline bool MusicEnabled() +inline int MusicEnabled() // int return is for scripting { return mus_enabled && !nomusic; } -inline bool SoundEnabled() +inline int SoundEnabled() { return snd_enabled && !nosound; } diff --git a/source/games/duke/src/2d_d.cpp b/source/games/duke/src/2d_d.cpp index ab3d3cfcf..0667fd568 100644 --- a/source/games/duke/src/2d_d.cpp +++ b/source/games/duke/src/2d_d.cpp @@ -139,10 +139,11 @@ void InitFonts_d() // //========================================================================== -static void BigText(double x, double y, const char* text, double alpha = 1.) +static void BigText(double x, double y, const char* text, int align = -1, double alpha = 1.) { - auto width = BigFont->StringWidth(text); - DrawText(twod, BigFont, CR_UNTRANSLATED, x - width / 2, y - 12, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Alpha, alpha, TAG_DONE); + if (align != -1) + x -= BigFont->StringWidth(text) * (align == 0 ? 0.5 : 1); + DrawText(twod, BigFont, CR_UNTRANSLATED, x, y - 12, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Alpha, alpha, TAG_DONE); } static void GameText(double x, double y, const char* t, int shade, int align = -1, int trans = 0) diff --git a/source/games/duke/src/2d_r.cpp b/source/games/duke/src/2d_r.cpp index 101c41567..01602ee37 100644 --- a/source/games/duke/src/2d_r.cpp +++ b/source/games/duke/src/2d_r.cpp @@ -135,7 +135,6 @@ static void BigText(double x, double y, const char* text, int align, double alph //x *= 2.2; y *= 2.64; if (align != -1) x -= BigFont->StringWidth(text) * (align == 0 ? 0.2 : 0.4); - auto width = BigFont->StringWidth(text); DrawText(twod, BigFont, CR_UNTRANSLATED, x, y - 12, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_ScaleX, 0.4, DTA_ScaleY, 0.4, DTA_Alpha, alpha, TAG_DONE); } @@ -576,7 +575,7 @@ public: void OnTick() override { - if (!S_CheckSoundPlaying(-1, 35) && ticks > 15 * GameTicRate) state = finished; // make sure it stays, even if sound is off. + if (!S_CheckSoundPlaying(35) && ticks > 15 * GameTicRate) state = finished; // make sure it stays, even if sound is off. } void Draw(double) override { diff --git a/source/games/duke/src/sounds.cpp b/source/games/duke/src/sounds.cpp index d617e7df8..f5a693dc3 100644 --- a/source/games/duke/src/sounds.cpp +++ b/source/games/duke/src/sounds.cpp @@ -897,4 +897,11 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Duke, PLaySound, PlaySound) ACTION_RETURN_INT(PlaySound(snd, chan, flags, vol)); } +DEFINE_ACTION_FUNCTION_NATIVE(_Duke, CheckSoundPlaying, S_CheckSoundPlaying) +{ + PARAM_PROLOGUE; + PARAM_INT(snd); + ACTION_RETURN_INT(S_CheckSoundPlaying(snd)); +} + END_DUKE_NS diff --git a/source/games/duke/src/sounds.h b/source/games/duke/src/sounds.h index 415af4406..4862ee28c 100644 --- a/source/games/duke/src/sounds.h +++ b/source/games/duke/src/sounds.h @@ -48,7 +48,6 @@ void S_MenuSound(void); void S_StopSound(int sndNum, DDukeActor* spr = nullptr, int flags = -1); int S_CheckSoundPlaying(int soundNum); -inline int S_CheckSoundPlaying(int sprnum, int soundNum) { return S_CheckSoundPlaying(soundNum); } int S_CheckActorSoundPlaying(DDukeActor* spriteNum, int soundNum, int channel = 0); int S_CheckAnyActorSoundPlaying(DDukeActor* spriteNum); diff --git a/wadsrc/static/zscript/engine/base.zs b/wadsrc/static/zscript/engine/base.zs index 3a3a4fb3b..0fef04818 100644 --- a/wadsrc/static/zscript/engine/base.zs +++ b/wadsrc/static/zscript/engine/base.zs @@ -218,7 +218,9 @@ struct TexMan AllowSkins = 8, ShortNameOnly = 16, DontCreate = 32, - Localize = 64 + Localize = 64, + ForceLookup = 128, + NoAlias = 256 }; enum ETexReplaceFlags diff --git a/wadsrc/static/zscript/games/blood/ui/menu.zs b/wadsrc/static/zscript/games/blood/ui/menu.zs index 53035e7af..dbcb2a947 100644 --- a/wadsrc/static/zscript/games/blood/ui/menu.zs +++ b/wadsrc/static/zscript/games/blood/ui/menu.zs @@ -85,7 +85,7 @@ class ListMenuItemBloodTextItem : ListMenuItemTextItem if (selected) shade = 32 - ((MSTime() * 120 / 1000) & 63); Screen.DrawText(gamefont, Font.CR_UNDEFINED, xpos+1, mYpos+1, mText, DTA_Color, 0xff000000, DTA_FullscreenScale, FSMode_Fit320x200); - Screen.DrawText(gamefont, Font.CR_UNDEFINED, xpos, mYpos, mText, DTA_TranslationIndex, trans, DTA_Color, Build.shadeToLight(shade), DTA_FullscreenScale, FSMode_Fit320x200); + Screen.DrawText(gamefont, Font.CR_UNDEFINED, xpos, mYpos, mText, DTA_TranslationIndex, trans, DTA_Color, Raze.shadeToLight(shade), DTA_FullscreenScale, FSMode_Fit320x200); } } diff --git a/wadsrc/static/zscript/games/duke/dukegame.zs b/wadsrc/static/zscript/games/duke/dukegame.zs index 2eb7b2e98..d92e9e27d 100644 --- a/wadsrc/static/zscript/games/duke/dukegame.zs +++ b/wadsrc/static/zscript/games/duke/dukegame.zs @@ -23,6 +23,56 @@ struct Duke native native static void PlaySpecialMusic(int which); native static int PlaySound(int num, int channel = CHAN_AUTO, int flags = 0, float vol =0.8f); + native static bool CheckSoundPlaying(int num); + + //========================================================================== + // + // wrappers around DrawText to allow easier reuse of the old code. + // The vertical displacements are to have the same positioning as with the original code. + // + //========================================================================== + + static void BigText(double x, double y, String text, int align = -1, double alpha = 1.) + { + + if (!Raze.isRR()) + { + if (align != -1) x -= BigFont.StringWidth(text) * (align == 0 ? 0.5 : 1); + Screen.DrawText(BigFont, Font.CR_UNTRANSLATED, x, y - 12, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Alpha, alpha); + } + else + { + if (align != -1) x -= BigFont.StringWidth(text) * (align == 0 ? 0.2 : 0.4); + Screen.DrawText(BigFont, Font.CR_UNTRANSLATED, x, y - 12, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_ScaleX, 0.4, DTA_ScaleY, 0.4, DTA_Alpha, alpha); + } + } + + static void GameText(double x, double y, String t, int shade, int align = -1, int trans = 0) + { + int fsmode = FSMode_Fit320x200; + if (Raze.isRR()) + { + x *= 2; + y *= 2; + fsmode = FSMode_Fit640x400; + } + if (align != -1) x -= SmallFont.StringWidth(t) * (align == 0 ? 0.5 : 1); + Screen.DrawText(SmallFont, Font.CR_UNDEFINED, x, y + 2, t, DTA_FullscreenScale, fsmode, DTA_TranslationIndex, Translation.MakeID(Translation_Remap, trans), DTA_Color, Raze.shadeToLight(shade)); + } + + static void MiniText(double x, double y, String t, int shade, int align = -1, int trans = 0) + { + int fsmode = FSMode_Fit320x200; + if (Raze.isRR()) + { + x *= 2; + y *= 2; + fsmode = FSMode_Fit640x400; + } + if (align != -1) x -= SmallFont2.StringWidth(t) * (align == 0 ? 0.5 : 1); + Screen.DrawText(SmallFont2, Font.CR_UNDEFINED, x, y, t, DTA_FullscreenScale, fsmode, DTA_TranslationIndex, Translation.MakeID(Translation_Remap, trans), DTA_Color, Raze.shadeToLight(shade)); + } + } diff --git a/wadsrc/static/zscript/games/duke/ui/menu.zs b/wadsrc/static/zscript/games/duke/ui/menu.zs index 6c81fbae3..604624f96 100644 --- a/wadsrc/static/zscript/games/duke/ui/menu.zs +++ b/wadsrc/static/zscript/games/duke/ui/menu.zs @@ -38,7 +38,7 @@ class DukeMenuDelegate : RazeMenuDelegate String picname; if (!right) picname= String.Format("SPINNINGNUKEICON%d", ((mclock >> 3) % frames)); else picname = String.Format("SPINNINGNUKEICON%d", frames - 1 - ((frames - 1 + (mclock >> 3)) % frames)); - int light = 231 + (Build.calcSinTableValue(mclock<<5) / 768.); + int light = 231 + (Raze.calcSinTableValue(mclock<<5) / 768.); let pe = color(255, light, light, light); Screen.DrawTexture(TexMan.CheckForTexture(picname), false, x, y, DTA_FullscreenScale, FSMode_Fit320x200, DTA_ScaleX, scale, DTA_ScaleY, scale, DTA_Color, pe, DTA_CenterOffsetRel, true); } @@ -110,7 +110,7 @@ class ListMenuItemDukeLogo : ListMenuItem if (gameinfo.gametype & GAMEFLAG_PLUTOPAK) { int mclock = MSTime() * 120 / 1000; - int light = 223 + (Build.calcSinTableValue(mclock<<4) / 512.); + int light = 223 + (Raze.calcSinTableValue(mclock<<4) / 512.); let pe = Color(255, light, light, light); Screen.DrawTexture(TexMan.CheckForTexture("MENUPLUTOPAKSPRITE"), false, x + 100, 36, DTA_FullscreenScale, FSMode_Fit320x200Top, DTA_Color, pe, DTA_CenterOffsetRel, true); } @@ -148,7 +148,7 @@ class ListMenuItemDukeTextItem : ListMenuItemTextItem if (selected) { int mclock = MSTime() * 120 / 1000; - int light = 231 + (Build.calcSinTableValue(mclock<<5) / 512.); + int light = 231 + (Raze.calcSinTableValue(mclock<<5) / 512.); pe = Color(255, light, light, light); } else diff --git a/wadsrc/static/zscript/games/duke/ui/screens.zs b/wadsrc/static/zscript/games/duke/ui/screens.zs index 282f1d7bf..264c78ec1 100644 --- a/wadsrc/static/zscript/games/duke/ui/screens.zs +++ b/wadsrc/static/zscript/games/duke/ui/screens.zs @@ -51,7 +51,7 @@ class TitleScreen : SkippableScreenJob override void Start() { - if (Build.isNam() || userConfig.nologo) Duke.PlaySpecialMusic(Duke.MUS_INTRO); + if (Raze.isNam() || userConfig.nologo) Duke.PlaySpecialMusic(Duke.MUS_INTRO); } override void OnTick() @@ -70,12 +70,12 @@ class TitleScreen : SkippableScreenJob if (soundanm == 2 && clock >= 280 && clock < 395) { soundanm = 3; - if (Build.isPlutoPak()) Duke.PlaySound(DukeSnd.FLY_BY, CHAN_AUTO, CHANF_UI); + if (Raze.isPlutoPak()) Duke.PlaySound(DukeSnd.FLY_BY, CHAN_AUTO, CHANF_UI); } else if (soundanm == 3 && clock >= 395) { soundanm = 4; - if (Build.isPlutoPak()) Duke.PlaySound(DukeSnd.PIPEBOMB_EXPLODE, CHAN_AUTO, CHANF_UI); + if (Raze.isPlutoPak()) Duke.PlaySound(DukeSnd.PIPEBOMB_EXPLODE, CHAN_AUTO, CHANF_UI); } if (clock > (860 + 120)) @@ -116,7 +116,7 @@ class TitleScreen : SkippableScreenJob DTA_CenterOffsetRel, true, DTA_TranslationIndex, trans, DTA_ScaleX, scale, DTA_ScaleY, scale); } - if (Build.isPlutoPak()) + if (Raze.isPlutoPak()) { scale = (410 - clamp(clock, 280, 395)) / 16.; if (scale > 0. && clock > 280) @@ -269,3 +269,145 @@ class E2EndScreen : ImageScreen Duke.PlaySound(DukeSnd.PIPEBOMB_EXPLODE, CHAN_AUTO, CHANF_UI); } } + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +class Episode3End : ImageScreen +{ + int soundstate; + int finishtime; + + void Init() + { + Super.Init("", fadein|fadeout, 0x7fffffff); + texid = TexMan.CheckForTexture("radlogo.anm", TexMan.Type_Any, TexMan.TryAny | TexMan.ForceLookup); // must override with 'forcelookup'. + soundstate = 0; + finishtime = 0; + } + + override void OnSkip() + { + Raze.StopAllSounds(); + } + + override void OnTick() + { + switch (soundstate) + { + case 0: + Duke.PlaySound(DukeSnd.ENDSEQVOL3SND5, CHAN_AUTO, CHANF_UI); + soundstate++; + break; + + case 1: + if (!Duke.CheckSoundPlaying(DukeSnd.ENDSEQVOL3SND5)) + { + Duke.PlaySound(DukeSnd.ENDSEQVOL3SND6, CHAN_AUTO, CHANF_UI); + soundstate++; + } + break; + + case 2: + if (!Duke.CheckSoundPlaying(DukeSnd.ENDSEQVOL3SND6)) + { + Duke.PlaySound(DukeSnd.ENDSEQVOL3SND7, CHAN_AUTO, CHANF_UI); + soundstate++; + } + break; + + case 3: + if (!Duke.CheckSoundPlaying(DukeSnd.ENDSEQVOL3SND7)) + { + Duke.PlaySound(DukeSnd.ENDSEQVOL3SND8, CHAN_AUTO, CHANF_UI); + soundstate++; + } + break; + + case 4: + if (!Duke.CheckSoundPlaying(DukeSnd.ENDSEQVOL3SND8)) + { + Duke.PlaySound(DukeSnd.ENDSEQVOL3SND9, CHAN_AUTO, CHANF_UI); + soundstate++; + } + break; + + case 5: + if (!Duke.CheckSoundPlaying(DukeSnd.ENDSEQVOL3SND9)) + { + soundstate++; + finishtime = ticks + GameTicRate * (Raze.SoundEnabled() ? 1 : 5); // if sound is off this wouldn't wait without a longer delay here. + } + break; + + case 6: + if (Raze.isPlutoPak()) + { + if (ticks > finishtime) jobstate = finished; + } + break; + + default: + break; + } + if (jobstate != running) Raze.StopAllSounds(); + } + + override void OnDestroy() + { + if (!Raze.isPlutoPak()) Duke.PlaySound(DukeSnd.ENDSEQVOL3SND4, CHAN_AUTO, CHANF_UI); + } +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +class Episode4Text : SkippableScreenJob +{ + void Init() + { + Super.Init(fadein|fadeout); + } + + + override void Draw(double sm) + { + Screen.ClearScreen(); + Duke.BigText(160, 60, "$Thanks to all our"); + Duke.BigText(160, 60 + 16, "$fans for giving"); + Duke.BigText(160, 60 + 16 + 16, "$us big heads."); + Duke.BigText(160, 70 + 16 + 16 + 16, "$Look for a Duke Nukem 3D"); + Duke.BigText(160, 70 + 16 + 16 + 16 + 16, "$sequel soon."); + } + + override void Start() + { + Duke.PlaySound(DukeSnd.ENDSEQVOL3SND4, CHAN_AUTO, CHANF_UI); + } +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +class Episode5End : ImageScreen +{ + void Init() + { + Super.Init("FIREFLYGROWEFFECT", fadein|fadeout|stopsound); + } + + override void OnTick() + { + if (ticks == 1) Duke.PlaySound(DukeSnd.E5L7_DUKE_QUIT_YOU, CHAN_AUTO, CHANF_UI); + } +} + diff --git a/wadsrc/static/zscript/games/exhumed/ui/menu.zs b/wadsrc/static/zscript/games/exhumed/ui/menu.zs index 52101751d..b8e139181 100644 --- a/wadsrc/static/zscript/games/exhumed/ui/menu.zs +++ b/wadsrc/static/zscript/games/exhumed/ui/menu.zs @@ -98,10 +98,10 @@ class ListMenuItemExhumedTextItem : ListMenuItemTextItem double y = mYpos + v.y / 2; int shade; - if (selected) shade = Build.CalcSinTableValue(MSTime() * 16 * 120 / 1000) >> 9; + if (selected) shade = Raze.CalcSinTableValue(MSTime() * 16 * 120 / 1000) >> 9; else if (Selectable()) shade = 0; else shade = 25; - let color = Build.shadeToLight(shade); + let color = Raze.shadeToLight(shade); double scalex = 1.; // Squash the text if it is too wide. Due to design limitations we cannot expand the box here. :( if (texsize.X - 18 < width) diff --git a/wadsrc/static/zscript/razebase.zs b/wadsrc/static/zscript/razebase.zs index 4c6273945..41cb20aee 100644 --- a/wadsrc/static/zscript/razebase.zs +++ b/wadsrc/static/zscript/razebase.zs @@ -39,7 +39,7 @@ extend struct _ native @UserConfigStruct userConfig; } -struct Build +struct Raze { static int calcSinTableValue(int ang) { @@ -47,6 +47,9 @@ struct Build } native static Color shadeToLight(int shade); + native static void StopAllSounds(); + native static bool SoundEnabled(); + native static bool MusicEnabled(); // game check shortcuts static bool isNam() diff --git a/wadsrc/static/zscript/screenjob.zs b/wadsrc/static/zscript/screenjob.zs index f1aac763b..477dd8889 100644 --- a/wadsrc/static/zscript/screenjob.zs +++ b/wadsrc/static/zscript/screenjob.zs @@ -32,6 +32,7 @@ class ScreenJob native native virtual bool OnEvent(InputEvent evt); native virtual void OnTick(); native virtual void Draw(double smoothratio); + virtual void OnSkip() {} //native int DrawFrame(double smoothratio); //native int GetFadeState(); @@ -48,7 +49,6 @@ class SkippableScreenJob : ScreenJob native { native void Init(int flags = 0, float fadet = 250.f); //native override bool OnEvent(InputEvent evt); - virtual void Skipped() {} } //---------------------------------------------------------------------------