浏览代码

Changed configurable UI to match text refactoring:

- help.txt strings are now loaded as (hover, help) pairs
- renamed string pairs from translate.json to use (hover, help) form
- interface builder will always load label texts via unified ID
- interface builder way of loading buttons text has been changed:
- - field has been renamed "zelp" -> "help" for consistency
- - "help" field now only accepts string or object json type
Ivan Savenko 2 年之前
父节点
当前提交
01d0cd4f7a

+ 7 - 21
client/gui/InterfaceObjectConfigurable.cpp

@@ -84,16 +84,7 @@ std::string InterfaceObjectConfigurable::readText(const JsonNode & config) const
 	if(config.isNull())
 		return "";
 	
-	if(config.isNumber())
-	{
-		logGlobal->debug("Reading text from generaltext handler id:%d", config.Integer());
-		return CGI->generaltexth->allTexts[config.Integer()];
-	}
-	
-	const std::string delimiter = "/";
 	std::string s = config.String();
-	boost::replace_all(s, "/", "." );
-
 	logGlobal->debug("Reading text from translations by key: %s", s);
 	return CGI->generaltexth->translate(s);
 }
@@ -180,12 +171,6 @@ std::pair<std::string, std::string> InterfaceObjectConfigurable::readHintText(co
 	std::pair<std::string, std::string> result;
 	if(!config.isNull())
 	{
-		if(config.isNumber())
-		{
-			logGlobal->debug("Reading hint text (zelp) from generaltext handler id:%d", config.Integer());
-			return CGI->generaltexth->zelp[config.Integer()];
-		}
-		
 		if(config.getType() == JsonNode::JsonType::DATA_STRUCT)
 		{
 			result.first = readText(config["hover"]);
@@ -194,8 +179,9 @@ std::pair<std::string, std::string> InterfaceObjectConfigurable::readHintText(co
 		}
 		if(config.getType() == JsonNode::JsonType::DATA_STRING)
 		{
-			logGlobal->debug("Reading non-translated hint: %s", config.String());
-			result.first = result.second = config.String();
+			logGlobal->debug("Reading hint text (help) from generaltext handler:%sd", config.String());
+			result.first  = CGI->generaltexth->translate( config.String() + ".hover");
+			result.second = CGI->generaltexth->translate( config.String() + ".help");
 		}
 	}
 	return result;
@@ -251,8 +237,8 @@ std::shared_ptr<CToggleButton> InterfaceObjectConfigurable::buildToggleButton(co
 	logGlobal->debug("Building widget CToggleButton");
 	auto position = readPosition(config["position"]);
 	auto image = config["image"].String();
-	auto zelp = readHintText(config["zelp"]);
-	auto button = std::make_shared<CToggleButton>(position, image, zelp);
+	auto help = readHintText(config["help"]);
+	auto button = std::make_shared<CToggleButton>(position, image, help);
 	if(!config["selected"].isNull())
 		button->setSelected(config["selected"].Bool());
 	if(!config["imageOrder"].isNull())
@@ -271,8 +257,8 @@ std::shared_ptr<CButton> InterfaceObjectConfigurable::buildButton(const JsonNode
 	logGlobal->debug("Building widget CButton");
 	auto position = readPosition(config["position"]);
 	auto image = config["image"].String();
-	auto zelp = readHintText(config["zelp"]);
-	auto button = std::make_shared<CButton>(position, image, zelp);
+	auto help = readHintText(config["help"]);
+	auto button = std::make_shared<CButton>(position, image, help);
 	if(!config["items"].isNull())
 	{
 		for(const auto & item : config["items"].Vector())

+ 1 - 1
client/widgets/Buttons.cpp

@@ -289,7 +289,7 @@ std::pair<std::string, std::string> CButton::tooltip()
 std::pair<std::string, std::string> CButton::tooltipLocalized(const std::string & key)
 {
 	return std::make_pair(
-		CGI->generaltexth->translate(key + ".label"),
+		CGI->generaltexth->translate(key + ".hover"),
 		CGI->generaltexth->translate(key + ".help")
 	);
 }

+ 8 - 8
config/translate.json

@@ -23,11 +23,11 @@
 	"vcmi.server.errors.modsIncompatibility" : "Required mods to load game:",
 	"vcmi.server.confirmReconnect"          : "Connect to the last session?",
 
-	"vcmi.systemOptions.fullscreenButton.label" : "Fullscreen",
+	"vcmi.systemOptions.fullscreenButton.hover" : "Fullscreen",
 	"vcmi.systemOptions.fullscreenButton.help"  : "{Fullscreen}\n\n If selected, VCMI will run in fullscreen mode, othervice VCMI will run in window",
-	"vcmi.systemOptions.resolutionButton.label" : "Resolution",
+	"vcmi.systemOptions.resolutionButton.hover" : "Resolution",
 	"vcmi.systemOptions.resolutionButton.help"  : "{Select resolution}\n\n Change in-game screen resolution. Game restart required to apply new resolution.",
-	"vcmi.systemOptions.resolutionMenu.label"   : "Select resolution",
+	"vcmi.systemOptions.resolutionMenu.hover"   : "Select resolution",
 	"vcmi.systemOptions.resolutionMenu.help"    : "Change in-game screen resolution.",
 
 	"vcmi.townHall.missingBase"             : "Base building %s must be built first",
@@ -48,19 +48,19 @@
 	"vcmi.logicalExpressions.allOf"  : "All of the following:",
 	"vcmi.logicalExpressions.noneOf" : "None of the following:",
 
-	"vcmi.heroWindow.openCommander.label" : "Open commander window",
+	"vcmi.heroWindow.openCommander.hover" : "Open commander window",
 	"vcmi.heroWindow.openCommander.help"  : "Displays information about commander of this hero",
 
 	"vcmi.commanderWindow.artifactMessage" : "Do you want to give this artifact back to hero?",
 
-	"vcmi.creatureWindow.showBonuses.label"    : "Switch to bonuses view",
+	"vcmi.creatureWindow.showBonuses.hover"    : "Switch to bonuses view",
 	"vcmi.creatureWindow.showBonuses.help"     : "Displays all active bonuses of the commander",
-	"vcmi.creatureWindow.showSkills.label"     : "Switch to skills view",
+	"vcmi.creatureWindow.showSkills.hover"     : "Switch to skills view",
 	"vcmi.creatureWindow.showSkills.help"      : "Displays all learned skills of the commander",
-	"vcmi.creatureWindow.returnArtifact.label" : "Give back artifact",
+	"vcmi.creatureWindow.returnArtifact.hover" : "Give back artifact",
 	"vcmi.creatureWindow.returnArtifact.help"  : "Use this button to return stack artifact back into hero backpack",
 
-	"vcmi.questLog.hideComplete.label" : "Hide complete quests",
+	"vcmi.questLog.hideComplete.hover" : "Hide complete quests",
 	"vcmi.questLog.hideComplete.help"  : "Hide all quests that already completed",
 
 	"vcmi.randomMapTab.widgets.defaultTemplate"      : "default",

+ 57 - 57
config/widgets/randomMapTab.json

@@ -14,7 +14,7 @@
 			"font": "big",
 			"alignment": "center",
 			"color": "yellow",
-			"text": 738,
+			"text": "core.genrltxt.738",
 			"position": {"x": 222, "y": 36}
 		},
 
@@ -24,7 +24,7 @@
 			"font": "small",
 			"alignment": "center",
 			"color": "white",
-			"text": 739,
+			"text": "core.genrltxt.739",
 			"position": {"x": 222, "y": 56}
 		},
 
@@ -34,7 +34,7 @@
 			"font": "small",
 			"alignment": "center",
 			"color": "white",
-			"text": 752,
+			"text": "core.genrltxt.752",
 			"position": {"x": 104, "y": 97}
 		},
 
@@ -48,7 +48,7 @@
 					"index": 0,
 					"type": "toggleButton",
 					"image": "RANSIZS",
-					"zelp": 198,
+					"help": "core.help.198",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 0, "y": 0},
 				},
