2020-03-22 00:45:04 +01:00
|
|
|
#pragma once
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
#include "Core/Common.hpp"
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
* Manages a single key-bind entity.
|
2015-09-30 02:56:11 +02:00
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
class CKeyBind
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
friend class Core;
|
2021-01-30 07:51:39 +01:00
|
|
|
friend class KeyBindInst;
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Identifier of the managed entity.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
int32_t m_ID;
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
* User tag associated with this instance.
|
2016-02-20 23:25:00 +01:00
|
|
|
*/
|
2017-02-21 20:24:59 +01:00
|
|
|
String m_Tag;
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* User data associated with this instance.
|
|
|
|
*/
|
2017-02-21 20:24:59 +01:00
|
|
|
LightObj m_Data;
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Base constructor.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
explicit CKeyBind(int32_t id);
|
2016-02-20 23:25:00 +01:00
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
public:
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
* Maximum possible number that could represent an identifier for this entity type.
|
2016-02-20 23:25:00 +01:00
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
static const int32_t Max;
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
* Copy constructor. (disabled)
|
2016-02-20 23:25:00 +01:00
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
CKeyBind(const CKeyBind &) = delete;
|
2016-02-20 23:25:00 +01:00
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Move constructor. (disabled)
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
CKeyBind(CKeyBind &&) = delete;
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
* Copy assignment operator. (disabled)
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
CKeyBind & operator = (const CKeyBind &) = delete;
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Move assignment operator. (disabled)
|
2016-02-20 23:25:00 +01:00
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
CKeyBind & operator = (CKeyBind &&) = delete;
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* See whether this instance manages a valid entity instance otherwise throw an exception.
|
|
|
|
*/
|
|
|
|
void Validate() const
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
if (INVALID_ENTITY(m_ID))
|
2016-03-12 21:51:44 +01:00
|
|
|
{
|
2021-02-03 16:50:39 +01:00
|
|
|
STHROWF("Invalid keybind reference [{}]", m_Tag);
|
2016-03-12 21:51:44 +01:00
|
|
|
}
|
2016-02-20 23:25:00 +01:00
|
|
|
}
|
|
|
|
|
2015-10-29 22:06:20 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Used by the script engine to convert an instance of this type to a string.
|
2015-10-29 22:06:20 +01:00
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD const String & ToString() const;
|
2015-10-29 21:09:53 +01:00
|
|
|
|
2016-08-07 00:54:33 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the associated null entity instance.
|
|
|
|
*/
|
|
|
|
static SQInteger SqGetNull(HSQUIRRELVM vm);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the associated null entity instance.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD static LightObj & GetNull();
|
2016-08-07 00:54:33 +02:00
|
|
|
|
2015-10-29 21:09:53 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
* Retrieve the identifier of the entity managed by this instance.
|
2015-10-29 21:09:53 +01:00
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD int32_t GetID() const
|
2016-03-10 04:57:13 +01:00
|
|
|
{
|
|
|
|
return m_ID;
|
|
|
|
}
|
2015-10-29 21:09:53 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Check whether this instance manages a valid entity.
|
2015-10-29 21:09:53 +01:00
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD bool IsActive() const
|
2016-03-10 04:57:13 +01:00
|
|
|
{
|
|
|
|
return VALID_ENTITY(m_ID);
|
|
|
|
}
|
2015-10-29 21:09:53 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Retrieve the associated user tag.
|
2015-10-29 21:09:53 +01:00
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD const String & GetTag() const;
|
2015-10-29 21:09:53 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Modify the associated user tag.
|
2015-10-29 21:09:53 +01:00
|
|
|
*/
|
2019-02-17 16:23:59 +01:00
|
|
|
void SetTag(StackStrF & tag);
|
2016-11-16 13:48:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Modify the associated user tag.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
CKeyBind & ApplyTag(StackStrF & tag);
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the associated user data.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD LightObj & GetData();
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Modify the associated user data.
|
|
|
|
*/
|
2017-02-21 20:24:59 +01:00
|
|
|
void SetData(LightObj & data);
|
2016-02-20 23:25:00 +01:00
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Destroy the managed destroy entity.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
bool Destroy0() const // NOLINT(modernize-use-nodiscard)
|
2016-03-10 04:57:13 +01:00
|
|
|
{
|
2017-02-21 20:24:59 +01:00
|
|
|
return Destroy(0, NullLightObj());
|
2016-03-10 04:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Destroy the managed destroy entity.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
bool Destroy1(int32_t header) const // NOLINT(modernize-use-nodiscard)
|
2016-03-10 04:57:13 +01:00
|
|
|
{
|
2017-02-21 20:24:59 +01:00
|
|
|
return Destroy(header, NullLightObj());
|
2016-03-10 04:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Destroy the managed destroy entity.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
bool Destroy(int32_t header, LightObj & payload) const; // NOLINT(modernize-use-nodiscard)
|
2016-02-20 23:25:00 +01:00
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
* Retrieve the events table of this entity.
|
2016-03-10 04:57:13 +01:00
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD LightObj & GetEvents() const;
|
2016-02-20 23:25:00 +01:00
|
|
|
|
2016-07-26 23:13:50 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Emit a custom event for the managed entity
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
void CustomEvent(int32_t header, LightObj & payload) const;
|
2016-07-26 23:13:50 +02:00
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
* Retrieve the first key code of the managed key-bind entity.
|
2016-03-10 04:57:13 +01:00
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD int32_t GetFirst() const;
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
* Retrieve the second key code of the managed key-bind entity.
|
2016-03-10 04:57:13 +01:00
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD int32_t GetSecond() const;
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
* Retrieve the third key code of the managed key-bind entity.
|
2016-03-10 04:57:13 +01:00
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD int32_t GetThird() const;
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
* See whether the managed key-bind entity reacts to key release events.
|
2016-03-10 04:57:13 +01:00
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD bool IsRelease() const;
|
2015-09-30 02:56:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|