aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic-extension/singletons
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2024-09-08 18:55:42 +0200
committer hop311 <hop3114@gmail.com>2024-09-10 00:29:16 +0200
commit6d4b8b087b62b5487d72cc6c2265b3e00afb9c8a (patch)
tree95518129dcaf6116c71b8c9f0e819675c31b99fd /extension/src/openvic-extension/singletons
parenta3b34e2d6a9bf2bc59619390e0490a5b45d75337 (diff)
Ranking + army topbar inforanking
Diffstat (limited to 'extension/src/openvic-extension/singletons')
-rw-r--r--extension/src/openvic-extension/singletons/GameSingleton.cpp29
-rw-r--r--extension/src/openvic-extension/singletons/GameSingleton.hpp5
-rw-r--r--extension/src/openvic-extension/singletons/MenuSingleton.cpp201
-rw-r--r--extension/src/openvic-extension/singletons/MenuSingleton.hpp7
-rw-r--r--extension/src/openvic-extension/singletons/PopulationMenu.cpp6
5 files changed, 244 insertions, 4 deletions
diff --git a/extension/src/openvic-extension/singletons/GameSingleton.cpp b/extension/src/openvic-extension/singletons/GameSingleton.cpp
index 24d8a73..f258fe1 100644
--- a/extension/src/openvic-extension/singletons/GameSingleton.cpp
+++ b/extension/src/openvic-extension/singletons/GameSingleton.cpp
@@ -69,6 +69,8 @@ void GameSingleton::_bind_methods() {
OV_BIND_METHOD(GameSingleton::set_selected_province, { "index" });
OV_BIND_METHOD(GameSingleton::unset_selected_province);
+ OV_BIND_METHOD(GameSingleton::set_viewed_country_by_province_index, { "province_index" });
+
OV_BIND_METHOD(GameSingleton::update_clock);
ADD_SIGNAL(MethodInfo(_signal_gamestate_updated()));
@@ -95,7 +97,7 @@ void GameSingleton::_on_clock_state_changed() {
GameSingleton::GameSingleton()
: game_manager {
std::bind(&GameSingleton::_on_gamestate_updated, this), std::bind(&GameSingleton::_on_clock_state_changed, this)
- } {
+ }, viewed_country { nullptr } {
ERR_FAIL_COND(singleton != nullptr);
singleton = this;
}
@@ -139,6 +141,10 @@ Error GameSingleton::setup_game(int32_t bookmark_index) {
ERR_FAIL_NULL_V(menu_singleton, FAILED);
ret &= menu_singleton->_population_menu_update_provinces() == OK;
+ // TODO - replace with actual starting country
+ set_viewed_country(instance_manager->get_country_instance_manager().get_country_instance_by_identifier("ENG"));
+ ERR_FAIL_NULL_V(viewed_country, FAILED);
+
return ERR(ret);
}
@@ -349,6 +355,27 @@ void GameSingleton::unset_selected_province() {
set_selected_province(ProvinceDefinition::NULL_INDEX);
}
+void GameSingleton::set_viewed_country(CountryInstance const* new_viewed_country) {
+ if (viewed_country != new_viewed_country) {
+ viewed_country = new_viewed_country;
+
+ Logger::info("Set viewed country to: ", viewed_country != nullptr ? viewed_country->get_identifier() : "NULL");
+
+ _on_gamestate_updated();
+ }
+}
+
+void GameSingleton::set_viewed_country_by_province_index(int32_t province_index) {
+ InstanceManager* instance_manager = get_instance_manager();
+ ERR_FAIL_NULL(instance_manager);
+
+ ProvinceInstance const* province_instance =
+ instance_manager->get_map_instance().get_province_instance_by_index(province_index);
+ ERR_FAIL_NULL(province_instance);
+
+ set_viewed_country(province_instance->get_owner());
+}
+
Error GameSingleton::update_clock() {
return ERR(game_manager.update_clock());
}
diff --git a/extension/src/openvic-extension/singletons/GameSingleton.hpp b/extension/src/openvic-extension/singletons/GameSingleton.hpp
index e0eb5fc..e737643 100644
--- a/extension/src/openvic-extension/singletons/GameSingleton.hpp
+++ b/extension/src/openvic-extension/singletons/GameSingleton.hpp
@@ -15,6 +15,8 @@ namespace OpenVic {
GameManager game_manager;
+ CountryInstance const* PROPERTY(viewed_country);
+
godot::Vector2i image_subdivisions;
godot::Ref<godot::Texture2DArray> province_shape_texture;
godot::Ref<godot::Image> province_colour_image;
@@ -124,6 +126,9 @@ namespace OpenVic {
void set_selected_province(int32_t index);
void unset_selected_province();
+ void set_viewed_country(CountryInstance const* new_viewed_country);
+ void set_viewed_country_by_province_index(int32_t province_index);
+
godot::Error update_clock();
};
}
diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.cpp b/extension/src/openvic-extension/singletons/MenuSingleton.cpp
index 367462b..5074507 100644
--- a/extension/src/openvic-extension/singletons/MenuSingleton.cpp
+++ b/extension/src/openvic-extension/singletons/MenuSingleton.cpp
@@ -107,6 +107,10 @@ String MenuSingleton::get_country_adjective(CountryInstance const& country) cons
}
void MenuSingleton::_bind_methods() {
+ OV_BIND_SMETHOD(get_tooltip_separator);
+ OV_BIND_METHOD(MenuSingleton::get_country_name_from_identifier, { "country_identifier" });
+ OV_BIND_METHOD(MenuSingleton::get_country_adjective_from_identifier, { "country_identifier" });
+
/* TOOLTIP */
OV_BIND_METHOD(MenuSingleton::show_tooltip, { "text", "substitution_dict", "position" });
OV_BIND_METHOD(MenuSingleton::show_control_tooltip, { "text", "substitution_dict", "control" });
@@ -126,6 +130,9 @@ void MenuSingleton::_bind_methods() {
OV_BIND_METHOD(MenuSingleton::get_administrative_pop_icon_index);
OV_BIND_METHOD(MenuSingleton::get_rgo_owner_pop_icon_index);
+ /* TOPBAR */
+ OV_BIND_METHOD(MenuSingleton::get_topbar_info);
+
/* TIME/SPEED CONTROL PANEL */
OV_BIND_METHOD(MenuSingleton::set_paused, { "paused" });
OV_BIND_METHOD(MenuSingleton::toggle_paused);
@@ -219,6 +226,49 @@ MenuSingleton::~MenuSingleton() {
singleton = nullptr;
}
+String MenuSingleton::get_tooltip_separator() {
+ static const String tooltip_separator = "\n" + String { "-" }.repeat(14) + "\n";
+ return tooltip_separator;
+}
+
+String MenuSingleton::get_country_name_from_identifier(String const& country_identifier) const {
+ if (country_identifier.is_empty()) {
+ return {};
+ }
+
+ GameSingleton const* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL_V(game_singleton, {});
+
+ InstanceManager const* instance_manager = game_singleton->get_instance_manager();
+ ERR_FAIL_NULL_V(instance_manager, {});
+
+ CountryInstance const* country = instance_manager->get_country_instance_manager().get_country_instance_by_identifier(
+ Utilities::godot_to_std_string(country_identifier)
+ );
+ ERR_FAIL_NULL_V(country, {});
+
+ return get_country_name(*country);
+}
+
+String MenuSingleton::get_country_adjective_from_identifier(String const& country_identifier) const {
+ if (country_identifier.is_empty()) {
+ return {};
+ }
+
+ GameSingleton const* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL_V(game_singleton, {});
+
+ InstanceManager const* instance_manager = game_singleton->get_instance_manager();
+ ERR_FAIL_NULL_V(instance_manager, {});
+
+ CountryInstance const* country = instance_manager->get_country_instance_manager().get_country_instance_by_identifier(
+ Utilities::godot_to_std_string(country_identifier)
+ );
+ ERR_FAIL_NULL_V(country, {});
+
+ return get_country_adjective(*country);
+}
+
/* TOOLTIP */
void MenuSingleton::show_tooltip(String const& text, Dictionary const& substitution_dict, Vector2 const& position) {
@@ -452,6 +502,157 @@ int32_t MenuSingleton::get_rgo_owner_pop_icon_index() const {
return sprite;
}
+/* TOPBAR */
+
+Dictionary MenuSingleton::get_topbar_info() const {
+ GameSingleton const* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL_V(game_singleton, {});
+
+ CountryInstance const* country = game_singleton->get_viewed_country();
+ if (country == nullptr) {
+ return {};
+ }
+
+ Dictionary ret;
+
+ // Country / Ranking
+ static const StringName country_key = "country";
+ static const StringName country_status_key = "country_status";
+ static const StringName total_rank_key = "total_rank";
+
+ ret[country_key] = Utilities::std_to_godot_string(country->get_identifier());
+ ret[country_status_key] = static_cast<int32_t>(country->get_country_status());
+ ret[total_rank_key] = static_cast<uint64_t>(country->get_total_rank());
+
+ static const StringName prestige_key = "prestige";
+ static const StringName prestige_rank_key = "prestige_rank";
+ static const StringName prestige_tooltip_key = "prestige_tooltip";
+
+ ret[prestige_key] = country->get_prestige().to_int32_t();
+ ret[prestige_rank_key] = static_cast<uint64_t>(country->get_prestige_rank());
+ ret[prestige_tooltip_key] = String {}; // TODO - list prestige sources (e.g. power status)
+
+ static const StringName industrial_power_key = "industrial_power";
+ static const StringName industrial_rank_key = "industrial_rank";
+ static const StringName industrial_power_tooltip_key = "industrial_power_tooltip";
+
+ ret[industrial_power_key] = country->get_industrial_power().to_int32_t();
+ ret[industrial_rank_key] = static_cast<uint64_t>(country->get_industrial_rank());
+ {
+ String industrial_power_tooltip;
+
+ // Pair: State name / Power
+ std::vector<std::pair<String, fixed_point_t>> industrial_power_states;
+ for (auto const& [state, power] : country->get_industrial_power_from_states()) {
+ industrial_power_states.emplace_back(get_state_name(*state), power);
+ }
+ std::sort(
+ industrial_power_states.begin(), industrial_power_states.end(),
+ [](auto const& a, auto const& b) -> bool {
+ // Sort by greatest power, then by state name alphabetically
+ return a.second != b.second ? a.second > b.second : a.first < b.first;
+ }
+ );
+ for (auto const& [state_name, power] : industrial_power_states) {
+ industrial_power_tooltip += "\n" + state_name + ": " + GUILabel::get_colour_marker() + "Y"
+ + GUINode::float_to_string_dp(power, 3) + GUILabel::get_colour_marker() + "!";
+ }
+
+ // Tuple: Country identifier / Country name / Power
+ std::vector<std::tuple<String, String, fixed_point_t>> industrial_power_from_investments;
+ for (auto const& [country, power] : country->get_industrial_power_from_investments()) {
+ industrial_power_from_investments.emplace_back(
+ Utilities::std_to_godot_string(country->get_identifier()), get_country_name(*country), power
+ );
+ }
+ std::sort(
+ industrial_power_from_investments.begin(), industrial_power_from_investments.end(),
+ [](auto const& a, auto const& b) -> bool {
+ // Sort by greatest power, then by country name alphabetically
+ return std::get<2>(a) != std::get<2>(b) ? std::get<2>(a) > std::get<2>(b) : std::get<1>(a) < std::get<1>(b);
+ }
+ );
+ for (auto const& [country_identifier, country_name, power] : industrial_power_from_investments) {
+ industrial_power_tooltip += "\n" + GUILabel::get_flag_marker() + country_identifier + country_name + ": "
+ + GUILabel::get_colour_marker() + "Y" + GUINode::float_to_string_dp(power, 3) + GUILabel::get_colour_marker()
+ + "!";
+ }
+
+ ret[industrial_power_tooltip_key] = std::move(industrial_power_tooltip);
+ }
+
+ static const StringName military_power_key = "military_power";
+ static const StringName military_rank_key = "military_rank";
+ static const StringName military_power_tooltip_key = "military_power_tooltip";
+
+ ret[military_power_key] = country->get_military_power().to_int32_t();
+ ret[military_rank_key] = static_cast<uint64_t>(country->get_military_rank());
+ {
+ String military_power_tooltip;
+
+ for (auto const& [source, power] : {
+ std::pair
+ { "MIL_FROM_TROOPS", country->get_military_power_from_land() },
+ { "MIL_FROM_CAP_SHIPS", country->get_military_power_from_sea() },
+ { "MIL_FROM_LEADERS", country->get_military_power_from_leaders() }
+ }) {
+ if (power != 0) {
+ military_power_tooltip += "\n" + tr(source) + ": " + GUILabel::get_colour_marker() + "Y"
+ + GUINode::float_to_string_dp(power, 3) + GUILabel::get_colour_marker() + "!";
+ }
+ }
+
+ ret[military_power_tooltip_key] = std::move(military_power_tooltip);
+ }
+
+ static const StringName colonial_power_available_key = "colonial_power_available";
+ static const StringName colonial_power_max_key = "colonial_power_max";
+ static const StringName colonial_power_tooltip_key = "colonial_power_tooltip";
+ // TODO - colonial power info
+ ret[colonial_power_available_key] = 0;
+ ret[colonial_power_max_key] = 0;
+ ret[colonial_power_tooltip_key] = String {};
+
+ // Production
+
+ // Budget
+
+ // Technology
+
+ // Politics
+
+ // Population
+
+ // Trade
+
+ // Diplomacy
+
+ // Military
+ static const StringName regiment_count_key = "regiment_count";
+ static const StringName max_supported_regiments_key = "max_supported_regiments";
+
+ ret[regiment_count_key] = static_cast<uint64_t>(country->get_regiment_count());
+ ret[max_supported_regiments_key] = static_cast<uint64_t>(country->get_max_supported_regiment_count());
+
+ static const StringName mobilised_key = "mobilised";
+ static const StringName mobilisation_regiments_key = "mobilisation_regiments";
+ static const StringName mobilisation_impact_key = "mobilisation_impact";
+ static const StringName war_policy_key = "war_policy";
+ static const StringName mobilisation_max_regiments_key = "mobilisation_max_regiments";
+
+ if (country->is_mobilised()) {
+ ret[mobilised_key] = true;
+ } else {
+ ret[mobilised_key] = false;
+ ret[mobilisation_regiments_key] = static_cast<uint64_t>(country->get_mobilisation_potential_regiment_count());
+ ret[mobilisation_impact_key] = country->get_mobilisation_impact().to_float();
+ ret[war_policy_key] = String {}; // TODO - get ruling party's war policy
+ ret[mobilisation_max_regiments_key] = static_cast<uint64_t>(country->get_mobilisation_max_regiment_count());
+ }
+
+ return ret;
+}
+
/* TIME/SPEED CONTROL PANEL */
void MenuSingleton::set_paused(bool paused) {
diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.hpp b/extension/src/openvic-extension/singletons/MenuSingleton.hpp
index 022bce5..3f07583 100644
--- a/extension/src/openvic-extension/singletons/MenuSingleton.hpp
+++ b/extension/src/openvic-extension/singletons/MenuSingleton.hpp
@@ -115,6 +115,10 @@ namespace OpenVic {
MenuSingleton();
~MenuSingleton();
+ static godot::String get_tooltip_separator();
+ godot::String get_country_name_from_identifier(godot::String const& country_identifier) const;
+ godot::String get_country_adjective_from_identifier(godot::String const& country_identifier) const;
+
/* TOOLTIP */
void show_tooltip(
godot::String const& text, godot::Dictionary const& substitution_dict, godot::Vector2 const& position
@@ -134,6 +138,9 @@ namespace OpenVic {
int32_t get_administrative_pop_icon_index() const;
int32_t get_rgo_owner_pop_icon_index() const;
+ /* TOPBAR */
+ godot::Dictionary get_topbar_info() const;
+
/* TIME/SPEED CONTROL PANEL */
void set_paused(bool paused);
void toggle_paused();
diff --git a/extension/src/openvic-extension/singletons/PopulationMenu.cpp b/extension/src/openvic-extension/singletons/PopulationMenu.cpp
index 271068b..c96ef02 100644
--- a/extension/src/openvic-extension/singletons/PopulationMenu.cpp
+++ b/extension/src/openvic-extension/singletons/PopulationMenu.cpp
@@ -393,12 +393,12 @@ Error MenuSingleton::_population_menu_update_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() * static_cast<fixed_point_t>(static_cast<int32_t>(pop->get_size()));
+ 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() * static_cast<int32_t>(pop->get_size()));
+ cast_map<HasIdentifierAndColour>(pop->get_issues() * fixed_point_t::parse(pop->get_size()));
population_menu.distributions[5] +=
- pop->get_votes() * static_cast<fixed_point_t>(static_cast<int32_t>(pop->get_size()));
+ pop->get_votes() * fixed_point_t::parse(pop->get_size());
}
for (fixed_point_map_t<HasIdentifierAndColour const*>& distribution : population_menu.distributions) {