Skip to content

Commit 0f67b06

Browse files
committed
Implement the Technology Menu
1 parent 38a840b commit 0f67b06

File tree

7 files changed

+560
-24
lines changed

7 files changed

+560
-24
lines changed

extension/doc_classes/MenuSingleton.xml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,46 @@
155155
<description>
156156
</description>
157157
</method>
158+
<method name="get_specific_technology_info" qualifiers="const">
159+
<return type="Dictionary" />
160+
<param index="0" name="technology_id" type="String" />
161+
<description>
162+
Returns the effects, point cost, unlock year, and prerequisite tech of the given technology, in a [Dictionary].
163+
</description>
164+
</method>
158165
<method name="get_speed" qualifiers="const">
159166
<return type="int" />
160167
<description>
161168
</description>
162169
</method>
170+
<method name="get_technology_menu_defines" qualifiers="const">
171+
<return type="Dictionary" />
172+
<description>
173+
Returns a [Dictionary] with static defines for the technology menu.
174+
</description>
175+
</method>
176+
<method name="get_technology_menu_info" qualifiers="const">
177+
<return type="Dictionary" />
178+
<description>
179+
Returns a [Dictionary] with the dynamic state of the technology menu.
180+
</description>
181+
</method>
182+
<method name="get_tooltip_condition_met" qualifiers="static">
183+
<return type="String" />
184+
<description>
185+
Returns the coloured symbol used by met tooltip conditions "(*)"
186+
</description>
187+
</method>
188+
<method name="get_tooltip_condition_unmet" qualifiers="static">
189+
<return type="String" />
190+
<description>
191+
Returns the coloured symbol used by unmet tooltip conditions "(X)"
192+
</description>
193+
</method>
163194
<method name="get_tooltip_separator" qualifiers="static">
164195
<return type="String" />
165196
<description>
197+
Returns the symbol used to separate normal and extended tooltips.
166198
</description>
167199
</method>
168200
<method name="get_topbar_info" qualifiers="const">
@@ -254,6 +286,12 @@
254286
<description>
255287
</description>
256288
</method>
289+
<method name="start_research">
290+
<return type="void" />
291+
<param index="0" name="technology_id" type="String" />
292+
<description>
293+
</description>
294+
</method>
257295
<method name="toggle_paused">
258296
<return type="void" />
259297
<description>

extension/src/openvic-extension/singletons/GameSingleton.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "openvic-extension/singletons/MenuSingleton.hpp"
1313
#include "openvic-extension/utility/ClassBindings.hpp"
1414
#include "openvic-extension/utility/Utilities.hpp"
15+
#include "openvic-simulation/country/CountryInstance.hpp"
1516

1617
using namespace godot;
1718
using namespace OpenVic;
@@ -179,17 +180,6 @@ Error GameSingleton::setup_game(int32_t bookmark_index) {
179180
set_viewed_country(starting_country);
180181
ERR_FAIL_NULL_V(viewed_country, FAILED);
181182

182-
// TODO - remove this test starting research
183-
for (
184-
Technology const& technology :
185-
get_definition_manager().get_research_manager().get_technology_manager().get_technologies()
186-
) {
187-
if (starting_country->can_research_tech(technology, instance_manager->get_today())) {
188-
starting_country->start_research(technology, *instance_manager);
189-
break;
190-
}
191-
}
192-
193183
return ERR(ret);
194184
}
195185

@@ -425,7 +415,7 @@ void GameSingleton::unset_selected_province() {
425415
set_selected_province(ProvinceDefinition::NULL_INDEX);
426416
}
427417