@@ -56,7 +56,7 @@
 				{
 					"type": "toggleButton",
 					"image": "RANSIZM",
-					"zelp": 199,
+					"help": "core.help.199",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 47, "y": 0},
 				},
@@ -64,7 +64,7 @@
 				{
 					"type": "toggleButton",
 					"image": "RANSIZL",
-					"zelp": 200,
+					"help": "core.help.200",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 94, "y": 0},
 				},
@@ -72,7 +72,7 @@
 				{
 					"type": "toggleButton",
 					"image": "RANSIZX",
-					"zelp": 201,
+					"help": "core.help.201",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 141, "y": 0}
 				}
@@ -100,56 +100,56 @@
 					"index": 1,
 					"type": "toggleButton",
 					"image": "RANNUM1",
-					"zelp": 204,
+					"help": "core.help.204",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 0, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM2",
-					"zelp": 205,
+					"help": "core.help.205",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 32, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM3",
-					"zelp": 206,
+					"help": "core.help.206",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 64, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM4",
-					"zelp": 207,
+					"help": "core.help.207",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 96, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM5",
-					"zelp": 208,
+					"help": "core.help.208",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 128, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM6",
-					"zelp": 209,
+					"help": "core.help.209",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 160, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM7",
-					"zelp": 210,
+					"help": "core.help.210",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 192, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM8",
-					"zelp": 211,
+					"help": "core.help.211",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 224, "y": 0}
 				},
