2015-09-30 02:56:11 +02:00
|
|
|
#ifndef _ENTITY_SPRITE_HPP_
|
|
|
|
#define _ENTITY_SPRITE_HPP_
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
#include "Base/Shared.hpp"
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Manages Sprite instances.
|
2015-09-30 02:56:11 +02:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
class CSprite
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
friend class Core;
|
2015-10-29 21:41:20 +01:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
private:
|
2015-10-29 21:41:20 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Cached identifiers for fast integer to string conversion.
|
2015-10-29 21:41:20 +01:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
static SQChar s_StrID[SQMOD_SPRITE_POOL][8];
|
2015-10-29 21:41:20 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Identifier of the managed entity.
|
2015-10-29 21:41:20 +01:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
Int32 m_ID;
|
2015-10-29 21:41:20 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* User tag and data associated with this instance.
|
2015-10-29 21:41:20 +01:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
String m_Tag;
|
|
|
|
Object m_Data;
|
2015-10-29 21:41:20 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Base constructor.
|
2015-10-29 21:41:20 +01:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
CSprite(Int32 id);
|
2015-10-29 21:41:20 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Copy constructor. (disabled)
|
2015-10-29 21:41:20 +01:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
CSprite(const CSprite &);
|
2015-10-29 21:41:20 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Copy assignment operator. (disabled)
|
2015-10-29 21:41:20 +01:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
CSprite & operator = (const CSprite &);
|
2015-10-29 21:41:20 +01:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
public:
|
2015-10-29 21:41:20 +01:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
static const Int32 Max;
|
2015-10-29 21:41:20 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Destructor.
|
2015-10-29 21:41:20 +01:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
~CSprite();
|
2015-10-29 21:41:20 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* See whether this instance manages a valid entity.
|
2015-10-29 21:41:20 +01:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
bool Validate() const
|
|
|
|
{
|
|
|
|
if (VALID_ENTITY(m_ID))
|
|
|
|
return true;
|
|
|
|
SqThrow("Invalid sprite reference [%s]", m_Tag.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-29 21:41:20 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Used by the script engine to compare two instances of this type.
|
2015-10-29 21:41:20 +01:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
Int32 Cmp(const CSprite & o) const;
|
2015-10-29 21:41: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 21:41:20 +01:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
CSStr ToString() const;
|
2015-10-29 21:41:20 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Retrieve the identifier of the entity managed by this instance.
|
2015-10-29 21:41:20 +01:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
Int32 GetID() const { return m_ID; }
|
2015-10-29 21:41:20 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Retrieve the maximum possible identifier to an entity of this type.
|
2015-10-29 21:41:20 +01:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
Int32 GetMaxID() const { return SQMOD_SPRITE_POOL; }
|
2015-10-29 21:41:20 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Check whether this instance manages a valid entity.
|
2015-10-29 21:41:20 +01:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
bool IsActive() const { return VALID_ENTITY(m_ID); }
|
2015-10-29 21:41:20 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Retrieve the associated user tag.
|
2015-10-29 21:41:20 +01:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
CSStr GetTag() const;
|
2015-10-29 21:41:20 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Modify the associated user tag.
|
2015-10-29 21:41:20 +01:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
void SetTag(CSStr tag);
|
2015-10-29 21:41:20 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Retrieve the associated user data.
|
2015-10-29 21:41:20 +01:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
Object & GetData();
|
2015-10-29 21:41:20 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Modify the associated user data.
|
2015-10-29 21:41:20 +01:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
void SetData(Object & data);
|
2015-10-29 21:41:20 +01:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
bool Destroy(Int32 header, Object & payload);
|
|
|
|
bool Destroy() { return Destroy(0, NullObject()); }
|
|
|
|
bool Destroy(Int32 header) { return Destroy(header, NullObject()); }
|
2015-10-29 21:41:20 +01:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
bool BindEvent(Int32 evid, Object & env, Function & func) const;
|
2015-10-29 21:41:20 +01:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
void ShowAll() const;
|
|
|
|
void ShowFor(CPlayer & player) const;
|
|
|
|
void ShowRange(Int32 first, Int32 last) const;
|
|
|
|
void HideAll() const;
|
|
|
|
void HideFor(CPlayer & player) const;
|
|
|
|
void HideRange(Int32 first, Int32 last) const;
|
|
|
|
void SetPositionAll(const Vector2i & pos) const;
|
|
|
|
void SetPositionAllEx(Int32 x, Int32 y) const;
|
|
|
|
void SetPositionFor(CPlayer & player, const Vector2i & pos) const;
|
|
|
|
void SetPositionForEx(CPlayer & player, Int32 x, Int32 y) const;
|
|
|
|
void SetPositionRange(Int32 first, Int32 last, const Vector2i & pos) const;
|
|
|
|
void SetCenterAll(const Vector2i & pos) const;
|
|
|
|
void SetCenterAllEx(Int32 x, Int32 y) const;
|
|
|
|
void SetCenterFor(CPlayer & player, const Vector2i & pos) const;
|
|
|
|
void SetCenterForEx(CPlayer & player, Int32 x, Int32 y) const;
|
|
|
|
void SetCenterRange(Int32 first, Int32 last, const Vector2i & pos) const;
|
|
|
|
void SetRotationAll(SQFloat rot) const;
|
|
|
|
void SetRotationFor(CPlayer & player, SQFloat rot) const;
|
|
|
|
void SetRotationRange(Int32 first, Int32 last, SQFloat rot) const;
|
|
|
|
void SetAlphaAll(Uint8 alpha) const;
|
|
|
|
void SetAlphaFor(CPlayer & player, Uint8 alpha) const;
|
|
|
|
void SetAlphaRange(Int32 first, Int32 last, Uint8 alpha) const;
|
|
|
|
CSStr GetFilePath() const;
|
2015-09-30 02:56:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|
|
|
|
|
|
|
|
#endif // _ENTITY_SPRITE_HPP_
|