瀏覽代碼

Merge pull request #2687 from Nordsoft91/filledTexturePlayerColored

Support FilledTexturePlayerColored in configurable interface
Ivan Savenko 2 年之前
父節點
當前提交
a59d7b5fc9
共有 2 個文件被更改,包括 19 次插入0 次删除
  1. 18 0
      client/gui/InterfaceObjectConfigurable.cpp
  2. 1 0
      client/gui/InterfaceObjectConfigurable.h

+ 18 - 0
client/gui/InterfaceObjectConfigurable.cpp

@@ -29,6 +29,7 @@
 #include "../windows/GUIClasses.h"
 #include "../windows/InfoWindows.h"
 
+#include "../../lib//constants/StringConstants.h"
 #include "../../lib/CGeneralTextHandler.h"
 #include "../../lib/filesystem/ResourceID.h"
 
@@ -228,8 +229,19 @@ ColorRGBA InterfaceObjectConfigurable::readColor(const JsonNode & config) const
 	}
 	logGlobal->debug("Uknown color attribute");
 	return Colors::DEFAULT_KEY_COLOR;
+
+}
+
+PlayerColor InterfaceObjectConfigurable::readPlayerColor(const JsonNode & config) const
+{
+	logGlobal->debug("Reading PlayerColor");
+	if(!config.isNull() && config.isString())
+		return PlayerColor(vstd::find_pos(GameConstants::PLAYER_COLOR_NAMES, config.String()));
 	
+	logGlobal->debug("Unknown PlayerColor attribute");
+	return PlayerColor::CANNOT_DETERMINE;
 }
+
 EFonts InterfaceObjectConfigurable::readFont(const JsonNode & config) const
 {
 	logGlobal->debug("Reading font");
@@ -519,6 +531,12 @@ std::shared_ptr<CFilledTexture> InterfaceObjectConfigurable::buildTexture(const
 	logGlobal->debug("Building widget CFilledTexture");
 	auto image = config["image"].String();
 	auto rect = readRect(config["rect"]);
+	auto playerColor = readPlayerColor(config["color"]);
+	if(playerColor.isValidPlayer())
+	{
+		auto result = std::make_shared<FilledTexturePlayerColored>(image, rect);
+		result->playerColored(playerColor);
+	}
 	return std::make_shared<CFilledTexture>(image, rect);
 }
 

+ 1 - 0
client/gui/InterfaceObjectConfigurable.h

@@ -83,6 +83,7 @@ protected:
 	std::string readText(const JsonNode &) const;
 	std::pair<std::string, std::string> readHintText(const JsonNode &) const;
 	EShortcut readHotkey(const JsonNode &) const;
+	PlayerColor readPlayerColor(const JsonNode &) const;
 	
 	void loadToggleButtonCallback(std::shared_ptr<CToggleButton> button, const JsonNode & config) const;
 	void loadButtonCallback(std::shared_ptr<CButton> button, const JsonNode & config) const;