2020-10-28 15:56:00 +00:00
|
|
|
/*
|
|
|
|
** shared_sbar.cpp
|
|
|
|
** Base status bar implementation
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 1998-2006 Randy Heit
|
|
|
|
** Copyright 2017 Christoph Oelckers
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "build.h"
|
2021-10-30 08:51:03 +00:00
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
#include "statusbar.h"
|
|
|
|
#include "c_cvars.h"
|
|
|
|
#include "c_dispatch.h"
|
|
|
|
#include "c_console.h"
|
|
|
|
#include "v_video.h"
|
|
|
|
#include "filesystem.h"
|
|
|
|
#include "s_soundinternal.h"
|
|
|
|
#include "serializer.h"
|
|
|
|
#include "serialize_obj.h"
|
|
|
|
#include "cmdlib.h"
|
|
|
|
#include "vm.h"
|
|
|
|
#include "gstrings.h"
|
|
|
|
#include "utf8.h"
|
|
|
|
#include "texturemanager.h"
|
|
|
|
#include "cmdlib.h"
|
|
|
|
#include "v_draw.h"
|
|
|
|
#include "v_font.h"
|
|
|
|
#include "v_draw.h"
|
|
|
|
#include "gamecvars.h"
|
|
|
|
#include "m_fixed.h"
|
|
|
|
#include "gamecontrol.h"
|
|
|
|
#include "gamestruct.h"
|
|
|
|
#include "razemenu.h"
|
|
|
|
#include "mapinfo.h"
|
2021-05-31 09:51:02 +00:00
|
|
|
#include "razefont.h"
|
2022-08-04 21:47:01 +00:00
|
|
|
#include "gamefuncs.h"
|
2023-10-01 09:59:35 +00:00
|
|
|
#include "statistics.h"
|
2020-10-28 15:56:00 +00:00
|
|
|
|
|
|
|
#include "../version.h"
|
|
|
|
|
|
|
|
EXTERN_CVAR (Bool, am_showmonsters)
|
|
|
|
EXTERN_CVAR (Bool, am_showsecrets)
|
|
|
|
EXTERN_CVAR (Bool, am_showtime)
|
|
|
|
EXTERN_CVAR (Bool, am_showtotaltime)
|
|
|
|
EXTERN_CVAR (Bool, noisedebug)
|
|
|
|
EXTERN_CVAR(Bool, vid_fps)
|
|
|
|
EXTERN_CVAR(Bool, inter_subtitles)
|
|
|
|
|
|
|
|
extern int setblocks;
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
2021-05-16 08:35:33 +00:00
|
|
|
//
|
2020-10-28 15:56:00 +00:00
|
|
|
// ST_Clear
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void ST_Clear()
|
|
|
|
{
|
2020-10-28 16:16:42 +00:00
|
|
|
/*
|
2020-10-28 15:56:00 +00:00
|
|
|
if (StatusBar != NULL)
|
|
|
|
{
|
|
|
|
delete StatusBar;
|
|
|
|
StatusBar = NULL;
|
|
|
|
}
|
2020-10-28 16:16:42 +00:00
|
|
|
*/
|
2020-10-28 15:56:00 +00:00
|
|
|
}
|
|
|
|
|
2022-12-09 14:43:10 +00:00
|
|
|
ReservedSpace GetReservedScreenSpace(int viewsize)
|
|
|
|
{
|
|
|
|
ReservedSpace res{};
|
2024-01-05 16:08:05 +00:00
|
|
|
if (StatusBar == nullptr) return res;
|
2022-12-09 14:43:10 +00:00
|
|
|
IFVIRTUALPTRNAME(StatusBar, NAME_RazeStatusBar, GetReservedScreenSpace)
|
|
|
|
{
|
|
|
|
VMReturn ret[2];
|
|
|
|
ret[0].IntAt(&res.top);
|
|
|
|
ret[1].IntAt(&res.statusbar);
|
|
|
|
VMValue params[] = { StatusBar, viewsize };
|
|
|
|
VMCall(func, params, 2, ret, 2);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
void setViewport(int viewSize)
|
|
|
|
{
|
|
|
|
int x0, y0, x1, y1;
|
|
|
|
if (screen == nullptr) return;
|
|
|
|
int xdim = screen->GetWidth();
|
|
|
|
int ydim = screen->GetHeight();
|
|
|
|
if (xdim == 0 || ydim == 0) return;
|
2022-12-09 14:43:10 +00:00
|
|
|
auto reserved = GetReservedScreenSpace(viewSize);
|
2020-10-28 16:16:42 +00:00
|
|
|
reserved.top = xs_CRoundToInt((reserved.top * hud_scalefactor * ydim) / 200);
|
|
|
|
reserved.statusbar = xs_CRoundToInt((reserved.statusbar * hud_scalefactor * ydim) / 200);
|
2020-10-28 15:56:00 +00:00
|
|
|
|
|
|
|
if (viewSize > Hud_Stbar)
|
|
|
|
{
|
|
|
|
x0 = 0;
|
2022-08-04 21:47:01 +00:00
|
|
|
x1 = xdim;
|
2020-10-28 15:56:00 +00:00
|
|
|
y0 = reserved.top;
|
2022-08-04 21:47:01 +00:00
|
|
|
y1 = ydim;
|
2020-10-28 15:56:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x0 = 0;
|
|
|
|
y0 = reserved.top;
|
2022-08-04 21:47:01 +00:00
|
|
|
x1 = xdim;
|
|
|
|
y1 = ydim - reserved.statusbar;
|
2020-10-28 15:56:00 +00:00
|
|
|
|
|
|
|
int height = y1 - y0;
|
|
|
|
int frameheight = (height * (5 - viewSize) / 20);
|
2022-08-04 21:47:01 +00:00
|
|
|
int framewidth = Scale(frameheight, xdim, y1);
|
2020-10-28 15:56:00 +00:00
|
|
|
x0 += framewidth;
|
|
|
|
x1 -= framewidth;
|
|
|
|
y0 += frameheight;
|
|
|
|
y1 -= frameheight;
|
|
|
|
}
|
2022-08-04 21:47:01 +00:00
|
|
|
viewport3d = { x0, y0, x1 - x0, y1 - y0 };
|
2020-10-28 15:56:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
int levelTextTime;
|
|
|
|
|
|
|
|
void SerializeHud(FSerializer &arc)
|
|
|
|
{
|
|
|
|
if (arc.BeginObject("hud"))
|
|
|
|
{
|
|
|
|
arc("texttimer", levelTextTime)
|
|
|
|
.EndObject();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void setLevelStarted(MapRecord *mi)
|
|
|
|
{
|
|
|
|
levelTextTime = 85;
|
|
|
|
Printf(PRINT_NONOTIFY, TEXTCOLOR_GOLD "%s: %s\n", mi->LabelName(), mi->DisplayName());
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawMapTitle()
|
|
|
|
{
|
2021-11-14 11:30:18 +00:00
|
|
|
if (!hud_showmapname || levelTextTime <= 0 || M_Active())
|
|
|
|
return;
|
2021-12-30 09:30:21 +00:00
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
double alpha = levelTextTime > 16? 1.0 : levelTextTime / 16.;
|
2021-11-14 11:30:18 +00:00
|
|
|
if (alpha > 0)
|
|
|
|
{
|
2021-07-11 02:38:42 +00:00
|
|
|
double scale = isRR()? 0.4 : isSWALL()? 0.7 : 1.0;
|
2020-10-28 15:56:00 +00:00
|
|
|
auto text = currentLevel->DisplayName();
|
2021-05-31 09:51:02 +00:00
|
|
|
auto myfont = PickBigFont(text);
|
|
|
|
double x = 160 - myfont->StringWidth(text) * scale / 2.;
|
|
|
|
double y = isBlood() ? 50 : 100 - myfont->GetHeight()/2.;
|
2020-10-28 15:56:00 +00:00
|
|
|
bool shadow = true;
|
|
|
|
|
|
|
|
if (shadow)
|
|
|
|
{
|
2021-05-31 09:51:02 +00:00
|
|
|
DrawText(twod, myfont, CR_UNTRANSLATED, x+1, y+1, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Color, 0xff000000, DTA_Alpha, alpha / 2., DTA_ScaleX, scale, DTA_ScaleY, scale, TAG_DONE);
|
2020-10-28 15:56:00 +00:00
|
|
|
}
|
2021-05-31 09:51:02 +00:00
|
|
|
DrawText(twod, myfont, CR_UNTRANSLATED, x, y, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Alpha, alpha, DTA_ScaleX, scale, DTA_ScaleY, scale, TAG_DONE);
|
2021-11-14 11:30:18 +00:00
|
|
|
}
|
2020-10-28 15:56:00 +00:00
|
|
|
}
|
|
|
|
|
2022-10-15 21:13:47 +00:00
|
|
|
void DrawAltHUD(SummaryInfo* info);
|
|
|
|
|
2021-05-12 19:46:49 +00:00
|
|
|
void UpdateStatusBar(SummaryInfo* info)
|
|
|
|
{
|
2023-10-01 09:59:35 +00:00
|
|
|
info->time = Scale(info->time, 1000, 120); // The statusbar expects milliseconds
|
|
|
|
info->totaltime = STAT_GetTotalTime();
|
|
|
|
|
2022-10-25 14:58:56 +00:00
|
|
|
if (hud_size == Hud_Althud)
|
2022-10-15 21:13:47 +00:00
|
|
|
{
|
|
|
|
DrawAltHUD(info);
|
2023-04-15 07:33:46 +00:00
|
|
|
IFVIRTUALPTRNAME(StatusBar, NAME_RazeStatusBar, AltHUDOverlay)
|
|
|
|
{
|
|
|
|
VMValue params[] = { StatusBar, info };
|
|
|
|
VMCall(func, params, 2, nullptr, 0);
|
|
|
|
}
|
2022-10-15 21:13:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-05-12 19:46:49 +00:00
|
|
|
IFVIRTUALPTRNAME(StatusBar, NAME_RazeStatusBar, UpdateStatusBar)
|
|
|
|
{
|
|
|
|
VMValue params[] = { StatusBar, info };
|
|
|
|
VMCall(func, params, 2, nullptr, 0);
|
|
|
|
}
|
2021-05-13 17:48:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TickStatusBar()
|
|
|
|
{
|
|
|
|
IFVIRTUALPTRNAME(StatusBar, NAME_RazeStatusBar, Tick)
|
|
|
|
{
|
|
|
|
VMValue params[] = { StatusBar };
|
|
|
|
VMCall(func, params, 1, nullptr, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetStatusBar()
|
|
|
|
{
|
|
|
|
IFVIRTUALPTRNAME(StatusBar, NAME_RazeStatusBar, Reset)
|
|
|
|
{
|
|
|
|
VMValue params[] = { StatusBar };
|
|
|
|
VMCall(func, params, 1, nullptr, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitStatusBar()
|
|
|
|
{
|
|
|
|
IFVIRTUALPTRNAME(StatusBar, NAME_RazeStatusBar, Init)
|
|
|
|
{
|
|
|
|
VMValue params[] = { StatusBar };
|
|
|
|
VMCall(func, params, 1, nullptr, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|