Added client translation to achievements
This commit is contained in:
parent
1de4408a18
commit
42c36429d7
@ -189,6 +189,15 @@ void cCompositeChat::AddSuggestCommandPart(const AString & a_Text, const AString
|
||||
|
||||
|
||||
|
||||
void cCompositeChat::AddShowAchievementPart(const AString & a_PlayerName, const AString & a_Achievement, const AString & a_Style)
|
||||
{
|
||||
m_Parts.push_back(new cShowAchievementPart(a_PlayerName, a_Achievement, a_Style));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cCompositeChat::ParseText(const AString & a_ParseText)
|
||||
{
|
||||
size_t len = a_ParseText.length();
|
||||
@ -476,3 +485,16 @@ cCompositeChat::cSuggestCommandPart::cSuggestCommandPart(const AString & a_Text,
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cCompositeChat::cShowAchievementPart:
|
||||
|
||||
cCompositeChat::cShowAchievementPart::cShowAchievementPart(const AString & a_PlayerName, const AString & a_Achievement, const AString & a_Style) :
|
||||
super(ptShowAchievement, a_Achievement, a_Style),
|
||||
m_PlayerName(a_PlayerName)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -38,6 +38,7 @@ public:
|
||||
ptUrl,
|
||||
ptRunCommand,
|
||||
ptSuggestCommand,
|
||||
ptShowAchievement,
|
||||
} ;
|
||||
|
||||
class cBasePart
|
||||
@ -107,6 +108,15 @@ public:
|
||||
cSuggestCommandPart(const AString & a_Text, const AString & a_Command, const AString & a_Style = "");
|
||||
} ;
|
||||
|
||||
class cShowAchievementPart :
|
||||
public cBasePart
|
||||
{
|
||||
typedef cBasePart super;
|
||||
public:
|
||||
AString m_PlayerName;
|
||||
cShowAchievementPart(const AString & a_PlayerName, const AString & a_Achievement, const AString & a_Style = "");
|
||||
} ;
|
||||
|
||||
typedef std::vector<cBasePart *> cParts;
|
||||
|
||||
// tolua_begin
|
||||
@ -149,6 +159,11 @@ public:
|
||||
The default style is underlined yellow text. */
|
||||
void AddSuggestCommandPart(const AString & a_Text, const AString & a_SuggestedCommand, const AString & a_Style = "u@b");
|
||||
|
||||
/** Adds a part that fully formats a specified achievement using client translatable strings
|
||||
Takes achievement name and player awarded to. Displays as {player} has earned the achievement {achievement_name}.
|
||||
*/
|
||||
void AddShowAchievementPart(const AString & a_PlayerName, const AString & a_Achievement, const AString & a_Style = "");
|
||||
|
||||
/** Parses text into various parts, adds those.
|
||||
Recognizes "http:" and "https:" URLs and @color-codes. */
|
||||
void ParseText(const AString & a_ParseText);
|
||||
|
@ -1169,8 +1169,8 @@ unsigned int cPlayer::AwardAchievement(const eStatistic a_Ach)
|
||||
{
|
||||
// First time, announce it
|
||||
cCompositeChat Msg;
|
||||
Msg.AddTextPart(m_PlayerName + " has just earned the achievement ");
|
||||
Msg.AddTextPart(cStatInfo::GetName(a_Ach)); // TODO 2014-05-12 xdot: Use the proper cCompositeChat part (cAchievement)
|
||||
Msg.SetMessageType(mtSuccess);
|
||||
Msg.AddShowAchievementPart(GetName(), cStatInfo::GetName(a_Ach));
|
||||
m_World->BroadcastChat(Msg);
|
||||
|
||||
// Increment the statistic
|
||||
@ -1788,7 +1788,7 @@ bool cPlayer::SaveToDisk()
|
||||
|
||||
// Save the player stats.
|
||||
// We use the default world name (like bukkit) because stats are shared between dimensions/worlds.
|
||||
cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetName(), m_PlayerName, &m_Stats);
|
||||
cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetName(), GetName(), &m_Stats);
|
||||
if (!StatSerializer.Save())
|
||||
{
|
||||
LOGERROR("Could not save stats for player %s", m_PlayerName.c_str());
|
||||
@ -1963,7 +1963,7 @@ void cPlayer::UpdateMovementStats(const Vector3d & a_DeltaPos)
|
||||
|
||||
BLOCKTYPE Block;
|
||||
NIBBLETYPE Meta;
|
||||
if (!m_World->GetBlockTypeMeta(PosX, PosY, PosZ, Block, Meta))
|
||||
if ((PosY < 0) || (PosY > cChunkDef::Height) || !m_World->GetBlockTypeMeta(PosX, PosY, PosZ, Block, Meta))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -289,6 +289,35 @@ void cProtocol172::SendChat(const cCompositeChat & a_Message)
|
||||
AddChatPartStyle(Part, p.m_Style);
|
||||
break;
|
||||
}
|
||||
|
||||
case cCompositeChat::ptShowAchievement:
|
||||
{
|
||||
const cCompositeChat::cShowAchievementPart & p = (const cCompositeChat::cShowAchievementPart &)**itr;
|
||||
Part["translate"] = "chat.type.achievement";
|
||||
|
||||
Json::Value Ach;
|
||||
Ach["action"] = "show_achievement";
|
||||
Ach["value"] = p.m_Text;
|
||||
|
||||
Json::Value AchColourAndName;
|
||||
AchColourAndName["color"] = "green";
|
||||
AchColourAndName["translate"] = p.m_Text;
|
||||
AchColourAndName["hoverEvent"] = Ach;
|
||||
|
||||
Json::Value Extra;
|
||||
Extra.append(AchColourAndName);
|
||||
|
||||
Json::Value Name;
|
||||
Name["text"] = p.m_PlayerName;
|
||||
|
||||
Json::Value With;
|
||||
With.append(Name);
|
||||
With.append(Extra);
|
||||
|
||||
Part["with"] = With;
|
||||
AddChatPartStyle(Part, p.m_Style);
|
||||
break;
|
||||
}
|
||||
}
|
||||
msg["extra"].append(Part);
|
||||
} // for itr - Parts[]
|
||||
|
Loading…
Reference in New Issue
Block a user