25 #include "eng3d/string.hpp"
26 #include "eng3d/texture.hpp"
27 #include "eng3d/ui/button.hpp"
28 #include "eng3d/ui/chart.hpp"
29 #include "eng3d/ui/image.hpp"
30 #include "eng3d/ui/label.hpp"
31 #include "eng3d/ui/progress_bar.hpp"
32 #include "eng3d/ui/tooltip.hpp"
33 #include "eng3d/ui/close_button.hpp"
34 #include "eng3d/ui/div.hpp"
45 :
UI::Group(_x, _y, _parent->width - _x, _parent->height - _y, _parent),
48 auto& flex_column = this->make_widget<UI::Div>(0, 0, this->
width, this->
height);
51 if(!filter || !filter(unit))
return;
54 const auto& current_unit = this->gs.world->unit_manager.units[unit_id];
55 const auto& current_type = this->gs.world->unit_types[current_unit.type_id];
56 w.set_text(string_format(
"%zu %s", current_unit.size, current_type.name.c_str()));
58 btn.on_each_tick(btn);
63 :
UI::Group(_x, _y, _parent->width - _x, _parent->height, _parent),
68 auto& flex_column = this->make_widget<UI::Div>(0, 0, this->
width, this->
height);
70 for(
const auto& unit_type : gs.
world->unit_types) {
71 auto& unit_type_grp = flex_column.make_widget<
UI::Div>(0, 0, flex_column.width, 24);
74 unit_type_grp.set_on_click([
this, unit_type_id = unit_type.get_id()](
UI::Widget&) {
78 auto& icon_img = unit_type_grp.make_widget<
UI::Image>(0, 0, 24, 24, unit_type.get_icon_path());
85 auto& reqmat_chart = flex_column.make_widget<
UI::Chart>(0, 0, this->
width, 128);
86 reqmat_chart.
set_text(
"Material demand");
87 reqmat_chart.set_on_each_tick([
this](
UI::Widget& w) {
91 const auto& province = gs.
world->provinces[province_id];
92 for(
const auto& building : province.get_buildings()) {
93 for(
const auto& [_, amount] : building.req_goods_for_unit)
95 for(
const auto& [_, amount] : building.req_goods)
103 for(
const auto& building_type : gs.
world->building_types)
104 if(building_type.can_build_land_units())
109 :
UI::Group(_x, _y, _parent->width - _x, 48, _parent),
111 province_id{ _province_id },
114 const auto& province = gs.
world->provinces[province_id];
115 const auto& building = province.get_buildings()[idx];
120 auto& unit_icon = this->make_widget<UI::Image>(0, 0, 24, 24);
123 auto& province_lab = this->make_widget<UI::Label>(0, 0,
"?");
124 province_lab.set_on_each_tick([
this](
UI::Widget& w) {
125 const auto& current_province = gs.
world->provinces[province_id];
128 province_lab.on_each_tick(province_lab);
130 auto& name_lab = this->make_widget<UI::Label>(0, 0,
"?");
131 name_lab.set_on_each_tick([
this](
UI::Widget& w) {
132 const auto& current_province = gs.
world->provinces[province_id];
133 auto& current_building = current_province.get_buildings()[this->idx];
134 w.
set_text(this->gs.
world->unit_types[current_building.working_unit_type_id].name);
136 name_lab.on_each_tick(name_lab);
138 auto& progress_pgbar = this->make_widget<UI::ProgressBar>(0, 0, 128, 24, 0.f, 1.f);
139 progress_pgbar.set_on_each_tick([
this](
UI::Widget& _w) {
141 const auto& c_province = gs.
world->provinces[province_id];
142 const auto& c_building = c_province.get_buildings()[this->idx];
143 if(c_building.is_working_on_unit())
return;
144 auto full = 0.f, needed = 0.f;
146 for(
size_t i = 0; i < c_building.req_goods_for_unit.size(); i++) {
147 auto need_req = c_building.req_goods_for_unit[i];
148 auto full_req = this->gs.
world->unit_types[c_building.working_unit_type_id].req_goods[i];
149 full += full_req.second;
150 needed += need_req.second;
151 text +=
translate_format(
"Requires %.2f of %s (has %.2f)", need_req.second, this->gs.world->commodities[need_req.first].name.c_str(), full_req.second);
153 w.set_value(full / glm::max(needed, 0.01f));
156 progress_pgbar.on_each_tick(progress_pgbar);
160 :
UI::Window(-400, 0, 400, _gs.height),
181 this->
units_tab = &this->make_widget<ArmyUnitsTab>(gs, 0, 32, [
this](
Unit& unit) {
182 auto& current_type = this->gs.
world->unit_types[unit.
type_id];
183 return unit.
owner_id == *this->gs.
curr_nation && current_type.is_ground && !current_type.is_naval;
187 army_ibtn.set_tooltip(
translate(
"Land army"));
190 airforce_ibtn.right_side_of(army_ibtn);
191 airforce_ibtn.set_on_click([
this](
UI::Widget&) {
194 this->
units_tab = &this->make_widget<ArmyUnitsTab>(gs, 0, 32, [
this](
Unit& unit) {
195 auto& current_type = this->gs.
world->unit_types[unit.
type_id];
196 return unit.
owner_id == *this->gs.
curr_nation && !current_type.is_ground && !current_type.is_naval;
200 airforce_ibtn.set_tooltip(
translate(
"Airforce"));
203 navy_ibtn.right_side_of(airforce_ibtn);
207 this->
units_tab = &this->make_widget<ArmyUnitsTab>(gs, 0, 32, [
this](
Unit& unit) {
208 auto& current_type = this->gs.
world->unit_types[unit.
type_id];
209 return unit.
owner_id == *this->gs.
curr_nation && !current_type.is_ground && current_type.is_naval;
213 navy_ibtn.set_tooltip(
translate(
"Navy"));
218 production_ibtn.right_side_of(navy_ibtn);
219 production_ibtn.set_on_click([
this](
UI::Widget&) {
223 production_ibtn.set_tooltip(
translate(
"Military production"));
225 army_ibtn.on_click(army_ibtn);
std::shared_ptr< Eng3D::IO::Asset::Base > get_unique(const Eng3D::IO::Path &path)
Obtaining an unique asset means the "first-found" policy applies.
Eng3D::TextureManager tex_man
Eng3D::IO::PackageManager package_man
std::shared_ptr< Eng3D::Texture > load(const std::string &path, TextureOptions options=default_options)
Finds a texture in the list of a texture manager if the texture is already in the list we load the sa...
UI::Widget * right_side_panel
std::vector< UnitTypeId > production_queue
ArmyProductionTab(GameState &gs, int x, int y, UI::Widget *parent)
ArmyProductionUnitInfo(GameState &_gs, int x, int y, ProvinceId _province_id, size_t _idx, UI::Widget *parent)
ArmyUnitsTab(GameState &gs, int x, int y, std::function< bool(Unit &unit)> filter, UI::Widget *parent)
ArmyProductionTab * production_tab
std::vector< ProvinceId > owned_provinces
Image widget, can display pictures or effects on the screen.
void set_close_btn_function(std::function< void(Widget &)> on_click)
Roughly a batallion, consisting of approximately 500 soldiers each.
Eng3D::Freelist< Unit > units
std::string translate(const std::string_view str)
std::string translate_format(const std::string_view format, Args &&... args)
String formatter, with translation.
void for_each(const F &lambda) const
constexpr Id get_id() const
A basic widget without any presets.