Skip to content
Permalink
Browse files

Add get and set functions for the nametag color

  • Loading branch information
TeTpaAka authored and est31 committed May 14, 2015
1 parent 99cf53c commit 86a963caca9604ad57904e9acd9bef7c46ca47d8
@@ -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
* in first person view
* 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`
An `InvRef` is a reference to an inventory.
@@ -552,6 +552,7 @@ GenericCAO::GenericCAO(IGameDef *gamedef, ClientEnvironment *env):
m_animated_meshnode(NULL),
m_wield_meshnode(NULL),
m_spritenode(NULL),
m_nametag_color(video::SColor(255, 255, 255, 255)),
m_textnode(NULL),
m_position(v3f(0,10*BS,0)),
m_velocity(v3f(0,0,0)),
@@ -962,7 +963,7 @@ void GenericCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
gui::IGUIEnvironment* gui = irr->getGUIEnvironment();
std::wstring wname = narrow_to_wide(m_name);
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->setPosition(v3f(0, BS*1.1, 0));
}
@@ -1714,6 +1715,11 @@ void GenericCAO::processMessage(const std::string &data)
int rating = readS16(is);
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 @@ class GenericCAO : public ClientActiveObject
scene::IAnimatedMeshSceneNode *m_animated_meshnode;
WieldMeshSceneNode *m_wield_meshnode;
scene::IBillboardSceneNode *m_spritenode;
video::SColor m_nametag_color;
scene::ITextSceneNode* m_textnode;
v3f m_position;
v3f m_velocity;
@@ -715,6 +715,8 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
m_bone_position_sent(false),
m_attachment_parent_id(0),
m_attachment_sent(false),
m_nametag_color(video::SColor(255, 255, 255, 255)),
m_nametag_sent(false),
// public
m_physics_override_speed(1),
m_physics_override_jump(1),
@@ -801,7 +803,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
writeF1000(os, m_player->getYaw());
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(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
@@ -812,6 +814,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
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_sneak_glitch)); // 5
os << serializeLongString(gob_cmd_set_nametag_color(m_nametag_color)); // 6
}
else
{
@@ -965,6 +968,14 @@ void PlayerSAO::step(float dtime, bool send_recommended)
ActiveObjectMessage aom(getId(), true, str);
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)
@@ -1144,6 +1155,17 @@ void PlayerSAO::notifyObjectPropertiesModified()
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()
{
return m_inventory;
@@ -197,6 +197,8 @@ class PlayerSAO : public ServerActiveObject
void setAttachment(int parent_id, std::string bone, v3f position, v3f rotation);
ObjectProperties* accessObjectProperties();
void notifyObjectPropertiesModified();
void setNametagColor(video::SColor color);
video::SColor getNametagColor();

/*
Inventory interface
@@ -313,6 +315,9 @@ class PlayerSAO : public ServerActiveObject
v3f m_attachment_rotation;
bool m_attachment_sent;

video::SColor m_nametag_color;
bool m_nametag_sent;

public:
float m_physics_override_speed;
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();
}

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_ATTACHMENT 8
#define GENERIC_CMD_SET_PHYSICS_OVERRIDE 9
#define GENERIC_CMD_SET_NAMETAG_COLOR 10

#include "object_properties.h"
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_set_nametag_color(video::SColor color);

#endif

@@ -1274,6 +1274,48 @@ int ObjectRef::l_override_day_night_ratio(lua_State *L)
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):
m_object(object)
{
@@ -1396,5 +1438,7 @@ const luaL_reg ObjectRef::methods[] = {
luamethod(ObjectRef, override_day_night_ratio),
luamethod(ObjectRef, set_local_animation),
luamethod(ObjectRef, set_eye_offset),
luamethod(ObjectRef, set_nametag_color),
luamethod(ObjectRef, get_nametag_color),
{0,0}
};
@@ -240,6 +240,12 @@ class ObjectRef : public ModApiBase {
// set_eye_offset(self, v3f first pv, v3f third pv)
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:
ObjectRef(ServerActiveObject *object);

0 comments on commit 86a963c

Please sign in to comment.
You can’t perform that action at this time.