Skip to content

Commit 2e3d389

Browse files
BrickPiHop311
authored andcommitted
Implement the Technology Menu
1 parent fdeb0f5 commit 2e3d389

File tree

10 files changed

+564
-19
lines changed

10 files changed

+564
-19
lines changed

extension/doc_classes/MenuSingleton.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,46 @@
150150
<description>
151151
</description>
152152
</method>
153+
<method name="get_specific_technology_info" qualifiers="const">
154+
<return type="Dictionary" />
155+
<param index="0" name="technology_identifier" type="String" />
156+
<description>
157+
Returns the effects, point cost, unlock year, and prerequisite tech of the given technology, in a [Dictionary].
158+
</description>
159+
</method>
153160
<method name="get_speed" qualifiers="const">
154161
<return type="int" />
155162
<description>
156163
</description>
157164
</method>
165+
<method name="get_technology_menu_defines" qualifiers="const">
166+
<return type="Dictionary" />
167+
<description>
168+
Returns a [Dictionary] with static defines for the technology menu.
169+
</description>
170+
</method>
171+
<method name="get_technology_menu_info" qualifiers="const">
172+
<return type="Dictionary" />
173+
<description>
174+
Returns a [Dictionary] with the dynamic state of the technology menu.
175+
</description>
176+
</method>
177+
<method name="get_tooltip_condition_met" qualifiers="static">
178+
<return type="String" />
179+
<description>
180+
Returns the colored symbol used by met tooltip conditions "(*)"
181+
</description>
182+
</method>
183+
<method name="get_tooltip_condition_unmet" qualifiers="static">
184+
<return type="String" />
185+
<description>
186+
Returns the colored symbol used by unmet tooltip conditions "(X)"
187+
</description>
188+
</method>
158189
<method name="get_tooltip_separator" qualifiers="static">
159190
<return type="String" />
160191
<description>
192+
Returns the symbol used to separate normal and extended tooltips.
161193
</description>
162194
</method>
163195
<method name="get_topbar_info" qualifiers="const">

extension/doc_classes/PlayerSingleton.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@
9191
<description>
9292
</description>
9393
</method>
94+
<method name="start_research" qualifiers="const">
95+
<return type="void" />
96+
<param index="0" name="technology_identifier" type="String" />
97+
<description>
98+
</description>
99+
</method>
94100
<method name="toggle_paused" qualifiers="const">
95101
<return type="void" />
96102
<description>

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "openvic-extension/singletons/PlayerSingleton.hpp"
1414
#include "openvic-extension/utility/ClassBindings.hpp"
1515
#include "openvic-extension/utility/Utilities.hpp"
16+
#include "openvic-simulation/country/CountryInstance.hpp"
1617

1718
using namespace godot;
1819
using namespace OpenVic;
@@ -159,17 +160,6 @@ Error GameSingleton::setup_game(int32_t bookmark_index) {
159160
player_singleton.set_player_country(starting_country);
160161
ERR_FAIL_NULL_V(player_singleton.get_player_country(), FAILED);
161162

162-
// TODO - remove this test starting research
163-
for (
164-
Technology const& technology :
165-
get_definition_manager().get_research_manager().get_technology_manager().get_technologies()
166-
) {
167-
if (starting_country->can_research_tech(technology, instance_manager->get_today())) {
168-
starting_country->start_research(technology, *instance_manager);
169-
break;
170-
}
171-
}
172-
173163
return ERR(ret);
174164
}
175165

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

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
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/singletons/PlayerSingleton.hpp"
1325
#include "openvic-extension/utility/ClassBindings.hpp"
14-
#include "openvic-extension/utility/Utilities.hpp"
1526

1627
using namespace godot;
1728
using namespace OpenVic;
@@ -168,13 +179,17 @@ String MenuSingleton::_make_modifier_effect_value_coloured(
168179
return result;
169180
}
170181

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

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

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

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

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

