minor refactor
This commit is contained in:
parent
e3297a418e
commit
a8aa0550c9
@ -478,6 +478,8 @@ void Hud::draw(const GfxContext& ctx){
|
|||||||
const uint width = viewport.getWidth();
|
const uint width = viewport.getWidth();
|
||||||
const uint height = viewport.getHeight();
|
const uint height = viewport.getHeight();
|
||||||
|
|
||||||
|
updateElementsPosition(viewport);
|
||||||
|
|
||||||
uicamera->setFov(height);
|
uicamera->setFov(height);
|
||||||
|
|
||||||
auto batch = ctx.getBatch2D();
|
auto batch = ctx.getBatch2D();
|
||||||
@ -487,11 +489,8 @@ void Hud::draw(const GfxContext& ctx){
|
|||||||
uishader->use();
|
uishader->use();
|
||||||
uishader->uniformMatrix("u_projview", uicamera->getProjView());
|
uishader->uniformMatrix("u_projview", uicamera->getProjView());
|
||||||
|
|
||||||
hotbarView->setPos(glm::vec2(width/2, height-65));
|
|
||||||
hotbarView->setSelected(player->getChosenSlot());
|
|
||||||
|
|
||||||
// Crosshair
|
// Crosshair
|
||||||
if (!pause && Events::_cursor_locked && !player->debug) {
|
if (!pause && !inventoryOpen && !player->debug) {
|
||||||
GfxContext chctx = ctx.sub();
|
GfxContext chctx = ctx.sub();
|
||||||
chctx.blendMode(blendmode::inversion);
|
chctx.blendMode(blendmode::inversion);
|
||||||
auto texture = assets->getTexture("gui/crosshair");
|
auto texture = assets->getTexture("gui/crosshair");
|
||||||
@ -504,6 +503,12 @@ void Hud::draw(const GfxContext& ctx){
|
|||||||
);
|
);
|
||||||
batch->flush();
|
batch->flush();
|
||||||
}
|
}
|
||||||
|
batch->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Hud::updateElementsPosition(const Viewport& viewport) {
|
||||||
|
const uint width = viewport.getWidth();
|
||||||
|
const uint height = viewport.getHeight();
|
||||||
|
|
||||||
if (inventoryOpen) {
|
if (inventoryOpen) {
|
||||||
float caWidth = inventoryView ? contentAccess->getSize().x : 0.0f;
|
float caWidth = inventoryView ? contentAccess->getSize().x : 0.0f;
|
||||||
@ -518,10 +523,10 @@ void Hud::draw(const GfxContext& ctx){
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
glm::vec2 blockInvSize = secondUI->getSize();
|
glm::vec2 secondUISize = secondUI->getSize();
|
||||||
float invwidth = glm::max(invSize.x, blockInvSize.x);
|
float invwidth = glm::max(invSize.x, secondUISize.x);
|
||||||
int interval = invSize.y > 0.0 ? 5 : 0;
|
int interval = invSize.y > 0.0 ? 5 : 0;
|
||||||
float totalHeight = invSize.y + blockInvSize.y + interval;
|
float totalHeight = invSize.y + secondUISize.y + interval;
|
||||||
if (inventoryView) {
|
if (inventoryView) {
|
||||||
inventoryView->setPos(glm::vec2(
|
inventoryView->setPos(glm::vec2(
|
||||||
glm::min(width/2-invwidth/2, width-caWidth-10-invwidth),
|
glm::min(width/2-invwidth/2, width-caWidth-10-invwidth),
|
||||||
@ -535,7 +540,8 @@ void Hud::draw(const GfxContext& ctx){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
grabbedItemView->setPos(glm::vec2(Events::cursor));
|
grabbedItemView->setPos(glm::vec2(Events::cursor));
|
||||||
batch->flush();
|
hotbarView->setPos(glm::vec2(width/2, height-65));
|
||||||
|
hotbarView->setSelected(player->getChosenSlot());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Hud::isInventoryOpen() const {
|
bool Hud::isInventoryOpen() const {
|
||||||
|
|||||||
@ -107,6 +107,7 @@ class Hud {
|
|||||||
std::shared_ptr<InventoryView> createContentAccess();
|
std::shared_ptr<InventoryView> createContentAccess();
|
||||||
std::shared_ptr<InventoryView> createHotbar();
|
std::shared_ptr<InventoryView> createHotbar();
|
||||||
|
|
||||||
|
void updateElementsPosition(const Viewport& viewport);
|
||||||
void cleanup();
|
void cleanup();
|
||||||
public:
|
public:
|
||||||
Hud(Engine* engine, LevelFrontend* frontend, Player* player);
|
Hud(Engine* engine, LevelFrontend* frontend, Player* player);
|
||||||
|
|||||||
@ -19,12 +19,11 @@ Batch2D::Batch2D(size_t capacity) : capacity(capacity), color(1.0f){
|
|||||||
ubyte pixels[] = {
|
ubyte pixels[] = {
|
||||||
0xFF, 0xFF, 0xFF, 0xFF
|
0xFF, 0xFF, 0xFF, 0xFF
|
||||||
};
|
};
|
||||||
blank = new Texture(pixels, 1, 1, GL_RGBA);
|
blank = std::make_unique<Texture>(pixels, 1, 1, GL_RGBA);
|
||||||
_texture = nullptr;
|
_texture = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Batch2D::~Batch2D(){
|
Batch2D::~Batch2D(){
|
||||||
delete blank;
|
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,10 +15,9 @@ class Batch2D {
|
|||||||
float* buffer;
|
float* buffer;
|
||||||
size_t capacity;
|
size_t capacity;
|
||||||
std::unique_ptr<Mesh> mesh;
|
std::unique_ptr<Mesh> mesh;
|
||||||
|
std::unique_ptr<Texture> blank;
|
||||||
size_t index;
|
size_t index;
|
||||||
glm::vec4 color;
|
glm::vec4 color;
|
||||||
|
|
||||||
Texture* blank;
|
|
||||||
Texture* _texture;
|
Texture* _texture;
|
||||||
|
|
||||||
void vertex(
|
void vertex(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user