2015-11-11 07:57:18 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-09-30 02:56:11 +02:00
|
|
|
#include "Entity/Keybind.hpp"
|
2015-11-01 00:31:46 +01:00
|
|
|
#include "Core.hpp"
|
2018-07-29 11:25:44 +02:00
|
|
|
#include "Misc/Tasks.hpp"
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
2015-11-01 00:31:46 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-11-15 20:16:24 +01:00
|
|
|
SQMODE_DECL_TYPENAME(Typename, _SC("SqKeybind"))
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-11-15 20:16:24 +01:00
|
|
|
const Int32 CKeybind::Max = SQMOD_KEYBIND_POOL;
|
2016-02-20 23:25:00 +01:00
|
|
|
|
2016-08-07 00:54:33 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
SQInteger CKeybind::SqGetNull(HSQUIRRELVM vm)
|
|
|
|
{
|
|
|
|
sq_pushobject(vm, Core::Get().GetNullKeybind().GetObject());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
LightObj & CKeybind::GetNull()
|
2016-08-07 00:54:33 +02:00
|
|
|
{
|
|
|
|
return Core::Get().GetNullKeybind();
|
|
|
|
}
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
CKeybind::CKeybind(Int32 id)
|
|
|
|
: m_ID(VALID_ENTITYGETEX(id, SQMOD_KEYBIND_POOL))
|
2016-03-10 04:57:13 +01:00
|
|
|
, m_Tag(ToStrF("%d", id))
|
2015-11-01 00:31:46 +01:00
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
2015-09-30 02:56:11 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
CKeybind::~CKeybind()
|
2015-10-29 21:09:53 +01:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
/* ... */
|
2015-10-29 21:09:53 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
const String & CKeybind::ToString() const
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
return m_Tag;
|
2015-10-29 21:09:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
const String & CKeybind::GetTag() const
|
2015-10-29 21:09:53 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
return m_Tag;
|
2016-02-20 23:25:00 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2019-02-17 16:23:59 +01:00
|
|
|
void CKeybind::SetTag(StackStrF & tag)
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2016-11-16 13:48:28 +01:00
|
|
|
if (tag.mLen > 0)
|
|
|
|
{
|
|
|
|
m_Tag.assign(tag.mPtr, tag.mLen);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_Tag.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2019-02-17 16:23:59 +01:00
|
|
|
CKeybind & CKeybind::ApplyTag(StackStrF & tag)
|
2016-11-16 13:48:28 +01:00
|
|
|
{
|
|
|
|
SetTag(tag);
|
|
|
|
return *this;
|
2016-02-20 23:25:00 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
LightObj & CKeybind::GetData()
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
|
|
|
return m_Data;
|
2016-02-20 23:25:00 +01:00
|
|
|
}
|
2015-10-29 21:09:53 +01:00
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
void CKeybind::SetData(LightObj & data)
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Apply the specified value
|
|
|
|
m_Data = data;
|
2015-10-29 21:09:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
bool CKeybind::Destroy(Int32 header, LightObj & payload)
|
2015-10-29 21:09:53 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
2016-05-22 05:20:38 +02:00
|
|
|
return Core::Get().DelKeybind(m_ID, header, payload);
|
2016-02-20 23:25:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
LightObj & CKeybind::GetEvents() const
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
2017-02-21 20:24:59 +01:00
|
|
|
// Return the associated event table
|
|
|
|
return Core::Get().GetKeybind(m_ID).mEvents;
|
2015-10-29 21:09:53 +01:00
|
|
|
}
|
|
|
|
|
2016-07-26 23:13:50 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
void CKeybind::CustomEvent(Int32 header, LightObj & payload) const
|
2016-07-26 23:13:50 +02:00
|
|
|
{
|
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perfrom the requested action
|
|
|
|
Core::Get().EmitKeybindCustom(m_ID, header, payload);
|
|
|
|
}
|
|
|
|
|
2015-11-01 00:31:46 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
Int32 CKeybind::GetFirst() const
|
2015-11-01 00:31:46 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
2016-05-22 05:20:38 +02:00
|
|
|
return Core::Get().GetKeybind(m_ID).mFirst;
|
2015-11-01 00:31:46 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Int32 CKeybind::GetSecond() const
|
2015-11-01 00:31:46 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
2016-05-22 05:20:38 +02:00
|
|
|
return Core::Get().GetKeybind(m_ID).mSecond;
|
2015-11-01 00:31:46 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Int32 CKeybind::GetThird() const
|
2015-11-01 00:31:46 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
2016-05-22 05:20:38 +02:00
|
|
|
return Core::Get().GetKeybind(m_ID).mThird;
|
2015-11-01 00:31:46 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
bool CKeybind::IsRelease() const
|
2015-11-01 00:31:46 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
2016-05-22 05:20:38 +02:00
|
|
|
return Core::Get().GetKeybind(m_ID).mRelease;
|
2015-11-01 00:31:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
static LightObj & Keybind_CreateEx(Int32 slot, bool release, Int32 primary, Int32 secondary,
|
2016-02-20 23:25:00 +01:00
|
|
|
Int32 alternative)
|
2015-11-01 00:31:46 +01:00
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
return Core::Get().NewKeybind(slot, release, primary, secondary, alternative,
|
2017-02-21 20:24:59 +01:00
|
|
|
SQMOD_CREATE_DEFAULT, NullLightObj());
|
2015-11-01 00:31:46 +01:00
|
|
|
}
|
|
|
|
|
2017-02-21 20:24:59 +01:00
|
|
|
static LightObj & Keybind_CreateEx(Int32 slot, bool release, Int32 primary, Int32 secondary,
|
|
|
|
Int32 alternative, Int32 header, LightObj & payload)
|
2015-11-01 00:31:46 +01:00
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
return Core::Get().NewKeybind(slot, release, primary, secondary, alternative, header, payload);
|
2015-11-01 00:31:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
static LightObj & Keybind_Create(bool release, Int32 primary, Int32 secondary, Int32 alternative)
|
2015-11-01 00:31:46 +01:00
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
return Core::Get().NewKeybind(-1, release, primary, secondary, alternative,
|
2017-02-21 20:24:59 +01:00
|
|
|
SQMOD_CREATE_DEFAULT, NullLightObj());
|
2015-11-01 00:31:46 +01:00
|
|
|
}
|
|
|
|
|
2017-02-21 20:24:59 +01:00
|
|
|
static LightObj & Keybind_Create(bool release, Int32 primary, Int32 secondary, Int32 alternative,
|
|
|
|
Int32 header, LightObj & payload)
|
2015-11-01 00:31:46 +01:00
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
return Core::Get().NewKeybind(-1, release, primary, secondary, alternative, header, payload);
|
2015-11-01 00:31:46 +01:00
|
|
|
}
|
|
|
|
|
2016-06-20 07:01:59 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static SQInteger Keybind_UnusedSlot()
|
|
|
|
{
|
|
|
|
return _Func->GetKeyBindUnusedSlot();
|
|
|
|
}
|
|
|
|
|
2015-10-29 21:09:53 +01:00
|
|
|
// ================================================================================================
|
2016-02-20 23:25:00 +01:00
|
|
|
void Register_CKeybind(HSQUIRRELVM vm)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-11-15 20:16:24 +01:00
|
|
|
RootTable(vm).Bind(Typename::Str,
|
|
|
|
Class< CKeybind, NoConstructor< CKeybind > >(vm, Typename::Str)
|
2016-06-03 20:26:19 +02:00
|
|
|
// Meta-methods
|
2016-11-15 20:16:24 +01:00
|
|
|
.SquirrelFunc(_SC("_typename"), &Typename::Fn)
|
2016-02-20 23:25:00 +01:00
|
|
|
.Func(_SC("_tostring"), &CKeybind::ToString)
|
2016-03-10 05:18:39 +01:00
|
|
|
// Static Values
|
2016-03-10 04:57:13 +01:00
|
|
|
.SetStaticValue(_SC("MaxID"), CKeybind::Max)
|
|
|
|
// Core Properties
|
2017-02-21 20:24:59 +01:00
|
|
|
.Prop(_SC("On"), &CKeybind::GetEvents)
|
2016-02-20 23:25:00 +01:00
|
|
|
.Prop(_SC("ID"), &CKeybind::GetID)
|
|
|
|
.Prop(_SC("Tag"), &CKeybind::GetTag, &CKeybind::SetTag)
|
|
|
|
.Prop(_SC("Data"), &CKeybind::GetData, &CKeybind::SetData)
|
|
|
|
.Prop(_SC("Active"), &CKeybind::IsActive)
|
2016-03-10 05:18:39 +01:00
|
|
|
// Core Methods
|
2016-11-16 13:48:28 +01:00
|
|
|
.FmtFunc(_SC("SetTag"), &CKeybind::ApplyTag)
|
2016-07-26 23:13:50 +02:00
|
|
|
.Func(_SC("CustomEvent"), &CKeybind::CustomEvent)
|
2016-03-10 04:57:13 +01:00
|
|
|
// Core Overloads
|
2016-02-20 23:25:00 +01:00
|
|
|
.Overload< bool (CKeybind::*)(void) >(_SC("Destroy"), &CKeybind::Destroy)
|
|
|
|
.Overload< bool (CKeybind::*)(Int32) >(_SC("Destroy"), &CKeybind::Destroy)
|
2017-02-21 20:24:59 +01:00
|
|
|
.Overload< bool (CKeybind::*)(Int32, LightObj &) >(_SC("Destroy"), &CKeybind::Destroy)
|
2016-03-10 04:57:13 +01:00
|
|
|
// Properties
|
|
|
|
.Prop(_SC("First"), &CKeybind::GetFirst)
|
|
|
|
.Prop(_SC("Second"), &CKeybind::GetSecond)
|
|
|
|
.Prop(_SC("Third"), &CKeybind::GetThird)
|
2016-02-20 23:25:00 +01:00
|
|
|
.Prop(_SC("Release"), &CKeybind::IsRelease)
|
2016-03-10 05:18:39 +01:00
|
|
|
// Static Functions
|
2016-06-20 07:01:59 +02:00
|
|
|
.StaticFunc(_SC("UnusedSlot"), &Keybind_UnusedSlot)
|
2016-03-10 04:57:13 +01:00
|
|
|
// Static Overloads
|
2017-02-21 20:24:59 +01:00
|
|
|
.StaticOverload< LightObj & (*)(Int32, bool, Int32, Int32, Int32) >
|
2016-03-10 04:57:13 +01:00
|
|
|
(_SC("CreateEx"), &Keybind_CreateEx)
|
2017-02-21 20:24:59 +01:00
|
|
|
.StaticOverload< LightObj & (*)(Int32, bool, Int32, Int32, Int32, Int32, LightObj &) >
|
2016-03-10 04:57:13 +01:00
|
|
|
(_SC("CreateEx"), &Keybind_CreateEx)
|
2017-02-21 20:24:59 +01:00
|
|
|
.StaticOverload< LightObj & (*)(bool, Int32, Int32, Int32) >
|
2016-03-10 04:57:13 +01:00
|
|
|
(_SC("Create"), &Keybind_Create)
|
2017-02-21 20:24:59 +01:00
|
|
|
.StaticOverload< LightObj & (*)(bool, Int32, Int32, Int32, Int32, LightObj &) >
|
2016-03-10 04:57:13 +01:00
|
|
|
(_SC("Create"), &Keybind_Create)
|
2016-08-07 00:54:33 +02:00
|
|
|
// Raw Squirrel Methods
|
|
|
|
.SquirrelFunc(_SC("NullInst"), &CKeybind::SqGetNull)
|
2016-11-16 23:23:59 +01:00
|
|
|
.SquirrelFunc(_SC("MakeTask"), &Tasks::MakeTask< CKeybind, ENT_KEYBIND >)
|
|
|
|
.SquirrelFunc(_SC("DropTask"), &Tasks::DropTask< CKeybind, ENT_KEYBIND >)
|
|
|
|
.SquirrelFunc(_SC("DoesTask"), &Tasks::DoesTask< CKeybind, ENT_KEYBIND >)
|
2016-11-17 16:04:21 +01:00
|
|
|
.SquirrelFunc(_SC("FindTask"), &Tasks::FindTask< CKeybind, ENT_KEYBIND >)
|
2015-09-30 02:56:11 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-04-14 02:08:06 +02:00
|
|
|
} // Namespace:: SqMod
|