438456
ADD_SIGNAL(MethodInfo(_signal_search_cache_changed()));
457+
458+
/* TECHNOLOGY MENU */
459+
OV_BIND_METHOD(MenuSingleton::get_technology_menu_defines);
460+
OV_BIND_METHOD(MenuSingleton::get_technology_menu_info);
461+
OV_BIND_METHOD(MenuSingleton::get_specific_technology_info, { "technology_identifier" });
439462
}
440463

441464
MenuSingleton* MenuSingleton::get_singleton() {
@@ -460,6 +483,16 @@ String MenuSingleton::get_tooltip_separator() {
460483
return tooltip_separator;
461484
}
462485

486+
String MenuSingleton::get_tooltip_condition_met() {
487+
static const String condition_met = String { "(" } + GUILabel::get_colour_marker() + String { "G*" } + GUILabel::get_colour_marker() + "W)";
488+
return condition_met;
489+
}
490+
491+
String MenuSingleton::get_tooltip_condition_unmet() {
492+
static const String condition_unmet = String { "(" } + GUILabel::get_colour_marker() + String { "RX" } + GUILabel::get_colour_marker() + "W)";
493+
return condition_unmet;
494+
}
495+
463496
String MenuSingleton::get_country_name_from_identifier(String const& country_identifier) const {
464497
if (country_identifier.is_empty()) {
465498
return {};

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

Lines changed: 13 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;
@@ -149,6 +151,7 @@ namespace OpenVic {
149151
ModifierEffect const& format_effect, fixed_point_t value, bool plus_for_non_negative
150152
);
151153

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

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

175178
static godot::String get_tooltip_separator();
179+
static godot::String get_tooltip_condition_met();
180+
static godot::String get_tooltip_condition_unmet();
181+
176182
godot::String get_country_name_from_identifier(godot::String const& country_identifier) const;
177183
godot::String get_country_adjective_from_identifier(godot::String const& country_identifier) const;
178184

@@ -233,6 +239,11 @@ 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_identifier) const;
246+
236247
/* TRADE MENU */
237248
godot::Dictionary get_trade_menu_good_categories_info() const;
238249
godot::Dictionary get_trade_menu_trade_details_info(

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "openvic-extension/singletons/GameSingleton.hpp"
88
#include "openvic-extension/singletons/MenuSingleton.hpp"
99
#include "openvic-extension/utility/ClassBindings.hpp"
10+
#include "openvic-extension/utility/Utilities.hpp"
1011

1112
using namespace OpenVic;
1213
using namespace godot;
@@ -39,6 +40,7 @@ void PlayerSingleton::_bind_methods() {
3940
// Budget
4041

4142
// Technology
43+
OV_BIND_METHOD(PlayerSingleton::start_research, { "technology_identifier" });
4244

4345
// Politics
4446

@@ -213,6 +215,25 @@ void PlayerSingleton::expand_selected_province_building(int32_t building_index)
213215
// Budget
214216

215217
// Technology
218+
void PlayerSingleton::start_research(String const& technology_identifier) const {
219+
ERR_FAIL_NULL(player_country);
220+
221+
GameSingleton& game_singleton = *GameSingleton::get_singleton();
222+
223+
Technology const* technology =
224+
game_singleton.get_definition_manager().get_research_manager().get_technology_manager().get_technology_by_identifier(
225+
Utilities::godot_to_std_string(technology_identifier)
226+
);
227+
ERR_FAIL_NULL(technology);
228+
229+
InstanceManager* instance_manager = game_singleton.get_instance_manager();
230+
ERR_FAIL_NULL(instance_manager);
231+
232+
instance_manager->queue_game_action(
233+
game_action_type_t::GAME_ACTION_START_RESEARCH,
234+
std::pair<uint64_t, uint64_t> { player_country->get_index(), technology->get_index() }
235+
);
236+
}
216237

217238
// Politics
218239

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ namespace OpenVic {
5050
// Budget
5151

5252
// Technology
53+
void start_research(godot::String const& technology_identifier) const;
5354

5455
// Politics
5556

0 commit comments

Comments
 (0)