Skip to content

Commit

Permalink
Implement the Technology Menu
Browse files Browse the repository at this point in the history
  • Loading branch information
BrickPi committed Feb 2, 2025
1 parent 38c1d46 commit cae21ea
Show file tree
Hide file tree
Showing 7 changed files with 562 additions and 24 deletions.
38 changes: 38 additions & 0 deletions extension/doc_classes/MenuSingleton.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,46 @@
<description>
</description>
</method>
<method name="get_specific_technology_info" qualifiers="const">
<return type="Dictionary" />
<param index="0" name="technology_id" 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 coloured symbol used by met tooltip conditions "(*)"
</description>
</method>
<method name="get_tooltip_condition_unmet" qualifiers="static">
<return type="String" />
<description>
Returns the coloured 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 Expand Up @@ -270,6 +302,12 @@
<description>
</description>
</method>
<method name="start_research">
<return type="void" />
<param index="0" name="technology_id" type="String" />
<description>
</description>
</method>
<method name="toggle_paused">
<return type="void" />
<description>
Expand Down
16 changes: 3 additions & 13 deletions extension/src/openvic-extension/singletons/GameSingleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "openvic-extension/singletons/MenuSingleton.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 @@ -179,17 +180,6 @@ Error GameSingleton::setup_game(int32_t bookmark_index) {
set_viewed_country(starting_country);
ERR_FAIL_NULL_V(viewed_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 Expand Up @@ -425,7 +415,7 @@ void GameSingleton::unset_selected_province() {
set_selected_province(ProvinceDefinition::NULL_INDEX);
}

void GameSingleton::set_viewed_country(CountryInstance const* new_viewed_country) {
void GameSingleton::set_viewed_country(CountryInstance* new_viewed_country) {
if (viewed_country != new_viewed_country) {
viewed_country = new_viewed_country;

Expand All @@ -439,7 +429,7 @@ 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 =
ProvinceInstance* province_instance =
instance_manager->get_map_instance().get_province_instance_by_index(province_index);
ERR_FAIL_NULL(province_instance);

Expand Down
4 changes: 2 additions & 2 deletions extension/src/openvic-extension/singletons/GameSingleton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace OpenVic {

GameManager game_manager;

CountryInstance const* PROPERTY(viewed_country, nullptr);
CountryInstance* PROPERTY_PTR(viewed_country, nullptr);

godot::Vector2i image_subdivisions;
godot::Ref<godot::Texture2DArray> province_shape_texture;
Expand Down Expand Up @@ -133,7 +133,7 @@ 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(CountryInstance* new_viewed_country);
void set_viewed_country_by_province_index(int32_t province_index);
godot::Vector2 get_viewed_country_capital_position() const;

Expand Down
46 changes: 40 additions & 6 deletions extension/src/openvic-extension/singletons/MenuSingleton.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
#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/utility/ClassBindings.hpp"
#include "openvic-extension/utility/Utilities.hpp"

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

String MenuSingleton::_make_modifier_effects_tooltip(ModifierValue const& modifier) const {
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& modifiers) const {
String result;

for (auto const& [effect, value] : modifier.get_values()) {
for (auto const& [effect, value] : modifiers.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 @@ -315,6 +330,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 @@ -441,6 +459,12 @@ 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_id" });
OV_BIND_METHOD(MenuSingleton::start_research, { "technology_id" });
}

MenuSingleton* MenuSingleton::get_singleton() {
Expand All @@ -465,6 +489,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
16 changes: 14 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 @@ -148,6 +150,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 @@ -172,6 +175,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 @@ -237,6 +243,12 @@ 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_id) const;
void start_research(godot::String technology_id); // TODO: move to PlayerSingleton

/* TRADE MENU */
godot::Dictionary get_trade_menu_good_categories_info() const;
godot::Dictionary get_trade_menu_trade_details_info(int32_t trade_detail_good_index) const;
Expand Down
Loading

0 comments on commit cae21ea

Please sign in to comment.