Skip to content

Commit

Permalink
Worldmap user message and test UI.
Browse files Browse the repository at this point in the history
Instead of using VGUI v1, it's better to rewrite the UI to VGUI v2 that Source uses, since v1 cannot resize images.
  • Loading branch information
jonnyboy0719 committed Dec 10, 2023
1 parent f58d1c0 commit 7966f1e
Show file tree
Hide file tree
Showing 17 changed files with 263 additions and 6 deletions.
107 changes: 107 additions & 0 deletions cl_dll/czero/vgui_worldmap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@

#include "VGUI_Font.h"
#include "VGUI_TextImage.h"

#include <VGUI_StackLayout.h>

#include "hud.h"
#include "cl_util.h"
#include "camera.h"
#include "kbutton.h"
#include "const.h"
#include "vgui_TeamFortressViewport.h"
#include "vgui_int.h"
#include "vgui_worldmap.h"
#include "vgui_loadtga.h"

using namespace vgui;

#define MOTD_TITLE_X XRES(16)
#define MOTD_TITLE_Y YRES(16)

#define MOTD_WINDOW_X XRES(112)
#define MOTD_WINDOW_Y YRES(80)
#define MOTD_WINDOW_SIZE_X XRES(424)
#define MOTD_WINDOW_SIZE_Y YRES(312)

static CImageLabel *_background = NULL;
extern bool g_iVisibleMouse;

//==============================================================================
char* GetTGAWorldMap( const char* pszName )
{
static char gd[256];
sprintf( gd, "%s/gfx/vgui/worldmap/%s.tga", gEngfuncs.pfnGetGameDirectory(), pszName );
gEngfuncs.Con_Printf("----: GetTGAWorldMap :----\n");
gEngfuncs.Con_Printf("TGA: %s\n", gd);
return gd;
}

//==============================================================================
BitmapTGAWorldMap* LoadWorldMapForRes( const char* pImageName, int wide, int tall )
{
BitmapTGAWorldMap *pWorldTGA = vgui_LoadWorldMapTGA( GetTGAWorldMap( pImageName ) );
if ( pWorldTGA )
pWorldTGA->SetMapSzie( wide, tall );
return pWorldTGA;
}

//==============================================================================
UIWorldMap::UIWorldMap(int iTrans, bool iRemoveMe, int x, int y, int wide, int tall) : CMenuPanel(iTrans, iRemoveMe, x, y, wide, tall)
{
_worldmap1 = LoadWorldMapForRes( "worldmap", wide, tall );
_worldmap2 = LoadWorldMapForRes( "worldmap2", wide, tall );

// Create the Health Label
_background = new CImageLabel( _worldmap1, 0, 0, ScreenWidth, ScreenHeight );
_background->setParent( this );
_background->setSize( ScreenWidth, ScreenHeight );

// BELOW THIS IS JUST DEBUG TEST
// Get the scheme used for the Titles
CSchemeManager* pSchemes = gViewPort->GetSchemeManager();

// schemes
SchemeHandle_t hTitleScheme = pSchemes->getSchemeHandle( "Title Font" );

// color schemes
int r, g, b, a;

// Create the title
Label* pLabel = new Label( "", MOTD_TITLE_X, MOTD_TITLE_Y );
pLabel->setParent(this);
pLabel->setFont(pSchemes->getFont(hTitleScheme));
pLabel->setFont(Scheme::sf_primary1);

pSchemes->getFgColor(hTitleScheme, r, g, b, a);
pLabel->setFgColor(r, g, b, a);
pLabel->setFgColor(Scheme::sc_primary1);
pSchemes->getBgColor(hTitleScheme, r, g, b, a);
pLabel->setBgColor(r, g, b, a);
pLabel->setContentAlignment(vgui::Label::a_west);
pLabel->setText("WorldMap: POTATO LAND");

CommandButton* pButton = new CommandButton(CHudTextMessage::BufferedLocaliseTextString("#Menu_OK"), XRES(16), tall - YRES(16) - BUTTON_SIZE_Y, CMENU_SIZE_X, BUTTON_SIZE_Y);
pButton->addActionSignal(new CMenuHandler_TextWindow(HIDE_TEXTWINDOW));
pButton->setParent(this);
}


