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)
|
void cCompositeChat::ParseText(const AString & a_ParseText)
|
||||||
{
|
{
|
||||||
size_t len = a_ParseText.length();
|
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,
|
ptUrl,
|
||||||
ptRunCommand,
|
ptRunCommand,
|
||||||
ptSuggestCommand,
|
ptSuggestCommand,
|
||||||
|
ptShowAchievement,
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
class cBasePart
|
class cBasePart
|
||||||
|
@ -106,6 +107,15 @@ public:
|
||||||
public:
|
public:
|
||||||
cSuggestCommandPart(const AString & a_Text, const AString & a_Command, const AString & a_Style = "");
|
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;
|
typedef std::vector<cBasePart *> cParts;
|
||||||
|
|
||||||
|
@ -148,6 +158,11 @@ public:
|
||||||
/** Adds a part that suggests a command (enters it into the chat message area, but doesn't send) when clicked.
|
/** Adds a part that suggests a command (enters it into the chat message area, but doesn't send) when clicked.
|
||||||
The default style is underlined yellow text. */
|
The default style is underlined yellow text. */
|
||||||
void AddSuggestCommandPart(const AString & a_Text, const AString & a_SuggestedCommand, const AString & a_Style = "u@b");
|
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.
|
/** Parses text into various parts, adds those.
|
||||||
Recognizes "http:" and "https:" URLs and @color-codes. */
|
Recognizes "http:" and "https:" URLs and @color-codes. */
|
||||||
|
|
|
@ -1169,8 +1169,8 @@ unsigned int cPlayer::AwardAchievement(const eStatistic a_Ach)
|
||||||
{
|
{
|
||||||
// First time, announce it
|
// First time, announce it
|
||||||
cCompositeChat Msg;
|
cCompositeChat Msg;
|
||||||
Msg.AddTextPart(m_PlayerName + " has just earned the achievement ");
|
Msg.SetMessageType(mtSuccess);
|
||||||
Msg.AddTextPart(cStatInfo::GetName(a_Ach)); // TODO 2014-05-12 xdot: Use the proper cCompositeChat part (cAchievement)
|
Msg.AddShowAchievementPart(GetName(), cStatInfo::GetName(a_Ach));
|
||||||
m_World->BroadcastChat(Msg);
|
m_World->BroadcastChat(Msg);
|
||||||
|
|
||||||
// Increment the statistic
|
// Increment the statistic
|
||||||
|
@ -1788,7 +1788,7 @@ bool cPlayer::SaveToDisk()
|
||||||
|
|
||||||
// Save the player stats.
|
// Save the player stats.
|
||||||
// We use the default world name (like bukkit) because stats are shared between dimensions/worlds.
|
// 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())
|
if (!StatSerializer.Save())
|
||||||
{
|
{
|
||||||
LOGERROR("Could not save stats for player %s", m_PlayerName.c_str());
|
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;
|
BLOCKTYPE Block;
|
||||||
NIBBLETYPE Meta;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -289,6 +289,35 @@ void cProtocol172::SendChat(const cCompositeChat & a_Message)
|
||||||
AddChatPartStyle(Part, p.m_Style);
|
AddChatPartStyle(Part, p.m_Style);
|
||||||
break;
|
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);
|
msg["extra"].append(Part);
|
||||||
} // for itr - Parts[]
|
} // for itr - Parts[]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user