Skip to content

Commit e927d76

Browse files
fix tooltips and a few other UI oversights
1 parent 19f19d6 commit e927d76

File tree

7 files changed

+195
-60
lines changed

7 files changed

+195
-60
lines changed

assets/alice.gui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5804,7 +5804,7 @@ guiTypes = {
58045804

58055805
guiButtonType = {
58065806
name = "factory_refit_button"
5807-
position = { x = 25 y = 15 }
5807+
position = { x = 60 y = 15 }
58085808
quadTextureSprite ="GFX_unit_upgrade_button"
58095809
extends="factory_info"
58105810
}

src/economy/construction.cpp

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,112 @@
11
#include "construction.hpp"
22
#include "economy_stats.hpp"
33
#include "province_templates.hpp"
4+
#include "text.hpp"
45

56
namespace economy {
67

8+
void build_land_unit_construction_tooltip(
9+
sys::state& state,
10+
text::columnar_layout& contents,
11+
const dcon::province_land_construction_id conid
12+
) {
13+
auto details = explain_land_unit_construction(state, conid);
14+
auto unit = state.world.province_land_construction_get_type(conid);
15+
auto& goods = state.military_definitions.unit_base_definitions[unit].build_cost;
16+
auto& cgoods = state.world.province_land_construction_get_purchased_goods(conid);
17+
18+
float total = 0.0f;
19+
float purchased = 0.0f;
20+
21+
{
22+
auto name = state.military_definitions.unit_base_definitions[unit].name;
23+
auto box = text::open_layout_box(contents, 0);
24+
text::add_to_layout_box(state, contents, box, name);
25+
text::close_layout_box(contents, box);
26+
}
27+
28+
for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
29+
if(goods.commodity_type[i]) {
30+
auto box = text::open_layout_box(contents, 0);
31+
32+
auto cid = goods.commodity_type[i];
33+
std::string padding = cid.index() < 10 ? "0" : "";
34+
std::string description = "@$" + padding + std::to_string(cid.index());
35+
text::add_unparsed_text_to_layout_box(state, contents, box, description);
36+
37+
text::add_to_layout_box(state, contents, box, state.world.commodity_get_name(goods.commodity_type[i]));
38+
text::add_to_layout_box(state, contents, box, std::string_view{ ": " });
39+
text::add_to_layout_box(state, contents, box, text::fp_one_place{ cgoods.commodity_amounts[i] });
40+
text::add_to_layout_box(state, contents, box, std::string_view{ " / " });
41+
text::add_to_layout_box(state, contents, box, text::fp_one_place{ goods.commodity_amounts[i] * details.cost_multiplier });
42+
text::close_layout_box(contents, box);
43+
}
44+
}
45+
}
46+
47+
void build_naval_unit_construction_tooltip(
48+
sys::state& state,
49+
text::columnar_layout& contents,
50+
const dcon::province_naval_construction_id conid
51+
) {
52+
auto details = explain_naval_unit_construction(state, conid);
53+
auto unit = state.world.province_naval_construction_get_type(conid);
54+
auto& goods = state.military_definitions.unit_base_definitions[unit].build_cost;
55+
auto& cgoods = state.world.province_naval_construction_get_purchased_goods(conid);
56+
57+
float total = 0.0f;
58+
float purchased = 0.0f;
59+
60+
{
61+
auto name = state.military_definitions.unit_base_definitions[unit].name;
62+
auto box = text::open_layout_box(contents, 0);
63+
text::add_to_layout_box(state, contents, box, name);
64+
text::close_layout_box(contents, box);
65+
}
66+
67+
for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
68+
if(goods.commodity_type[i]) {
69+
auto box = text::open_layout_box(contents, 0);
70+
71+
auto cid = goods.commodity_type[i];
72+
std::string padding = cid.index() < 10 ? "0" : "";
73+
std::string description = "@$" + padding + std::to_string(cid.index());
74+
text::add_unparsed_text_to_layout_box(state, contents, box, description);
75+
76+
text::add_to_layout_box(state, contents, box, state.world.commodity_get_name(goods.commodity_type[i]));
77+
text::add_to_layout_box(state, contents, box, std::string_view{ ": " });
78+
text::add_to_layout_box(state, contents, box, text::fp_one_place{ cgoods.commodity_amounts[i] });
79+
text::add_to_layout_box(state, contents, box, std::string_view{ " / " });
80+
text::add_to_layout_box(state, contents, box, text::fp_one_place{ goods.commodity_amounts[i] * details.cost_multiplier });
81+
text::close_layout_box(contents, box);
82+
}
83+
}
84+
}
85+
86+
economy::commodity_set calculate_factory_upgrade_goods_cost(
87+
sys::state& state,
88+
dcon::nation_id n,
89+
dcon::province_id pid,
90+
dcon::factory_type_id upgrade_target,
91+
bool is_pop_project
92+
) {
93+
economy::commodity_set res{};
94+
auto& base_cost = state.world.factory_type_get_construction_costs(upgrade_target);
95+
float factory_mod = factory_build_cost_multiplier(state, n, pid, is_pop_project);
96+
97+
98+
for(uint32_t j = 0; j < commodity_set::set_size; ++j) {
99+
if(base_cost.commodity_type[j]) {
100+
res.commodity_type[j] = base_cost.commodity_type[j];
101+
res.commodity_amounts[j] = base_cost.commodity_amounts[j] * factory_mod;
102+
} else {
103+
break;
104+
}
105+
}
106+
107+
return res;
108+
}
109+
7110
economy::commodity_set calculate_factory_refit_goods_cost(sys::state& state, dcon::nation_id n, dcon::province_id pid, dcon::factory_type_id from, dcon::factory_type_id to) {
8111
auto& from_cost = state.world.factory_type_get_construction_costs(from);
9112
auto& to_cost = state.world.factory_type_get_construction_costs(to);

src/economy/construction.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@ struct state;
77

88
namespace economy {
99

10+
void build_land_unit_construction_tooltip(
11+
sys::state& state,
12+
text::columnar_layout& contents,
13+
dcon::province_land_construction_id conid
14+
);
15+
16+
void build_naval_unit_construction_tooltip(
17+
sys::state& state,
18+
text::columnar_layout& contents,
19+
dcon::province_naval_construction_id conid
20+
);
21+
22+
economy::commodity_set calculate_factory_upgrade_goods_cost(
23+
sys::state& state,
24+
dcon::nation_id n,
25+
dcon::province_id pid,
26+
dcon::factory_type_id upgrade_target,
27+
bool is_pop_project
28+
);
29+
1030
void populate_construction_consumption(sys::state& state);
1131

1232
struct unit_construction_data {
@@ -18,6 +38,14 @@ struct unit_construction_data {
1838
dcon::province_id province;
1939
dcon::unit_type_id unit_type;
2040
};
41+
unit_construction_data explain_land_unit_construction(
42+
sys::state& state,
43+
dcon::province_land_construction_id construction
44+
);
45+
unit_construction_data explain_naval_unit_construction(
46+
sys::state& state,
47+
dcon::province_naval_construction_id construction
48+
);
2149
struct province_construction_spending_entry {
2250
dcon::province_building_construction_id construction;
2351
float spending;

src/gui/gui_outliner_window.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ class outliner_element_button : public button_element_base {
7979
auto nationname = text::produce_simple_string(state, text::get_name(state, n));
8080
text::add_line(state, contents, nationname + " (" + text::get_influence_level_name(state, status) + ", " + text::format_float(influence, 0) + ")", 0);
8181
}
82+
} else if(std::holds_alternative<dcon::province_land_construction_id>(content)) {
83+
auto plcid = std::get<dcon::province_land_construction_id>(content);
84+
economy::build_land_unit_construction_tooltip(
85+
state,
86+
contents,
87+
plcid
88+
);
89+
} else if(std::holds_alternative<dcon::province_naval_construction_id>(content)) {
90+
auto pncid = std::get<dcon::province_naval_construction_id>(content);
91+
economy::build_naval_unit_construction_tooltip(
92+
state,
93+
contents,
94+
pncid
95+
);
8296
}
8397
}
8498
void on_update(sys::state& state) noexcept override {

src/gui/gui_province_window.hpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "province_templates.hpp"
1616
#include "nations_templates.hpp"
1717
#include "gui_province_tiles_window.hpp"
18+
#include "construction.hpp"
1819

1920
namespace ui {
2021

@@ -1692,6 +1693,10 @@ class province_view_statistics : public window_element_base {
16921693

16931694
class province_army_progress : public progress_bar {
16941695
public:
1696+
tooltip_behavior has_tooltip(sys::state& state) noexcept override {
1697+
return tooltip_behavior::variable_tooltip;
1698+
}
1699+
16951700
void on_update(sys::state& state) noexcept override {
16961701
progress = 0.f;
16971702
float amount = 0.f;
@@ -1701,12 +1706,13 @@ class province_army_progress : public progress_bar {
17011706
if(pop.get_pop().get_poptype() == state.culture_definitions.soldiers) {
17021707
auto lcs = pop.get_pop().get_province_land_construction();
17031708
for(const auto lc : lcs) {
1709+
auto details = economy::explain_land_unit_construction(state, lc);
17041710
auto& base_cost = state.military_definitions.unit_base_definitions[lc.get_type()].build_cost;
17051711
auto& current_purchased = lc.get_purchased_goods();
17061712
for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
17071713
if(base_cost.commodity_type[i]) {
17081714
amount += current_purchased.commodity_amounts[i];
1709-
total += base_cost.commodity_amounts[i];
1715+
total += base_cost.commodity_amounts[i] * details.cost_multiplier;
17101716
} else {
17111717
break;
17121718
}
@@ -1718,9 +1724,25 @@ class province_army_progress : public progress_bar {
17181724
progress = amount / total;
17191725
}
17201726
}
1727+
1728+
void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
1729+
auto p = retrieve<dcon::province_id>(state, parent);
1730+
for(auto pop : dcon::fatten(state.world, p).get_pop_location()) {
1731+
if(pop.get_pop().get_poptype() == state.culture_definitions.soldiers) {
1732+
auto lcs = pop.get_pop().get_province_land_construction();
1733+
for(const auto lc : lcs) {
1734+
economy::build_land_unit_construction_tooltip(state, contents, lc.id);
1735+
}
1736+
}
1737+
}
1738+
}
17211739
};
17221740
class province_navy_progress : public progress_bar {
17231741
public:
1742+
tooltip_behavior has_tooltip(sys::state& state) noexcept override {
1743+
return tooltip_behavior::variable_tooltip;
1744+
}
1745+
17241746
void on_update(sys::state& state) noexcept override {
17251747
progress = 0.f;
17261748
float amount = 0.f;
@@ -1731,9 +1753,10 @@ class province_navy_progress : public progress_bar {
17311753
auto& base_cost = state.military_definitions.unit_base_definitions[nc.get_type()].build_cost;
17321754
auto& current_purchased = nc.get_purchased_goods();
17331755
for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
1756+
auto details = economy::explain_naval_unit_construction(state, nc);
17341757
if(base_cost.commodity_type[i]) {
17351758
amount += current_purchased.commodity_amounts[i];
1736-
total += base_cost.commodity_amounts[i];
1759+
total += base_cost.commodity_amounts[i] * details.cost_multiplier;
17371760
} else {
17381761
break;
17391762
}
@@ -1743,6 +1766,14 @@ class province_navy_progress : public progress_bar {
17431766
progress = amount / total;
17441767
}
17451768
}
1769+
1770+
void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
1771+
auto p = retrieve<dcon::province_id>(state, parent);
1772+
auto ncs = state.world.province_get_province_naval_construction(p);
1773+
for(auto nc : ncs) {
1774+
economy::build_naval_unit_construction_tooltip(state, contents, nc.id);
1775+
}
1776+
}
17461777
};
17471778

17481779
class province_army_progress_text : public simple_text_element_base {

src/gui/topbar_subwindows/gui_production_window.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,11 @@ class factory_upgrade_progress_bar : public progress_bar {
624624
float factory_mod = economy::factory_build_cost_multiplier(state, p.get_nation(), pid, p.get_is_pop_project());
625625
auto owner = state.world.province_get_nation_from_province_ownership(pid);
626626

627-
auto goods = economy::calculate_factory_refit_goods_cost(state, owner, pid, nf.type, nf.target_type);
627+
auto goods = economy::calculate_factory_upgrade_goods_cost(state, owner, pid, nf.type, p.get_is_pop_project());
628+
if(nf.target_type) {
629+
goods = economy::calculate_factory_refit_goods_cost(state, owner, pid, nf.type, nf.target_type);
630+
}
631+
628632
auto& cgoods = p.get_purchased_goods();
629633

630634
for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
@@ -1291,9 +1295,6 @@ class production_factory_info : public window_element_base {
12911295
} else if(payload.holds_type<dcon::commodity_id>()) {
12921296
payload.emplace<dcon::commodity_id>(output_commodity);
12931297
return message_result::consumed;
1294-
} else if(payload.holds_type<dcon::province_id>()) {
1295-
payload.emplace<dcon::province_id>(state.world.factory_get_province_from_factory_location(content.id));
1296-
return message_result::consumed;
12971298
}
12981299
}
12991300
return message_result::unseen;

src/gui/topbar_subwindows/military_subwindows/gui_units_window.hpp

Lines changed: 11 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "gui_element_types.hpp"
4+
#include "construction.hpp"
45

56
namespace ui {
67

@@ -48,63 +49,20 @@ class military_unit_building_progress_bar : public progress_bar {
4849
auto container = retrieve<military_unit_info<T>>(state, parent);
4950
if(std::holds_alternative<dcon::province_land_construction_id>(container)) {
5051
auto c = std::get<dcon::province_land_construction_id>(container);
51-
52-
auto pop = state.world.province_land_construction_get_pop(c);
53-
auto pid = state.world.pop_get_province_from_pop_location(pop);
54-
float factor = economy::build_cost_multiplier(state, pid, false);
55-
56-
auto& goods = state.military_definitions.unit_base_definitions[state.world.province_land_construction_get_type(c)].build_cost;
57-
auto& cgoods = state.world.province_land_construction_get_purchased_goods(c);
58-
59-
float total = 0.0f;
60-
float purchased = 0.0f;
61-
62-
for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
63-
if(goods.commodity_type[i]) {
64-
auto box = text::open_layout_box(contents, 0);
65-
66-
auto cid = goods.commodity_type[i];
67-
std::string padding = cid.index() < 10 ? "0" : "";
68-
std::string description = "@$" + padding + std::to_string(cid.index());
69-
text::add_unparsed_text_to_layout_box(state, contents, box, description);
70-
71-
text::add_to_layout_box(state, contents, box, state.world.commodity_get_name(goods.commodity_type[i]));
72-
text::add_to_layout_box(state, contents, box, std::string_view{ ": " });
73-
text::add_to_layout_box(state, contents, box, text::fp_one_place{ cgoods.commodity_amounts[i] });
74-
text::add_to_layout_box(state, contents, box, std::string_view{ " / " });
75-
text::add_to_layout_box(state, contents, box, text::fp_one_place{ goods.commodity_amounts[i] * factor });
76-
text::close_layout_box(contents, box);
77-
}
78-
}
52+
economy::build_land_unit_construction_tooltip(
53+
state,
54+
contents,
55+
c
56+
);
7957
} else if(std::holds_alternative<dcon::province_naval_construction_id>(container)) {
8058
auto c = std::get<dcon::province_naval_construction_id>(container);
8159

8260
auto pid = state.world.province_naval_construction_get_province(c);
83-
float factor = economy::build_cost_multiplier(state, pid, false);
84-
85-
auto& goods = state.military_definitions.unit_base_definitions[state.world.province_naval_construction_get_type(c)].build_cost;
86-
auto& cgoods = state.world.province_naval_construction_get_purchased_goods(c);
87-
88-
float total = 0.0f;
89-
float purchased = 0.0f;
90-
91-
for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
92-
if(goods.commodity_type[i]) {
93-
auto box = text::open_layout_box(contents, 0);
94-
95-
auto cid = goods.commodity_type[i];
96-
std::string padding = cid.index() < 10 ? "0" : "";
97-
std::string description = "@$" + padding + std::to_string(cid.index());
98-
text::add_unparsed_text_to_layout_box(state, contents, box, description);
99-
100-
text::add_to_layout_box(state, contents, box, state.world.commodity_get_name(goods.commodity_type[i]));
101-
text::add_to_layout_box(state, contents, box, std::string_view{ ": " });
102-
text::add_to_layout_box(state, contents, box, text::fp_one_place{ cgoods.commodity_amounts[i] });
103-
text::add_to_layout_box(state, contents, box, std::string_view{ " / " });
104-
text::add_to_layout_box(state, contents, box, text::fp_one_place{ goods.commodity_amounts[i] * factor });
105-
text::close_layout_box(contents, box);
106-
}
107-
}
61+
economy::build_naval_unit_construction_tooltip(
62+
state,
63+
contents,
64+
c
65+
);
10866
}
10967

11068
}

0 commit comments

Comments
 (0)