Fixing more bugs related to percentages and then prototype a more complex UI.
This commit is contained in:
parent
e106ad4be7
commit
a7991a8f06
5 changed files with 45 additions and 20 deletions
2
Makefile
2
Makefile
|
@ -22,7 +22,7 @@ tracy_build:
|
|||
meson compile -j 10 -C builddir
|
||||
|
||||
test: build
|
||||
./builddir/runtests "[lel]"
|
||||
./builddir/runtests
|
||||
|
||||
run: build test
|
||||
powershell "cp ./builddir/zedcaster.exe ."
|
||||
|
|
|
@ -6,14 +6,17 @@ namespace gui {
|
|||
CombatUI::CombatUI(GameLevel level) :
|
||||
$layout(RAY_VIEW_X, RAY_VIEW_HEIGHT,
|
||||
RAY_VIEW_WIDTH, SCREEN_HEIGHT - RAY_VIEW_HEIGHT),
|
||||
$level(level)
|
||||
$level(level),
|
||||
$font{FONT_FILE_NAME}
|
||||
{
|
||||
bool good = $layout.parse(
|
||||
"[attack1 | attack2 | attack3 | heal]"
|
||||
);
|
||||
|
||||
bool good = $layout.parse($grid);
|
||||
dbc::check(good, "failed to parse combat layout");
|
||||
|
||||
render();
|
||||
}
|
||||
|
||||
void CombatUI::render() {
|
||||
|
||||
for(auto& [name, cell] : $layout.cells) {
|
||||
sf::RectangleShape button;
|
||||
button.setPosition({float(cell.x + 10), float(cell.y + 10)});
|
||||
|
@ -23,14 +26,11 @@ namespace gui {
|
|||
button.setOutlineThickness(5);
|
||||
$shapes.insert_or_assign(name, button);
|
||||
|
||||
sf::RectangleShape inner;
|
||||
auto inner_cell = lel::center(30, 40, cell);
|
||||
inner.setPosition({float(inner_cell.x), float(inner_cell.y)});
|
||||
inner.setSize({float(inner_cell.w), float(inner_cell.h)});
|
||||
inner.setOutlineColor({100, 0, 0});
|
||||
inner.setOutlineThickness(5);
|
||||
inner.setFillColor({50, 50, 50});
|
||||
$shapes.insert_or_assign(name + "_text", inner);
|
||||
sf::Text label($font, name);
|
||||
auto bounds = label.getLocalBounds();
|
||||
auto inner_cell = lel::center(bounds.size.x, bounds.size.y, cell);
|
||||
label.setPosition({float(inner_cell.x), float(inner_cell.y)});
|
||||
$labels.push_back(label);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,10 @@ namespace gui {
|
|||
for(auto& [name, shape] : $shapes) {
|
||||
window.draw(shape);
|
||||
}
|
||||
|
||||
for(auto& label : $labels) {
|
||||
window.draw(label);
|
||||
}
|
||||
}
|
||||
|
||||
void CombatUI::click(int x, int y) {
|
||||
|
|
|
@ -3,16 +3,24 @@
|
|||
#include "levelmanager.hpp"
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
#include <SFML/Graphics/RectangleShape.hpp>
|
||||
#include <SFML/Graphics/Font.hpp>
|
||||
#include <SFML/Graphics/Text.hpp>
|
||||
#include "lel.hpp"
|
||||
|
||||
namespace gui {
|
||||
class CombatUI {
|
||||
public:
|
||||
std::string $grid =
|
||||
"[*%(200)hp | _ | *%(200)ap | _ ]"
|
||||
"[attack1 | attack2 | attack3 | heal]";
|
||||
lel::Parser $layout;
|
||||
GameLevel $level;
|
||||
sf::Font $font;
|
||||
std::unordered_map<std::string, sf::RectangleShape> $shapes;
|
||||
std::vector<sf::Text> $labels;
|
||||
CombatUI(GameLevel level);
|
||||
|
||||
void render();
|
||||
void draw(sf::RenderWindow& window);
|
||||
void update_level(GameLevel &level) { $level = level; }
|
||||
void click(int x, int y);
|
||||
|
|
7
gui.cpp
7
gui.cpp
|
@ -161,6 +161,9 @@ namespace gui {
|
|||
case CLOSE:
|
||||
dbc::log("Nothing to close.");
|
||||
break;
|
||||
case TICK:
|
||||
// do nothing
|
||||
break;
|
||||
default:
|
||||
dbc::sentinel("unhandled event in IDLE");
|
||||
}
|
||||
|
@ -243,6 +246,10 @@ namespace gui {
|
|||
case KEY::R:
|
||||
$stats.reset();
|
||||
break;
|
||||
case KEY::G:
|
||||
$combat_view.render();
|
||||
event(Event::TICK);
|
||||
break;
|
||||
case KEY::M:
|
||||
event(Event::MAP_OPEN);
|
||||
break;
|
||||
|
|
18
lel.cpp
18
lel.cpp
|
@ -35,21 +35,27 @@ namespace lel {
|
|||
dbc::check(cell_width > 0, "invalid cell width calc");
|
||||
dbc::check(cell_height > 0, "invalid cell height calc");
|
||||
|
||||
|
||||
for(auto& [name, cell] : cells) {
|
||||
cell.x = grid_x + (cell.col * cell_width);
|
||||
cell.y = grid_y + (cell.row * cell_height);
|
||||
cell.max_w = cell.max_w == 0 ? cell_width : cell.max_w;
|
||||
cell.max_h = cell.max_h == 0 ? cell_height : cell.max_h;
|
||||
|
||||
// ZED: getting a bit hairy but this should work
|
||||
if(cell.percent) {
|
||||
cell.max_w = cell.max_w * 0.01 * cell_width;
|
||||
cell.max_h = cell.max_h * 0.01 * cell_height;
|
||||
// when percent mode we have to take unset to 100%
|
||||
if(cell.max_w == 0) cell.max_w = 100;
|
||||
if(cell.max_h == 0) cell.max_h = 100;
|
||||
cell.max_w *= cell_width * 0.01;
|
||||
cell.max_h *= cell_height * 0.01;
|
||||
} else {
|
||||
if(cell.max_w == 0) cell.max_w = cell_width;
|
||||
if(cell.max_h == 0) cell.max_h = cell_height;
|
||||
}
|
||||
|
||||
cell.w = cell.expand ? std::min(cell.max_w, grid_w) : std::min(cell_width, cell.max_w);
|
||||
cell.h = cell.expand ? std::min(cell.max_h, grid_h) : std::min(cell_height, cell.max_h);
|
||||
cell.mid_x = std::midpoint(cell.x, cell.x + cell_width);
|
||||
cell.mid_y = std::midpoint(cell.y, cell.y + cell_height);
|
||||
cell.mid_x = std::midpoint(cell.x, cell.x + cell.w);
|
||||
cell.mid_y = std::midpoint(cell.y, cell.y + cell.h);
|
||||
|
||||
if(cell.right) cell.x += cell_width - cell.w;
|
||||
if(cell.bottom) cell.y += cell_height - cell.h;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue