Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions extension/doc_classes/MenuSingleton.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,46 @@
<description>
</description>
</method>
<method name="get_specific_technology_info" qualifiers="const">
<return type="Dictionary" />
<param index="0" name="technology_identifier" type="String" />
<description>
Returns the effects, point cost, unlock year, and prerequisite tech of the given technology, in a [Dictionary].
</description>
</method>
<method name="get_speed" qualifiers="const">
<return type="int" />
<description>
</description>
</method>
<method name="get_technology_menu_defines" qualifiers="const">
<return type="Dictionary" />
<description>
Returns a [Dictionary] with static defines for the technology menu.
</description>
</method>
<method name="get_technology_menu_info" qualifiers="const">
<return type="Dictionary" />
<description>
Returns a [Dictionary] with the dynamic state of the technology menu.
</description>
</method>
<method name="get_tooltip_condition_met" qualifiers="static">
<return type="String" />
<description>
Returns the colored symbol used by met tooltip conditions "(*)"
</description>
</method>
<method name="get_tooltip_condition_unmet" qualifiers="static">
<return type="String" />
<description>
Returns the colored symbol used by unmet tooltip conditions "(X)"
</description>
</method>
<method name="get_tooltip_separator" qualifiers="static">
<return type="String" />
<description>
Returns the symbol used to separate normal and extended tooltips.
</description>
</method>
<method name="get_topbar_info" qualifiers="const">
Expand Down
6 changes: 6 additions & 0 deletions extension/doc_classes/PlayerSingleton.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@
<description>
</description>
</method>
<method name="start_research" qualifiers="const">
<return type="void" />
<param index="0" name="technology_identifier" type="String" />
<description>
</description>
</method>
<method name="toggle_paused" qualifiers="const">
<return type="void" />
<description>
Expand Down
12 changes: 1 addition & 11 deletions extension/src/openvic-extension/singletons/GameSingleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "openvic-extension/singletons/PlayerSingleton.hpp"
#include "openvic-extension/utility/ClassBindings.hpp"
#include "openvic-extension/utility/Utilities.hpp"
#include "openvic-simulation/country/CountryInstance.hpp"

using namespace godot;
using namespace OpenVic;
Expand Down Expand Up @@ -159,17 +160,6 @@ Error GameSingleton::setup_game(int32_t bookmark_index) {
player_singleton.set_player_country(starting_country);
ERR_FAIL_NULL_V(player_singleton.get_player_country(), FAILED);

// TODO - remove this test starting research
for (
Technology const& technology :
get_definition_manager().get_research_manager().get_technology_manager().get_technologies()
) {
if (starting_country->can_research_tech(technology, instance_manager->get_today())) {
starting_country->start_research(technology, *instance_manager);
break;
}
}

return ERR(ret);
}

Expand Down
41 changes: 37 additions & 4 deletions extension/src/openvic-extension/singletons/MenuSingleton.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
#include "MenuSingleton.hpp"

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <string_view>

#include <godot_cpp/variant/utility_functions.hpp>
#include <godot_cpp/variant/dictionary.hpp>
#include <godot_cpp/variant/packed_string_array.hpp>

#include <openvic-simulation/economy/GoodDefinition.hpp>
#include <openvic-simulation/modifier/Modifier.hpp>
#include <openvic-simulation/types/fixed_point/FixedPoint.hpp>
#include <openvic-simulation/economy/GoodDefinition.hpp>
#include <openvic-simulation/research/Technology.hpp>
#include <openvic-simulation/country/CountryInstance.hpp>
#include <openvic-simulation/modifier/ModifierEffect.hpp>

#include "openvic-extension/classes/GUILabel.hpp"
#include "openvic-extension/utility/Utilities.hpp"
#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"

using namespace godot;
using namespace OpenVic;
Expand Down Expand Up @@ -168,13 +179,17 @@ String MenuSingleton::_make_modifier_effect_value_coloured(
return result;
}

String MenuSingleton::_make_modifier_effect_tooltip(ModifierEffect const& effect, const fixed_point_t value) const {
return tr(Utilities::std_to_godot_string(effect.get_localisation_key())) + ": " +
_make_modifier_effect_value_coloured(effect, value, true);
}

