Menu basically done, grid is a bit buggy but good enough.

This commit is contained in:
2023-01-28 21:28:10 -08:00
parent d14e063ba6
commit a06d24aad8
7 changed files with 52 additions and 14 deletions

View File

@ -29,5 +29,5 @@ scene.22.1,"King Fight"
scene.23.1,"Post King Fight, angry he leaves, town rallies around you"
scene.24.1,"Go to one of the kingsmen who's working with the big bad, he's worried that the townspeople know more than they let on."
unknown3,"Something here has to bring the big bad to town."
test.1,"Test "
test.1,"Test"
test.2,"Test*"
1 undefined UNDEFINED
29 scene.23.1 Post King Fight, angry he leaves, town rallies around you
30 scene.24.1 Go to one of the kingsmen who's working with the big bad, he's worried that the townspeople know more than they let on.
31 unknown3 Something here has to bring the big bad to town.
32 test.1 Test Test
33 test.2 Test*

View File

@ -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() {

View File

@ -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.

View File

@ -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() {

View File

@ -61,10 +61,10 @@ int32_t DawnHost::init(DawnGame *game) {
game->inputManager.bind(INPUT_BIND_ACCEPT, GLFW_KEY_ENTER);
game->inputManager.bind(INPUT_BIND_ACCEPT, GLFW_KEY_E);
game->inputManager.bind(INPUT_BIND_ACCEPT, GLFW_KEY_SPACE);
// game->inputManager.bind(INPUT_BIND_NEGATIVE_X, GLFW_KEY_A);
// game->inputManager.bind(INPUT_BIND_POSITIVE_X, GLFW_KEY_D);
// game->inputManager.bind(INPUT_BIND_NEGATIVE_Y, GLFW_KEY_S);
// game->inputManager.bind(INPUT_BIND_POSITIVE_Y, GLFW_KEY_W);
game->inputManager.bind(INPUT_BIND_NEGATIVE_X, GLFW_KEY_A);
game->inputManager.bind(INPUT_BIND_POSITIVE_X, GLFW_KEY_D);
game->inputManager.bind(INPUT_BIND_NEGATIVE_Y, GLFW_KEY_S);
game->inputManager.bind(INPUT_BIND_POSITIVE_Y, GLFW_KEY_W);
// Initialize the game
auto result = game->init();

View File

@ -6,4 +6,10 @@
#pragma once
#include "input/InputManager.hpp"
#define INPUT_BIND_ACCEPT ((inputbind_t)1)
#define dbind(n) ((inputbind_t)n)
#define INPUT_BIND_ACCEPT dbind(1)
#define INPUT_BIND_NEGATIVE_X dbind(2)
#define INPUT_BIND_POSITIVE_X dbind(3)
#define INPUT_BIND_NEGATIVE_Y dbind(4)
#define INPUT_BIND_POSITIVE_Y dbind(5)

View File

@ -55,7 +55,7 @@ void TestUIScene::stage() {
label->setFont(&assetFont->font);
label->setText("test.1");
label->setFontSize(24);
grid->addToGrid(label, x, y, UI_COMPONENT_ALIGN_END, UI_COMPONENT_ALIGN_END);
grid->addToGrid(label, x, y, UI_COMPONENT_ALIGN_MIDDLE, UI_COMPONENT_ALIGN_MIDDLE);
auto menuItem = new TestMenuItem;
menuItem->label = label;