Ver código fonte

PlayerColor: add getStr and getStrCap functions with optional L10n

Arseniy Shestakov 9 anos atrás
pai
commit
fdca75b4b0
2 arquivos alterados com 31 adições e 0 exclusões
  1. 28 0
      lib/GameConstants.cpp
  2. 3 0
      lib/GameConstants.h

+ 28 - 0
lib/GameConstants.cpp

@@ -17,6 +17,8 @@
 #include "CArtHandler.h"
 #include "CCreatureHandler.h"
 #include "spells/CSpellHandler.h"
+#include "StringConstants.h"
+#include "CGeneralTextHandler.h"
 
 const SlotID SlotID::COMMANDER_SLOT_PLACEHOLDER = SlotID(-2);
 const SlotID SlotID::SUMMONED_SLOT_PLACEHOLDER = SlotID(-3);
@@ -57,6 +59,32 @@ bool PlayerColor::isValidPlayer() const
 	return num < PLAYER_LIMIT_I;
 }
 
+std::string PlayerColor::getStr(bool L10n) const
+{
+	std::string ret = "unnamed";
+	if(isValidPlayer())
+	{
+		if(L10n)
+			ret = VLC->generaltexth->colors[num];
+		else
+			ret = GameConstants::PLAYER_COLOR_NAMES[num];
+	}
+	else if(L10n)
+	{
+		ret = VLC->generaltexth->allTexts[508];
+		ret[0] = std::tolower(ret[0]);
+	}
+
+	return ret;
+}
+
+std::string PlayerColor::getStrCap(bool L10n) const
+{
+	std::string ret = getStr(L10n);
+	ret[0] = std::toupper(ret[0]);
+	return ret;
+}
+
 std::ostream & operator<<(std::ostream & os, const Battle::ActionType actionType)
 {
 	static const std::map<Battle::ActionType, std::string> actionTypeToString =

+ 3 - 0
lib/GameConstants.h

@@ -262,6 +262,9 @@ class PlayerColor : public BaseForID<PlayerColor, ui8>
 
 	DLL_LINKAGE bool isValidPlayer() const; //valid means < PLAYER_LIMIT (especially non-neutral)
 
+	std::string getStr(bool L10n = false) const;
+	std::string getStrCap(bool L10n = false) const;
+
 	friend class CGameInfoCallback;
 	friend class CNonConstInfoCallback;
 };