mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-27 06:22:18 +00:00
- safety commit
This commit is contained in:
parent
29a4955f79
commit
3dbb8cbb11
16 changed files with 75 additions and 56 deletions
|
@ -81,7 +81,6 @@ struct GameInterface : ::GameInterface
|
|||
bool CanSave() override;
|
||||
bool StartGame(FNewGameStartup& gs) override;
|
||||
void DrawNativeMenuText(int fontnum, int state, double xpos, double ypos, float fontscale, const char* text, int flags) override;
|
||||
void DrawMenuCaption(const DVector2& origin, const char* text) override;
|
||||
bool SaveGame(FSaveGameNode*) override;
|
||||
bool LoadGame(FSaveGameNode*) override;
|
||||
void DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool bg) override;
|
||||
|
|
|
@ -269,23 +269,6 @@ FSavegameInfo GameInterface::GetSaveSig()
|
|||
return { SAVESIG_BLD, MINSAVEVER_BLD, SAVEVER_BLD };
|
||||
}
|
||||
|
||||
// This also gets used by the summary and the loading screen
|
||||
void DrawMenuCaption(const char* text)
|
||||
{
|
||||
double scalex = 1.; // Expand the box if the text is longer
|
||||
int width = BigFont->StringWidth(text);
|
||||
int boxwidth = tileWidth(2038);
|
||||
if (boxwidth - 10 < width) scalex = double(width) / (boxwidth - 10);
|
||||
|
||||
DrawTexture(twod, tileGetTexture(2038, true), 160, 20, DTA_FullscreenScale, FSMode_Fit320x200Top, DTA_CenterOffsetRel, true, DTA_ScaleX, scalex, TAG_DONE);
|
||||
DrawText(twod, BigFont, CR_UNDEFINED, 160 - width/2, 20 - tileHeight(4193) / 2, text, DTA_FullscreenScale, FSMode_Fit320x200Top, TAG_DONE);
|
||||
}
|
||||
|
||||
void GameInterface::DrawMenuCaption(const DVector2& origin, const char* text)
|
||||
{
|
||||
Blood::DrawMenuCaption(text);
|
||||
}
|
||||
|
||||
void GameInterface::DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool bg)
|
||||
{
|
||||
if (text)
|
||||
|
|
|
@ -87,6 +87,18 @@ static void drawTextScreenBackground(void)
|
|||
}
|
||||
}
|
||||
|
||||
// One these screens get scriptified this should use the version in menuCustomizerBlood.
|
||||
static void DrawCaption(const char* text)
|
||||
{
|
||||
double scalex = 1.; // Expand the box if the text is longer
|
||||
int width = BigFont->StringWidth(text);
|
||||
int boxwidth = tileWidth(2038);
|
||||
if (boxwidth - 10 < width) scalex = double(width) / (boxwidth - 10);
|
||||
|
||||
DrawTexture(twod, tileGetTexture(2038, true), 160, 20, DTA_FullscreenScale, FSMode_Fit320x200Top, DTA_CenterOffsetRel, true, DTA_ScaleX, scalex, TAG_DONE);
|
||||
DrawText(twod, BigFont, CR_UNDEFINED, 160 - width / 2, 20 - tileHeight(4193) / 2, text, DTA_FullscreenScale, FSMode_Fit320x200Top, TAG_DONE);
|
||||
}
|
||||
|
||||
|
||||
class DBloodSummaryScreen : public DScreenJob
|
||||
{
|
||||
|
@ -141,7 +153,7 @@ class DBloodSummaryScreen : public DScreenJob
|
|||
drawTextScreenBackground();
|
||||
if (gGameOptions.nGameType == 0)
|
||||
{
|
||||
DrawMenuCaption(GStrings("TXTB_LEVELSTATS"));
|
||||
DrawCaption(GStrings("TXTB_LEVELSTATS"));
|
||||
if (bPlayerCheated)
|
||||
{
|
||||
auto text = GStrings("TXTB_CHEATED");
|
||||
|
@ -154,7 +166,7 @@ class DBloodSummaryScreen : public DScreenJob
|
|||
}
|
||||
else
|
||||
{
|
||||
DrawMenuCaption(GStrings("TXTB_FRAGSTATS"));
|
||||
DrawCaption(GStrings("TXTB_FRAGSTATS"));
|
||||
DrawKills();
|
||||
}
|
||||
int myclock = int(clock * 120 / 1'000'000'000);
|
||||
|
@ -301,7 +313,7 @@ public:
|
|||
{
|
||||
twod->ClearScreen();
|
||||
drawTextScreenBackground();
|
||||
DrawMenuCaption(pzLoadingScreenText1);
|
||||
DrawCaption(pzLoadingScreenText1);
|
||||
viewDrawText(1, rec->DisplayName(), 160, 50, -128, 0, 1, 1);
|
||||
|
||||
auto text = GStrings("TXTB_PLSWAIT");
|
||||
|
|
|
@ -143,6 +143,5 @@ void tilePrecacheTile(int nTile, int nType, HitList& hits);
|
|||
char tileGetSurfType(int hit);
|
||||
|
||||
void scrLoadPalette(void);
|
||||
void DrawMenuCaption(const char* text);
|
||||
|
||||
END_BLD_NS
|
||||
|
|
|
@ -355,6 +355,18 @@ DEFINE_ACTION_FUNCTION_NATIVE(FFont, GetCursor, GetCursor)
|
|||
ACTION_RETURN_STRING(FString(self->GetCursor()));
|
||||
}
|
||||
|
||||
static int GetGlyphHeight(FFont* fnt, int code)
|
||||
{
|
||||
auto glyph = fnt->GetChar(code, CR_UNTRANSLATED, nullptr);
|
||||
return glyph ? (int)glyph->GetDisplayHeight() : 0;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(FFont, GetGlyphHeight, GetGlyphHeight)
|
||||
{
|
||||
PARAM_SELF_STRUCT_PROLOGUE(FFont);
|
||||
PARAM_INT(code);
|
||||
ACTION_RETURN_INT(GetGlyphHeight(self, code));
|
||||
}
|
||||
//==========================================================================
|
||||
//
|
||||
// file system
|
||||
|
|
|
@ -83,7 +83,6 @@ struct GameInterface
|
|||
virtual bool DrawSpecialScreen(const DVector2 &origin, int tilenum) { return false; }
|
||||
virtual void DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool withbg = true);
|
||||
virtual double SmallFontScale() { return 1; }
|
||||
virtual void DrawMenuCaption(const DVector2& origin, const char* text) {}
|
||||
virtual bool SaveGame(FSaveGameNode*) { return true; }
|
||||
virtual bool LoadGame(FSaveGameNode*) { return true; }
|
||||
virtual void SerializeGameState(FSerializer& arc) {}
|
||||
|
|
|
@ -1194,3 +1194,20 @@ void processSetAnim(const char* cmd, FScriptPosition& pos, SetAnim& imp)
|
|||
|
||||
TileSiz tilesiz;
|
||||
PicAnm picanm;
|
||||
|
||||
#include "vm.h"
|
||||
|
||||
static int GetTexture(int tile, int anim)
|
||||
{
|
||||
if (tile < 0 || tile >= MAXTILES) return 0;
|
||||
auto tex = tileGetTexture(tile, anim);
|
||||
return tex ? tex->GetID().GetIndex() : 0;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(_TileFiles, GetTexture, GetTexture)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_INT(tile);
|
||||
PARAM_BOOL(animate);
|
||||
ACTION_RETURN_INT(GetTexture(tile, animate));
|
||||
}
|
||||
|
|
|
@ -179,12 +179,6 @@ FSavegameInfo GameInterface::GetSaveSig()
|
|||
return { SAVESIG_PS, MINSAVEVER_PS, SAVEVER_PS };
|
||||
}
|
||||
|
||||
void GameInterface::DrawMenuCaption(const DVector2& origin, const char* text)
|
||||
{
|
||||
// Fixme: should use the extracted font from the menu items (i.e. BigFont) and a stretched box for the menu items.
|
||||
DrawText(twod, SmallFont, CR_UNTRANSLATED, 160 - SmallFont->StringWidth(text)/2, 10, text, DTA_FullscreenScale, FSMode_Fit320x200Top, TAG_DONE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
END_PS_NS
|
||||
|
|
|
@ -243,7 +243,6 @@ struct GameInterface : ::GameInterface
|
|||
void MenuClosed() override;
|
||||
bool StartGame(FNewGameStartup& gs) override;
|
||||
FSavegameInfo GetSaveSig() override;
|
||||
void DrawMenuCaption(const DVector2& origin, const char* text) override;
|
||||
bool LoadGame(FSaveGameNode* sv) override;
|
||||
bool SaveGame(FSaveGameNode* sv) override;
|
||||
bool CanSave() override;
|
||||
|
|
|
@ -314,20 +314,6 @@ FSavegameInfo GameInterface::GetSaveSig()
|
|||
return { SAVESIG_DN3D, MINSAVEVER_DN3D, SAVEVER_DN3D };
|
||||
}
|
||||
|
||||
void GameInterface::DrawMenuCaption(const DVector2& origin, const char* text)
|
||||
{
|
||||
DrawTexture(twod, tileGetTexture(TILE_MENUBAR), origin.X + 160, origin.Y + 19, DTA_FullscreenScale, FSMode_Fit320x200Top, DTA_Color, 0xff808080, DTA_CenterOffsetRel, 1, TAG_DONE);
|
||||
|
||||
FString t = text;
|
||||
size_t newlen = t.Len();
|
||||
if (t[t.Len() - 1] == ':') newlen--;
|
||||
if (newlen > 63) newlen = 63;
|
||||
t.Truncate(newlen);
|
||||
double scale = isRR() ? 0.4 : 1.0;
|
||||
double x = 160 + origin.X - BigFont->StringWidth(t) * scale * 0.5;
|
||||
DrawText(twod, BigFont, CR_UNTRANSLATED, x, origin.Y + 12, t, DTA_FullscreenScale, FSMode_Fit320x200Top, DTA_ScaleX, scale, DTA_ScaleY, scale, TAG_DONE);
|
||||
}
|
||||
|
||||
void GameInterface::DrawCenteredTextScreen(const DVector2 &origin, const char *text, int position, bool bg)
|
||||
{
|
||||
if (bg) Menu_DrawBackground(origin);
|
||||
|
@ -401,7 +387,7 @@ bool GameInterface::DrawSpecialScreen(const DVector2& origin, int tilenum)
|
|||
if (tilenum == 2504)
|
||||
{
|
||||
Menu_DrawBackground(origin);
|
||||
DrawMenuCaption(origin, GStrings("MNU_CREDITS"));
|
||||
//DrawMenuCaption(origin, GStrings("MNU_CREDITS"));
|
||||
m = int(origin.X * 65536) + (20 << 16);
|
||||
l = int(origin.Y * 65536) + (33 << 16);
|
||||
|
||||
|
@ -462,7 +448,7 @@ bool GameInterface::DrawSpecialScreen(const DVector2& origin, int tilenum)
|
|||
else if (tilenum == 2505)
|
||||
{
|
||||
Menu_DrawBackground(origin);
|
||||
DrawMenuCaption(origin, GStrings("MNU_CREDITS"));
|
||||
//DrawMenuCaption(origin, GStrings("MNU_CREDITS"));
|
||||
m = int(origin.X * 65536) + (20 << 16);
|
||||
l = int(origin.Y * 65536) + (33 << 16);
|
||||
|
||||
|
@ -505,7 +491,7 @@ bool GameInterface::DrawSpecialScreen(const DVector2& origin, int tilenum)
|
|||
else if (tilenum == 2506)
|
||||
{
|
||||
Menu_DrawBackground(origin);
|
||||
DrawMenuCaption(origin, GStrings("MNU_CREDITS"));
|
||||
//DrawMenuCaption(origin, GStrings("MNU_CREDITS"));
|
||||
mgametextcenter(int(origin.X * 65536), int(origin.Y * 65536) + (50 << 16), "Duke Nukem 3D is a trademark of");
|
||||
mgametextcenter(int(origin.X * 65536), int(origin.Y * 65536) + (59 << 16), "3D Realms Entertainment");
|
||||
mgametextcenter(int(origin.X * 65536), int(origin.Y * 65536) + (77 << 16), "Duke Nukem 3D");
|
||||
|
|
|
@ -45,7 +45,6 @@ struct GameInterface : public ::GameInterface
|
|||
FSavegameInfo GetSaveSig() override;
|
||||
void DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool bg) override;
|
||||
double SmallFontScale() override { return isRR() ? 0.5 : 1.; }
|
||||
void DrawMenuCaption(const DVector2& origin, const char* text) override;
|
||||
void SerializeGameState(FSerializer& arc) override;
|
||||
void QuitToTitle() override;
|
||||
bool DrawSpecialScreen(const DVector2& origin, int tilenum) override;
|
||||
|
|
|
@ -247,12 +247,6 @@ FSavegameInfo GameInterface::GetSaveSig()
|
|||
return { SAVESIG_SW, MINSAVEVER_SW, SAVEVER_SW };
|
||||
}
|
||||
|
||||
void GameInterface::DrawMenuCaption(const DVector2& origin, const char* text)
|
||||
{
|
||||
DrawTexture(twod, tileGetTexture(2427), 10, 2, DTA_FullscreenScale, FSMode_Fit320x200Top, DTA_TopLeft, true, DTA_Color, 0xfff0f0f0, TAG_DONE);
|
||||
DrawText(twod, BigFont, CR_UNDEFINED, 160 - BigFont->StringWidth(text) * 0.5, 5, text, DTA_FullscreenScale, FSMode_Fit320x200Top, TAG_DONE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
END_SW_NS
|
||||
|
|
|
@ -2193,8 +2193,7 @@ struct GameInterface : ::GameInterface
|
|||
bool CanSave() override;
|
||||
bool StartGame(FNewGameStartup& gs) override;
|
||||
FSavegameInfo GetSaveSig() override;
|
||||
void DrawMenuCaption(const DVector2& origin, const char* text) override;
|
||||
bool LoadGame(FSaveGameNode* sv) override;
|
||||
bool LoadGame(FSaveGameNode* sv) override;
|
||||
bool SaveGame(FSaveGameNode* sv) override;
|
||||
void SetAmbience(bool on) override { if (on) StartAmbientSound(); else StopAmbientSound(); }
|
||||
FString GetCoordString() override;
|
||||
|
|
|
@ -20,3 +20,5 @@ version "4.3"
|
|||
#include "zscript/ui/menu/textentermenu.zs"
|
||||
#include "zscript/ui/menu/menucustomize.zs"
|
||||
|
||||
#include "zscript/games/blood/ui/menu.zs"
|
||||
|
||||
|
|
|
@ -482,6 +482,7 @@ struct Font native
|
|||
native static Font FindFont(Name fontname);
|
||||
native static Font GetFont(Name fontname);
|
||||
native BrokenLines BreakLines(String text, int maxlen);
|
||||
native int GetGlyphHeight(int code);
|
||||
}
|
||||
|
||||
struct Console native
|
||||
|
|
24
wadsrc/static/zscript/games/blood/ui/menu.zs
Normal file
24
wadsrc/static/zscript/games/blood/ui/menu.zs
Normal file
|
@ -0,0 +1,24 @@
|
|||
|
||||
class MenuCustomizerBlood : MenuCustomize
|
||||
{
|
||||
override int DrawCaption(String title, Font fnt, int y, bool drawit)
|
||||
{
|
||||
let font = generic_ui? NewConsoleFont : BigFont; // this ignores the passed font intentionally.
|
||||
let texid = tileFiles.GetTexture(2038, true);
|
||||
let texsize = TexMan.GetScaledSize(texid);
|
||||
let fonth = fnt.GetGlyphHeight("A");
|
||||
if (drawit)
|
||||
{
|
||||
int width = font.StringWidth(title);
|
||||
if (texid.isValid())
|
||||
{
|
||||
double scalex = 1.; // Expand the box if the text is longer
|
||||
if (texsize.X - 10 < width) scalex = texsize.X / (boxwidth - 10);
|
||||
screen.DrawTexture(texid, false, 160, 20, DTA_FullscreenScale, FSMode_Fit320x200Top, DTA_CenterOffsetRel, true, DTA_ScaleX, scalex);
|
||||
}
|
||||
screen.DrawText(fnt, Font.CR_UNDEFINED, 160 - width / 2, 20 - fonth / 2, text, DTA_FullscreenScale, FSMode_Fit320x200Top);
|
||||
}
|
||||
int h = texid.isValid()? texsize.Y : fonth;
|
||||
return y + h * screen.GetHeight() * CleanYfac_1 / 200; // option menus use Clean?fac_1 so we have to convert to that screen space.
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue