Add get and set functions for the nametag color
parent
99cf53c908
commit
86a963caca
|
@ -2482,6 +2482,12 @@ This is basically a reference to a C++ `ServerActiveObject`
|
||||||
* `set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})`: defines offset value for camera per player
|
* `set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})`: defines offset value for camera per player
|
||||||
* in first person view
|
* in first person view
|
||||||
* in third person view (max. values `{x=-10/10,y=-10,15,z=-5/5}`)
|
* in third person view (max. values `{x=-10/10,y=-10,15,z=-5/5}`)
|
||||||
|
* `get_nametag_color()`
|
||||||
|
* returns the color of the nametag as table
|
||||||
|
* { a = 0...255, r = 0...255, g = 0...255, b = 0...255 }
|
||||||
|
* `set_nametag_color(color)`
|
||||||
|
* sets the color of the nametag
|
||||||
|
* `color`: { a = 0...255, r = 0...255, g = 0...255, b = 0...255 }
|
||||||
|
|
||||||
### `InvRef`
|
### `InvRef`
|
||||||
An `InvRef` is a reference to an inventory.
|
An `InvRef` is a reference to an inventory.
|
||||||
|
|
|
@ -552,6 +552,7 @@ GenericCAO::GenericCAO(IGameDef *gamedef, ClientEnvironment *env):
|
||||||
m_animated_meshnode(NULL),
|
m_animated_meshnode(NULL),
|
||||||
m_wield_meshnode(NULL),
|
m_wield_meshnode(NULL),
|
||||||
m_spritenode(NULL),
|
m_spritenode(NULL),
|
||||||
|
m_nametag_color(video::SColor(255, 255, 255, 255)),
|
||||||
m_textnode(NULL),
|
m_textnode(NULL),
|
||||||
m_position(v3f(0,10*BS,0)),
|
m_position(v3f(0,10*BS,0)),
|
||||||
m_velocity(v3f(0,0,0)),
|
m_velocity(v3f(0,0,0)),
|
||||||
|
@ -962,7 +963,7 @@ void GenericCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
|
||||||
gui::IGUIEnvironment* gui = irr->getGUIEnvironment();
|
gui::IGUIEnvironment* gui = irr->getGUIEnvironment();
|
||||||
std::wstring wname = narrow_to_wide(m_name);
|
std::wstring wname = narrow_to_wide(m_name);
|
||||||
m_textnode = smgr->addTextSceneNode(gui->getSkin()->getFont(),
|
m_textnode = smgr->addTextSceneNode(gui->getSkin()->getFont(),
|
||||||
wname.c_str(), video::SColor(255,255,255,255), node);
|
wname.c_str(), m_nametag_color, node);
|
||||||
m_textnode->grab();
|
m_textnode->grab();
|
||||||
m_textnode->setPosition(v3f(0, BS*1.1, 0));
|
m_textnode->setPosition(v3f(0, BS*1.1, 0));
|
||||||
}
|
}
|
||||||
|
@ -1714,6 +1715,11 @@ void GenericCAO::processMessage(const std::string &data)
|
||||||
int rating = readS16(is);
|
int rating = readS16(is);
|
||||||
m_armor_groups[name] = rating;
|
m_armor_groups[name] = rating;
|
||||||
}
|
}
|
||||||
|
} else if (cmd == GENERIC_CMD_SET_NAMETAG_COLOR) {
|
||||||
|
m_nametag_color = readARGB8(is);
|
||||||
|
if (m_textnode != NULL) {
|
||||||
|
m_textnode->setTextColor(m_nametag_color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,7 @@ private:
|
||||||
scene::IAnimatedMeshSceneNode *m_animated_meshnode;
|
scene::IAnimatedMeshSceneNode *m_animated_meshnode;
|
||||||
WieldMeshSceneNode *m_wield_meshnode;
|
WieldMeshSceneNode *m_wield_meshnode;
|
||||||
scene::IBillboardSceneNode *m_spritenode;
|
scene::IBillboardSceneNode *m_spritenode;
|
||||||
|
video::SColor m_nametag_color;
|
||||||
scene::ITextSceneNode* m_textnode;
|
scene::ITextSceneNode* m_textnode;
|
||||||
v3f m_position;
|
v3f m_position;
|
||||||
v3f m_velocity;
|
v3f m_velocity;
|
||||||
|
|
|
@ -715,6 +715,8 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
|
||||||
m_bone_position_sent(false),
|
m_bone_position_sent(false),
|
||||||
m_attachment_parent_id(0),
|
m_attachment_parent_id(0),
|
||||||
m_attachment_sent(false),
|
m_attachment_sent(false),
|
||||||
|
m_nametag_color(video::SColor(255, 255, 255, 255)),
|
||||||
|
m_nametag_sent(false),
|
||||||
// public
|
// public
|
||||||
m_physics_override_speed(1),
|
m_physics_override_speed(1),
|
||||||
m_physics_override_jump(1),
|
m_physics_override_jump(1),
|
||||||
|
@ -801,7 +803,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
|
||||||
writeF1000(os, m_player->getYaw());
|
writeF1000(os, m_player->getYaw());
|
||||||
writeS16(os, getHP());
|
writeS16(os, getHP());
|
||||||
|
|
||||||
writeU8(os, 5 + m_bone_position.size()); // number of messages stuffed in here
|
writeU8(os, 6 + m_bone_position.size()); // number of messages stuffed in here
|
||||||
os<<serializeLongString(getPropertyPacket()); // message 1
|
os<<serializeLongString(getPropertyPacket()); // message 1
|
||||||
os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
|
os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
|
||||||
os<<serializeLongString(gob_cmd_update_animation(m_animation_range, m_animation_speed, m_animation_blend)); // 3
|
os<<serializeLongString(gob_cmd_update_animation(m_animation_range, m_animation_speed, m_animation_blend)); // 3
|
||||||
|
@ -812,6 +814,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
|
||||||
os<<serializeLongString(gob_cmd_update_physics_override(m_physics_override_speed,
|
os<<serializeLongString(gob_cmd_update_physics_override(m_physics_override_speed,
|
||||||
m_physics_override_jump, m_physics_override_gravity, m_physics_override_sneak,
|
m_physics_override_jump, m_physics_override_gravity, m_physics_override_sneak,
|
||||||
m_physics_override_sneak_glitch)); // 5
|
m_physics_override_sneak_glitch)); // 5
|
||||||
|
os << serializeLongString(gob_cmd_set_nametag_color(m_nametag_color)); // 6
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -965,6 +968,14 @@ void PlayerSAO::step(float dtime, bool send_recommended)
|
||||||
ActiveObjectMessage aom(getId(), true, str);
|
ActiveObjectMessage aom(getId(), true, str);
|
||||||
m_messages_out.push(aom);
|
m_messages_out.push(aom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_nametag_sent == false) {
|
||||||
|
m_nametag_sent = true;
|
||||||
|
std::string str = gob_cmd_set_nametag_color(m_nametag_color);
|
||||||
|
// create message and add to list
|
||||||
|
ActiveObjectMessage aom(getId(), true, str);
|
||||||
|
m_messages_out.push(aom);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerSAO::setBasePosition(const v3f &position)
|
void PlayerSAO::setBasePosition(const v3f &position)
|
||||||
|
@ -1144,6 +1155,17 @@ void PlayerSAO::notifyObjectPropertiesModified()
|
||||||
m_properties_sent = false;
|
m_properties_sent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlayerSAO::setNametagColor(video::SColor color)
|
||||||
|
{
|
||||||
|
m_nametag_color = color;
|
||||||
|
m_nametag_sent = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
video::SColor PlayerSAO::getNametagColor()
|
||||||
|
{
|
||||||
|
return m_nametag_color;
|
||||||
|
}
|
||||||
|
|
||||||
Inventory* PlayerSAO::getInventory()
|
Inventory* PlayerSAO::getInventory()
|
||||||
{
|
{
|
||||||
return m_inventory;
|
return m_inventory;
|
||||||
|
|
|
@ -197,6 +197,8 @@ public:
|
||||||
void setAttachment(int parent_id, std::string bone, v3f position, v3f rotation);
|
void setAttachment(int parent_id, std::string bone, v3f position, v3f rotation);
|
||||||
ObjectProperties* accessObjectProperties();
|
ObjectProperties* accessObjectProperties();
|
||||||
void notifyObjectPropertiesModified();
|
void notifyObjectPropertiesModified();
|
||||||
|
void setNametagColor(video::SColor color);
|
||||||
|
video::SColor getNametagColor();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Inventory interface
|
Inventory interface
|
||||||
|
@ -313,6 +315,9 @@ private:
|
||||||
v3f m_attachment_rotation;
|
v3f m_attachment_rotation;
|
||||||
bool m_attachment_sent;
|
bool m_attachment_sent;
|
||||||
|
|
||||||
|
video::SColor m_nametag_color;
|
||||||
|
bool m_nametag_sent;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
float m_physics_override_speed;
|
float m_physics_override_speed;
|
||||||
float m_physics_override_jump;
|
float m_physics_override_jump;
|
||||||
|
|
|
@ -170,3 +170,12 @@ std::string gob_cmd_update_attachment(int parent_id, std::string bone, v3f posit
|
||||||
return os.str();
|
return os.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string gob_cmd_set_nametag_color(video::SColor color)
|
||||||
|
{
|
||||||
|
std::ostringstream os(std::ios::binary);
|
||||||
|
// command
|
||||||
|
writeU8(os, GENERIC_CMD_SET_NAMETAG_COLOR);
|
||||||
|
// parameters
|
||||||
|
writeARGB8(os, color);
|
||||||
|
return os.str();
|
||||||
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
#define GENERIC_CMD_SET_BONE_POSITION 7
|
#define GENERIC_CMD_SET_BONE_POSITION 7
|
||||||
#define GENERIC_CMD_SET_ATTACHMENT 8
|
#define GENERIC_CMD_SET_ATTACHMENT 8
|
||||||
#define GENERIC_CMD_SET_PHYSICS_OVERRIDE 9
|
#define GENERIC_CMD_SET_PHYSICS_OVERRIDE 9
|
||||||
|
#define GENERIC_CMD_SET_NAMETAG_COLOR 10
|
||||||
|
|
||||||
#include "object_properties.h"
|
#include "object_properties.h"
|
||||||
std::string gob_cmd_set_properties(const ObjectProperties &prop);
|
std::string gob_cmd_set_properties(const ObjectProperties &prop);
|
||||||
|
@ -72,5 +73,7 @@ std::string gob_cmd_update_bone_position(std::string bone, v3f position, v3f rot
|
||||||
|
|
||||||
std::string gob_cmd_update_attachment(int parent_id, std::string bone, v3f position, v3f rotation);
|
std::string gob_cmd_update_attachment(int parent_id, std::string bone, v3f position, v3f rotation);
|
||||||
|
|
||||||
|
std::string gob_cmd_set_nametag_color(video::SColor color);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1274,6 +1274,48 @@ int ObjectRef::l_override_day_night_ratio(lua_State *L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set_nametag_color(self, color)
|
||||||
|
int ObjectRef::l_set_nametag_color(lua_State *L)
|
||||||
|
{
|
||||||
|
NO_MAP_LOCK_REQUIRED;
|
||||||
|
ObjectRef *ref = checkobject(L, 1);
|
||||||
|
PlayerSAO *playersao = getplayersao(ref);
|
||||||
|
if (playersao == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
video::SColor color(255,255,255,255);
|
||||||
|
if (!lua_isnil(L, 2))
|
||||||
|
color = readARGB8(L, 2);
|
||||||
|
playersao->setNametagColor(color);
|
||||||
|
|
||||||
|
lua_pushboolean(L, true);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get_nametag_color(self)
|
||||||
|
int ObjectRef::l_get_nametag_color(lua_State *L)
|
||||||
|
{
|
||||||
|
NO_MAP_LOCK_REQUIRED;
|
||||||
|
ObjectRef *ref = checkobject(L, 1);
|
||||||
|
PlayerSAO *playersao = getplayersao(ref);
|
||||||
|
if (playersao == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
video::SColor color = playersao->getNametagColor();
|
||||||
|
|
||||||
|
lua_newtable(L);
|
||||||
|
lua_pushnumber(L, color.getAlpha());
|
||||||
|
lua_setfield(L, -2, "a");
|
||||||
|
lua_pushnumber(L, color.getRed());
|
||||||
|
lua_setfield(L, -2, "r");
|
||||||
|
lua_pushnumber(L, color.getGreen());
|
||||||
|
lua_setfield(L, -2, "g");
|
||||||
|
lua_pushnumber(L, color.getBlue());
|
||||||
|
lua_setfield(L, -2, "b");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
ObjectRef::ObjectRef(ServerActiveObject *object):
|
ObjectRef::ObjectRef(ServerActiveObject *object):
|
||||||
m_object(object)
|
m_object(object)
|
||||||
{
|
{
|
||||||
|
@ -1396,5 +1438,7 @@ const luaL_reg ObjectRef::methods[] = {
|
||||||
luamethod(ObjectRef, override_day_night_ratio),
|
luamethod(ObjectRef, override_day_night_ratio),
|
||||||
luamethod(ObjectRef, set_local_animation),
|
luamethod(ObjectRef, set_local_animation),
|
||||||
luamethod(ObjectRef, set_eye_offset),
|
luamethod(ObjectRef, set_eye_offset),
|
||||||
|
luamethod(ObjectRef, set_nametag_color),
|
||||||
|
luamethod(ObjectRef, get_nametag_color),
|
||||||
{0,0}
|
{0,0}
|
||||||
};
|
};
|
||||||
|
|
|
@ -240,6 +240,12 @@ private:
|
||||||
// set_eye_offset(self, v3f first pv, v3f third pv)
|
// set_eye_offset(self, v3f first pv, v3f third pv)
|
||||||
static int l_set_eye_offset(lua_State *L);
|
static int l_set_eye_offset(lua_State *L);
|
||||||
|
|
||||||
|
// set_nametag_color(self, color)
|
||||||
|
static int l_set_nametag_color(lua_State *L);
|
||||||
|
|
||||||
|
// get_nametag_color(self)
|
||||||
|
static int l_get_nametag_color(lua_State *L);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ObjectRef(ServerActiveObject *object);
|
ObjectRef(ServerActiveObject *object);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue