GUECS now has a click_on function so you can programatically click on buttons for testing.
This commit is contained in:
parent
78ba83e916
commit
70d27b9a95
2 changed files with 25 additions and 6 deletions
29
guecs.cpp
29
guecs.cpp
|
@ -259,7 +259,7 @@ namespace guecs {
|
||||||
bool UI::mouse(float x, float y, bool hover) {
|
bool UI::mouse(float x, float y, bool hover) {
|
||||||
int action_count = 0;
|
int action_count = 0;
|
||||||
|
|
||||||
$world.query<lel::Cell, Clickable>([&](auto ent, auto& cell, auto &clicked) {
|
$world.query<lel::Cell>([&](auto ent, auto& cell) {
|
||||||
if((x >= cell.x && x <= cell.x + cell.w) &&
|
if((x >= cell.x && x <= cell.x + cell.w) &&
|
||||||
(y >= cell.y && y <= cell.y + cell.h))
|
(y >= cell.y && y <= cell.y + cell.h))
|
||||||
{
|
{
|
||||||
|
@ -275,11 +275,7 @@ namespace guecs {
|
||||||
|
|
||||||
if(hover) return;
|
if(hover) return;
|
||||||
|
|
||||||
if(auto action_data = get_if<ActionData>(ent)) {
|
click_on(ent);
|
||||||
clicked.action(ent, action_data->data);
|
|
||||||
} else {
|
|
||||||
clicked.action(ent, {});
|
|
||||||
}
|
|
||||||
|
|
||||||
action_count++;
|
action_count++;
|
||||||
} else {
|
} else {
|
||||||
|
@ -317,6 +313,27 @@ namespace guecs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UI::click_on(const std::string& name, bool required) {
|
||||||
|
auto ent = entity(name);
|
||||||
|
|
||||||
|
if(required) {
|
||||||
|
dbc::check(has<Clickable>(ent),
|
||||||
|
fmt::format("click_on required '{}' to exist but it doesn't", name));
|
||||||
|
}
|
||||||
|
|
||||||
|
click_on(ent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UI::click_on(DinkyECS::Entity ent) {
|
||||||
|
if(auto clicked = get_if<Clickable>(ent)) {
|
||||||
|
if(auto action_data = get_if<ActionData>(ent)) {
|
||||||
|
clicked->action(ent, action_data->data);
|
||||||
|
} else {
|
||||||
|
clicked->action(ent, {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void UI::show_label(string region, wstring content) {
|
void UI::show_label(string region, wstring content) {
|
||||||
auto ent = entity(region);
|
auto ent = entity(region);
|
||||||
|
|
||||||
|
|
|
@ -155,6 +155,8 @@ namespace guecs {
|
||||||
void init();
|
void init();
|
||||||
void render(sf::RenderWindow& window);
|
void render(sf::RenderWindow& window);
|
||||||
bool mouse(float x, float y, bool hover);
|
bool mouse(float x, float y, bool hover);
|
||||||
|
void click_on(const std::string& name, bool required=false);
|
||||||
|
void click_on(DinkyECS::Entity slot_id);
|
||||||
void debug_layout(sf::RenderWindow& window);
|
void debug_layout(sf::RenderWindow& window);
|
||||||
|
|
||||||
template <typename Comp>
|
template <typename Comp>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue