diff --git a/extension/deps/openvic-simulation b/extension/deps/openvic-simulation index 668daa1e..c44b9921 160000 --- a/extension/deps/openvic-simulation +++ b/extension/deps/openvic-simulation @@ -1 +1 @@ -Subproject commit 668daa1e4bea66cfba569c83fc5fe0f6e6abe4fe +Subproject commit c44b9921c62043d54a9eb9085a9c3e6dfc580460 diff --git a/extension/doc_classes/GameSingleton.xml b/extension/doc_classes/GameSingleton.xml index ad0f53e2..f6ec7f46 100644 --- a/extension/doc_classes/GameSingleton.xml +++ b/extension/doc_classes/GameSingleton.xml @@ -119,24 +119,12 @@ Return a [Texture2DArray] containing all the textures that the province shape image was split into. - - - - Returns the [int] index of the currently selected province, or [code]0[/code] if there is no selected province. - - Return a [Texture2DArray] containing all terrain textures, both the solid blue generated water texture and the loaded land terrain textures. - - - - Returns the viewed country's capital position as a normalized [Vector2], or [code](0.0, 0.0)[/code] if no country is being viewed. - - @@ -177,20 +165,6 @@ Sets the active mapmode to that identified by [param index]. Returns [code]FAILED[/code] if the mapmode index is invalid, otherwise returns [code]OK[/code]. - - - - - Sets the currently selected province to that identified by [param index], or unselects the currently selected province if [param index] is [code]0[/code]. - - - - - - - Sets the viewed country to that which owns the province identified by [param province_index], or unsets the viewed country if the province has no owner/is uncolonised. Returns [code]FAILED[/code] if the [param province_index] is invalid, otherwise returns [code]OK[/code]. - - @@ -210,12 +184,6 @@ Sets up the simulation's clock and timestamps so that it can be unpaused, marking the move from the initialized but static game state used for the lobby to the dynamic game session that is ready to tick, update and simulate. - - - - Unselects the currently selected province, should there be one. - - @@ -224,11 +192,6 @@ - - - Signal emitted when the simulation's clock changes state (paused vs unpaused, clock speed, etc.). - - Signal emitted when the simulation's gamestate is updated (this happens after any event that changes the gamestate, e.g. a day tick, a player taking a decision, etc). @@ -240,11 +203,5 @@ Signal emitted when the active mapmode changes, with the new mapmode's [param index] provided as a parameter. - - - - Signal emitted when the currently selected province changes, with the new province's [param index] provided as a parameter (or [code]0[/code] if there is no longer a selected province/the change was de-selecting a province). - - diff --git a/extension/doc_classes/MenuSingleton.xml b/extension/doc_classes/MenuSingleton.xml index b96d465d..5916e3d7 100644 --- a/extension/doc_classes/MenuSingleton.xml +++ b/extension/doc_classes/MenuSingleton.xml @@ -17,17 +17,6 @@ - - - - - - - - - - - @@ -191,11 +180,6 @@ - - - - - @@ -248,12 +232,6 @@ - - - - - - @@ -270,11 +248,6 @@ - - - - - diff --git a/extension/doc_classes/PlayerSingleton.xml b/extension/doc_classes/PlayerSingleton.xml new file mode 100644 index 00000000..f5fb60fb --- /dev/null +++ b/extension/doc_classes/PlayerSingleton.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/extension/src/openvic-extension/register_types.cpp b/extension/src/openvic-extension/register_types.cpp index bfd5f0e5..15710452 100644 --- a/extension/src/openvic-extension/register_types.cpp +++ b/extension/src/openvic-extension/register_types.cpp @@ -29,6 +29,7 @@ #include "openvic-extension/singletons/MapItemSingleton.hpp" #include "openvic-extension/singletons/MenuSingleton.hpp" #include "openvic-extension/singletons/ModelSingleton.hpp" +#include "openvic-extension/singletons/PlayerSingleton.hpp" #include "openvic-extension/singletons/SoundSingleton.hpp" using namespace godot; @@ -43,6 +44,7 @@ static MenuSingleton* _menu_singleton = nullptr; static ModelSingleton* _model_singleton = nullptr; static AssetManager* _asset_manager_singleton = nullptr; static SoundSingleton* _sound_singleton = nullptr; +static PlayerSingleton* _player_singleton = nullptr; void initialize_openvic_types(ModuleInitializationLevel p_level) { if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) { @@ -85,6 +87,10 @@ void initialize_openvic_types(ModuleInitializationLevel p_level) { _sound_singleton = memnew(SoundSingleton); Engine::get_singleton()->register_singleton("SoundSingleton", SoundSingleton::get_singleton()); + ClassDB::register_class(); + _player_singleton = memnew(PlayerSingleton); + Engine::get_singleton()->register_singleton("PlayerSingleton", PlayerSingleton::get_singleton()); + ClassDB::register_class(); ClassDB::register_abstract_class(); @@ -148,6 +154,9 @@ void uninitialize_openvic_types(ModuleInitializationLevel p_level) { Engine::get_singleton()->unregister_singleton("SoundSingleton"); memdelete(_sound_singleton); + + Engine::get_singleton()->unregister_singleton("PlayerSingleton"); + memdelete(_player_singleton); } extern "C" { diff --git a/extension/src/openvic-extension/singletons/GameSingleton.cpp b/extension/src/openvic-extension/singletons/GameSingleton.cpp index 37418c3a..4c927efd 100644 --- a/extension/src/openvic-extension/singletons/GameSingleton.cpp +++ b/extension/src/openvic-extension/singletons/GameSingleton.cpp @@ -10,6 +10,7 @@ #include "openvic-extension/singletons/AssetManager.hpp" #include "openvic-extension/singletons/LoadLocalisation.hpp" #include "openvic-extension/singletons/MenuSingleton.hpp" +#include "openvic-extension/singletons/PlayerSingleton.hpp" #include "openvic-extension/utility/ClassBindings.hpp" #include "openvic-extension/utility/Utilities.hpp" @@ -25,14 +26,6 @@ StringName const& GameSingleton::_signal_gamestate_updated() { static const StringName signal_gamestate_updated = "gamestate_updated"; return signal_gamestate_updated; } -StringName const& GameSingleton::_signal_province_selected() { - static const StringName signal_province_selected = "province_selected"; - return signal_province_selected; -} -StringName const& GameSingleton::_signal_clock_state_changed() { - static const StringName signal_clock_state_changed = "clock_state_changed"; - return signal_clock_state_changed; -} StringName const& GameSingleton::_signal_mapmode_changed() { static const StringName signal_mapmode_changed = "mapmode_changed"; return signal_mapmode_changed; @@ -73,18 +66,10 @@ void GameSingleton::_bind_methods() { OV_BIND_METHOD(GameSingleton::get_current_mapmode_index); OV_BIND_METHOD(GameSingleton::set_mapmode, { "index" }); OV_BIND_METHOD(GameSingleton::is_parchment_mapmode_allowed); - OV_BIND_METHOD(GameSingleton::get_selected_province_index); - 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::get_viewed_country_capital_position); OV_BIND_METHOD(GameSingleton::update_clock); ADD_SIGNAL(MethodInfo(_signal_gamestate_updated())); - ADD_SIGNAL(MethodInfo(_signal_province_selected(), PropertyInfo(Variant::INT, "index"))); - ADD_SIGNAL(MethodInfo(_signal_clock_state_changed())); ADD_SIGNAL(MethodInfo(_signal_mapmode_changed(), PropertyInfo(Variant::INT, "index"))); } @@ -97,16 +82,12 @@ void GameSingleton::_on_gamestate_updated() { emit_signal(_signal_gamestate_updated()); } -void GameSingleton::_on_clock_state_changed() { - emit_signal(_signal_clock_state_changed()); -} - /* REQUIREMENTS: * MAP-21, MAP-23, MAP-25, MAP-32, MAP-33, MAP-34 */ GameSingleton::GameSingleton() : game_manager { - std::bind(&GameSingleton::_on_gamestate_updated, this), std::bind(&GameSingleton::_on_clock_state_changed, this) + std::bind(&GameSingleton::_on_gamestate_updated, this) }, mapmode { &Mapmode::ERROR_MAPMODE } { ERR_FAIL_COND(singleton != nullptr); @@ -163,21 +144,20 @@ Error GameSingleton::setup_game(int32_t bookmark_index) { for (ProvinceInstance& province : instance_manager->get_map_instance().get_province_instances()) { province.set_crime( get_definition_manager().get_crime_manager().get_crime_modifier_by_index( - (province.get_province_definition().get_index() - 1) - % get_definition_manager().get_crime_manager().get_crime_modifier_count() + (province.get_index() - 1) % get_definition_manager().get_crime_manager().get_crime_modifier_count() ) ); } - MenuSingleton* menu_singleton = MenuSingleton::get_singleton(); - ERR_FAIL_NULL_V(menu_singleton, FAILED); - ret &= menu_singleton->_population_menu_update_provinces() == OK; + ret &= MenuSingleton::get_singleton()->_population_menu_update_provinces() == OK; + + PlayerSingleton& player_singleton = *PlayerSingleton::get_singleton(); // TODO - replace with actual starting country CountryInstance* starting_country = instance_manager->get_country_instance_manager().get_country_instance_by_identifier("ENG"); - set_viewed_country(starting_country); - ERR_FAIL_NULL_V(viewed_country, FAILED); + player_singleton.set_player_country(starting_country); + ERR_FAIL_NULL_V(player_singleton.get_player_country(), FAILED); // TODO - remove this test starting research for ( @@ -405,59 +385,6 @@ bool GameSingleton::is_parchment_mapmode_allowed() const { return mapmode->is_parchment_mapmode_allowed(); } -int32_t GameSingleton::get_selected_province_index() const { - InstanceManager const* instance_manager = get_instance_manager(); - ERR_FAIL_NULL_V(instance_manager, 0); - - return instance_manager->get_map_instance().get_selected_province_index(); -} - -void GameSingleton::set_selected_province(int32_t index) { - InstanceManager* instance_manager = get_instance_manager(); - ERR_FAIL_NULL(instance_manager); - - instance_manager->get_map_instance().set_selected_province(index); - _update_colour_image(); - emit_signal(_signal_province_selected(), index); -} - -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()); -} - -Vector2 GameSingleton::get_viewed_country_capital_position() const { - if (viewed_country != nullptr) { - ProvinceInstance const* capital = viewed_country->get_capital(); - - if (capital != nullptr) { - return get_billboard_pos(capital->get_province_definition()); - } - } - - return {}; -} - 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 653d712b..c42a7e23 100644 --- a/extension/src/openvic-extension/singletons/GameSingleton.hpp +++ b/extension/src/openvic-extension/singletons/GameSingleton.hpp @@ -15,8 +15,6 @@ namespace OpenVic { GameManager game_manager; - CountryInstance const* PROPERTY(viewed_country, nullptr); - godot::Vector2i image_subdivisions; godot::Ref province_shape_texture; godot::Ref province_colour_image; @@ -32,18 +30,16 @@ namespace OpenVic { ordered_map flag_type_index_map; static godot::StringName const& _signal_gamestate_updated(); - static godot::StringName const& _signal_province_selected(); - static godot::StringName const& _signal_clock_state_changed(); static godot::StringName const& _signal_mapmode_changed(); godot::Error _load_map_images(); godot::Error _load_terrain_variants(); godot::Error _load_flag_sheet(); + public: /* Generate the province_colour_texture from the current mapmode. */ godot::Error _update_colour_image(); void _on_gamestate_updated(); - void _on_clock_state_changed(); protected: static void _bind_methods(); @@ -129,13 +125,6 @@ namespace OpenVic { int32_t get_current_mapmode_index() const; godot::Error set_mapmode(int32_t index); bool is_parchment_mapmode_allowed() const; - int32_t get_selected_province_index() const; - 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::Vector2 get_viewed_country_capital_position() const; godot::Error update_clock(); }; diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.cpp b/extension/src/openvic-extension/singletons/MenuSingleton.cpp index 20460979..4d455858 100644 --- a/extension/src/openvic-extension/singletons/MenuSingleton.cpp +++ b/extension/src/openvic-extension/singletons/MenuSingleton.cpp @@ -9,6 +9,7 @@ #include "openvic-extension/classes/GFXPieChartTexture.hpp" #include "openvic-extension/classes/GUINode.hpp" #include "openvic-extension/singletons/GameSingleton.hpp" +#include "openvic-extension/singletons/PlayerSingleton.hpp" #include "openvic-extension/utility/ClassBindings.hpp" #include "openvic-extension/utility/Utilities.hpp" @@ -263,16 +264,14 @@ String MenuSingleton::_make_rules_tooltip(RuleSet const& rules) const { } String MenuSingleton::_make_mobilisation_impact_tooltip() const { - GameSingleton const* game_singleton = GameSingleton::get_singleton(); - ERR_FAIL_NULL_V(game_singleton, {}); - - CountryInstance const* country = game_singleton->get_viewed_country(); + CountryInstance const* country = PlayerSingleton::get_singleton()->get_player_country(); if (country == nullptr) { return {}; } - IssueManager const& issue_manager = game_singleton->get_definition_manager().get_politics_manager().get_issue_manager(); + IssueManager const& issue_manager = + GameSingleton::get_singleton()->get_definition_manager().get_politics_manager().get_issue_manager(); static const StringName mobilisation_impact_tooltip_localisation_key = "MOBILIZATION_IMPACT_LIMIT_DESC"; static const String mobilisation_impact_tooltip_replace_impact_key = "$IMPACT$"; @@ -332,7 +331,6 @@ void MenuSingleton::_bind_methods() { OV_BIND_METHOD(MenuSingleton::get_province_info_from_index, { "index" }); OV_BIND_METHOD(MenuSingleton::get_province_building_count); OV_BIND_METHOD(MenuSingleton::get_province_building_identifier, { "building_index" }); - OV_BIND_METHOD(MenuSingleton::expand_selected_province_building, { "building_index" }); OV_BIND_METHOD(MenuSingleton::get_slave_pop_icon_index); OV_BIND_METHOD(MenuSingleton::get_administrative_pop_icon_index); OV_BIND_METHOD(MenuSingleton::get_rgo_owner_pop_icon_index); @@ -341,11 +339,7 @@ void MenuSingleton::_bind_methods() { OV_BIND_METHOD(MenuSingleton::get_topbar_info); /* TIME/SPEED CONTROL PANEL */ - OV_BIND_METHOD(MenuSingleton::set_paused, { "paused" }); - OV_BIND_METHOD(MenuSingleton::toggle_paused); OV_BIND_METHOD(MenuSingleton::is_paused); - OV_BIND_METHOD(MenuSingleton::increase_speed); - OV_BIND_METHOD(MenuSingleton::decrease_speed); OV_BIND_METHOD(MenuSingleton::get_speed); OV_BIND_METHOD(MenuSingleton::can_increase_speed); OV_BIND_METHOD(MenuSingleton::can_decrease_speed); @@ -1065,19 +1059,6 @@ String MenuSingleton::get_province_building_identifier(int32_t building_index) c return Utilities::std_to_godot_string(province_building_types[building_index]->get_identifier()); } -Error MenuSingleton::expand_selected_province_building(int32_t building_index) { - GameSingleton* game_singleton = GameSingleton::get_singleton(); - ERR_FAIL_NULL_V(game_singleton, FAILED); - InstanceManager* instance_manager = game_singleton->get_instance_manager(); - ERR_FAIL_NULL_V(instance_manager, FAILED); - - ERR_FAIL_COND_V_MSG( - !instance_manager->expand_selected_province_building(building_index), FAILED, - vformat("Failed to expand the currently selected province's building index %d", building_index) - ); - return OK; -} - int32_t MenuSingleton::get_slave_pop_icon_index() const { GameSingleton const* game_singleton = GameSingleton::get_singleton(); ERR_FAIL_NULL_V(game_singleton, 0); @@ -1108,15 +1089,12 @@ int32_t MenuSingleton::get_rgo_owner_pop_icon_index() const { /* 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(); + CountryInstance const* country = PlayerSingleton::get_singleton()->get_player_country(); if (country == nullptr) { return {}; } - DefinitionManager const& definition_manager = game_singleton->get_definition_manager(); + DefinitionManager const& definition_manager = GameSingleton::get_singleton()->get_definition_manager(); ModifierEffectCache const& modifier_effect_cache = definition_manager.get_modifier_manager().get_modifier_effect_cache(); Dictionary ret; @@ -1467,24 +1445,6 @@ Dictionary MenuSingleton::get_topbar_info() const { /* TIME/SPEED CONTROL PANEL */ -void MenuSingleton::set_paused(bool paused) { - GameSingleton* game_singleton = GameSingleton::get_singleton(); - ERR_FAIL_NULL(game_singleton); - InstanceManager* instance_manager = game_singleton->get_instance_manager(); - ERR_FAIL_NULL(instance_manager); - - instance_manager->get_simulation_clock().set_paused(paused); -} - -void MenuSingleton::toggle_paused() { - GameSingleton* game_singleton = GameSingleton::get_singleton(); - ERR_FAIL_NULL(game_singleton); - InstanceManager* instance_manager = game_singleton->get_instance_manager(); - ERR_FAIL_NULL(instance_manager); - - instance_manager->get_simulation_clock().toggle_paused(); -} - bool MenuSingleton::is_paused() const { GameSingleton const* game_singleton = GameSingleton::get_singleton(); ERR_FAIL_NULL_V(game_singleton, true); @@ -1494,24 +1454,6 @@ bool MenuSingleton::is_paused() const { return instance_manager->get_simulation_clock().is_paused(); } -void MenuSingleton::increase_speed() { - GameSingleton* game_singleton = GameSingleton::get_singleton(); - ERR_FAIL_NULL(game_singleton); - InstanceManager* instance_manager = game_singleton->get_instance_manager(); - ERR_FAIL_NULL(instance_manager); - - instance_manager->get_simulation_clock().increase_simulation_speed(); -} - -void MenuSingleton::decrease_speed() { - GameSingleton* game_singleton = GameSingleton::get_singleton(); - ERR_FAIL_NULL(game_singleton); - InstanceManager* instance_manager = game_singleton->get_instance_manager(); - ERR_FAIL_NULL(instance_manager); - - instance_manager->get_simulation_clock().decrease_simulation_speed(); -} - int32_t MenuSingleton::get_speed() const { GameSingleton const* game_singleton = GameSingleton::get_singleton(); ERR_FAIL_NULL_V(game_singleton, 0); diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.hpp b/extension/src/openvic-extension/singletons/MenuSingleton.hpp index 2623b2e8..627713b0 100644 --- a/extension/src/openvic-extension/singletons/MenuSingleton.hpp +++ b/extension/src/openvic-extension/singletons/MenuSingleton.hpp @@ -25,7 +25,7 @@ namespace OpenVic { struct ModifierValue; struct ModifierSum; struct RuleSet; - struct LeaderBase; + struct LeaderInstance; class MenuSingleton : public godot::Object { GDCLASS(MenuSingleton, godot::Object) @@ -104,7 +104,7 @@ namespace OpenVic { LEADER_SORT_NONE, LEADER_SORT_PRESTIGE, LEADER_SORT_TYPE, LEADER_SORT_NAME, LEADER_SORT_ASSIGNMENT, MAX_LEADER_SORT_KEY }; - ordered_map cached_leader_dicts; + ordered_map cached_leader_dicts; enum UnitGroupSortKey { UNIT_GROUP_SORT_NONE, UNIT_GROUP_SORT_NAME, UNIT_GROUP_SORT_STRENGTH, MAX_UNIT_GROUP_SORT_KEY }; @@ -189,7 +189,6 @@ namespace OpenVic { godot::Dictionary get_province_info_from_index(int32_t index) const; int32_t get_province_building_count() const; godot::String get_province_building_identifier(int32_t building_index) const; - godot::Error expand_selected_province_building(int32_t building_index); int32_t get_slave_pop_icon_index() const; int32_t get_administrative_pop_icon_index() const; int32_t get_rgo_owner_pop_icon_index() const; @@ -198,11 +197,7 @@ namespace OpenVic { godot::Dictionary get_topbar_info() const; /* TIME/SPEED CONTROL PANEL */ - void set_paused(bool paused); - void toggle_paused(); bool is_paused() const; - void increase_speed(); - void decrease_speed(); int32_t get_speed() const; bool can_increase_speed() const; bool can_decrease_speed() const; @@ -243,9 +238,9 @@ namespace OpenVic { godot::Dictionary get_trade_menu_tables_info() const; /* MILITARY MENU */ - godot::Dictionary make_leader_dict(LeaderBase const& leader); + godot::Dictionary make_leader_dict(LeaderInstance const& leader); template - godot::Dictionary make_unit_group_dict(UnitInstanceGroup const& unit_group); + godot::Dictionary make_unit_group_dict(UnitInstanceGroupBranched const& unit_group); godot::Dictionary make_in_progress_unit_dict() const; godot::Dictionary get_military_menu_info( LeaderSortKey leader_sort_key, bool sort_leaders_descending, diff --git a/extension/src/openvic-extension/singletons/MilitaryMenu.cpp b/extension/src/openvic-extension/singletons/MilitaryMenu.cpp index 0d4a9b8f..684e8519 100644 --- a/extension/src/openvic-extension/singletons/MilitaryMenu.cpp +++ b/extension/src/openvic-extension/singletons/MilitaryMenu.cpp @@ -7,6 +7,7 @@ #include "openvic-extension/classes/GUINode.hpp" #include "openvic-extension/singletons/AssetManager.hpp" #include "openvic-extension/singletons/GameSingleton.hpp" +#include "openvic-extension/singletons/PlayerSingleton.hpp" #include "openvic-extension/utility/Utilities.hpp" using namespace OpenVic; @@ -14,22 +15,21 @@ using namespace godot; /* MILITARY MENU */ -static Ref _get_leader_picture(LeaderBase const& leader) { - AssetManager* asset_manager = AssetManager::get_singleton(); - ERR_FAIL_NULL_V(asset_manager, {}); +static Ref _get_leader_picture(LeaderInstance const& leader) { + AssetManager& asset_manager = *AssetManager::get_singleton(); if (!leader.get_picture().empty()) { - const Ref texture = asset_manager->get_leader_texture_std(leader.get_picture()); + const Ref texture = asset_manager.get_leader_texture_std(leader.get_picture()); if (texture.is_valid()) { return texture; } } - return asset_manager->get_missing_leader_texture(); + return asset_manager.get_missing_leader_texture(); } -Dictionary MenuSingleton::make_leader_dict(LeaderBase const& leader) { +Dictionary MenuSingleton::make_leader_dict(LeaderInstance const& leader) { const decltype(cached_leader_dicts)::const_iterator it = cached_leader_dicts.find(&leader); if (it != cached_leader_dicts.end()) { @@ -55,46 +55,18 @@ Dictionary MenuSingleton::make_leader_dict(LeaderBase const& leader) { leader_dict[military_info_leader_picture_key] = _get_leader_picture(leader); { - // Branched (can be used, assignment, location, title) - static const auto branched_section = []( - LeaderBranched const& leader, Dictionary& leader_dict - ) -> void { - leader_dict[military_info_leader_can_be_used_key] = leader.get_can_be_used(); - - UnitInstanceGroup const* group = leader.get_unit_instance_group(); - if (group != nullptr) { - leader_dict[military_info_leader_assignment_key] = Utilities::std_to_godot_string(group->get_name()); - - ProvinceInstance const* location = group->get_position(); - if (location != nullptr) { - leader_dict[military_info_leader_location_key] = - Utilities::std_to_godot_string(location->get_identifier()); - } - } - }; - - using enum UnitType::branch_t; - - switch (leader.get_branch()) { - case LAND: { - static const StringName general_localisation_key = "MILITARY_GENERAL_TOOLTIP"; - tooltip = tr(general_localisation_key) + " "; - - branched_section(static_cast(leader), leader_dict); - } break; - - case NAVAL: { - static const StringName admiral_localisation_key = "MILITARY_ADMIRAL_TOOLTIP"; - tooltip = tr(admiral_localisation_key) + " "; + // Generic data + leader_dict[military_info_leader_can_be_used_key] = leader.get_can_be_used(); - branched_section(static_cast(leader), leader_dict); - } break; + UnitInstanceGroup const* group = leader.get_unit_instance_group(); + if (group != nullptr) { + leader_dict[military_info_leader_assignment_key] = Utilities::std_to_godot_string(group->get_name()); - default: - UtilityFunctions::push_error( - "Invalid branch type \"", static_cast(leader.get_branch()), "\" for leader \"", - Utilities::std_to_godot_string(leader.get_name()), "\"" - ); + ProvinceInstance const* location = group->get_position(); + if (location != nullptr) { + leader_dict[military_info_leader_location_key] = + Utilities::std_to_godot_string(location->get_identifier()); + } } } @@ -210,7 +182,7 @@ static inline int32_t _scale_land_unit_strength(fixed_point_t strength) { } template -Dictionary MenuSingleton::make_unit_group_dict(UnitInstanceGroup const& unit_group) { +Dictionary MenuSingleton::make_unit_group_dict(UnitInstanceGroupBranched const& unit_group) { static const StringName military_info_unit_group_leader_picture_key = "unit_group_leader_picture"; static const StringName military_info_unit_group_leader_tooltip_key = "unit_group_leader_tooltip"; static const StringName military_info_unit_group_name_key = "unit_group_name"; @@ -266,12 +238,11 @@ Dictionary MenuSingleton::make_unit_group_dict(UnitInstanceGroup const& } if constexpr (Branch == LAND) { - ArmyInstance const& army = static_cast(unit_group); + unit_group_dict[military_info_unit_group_men_count_key] = _scale_land_unit_strength(unit_group.get_total_strength()); + unit_group_dict[military_info_unit_group_max_men_count_key] = + _scale_land_unit_strength(unit_group.get_total_max_strength()); - unit_group_dict[military_info_unit_group_men_count_key] = _scale_land_unit_strength(army.get_total_strength()); - unit_group_dict[military_info_unit_group_max_men_count_key] = _scale_land_unit_strength(army.get_total_max_strength()); - - const ArmyInstance::dig_in_level_t dig_in_level = army.get_dig_in_level(); + const ArmyInstance::dig_in_level_t dig_in_level = unit_group.get_dig_in_level(); if (dig_in_level > 0) { static const StringName dig_in_localisation_key = "MILITARY_DIGIN_TOOLTIP"; @@ -290,6 +261,7 @@ Dictionary MenuSingleton::make_unit_group_dict(UnitInstanceGroup const& return unit_group_dict; } +// Only ever called if we know player country isn't null Dictionary MenuSingleton::make_in_progress_unit_dict() const { static const StringName military_info_unit_progress_key = "unit_progress"; static const StringName military_info_unit_icon_key = "unit_icon"; @@ -298,14 +270,13 @@ Dictionary MenuSingleton::make_in_progress_unit_dict() const { static const StringName military_info_unit_eta_key = "unit_eta"; static const StringName military_info_unit_tooltip_key = "unit_tooltip"; - GameSingleton const* game_singleton = GameSingleton::get_singleton(); - DefinitionManager const& definition_manager = game_singleton->get_definition_manager(); + DefinitionManager const& definition_manager = GameSingleton::get_singleton()->get_definition_manager(); GoodDefinitionManager const& good_definition_manager = definition_manager.get_economy_manager().get_good_definition_manager(); // TODO - remove test data, read actual in-progress units from SIM UnitType const* unit_type = definition_manager.get_military_manager().get_unit_type_manager().get_unit_type_by_index(0); - ProvinceInstance const* location = game_singleton->get_viewed_country()->get_capital(); + ProvinceInstance const* location = PlayerSingleton::get_singleton()->get_player_country()->get_capital(); const Date eta { 1900 }; const fixed_point_t progress = fixed_point_t::_0_50(); const ordered_map> required_goods { @@ -329,7 +300,9 @@ Dictionary MenuSingleton::make_in_progress_unit_dict() const { in_progress_unit_dict[military_info_unit_progress_key] = progress.to_float(); in_progress_unit_dict[military_info_unit_icon_key] = unit_type->get_icon(); in_progress_unit_dict[military_info_unit_name_key] = Utilities::std_to_godot_string(unit_type->get_identifier()); - in_progress_unit_dict[military_info_unit_location_key] = Utilities::std_to_godot_string(location->get_identifier()); + if (location != nullptr) { + in_progress_unit_dict[military_info_unit_location_key] = Utilities::std_to_godot_string(location->get_identifier()); + } in_progress_unit_dict[military_info_unit_eta_key] = Utilities::date_to_string(eta); String tooltip; @@ -350,74 +323,52 @@ Dictionary MenuSingleton::make_in_progress_unit_dict() const { return in_progress_unit_dict; } -using leader_sort_func_t = bool (*)(LeaderBase const*, LeaderBase const*); +using leader_sort_func_t = bool (*)(LeaderInstance const*, LeaderInstance const*); static leader_sort_func_t _get_leader_sort_func(MenuSingleton::LeaderSortKey leader_sort_key) { - static const auto get_assignment = [](LeaderBase const* leader) -> std::string_view { - static const auto get_assignment_template = - [](LeaderBranched const* leader) -> std::string_view { - UnitInstanceGroup const* group = leader->get_unit_instance_group(); - return group != nullptr ? group->get_name() : std::string_view {}; - }; - - using enum UnitType::branch_t; - switch (leader->get_branch()) { - case LAND: - return get_assignment_template(static_cast(leader)); - case NAVAL: - return get_assignment_template(static_cast(leader)); - default: - return {}; - } - }; - using enum MenuSingleton::LeaderSortKey; switch (leader_sort_key) { case LEADER_SORT_PRESTIGE: - return [](LeaderBase const* a, LeaderBase const* b) -> bool { + return [](LeaderInstance const* a, LeaderInstance const* b) -> bool { return a->get_prestige() < b->get_prestige(); }; case LEADER_SORT_TYPE: - return [](LeaderBase const* a, LeaderBase const* b) -> bool { + return [](LeaderInstance const* a, LeaderInstance const* b) -> bool { return a->get_branch() < b->get_branch(); }; case LEADER_SORT_NAME: - return [](LeaderBase const* a, LeaderBase const* b) -> bool { + return [](LeaderInstance const* a, LeaderInstance const* b) -> bool { return a->get_name() < b->get_name(); }; case LEADER_SORT_ASSIGNMENT: - return [](LeaderBase const* a, LeaderBase const* b) -> bool { - return get_assignment(a) < get_assignment(b); + return [](LeaderInstance const* a, LeaderInstance const* b) -> bool { + return (a->get_unit_instance_group() != nullptr ? a->get_unit_instance_group()->get_name() : std::string_view {}) + < (b->get_unit_instance_group() != nullptr ? b->get_unit_instance_group()->get_name() : std::string_view {}); }; default: UtilityFunctions::push_error("Invalid miltiary menu leader sort key: ", leader_sort_key); - return [](LeaderBase const* a, LeaderBase const* b) -> bool { return false; }; + return [](LeaderInstance const* a, LeaderInstance const* b) -> bool { return false; }; } } -template -using unit_group_sort_func_t = bool (*)(UnitInstanceGroup const*, UnitInstanceGroup const*); +using unit_group_sort_func_t = bool (*)(UnitInstanceGroup const*, UnitInstanceGroup const*); -template -static unit_group_sort_func_t _get_unit_group_sort_func(MenuSingleton::UnitGroupSortKey unit_group_sort_key) { +static unit_group_sort_func_t _get_unit_group_sort_func(MenuSingleton::UnitGroupSortKey unit_group_sort_key) { using enum MenuSingleton::UnitGroupSortKey; switch (unit_group_sort_key) { case UNIT_GROUP_SORT_NAME: - return [](UnitInstanceGroup const* a, UnitInstanceGroup const* b) -> bool { + return [](UnitInstanceGroup const* a, UnitInstanceGroup const* b) -> bool { return a->get_name() < b->get_name(); }; case UNIT_GROUP_SORT_STRENGTH: - return [](UnitInstanceGroup const* a, UnitInstanceGroup const* b) -> bool { + return [](UnitInstanceGroup const* a, UnitInstanceGroup const* b) -> bool { return a->get_unit_count() < b->get_unit_count(); }; default: - UtilityFunctions::push_error( - "Invalid miltiary menu ", Utilities::std_to_godot_string(UnitType::get_branched_unit_group_name(Branch)), - " sort key: ", unit_group_sort_key - ); - return [](UnitInstanceGroup const* a, UnitInstanceGroup const* b) -> bool { return false; }; + UtilityFunctions::push_error("Invalid miltiary menu unit group sort key: ", unit_group_sort_key); + return [](UnitInstanceGroup const* a, UnitInstanceGroup const* b) -> bool { return false; }; } } @@ -436,7 +387,7 @@ Dictionary MenuSingleton::get_military_menu_info( StaticModifierCache const& static_modifier_cache = definition_manager.get_modifier_manager().get_static_modifier_cache(); IssueManager const& issue_manager = definition_manager.get_politics_manager().get_issue_manager(); - CountryInstance const* country = game_singleton->get_viewed_country(); + CountryInstance const* country = PlayerSingleton::get_singleton()->get_player_country(); if (country == nullptr) { return {}; } @@ -657,13 +608,13 @@ Dictionary MenuSingleton::get_military_menu_info( ret[military_info_auto_assign_leaders_key] = country->get_auto_assign_leaders(); if (country->has_leaders()) { - std::vector sorted_leaders; + std::vector sorted_leaders; sorted_leaders.reserve(country->get_leader_count()); - for (General const& general : country->get_generals()) { - sorted_leaders.push_back(&general); + for (LeaderInstance const* general : country->get_generals()) { + sorted_leaders.push_back(general); } - for (Admiral const& admiral : country->get_admirals()) { - sorted_leaders.push_back(&admiral); + for (LeaderInstance const* admiral : country->get_admirals()) { + sorted_leaders.push_back(admiral); } if (leader_sort_key != LEADER_SORT_NONE) { @@ -672,7 +623,7 @@ Dictionary MenuSingleton::get_military_menu_info( if (sort_leaders_descending) { std::sort( sorted_leaders.begin(), sorted_leaders.end(), - [leader_sort_func](LeaderBase const* a, LeaderBase const* b) -> bool { + [leader_sort_func](LeaderInstance const* a, LeaderInstance const* b) -> bool { return leader_sort_func(b, a); } ); @@ -707,8 +658,6 @@ Dictionary MenuSingleton::get_military_menu_info( ret[military_info_is_disarmed_key] = country->is_disarmed(); - using enum UnitType::branch_t; - if (country->has_armies()) { std::vector sorted_armies; sorted_armies.reserve(country->get_army_count()); @@ -717,12 +666,12 @@ Dictionary MenuSingleton::get_military_menu_info( } if (army_sort_key != UNIT_GROUP_SORT_NONE) { - const unit_group_sort_func_t army_sort_func = _get_unit_group_sort_func(army_sort_key); + const unit_group_sort_func_t army_sort_func = _get_unit_group_sort_func(army_sort_key); if (sort_armies_descending) { std::sort( sorted_armies.begin(), sorted_armies.end(), - [army_sort_func](UnitInstanceGroup const* a, UnitInstanceGroup const* b) -> bool { + [army_sort_func](UnitInstanceGroup const* a, UnitInstanceGroup const* b) -> bool { return army_sort_func(b, a); } ); @@ -764,12 +713,12 @@ Dictionary MenuSingleton::get_military_menu_info( } if (navy_sort_key != UNIT_GROUP_SORT_NONE) { - const unit_group_sort_func_t navy_sort_func = _get_unit_group_sort_func(navy_sort_key); + const unit_group_sort_func_t navy_sort_func = _get_unit_group_sort_func(navy_sort_key); if (sort_navies_descending) { std::sort( sorted_navies.begin(), sorted_navies.end(), - [navy_sort_func](UnitInstanceGroup const* a, UnitInstanceGroup const* b) -> bool { + [navy_sort_func](UnitInstanceGroup const* a, UnitInstanceGroup const* b) -> bool { return navy_sort_func(b, a); } ); diff --git a/extension/src/openvic-extension/singletons/ModelSingleton.cpp b/extension/src/openvic-extension/singletons/ModelSingleton.cpp index f51ae77f..5b2fa8b8 100644 --- a/extension/src/openvic-extension/singletons/ModelSingleton.cpp +++ b/extension/src/openvic-extension/singletons/ModelSingleton.cpp @@ -195,7 +195,7 @@ Dictionary ModelSingleton::get_model_dict(GFX::Actor const& actor) { * Returning true doesn't necessarily mean a unit was added, e.g. when units is empty. */ template bool ModelSingleton::add_unit_dict( - ordered_set*> const& units, TypedArray& unit_array + std::vector*> const& units, TypedArray& unit_array ) { using _UnitInstanceGroup = UnitInstanceGroupBranched; diff --git a/extension/src/openvic-extension/singletons/ModelSingleton.hpp b/extension/src/openvic-extension/singletons/ModelSingleton.hpp index f0c45be0..ebec7504 100644 --- a/extension/src/openvic-extension/singletons/ModelSingleton.hpp +++ b/extension/src/openvic-extension/singletons/ModelSingleton.hpp @@ -40,7 +40,7 @@ namespace OpenVic { template bool add_unit_dict( - ordered_set*> const& units, godot::TypedArray& unit_array + std::vector*> const& units, godot::TypedArray& unit_array ); bool add_building_dict( diff --git a/extension/src/openvic-extension/singletons/PlayerSingleton.cpp b/extension/src/openvic-extension/singletons/PlayerSingleton.cpp new file mode 100644 index 00000000..24f69bb4 --- /dev/null +++ b/extension/src/openvic-extension/singletons/PlayerSingleton.cpp @@ -0,0 +1,205 @@ +#include "PlayerSingleton.hpp" + +#include +#include + +#include "openvic-extension/singletons/GameSingleton.hpp" +#include "openvic-extension/utility/ClassBindings.hpp" + +using namespace OpenVic; +using namespace godot; + +/* StringNames cannot be constructed until Godot has called StringName::setup(), + * so we must use these wrapper functions to delay their initialisation. */ +StringName const& PlayerSingleton::_signal_province_selected() { + static const StringName signal_province_selected = "province_selected"; + return signal_province_selected; +} + +void PlayerSingleton::_bind_methods() { + OV_BIND_METHOD(PlayerSingleton::set_player_country_by_province_index, { "province_index" }); + OV_BIND_METHOD(PlayerSingleton::get_player_country_capital_position); + + OV_BIND_METHOD(PlayerSingleton::set_selected_province_by_index, { "province_index" }); + OV_BIND_METHOD(PlayerSingleton::unset_selected_province); + OV_BIND_METHOD(PlayerSingleton::get_selected_province_index); + + OV_BIND_METHOD(PlayerSingleton::toggle_paused); + OV_BIND_METHOD(PlayerSingleton::increase_speed); + OV_BIND_METHOD(PlayerSingleton::decrease_speed); + + OV_BIND_METHOD(PlayerSingleton::set_auto_create_leaders, { "value" }); + OV_BIND_METHOD(PlayerSingleton::set_auto_assign_leaders, { "value" }); + + OV_BIND_METHOD(PlayerSingleton::expand_selected_province_building, { "building_index" }); + + ADD_SIGNAL(MethodInfo(_signal_province_selected(), PropertyInfo(Variant::INT, "index"))); +} + +PlayerSingleton* PlayerSingleton::get_singleton() { + return singleton; +} + +PlayerSingleton::PlayerSingleton() { + ERR_FAIL_COND(singleton != nullptr); + singleton = this; +} + +PlayerSingleton::~PlayerSingleton() { + ERR_FAIL_COND(singleton != this); + singleton = nullptr; +} + +void PlayerSingleton::set_player_country(CountryInstance const* new_player_country) { + if (player_country != new_player_country) { + GameSingleton& game_singleton = *GameSingleton::get_singleton(); + InstanceManager* instance_manager = game_singleton.get_instance_manager(); + ERR_FAIL_NULL(instance_manager); + + if (player_country != nullptr) { + instance_manager->queue_game_action( + game_action_type_t::GAME_ACTION_SET_AI, + std::pair { player_country->get_index(), true } + ); + } + + player_country = new_player_country; + + if (player_country != nullptr) { + instance_manager->queue_game_action( + game_action_type_t::GAME_ACTION_SET_AI, + std::pair { player_country->get_index(), false } + ); + } + + Logger::info("Set player country to: ", player_country); + + game_singleton._on_gamestate_updated(); + } +} + +void PlayerSingleton::set_player_country_by_province_index(int32_t province_index) { + InstanceManager* instance_manager = GameSingleton::get_singleton()->get_instance_manager(); + ERR_FAIL_NULL(instance_manager); + + ProvinceInstance* province_instance = instance_manager->get_map_instance().get_province_instance_by_index(province_index); + ERR_FAIL_NULL(province_instance); + + set_player_country(province_instance->get_owner()); +} + +Vector2 PlayerSingleton::get_player_country_capital_position() const { + if (player_country != nullptr) { + ProvinceInstance const* capital = player_country->get_capital(); + + if (capital != nullptr) { + return GameSingleton::get_singleton()->get_billboard_pos(capital->get_province_definition()); + } + } + + return {}; +} + +void PlayerSingleton::set_selected_province(ProvinceInstance const* new_selected_province) { + if (selected_province != new_selected_province) { + selected_province = new_selected_province; + + GameSingleton::get_singleton()->_update_colour_image(); + + emit_signal(_signal_province_selected(), get_selected_province_index()); + } +} + +void PlayerSingleton::set_selected_province_by_index(int32_t province_index) { + if (province_index == ProvinceDefinition::NULL_INDEX) { + unset_selected_province(); + } else { + InstanceManager const* instance_manager = GameSingleton::get_singleton()->get_instance_manager(); + ERR_FAIL_NULL(instance_manager); + + MapInstance const& map_instance = instance_manager->get_map_instance(); + + set_selected_province(map_instance.get_province_instance_by_index(province_index)); + + if (selected_province == nullptr) { + Logger::error( + "Trying to set selected province to an invalid index ", province_index, " (max index is ", + map_instance.get_province_instance_count(), ")" + ); + } + } +} + +void PlayerSingleton::unset_selected_province() { + set_selected_province(nullptr); +} + +int32_t PlayerSingleton::get_selected_province_index() const { + return selected_province != nullptr ? selected_province->get_index() : ProvinceDefinition::NULL_INDEX; +} + +void PlayerSingleton::toggle_paused() { + InstanceManager* instance_manager = GameSingleton::get_singleton()->get_instance_manager(); + ERR_FAIL_NULL(instance_manager); + + instance_manager->queue_game_action( + game_action_type_t::GAME_ACTION_SET_PAUSE, + !instance_manager->get_simulation_clock().is_paused() + ); +} + +void PlayerSingleton::increase_speed() { + InstanceManager* instance_manager = GameSingleton::get_singleton()->get_instance_manager(); + ERR_FAIL_NULL(instance_manager); + + instance_manager->queue_game_action( + game_action_type_t::GAME_ACTION_SET_SPEED, + instance_manager->get_simulation_clock().get_simulation_speed() + 1 + ); +} + +void PlayerSingleton::decrease_speed() { + InstanceManager* instance_manager = GameSingleton::get_singleton()->get_instance_manager(); + ERR_FAIL_NULL(instance_manager); + + instance_manager->queue_game_action( + game_action_type_t::GAME_ACTION_SET_SPEED, + instance_manager->get_simulation_clock().get_simulation_speed() - 1 + ); +} + +void PlayerSingleton::set_auto_create_leaders(bool value) const { + ERR_FAIL_NULL(player_country); + + InstanceManager* instance_manager = GameSingleton::get_singleton()->get_instance_manager(); + ERR_FAIL_NULL(instance_manager); + + instance_manager->queue_game_action( + game_action_type_t::GAME_ACTION_SET_AUTO_CREATE_LEADERS, + std::pair { player_country->get_index(), value } + ); +} + +void PlayerSingleton::set_auto_assign_leaders(bool value) const { + ERR_FAIL_NULL(player_country); + + InstanceManager* instance_manager = GameSingleton::get_singleton()->get_instance_manager(); + ERR_FAIL_NULL(instance_manager); + + instance_manager->queue_game_action( + game_action_type_t::GAME_ACTION_SET_AUTO_ASSIGN_LEADERS, + std::pair { player_country->get_index(), value } + ); +} + +void PlayerSingleton::expand_selected_province_building(int32_t building_index) { + ERR_FAIL_NULL(selected_province); + + InstanceManager* instance_manager = GameSingleton::get_singleton()->get_instance_manager(); + ERR_FAIL_NULL(instance_manager); + + instance_manager->queue_game_action( + game_action_type_t::GAME_ACTION_EXPAND_PROVINCE_BUILDING, + std::pair { selected_province->get_index(), building_index } + ); +} diff --git a/extension/src/openvic-extension/singletons/PlayerSingleton.hpp b/extension/src/openvic-extension/singletons/PlayerSingleton.hpp new file mode 100644 index 00000000..e8260660 --- /dev/null +++ b/extension/src/openvic-extension/singletons/PlayerSingleton.hpp @@ -0,0 +1,50 @@ +#pragma once + +#include + +#include + +namespace OpenVic { + struct CountryInstance; + struct ProvinceInstance; + + class PlayerSingleton : public godot::Object { + GDCLASS(PlayerSingleton, godot::Object) + + static inline PlayerSingleton* singleton = nullptr; + + // TODO - move selected province here! + + CountryInstance const* PROPERTY(player_country, nullptr); + ProvinceInstance const* PROPERTY(selected_province, nullptr); + + static godot::StringName const& _signal_province_selected(); + + protected: + static void _bind_methods(); + + public: + static PlayerSingleton* get_singleton(); + + PlayerSingleton(); + ~PlayerSingleton(); + + void set_player_country(CountryInstance const* new_player_country); + void set_player_country_by_province_index(int32_t province_index); + godot::Vector2 get_player_country_capital_position() const; + + void set_selected_province(ProvinceInstance const* new_selected_province); + void set_selected_province_by_index(int32_t province_index); + void unset_selected_province(); + int32_t get_selected_province_index() const; + + void toggle_paused(); + void increase_speed(); + void decrease_speed(); + + void set_auto_create_leaders(bool value) const; + void set_auto_assign_leaders(bool value) const; + + void expand_selected_province_building(int32_t building_index); + }; +} diff --git a/extension/src/openvic-extension/singletons/PopulationMenu.cpp b/extension/src/openvic-extension/singletons/PopulationMenu.cpp index 7f7fa8db..cb976d22 100644 --- a/extension/src/openvic-extension/singletons/PopulationMenu.cpp +++ b/extension/src/openvic-extension/singletons/PopulationMenu.cpp @@ -291,7 +291,7 @@ Error MenuSingleton::population_menu_select_province(int32_t province_index) { } bool operator()(population_menu_t::province_entry_t& province_entry) { - if (province_entry.province.get_province_definition().get_index() == _province_index) { + if (province_entry.province.get_index() == _province_index) { if (state_entry_to_expand >= 0) { ret &= menu_singleton.population_menu_toggle_expanded(state_entry_to_expand, false) == OK; diff --git a/extension/src/openvic-extension/singletons/TradeMenu.cpp b/extension/src/openvic-extension/singletons/TradeMenu.cpp index 8a65d7fb..03f00e55 100644 --- a/extension/src/openvic-extension/singletons/TradeMenu.cpp +++ b/extension/src/openvic-extension/singletons/TradeMenu.cpp @@ -4,6 +4,7 @@ #include "openvic-extension/classes/GUILabel.hpp" #include "openvic-extension/singletons/GameSingleton.hpp" +#include "openvic-extension/singletons/PlayerSingleton.hpp" #include "openvic-extension/utility/Utilities.hpp" using namespace OpenVic; @@ -18,14 +19,13 @@ Dictionary MenuSingleton::get_trade_menu_good_categories_info() const { static const StringName demand_tooltip_key = "demand_tooltip"; static const StringName trade_settings_key = "trade_settings"; - GameSingleton const& game_singleton = *GameSingleton::get_singleton(); - InstanceManager const* instance_manager = game_singleton.get_instance_manager(); + InstanceManager const* instance_manager = GameSingleton::get_singleton()->get_instance_manager(); ERR_FAIL_NULL_V(instance_manager, {}); GoodInstanceManager const& good_instance_manager = instance_manager->get_good_instance_manager(); GoodDefinitionManager const& good_definition_manager = good_instance_manager.get_good_definition_manager(); - CountryInstance const* country = game_singleton.get_viewed_country(); + CountryInstance const* country = PlayerSingleton::get_singleton()->get_player_country(); Dictionary ret; @@ -123,15 +123,14 @@ Dictionary MenuSingleton::get_trade_menu_trade_details_info(int32_t trade_detail static const StringName trade_detail_pop_needs_key = "trade_detail_pop_needs"; static const StringName trade_detail_available_key = "trade_detail_available"; - GameSingleton const& game_singleton = *GameSingleton::get_singleton(); - InstanceManager const* instance_manager = game_singleton.get_instance_manager(); + InstanceManager const* instance_manager = GameSingleton::get_singleton()->get_instance_manager(); ERR_FAIL_NULL_V(instance_manager, {}); GoodInstance const* good_instance = instance_manager->get_good_instance_manager().get_good_instance_by_index(trade_detail_good_index); ERR_FAIL_NULL_V(good_instance, {}); - CountryInstance const* country = game_singleton.get_viewed_country(); + CountryInstance const* country = PlayerSingleton::get_singleton()->get_player_country(); Dictionary ret; @@ -190,12 +189,11 @@ Dictionary MenuSingleton::get_trade_menu_tables_info() const { static const StringName stockpile_key = "stockpile"; static const StringName common_market_key = "common_market"; - GameSingleton const& game_singleton = *GameSingleton::get_singleton(); - InstanceManager const* instance_manager = game_singleton.get_instance_manager(); + InstanceManager const* instance_manager = GameSingleton::get_singleton()->get_instance_manager(); ERR_FAIL_NULL_V(instance_manager, {}); GoodInstanceManager const& good_instance_manager = instance_manager->get_good_instance_manager(); - CountryInstance const* country = game_singleton.get_viewed_country(); + CountryInstance const* country = PlayerSingleton::get_singleton()->get_player_country(); Dictionary ret; diff --git a/game/src/Game/GameSession/GameSession.gd b/game/src/Game/GameSession/GameSession.gd index f9c29824..f2cb5518 100644 --- a/game/src/Game/GameSession/GameSession.gd +++ b/game/src/Game/GameSession/GameSession.gd @@ -28,7 +28,7 @@ func _on_map_view_ready() -> void: # Set the camera's starting position _map_view._camera.position = _map_view._map_to_world_coords( # Start at the player country's capital position (when loading a save game in the lobby or entering the actual game) - GameSingleton.get_viewed_country_capital_position() + PlayerSingleton.get_player_country_capital_position() ) func _on_map_view_province_hovered(index: int) -> void: @@ -38,9 +38,9 @@ func _on_map_view_province_unhovered() -> void: _map_view.unset_hovered_province() func _on_map_view_province_clicked(index: int) -> void: - GameSingleton.set_selected_province(index) + PlayerSingleton.set_selected_province_by_index(index) func _on_map_view_province_right_clicked(index: int) -> void: # TODO - open diplomacy screen on province owner or viewed country if province has no owner #Events.NationManagementScreens.open_nation_management_screen(NationManagement.Screen.DIPLOMACY) - GameSingleton.set_viewed_country_by_province_index(index) + PlayerSingleton.set_player_country_by_province_index(index) diff --git a/game/src/Game/GameSession/MapView.gd b/game/src/Game/GameSession/MapView.gd index 7cc69b25..80f0bc5d 100644 --- a/game/src/Game/GameSession/MapView.gd +++ b/game/src/Game/GameSession/MapView.gd @@ -105,7 +105,7 @@ func _ready() -> void: map_mesh_aabb.position.z - map_mesh_aabb.end.z )) - GameSingleton.province_selected.connect(_on_province_selected) + PlayerSingleton.province_selected.connect(_on_province_selected) # Start zoomed out with the parchment map active _camera.position.y = _zoom_parchment_threshold * 1.5 diff --git a/game/src/Game/GameSession/NationManagementScreen/MilitaryMenu.gd b/game/src/Game/GameSession/NationManagementScreen/MilitaryMenu.gd index ce9a2731..de685b2d 100644 --- a/game/src/Game/GameSession/NationManagementScreen/MilitaryMenu.gd +++ b/game/src/Game/GameSession/NationManagementScreen/MilitaryMenu.gd @@ -152,11 +152,11 @@ func _ready() -> void: _create_admiral_button.pressed.connect(func() -> void: print("CREATE ADMIRAL")) _auto_create_leader_button = GUINode.get_gui_icon_button_from_node(leaders_panel.get_node(^"./auto_create")) if _auto_create_leader_button: - _auto_create_leader_button.toggled.connect(func(state : bool) -> void: print("AUTO CREATE LEADERS = ", state)) + _auto_create_leader_button.toggled.connect(func(state : bool) -> void: PlayerSingleton.set_auto_create_leaders(state)) _auto_create_leader_button.set_tooltip_string("MILITARY_AUTOCREATE_TOOLTIP") _auto_assign_leader_button = GUINode.get_gui_icon_button_from_node(leaders_panel.get_node(^"./auto_assign")) if _auto_assign_leader_button: - _auto_assign_leader_button.toggled.connect(func(state : bool) -> void: print("AUTO ASSIGN LEADERS = ", state)) + _auto_assign_leader_button.toggled.connect(func(state : bool) -> void: PlayerSingleton.set_auto_assign_leaders(state)) _auto_assign_leader_button.set_tooltip_string("MILITARY_AUTOASSIGN_TOOLTIP") _leader_listbox = GUINode.get_gui_listbox_from_node(military_menu.get_node(^"./leaders/leader_listbox")) diff --git a/game/src/Game/GameSession/ProvinceOverviewPanel.gd b/game/src/Game/GameSession/ProvinceOverviewPanel.gd index 36040034..684da5d2 100644 --- a/game/src/Game/GameSession/ProvinceOverviewPanel.gd +++ b/game/src/Game/GameSession/ProvinceOverviewPanel.gd @@ -72,7 +72,7 @@ class BuildingSlot: building_name.text = MenuSingleton.get_province_building_identifier(_slot_index) _expand_button = GUINode.get_gui_icon_button_from_node(_slot_node.get_node(^"./expand")) if _expand_button: - _expand_button.pressed.connect(func() -> void: MenuSingleton.expand_selected_province_building(_slot_index)) + _expand_button.pressed.connect(func() -> void: PlayerSingleton.expand_selected_province_building(_slot_index)) _expanding_icon = GUINode.get_gui_icon_from_node(_slot_node.get_node(^"./underconstruction_icon")) _expanding_progress_bar = GUINode.get_gui_progress_bar_from_node(_slot_node.get_node(^"./building_progress")) if _expanding_progress_bar: @@ -117,7 +117,7 @@ var _selected_index : int: var _province_info : Dictionary func _ready() -> void: - GameSingleton.province_selected.connect(_on_province_selected) + PlayerSingleton.province_selected.connect(_on_province_selected) GameSingleton.gamestate_updated.connect(_update_info) if add_gui_element("province_interface", "province_view") != OK: @@ -394,4 +394,4 @@ func _on_province_selected(index : int) -> void: _selected_index = index func _on_close_button_pressed() -> void: - GameSingleton.unset_selected_province() + PlayerSingleton.unset_selected_province() diff --git a/game/src/Game/GameSession/Topbar.gd b/game/src/Game/GameSession/Topbar.gd index ac9019f9..d0f3c29f 100644 --- a/game/src/Game/GameSession/Topbar.gd +++ b/game/src/Game/GameSession/Topbar.gd @@ -76,7 +76,6 @@ var _military_leadership_points_label : GUILabel func _ready() -> void: GameSingleton.gamestate_updated.connect(_update_info) - GameSingleton.clock_state_changed.connect(_update_speed_controls) add_gui_element("topbar", "topbar") @@ -109,7 +108,7 @@ func _ready() -> void: # Time controls _speed_up_button = get_gui_icon_button_from_nodepath(^"./topbar/button_speedup") if _speed_up_button: - _speed_up_button.pressed.connect(_on_increase_speed_button_pressed) + _speed_up_button.pressed.connect(PlayerSingleton.increase_speed) _speed_up_button.set_tooltip_string("TOPBAR_INC_SPEED") var speed_up_action := InputEventAction.new() speed_up_action.action = "time_speed_increase" @@ -117,7 +116,7 @@ func _ready() -> void: _speed_up_button.shortcut.events.append(speed_up_action) _speed_down_button = get_gui_icon_button_from_nodepath(^"./topbar/button_speeddown") if _speed_down_button: - _speed_down_button.pressed.connect(_on_decrease_speed_button_pressed) + _speed_down_button.pressed.connect(PlayerSingleton.decrease_speed) _speed_down_button.set_tooltip_string("TOPBAR_DEC_SPEED") var speed_down_action := InputEventAction.new() speed_down_action.action = "time_speed_decrease" @@ -125,14 +124,14 @@ func _ready() -> void: _speed_down_button.shortcut.events.append(speed_down_action) _pause_bg_button = get_gui_icon_button_from_nodepath(^"./topbar/pause_bg") if _pause_bg_button: - _pause_bg_button.pressed.connect(_on_play_pause_button_pressed) + _pause_bg_button.pressed.connect(PlayerSingleton.toggle_paused) var time_pause_action := InputEventAction.new() time_pause_action.action = "time_pause" _pause_bg_button.shortcut = Shortcut.new() _pause_bg_button.shortcut.events.append(time_pause_action) _speed_indicator_button = get_gui_icon_button_from_nodepath(^"./topbar/speed_indicator") if _speed_indicator_button: - _speed_indicator_button.pressed.connect(_on_play_pause_button_pressed) + _speed_indicator_button.pressed.connect(PlayerSingleton.toggle_paused) _date_label = get_gui_label_from_nodepath(^"./topbar/DateText") # Nation management screens @@ -280,13 +279,11 @@ func _ready() -> void: _military_leadership_points_label.set_auto_translate(false) _update_info() - _update_speed_controls() func _notification(what : int) -> void: match what: NOTIFICATION_TRANSLATION_CHANGED: _update_info() - _update_speed_controls() enum CountryStatus { GREAT_POWER, @@ -298,6 +295,8 @@ enum CountryStatus { } func _update_info() -> void: + _update_speed_controls() + var topbar_info : Dictionary = MenuSingleton.get_topbar_info() ## Country info @@ -604,24 +603,6 @@ func _update_speed_controls() -> void: ) _speed_indicator_button.set_icon_index(index) -# REQUIREMENTS: -# * UIFUN-71 -func _on_play_pause_button_pressed() -> void: - print("Toggling pause!") - MenuSingleton.toggle_paused() - -# REQUIREMENTS: -# * UIFUN-72 -func _on_increase_speed_button_pressed() -> void: - print("Speed up!") - MenuSingleton.increase_speed() - -# REQUIREMENTS: -# * UIFUN-73 -func _on_decrease_speed_button_pressed() -> void: - print("Speed down!") - MenuSingleton.decrease_speed() - func _on_update_active_nation_management_screen(active_screen : NationManagement.Screen) -> void: for screen : NationManagement.Screen in _nation_management_buttons: _nation_management_buttons[screen].set_icon_index(1 + int(screen == active_screen)) diff --git a/game/src/Game/GameStart.tscn b/game/src/Game/GameStart.tscn index 3b3a41fb..dc264813 100644 --- a/game/src/Game/GameStart.tscn +++ b/game/src/Game/GameStart.tscn @@ -56,8 +56,8 @@ expand = true process_mode = 2 disable_3d = true title = "VIC2_DIR_DIALOG_TITLE" -size = Vector2i(935, 159) -ok_button_text = "VIC2_DIR_DIALOG_SELECT" +size = Vector2i(935, 175) +ok_button_text = "Select Current Folder" cancel_button_text = "VIC2_DIR_DIALOG_CANCEL" mode_overrides_title = false file_mode = 2 diff --git a/game/src/Game/Menu/LobbyMenu/LobbyMenu.gd b/game/src/Game/Menu/LobbyMenu/LobbyMenu.gd index 2951c738..0b402132 100644 --- a/game/src/Game/Menu/LobbyMenu/LobbyMenu.gd +++ b/game/src/Game/Menu/LobbyMenu/LobbyMenu.gd @@ -183,5 +183,5 @@ func _on_map_view_ready() -> void: pass func _on_map_view_province_clicked(_index: int) -> void: - # TODO: need to be able to call something like GameSingleton.set_viewed_country_by_province_index(index) here + # TODO: need to be able to call something like PlayerSingleton.set_player_country_by_province_index(index) here pass diff --git a/game/src/Game/MusicConductor/MusicConductor.gd b/game/src/Game/MusicConductor/MusicConductor.gd index ade8fb4d..df1b1ed3 100644 --- a/game/src/Game/MusicConductor/MusicConductor.gd +++ b/game/src/Game/MusicConductor/MusicConductor.gd @@ -67,7 +67,7 @@ func toggle_play_pause() -> void: func start_current_song() -> void: _audio_stream_player.stream = _available_songs[_selected_track].song_stream - _audio_stream_player.play() + # _audio_stream_player.play() song_started.emit(_selected_track) # REQUIREMENTS