//==============================================================================
void UIWorldMap::Initialize()
{
gEngfuncs.Con_Printf("----: UIWorldMap >> Initialize :----\n");
}


//==============================================================================
void UIWorldMap::paintBackground()
{
CMenuPanel::paintBackground();

int wide, tall;
getParent()->getSize( wide, tall );
setSize( wide, tall );

_background->setSize( wide, tall );
}
23 changes: 23 additions & 0 deletions cl_dll/czero/vgui_worldmap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

#pragma once

#include <VGUI_Panel.h>
#include <VGUI_Label.h>
#include <VGUI_Button.h>
#include <VGUI_BitmapTGA.h>

class CMenuPanel;

//==============================================================================
class UIWorldMap : public CMenuPanel
{
private:
vgui::BitmapTGA *_worldmap1;
vgui::BitmapTGA *_worldmap2;

public:
UIWorldMap(int iTrans, bool iRemoveMe, int x, int y, int wide, int tall);
void Initialize();

virtual void paintBackground();
};
8 changes: 8 additions & 0 deletions cl_dll/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,13 @@ int __MsgFunc_MOTD(const char* pszName, int iSize, void* pbuf)
return 0;
}

int __MsgFunc_WorldMap(const char* pszName, int iSize, void* pbuf)
{
if (gViewPort)
return static_cast<int>(gViewPort->MsgFunc_WorldMap(pszName, iSize, pbuf));
return 0;
}

