Can now do UI rendering based on the name and also have gaps in the grid reliably.
This commit is contained in:
parent
79c84ce885
commit
3ec2bf4784
4 changed files with 39 additions and 26 deletions
|
@ -17,13 +17,14 @@ namespace gui {
|
||||||
|
|
||||||
void CombatUI::render() {
|
void CombatUI::render() {
|
||||||
for(auto& [name, cell] : $layout.cells) {
|
for(auto& [name, cell] : $layout.cells) {
|
||||||
sf::RectangleShape button;
|
sf::RectangleShape shape;
|
||||||
button.setPosition({float(cell.x + 10), float(cell.y + 10)});
|
shape.setPosition({float(cell.x + 3), float(cell.y + 3)});
|
||||||
button.setSize({float(cell.w - 20), float(cell.h - 20)});
|
shape.setSize({float(cell.w - 6), float(cell.h - 6)});
|
||||||
button.setFillColor({100, 100, 100});
|
shape.setFillColor({100, 100, 100});
|
||||||
button.setOutlineColor({200, 200, 200});
|
|
||||||
button.setOutlineThickness(5);
|
if(name.starts_with("button_")) {
|
||||||
$shapes.insert_or_assign(name, button);
|
shape.setOutlineColor({200, 200, 200});
|
||||||
|
shape.setOutlineThickness(1);
|
||||||
|
|
||||||
sf::Text label($font, name);
|
sf::Text label($font, name);
|
||||||
auto bounds = label.getLocalBounds();
|
auto bounds = label.getLocalBounds();
|
||||||
|
@ -32,6 +33,9 @@ namespace gui {
|
||||||
label.setPosition({float(label_cell.x), float(label_cell.y) - label_cell.h / 2});
|
label.setPosition({float(label_cell.x), float(label_cell.y) - label_cell.h / 2});
|
||||||
$labels.push_back(label);
|
$labels.push_back(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$shapes.insert_or_assign(name, shape);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CombatUI::draw(sf::RenderWindow& window) {
|
void CombatUI::draw(sf::RenderWindow& window) {
|
||||||
|
@ -50,8 +54,10 @@ namespace gui {
|
||||||
|
|
||||||
void CombatUI::click(int x, int y) {
|
void CombatUI::click(int x, int y) {
|
||||||
if(auto name = $layout.hit(x, y)) {
|
if(auto name = $layout.hit(x, y)) {
|
||||||
|
if((*name).starts_with("button_")) {
|
||||||
auto& shape = $shapes.at(*name);
|
auto& shape = $shapes.at(*name);
|
||||||
shape.setFillColor({100, 0, 0});
|
shape.setFillColor({100, 0, 0});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,8 @@ namespace gui {
|
||||||
class CombatUI {
|
class CombatUI {
|
||||||
public:
|
public:
|
||||||
std::string $grid =
|
std::string $grid =
|
||||||
"[hp | ap ]"
|
"[*%(100,150)button_attack1 | *%(100,150)button_attack2 | *%(100,150)button_attack3 | *%(100,150)button_heal]"
|
||||||
"[attack1 | attack2 | attack3 | heal]";
|
"[*%.(200,50)bar_hp | _ | %.(100,50)bar_ap ]";
|
||||||
lel::Parser $layout;
|
lel::Parser $layout;
|
||||||
GameLevel $level;
|
GameLevel $level;
|
||||||
sf::Font $font;
|
sf::Font $font;
|
||||||
|
|
7
lel.cpp
7
lel.cpp
|
@ -17,12 +17,13 @@ namespace lel {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::id(std::string name) {
|
void Parser::id(std::string name) {
|
||||||
|
if(name != "_") {
|
||||||
dbc::check(!cells.contains(name),
|
dbc::check(!cells.contains(name),
|
||||||
fmt::format("duplicate cell name {}", name));
|
fmt::format("duplicate cell name {}", name));
|
||||||
cells.insert_or_assign(name, cur);
|
cells.insert_or_assign(name, cur);
|
||||||
|
}
|
||||||
|
|
||||||
cur = {cur.col + 1, cur.row};
|
cur = {cur.col + 1, cur.row};
|
||||||
|
|
||||||
auto& row = grid.back();
|
auto& row = grid.back();
|
||||||
row.push_back(name);
|
row.push_back(name);
|
||||||
}
|
}
|
||||||
|
@ -32,8 +33,10 @@ namespace lel {
|
||||||
int cell_height = grid_h / rows;
|
int cell_height = grid_h / rows;
|
||||||
|
|
||||||
for(auto& row : grid) {
|
for(auto& row : grid) {
|
||||||
for(auto& name : row) {
|
|
||||||
size_t columns = row.size();
|
size_t columns = row.size();
|
||||||
|
|
||||||
|
for(auto& name : row) {
|
||||||
|
if(name == "_") continue;
|
||||||
auto& cell = cells.at(name);
|
auto& cell = cells.at(name);
|
||||||
|
|
||||||
int cell_width = grid_w / columns;
|
int cell_width = grid_w / columns;
|
||||||
|
|
|
@ -23,13 +23,17 @@ TEST_CASE("test basic ops", "[lel]") {
|
||||||
|
|
||||||
for(size_t colcount = 0; colcount < row.size(); colcount++) {
|
for(size_t colcount = 0; colcount < row.size(); colcount++) {
|
||||||
auto &name = row[colcount];
|
auto &name = row[colcount];
|
||||||
|
if(name == "_") {
|
||||||
|
REQUIRE(!parser.cells.contains(name));
|
||||||
|
} else {
|
||||||
auto &cell = parser.cells.at(name);
|
auto &cell = parser.cells.at(name);
|
||||||
REQUIRE(cell.row == int(rowcount));
|
REQUIRE(cell.row == int(rowcount));
|
||||||
REQUIRE(cell.col == int(colcount));
|
REQUIRE(cell.col == int(colcount));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
REQUIRE(parser.cells.size() == 12);
|
REQUIRE(parser.cells.size() == 11);
|
||||||
REQUIRE(parser.cells.at("label2").right == true);
|
REQUIRE(parser.cells.at("label2").right == true);
|
||||||
REQUIRE(parser.cells.at("text1").expand == true);
|
REQUIRE(parser.cells.at("text1").expand == true);
|
||||||
REQUIRE(parser.cells.at("text1").w == 300);
|
REQUIRE(parser.cells.at("text1").w == 300);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue