Menu basically done, grid is a bit buggy but good enough.
This commit is contained in:
@ -37,17 +37,17 @@ std::vector<struct ShaderPassItem> UIGrid::getSelfPassItems(
|
||||
}
|
||||
|
||||
void UIGrid::onChildAligned(UIComponent *child) {
|
||||
if(this->alignmentListenerLocked) return;
|
||||
assertNotNull(child);
|
||||
assertMapHasKey(this->gridChildren, child);
|
||||
this->alignmentListenerLocked = true;
|
||||
this->alignChild(child, this->gridChildren[child]);
|
||||
this->alignmentListenerLocked = false;
|
||||
}
|
||||
|
||||
void UIGrid::alignChild(UIComponent *child, struct UIGridPosition pos) {
|
||||
assertNotNull(child);
|
||||
|
||||
// Remove event listener
|
||||
child->eventAlignmentUpdated.addListener(this, &UIGrid::onChildAligned);
|
||||
|
||||
float_t gridX = (this->sizeCol * pos.x) + (this->gutterX * pos.x);
|
||||
float_t gridY = (this->sizeRow * pos.y) + (this->gutterY * pos.y);
|
||||
|
||||
@ -79,9 +79,6 @@ void UIGrid::alignChild(UIComponent *child, struct UIGridPosition pos) {
|
||||
glm::vec4(gridX + x, gridY + y, sizeX, sizeY),
|
||||
0.0f
|
||||
);
|
||||
|
||||
// Re-Add event listener
|
||||
child->eventAlignmentUpdated.addListener(this, &UIGrid::onChildAligned);
|
||||
}
|
||||
|
||||
void UIGrid::setGridSize(
|
||||
@ -114,6 +111,9 @@ void UIGrid::addToGrid(
|
||||
pos.alignY = alignY;
|
||||
this->gridChildren[ui] = pos;
|
||||
this->alignChild(ui, pos);
|
||||
|
||||
// Re-Add event listener
|
||||
ui->eventAlignmentUpdated.addListener(this, &UIGrid::onChildAligned);
|
||||
}
|
||||
|
||||
int32_t UIGrid::getRows() {
|
||||
|
@ -24,6 +24,7 @@ namespace Dawn {
|
||||
float_t gutterY = 0;
|
||||
float_t sizeRow, sizeCol;
|
||||
std::map<UIComponent*, struct UIGridPosition> gridChildren;
|
||||
bool_t alignmentListenerLocked = false;
|
||||
|
||||
/**
|
||||
* Internal method to update the alignment of a child.
|
||||
|
@ -4,6 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "UIMenu.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
@ -85,7 +86,37 @@ void UIMenu::onActive() {
|
||||
}
|
||||
|
||||
void UIMenu::onTick() {
|
||||
std::cout << "Tick menu" << std::endl;
|
||||
auto im = &this->canvas->getGame()->inputManager;
|
||||
|
||||
if(im->isPressed(INPUT_BIND_ACCEPT)) {
|
||||
auto item = this->getItem(this->x, this->y);
|
||||
if(item != nullptr && item->canBeSelected()) {
|
||||
item->onItemSelected();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(im->isPressed(INPUT_BIND_NEGATIVE_Y)) {
|
||||
this->moveRelative(0, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if(im->isPressed(INPUT_BIND_POSITIVE_Y)) {
|
||||
this->moveRelative(0, -1);
|
||||
return;
|
||||
}
|
||||
|
||||
if(im->isPressed(INPUT_BIND_NEGATIVE_X)) {
|
||||
this->moveRelative(-1, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if(im->isPressed(INPUT_BIND_POSITIVE_X)) {
|
||||
this->moveRelative(1, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Support more modes and holding buttons to scroll.
|
||||
}
|
||||
|
||||
UIMenu::~UIMenu() {
|
||||
|
Reference in New Issue
Block a user