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
|
meson compile -j 10 -C builddir
|
||||||
|
|
||||||
test: build
|
test: build
|
||||||
./builddir/runtests "[lel]"
|
./builddir/runtests
|
||||||
|
|
||||||
run: build test
|
run: build test
|
||||||
powershell "cp ./builddir/zedcaster.exe ."
|
powershell "cp ./builddir/zedcaster.exe ."
|
||||||
|
|
|
@ -6,14 +6,17 @@ namespace gui {
|
||||||
CombatUI::CombatUI(GameLevel level) :
|
CombatUI::CombatUI(GameLevel level) :
|
||||||
$layout(RAY_VIEW_X, RAY_VIEW_HEIGHT,
|
$layout(RAY_VIEW_X, RAY_VIEW_HEIGHT,
|
||||||
RAY_VIEW_WIDTH, SCREEN_HEIGHT - RAY_VIEW_HEIGHT),
|
RAY_VIEW_WIDTH, SCREEN_HEIGHT - RAY_VIEW_HEIGHT),
|
||||||
$level(level)
|
$level(level),
|
||||||
|
$font{FONT_FILE_NAME}
|
||||||
{
|
{
|
||||||
bool good = $layout.parse(
|
bool good = $layout.parse($grid);
|
||||||
"[attack1 | attack2 | attack3 | heal]"
|
|
||||||
);
|
|
||||||
|
|
||||||
dbc::check(good, "failed to parse combat layout");
|
dbc::check(good, "failed to parse combat layout");
|
||||||
|
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CombatUI::render() {
|
||||||
|
|
||||||
for(auto& [name, cell] : $layout.cells) {
|
for(auto& [name, cell] : $layout.cells) {
|
||||||
sf::RectangleShape button;
|
sf::RectangleShape button;
|
||||||
button.setPosition({float(cell.x + 10), float(cell.y + 10)});
|
button.setPosition({float(cell.x + 10), float(cell.y + 10)});
|
||||||
|
@ -23,14 +26,11 @@ namespace gui {
|
||||||
button.setOutlineThickness(5);
|
button.setOutlineThickness(5);
|
||||||
$shapes.insert_or_assign(name, button);
|
$shapes.insert_or_assign(name, button);
|
||||||
|
|
||||||
sf::RectangleShape inner;
|
sf::Text label($font, name);
|
||||||
auto inner_cell = lel::center(30, 40, cell);
|
auto bounds = label.getLocalBounds();
|
||||||
inner.setPosition({float(inner_cell.x), float(inner_cell.y)});
|
auto inner_cell = lel::center(bounds.size.x, bounds.size.y, cell);
|
||||||
inner.setSize({float(inner_cell.w), float(inner_cell.h)});
|
label.setPosition({float(inner_cell.x), float(inner_cell.y)});
|
||||||
inner.setOutlineColor({100, 0, 0});
|
$labels.push_back(label);
|
||||||
inner.setOutlineThickness(5);
|
|
||||||
inner.setFillColor({50, 50, 50});
|
|
||||||
$shapes.insert_or_assign(name + "_text", inner);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,10 @@ namespace gui {
|
||||||
for(auto& [name, shape] : $shapes) {
|
for(auto& [name, shape] : $shapes) {
|
||||||
window.draw(shape);
|
window.draw(shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(auto& label : $labels) {
|
||||||
|
window.draw(label);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CombatUI::click(int x, int y) {
|
void CombatUI::click(int x, int y) {
|
||||||
|
|
|
@ -3,16 +3,24 @@
|
||||||
#include "levelmanager.hpp"
|
#include "levelmanager.hpp"
|
||||||
#include <SFML/Graphics/RenderWindow.hpp>
|
#include <SFML/Graphics/RenderWindow.hpp>
|
||||||
#include <SFML/Graphics/RectangleShape.hpp>
|
#include <SFML/Graphics/RectangleShape.hpp>
|
||||||
|
#include <SFML/Graphics/Font.hpp>
|
||||||
|
#include <SFML/Graphics/Text.hpp>
|
||||||
#include "lel.hpp"
|
#include "lel.hpp"
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
class CombatUI {
|
class CombatUI {
|
||||||
public:
|
public:
|
||||||
|
std::string $grid =
|
||||||
|
"[*%(200)hp | _ | *%(200)ap | _ ]"
|
||||||
|
"[attack1 | attack2 | attack3 | heal]";
|
||||||
lel::Parser $layout;
|
lel::Parser $layout;
|
||||||
GameLevel $level;
|
GameLevel $level;
|
||||||
|
sf::Font $font;
|
||||||
std::unordered_map<std::string, sf::RectangleShape> $shapes;
|
std::unordered_map<std::string, sf::RectangleShape> $shapes;
|
||||||
|
std::vector<sf::Text> $labels;
|
||||||
CombatUI(GameLevel level);
|
CombatUI(GameLevel level);
|
||||||
|
|
||||||
|
void render();
|
||||||
void draw(sf::RenderWindow& window);
|
void draw(sf::RenderWindow& window);
|
||||||
void update_level(GameLevel &level) { $level = level; }
|
void update_level(GameLevel &level) { $level = level; }
|
||||||
void click(int x, int y);
|
void click(int x, int y);
|
||||||
|
|
7
gui.cpp
7
gui.cpp
|
@ -161,6 +161,9 @@ namespace gui {
|
||||||
case CLOSE:
|
case CLOSE:
|
||||||
dbc::log("Nothing to close.");
|
dbc::log("Nothing to close.");
|
||||||
break;
|
break;
|
||||||
|
case TICK:
|
||||||
|
// do nothing
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
dbc::sentinel("unhandled event in IDLE");
|
dbc::sentinel("unhandled event in IDLE");
|
||||||
}
|
}
|
||||||
|
@ -243,6 +246,10 @@ namespace gui {
|
||||||
case KEY::R:
|
case KEY::R:
|
||||||
$stats.reset();
|
$stats.reset();
|
||||||
break;
|
break;
|
||||||
|
case KEY::G:
|
||||||
|
$combat_view.render();
|
||||||
|
event(Event::TICK);
|
||||||
|
break;
|
||||||
case KEY::M:
|
case KEY::M:
|
||||||
event(Event::MAP_OPEN);
|
event(Event::MAP_OPEN);
|
||||||
break;
|
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_width > 0, "invalid cell width calc");
|
||||||
dbc::check(cell_height > 0, "invalid cell height calc");
|
dbc::check(cell_height > 0, "invalid cell height calc");
|
||||||
|
|
||||||
|
|
||||||
for(auto& [name, cell] : cells) {
|
for(auto& [name, cell] : cells) {
|
||||||
cell.x = grid_x + (cell.col * cell_width);
|
cell.x = grid_x + (cell.col * cell_width);
|
||||||
cell.y = grid_y + (cell.row * cell_height);
|
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) {
|
if(cell.percent) {
|
||||||
cell.max_w = cell.max_w * 0.01 * cell_width;
|
// when percent mode we have to take unset to 100%
|
||||||
cell.max_h = cell.max_h * 0.01 * cell_height;
|
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.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.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_x = std::midpoint(cell.x, cell.x + cell.w);
|
||||||
cell.mid_y = std::midpoint(cell.y, cell.y + cell_height);
|
cell.mid_y = std::midpoint(cell.y, cell.y + cell.h);
|
||||||
|
|
||||||
if(cell.right) cell.x += cell_width - cell.w;
|
if(cell.right) cell.x += cell_width - cell.w;
|
||||||
if(cell.bottom) cell.y += cell_height - cell.h;
|
if(cell.bottom) cell.y += cell_height - cell.h;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue