mirror of
https://github.com/fortressforever/fortressforever-2013.git
synced 2024-11-10 07:11:45 +00:00
* Added basic support for drawing text in LuaPanels, will probably end up changing how this is done
* Bound C_BaseEntity, C_BasePlayer, CFF_CL_Player and a few member functions (speed/velocity/health getters) to the UI Lua environment
This commit is contained in:
parent
82afcfedc8
commit
065163fe5f
3 changed files with 68 additions and 16 deletions
|
@ -21,28 +21,44 @@
|
|||
#include "ui/ff_cl_luaui_basepanel.h"
|
||||
#include "hud.h"
|
||||
#include "hudelement.h"
|
||||
#include "ff_cl_player.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace luabind;
|
||||
|
||||
void RegisterHudElement( CHudElement *pHudElement )
|
||||
namespace FFLuaLib_UI
|
||||
{
|
||||
gHUD.AddHudElement( pHudElement );
|
||||
|
||||
pHudElement->Init();
|
||||
}
|
||||
void RegisterHudElement( CHudElement *pHudElement )
|
||||
{
|
||||
gHUD.AddHudElement( pHudElement );
|
||||
|
||||
/* Alternate method of creating a Panel, might be needed if Lua starts garbage collecting Panels and we cant adopt them from their constructor
|
||||
object CreatePanel( lua_State *L, const char *szPanelName )
|
||||
{
|
||||
CFF_CL_LuaUI_BasePanel *pPanel = new CFF_CL_LuaUI_BasePanel( szPanelName );
|
||||
object LuaPanel( L, pPanel );
|
||||
pPanel->m_luaobjDefinedFunctions = LuaPanel;
|
||||
return LuaPanel;
|
||||
}
|
||||
*/
|
||||
pHudElement->Init();
|
||||
}
|
||||
|
||||
/* Alternate method of creating a Panel, might be needed if Lua starts garbage collecting Panels and we cant adopt them from their constructor
|
||||
object CreatePanel( lua_State *L, const char *szPanelName )
|
||||
{
|
||||
CFF_CL_LuaUI_BasePanel *pPanel = new CFF_CL_LuaUI_BasePanel( szPanelName );
|
||||
object LuaPanel( L, pPanel );
|
||||
pPanel->m_luaobjDefinedFunctions = LuaPanel;
|
||||
return LuaPanel;
|
||||
}
|
||||
*/
|
||||
|
||||
float GetSpeed( const C_BaseEntity *pEntity )
|
||||
{
|
||||
return pEntity->GetAbsVelocity().Length2D();
|
||||
}
|
||||
|
||||
CFF_CL_Player *GetLocalPlayer()
|
||||
{
|
||||
return CFF_CL_Player::GetLocalFFPlayer();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
void FF_Lua_InitUI( lua_State *L )
|
||||
{
|
||||
|
@ -50,8 +66,10 @@ void FF_Lua_InitUI( lua_State *L )
|
|||
|
||||
module(L)
|
||||
[
|
||||
def( "RegisterHudElement", &RegisterHudElement ),
|
||||
// globals
|
||||
def( "RegisterHudElement", &FFLuaLib_UI::RegisterHudElement ),
|
||||
|
||||
// UI elements
|
||||
class_<CHudElement>("HudElement")
|
||||
.def("ListenForGameEvent", &CHudElement::ListenForGameEvent),
|
||||
|
||||
|
@ -71,5 +89,21 @@ void FF_Lua_InitUI( lua_State *L )
|
|||
|
||||
class_<CFF_CL_LuaUI_BasePanel, bases<CHudElement, vgui::Panel>>("Panel")
|
||||
.def(constructor<lua_State *, const char *>())
|
||||
.def("DrawText", &CFF_CL_LuaUI_BasePanel::DrawText)
|
||||
.def("DrawBox", &CFF_CL_LuaUI_BasePanel::DrawBox),
|
||||
|
||||
// base entity
|
||||
class_<C_BaseEntity>("BaseEntity")
|
||||
.def("GetVelocity", &C_BaseEntity::GetAbsVelocity)
|
||||
.def("GetSpeed", &FFLuaLib_UI::GetSpeed),
|
||||
|
||||
class_<C_BasePlayer, C_BaseEntity>("BasePlayer"),
|
||||
|
||||
class_<CFF_CL_Player, C_BasePlayer>("Player")
|
||||
.def("GetMaxSpeed", &CFF_CL_Player::MaxSpeed)
|
||||
.def("GetHealth", &CFF_CL_Player::GetHealth)
|
||||
.def("GetMaxHealth", &CFF_CL_Player::GetMaxHealth),
|
||||
|
||||
def("LocalPlayer", &FFLuaLib_UI::GetLocalPlayer)
|
||||
];
|
||||
}
|
|
@ -4,17 +4,17 @@
|
|||
#include "ff_cl_scriptman_ui.h"
|
||||
|
||||
#include "iclientmode.h"
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/ILocalize.h>
|
||||
/*
|
||||
#include "hud.h"
|
||||
#include "hud_macros.h"
|
||||
#include "view.h"
|
||||
|
||||
#include <KeyValues.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/ISystem.h>
|
||||
#include <vgui_controls/AnimationController.h>
|
||||
|
||||
#include <vgui/ILocalize.h>
|
||||
*/
|
||||
|
||||
#include "luabind/luabind.hpp"
|
||||
|
@ -93,4 +93,20 @@ void CFF_CL_LuaUI_BasePanel::Paint()
|
|||
{
|
||||
luabind::call_function<void>( m_LuaObject["Paint"], this );
|
||||
}
|
||||
}
|
||||
|
||||
void CFF_CL_LuaUI_BasePanel::DrawText( const char *szText, int xpos, int ypos )
|
||||
{
|
||||
wchar_t wszText[255];
|
||||
g_pVGuiLocalize->ConvertANSIToUnicode( szText, wszText, sizeof(wszText) );
|
||||
|
||||
IScheme *pScheme = scheme()->GetIScheme( GetScheme() );
|
||||
Assert( pScheme );
|
||||
|
||||
HFont font = pScheme->GetFont( "Default", IsProportional() );
|
||||
|
||||
surface()->DrawSetTextFont(font);
|
||||
surface()->DrawSetTextColor(GetFgColor());
|
||||
surface()->DrawSetTextPos(xpos, ypos);
|
||||
surface()->DrawUnicodeString( wszText );
|
||||
}
|
|
@ -23,6 +23,8 @@ public:
|
|||
virtual void OnThink();
|
||||
virtual void Paint();
|
||||
// --> from vgui::Panel
|
||||
|
||||
void DrawText( const char *szText, int xpos, int ypos );
|
||||
|
||||
private:
|
||||
luabind::object m_LuaObject;
|
||||
|
|
Loading…
Reference in a new issue