428-
void GameSingleton::set_viewed_country(CountryInstance const* new_viewed_country) {
418+
void GameSingleton::set_viewed_country(CountryInstance* new_viewed_country) {
429419
if (viewed_country != new_viewed_country) {
430420
viewed_country = new_viewed_country;
431421

@@ -439,7 +429,7 @@ void GameSingleton::set_viewed_country_by_province_index(int32_t province_index)
439429
InstanceManager* instance_manager = get_instance_manager();
440430
ERR_FAIL_NULL(instance_manager);
441431

442-
ProvinceInstance const* province_instance =
432+
ProvinceInstance* province_instance =
443433
instance_manager->get_map_instance().get_province_instance_by_index(province_index);
444434
ERR_FAIL_NULL(province_instance);
445435

extension/src/openvic-extension/singletons/GameSingleton.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace OpenVic {
1515

1616
GameManager game_manager;
1717

18-
CountryInstance const* PROPERTY(viewed_country, nullptr);
18+
CountryInstance* PROPERTY_PTR(viewed_country, nullptr);
1919

2020
godot::Vector2i image_subdivisions;
2121
godot::Ref<godot::Texture2DArray> province_shape_texture;
@@ -133,7 +133,7 @@ namespace OpenVic {
133133
void set_selected_province(int32_t index);
134134
void unset_selected_province();
135135

136-
void set_viewed_country(CountryInstance const* new_viewed_country);
136+
void set_viewed_country(CountryInstance* new_viewed_country);
137137
void set_viewed_country_by_province_index(int32_t province_index);
138138
godot::Vector2 get_viewed_country_capital_position() const;
139139

extension/src/openvic-extension/singletons/MenuSingleton.cpp

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
#include "MenuSingleton.hpp"
22

3+
#include <algorithm>
4+
#include <cstddef>
5+
#include <cstdint>
6+
#include <string_view>
7+
38
#include <godot_cpp/variant/utility_functions.hpp>
9+
#include <godot_cpp/variant/dictionary.hpp>
10+
#include <godot_cpp/variant/packed_string_array.hpp>
411

5-
#include <openvic-simulation/economy/GoodDefinition.hpp>
612
#include <openvic-simulation/modifier/Modifier.hpp>
713
#include <openvic-simulation/types/fixed_point/FixedPoint.hpp>
14+
#include <openvic-simulation/economy/GoodDefinition.hpp>
15+
#include <openvic-simulation/research/Technology.hpp>
16+
#include <openvic-simulation/country/CountryInstance.hpp>
17+
#include <openvic-simulation/modifier/ModifierEffect.hpp>
818

19+
#include "openvic-extension/classes/GUILabel.hpp"
20+
#include "openvic-extension/utility/Utilities.hpp"
921
#include "openvic-extension/classes/GFXPieChartTexture.hpp"
1022
#include "openvic-extension/classes/GUINode.hpp"
1123
#include "openvic-extension/singletons/GameSingleton.hpp"
1224
#include "openvic-extension/utility/ClassBindings.hpp"
13-
#include "openvic-extension/utility/Utilities.hpp"
1425

1526
using namespace godot;
1627
using namespace OpenVic;
@@ -167,13 +178,17 @@ String MenuSingleton::_make_modifier_effect_value_coloured(
167178
return result;
168179
}
169180

170-
String MenuSingleton::_make_modifier_effects_tooltip(ModifierValue const& modifier) const {
181+
String MenuSingleton::_make_modifier_effect_tooltip(ModifierEffect const& effect, const fixed_point_t value) const {
182+
return tr(Utilities::std_to_godot_string(effect.get_localisation_key())) + ": " +
183+
_make_modifier_effect_value_coloured(effect, value, true);
184+
}
185+
186+
String MenuSingleton::_make_modifier_effects_tooltip(ModifierValue const& modifiers) const {
171187
String result;
172188

173-
for (auto const& [effect, value] : modifier.get_values()) {
189+
for (auto const& [effect, value] : modifiers.get_values()) {
174190
if (value != fixed_point_t::_0()) {
175-
result += "\n" + tr(Utilities::std_to_godot_string(effect->get_localisation_key())) + ": " +
176-
_make_modifier_effect_value_coloured(*effect, value, true);
191+
result += "\n" + _make_modifier_effect_tooltip(*effect, value);
177192
}
178193
}
179194

@@ -315,6 +330,9 @@ String MenuSingleton::_make_mobilisation_impact_tooltip() const {
315330

316331
void MenuSingleton::_bind_methods() {
317332
OV_BIND_SMETHOD(get_tooltip_separator);
333+
OV_BIND_SMETHOD(get_tooltip_condition_met);
334+
OV_BIND_SMETHOD(get_tooltip_condition_unmet);
335+
318336
OV_BIND_METHOD(MenuSingleton::get_country_name_from_identifier, { "country_identifier" });
319337
OV_BIND_METHOD(MenuSingleton::get_country_adjective_from_identifier, { "country_identifier" });
320338

@@ -431,6 +449,12 @@ void MenuSingleton::_bind_methods() {
431449
OV_BIND_METHOD(MenuSingleton::get_search_result_position, { "result_index" });
432450

433451
ADD_SIGNAL(MethodInfo(_signal_search_cache_changed()));
452+
453+
/* TECHNOLOGY MENU */
454+
OV_BIND_METHOD(MenuSingleton::get_technology_menu_defines);
455+
OV_BIND_METHOD(MenuSingleton::get_technology_menu_info);
456+
OV_BIND_METHOD(MenuSingleton::get_specific_technology_info, { "technology_id" });
457+
OV_BIND_METHOD(MenuSingleton::start_research, { "technology_id" });
434458
}
435459

436460
MenuSingleton* MenuSingleton::get_singleton() {
@@ -455,6 +479,16 @@ String MenuSingleton::get_tooltip_separator() {
455479
return tooltip_separator;
456480
}
457481

482+
String MenuSingleton::get_tooltip_condition_met() {
483+
static const String condition_met = String { "(" } + GUILabel::get_colour_marker() + String { "G*" } + GUILabel::get_colour_marker() + "W)";
484+
return condition_met;
485+
}
486+
487+
String MenuSingleton::get_tooltip_condition_unmet() {
488+
static const String condition_unmet = String { "(" } + GUILabel::get_colour_marker() + String { "RX" } + GUILabel::get_colour_marker() + "W)";
489+
return condition_unmet;
490+
}
491+
458492
String MenuSingleton::get_country_name_from_identifier(String const& country_identifier) const {
459493
if (country_identifier.is_empty()) {
460494
return {};

extension/src/openvic-extension/singletons/MenuSingleton.hpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#pragma once
22

3-
#include <variant>
4-
53
#include <godot_cpp/classes/control.hpp>
64
#include <godot_cpp/classes/image.hpp>
5+
#include <godot_cpp/variant/dictionary.hpp>
76

87
#include <openvic-simulation/military/UnitInstanceGroup.hpp>
98
#include <openvic-simulation/types/IndexedMap.hpp>
109
#include <openvic-simulation/types/PopSize.hpp>
1110
#include <openvic-simulation/types/OrderedContainers.hpp>
11+
#include <openvic-simulation/types/fixed_point/FixedPoint.hpp>
12+
#include <openvic-simulation/modifier/ModifierEffect.hpp>
13+
#include <openvic-simulation/pop/Pop.hpp>
1214

1315
namespace OpenVic {
1416
struct CountryInstance;
@@ -144,6 +146,7 @@ namespace OpenVic {
144146
ModifierEffect const& format_effect, fixed_point_t value, bool plus_for_non_negative
145147
);
146148

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

149152
template<typename T>
@@ -168,6 +171,9 @@ namespace OpenVic {
168171
~MenuSingleton();
169172

170173
static godot::String get_tooltip_separator();
174+
static godot::String get_tooltip_condition_met();
175+
static godot::String get_tooltip_condition_unmet();
176+
171177
godot::String get_country_name_from_identifier(godot::String const& country_identifier) const;
172178
godot::String get_country_adjective_from_identifier(godot::String const& country_identifier) const;
173179

@@ -233,6 +239,12 @@ namespace OpenVic {
233239
/* Array of GFXPieChartTexture::godot_pie_chart_data_t. */
234240
godot::TypedArray<godot::Array> get_population_menu_distribution_info() const;
235241

242+
/* TECHNOLOGY MENU */
243+
godot::Dictionary get_technology_menu_defines() const;
244+
godot::Dictionary get_technology_menu_info() const;
245+
godot::Dictionary get_specific_technology_info(godot::String technology_id) const;
246+
void start_research(godot::String technology_id); // TODO: move to PlayerSingleton
247+
236248
/* MILITARY MENU */
237249
godot::Dictionary make_leader_dict(LeaderBase const& leader);
238250
template<UnitType::branch_t Branch>

0 commit comments

Comments
 (0)