aboutsummaryrefslogtreecommitdiff
path: root/extension/src
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2024-09-19 00:12:41 +0200
committer hop311 <hop3114@gmail.com>2024-09-20 14:21:53 +0200
commitb78093041d877ef30c2d17878cc03fd30c4b229c (patch)
treea7959840d5332abbbbeeef24a6322b215d1beaeb /extension/src
parentc26247464feabe0fbb9d6a8527b242d667faa066 (diff)
Add RuleSet and ModifierValue tooltip making functionsrule-modifier-tooltips
Diffstat (limited to 'extension/src')
-rw-r--r--extension/src/openvic-extension/classes/GUILabel.cpp11
-rw-r--r--extension/src/openvic-extension/singletons/MenuSingleton.cpp87
-rw-r--r--extension/src/openvic-extension/singletons/MenuSingleton.hpp5
3 files changed, 102 insertions, 1 deletions
diff --git a/extension/src/openvic-extension/classes/GUILabel.cpp b/extension/src/openvic-extension/classes/GUILabel.cpp
index 7e93f01..3c7cfed 100644
--- a/extension/src/openvic-extension/classes/GUILabel.cpp
+++ b/extension/src/openvic-extension/classes/GUILabel.cpp
@@ -523,7 +523,16 @@ String GUILabel::generate_substituted_text(String const& base_text) const {
String value = substitution_dict.get(key, String {});
// Use the un-substituted key if no value is found or the value is empty
- result += value.is_empty() ? key : is_auto_translating() ? tr(value) : value;
+ if (value.is_empty()) {
+ value = key;
+ }
+
+ // Translate the value if auto-translating (even if it's the key after a failed substitution)
+ if (is_auto_translating()) {
+ value = tr(value);
+ }
+
+ result += value;
start_pos = marker_end_pos + get_substitution_marker().length();
}
diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.cpp b/extension/src/openvic-extension/singletons/MenuSingleton.cpp
index 5074507..c4b704d 100644
--- a/extension/src/openvic-extension/singletons/MenuSingleton.cpp
+++ b/extension/src/openvic-extension/singletons/MenuSingleton.cpp
@@ -3,6 +3,7 @@
#include <godot_cpp/variant/utility_functions.hpp>
#include <openvic-simulation/GameManager.hpp>
+#include <openvic-simulation/misc/Modifier.hpp>
#include "openvic-extension/classes/GFXPieChartTexture.hpp"
#include "openvic-extension/classes/GUINode.hpp"
@@ -106,6 +107,92 @@ String MenuSingleton::get_country_adjective(CountryInstance const& country) cons
return tr(Utilities::std_to_godot_string(StringUtils::append_string_views(country.get_identifier(), adjective)));
}
+String MenuSingleton::make_modifier_effects_tooltip(ModifierValue const& modifier) const {
+ if (modifier.empty()) {
+ return {};
+ }
+
+ String result;
+
+ for (auto const& [effect, value] : modifier.get_values()) {
+ if (!result.is_empty()) {
+ result += "\n";
+ }
+
+ result += tr(Utilities::std_to_godot_string(effect->get_localisation_key()));
+
+ static const String post_name_text = ": " + GUILabel::get_colour_marker();
+ result += post_name_text;
+
+ if (value == 0) {
+ result += "Y";
+ } else if (effect->is_positive_good() == value > 0) {
+ result += "G";
+ } else {
+ result += "R";
+ }
+
+ if (value >= 0) {
+ result += "+";
+ }
+
+ static constexpr int32_t DECIMAL_PLACES = 2;
+
+ using enum ModifierEffect::format_t;
+
+ switch (effect->get_format()) {
+ case PROPORTION_DECIMAL:
+ result += GUINode::float_to_string_dp((value * 100).to_float(), DECIMAL_PLACES) + "%";
+ break;
+ case PERCENTAGE_DECIMAL:
+ result += GUINode::float_to_string_dp(value.to_float(), DECIMAL_PLACES) + "%";
+ break;
+ case INT:
+ result += String::num_int64(value.to_int64_t());
+ break;
+ case RAW_DECIMAL: [[fallthrough]];
+ default: // Use raw decimal as fallback format
+ result += GUINode::float_to_string_dp(value.to_float(), DECIMAL_PLACES);
+ break;
+ }
+
+ static const String end_text = GUILabel::get_colour_marker() + String { "!" };
+ result += end_text;
+ }
+
+ return result;
+}
+
+String MenuSingleton::make_rules_tooltip(RuleSet const& rules) const {
+ if (rules.empty()) {
+ return {};
+ }
+
+ static const StringName yes_key = "YES";
+ static const StringName no_key = "NO";
+
+ static const String start_text = ": " + GUILabel::get_colour_marker();
+ static const String end_text = GUILabel::get_colour_marker() + String { "!" };
+
+ const String enabled_text = start_text + String { "G" } + tr(yes_key) + end_text;
+ const String disabled_text = start_text + String { "R" } + tr(no_key) + end_text;
+
+ String result;
+
+ for (auto const& [rule_group, rule_map] : rules.get_rule_groups()) {
+ for (auto const& [rule, enabled] : rule_map) {
+ if (!result.is_empty()) {
+ result += "\n";
+ }
+
+ result += tr(Utilities::std_to_godot_string(rule->get_localisation_key()))
+ + (enabled ? enabled_text : disabled_text);
+ }
+ }
+
+ return result;
+}
+
void MenuSingleton::_bind_methods() {
OV_BIND_SMETHOD(get_tooltip_separator);
OV_BIND_METHOD(MenuSingleton::get_country_name_from_identifier, { "country_identifier" });
diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.hpp b/extension/src/openvic-extension/singletons/MenuSingleton.hpp
index 3f07583..97a6956 100644
--- a/extension/src/openvic-extension/singletons/MenuSingleton.hpp
+++ b/extension/src/openvic-extension/singletons/MenuSingleton.hpp
@@ -11,6 +11,8 @@ namespace OpenVic {
struct CountryInstance;
struct State;
struct ProvinceInstance;
+ struct ModifierValue;
+ struct RuleSet;
class MenuSingleton : public godot::Object {
GDCLASS(MenuSingleton, godot::Object)
@@ -105,6 +107,9 @@ namespace OpenVic {
godot::String get_country_name(CountryInstance const& country) const;
godot::String get_country_adjective(CountryInstance const& country) const;
+ godot::String make_modifier_effects_tooltip(ModifierValue const& modifier) const;
+ godot::String make_rules_tooltip(RuleSet const& rules) const;
+
protected:
static void _bind_methods();