26 #include "eng3d/ui/ui.hpp"
27 #include "eng3d/ui/button.hpp"
28 #include "eng3d/ui/label.hpp"
29 #include "eng3d/ui/group.hpp"
30 #include "eng3d/ui/image.hpp"
31 #include "eng3d/ui/window.hpp"
32 #include "eng3d/camera.hpp"
47 :
UI::Window(-450, 0, 450, 128),
49 curr_selected_nation{ 0 }
54 this->curr_country_btn =
new UI::Button(0, 0, 250, 24,
this);
56 this->curr_country_btn->
set_tooltip(
translate(
"Select a country by clicking on the map or pressing the buttons below"));
59 this->gs.ui_ctx.clear();
60 if(!this->gs.singleplayer) {
61 if(this->gs.host_mode) {
62 this->gs.server = std::make_unique<Server>(gs, 1836);
63 this->gs.client = std::make_unique<Client>(gs,
"127.0.0.1", 1836);
64 this->gs.client->username =
"Host";
67 this->gs.in_game =
true;
68 this->gs.play_nation();
73 this->curr_country_flag_img =
new UI::Image(250, 0, 128, 72, gs.tex_man.get_white(),
this);
75 this->make_widget<UI::Image>(250, 0, this->curr_country_flag_img->width, this->curr_country_flag_img->height,
"gfx/drop_shadow.png");
78 auto& back_btn = this->make_widget<UI::Button>(0, 0, 128, 24);
79 back_btn.set_text(
"Back");
80 back_btn.below_of(*curr_country_btn);
86 auto& prev_country_btn = this->make_widget<UI::Image>(0, 0, 24, 24,
"gfx/arrow_left.png");
87 prev_country_btn.below_of(*curr_country_btn);
88 prev_country_btn.right_side_of(back_btn);
89 prev_country_btn.set_on_click([
this](
UI::Widget&) {
90 this->change_nation(this->curr_selected_nation - 1);
93 auto& next_country_ibtn = this->make_widget<UI::Image>(0, 0, 24, 24,
"gfx/arrow_right.png");
94 next_country_ibtn.below_of(*curr_country_btn);
95 next_country_ibtn.right_side_of(prev_country_btn);
96 next_country_ibtn.set_on_click([
this](
UI::Widget&) {
97 this->change_nation(this->curr_selected_nation + 1);
100 auto& random_country_ibtn = this->make_widget<UI::Image>(0, 0, 24, 24,
"gfx/noicon.png");
101 random_country_ibtn.set_tooltip(
translate(
"Select a random country"));
102 random_country_ibtn.below_of(*curr_country_btn);
103 random_country_ibtn.right_side_of(next_country_ibtn);
104 random_country_ibtn.set_on_click([
this](
UI::Widget&) {
105 this->change_nation(rand() % this->gs.world->nations.size());
108 const auto path = std::filesystem::current_path().string();
109 auto& savefiles_grp = this->make_widget<UI::Group>(0, 0, 128, gs.height);
110 savefiles_grp.below_of(random_country_ibtn);
112 savefiles_grp.is_scroll =
true;
113 for(
const auto& entry : std::filesystem::directory_iterator(path)) {
114 if(!entry.is_directory() && entry.path().extension() ==
".sc4") {
115 auto savefile_path = entry.path().lexically_relative(path).string();
116 auto& savefile_btn = savefiles_grp.make_widget<
UI::Button>(0, 0, 128, 24);
117 savefile_btn.
set_text(savefile_path);
118 savefile_btn.set_on_click([
this, &savefile_path](
UI::Widget&) {
126 void LobbySelectView::change_nation(
size_t id) {
128 if(gs.
world->nations.empty()) {
133 if(
id >= gs.
world->nations.size())
140 if(
id >= gs.
world->nations.size())
147 if(
id >= gs.
world->nations.size())
148 id = gs.
world->nations.size() - 1;
157 gs.
map->camera->set_pos(capital.box_area.right, capital.box_area.bottom);
std::unique_ptr< Map > map
std::shared_ptr< Eng3D::Texture > get_nation_flag(const Nation &nation)
LobbySelectView(GameState &gs)
size_t curr_selected_nation
bool exists() const
Whetever the nation exists at all - we cannot add nations in-game so we just check if the nation "exi...
void prompt(const std::string &title, const std::string &text)
Image widget, can display pictures or effects on the screen.
std::string translate(const std::string_view str)
void load(GameState &gs, const std::string &savefile_path)
const char * c_str() const