@@ -157,7 +157,7 @@
 					"index": -1,
 					"type": "toggleButton",
 					"image": "RANRAND",
-					"zelp": 212,
+					"help": "core.help.212",
 					"position": {"x": 256, "y": 0},
 				}
 			],
@@ -175,56 +175,56 @@
 					"index": 0,
 					"type": "toggleButton",
 					"image": "RANNUM0",
-					"zelp": 214,
+					"help": "core.help.214",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 0, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM1",
-					"zelp": 215,
+					"help": "core.help.215",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 32, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM2",
-					"zelp": 216,
+					"help": "core.help.216",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 64, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM3",
-					"zelp": 217,
+					"help": "core.help.217",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 96, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM4",
-					"zelp": 218,
+					"help": "core.help.218",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 128, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM5",
-					"zelp": 219,
+					"help": "core.help.219",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 160, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM6",
-					"zelp": 220,
+					"help": "core.help.220",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 192, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM7",
-					"zelp": 221,
+					"help": "core.help.221",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 224, "y": 0}
 				},
@@ -232,7 +232,7 @@
 					"index": -1,
 					"type": "toggleButton",
 					"image": "RANRAND",
-					"zelp": 222,
+					"help": "core.help.222",
 					"position": {"x": 256, "y": 0},
 				}
 			],
@@ -250,56 +250,56 @@
 					"index": 0,
 					"type": "toggleButton",
 					"image": "RANNUM0",
-					"zelp": 224,
+					"help": "core.help.224",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 0, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM1",
-					"zelp": 225,
+					"help": "core.help.225",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 32, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM2",
-					"zelp": 226,
+					"help": "core.help.226",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 64, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM3",
-					"zelp": 227,
+					"help": "core.help.227",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 96, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM4",
-					"zelp": 228,
+					"help": "core.help.228",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 128, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM5",
-					"zelp": 229,
+					"help": "core.help.229",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 160, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM6",
-					"zelp": 230,
+					"help": "core.help.230",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 192, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM7",
-					"zelp": 231,
+					"help": "core.help.231",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 224, "y": 0}
 				},
@@ -307,7 +307,7 @@
 					"index": -1,
 					"type": "toggleButton",
 					"image": "RANRAND",
-					"zelp": 232,
+					"help": "core.help.232",
 					"position": {"x": 256, "y": 0},
 				}
 			],
@@ -325,49 +325,49 @@
 					"index": 0,
 					"type": "toggleButton",
 					"image": "RANNUM0",
-					"zelp": 234,
+					"help": 234,
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 0, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM1",
-					"zelp": 235,
+					"help": "core.help.235",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 32, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM2",
-					"zelp": 236,
+					"help": "core.help.236",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 64, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM3",
-					"zelp": 237,
+					"help": "core.help.237",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 96, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM4",
-					"zelp": 238,
+					"help": "core.help.238",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 128, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM5",
-					"zelp": 239,
+					"help": "core.help.239",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 160, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNUM6",
-					"zelp": 240,
+					"help": "core.help.240",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 192, "y": 0}
 				},
