feat: Implement ProgressBar, show loading screen progress

This commit is contained in:
Vsevolod Kremianskii 2021-02-27 12:35:03 +07:00
parent 277c9719bb
commit 989d39c651
8 changed files with 144 additions and 4 deletions

View file

@ -345,6 +345,7 @@ set(GUI_HEADERS
src/gui/control/label.h src/gui/control/label.h
src/gui/control/listbox.h src/gui/control/listbox.h
src/gui/control/panel.h src/gui/control/panel.h
src/gui/control/progressbar.h
src/gui/control/scrollbar.h src/gui/control/scrollbar.h
src/gui/control/togglebutton.h src/gui/control/togglebutton.h
src/gui/gui.h src/gui/gui.h
@ -359,6 +360,7 @@ set(GUI_SOURCES
src/gui/control/label.cpp src/gui/control/label.cpp
src/gui/control/listbox.cpp src/gui/control/listbox.cpp
src/gui/control/panel.cpp src/gui/control/panel.cpp
src/gui/control/progressbar.cpp
src/gui/control/scrollbar.cpp src/gui/control/scrollbar.cpp
src/gui/control/togglebutton.cpp src/gui/control/togglebutton.cpp
src/gui/gui.cpp src/gui/gui.cpp

View file

@ -243,6 +243,9 @@ void Game::loadModule(const string &name, string entry) {
_module->area()->unloadParty(); _module->area()->unloadParty();
} }
_loadScreen->setProgress(50);
drawAll();
auto maybeModule = _loadedModules.find(name); auto maybeModule = _loadedModules.find(name);
if (maybeModule != _loadedModules.end()) { if (maybeModule != _loadedModules.end()) {
_module = maybeModule->second; _module = maybeModule->second;
@ -258,6 +261,9 @@ void Game::loadModule(const string &name, string entry) {
_module->loadParty(entry); _module->loadParty(entry);
_module->area()->fill(_sceneGraph); _module->area()->fill(_sceneGraph);
_loadScreen->setProgress(100);
drawAll();
string musicName(_module->area()->music()); string musicName(_module->area()->music());
playMusic(musicName); playMusic(musicName);
@ -272,6 +278,7 @@ void Game::withLoadingScreen(const string &imageResRef, const function<void()> &
loadLoadingScreen(); loadLoadingScreen();
} }
_loadScreen->setImage(imageResRef); _loadScreen->setImage(imageResRef);
_loadScreen->setProgress(0);
changeScreen(GameScreen::Loading); changeScreen(GameScreen::Loading);
drawAll(); drawAll();
block(); block();
@ -557,6 +564,8 @@ void Game::startCharacterGeneration() {
if (!_charGen) { if (!_charGen) {
loadCharacterGeneration(); loadCharacterGeneration();
} }
_loadScreen->setProgress(100);
drawAll();
playMusic(getCharacterGenerationMusic()); playMusic(getCharacterGenerationMusic());
changeScreen(GameScreen::CharacterGeneration); changeScreen(GameScreen::CharacterGeneration);
}); });

View file

@ -17,6 +17,7 @@
#include "loadscreen.h" #include "loadscreen.h"
#include "../../gui/control/progressbar.h"
#include "../../resource/resources.h" #include "../../resource/resources.h"
#include "../game.h" #include "../game.h"
@ -24,7 +25,6 @@
using namespace std; using namespace std;
using namespace reone::gui; using namespace reone::gui;
using namespace reone::render;
using namespace reone::resource; using namespace reone::resource;
namespace reone { namespace reone {
@ -54,6 +54,11 @@ void LoadingScreen::setImage(const string &resRef) {
configureRootContol([&resRef](Control &ctrl) { ctrl.setBorderFill(resRef); }); configureRootContol([&resRef](Control &ctrl) { ctrl.setBorderFill(resRef); });
} }
void LoadingScreen::setProgress(int progress) {
auto &progressBar = getControl<ProgressBar>("PB_PROGRESS");
progressBar.setValue(progress);
}
} // namespace game } // namespace game
} // namespace reone } // namespace reone

