feat: Implement ProgressBar, show loading screen progress
This commit is contained in:
parent
277c9719bb
commit
989d39c651
8 changed files with 144 additions and 4 deletions
|
@ -345,6 +345,7 @@ set(GUI_HEADERS
|
|||
src/gui/control/label.h
|
||||
src/gui/control/listbox.h
|
||||
src/gui/control/panel.h
|
||||
src/gui/control/progressbar.h
|
||||
src/gui/control/scrollbar.h
|
||||
src/gui/control/togglebutton.h
|
||||
src/gui/gui.h
|
||||
|
@ -359,6 +360,7 @@ set(GUI_SOURCES
|
|||
src/gui/control/label.cpp
|
||||
src/gui/control/listbox.cpp
|
||||
src/gui/control/panel.cpp
|
||||
src/gui/control/progressbar.cpp
|
||||
src/gui/control/scrollbar.cpp
|
||||
src/gui/control/togglebutton.cpp
|
||||
src/gui/gui.cpp
|
||||
|
|
|
@ -243,6 +243,9 @@ void Game::loadModule(const string &name, string entry) {
|
|||
_module->area()->unloadParty();
|
||||
}
|
||||
|
||||
_loadScreen->setProgress(50);
|
||||
drawAll();
|
||||
|
||||
auto maybeModule = _loadedModules.find(name);
|
||||
if (maybeModule != _loadedModules.end()) {
|
||||
_module = maybeModule->second;
|
||||
|
@ -258,6 +261,9 @@ void Game::loadModule(const string &name, string entry) {
|
|||
_module->loadParty(entry);
|
||||
_module->area()->fill(_sceneGraph);
|
||||
|
||||
_loadScreen->setProgress(100);
|
||||
drawAll();
|
||||
|
||||
string musicName(_module->area()->music());
|
||||
playMusic(musicName);
|
||||
|
||||
|
@ -272,6 +278,7 @@ void Game::withLoadingScreen(const string &imageResRef, const function<void()> &
|
|||
loadLoadingScreen();
|
||||
}
|
||||
_loadScreen->setImage(imageResRef);
|
||||
_loadScreen->setProgress(0);
|
||||
changeScreen(GameScreen::Loading);
|
||||
drawAll();
|
||||
block();
|
||||
|
@ -557,6 +564,8 @@ void Game::startCharacterGeneration() {
|
|||
if (!_charGen) {
|
||||
loadCharacterGeneration();
|
||||
}
|
||||
_loadScreen->setProgress(100);
|
||||
drawAll();
|
||||
playMusic(getCharacterGenerationMusic());
|
||||
changeScreen(GameScreen::CharacterGeneration);
|
||||
});
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include "loadscreen.h"
|
||||
|
||||
#include "../../gui/control/progressbar.h"
|
||||
#include "../../resource/resources.h"
|
||||
|
||||
#include "../game.h"
|
||||
|
@ -24,7 +25,6 @@
|
|||
using namespace std;
|
||||
|
||||
using namespace reone::gui;
|
||||
using namespace reone::render;
|
||||
using namespace reone::resource;
|
||||
|
||||
namespace reone {
|
||||
|
@ -54,6 +54,11 @@ void LoadingScreen::setImage(const string &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 reone
|
||||
|
|
|
@ -32,6 +32,7 @@ public:
|
|||
void load() override;
|
||||
|
||||
void setImage(const std::string &resRef);
|
||||
void setProgress(int progress);
|
||||
|
||||
private:
|
||||
Game *_game;
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "label.h"
|
||||
#include "listbox.h"
|
||||
#include "panel.h"
|
||||
#include "progressbar.h"
|
||||
#include "scrollbar.h"
|
||||
#include "togglebutton.h"
|
||||
|
||||
|
@ -81,12 +82,15 @@ unique_ptr<Control> Control::of(GUI *gui, ControlType type, const string &tag) {
|
|||
case ControlType::ToggleButton:
|
||||
control = make_unique<ToggleButton>(gui);
|
||||
break;
|
||||
case ControlType::ListBox:
|
||||
control = make_unique<ListBox>(gui);
|
||||
break;
|
||||
case ControlType::ScrollBar:
|
||||
control = make_unique<ScrollBar>(gui);
|
||||
break;
|
||||
case ControlType::ProgressBar:
|
||||
control = make_unique<ProgressBar>(gui);
|
||||
break;
|
||||
case ControlType::ListBox:
|
||||
control = make_unique<ListBox>(gui);
|
||||
break;
|
||||
default:
|
||||
warn("GUI: unsupported control type: " + to_string(static_cast<int>(type)));
|
||||
return nullptr;
|
||||
|
|
72
src/gui/control/progressbar.cpp
Normal file
72
src/gui/control/progressbar.cpp
Normal 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
|
46
src/gui/control/progressbar.h
Normal file
46
src/gui/control/progressbar.h
Normal 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
|
|
@ -29,6 +29,7 @@ enum class ControlType {
|
|||
Button = 6,
|
||||
ToggleButton = 7,
|
||||
ScrollBar = 9,
|
||||
ProgressBar = 10,
|
||||
ListBox = 11
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue