2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-09-30 02:56:11 +02:00
|
|
|
#include "Entity/Sprite.hpp"
|
2016-02-20 23:25:00 +01:00
|
|
|
#include "Entity/Player.hpp"
|
2015-11-01 00:32:57 +01:00
|
|
|
#include "Base/Vector2i.hpp"
|
|
|
|
#include "Core.hpp"
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
2015-11-01 00:32:57 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
const Int32 CSprite::Max = SQMOD_SPRITE_POOL;
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
SQInteger CSprite::Typename(HSQUIRRELVM vm)
|
|
|
|
{
|
|
|
|
static SQChar name[] = _SC("SqSprite");
|
|
|
|
sq_pushstring(vm, name, sizeof(name));
|
|
|
|
return 1;
|
|
|
|
}
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
CSprite::CSprite(Int32 id)
|
|
|
|
: m_ID(VALID_ENTITYGETEX(id, SQMOD_SPRITE_POOL))
|
2016-03-10 04:57:13 +01:00
|
|
|
, m_Tag(ToStrF("%d", id))
|
2015-11-01 00:32:57 +01:00
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
2015-09-30 02:56:11 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
CSprite::~CSprite()
|
2015-10-29 21:41:20 +01:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
/* ... */
|
2015-10-29 21:41:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Int32 CSprite::Cmp(const CSprite & o) const
|
|
|
|
{
|
|
|
|
if (m_ID == o.m_ID)
|
|
|
|
return 0;
|
|
|
|
else if (m_ID > o.m_ID)
|
|
|
|
return 1;
|
2015-10-29 21:41:20 +01:00
|
|
|
else
|
2016-02-20 23:25:00 +01:00
|
|
|
return -1;
|
2015-10-29 21:41:20 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
const String & CSprite::ToString() const
|
2015-10-29 21:41:20 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
return m_Tag;
|
2015-10-29 21:41:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
const String & CSprite::GetTag() const
|
2015-10-29 21:41:20 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
return m_Tag;
|
2015-10-29 21:41:20 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::SetTag(CSStr tag)
|
|
|
|
{
|
|
|
|
m_Tag.assign(tag);
|
2015-10-29 21:41:20 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Object & CSprite::GetData()
|
2015-10-29 21:41:20 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
|
|
|
return m_Data;
|
2015-10-29 21:41:20 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::SetData(Object & data)
|
2015-10-29 21:41:20 +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:41:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
bool CSprite::Destroy(Int32 header, Object & payload)
|
2015-10-29 21:41:20 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
2016-02-20 23:25:00 +01:00
|
|
|
return _Core->DelSprite(m_ID, header, payload);
|
2015-10-29 21:41:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
void CSprite::BindEvent(Int32 evid, Object & env, Function & func) const
|
2016-02-20 23:25:00 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Obtain the function instance called for this event
|
2016-02-20 23:25:00 +01:00
|
|
|
Function & event = _Core->GetSpriteEvent(m_ID, evid);
|
2016-03-10 04:57:13 +01:00
|
|
|
// Is the specified callback function null?
|
2016-02-20 23:25:00 +01:00
|
|
|
if (func.IsNull())
|
2016-03-10 04:57:13 +01:00
|
|
|
event.Release(); // Then release the current callback
|
|
|
|
// Assign the specified environment and function
|
2015-10-29 21:41:20 +01:00
|
|
|
else
|
2016-02-20 23:25:00 +01:00
|
|
|
event = Function(env.GetVM(), env, func.GetFunc());
|
2015-10-29 21:41:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::ShowAll() const
|
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
_Func->ShowSprite(m_ID, -1);
|
2015-10-29 21:41:20 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::ShowFor(CPlayer & player) const
|
2015-10-29 21:41:20 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Is the specified player even valid?
|
2016-02-20 23:25:00 +01:00
|
|
|
if (!player.IsActive())
|
2016-03-10 04:57:13 +01:00
|
|
|
SqThrowF("Invalid player argument: null");
|
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
_Func->ShowSprite(m_ID, player.GetID());
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::ShowRange(Int32 first, Int32 last) const
|
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the specified range
|
2016-02-20 23:25:00 +01:00
|
|
|
if (first > last)
|
2016-03-10 04:57:13 +01:00
|
|
|
SqThrowF("Invalid player range: %d > %d", first, last);
|
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
for (; first <= last; ++first)
|
|
|
|
{
|
|
|
|
// Is the currently processed player even connected?
|
|
|
|
if (_Func->IsPlayerConnected(first))
|
|
|
|
// Then show this textdraw on his client
|
|
|
|
_Func->ShowSprite(m_ID, first);
|
|
|
|
}
|
2015-10-29 21:41:20 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::HideAll() const
|
2015-10-29 21:41:20 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
_Func->HideSprite(m_ID, -1);
|
2015-10-29 21:41:20 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::HideFor(CPlayer & player) const
|
2015-10-29 21:41:20 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Is the specified player even valid?
|
2016-02-20 23:25:00 +01:00
|
|
|
if (!player.IsActive())
|
2016-03-10 04:57:13 +01:00
|
|
|
SqThrowF("Invalid player argument: null");
|
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
_Func->HideSprite(m_ID, player.GetID());
|
2015-10-29 21:41:20 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::HideRange(Int32 first, Int32 last) const
|
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the specified range
|
2016-02-20 23:25:00 +01:00
|
|
|
if (first > last)
|
2016-03-10 04:57:13 +01:00
|
|
|
SqThrowF("Invalid player range: %d > %d", first, last);
|
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
for (; first <= last; ++first)
|
|
|
|
{
|
|
|
|
// Is the currently processed player even connected?
|
|
|
|
if (_Func->IsPlayerConnected(first))
|
|
|
|
// Then hide this textdraw on his client
|
|
|
|
_Func->HideSprite(m_ID, first);
|
|
|
|
}
|
2015-10-29 21:41:20 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::SetPositionAll(const Vector2i & pos) const
|
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
_Func->MoveSprite(m_ID, -1, pos.x, pos.y);
|
2015-10-29 21:41:20 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::SetPositionAllEx(Int32 x, Int32 y) const
|
2015-10-29 21:41:20 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
_Func->MoveSprite(m_ID, -1, x, y);
|
2015-10-29 21:41:20 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::SetPositionFor(CPlayer & player, const Vector2i & pos) const
|
2015-10-29 21:41:20 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Is the specified player even valid?
|
2016-02-20 23:25:00 +01:00
|
|
|
if (!player.IsActive())
|
2016-03-10 04:57:13 +01:00
|
|
|
SqThrowF("Invalid player argument: null");
|
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
_Func->MoveSprite(m_ID, player.GetID(), pos.x, pos.y);
|
2015-10-29 21:41:20 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::SetPositionForEx(CPlayer & player, Int32 x, Int32 y) const
|
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Is the specified player even valid?
|
2016-02-20 23:25:00 +01:00
|
|
|
if (!player.IsActive())
|
2016-03-10 04:57:13 +01:00
|
|
|
SqThrowF("Invalid player argument: null");
|
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
_Func->MoveSprite(m_ID, player.GetID(), x, y);
|
2015-10-29 21:41:20 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::SetPositionRange(Int32 first, Int32 last, const Vector2i & pos) const
|
2015-10-29 21:41:20 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the specified range
|
2016-02-20 23:25:00 +01:00
|
|
|
if (first > last)
|
2016-03-10 04:57:13 +01:00
|
|
|
SqThrowF("Invalid player range: %d > %d", first, last);
|
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
for (; first <= last; ++first)
|
|
|
|
{
|
|
|
|
// Is the currently processed player even connected?
|
|
|
|
if (_Func->IsPlayerConnected(first))
|
|
|
|
// Then move this textdraw on his client
|
|
|
|
_Func->MoveSprite(m_ID, first, pos.x, pos.y);
|
|
|
|
}
|
2015-10-29 21:41:20 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::SetCenterAll(const Vector2i & pos) const
|
2015-10-29 21:41:20 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
_Func->SetSpriteCenter(m_ID, -1, pos.x, pos.y);
|
2015-10-29 21:41:20 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::SetCenterAllEx(Int32 x, Int32 y) const
|
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
_Func->SetSpriteCenter(m_ID, -1, x, y);
|
2015-10-29 21:41:20 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::SetCenterFor(CPlayer & player, const Vector2i & pos) const
|
2015-10-29 21:41:20 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Is the specified player even valid?
|
2016-02-20 23:25:00 +01:00
|
|
|
if (!player.IsActive())
|
2016-03-10 04:57:13 +01:00
|
|
|
SqThrowF("Invalid player argument: null");
|
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
_Func->SetSpriteCenter(m_ID, player.GetID(), pos.x, pos.y);
|
2015-10-29 21:41:20 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::SetCenterForEx(CPlayer & player, Int32 x, Int32 y) const
|
2015-10-29 21:41:20 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Is the specified player even valid?
|
2016-02-20 23:25:00 +01:00
|
|
|
if (!player.IsActive())
|
2016-03-10 04:57:13 +01:00
|
|
|
SqThrowF("Invalid player argument: null");
|
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
_Func->SetSpriteCenter(m_ID, player.GetID(), x, y);
|
2015-10-29 21:41:20 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::SetCenterRange(Int32 first, Int32 last, const Vector2i & pos) const
|
2015-11-01 00:32:57 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the specified range
|
2016-02-20 23:25:00 +01:00
|
|
|
if (first > last)
|
2016-03-10 04:57:13 +01:00
|
|
|
SqThrowF("Invalid player range: %d > %d", first, last);
|
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
for (; first <= last; ++first)
|
|
|
|
{
|
|
|
|
// Is the currently processed player even connected?
|
|
|
|
if (_Func->IsPlayerConnected(first))
|
|
|
|
// Then center this textdraw on his client
|
|
|
|
_Func->SetSpriteCenter(m_ID, first, pos.x, pos.y);
|
|
|
|
}
|
2015-11-01 00:32:57 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::SetRotationAll(Float32 rot) const
|
2015-11-01 00:32:57 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
_Func->RotateSprite(m_ID, -1, rot);
|
2015-11-01 00:32:57 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::SetRotationFor(CPlayer & player, Float32 rot) const
|
2015-11-01 00:32:57 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Is the specified player even valid?
|
2016-02-20 23:25:00 +01:00
|
|
|
if (!player.IsActive())
|
2016-03-10 04:57:13 +01:00
|
|
|
SqThrowF("Invalid player argument: null");
|
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
_Func->RotateSprite(m_ID, player.GetID(), rot);
|
2015-11-01 00:32:57 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::SetRotationRange(Int32 first, Int32 last, Float32 rot) const
|
2015-11-01 00:32:57 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the specified range
|
2016-02-20 23:25:00 +01:00
|
|
|
if (first > last)
|
2016-03-10 04:57:13 +01:00
|
|
|
SqThrowF("Invalid player range: %d > %d", first, last);
|
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
for (; first <= last; ++first)
|
|
|
|
{
|
|
|
|
// Is the currently processed player even connected?
|
|
|
|
if (_Func->IsPlayerConnected(first))
|
|
|
|
// Then rotate this textdraw on his client
|
|
|
|
_Func->RotateSprite(m_ID, first, rot);
|
|
|
|
}
|
2015-11-01 00:32:57 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::SetAlphaAll(Uint8 alpha) const
|
2015-11-01 00:32:57 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
_Func->SetSpriteAlpha(m_ID, -1, alpha);
|
2015-11-01 00:32:57 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::SetAlphaFor(CPlayer & player, Uint8 alpha) const
|
2015-11-01 00:32:57 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Is the specified player even valid?
|
2016-02-20 23:25:00 +01:00
|
|
|
if (!player.IsActive())
|
2016-03-10 04:57:13 +01:00
|
|
|
SqThrowF("Invalid player argument: null");
|
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
_Func->SetSpriteAlpha(m_ID, player.GetID(), alpha);
|
2015-11-01 00:32:57 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void CSprite::SetAlphaRange(Int32 first, Int32 last, Uint8 alpha) const
|
2015-11-01 00:32:57 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the specified range
|
2016-02-20 23:25:00 +01:00
|
|
|
if (first > last)
|
2016-03-10 04:57:13 +01:00
|
|
|
SqThrowF("Invalid player range: %d > %d", first, last);
|
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Perform the requested operation
|
|
|
|
for (; first <= last; ++first)
|
|
|
|
{
|
|
|
|
// Is the currently processed player even connected?
|
|
|
|
if (_Func->IsPlayerConnected(first))
|
|
|
|
// Then colorize this textdraw on his client
|
|
|
|
_Func->SetSpriteAlpha(m_ID, first, alpha);
|
|
|
|
}
|
2015-11-01 00:32:57 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
const String & CSprite::GetFilePath() const
|
2015-11-01 00:32:57 +01:00
|
|
|
{
|
2016-03-10 04:57:13 +01:00
|
|
|
// Validate the managed identifier
|
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
|
|
|
return _Core->GetSprite(m_ID).mPath;
|
2015-11-01 00:32:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
static Object & Sprite_CreateEx(CSStr file, Int32 xp, Int32 yp, Int32 xr, Int32 yr,
|
2016-02-20 23:25:00 +01:00
|
|
|
Float32 angle, Int32 alpha, bool rel)
|
2015-11-01 00:32:57 +01:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return _Core->NewSprite(-1, file, xp, yp, xr, yr, angle, alpha, rel,
|
|
|
|
SQMOD_CREATE_DEFAULT, NullObject());
|
2015-11-01 00:32:57 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static Object & Sprite_CreateEx(CSStr file, Int32 xp, Int32 yp, Int32 xr, Int32 yr,
|
2016-02-20 23:25:00 +01:00
|
|
|
Float32 angle, Int32 alpha, bool rel, Int32 header, Object & payload)
|
2015-11-01 00:32:57 +01:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return _Core->NewSprite(-1, file, xp, yp, xr, yr, angle, alpha, rel, header, payload);
|
2015-11-01 00:32:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
static Object & Sprite_CreateEx(Int32 index, CSStr file, Int32 xp, Int32 yp, Int32 xr, Int32 yr,
|
2016-02-20 23:25:00 +01:00
|
|
|
Float32 angle, Int32 alpha, bool rel)
|
2015-11-01 00:32:57 +01:00
|
|
|
{
|
|
|
|
return _Core->NewSprite(index, file, xp, yp, xr, yr, angle, alpha, rel,
|
2016-02-20 23:25:00 +01:00
|
|
|
SQMOD_CREATE_DEFAULT, NullObject());
|
2015-11-01 00:32:57 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static Object & Sprite_CreateEx(Int32 index, CSStr file, Int32 xp, Int32 yp, Int32 xr, Int32 yr,
|
2016-02-20 23:25:00 +01:00
|
|
|
Float32 angle, Int32 alpha, bool rel, Int32 header, Object & payload)
|
2015-11-01 00:32:57 +01:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return _Core->NewSprite(index, file, xp, yp, xr, yr, angle, alpha, rel, header, payload);
|
2015-11-01 00:32:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
static Object & Sprite_Create(CSStr file, const Vector2i & pos, const Vector2i & rot,
|
2016-02-20 23:25:00 +01:00
|
|
|
Float32 angle, Int32 alpha, bool rel)
|
2015-11-01 00:32:57 +01:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return _Core->NewSprite(-1, file, pos.x, pos.y, rot.x, rot.y, angle, alpha, rel,
|
|
|
|
SQMOD_CREATE_DEFAULT, NullObject());
|
2015-11-01 00:32:57 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static Object & Sprite_Create(CSStr file, const Vector2i & pos, const Vector2i & rot,
|
2016-02-20 23:25:00 +01:00
|
|
|
Float32 angle, Int32 alpha, bool rel, Int32 header, Object & payload)
|
2015-11-01 00:32:57 +01:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return _Core->NewSprite(-1, file, pos.x, pos.y, rot.x, rot.y, angle, alpha, rel, header, payload);
|
2015-11-01 00:32:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
static Object & Sprite_Create(Int32 index, CSStr file, const Vector2i & pos, const Vector2i & rot,
|
2016-02-20 23:25:00 +01:00
|
|
|
Float32 angle, Int32 alpha, bool rel)
|
2015-11-01 00:32:57 +01:00
|
|
|
{
|
|
|
|
return _Core->NewSprite(index, file, pos.x, pos.y, rot.x, rot.y, angle, alpha, rel,
|
2016-02-20 23:25:00 +01:00
|
|
|
SQMOD_CREATE_DEFAULT, NullObject());
|
2015-11-01 00:32:57 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static Object & Sprite_Create(Int32 index, CSStr file, const Vector2i & pos, const Vector2i & rot,
|
2016-02-20 23:25:00 +01:00
|
|
|
Float32 angle, Int32 alpha, bool rel, Int32 header, Object & payload)
|
2015-11-01 00:32:57 +01:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return _Core->NewSprite(index, file, pos.x, pos.y, rot.x, rot.y, angle, alpha, rel, header, payload);
|
2015-11-01 00:32:57 +01:00
|
|
|
}
|
|
|
|
|
2016-03-10 05:18:39 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static const Object & Sprite_FindByID(Int32 id)
|
|
|
|
{
|
|
|
|
// Perform a range check on the specified identifier
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_SPRITE_POOL))
|
|
|
|
SqThrowF("The specified sprite identifier is invalid: %d", id);
|
|
|
|
// Obtain the ends of the entity pool
|
|
|
|
Core::Sprites::const_iterator itr = _Core->GetSprites().cbegin();
|
|
|
|
Core::Sprites::const_iterator end = _Core->GetSprites().cend();
|
|
|
|
// Process each entity in the pool
|
|
|
|
for (; itr != end; ++itr)
|
|
|
|
{
|
|
|
|
// Does the identifier match the specified one?
|
|
|
|
if (itr->mID == id)
|
|
|
|
return itr->mObj; // Stop searching and return this entity
|
|
|
|
}
|
|
|
|
// Unable to locate a sprite matching the specified identifier
|
|
|
|
return NullObject();
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Object & Sprite_FindByTag(CSStr tag)
|
|
|
|
{
|
|
|
|
// Perform a validity check on the specified tag
|
|
|
|
if (!tag || *tag == 0)
|
|
|
|
SqThrowF("The specified sprite tag is invalid: null/empty");
|
|
|
|
// Obtain the ends of the entity pool
|
|
|
|
Core::Sprites::const_iterator itr = _Core->GetSprites().cbegin();
|
|
|
|
Core::Sprites::const_iterator end = _Core->GetSprites().cend();
|
|
|
|
// Process each entity in the pool
|
|
|
|
for (; itr != end; ++itr)
|
|
|
|
{
|
|
|
|
// Does this entity even exist and does the tag match the specified one?
|
|
|
|
if (itr->mInst != nullptr && itr->mInst->GetTag().compare(tag) == 0)
|
|
|
|
return itr->mObj; // Stop searching and return this entity
|
|
|
|
}
|
|
|
|
// Unable to locate a sprite matching the specified tag
|
|
|
|
return NullObject();
|
|
|
|
}
|
|
|
|
|
2015-10-29 21:41:20 +01:00
|
|
|
// ================================================================================================
|
2016-02-20 23:25:00 +01:00
|
|
|
void Register_CSprite(HSQUIRRELVM vm)
|
|
|
|
{
|
|
|
|
RootTable(vm).Bind(_SC("SqSprite"),
|
|
|
|
Class< CSprite, NoConstructor< CSprite > >(vm, _SC("SqSprite"))
|
2016-03-10 04:57:13 +01:00
|
|
|
// Metamethods
|
2016-02-20 23:25:00 +01:00
|
|
|
.Func(_SC("_cmp"), &CSprite::Cmp)
|
2016-03-10 04:57:13 +01:00
|
|
|
.SquirrelFunc(_SC("_typename"), &CSprite::Typename)
|
2016-02-20 23:25:00 +01:00
|
|
|
.Func(_SC("_tostring"), &CSprite::ToString)
|
2016-03-10 05:18:39 +01:00
|
|
|
// Static Values
|
2016-03-10 04:57:13 +01:00
|
|
|
.SetStaticValue(_SC("MaxID"), CSprite::Max)
|
|
|
|
// Core Properties
|
2016-02-20 23:25:00 +01:00
|
|
|
.Prop(_SC("ID"), &CSprite::GetID)
|
|
|
|
.Prop(_SC("Tag"), &CSprite::GetTag, &CSprite::SetTag)
|
|
|
|
.Prop(_SC("Data"), &CSprite::GetData, &CSprite::SetData)
|
|
|
|
.Prop(_SC("Active"), &CSprite::IsActive)
|
2016-03-10 05:18:39 +01:00
|
|
|
// Core Methods
|
2016-02-20 23:25:00 +01:00
|
|
|
.Func(_SC("Bind"), &CSprite::BindEvent)
|
2016-03-10 04:57:13 +01:00
|
|
|
// Core Overloads
|
2016-02-20 23:25:00 +01:00
|
|
|
.Overload< bool (CSprite::*)(void) >(_SC("Destroy"), &CSprite::Destroy)
|
|
|
|
.Overload< bool (CSprite::*)(Int32) >(_SC("Destroy"), &CSprite::Destroy)
|
|
|
|
.Overload< bool (CSprite::*)(Int32, Object &) >(_SC("Destroy"), &CSprite::Destroy)
|
2016-03-10 04:57:13 +01:00
|
|
|
// Properties
|
2016-02-20 23:25:00 +01:00
|
|
|
.Prop(_SC("Path"), &CSprite::GetFilePath)
|
2016-03-10 05:18:39 +01:00
|
|
|
// Member Methods
|
2016-02-20 23:25:00 +01:00
|
|
|
.Func(_SC("ShowAll"), &CSprite::ShowAll)
|
|
|
|
.Func(_SC("ShowTo"), &CSprite::ShowFor)
|
|
|
|
.Func(_SC("ShowFor"), &CSprite::ShowFor)
|
|
|
|
.Func(_SC("ShowRange"), &CSprite::ShowRange)
|
|
|
|
.Func(_SC("HideAll"), &CSprite::HideAll)
|
|
|
|
.Func(_SC("HideFor"), &CSprite::HideFor)
|
|
|
|
.Func(_SC("HideFrom"), &CSprite::HideFor)
|
|
|
|
.Func(_SC("HideRange"), &CSprite::HideRange)
|
|
|
|
.Func(_SC("SetPositionRange"), &CSprite::SetPositionRange)
|
|
|
|
.Func(_SC("SetCenterRange"), &CSprite::SetCenterRange)
|
|
|
|
.Func(_SC("SetRotationAll"), &CSprite::SetRotationAll)
|
|
|
|
.Func(_SC("SetRotationFor"), &CSprite::SetRotationFor)
|
|
|
|
.Func(_SC("SetRotationRange"), &CSprite::SetRotationRange)
|
|
|
|
.Func(_SC("SetAlphaAll"), &CSprite::SetAlphaAll)
|
|
|
|
.Func(_SC("SetAlphaFor"), &CSprite::SetAlphaFor)
|
|
|
|
.Func(_SC("SetAlphaRange"), &CSprite::SetAlphaRange)
|
2016-03-10 05:18:39 +01:00
|
|
|
// Member Overloads
|
2015-11-01 00:32:57 +01:00
|
|
|
.Overload< void (CSprite::*)(const Vector2i &) const >
|
2016-02-20 23:25:00 +01:00
|
|
|
(_SC("SetPositionAll"), &CSprite::SetPositionAll)
|
|
|
|
.Overload< void (CSprite::*)(Int32, Int32) const >
|
|
|
|
(_SC("SetPositionAll"), &CSprite::SetPositionAllEx)
|
|
|
|
.Overload< void (CSprite::*)(CPlayer &, const Vector2i &) const >
|
|
|
|
(_SC("SetPositionFor"), &CSprite::SetPositionFor)
|
|
|
|
.Overload< void (CSprite::*)(CPlayer &, Int32, Int32) const >
|
|
|
|
(_SC("SetPositionFor"), &CSprite::SetPositionForEx)
|
2015-11-01 00:32:57 +01:00
|
|
|
.Overload< void (CSprite::*)(const Vector2i &) const >
|
2016-02-20 23:25:00 +01:00
|
|
|
(_SC("SetCenterAll"), &CSprite::SetCenterAll)
|
|
|
|
.Overload< void (CSprite::*)(Int32, Int32) const >
|
|
|
|
(_SC("SetCenterAll"), &CSprite::SetCenterAllEx)
|
|
|
|
.Overload< void (CSprite::*)(CPlayer &, const Vector2i &) const >
|
|
|
|
(_SC("SetCenterFor"), &CSprite::SetCenterFor)
|
|
|
|
.Overload< void (CSprite::*)(CPlayer &, Int32, Int32) const >
|
|
|
|
(_SC("SetCenterFor"), &CSprite::SetCenterForEx)
|
2016-03-10 05:18:39 +01:00
|
|
|
// Static Functions
|
|
|
|
.StaticFunc(_SC("FindByID"), &Sprite_FindByID)
|
|
|
|
.StaticFunc(_SC("FindByTag"), &Sprite_FindByTag)
|
2016-03-10 04:57:13 +01:00
|
|
|
// Static Overloads
|
|
|
|
.StaticOverload< Object & (*)(CSStr, Int32, Int32, Int32, Int32, Float32, Int32, bool rel) >
|
|
|
|
(_SC("CreateEx"), &Sprite_CreateEx)
|
|
|
|
.StaticOverload< Object & (*)(CSStr, Int32, Int32, Int32, Int32, Float32, Int32, bool rel, Int32, Object &) >
|
|
|
|
(_SC("CreateEx"), &Sprite_CreateEx)
|
|
|
|
.StaticOverload< Object & (*)(Int32, CSStr, Int32, Int32, Int32, Int32, Float32, Int32, bool rel) >
|
|
|
|
(_SC("CreateEx"), &Sprite_CreateEx)
|
|
|
|
.StaticOverload< Object & (*)(Int32, CSStr, Int32, Int32, Int32, Int32, Float32, Int32, bool rel, Int32, Object &) >
|
|
|
|
(_SC("CreateEx"), &Sprite_CreateEx)
|
|
|
|
.StaticOverload< Object & (*)(CSStr, const Vector2i &, const Vector2i &, Float32, Int32, bool) >
|
|
|
|
(_SC("Create"), &Sprite_Create)
|
|
|
|
.StaticOverload< Object & (*)(CSStr, const Vector2i &, const Vector2i &, Float32, Int32, bool, Int32, Object &) >
|
|
|
|
(_SC("Create"), &Sprite_Create)
|
|
|
|
.StaticOverload< Object & (*)(Int32, CSStr, const Vector2i &, const Vector2i &, Float32, Int32, bool) >
|
|
|
|
(_SC("Create"), &Sprite_Create)
|
|
|
|
.StaticOverload< Object & (*)(Int32, CSStr, const Vector2i &, const Vector2i &, Float32, Int32, bool, Int32, Object &) >
|
|
|
|
(_SC("Create"), &Sprite_Create)
|
2015-09-30 02:56:11 +02:00
|
|
|
);
|
2016-03-10 04:57:13 +01:00
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
} // Namespace:: SqMod
|