int __MsgFunc_BuildSt(const char* pszName, int iSize, void* pbuf)
{
if (gViewPort)
Expand Down Expand Up @@ -356,6 +363,7 @@ void CHud::Init()
HOOK_MESSAGE(VGUIMenu);

HOOK_MESSAGE(ScritSeq);
HOOK_MESSAGE(WorldMap);

CVAR_CREATE("hud_classautokill", "1", FCVAR_ARCHIVE | FCVAR_USERINFO); // controls whether or not to suicide immediately on TF class switch
CVAR_CREATE("hud_takesshots", "0", FCVAR_ARCHIVE); // controls whether or not to automatically take screenshots at the end of a round
Expand Down
14 changes: 14 additions & 0 deletions cl_dll/vgui_CustomObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,20 @@ bool ClassButton::IsNotValid()

//===========================================================
// Button with Class image beneath it
CImageLabel::CImageLabel(BitmapTGA* pImage, int x, int y) : Label("", x, y)
{
setContentFitted(true);
m_pTGA = pImage;
setImage(m_pTGA);
}

CImageLabel::CImageLabel(BitmapTGA* pImage, int x, int y, int wide, int tall) : Label("", x, y, wide, tall)
{
setContentFitted(true);
m_pTGA = pImage;
setImage(m_pTGA);
}

CImageLabel::CImageLabel(const char* pImageName, int x, int y) : Label("", x, y)
{
setContentFitted(true);
Expand Down
35 changes: 33 additions & 2 deletions cl_dll/vgui_TeamFortressViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "vgui_TeamFortressViewport.h"
#include "vgui_ScorePanel.h"
#include "vgui_SpectatorPanel.h"
#include "czero/vgui_worldmap.h"

#include "shake.h"
#include "screenfade.h"
Expand Down Expand Up @@ -516,6 +517,7 @@ TeamFortressViewport::TeamFortressViewport(int x, int y, int wide, int tall) : P
m_iInitialized = false;
m_pTeamMenu = NULL;
m_pClassMenu = NULL;
m_pWorldMap = NULL;
m_pScoreBoard = NULL;
m_pSpectatorPanel = NULL;
m_pCurrentMenu = NULL;
Expand Down Expand Up @@ -578,6 +580,7 @@ TeamFortressViewport::TeamFortressViewport(int x, int y, int wide, int tall) : P
CreateClassMenu();
CreateSpectatorMenu();
CreateScoreBoard();
CreateWorldMap();
// Init command menus
m_iNumMenus = 0;
m_iCurrentTeamNumber = m_iUser1 = m_iUser2 = m_iUser3 = 0;
Expand Down Expand Up @@ -615,6 +618,10 @@ void TeamFortressViewport::Initialize()
{
m_pClassMenu->Initialize();
}
if (m_pWorldMap)
{
m_pWorldMap->Initialize();
}
if (m_pScoreBoard)
{
m_pScoreBoard->Initialize();
Expand Down Expand Up @@ -1496,6 +1503,9 @@ void TeamFortressViewport::ShowVGUIMenu(int iMenu)
case MENU_CLASS:
pNewMenu = ShowClassMenu();
break;
case MENU_WORLDMAP:
pNewMenu = ShowWorldMap();
break;

default:
break;
Expand Down Expand Up @@ -1567,7 +1577,7 @@ bool TeamFortressViewport::AllowedToPrintText()
if (m_pCurrentMenu && g_iPlayerClass == 0)
{
int iId = m_pCurrentMenu->GetMenuID();
if (iId == MENU_TEAM || iId == MENU_CLASS || iId == MENU_INTRO || iId == MENU_CLASSHELP)
if (iId == MENU_TEAM || iId == MENU_CLASS || iId == MENU_INTRO || iId == MENU_WORLDMAP || iId == MENU_CLASSHELP)
return false;
}

Expand Down Expand Up @@ -1632,6 +1642,20 @@ void TeamFortressViewport::CreateSpectatorMenu()
m_pSpectatorPanel->Initialize();
}

void TeamFortressViewport::CreateWorldMap(void)
{
// Create the panel
m_pWorldMap = new UIWorldMap(255, false, 0, 0, ScreenWidth, ScreenHeight);
m_pWorldMap->setParent(this);
m_pWorldMap->setVisible(false);
}

CMenuPanel* TeamFortressViewport::ShowWorldMap(void)
{
m_pWorldMap->setVisible(true);
return m_pWorldMap;
}

//======================================================================================
// UPDATE HUD SECTIONS
//======================================================================================
Expand All @@ -1650,7 +1674,7 @@ void TeamFortressViewport::UpdateOnPlayerInfo()
void TeamFortressViewport::UpdateCursorState()
{
// Need cursor if any VGUI window is up
if (m_pSpectatorPanel->m_menuVisible || m_pCurrentMenu || m_pTeamMenu->isVisible() || GetClientVoiceMgr()->IsInSquelchMode())
if (m_pSpectatorPanel->m_menuVisible || m_pCurrentMenu || m_pWorldMap->isVisible() || m_pTeamMenu->isVisible() || GetClientVoiceMgr()->IsInSquelchMode())
{
g_iVisibleMouse = true;
App::getInstance()->setCursorOveride(App::getInstance()->getScheme()->getCursor(Scheme::scu_arrow));
Expand Down Expand Up @@ -2144,6 +2168,13 @@ bool TeamFortressViewport::MsgFunc_ResetFade(const char* pszName, int iSize, voi
return true;
}

bool TeamFortressViewport::MsgFunc_WorldMap(const char* pszName, int iSize, void* pbuf)
{
// We don't really care about our buffer data, just show the worldmap
ShowVGUIMenu( MENU_WORLDMAP );
return true;
}

// used to fade a player's screen out/in when they're spectating someone who is teleported
bool TeamFortressViewport::MsgFunc_SpecFade(const char* pszName, int iSize, void* pbuf)
{
Expand Down
15 changes: 13 additions & 2 deletions cl_dll/vgui_TeamFortressViewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#define MENU_CLASSHELP2 7
#define MENU_REPEATHELP 8
#define MENU_SPECHELP 9
#define MENU_WORLDMAP 10
using namespace vgui;

class Cursor;
Expand All @@ -51,6 +52,7 @@ class DragNDropPanel;
class CTransparentPanel;
class CClassMenuPanel;
class CTeamMenuPanel;
class UIWorldMap;
class TeamFortressViewport;

char* GetVGUITGAName(const char *pszName);
Expand Down Expand Up @@ -118,6 +120,8 @@ class CImageLabel : public Label

public:
void LoadImage(const char * pImageName);
CImageLabel( BitmapTGA *pImage,int x,int y );
CImageLabel( BitmapTGA *pImage,int x,int y,int wide,int tall );
CImageLabel( const char* pImageName,int x,int y );
CImageLabel( const char* pImageName,int x,int y,int wide,int tall );

Expand Down Expand Up @@ -507,6 +511,10 @@ class TeamFortressViewport : public Panel
void CreateClassMenu( void );
CMenuPanel* ShowClassMenu( void );
void CreateSpectatorMenu( void );

// CZERO
void CreateWorldMap( void );
CMenuPanel* ShowWorldMap( void );

// Scheme handler
CSchemeManager m_SchemeManager;
Expand Down Expand Up @@ -605,8 +613,10 @@ class TeamFortressViewport : public Panel
bool MsgFunc_TeamInfo( const char *pszName, int iSize, void *pbuf );
bool MsgFunc_Spectator( const char *pszName, int iSize, void *pbuf );
bool MsgFunc_AllowSpec( const char *pszName, int iSize, void *pbuf );
bool MsgFunc_SpecFade( const char *pszName, int iSize, void *pbuf );
bool MsgFunc_ResetFade( const char *pszName, int iSize, void *pbuf );
bool MsgFunc_SpecFade( const char *pszName, int iSize, void *pbuf );
bool MsgFunc_ResetFade( const char *pszName, int iSize, void *pbuf );
bool MsgFunc_WorldMap(const char *pszName, int iSize, void *pbuf );


// Input
bool SlotInput( int iSlot );
Expand All @@ -627,6 +637,7 @@ class TeamFortressViewport : public Panel
int m_SpectatorCameraMenu;
int m_PlayerMenu; // a list of current player
CClassMenuPanel *m_pClassMenu;
UIWorldMap *m_pWorldMap;
ScorePanel *m_pScoreBoard;
SpectatorPanel * m_pSpectatorPanel;
char m_szServerName[ MAX_SERVERNAME_LENGTH ];
Expand Down
1 change: 1 addition & 0 deletions dlls/UserMessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ void LinkUserMessages()
gmsgObjective = REG_USER_MSG("OBJ", -1);

gmsgRainData = REG_USER_MSG("RainData", 16);
gmsgWorldMap = REG_USER_MSG("WorldMap", 0);
}
1 change: 1 addition & 0 deletions dlls/UserMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ inline int gmsgFog = 0;
inline int gmsgScriptedSequence = 0;
inline int gmsgObjective = 0;
inline int gmsgRainData = 0;
inline int gmsgWorldMap = 0;

void LinkUserMessages();
27 changes: 27 additions & 0 deletions dlls/czeror/item_worldmap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "triggers.h"
#include "player.h"
#include "UserMessages.h"

class CItemWorldMap : public CBaseTrigger
{
public:
void Spawn() override;
void EXPORT OnUse(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value);
};
LINK_ENTITY_TO_CLASS( item_worldmap, CItemWorldMap );

void CItemWorldMap::OnUse( CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value )
{
MESSAGE_BEGIN( MSG_ALL, gmsgWorldMap );
MESSAGE_END();
}

void CItemWorldMap::Spawn()
{
InitTrigger();
SetUse( &CItemWorldMap::OnUse );
}
2 changes: 1 addition & 1 deletion fgd/halflife-csz.fgd
Original file line number Diff line number Diff line change
Expand Up @@ -3196,7 +3196,7 @@
[
]

@SolidClass base(Target) = func_model_brush : "Model brush"[]
@SolidClass base(Target) = item_worldmap : "World Map"[]

@SolidClass base(Target) = trigger_ammoresupply : "Ammo Resupply"
[
Expand Down
Binary file added game_build/mapsrc/cz_worldmap.jmf
Binary file not shown.
Loading

0 comments on commit 7966f1e

Please sign in to comment.