Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
GUI_LoadingWindow.cpp
Go to the documentation of this file.
1/*
2 This source file is part of Rigs of Rods
3 Copyright 2005-2012 Pierre-Michel Ricordel
4 Copyright 2007-2012 Thomas Fischer
5
6 For more information, see http://www.rigsofrods.org/
7
8 Rigs of Rods is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 3, as
10 published by the Free Software Foundation.
11
12 Rigs of Rods is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#include "GUI_LoadingWindow.h"
22#include <fmt/format.h>
23
24#include "Actor.h"
25#include "GUIManager.h"
26#include "GUIUtils.h"
27#include "OgreImGui.h"
28#include "Language.h"
29
30using namespace RoR;
31using namespace GUI;
32
33void LoadingWindow::SetProgress(int percent, std::string const& text, bool render_frame/*=true*/)
34{
35 if (render_frame && m_timer.getMilliseconds() > 10)
36 {
37 App::GetGuiManager()->NewImGuiFrame(m_timer.getMilliseconds() * 0.001);
38 m_timer.reset();
39 }
40 else
41 {
42 render_frame = false;
43 }
44
45 this->SetVisible(true); // Traditional behavior
46 m_percent = percent;
47 m_text = text;
48
49 // Count lines
50 Ogre::StringUtil::trim(m_text); // Remove leading/trailing whitespace, incl. newlines
51 m_text_num_lines = 1; // First or single line
52 size_t pos = 0;
53 while ((pos = m_text.find("\n", pos+1)) != std::string::npos) // Count newlines
54 {
55 ++m_text_num_lines; // New line
56 }
57
58 if (render_frame)
59 {
60 this->Draw();
61 Ogre::Root::getSingleton().renderOneFrame();
62 }
63
64 // Echo status to log
65 Str<200> msg;
66 msg << "[RoR|PleaseWaitUI] ";
67 if (percent == PERC_SHOW_SPINNER) { msg << "<spinner>"; }
68 else if (percent != PERC_HIDE_PROGRESSBAR) { msg << "<" << percent << "%>"; }
69 msg << " " << text;
70 RoR::Log(msg);
71}
72
73void LoadingWindow::SetProgressNetConnect(const std::string& net_status)
74{
76 fmt::format( "{} [{}:{}]\n{}", _LC("LoadingWindow", "Joining"),
77 App::mp_server_host->getStr(), App::mp_server_port->getInt(), net_status));
78}
79
81{
83
84 // Height calc
85 float text_h = ImGui::CalcTextSize("A").y;
86 float statusbar_h = text_h + (ImGui::GetStyle().FramePadding.y * 2);
87 float titlebar_h = text_h + (ImGui::GetStyle().FramePadding.y * 2);
88
89 float height = titlebar_h +
90 ImGui::GetStyle().WindowPadding.y +
91 (text_h * (m_text_num_lines + 1)) + // + One blank line
92 (ImGui::GetStyle().ItemSpacing.y * 2) + // Blank line, statusbar
93 statusbar_h +
94 ImGui::GetStyle().WindowPadding.y;
95
96 ImGui::SetNextWindowSize(ImVec2(500.f, height));
97 ImGui::SetNextWindowPosCenter();
98 ImGuiWindowFlags flags = ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove;
99 ImGui::Begin(_LC("LoadingWindow", "Please wait"), nullptr, flags);
100 ImGui::Text("%s", m_text.c_str());
101
103 {
104 float spinner_size = 8.f;
105 LoadingIndicatorCircle("spinner", spinner_size, theme.value_blue_text_color, theme.value_blue_text_color, 10, 10);
106 }
108 {
109 ImGui::NewLine();
110 }
111 else
112 {
113 ImGui::NewLine();
114 ImGui::ProgressBar(static_cast<float>(m_percent)/100.f);
115 }
116 ImGui::End();
117}
#define _LC(ctx, str)
Definition Language.h:38
void SetProgress(int _percent, const std::string &_text="", bool render_frame=true)
void SetProgressNetConnect(const std::string &net_status)
void NewImGuiFrame(float dt)
GuiTheme & GetTheme()
Definition GUIManager.h:168
Wrapper for classic c-string (local buffer) Refresher: strlen() excludes '\0' terminator; strncat() A...
Definition Str.h:36
CVar * mp_server_port
GUIManager * GetGuiManager()
CVar * mp_server_host
void Log(const char *msg)
The ultimate, application-wide logging function. Adds a line (any length) in 'RoR....
void LoadingIndicatorCircle(const char *label, const float indicator_radius, const ImVec4 &main_color, const ImVec4 &backdrop_color, const int circle_count, const float speed)
Draws animated loading spinner.
Definition GUIUtils.cpp:158