diff options
Diffstat (limited to 'extension/src')
6 files changed, 146 insertions, 29 deletions
diff --git a/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp b/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp index 3610efb..69330a4 100644 --- a/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp +++ b/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp @@ -45,7 +45,7 @@ namespace OpenVic { * - weight: float */ godot::Error set_slices_array(godot_pie_chart_data_t const& new_slices); - /* Generate slice data from a distribution of HasIdentifierAndColour derived objects, sorted by their weight. + /* Generate slice data from a distribution of objects satisfying HasGetIdentifierAndGetColour, sorted by their weight. * The resulting Array of Dictionaries can be used as an argument for set_slices_array. */ template<typename Container> static godot_pie_chart_data_t distribution_to_slices_array(Container const& dist) @@ -53,17 +53,18 @@ namespace OpenVic { ( /* fixed_point_map_t<T const*>, T derived from HasIdentifierAndColour */ utility::is_specialization_of_v<Container, tsl::ordered_map> && - std::derived_from<std::remove_pointer_t<typename Container::key_type>, HasIdentifierAndColour> && + HasGetIdentifierAndGetColour<std::remove_pointer_t<typename Container::key_type>> && std::is_same_v<typename Container::mapped_type, fixed_point_t> ) || ( /* IndexedMap<T, fixed_point_t>, T derived from HasIdentifierAndColour */ utility::is_specialization_of_v<Container, IndexedMap> && - std::derived_from<typename Container::key_t, HasIdentifierAndColour> && + HasGetIdentifierAndGetColour<typename Container::key_type> && std::is_same_v<typename Container::value_t, fixed_point_t> ) ) { using namespace godot; - using entry_t = std::pair<HasIdentifierAndColour const*, fixed_point_t>; + using key_type = std::remove_pointer_t<typename Container::key_type>; + using entry_t = std::pair<key_type const*, fixed_point_t>; std::vector<entry_t> sorted_dist; if constexpr (utility::is_specialization_of_v<Container, tsl::ordered_map>) { @@ -78,7 +79,7 @@ namespace OpenVic { for (size_t index = 0; index < dist.size(); ++index) { fixed_point_t const& value = dist[index]; if (value != 0) { - HasIdentifierAndColour const* key = &dist(index); + key_type const* key = &dist(index); sorted_dist.emplace_back(key, value); } } 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..3ea3aa2 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/modifier/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" }); @@ -611,7 +698,10 @@ Dictionary MenuSingleton::get_topbar_info() const { // TODO - colonial power info ret[colonial_power_available_key] = 0; ret[colonial_power_max_key] = 0; - ret[colonial_power_tooltip_key] = String {}; + ret[colonial_power_tooltip_key] = + // TODO - remove these examples eventually + // make_rules_tooltip(country->get_rule_set()) + get_tooltip_separator() + + make_modifier_effects_tooltip(country->get_modifier_sum().get_value_sum()); // Production diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.hpp b/extension/src/openvic-extension/singletons/MenuSingleton.hpp index 3f07583..0dcc8ff 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) @@ -57,7 +59,12 @@ namespace OpenVic { * - Nationality (Culture) * - Issues * - Vote */ - std::array<fixed_point_map_t<HasIdentifierAndColour const*>, DISTRIBUTION_COUNT> distributions; + fixed_point_map_t<PopType const*> workforce_distribution; + fixed_point_map_t<Religion const*> religion_distribution; + fixed_point_map_t<Ideology const*> ideology_distribution; + fixed_point_map_t<Culture const*> culture_distribution; + fixed_point_map_t<Issue const*> issue_distribution; + fixed_point_map_t<CountryParty const*> vote_distribution; enum PopSortKey { NONE, SORT_SIZE, SORT_TYPE, SORT_CULTURE, SORT_RELIGION, SORT_LOCATION, SORT_MILITANCY, SORT_CONSCIOUSNESS, @@ -105,6 +112,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(); diff --git a/extension/src/openvic-extension/singletons/PopulationMenu.cpp b/extension/src/openvic-extension/singletons/PopulationMenu.cpp index c96ef02..1bef050 100644 --- a/extension/src/openvic-extension/singletons/PopulationMenu.cpp +++ b/extension/src/openvic-extension/singletons/PopulationMenu.cpp @@ -379,9 +379,12 @@ Error MenuSingleton::_population_menu_update_pops() { Error MenuSingleton::_population_menu_update_filtered_pops() { population_menu.filtered_pops.clear(); - for (fixed_point_map_t<HasIdentifierAndColour const*>& distribution : population_menu.distributions) { - distribution.clear(); - } + population_menu.workforce_distribution.clear(); + population_menu.religion_distribution.clear(); + population_menu.ideology_distribution.clear(); + population_menu.culture_distribution.clear(); + population_menu.issue_distribution.clear(); + population_menu.vote_distribution.clear(); for (Pop const* pop : population_menu.pops) { if (population_menu.pop_filters[&pop->get_type()].selected) { @@ -390,20 +393,22 @@ Error MenuSingleton::_population_menu_update_filtered_pops() { } for (Pop const* pop : population_menu.filtered_pops) { - population_menu.distributions[0][&pop->get_type()] += pop->get_size(); - population_menu.distributions[1][&pop->get_religion()] += pop->get_size(); - population_menu.distributions[2] += - pop->get_ideologies() * fixed_point_t::parse(pop->get_size()); - population_menu.distributions[3][&pop->get_culture()] += pop->get_size(); - population_menu.distributions[4] += - cast_map<HasIdentifierAndColour>(pop->get_issues() * fixed_point_t::parse(pop->get_size())); - population_menu.distributions[5] += - pop->get_votes() * fixed_point_t::parse(pop->get_size()); + const fixed_point_t pop_size = fixed_point_t::parse(pop->get_size()); + + population_menu.workforce_distribution[&pop->get_type()] += pop->get_size(); + population_menu.religion_distribution[&pop->get_religion()] += pop->get_size(); + population_menu.ideology_distribution += pop->get_ideologies() * fixed_point_t::parse(pop->get_size()); + population_menu.culture_distribution[&pop->get_culture()] += pop->get_size(); + population_menu.issue_distribution += pop->get_issues() * fixed_point_t::parse(pop->get_size()); + population_menu.vote_distribution += pop->get_votes() * fixed_point_t::parse(pop->get_size()); } - for (fixed_point_map_t<HasIdentifierAndColour const*>& distribution : population_menu.distributions) { - normalise_fixed_point_map(distribution); - } + normalise_fixed_point_map(population_menu.workforce_distribution); + normalise_fixed_point_map(population_menu.religion_distribution); + normalise_fixed_point_map(population_menu.ideology_distribution); + normalise_fixed_point_map(population_menu.culture_distribution); + normalise_fixed_point_map(population_menu.issue_distribution); + normalise_fixed_point_map(population_menu.vote_distribution); return _population_menu_sort_pops(); } @@ -825,11 +830,14 @@ PackedStringArray MenuSingleton::get_population_menu_distribution_setup_info() c TypedArray<Array> MenuSingleton::get_population_menu_distribution_info() const { TypedArray<Array> array; - ERR_FAIL_COND_V(array.resize(population_menu.distributions.size()) != OK, {}); - - for (int32_t idx = 0; idx < array.size(); ++idx) { - array[idx] = GFXPieChartTexture::distribution_to_slices_array(population_menu.distributions[idx]); - } + ERR_FAIL_COND_V(array.resize(population_menu_t::DISTRIBUTION_COUNT) != OK, {}); + + array[0] = GFXPieChartTexture::distribution_to_slices_array(population_menu.workforce_distribution); + array[1] = GFXPieChartTexture::distribution_to_slices_array(population_menu.religion_distribution); + array[2] = GFXPieChartTexture::distribution_to_slices_array(population_menu.ideology_distribution); + array[3] = GFXPieChartTexture::distribution_to_slices_array(population_menu.culture_distribution); + array[4] = GFXPieChartTexture::distribution_to_slices_array(population_menu.issue_distribution); + array[5] = GFXPieChartTexture::distribution_to_slices_array(population_menu.vote_distribution); return array; } diff --git a/extension/src/openvic-extension/singletons/SoundSingleton.cpp b/extension/src/openvic-extension/singletons/SoundSingleton.cpp index a32d9fe..b9a2ee3 100644 --- a/extension/src/openvic-extension/singletons/SoundSingleton.cpp +++ b/extension/src/openvic-extension/singletons/SoundSingleton.cpp @@ -1,7 +1,6 @@ #include "SoundSingleton.hpp" #include <string_view> -#include <vector> #include <godot_cpp/core/error_macros.hpp> #include <godot_cpp/variant/string.hpp> |