String MenuSingleton::_make_modifier_effects_tooltip(ModifierValue const& modifier) const {
String result;

for (auto const& [effect, value] : modifier.get_values()) {
if (value != fixed_point_t::_0()) {
result += "\n" + tr(Utilities::std_to_godot_string(effect->get_localisation_key())) + ": " +
_make_modifier_effect_value_coloured(*effect, value, true);
result += "\n" + _make_modifier_effect_tooltip(*effect, value);
}
}

Expand Down Expand Up @@ -314,6 +329,9 @@ String MenuSingleton::_make_mobilisation_impact_tooltip() const {

void MenuSingleton::_bind_methods() {
OV_BIND_SMETHOD(get_tooltip_separator);
OV_BIND_SMETHOD(get_tooltip_condition_met);
OV_BIND_SMETHOD(get_tooltip_condition_unmet);

OV_BIND_METHOD(MenuSingleton::get_country_name_from_identifier, { "country_identifier" });
OV_BIND_METHOD(MenuSingleton::get_country_adjective_from_identifier, { "country_identifier" });

Expand Down Expand Up @@ -436,6 +454,11 @@ void MenuSingleton::_bind_methods() {
OV_BIND_METHOD(MenuSingleton::get_search_result_position, { "result_index" });

ADD_SIGNAL(MethodInfo(_signal_search_cache_changed()));

/* TECHNOLOGY MENU */
OV_BIND_METHOD(MenuSingleton::get_technology_menu_defines);
OV_BIND_METHOD(MenuSingleton::get_technology_menu_info);
OV_BIND_METHOD(MenuSingleton::get_specific_technology_info, { "technology_identifier" });
}

MenuSingleton* MenuSingleton::get_singleton() {
Expand All @@ -460,6 +483,16 @@ String MenuSingleton::get_tooltip_separator() {
return tooltip_separator;
}

String MenuSingleton::get_tooltip_condition_met() {
static const String condition_met = String { "(" } + GUILabel::get_colour_marker() + String { "G*" } + GUILabel::get_colour_marker() + "W)";
return condition_met;
}

String MenuSingleton::get_tooltip_condition_unmet() {
static const String condition_unmet = String { "(" } + GUILabel::get_colour_marker() + String { "RX" } + GUILabel::get_colour_marker() + "W)";
return condition_unmet;
}

String MenuSingleton::get_country_name_from_identifier(String const& country_identifier) const {
if (country_identifier.is_empty()) {
return {};
Expand Down
15 changes: 13 additions & 2 deletions extension/src/openvic-extension/singletons/MenuSingleton.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#pragma once

#include <variant>

#include <godot_cpp/classes/control.hpp>
#include <godot_cpp/classes/image.hpp>
#include <godot_cpp/variant/dictionary.hpp>

#include <openvic-simulation/military/UnitInstanceGroup.hpp>
#include <openvic-simulation/types/IndexedMap.hpp>
#include <openvic-simulation/types/PopSize.hpp>
#include <openvic-simulation/types/OrderedContainers.hpp>
#include <openvic-simulation/types/fixed_point/FixedPoint.hpp>
#include <openvic-simulation/modifier/ModifierEffect.hpp>
#include <openvic-simulation/pop/Pop.hpp>

namespace OpenVic {
struct CountryInstance;
Expand Down Expand Up @@ -149,6 +151,7 @@ namespace OpenVic {
ModifierEffect const& format_effect, fixed_point_t value, bool plus_for_non_negative
);

godot::String _make_modifier_effect_tooltip(ModifierEffect const& effect, const fixed_point_t value) const;
godot::String _make_modifier_effects_tooltip(ModifierValue const& modifier) const;

template<typename T>
Expand All @@ -173,6 +176,9 @@ namespace OpenVic {
~MenuSingleton();

static godot::String get_tooltip_separator();
static godot::String get_tooltip_condition_met();
static godot::String get_tooltip_condition_unmet();

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;

Expand Down Expand Up @@ -233,6 +239,11 @@ namespace OpenVic {
/* Array of GFXPieChartTexture::godot_pie_chart_data_t. */
godot::TypedArray<godot::Array> get_population_menu_distribution_info() const;

/* TECHNOLOGY MENU */
godot::Dictionary get_technology_menu_defines() const;
godot::Dictionary get_technology_menu_info() const;
godot::Dictionary get_specific_technology_info(godot::String technology_identifier) const;

/* TRADE MENU */
godot::Dictionary get_trade_menu_good_categories_info() const;
godot::Dictionary get_trade_menu_trade_details_info(
Expand Down
21 changes: 21 additions & 0 deletions extension/src/openvic-extension/singletons/PlayerSingleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "openvic-extension/singletons/GameSingleton.hpp"
#include "openvic-extension/singletons/MenuSingleton.hpp"
#include "openvic-extension/utility/ClassBindings.hpp"
#include "openvic-extension/utility/Utilities.hpp"

using namespace OpenVic;
using namespace godot;
Expand Down Expand Up @@ -39,6 +40,7 @@ void PlayerSingleton::_bind_methods() {
// Budget

// Technology
OV_BIND_METHOD(PlayerSingleton::start_research, { "technology_identifier" });

// Politics

Expand Down Expand Up @@ -213,6 +215,25 @@ void PlayerSingleton::expand_selected_province_building(int32_t building_index)
// Budget

// Technology
void PlayerSingleton::start_research(String const& technology_identifier) const {
ERR_FAIL_NULL(player_country);

GameSingleton& game_singleton = *GameSingleton::get_singleton();

Technology const* technology =
game_singleton.get_definition_manager().get_research_manager().get_technology_manager().get_technology_by_identifier(
Utilities::godot_to_std_string(technology_identifier)
);
ERR_FAIL_NULL(technology);

InstanceManager* instance_manager = game_singleton.get_instance_manager();
ERR_FAIL_NULL(instance_manager);

instance_manager->queue_game_action(
game_action_type_t::GAME_ACTION_START_RESEARCH,
std::pair<uint64_t, uint64_t> { player_country->get_index(), technology->get_index() }
);
}

// Politics

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace OpenVic {
// Budget

// Technology
void start_research(godot::String const& technology_identifier) const;

// Politics

Expand Down
Loading
Loading