raze/source/games/blood/src/d_menu.cpp

196 lines
4.8 KiB
C++
Raw Normal View History

//-------------------------------------------------------------------------
/*
Copyright (C) 2010-2019 EDuke32 developers and contributors
Copyright (C) 2019 Nuke.YKT
Copyright (C) 2020 Christoph Oelckers
This file is part of Raze.
NBlood is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//-------------------------------------------------------------------------
#include "ns.h" // Must come before everything else!
#include "build.h"
2020-07-31 19:05:09 +00:00
#include "c_bind.h"
#include "razemenu.h"
2020-07-31 19:05:09 +00:00
#include "gamestate.h"
#include "v_video.h"
#include "v_draw.h"
#include "vm.h"
#include "blood.h"
bool ShowOptionMenu();
BEGIN_BLD_NS
class CGameMenuItemQAV
{
public:
QAV* data;
int duration;
int lastTick;
bool bWideScreen;
bool bClearBackground;
CGameMenuItemQAV(int, int, const char*, bool widescreen = false, bool clearbackground = false);
void Draw(void);
};
CGameMenuItemQAV::CGameMenuItemQAV(int a3, int a4, const char* name, bool widescreen, bool clearbackground)
{
bWideScreen = widescreen;
bClearBackground = clearbackground;
if (name)
{
data = getQAV(fileSystem.GetResourceId(fileSystem.FindFile(name)));
if (data)
{
data->x = a3;
data->y = a4;
duration = data->duration;
lastTick = I_GetTime(data->ticrate);
}
}
}
void CGameMenuItemQAV::Draw(void)
{
if (bClearBackground)
twod->ClearScreen();
if (data)
{
qavProcessTicker(data, &duration, &lastTick);
if (duration <= 0 || duration > data->duration)
{
duration = data->duration;
}
auto currentDuration = data->duration - duration;
auto smoothratio = !cl_interpolate || cl_capfps? MaxSmoothRatio : I_GetTimeFrac(data->ticrate) * MaxSmoothRatio;
data->Play(currentDuration - data->ticksPerFrame, currentDuration, -1, NULL);
2020-08-14 19:12:32 +00:00
if (bWideScreen)
{
int xdim43 = scale(ydim, 4, 3);
int nCount = (twod->GetWidth() + xdim43 - 1) / xdim43;
int backX = data->x;
for (int i = 0; i < nCount; i++)
{
data->Draw(currentDuration, 10 + kQavOrientationLeft, 0, 0, false, smoothratio);
data->x += 320;
}
data->x = backX;
}
else
data->Draw(currentDuration, 10, 0, 0, false, smoothratio);
}
}
static std::unique_ptr<CGameMenuItemQAV> itemBloodQAV; // This must be global to ensure that the animation remains consistent across menus.
void UpdateNetworkMenus(void)
{
// For now disable the network menu item as it is not functional.
for (auto name : { NAME_Mainmenu, NAME_IngameMenu })
{
DMenuDescriptor** desc = MenuDescriptors.CheckKey(name);
if (desc != NULL && (*desc)->IsKindOf(RUNTIME_CLASS(DListMenuDescriptor)))
2019-12-01 21:54:52 +00:00
{
DListMenuDescriptor* ld = static_cast<DListMenuDescriptor*>(*desc);
2019-12-01 21:54:52 +00:00
for (auto& li : ld->mItems)
{
if (li->mAction == NAME_MultiMenu)
2019-12-01 21:54:52 +00:00
{
2020-10-06 22:50:26 +00:00
li->mEnabled = -1;
2019-12-01 21:54:52 +00:00
}
}
}
}
}
//----------------------------------------------------------------------------
//
// Menu related game interface functions
//
//----------------------------------------------------------------------------
void GameInterface::MenuOpened()
{
itemBloodQAV.reset(new CGameMenuItemQAV(160, 100, "BDRIP.QAV", true));
}
void GameInterface::MenuClosed()
{
itemBloodQAV.reset();
}
bool GameInterface::CanSave()
{
return (gamestate == GS_LEVEL && gPlayer[myconnectindex].pXSprite->health != 0);
}
FSavegameInfo GameInterface::GetSaveSig()
{
return { SAVESIG_BLD, MINSAVEVER_BLD, SAVEVER_BLD };
}
END_BLD_NS
using namespace Blood;
2020-10-08 22:50:21 +00:00
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
DEFINE_ACTION_FUNCTION(DListMenuItemBloodDripDrawer, Draw)
{
// For narrow screens this would be mispositioned so skip drawing it there.
2021-01-18 11:25:04 +00:00
double ratio = ActiveRatio(screen->GetWidth(), screen->GetHeight());
if (ratio > 1.32) itemBloodQAV->Draw();
return 0;
}
2020-10-08 22:50:21 +00:00
DEFINE_ACTION_FUNCTION(_ImageScrollerPageQavDrawer, LoadQav)
{
PARAM_PROLOGUE;
PARAM_STRING(str);
auto qav = new CGameMenuItemQAV(160, 100, str, false, true);
ACTION_RETURN_POINTER(qav);
}
DEFINE_ACTION_FUNCTION(_ImageScrollerPageQavDrawer, DestroyQav)
{
PARAM_PROLOGUE;
PARAM_POINTER(qav, CGameMenuItemQAV);
if (qav) delete qav;
return 0;
}
DEFINE_ACTION_FUNCTION(_ImageScrollerPageQavDrawer, DrawQav)
{
PARAM_PROLOGUE;
PARAM_POINTER(qav, CGameMenuItemQAV);
qav->Draw();
return 0;
}