feat: Add empty contextual action bar

This commit is contained in:
Vsevolod Kremianskii 2020-11-15 12:07:43 +07:00
parent ad209bcb7a
commit ac57c7f8ed
2 changed files with 57 additions and 9 deletions

View file

@ -38,8 +38,13 @@ namespace reone {
namespace game {
static const int kTitleBarWidth = 200;
static const int kTitleBarPadding = 3;
static const int kOffsetToReticle = 8;
static const int kTitleBarWidth = 250;
static const int kTitleBarPadding = 6;
static const int kActionBarMargin = 3;
static const int kActionBarPadding = 3;
static const int kActionWidth = 35;
static const int kActionHeight = 59;
SelectionOverlay::SelectionOverlay(Game *game) : _game(game) {
if (!game) {
@ -51,6 +56,9 @@ void SelectionOverlay::load() {
_font = Fonts::instance().get("dialogfont16x16");
_friendlyReticle = Textures::instance().get("friendlyreticle", TextureType::GUI);
_friendlyReticle2 = Textures::instance().get("friendlyreticle2", TextureType::GUI);
_friendlyScroll = Textures::instance().get("lbl_miscroll_f", TextureType::GUI);
_hostileScroll = Textures::instance().get("lbl_miscroll_h", TextureType::GUI);
_hilightedScroll = Textures::instance().get("lbl_miscroll_hi", TextureType::GUI);
_reticleHeight = _friendlyReticle2->height();
}
@ -75,6 +83,7 @@ void SelectionOverlay::update() {
_selectedScreenCoords = area->getSelectableScreenCoords(selectedObjectId, projection, view);
_selectedTitle = area->find(selectedObjectId)->title();
_hasSelected = _selectedScreenCoords.z < 1.0f;
_hasActions = true;
} else {
_hasSelected = false;
}
@ -86,6 +95,9 @@ void SelectionOverlay::render() const {
}
if (_hasSelected) {
drawReticle(*_friendlyReticle2, _selectedScreenCoords);
if (_hasActions) {
drawActionBar();
}
drawTitleBar();
}
}
@ -117,8 +129,14 @@ void SelectionOverlay::drawTitleBar() const {
const GraphicsOptions &opts = _game->options().graphics;
float barHeight = _font->height() + kTitleBarPadding;
{
float x = opts.width * _selectedScreenCoords.x - kTitleBarWidth / 2;
float y = opts.height * (1.0f - _selectedScreenCoords.y) - _reticleHeight / 2 - barHeight - kOffsetToReticle;
if (_hasActions) {
y -= kActionHeight + 2 * kActionBarMargin;
}
glm::mat4 transform(1.0f);
transform = glm::translate(transform, glm::vec3(opts.width * _selectedScreenCoords.x - kTitleBarWidth / 2, opts.height * (1.0f - _selectedScreenCoords.y) - _reticleHeight / 2 - barHeight, 0.0f));
transform = glm::translate(transform, glm::vec3(x, y, 0.0f));
transform = glm::scale(transform, glm::vec3(kTitleBarWidth, barHeight, 1.0f));
LocalUniforms locals;
@ -131,13 +149,14 @@ void SelectionOverlay::drawTitleBar() const {
Quad::getDefault().renderTriangles();
}
{
float x = opts.width * _selectedScreenCoords.x;
float y = opts.height * (1.0f - _selectedScreenCoords.y) - (_reticleHeight + barHeight) / 2 - kOffsetToReticle;
if (_hasActions) {
y -= kActionHeight + 2 * kActionBarMargin;
}
glm::mat4 transform(1.0f);
transform = glm::translate(
transform,
glm::vec3(
opts.width * _selectedScreenCoords.x,
opts.height * (1.0f - _selectedScreenCoords.y) - (_reticleHeight + barHeight) / 2,
0.0f));
transform = glm::translate(transform, glm::vec3(x, y, 0.0f));
glm::vec3 color(getBaseColor(_game->version()));
@ -145,6 +164,30 @@ void SelectionOverlay::drawTitleBar() const {
}
}
void SelectionOverlay::drawActionBar() const {
const GraphicsOptions &opts = _game->options().graphics;
float y = opts.height * (1.0f - _selectedScreenCoords.y) - _reticleHeight / 2 - kActionHeight - kOffsetToReticle - kActionBarMargin;
for (int i = -1; i < 2; ++i) {
float x = opts.width * _selectedScreenCoords.x + (static_cast<float>(i) - 0.5f) * kActionWidth + i * kActionBarMargin;
glm::mat4 transform(1.0f);
transform = glm::translate(transform, glm::vec3(x, y, 0.0f));
transform = glm::scale(transform, glm::vec3(kActionWidth, kActionHeight, 1.0f));
LocalUniforms locals;
locals.general.model = move(transform);
Shaders::instance().activate(ShaderProgram::GUIGUI, locals);
_friendlyScroll->bind(0);
Quad::getDefault().renderTriangles();
_friendlyScroll->unbind(0);
}
}
} // namespace game
} // namespace reone

View file

@ -51,8 +51,12 @@ private:
std::shared_ptr<render::Font> _font;
std::shared_ptr<render::Texture> _friendlyReticle;
std::shared_ptr<render::Texture> _friendlyReticle2;
std::shared_ptr<render::Texture> _friendlyScroll;
std::shared_ptr<render::Texture> _hostileScroll;
std::shared_ptr<render::Texture> _hilightedScroll;
bool _hasHilighted { false };
bool _hasSelected { false };
bool _hasActions { false };
glm::vec3 _hilightedScreenCoords { 0.0f };
glm::vec3 _selectedScreenCoords { 0.0f };
std::string _selectedTitle;
@ -60,6 +64,7 @@ private:
void drawReticle(render::Texture &texture, const glm::vec3 &screenCoords) const;
void drawTitleBar() const;
void drawActionBar() const;
};
} // namespace game