View file

@ -32,6 +32,7 @@ public:
void load() override; void load() override;
void setImage(const std::string &resRef); void setImage(const std::string &resRef);
void setProgress(int progress);
private: private:
Game *_game; Game *_game;

View file

@ -38,6 +38,7 @@
#include "label.h" #include "label.h"
#include "listbox.h" #include "listbox.h"
#include "panel.h" #include "panel.h"
#include "progressbar.h"
#include "scrollbar.h" #include "scrollbar.h"
#include "togglebutton.h" #include "togglebutton.h"
@ -81,12 +82,15 @@ unique_ptr<Control> Control::of(GUI *gui, ControlType type, const string &tag) {
case ControlType::ToggleButton: case ControlType::ToggleButton:
control = make_unique<ToggleButton>(gui); control = make_unique<ToggleButton>(gui);
break; break;
case ControlType::ListBox:
control = make_unique<ListBox>(gui);
break;
case ControlType::ScrollBar: case ControlType::ScrollBar:
control = make_unique<ScrollBar>(gui); control = make_unique<ScrollBar>(gui);
break; break;
case ControlType::ProgressBar:
control = make_unique<ProgressBar>(gui);
break;
case ControlType::ListBox:
control = make_unique<ListBox>(gui);
break;
default: default:
warn("GUI: unsupported control type: " + to_string(static_cast<int>(type))); warn("GUI: unsupported control type: " + to_string(static_cast<int>(type)));
return nullptr; return nullptr;

View file

@ -0,0 +1,72 @@
/*
* Copyright (c) 2020-2021 The reone project contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "progressbar.h"
#include "../../render/meshes.h"
#include "../../render/stateutil.h"
#include "../../render/textures.h"
#include "../../render/window.h"
using namespace std;
using namespace reone::render;
using namespace reone::resource;
namespace reone {
namespace gui {
ProgressBar::ProgressBar(GUI *gui) : Control(gui, ControlType::ScrollBar) {
}
void ProgressBar::load(const GffStruct &gffs) {
Control::load(gffs);
shared_ptr<GffStruct> dir(gffs.getStruct("PROGRESS"));
if (dir) {
string fill(dir->getString("FILL"));
_progress.fill = Textures::instance().get(fill, TextureUsage::GUI);
}
}
void ProgressBar::render(const glm::ivec2 &offset, const vector<string> &text) {
if (_value == 0 || !_progress.fill) return;
setActiveTextureUnit(TextureUnits::diffuse);
_progress.fill->bind();
float w = _extent.width * _value / 100.0f;
ShaderUniforms uniforms;
uniforms.general.projection = RenderWindow::instance().getOrthoProjection();
uniforms.general.model = glm::translate(glm::mat4(1.0f), glm::vec3(_extent.left + offset.x, _extent.top + offset.y, 0.0f));
uniforms.general.model = glm::scale(uniforms.general.model, glm::vec3(w, _extent.height, 1.0f));
Shaders::instance().activate(ShaderProgram::SimpleGUI, uniforms);
Meshes::instance().getQuad()->render();
}
void ProgressBar::setValue(int value) {
if (value < 0 || value > 100) {
throw out_of_range("value out of range: " + to_string(value));
}
_value = value;
}
} // namespace gui
} // namespace reone

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2020-2021 The reone project contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "control.h"
namespace reone {
namespace gui {
class ProgressBar : public Control {
public:
ProgressBar(GUI *gui);
void load(const resource::GffStruct &gffs) override;
void render(const glm::ivec2 &offset, const std::vector<std::string> &text) override;
void setValue(int value);
private:
struct Progress {
std::shared_ptr<render::Texture> fill;
};
Progress _progress;
int _value { 0 };
};
} // namespace gui
} // namespace reone

View file

@ -29,6 +29,7 @@ enum class ControlType {
Button = 6, Button = 6,
ToggleButton = 7, ToggleButton = 7,
ScrollBar = 9, ScrollBar = 9,
ProgressBar = 10,
ListBox = 11 ListBox = 11
}; };