mirror of
https://github.com/fortressforever/fortressforever-2013.git
synced 2024-11-10 07:11:45 +00:00
First pass at Lua panels, super basic implementation for now
* Can create new panels from Lua, but pretty much all they can do at the moment is draw a background
This commit is contained in:
parent
4fb1e2bc98
commit
8e52a86fd3
12 changed files with 273 additions and 0 deletions
|
@ -37,6 +37,15 @@ $Project "Client (FF)"
|
|||
}
|
||||
$Folder "Lua"
|
||||
{
|
||||
$Folder "UI"
|
||||
{
|
||||
$file "ff\ui\ff_cl_luaui_basepanel.cpp"
|
||||
$file "ff\ui\ff_cl_luaui_basepanel.h"
|
||||
}
|
||||
$folder "Binding"
|
||||
{
|
||||
$file "ff\ff_cl_luabind_ui.cpp"
|
||||
}
|
||||
$File "ff\ff_cl_scriptman_ui.cpp"
|
||||
$File "ff\ff_cl_scriptman_ui.h"
|
||||
}
|
||||
|
|
75
mp/src/game/client/ff/ff_cl_luabind_ui.cpp
Normal file
75
mp/src/game/client/ff/ff_cl_luabind_ui.cpp
Normal file
|
@ -0,0 +1,75 @@
|
|||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// includes
|
||||
#include "cbase.h"
|
||||
|
||||
#include "ff_sh_luabind.h"
|
||||
|
||||
// dexter note 10/29/2013 these are definitely still needed for lua/luabind
|
||||
#undef MINMAX_H
|
||||
#undef min
|
||||
#undef max
|
||||
//
|
||||
// luabind
|
||||
#include "lua.hpp"
|
||||
#include "luabind/luabind.hpp"
|
||||
//#include "luabind/object.hpp"
|
||||
//#include "luabind/iterator_policy.hpp"
|
||||
#include "luabind/out_value_policy.hpp"
|
||||
|
||||
// stuff to be bound
|
||||
#include "ui/ff_cl_luaui_basepanel.h"
|
||||
#include "hud.h"
|
||||
#include "hudelement.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace luabind;
|
||||
|
||||
void RegisterHudElement( CHudElement *pHudElement )
|
||||
{
|
||||
gHUD.AddHudElement( pHudElement );
|
||||
|
||||
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;
|
||||
}
|
||||
*/
|
||||
|
||||
void FF_Lua_InitUI( lua_State *L )
|
||||
{
|
||||
Assert(L);
|
||||
|
||||
module(L)
|
||||
[
|
||||
def( "RegisterHudElement", &RegisterHudElement ),
|
||||
|
||||
class_<CHudElement>("HudElement")
|
||||
.def("ListenForGameEvent", &CHudElement::ListenForGameEvent),
|
||||
|
||||
class_<vgui::Panel>("vguiPanel")
|
||||
.def("IsEnabled", &vgui::Panel::IsEnabled)
|
||||
.def("SetEnabled", &vgui::Panel::SetEnabled)
|
||||
.def("IsVisible", &vgui::Panel::IsVisible)
|
||||
.def("SetVisible", &vgui::Panel::SetVisible)
|
||||
.def("SetPaintEnabled", &vgui::Panel::SetPaintEnabled)
|
||||
.def("SetPaintBackgroundEnabled", &vgui::Panel::SetPaintBackgroundEnabled)
|
||||
.def("SetPaintBackgroundType", &vgui::Panel::SetPaintBackgroundType)
|
||||
.def("GetSize", &vgui::Panel::GetSize, pure_out_value(_2) + pure_out_value(_3)) // _1 is the this pointer
|
||||
.def("SetSize", &vgui::Panel::SetSize)
|
||||
.def("GetPos", &vgui::Panel::GetPos, pure_out_value(_2) + pure_out_value(_3)) // _1 is the this pointer
|
||||
.def("SetPos", &vgui::Panel::SetPos)
|
||||
.def("SetEnabled", &vgui::Panel::SetEnabled),
|
||||
|
||||
class_<CFF_CL_LuaUI_BasePanel, bases<CHudElement, vgui::Panel>>("Panel")
|
||||
.def(constructor<lua_State *, const char *>())
|
||||
];
|
||||
}
|
|
@ -18,6 +18,9 @@
|
|||
//#include "luabind/object.hpp"
|
||||
//#include "luabind/iterator_policy.hpp"
|
||||
|
||||
// binding
|
||||
#include "ff_sh_luabind.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
@ -35,6 +38,12 @@ CFF_CL_ScriptManager_UI::~CFF_CL_ScriptManager_UI()
|
|||
{
|
||||
}
|
||||
|
||||
void CFF_CL_ScriptManager_UI::SetupEnvironmentForFF()
|
||||
{
|
||||
BaseClass::SetupEnvironmentForFF();
|
||||
|
||||
FF_Lua_InitUI( L );
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
void CFF_CL_ScriptManager_UI::Shutdown()
|
||||
|
|
|
@ -17,6 +17,8 @@ protected:
|
|||
virtual const char* GetPackagePathRoot() { return "/ui/"; };
|
||||
|
||||
public:
|
||||
virtual void SetupEnvironmentForFF();
|
||||
|
||||
virtual bool Init();
|
||||
virtual void Shutdown();
|
||||
|
||||
|
|
96
mp/src/game/client/ff/ui/ff_cl_luaui_basepanel.cpp
Normal file
96
mp/src/game/client/ff/ui/ff_cl_luaui_basepanel.cpp
Normal file
|
@ -0,0 +1,96 @@
|
|||
#include "cbase.h"
|
||||
#include "ui/ff_cl_luaui_basepanel.h"
|
||||
|
||||
#include "ff_cl_scriptman_ui.h"
|
||||
|
||||
#include "iclientmode.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"
|
||||
#include "luabind/object.hpp"
|
||||
|
||||
#include "vgui_int.h"
|
||||
|
||||
#include "ff_sh_luautil.h"
|
||||
|
||||
using namespace vgui;
|
||||
using namespace luabind;
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
/// this should only be called from Lua
|
||||
CFF_CL_LuaUI_BasePanel::CFF_CL_LuaUI_BasePanel( lua_State *L, const char *pElementName ) : CHudElement( pElementName ), vgui::Panel(NULL, "HudLuaUIPanel")
|
||||
{
|
||||
Assert( L );
|
||||
|
||||
// the userdata object is on the top of the stack
|
||||
m_LuaObject = object(from_stack(L, 1));
|
||||
|
||||
SetParent(g_pClientMode->GetViewport());
|
||||
SetProportional( true );
|
||||
}
|
||||
|
||||
/// from CHudElement
|
||||
void CFF_CL_LuaUI_BasePanel::Init()
|
||||
{
|
||||
Reset();
|
||||
|
||||
if ( m_LuaObject.is_valid() && luabind::type( m_LuaObject["Init"] ) == LUA_TFUNCTION )
|
||||
{
|
||||
luabind::call_function<void>( m_LuaObject["Init"], this );
|
||||
}
|
||||
}
|
||||
|
||||
/// from CHudElement
|
||||
void CFF_CL_LuaUI_BasePanel::Reset()
|
||||
{
|
||||
if ( m_LuaObject.is_valid() && luabind::type( m_LuaObject["Reset"] ) == LUA_TFUNCTION )
|
||||
{
|
||||
luabind::call_function<void>( m_LuaObject["Reset"], this );
|
||||
}
|
||||
}
|
||||
|
||||
/// from CHudElement
|
||||
void CFF_CL_LuaUI_BasePanel::VidInit()
|
||||
{
|
||||
Reset();
|
||||
|
||||
if ( m_LuaObject.is_valid() && luabind::type( m_LuaObject["VidInit"] ) == LUA_TFUNCTION )
|
||||
{
|
||||
luabind::call_function<void>( m_LuaObject["VidInit"], this );
|
||||
}
|
||||
}
|
||||
|
||||
/// from vgui::Panel
|
||||
void CFF_CL_LuaUI_BasePanel::OnThink()
|
||||
{
|
||||
BaseClass::OnThink();
|
||||
|
||||
if ( m_LuaObject.is_valid() && luabind::type( m_LuaObject["OnThink"] ) == LUA_TFUNCTION )
|
||||
{
|
||||
luabind::call_function<void>( m_LuaObject["OnThink"], this );
|
||||
}
|
||||
}
|
||||
|
||||
/// from vgui::Panel
|
||||
void CFF_CL_LuaUI_BasePanel::Paint()
|
||||
{
|
||||
BaseClass::Paint();
|
||||
|
||||
if ( m_LuaObject.is_valid() && luabind::type( m_LuaObject["Paint"] ) == LUA_TFUNCTION )
|
||||
{
|
||||
luabind::call_function<void>( m_LuaObject["Paint"], this );
|
||||
}
|
||||
}
|
31
mp/src/game/client/ff/ui/ff_cl_luaui_basepanel.h
Normal file
31
mp/src/game/client/ff/ui/ff_cl_luaui_basepanel.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
#ifndef FF_CL_LUAUI_BASEPANEL_H
|
||||
#define FF_CL_LUAUI_BASEPANEL_H
|
||||
|
||||
#include "hudelement.h"
|
||||
#include <vgui_controls/Panel.h>
|
||||
|
||||
#include "luabind/object.hpp"
|
||||
|
||||
class CFF_CL_LuaUI_BasePanel : public CHudElement, public vgui::Panel
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CFF_CL_LuaUI_BasePanel, vgui::Panel );
|
||||
|
||||
public:
|
||||
CFF_CL_LuaUI_BasePanel( lua_State *L, const char *pElementName );
|
||||
// <-- from CHudElement
|
||||
virtual void Init( void );
|
||||
virtual void VidInit( void );
|
||||
virtual void Reset( void );
|
||||
// --> from CHudElement
|
||||
|
||||
// <-- from vgui::Panel
|
||||
virtual void OnThink();
|
||||
virtual void Paint();
|
||||
// --> from vgui::Panel
|
||||
|
||||
private:
|
||||
luabind::object m_LuaObject;
|
||||
};
|
||||
|
||||
#endif
|
9
mp/src/game/shared/ff/ff_sh_luabind.h
Normal file
9
mp/src/game/shared/ff/ff_sh_luabind.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#pragma once
|
||||
#ifndef FF_SH_LUABIND
|
||||
#define FF_SH_LUABIND
|
||||
|
||||
struct lua_State;
|
||||
|
||||
void FF_Lua_InitUI( lua_State *L );
|
||||
|
||||
#endif
|
|
@ -25,4 +25,34 @@ void LUAUTIL_RemoveKeysFromTable( lua_State *L, const char *pszTableName, const
|
|||
}
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
void LUAUTIL_StackDump (lua_State *L) {
|
||||
int i;
|
||||
int top = lua_gettop(L);
|
||||
for (i = 1; i <= top; i++) { /* repeat for each level */
|
||||
int t = lua_type(L, i);
|
||||
Msg("%d) ", i);
|
||||
switch (t) {
|
||||
|
||||
case LUA_TSTRING: /* strings */
|
||||
Msg("'%s'", lua_tostring(L, i));
|
||||
break;
|
||||
|
||||
case LUA_TBOOLEAN: /* booleans */
|
||||
Msg(lua_toboolean(L, i) ? "true" : "false");
|
||||
break;
|
||||
|
||||
case LUA_TNUMBER: /* numbers */
|
||||
Msg("%g", lua_tonumber(L, i));
|
||||
break;
|
||||
|
||||
default: /* other values */
|
||||
Msg("%s", lua_typename(L, t));
|
||||
break;
|
||||
|
||||
}
|
||||
Msg(" "); /* put a separator */
|
||||
}
|
||||
Msg("\n"); /* end the listing */
|
||||
}
|
|
@ -6,5 +6,6 @@ struct lua_State;
|
|||
|
||||
void LUAUTIL_RemoveKeysFromTable( lua_State *L, const char *pszTableName, const char** ppszKeys );
|
||||
void LUAUTIL_RemoveVarsFromGlobal( lua_State *L, const char** ppszVars );
|
||||
void LUAUTIL_StackDump( lua_State *L );
|
||||
|
||||
#endif
|
|
@ -26,6 +26,9 @@
|
|||
//#include "luabind/object.hpp"
|
||||
//#include "luabind/iterator_policy.hpp"
|
||||
|
||||
// binding
|
||||
#include "ff_sh_luabind.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
//#include "luabind/object.hpp"
|
||||
//#include "luabind/iterator_policy.hpp"
|
||||
|
||||
// binding
|
||||
#include "ff_sh_luabind.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
|
|
@ -15,6 +15,11 @@ $Project
|
|||
$File "$SRCDIR\game\shared\ff\ff_sh_scriptman_game.h"
|
||||
$File "$SRCDIR\game\shared\ff\ff_sh_luautil.cpp"
|
||||
$File "$SRCDIR\game\shared\ff\ff_sh_luautil.h"
|
||||
|
||||
$Folder "Binding"
|
||||
{
|
||||
$File "$SRCDIR\game\shared\ff\ff_sh_luabind.h"
|
||||
}
|
||||
}
|
||||
$Folder "Movement"
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue