forked from townforge/townforge
display chat lines above avatar heads
This commit is contained in:
parent
a5d9f1094f
commit
299fc136c9
@ -113,7 +113,8 @@ Avatar::Avatar(const Urho3D::SharedPtr<Urho3D::Node> &node, const Urho3D::Shared
|
||||
blocked_by_deep_water(false),
|
||||
water_level(0.0),
|
||||
lowest_walkable_height(0.0f),
|
||||
water_wake(SharedPtr<Node>(node->GetScene()->CreateChild("WaterWake")))
|
||||
water_wake(SharedPtr<Node>(node->GetScene()->CreateChild("WaterWake"))),
|
||||
text_ttl(0.0f)
|
||||
{
|
||||
modelNode = node->GetScene()->CreateChild("avatar");
|
||||
animationNode = modelNode->CreateChild("avatar-animation");
|
||||
@ -828,6 +829,13 @@ void Avatar::FixedUpdate(float timeStep)
|
||||
modelNode->SetPosition(Vector3(pos.x_, -100.0f, pos.z_));
|
||||
|
||||
rotation = Quaternion::IDENTITY;
|
||||
|
||||
if (text_ttl > 0.0f)
|
||||
{
|
||||
text_ttl -= timeStep;
|
||||
if (text_ttl <= 0.0f)
|
||||
SetText("");
|
||||
}
|
||||
}
|
||||
|
||||
void Avatar::Show(bool show)
|
||||
@ -912,38 +920,63 @@ void Avatar::SetDirection(const Urho3D::Vector3 &dir)
|
||||
modelNode->SetRotation(q);
|
||||
}
|
||||
|
||||
void Avatar::SetName(const std::string &s)
|
||||
std::string Avatar::MakeText3DString() const
|
||||
{
|
||||
if (s.empty() && nameNode)
|
||||
std::string s = name;
|
||||
if (!text.empty())
|
||||
{
|
||||
nameNode->Remove();
|
||||
nameNode = NULL;
|
||||
if (!s.empty())
|
||||
s += "\n\n";
|
||||
s += text;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
void Avatar::UpdateText3D()
|
||||
{
|
||||
const std::string s = MakeText3DString();
|
||||
|
||||
if (s.empty() && textNode)
|
||||
{
|
||||
textNode->Remove();
|
||||
textNode = NULL;
|
||||
}
|
||||
|
||||
name = s;
|
||||
|
||||
if (!name.empty())
|
||||
if (!s.empty())
|
||||
{
|
||||
Urho3D::Text3D *text = NULL;
|
||||
Urho3D::Text3D *text3d = NULL;
|
||||
|
||||
if (!nameNode)
|
||||
if (!textNode)
|
||||
{
|
||||
nameNode = modelNode->CreateChild("Name");
|
||||
nameNode->SetPosition(Vector3(0.0f, MODEL_HEIGHT + NAME_Y_OFFSET, -0.1f));
|
||||
nameNode->SetScale(1.0f);
|
||||
text = nameNode->CreateComponent<Text3D>();
|
||||
ResourceCache* cache = nameNode->GetSubsystem<ResourceCache>();
|
||||
text->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 24);
|
||||
text->SetColor(Color::GREEN);
|
||||
text->SetTextEffect(TE_SHADOW);
|
||||
text->SetEffectColor(Color::GRAY);
|
||||
text->SetAlignment(HA_CENTER, VA_CENTER);
|
||||
text->SetFaceCameraMode(FC_ROTATE_Y);
|
||||
textNode = modelNode->CreateChild("Text");
|
||||
textNode->SetPosition(Vector3(0.0f, MODEL_HEIGHT + NAME_Y_OFFSET, -0.1f));
|
||||
textNode->SetScale(1.0f);
|
||||
text3d = textNode->CreateComponent<Text3D>();
|
||||
ResourceCache* cache = textNode->GetSubsystem<ResourceCache>();
|
||||
text3d->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 24);
|
||||
text3d->SetColor(Color::GREEN);
|
||||
text3d->SetTextEffect(TE_SHADOW);
|
||||
text3d->SetEffectColor(Color::GRAY);
|
||||
text3d->SetAlignment(HA_CENTER, VA_CENTER);
|
||||
text3d->SetFaceCameraMode(FC_ROTATE_Y);
|
||||
}
|
||||
else
|
||||
text = nameNode->GetComponent<Text3D>();
|
||||
text3d = textNode->GetComponent<Text3D>();
|
||||
|
||||
if (text)
|
||||
text->SetText(name.c_str());
|
||||
if (text3d)
|
||||
text3d->SetText(s.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void Avatar::SetName(const std::string &s)
|
||||
{
|
||||
name = s;
|
||||
UpdateText3D();
|
||||
}
|
||||
|
||||
void Avatar::SetText(const std::string &s, float ttl)
|
||||
{
|
||||
text = s;
|
||||
text_ttl = ttl;
|
||||
UpdateText3D();
|
||||
}
|
||||
|
@ -58,6 +58,7 @@ public:
|
||||
void SetDirection(const Urho3D::Vector3 &dir);
|
||||
|
||||
void SetName(const std::string &s);
|
||||
void SetText(const std::string &s, float ttl = 0.0f);
|
||||
|
||||
private:
|
||||
enum state_t
|
||||
@ -124,6 +125,8 @@ private:
|
||||
void SetAnimationRotation(const Urho3D::Quaternion &q);
|
||||
void SetAnimationPosition(const Urho3D::Vector3 &pos);
|
||||
bool Crossing(float y0, float y1, float threshold) const;
|
||||
std::string MakeText3DString() const;
|
||||
void UpdateText3D();
|
||||
|
||||
private:
|
||||
Urho3D::SharedPtr<Urho3D::Node> node;
|
||||
@ -132,7 +135,7 @@ private:
|
||||
Urho3D::SharedPtr<Urho3D::Node> animationNode;
|
||||
Urho3D::SharedPtr<Urho3D::AnimationController> controller;
|
||||
Urho3D::SharedPtr<Urho3D::Node> collidable_root;
|
||||
Urho3D::SharedPtr<Urho3D::Node> nameNode;
|
||||
Urho3D::SharedPtr<Urho3D::Node> textNode;
|
||||
|
||||
Urho3D::Vector3 motion;
|
||||
Urho3D::Quaternion rotation;
|
||||
@ -155,4 +158,6 @@ private:
|
||||
std::vector<Urho3D::Vector3> offsets;
|
||||
|
||||
std::string name;
|
||||
std::string text;
|
||||
float text_ttl;
|
||||
};
|
||||
|
@ -9104,6 +9104,9 @@ void CryptoCityUrho3D::HandleNewChatLine(StringHash eventType, VariantMap& event
|
||||
}
|
||||
console->AddLine(prefix, source, final_line, me ? "ChatEmoteStyle" : "ChatDefaultStyle", color);
|
||||
|
||||
if (avatars)
|
||||
avatars->SetText(account_id, final_line.CString(), 10.0f);
|
||||
|
||||
if (boost::starts_with(line.CString(), gameState.get_player_name(wallet->get_cc_account())))
|
||||
mentioned_in_chat = true;
|
||||
}
|
||||
|
@ -68,6 +68,14 @@ void RemoteAvatars::Remove(uint32_t id)
|
||||
data.erase(id);
|
||||
}
|
||||
|
||||
void RemoteAvatars::SetText(uint32_t player, const std::string &text, float ttl)
|
||||
{
|
||||
auto i = data.find(player);
|
||||
if (i == data.end())
|
||||
return;
|
||||
i->second.avatar->SetText(text, ttl);
|
||||
}
|
||||
|
||||
void RemoteAvatars::Update(float timeStep)
|
||||
{
|
||||
for (auto &e: data)
|
||||
|
@ -17,6 +17,7 @@ public:
|
||||
virtual ~RemoteAvatars();
|
||||
|
||||
void SetAvatars(std::vector<std::tuple<uint32_t, Urho3D::Vector3, Urho3D::Vector3, Urho3D::Vector3, float>> &player_data, uint32_t local = 0);
|
||||
void SetText(uint32_t player, const std::string &text, float ttl);
|
||||
void Update(float timeStep);
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user