@@ -375,7 +375,7 @@
 					"index": -1,
 					"type": "toggleButton",
 					"image": "RANRAND",
-					"zelp": 241,
+					"help": "core.help.241",
 					"position": {"x": 256, "y": 0},
 				}
 			],
@@ -393,21 +393,21 @@
 					"index": 0,
 					"type": "toggleButton",
 					"image": "RANNONE",
-					"zelp": 243,
+					"help": "core.help.243",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 0, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANNORM",
-					"zelp": 244,
+					"help": "core.help.244",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 85, "y": 0}
 				},
 				{
 					"type": "toggleButton",
 					"image": "RANISLD",
-					"zelp": 245,
+					"help": "core.help.245",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 170, "y": 0}
 				},
@@ -415,7 +415,7 @@
 					"index": -1,
 					"type": "toggleButton",
 					"image": "RANRAND",
-					"zelp": 246,
+					"help": "core.help.246",
 					"position": {"x": 256, "y": 0},
 				}
 			],
@@ -433,7 +433,7 @@
 					"index": 2,
 					"type": "toggleButton",
 					"image": "RANWEAK",
-					"zelp": 248,
+					"help": "core.help.248",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 0, "y": 0}
 				},
@@ -441,7 +441,7 @@
 					"index": 3,
 					"type": "toggleButton",
 					"image": "RANNORM",
-					"zelp": 249,
+					"help": "core.help.249",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 85, "y": 0}
 				},
@@ -449,7 +449,7 @@
 					"index": 4,
 					"type": "toggleButton",
 					"image": "RANSTRG",
-					"zelp": 250,
+					"help": "core.help.250",
 					"imageOrder": [0, 1, 1, 3],
 					"position": {"x": 170, "y": 0}
 				},
@@ -457,7 +457,7 @@
 					"index": -2,
 					"type": "toggleButton",
 					"image": "RANRAND",
-					"zelp": 251,
+					"help": "core.help.251",
 					"position": {"x": 256, "y": 0},
 				}
 			],
@@ -470,7 +470,7 @@
 			"type": "button",
 			"position": {"x": 54, "y": 535},
 			"image": "RANSHOW",
-			"zelp": 252
+			"help": "core.help.252"
 		},
 
 		{
@@ -482,27 +482,27 @@
 			[
 				{
 					"position": {"x": 68, "y": 133},
-					"text": 753
+					"text": "core.genrltxt.753"
 				},
 				{
 					"position": {"x": 68, "y": 199},
-					"text": 754
+					"text": "core.genrltxt.754"
 				},
 				{
 					"position": {"x": 68, "y": 265},
-					"text": 755
+					"text": "core.genrltxt.755"
 				},
 				{
 					"position": {"x": 68, "y": 331},
-					"text": 756
+					"text": "core.genrltxt.756"
 				},
 				{
 					"position": {"x": 68, "y": 398},
-					"text": 757
+					"text": "core.genrltxt.757"
 				},
 				{
 					"position": {"x": 68, "y": 465},
-					"text": 758
+					"text": "core.genrltxt.758"
 				}
 			]
 		}

+ 2 - 2
lib/CGeneralTextHandler.cpp

@@ -448,7 +448,7 @@ CGeneralTextHandler::CGeneralTextHandler():
 		{
 			std::string first = parser.readString();
 			std::string second = parser.readString();
-			registerString("core.help." + std::to_string(index) + ".label", first);
+			registerString("core.help." + std::to_string(index) + ".hover", first);
 			registerString("core.help." + std::to_string(index) + ".help",  second);
 			index += 1;
 		}
@@ -631,7 +631,7 @@ LegacyHelpContainer::LegacyHelpContainer(CGeneralTextHandler & owner, std::strin
 std::pair<std::string, std::string> LegacyHelpContainer::operator[](size_t index) const
 {
 	return {
-		owner.translate(basePath + "." + std::to_string(index) + ".label"),
+		owner.translate(basePath + "." + std::to_string(index) + ".hover"),
 		owner.translate(basePath + "." + std::to_string(index) + ".help")
 	};
 }