diff options
| author | untodesu <kirill@untode.su> | 2025-12-11 15:14:26 +0500 |
|---|---|---|
| committer | untodesu <kirill@untode.su> | 2025-12-11 15:14:26 +0500 |
| commit | f40d09cb8f712e87691af4912f3630d92d692779 (patch) | |
| tree | 7ac3a4168ff722689372fd489c6f94d0a2546e8f /src/game/client/gui/message_box.cc | |
| parent | 8bcbd2729388edc63c82d77d314b583af1447c49 (diff) | |
| download | voxelius-f40d09cb8f712e87691af4912f3630d92d692779.tar.bz2 voxelius-f40d09cb8f712e87691af4912f3630d92d692779.zip | |
Shuffle stuff around
- Use the new and improved hierarchy I figured out when making Prospero chat
- Re-add NSIS scripts, again from Prospero
- Update most build and utility scripts with their most recent versions
Diffstat (limited to 'src/game/client/gui/message_box.cc')
| -rw-r--r-- | src/game/client/gui/message_box.cc | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/game/client/gui/message_box.cc b/src/game/client/gui/message_box.cc new file mode 100644 index 0000000..59e2d33 --- /dev/null +++ b/src/game/client/gui/message_box.cc @@ -0,0 +1,95 @@ +#include "client/pch.hh" + +#include "client/gui/message_box.hh" + +#include "client/gui/gui_screen.hh" +#include "client/gui/language.hh" + +#include "client/globals.hh" + +constexpr static ImGuiWindowFlags WINDOW_FLAGS = ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration; + +struct Button final { + gui::message_box_action action; + std::string str_title; +}; + +static std::string str_title; +static std::string str_subtitle; +static std::vector<Button> buttons; + +void gui::message_box::init(void) +{ + str_title = std::string(); + str_subtitle = std::string(); + buttons.clear(); +} + +void gui::message_box::layout(void) +{ + const auto viewport = ImGui::GetMainViewport(); + const auto window_start = ImVec2(0.0f, viewport->Size.y * 0.30f); + const auto window_size = ImVec2(viewport->Size.x, viewport->Size.y * 0.70f); + + ImGui::SetNextWindowPos(window_start); + ImGui::SetNextWindowSize(window_size); + + if(ImGui::Begin("###UIProgress", nullptr, WINDOW_FLAGS)) { + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.0f, 1.0f * globals::gui_scale)); + + const float title_width = ImGui::CalcTextSize(str_title.c_str()).x; + ImGui::SetCursorPosX(0.5f * (window_size.x - title_width)); + ImGui::TextUnformatted(str_title.c_str()); + + ImGui::Dummy(ImVec2(0.0f, 8.0f * globals::gui_scale)); + + if(!str_subtitle.empty()) { + const float subtitle_width = ImGui::CalcTextSize(str_subtitle.c_str()).x; + ImGui::SetCursorPosX(0.5f * (window_size.x - subtitle_width)); + ImGui::TextUnformatted(str_subtitle.c_str()); + } + + ImGui::Dummy(ImVec2(0.0f, 32.0f * globals::gui_scale)); + + for(const auto& button : buttons) { + const float button_width = 0.8f * ImGui::CalcItemWidth(); + ImGui::SetCursorPosX(0.5f * (window_size.x - button_width)); + + if(ImGui::Button(button.str_title.c_str(), ImVec2(button_width, 0.0f))) { + if(button.action) { + button.action(); + } + } + } + + ImGui::PopStyleVar(); + } + + ImGui::End(); +} + +void gui::message_box::reset(void) +{ + str_title.clear(); + str_subtitle.clear(); + buttons.clear(); +} + +void gui::message_box::set_title(std::string_view title) +{ + str_title = gui::language::resolve(title); +} + +void gui::message_box::set_subtitle(std::string_view subtitle) +{ + str_subtitle = gui::language::resolve(subtitle); +} + +void gui::message_box::add_button(std::string_view text, const message_box_action& action) +{ + Button button = {}; + button.str_title = std::format("{}###MessageBox_Button{}", gui::language::resolve(text), buttons.size()); + button.action = action; + + buttons.push_back(button); +} |
