Loot UI is now mostly formed, just need to get loot into it and make it work.
This commit is contained in:
parent
8545b8cf1d
commit
dfc6aa08e9
12 changed files with 38 additions and 146 deletions
15
color.hpp
15
color.hpp
|
@ -1,15 +0,0 @@
|
||||||
#pragma once
|
|
||||||
#include <SFML/Graphics/Color.hpp>
|
|
||||||
|
|
||||||
namespace ColorValue {
|
|
||||||
constexpr const sf::Color BLACK{0, 0, 0};
|
|
||||||
constexpr const sf::Color DARK_DARK{10, 10, 10};
|
|
||||||
constexpr const sf::Color DARK_MID{30, 30, 30};
|
|
||||||
constexpr const sf::Color DARK_LIGHT{60, 60, 60};
|
|
||||||
constexpr const sf::Color MID{100, 100, 100};
|
|
||||||
constexpr const sf::Color LIGHT_DARK{150, 150, 150};
|
|
||||||
constexpr const sf::Color LIGHT_MID{200, 200, 200};
|
|
||||||
constexpr const sf::Color LIGHT_LIGHT{230, 230, 230};
|
|
||||||
constexpr const sf::Color WHITE{255, 255, 255};
|
|
||||||
constexpr const sf::Color TRANSPARENT = sf::Color::Transparent;
|
|
||||||
}
|
|
|
@ -1,7 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "color.hpp"
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
constexpr const int INV_SLOTS=20;
|
constexpr const int INV_SLOTS=20;
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace Events {
|
||||||
START, COMBAT, LOOT, DEATH, STAIRS_UP, STAIRS_DOWN, TRAP,
|
START, COMBAT, LOOT, DEATH, STAIRS_UP, STAIRS_DOWN, TRAP,
|
||||||
COMBAT_START, NO_NEIGHBORS, HP_STATUS,
|
COMBAT_START, NO_NEIGHBORS, HP_STATUS,
|
||||||
ATTACK, BLOCK, EVADE, NEW_RITUAL,
|
ATTACK, BLOCK, EVADE, NEW_RITUAL,
|
||||||
UPDATE_SPRITE, ENEMY_SPAWN, NOOP
|
UPDATE_SPRITE, ENEMY_SPAWN, NOOP, LOOT_CLOSE
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Combat {
|
struct Combat {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "gui/combat_ui.hpp"
|
#include "gui/combat_ui.hpp"
|
||||||
#include "constants.hpp"
|
#include "constants.hpp"
|
||||||
#include "color.hpp"
|
|
||||||
#include "rituals.hpp"
|
#include "rituals.hpp"
|
||||||
#include <fmt/xchar.h>
|
#include <fmt/xchar.h>
|
||||||
#include "guecstra.hpp"
|
#include "guecstra.hpp"
|
||||||
|
@ -37,7 +36,8 @@ namespace gui {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CombatUI::init() {
|
void CombatUI::init() {
|
||||||
$gui.set<Background>($gui.MAIN, {$gui.$parser, ColorValue::DARK_MID});
|
using guecs::THEME;
|
||||||
|
$gui.set<Background>($gui.MAIN, {$gui.$parser, THEME.DARK_MID});
|
||||||
auto& the_belt = $level.world->get_the<ritual::Belt>();
|
auto& the_belt = $level.world->get_the<ritual::Belt>();
|
||||||
|
|
||||||
for(int slot = 0; slot < the_belt.max_slots; slot++) {
|
for(int slot = 0; slot < the_belt.max_slots; slot++) {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "gui/debug_ui.hpp"
|
#include "gui/debug_ui.hpp"
|
||||||
#include "constants.hpp"
|
#include "constants.hpp"
|
||||||
#include "color.hpp"
|
|
||||||
#include "events.hpp"
|
#include "events.hpp"
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
|
|
|
@ -420,6 +420,10 @@ namespace gui {
|
||||||
case eGUI::NO_NEIGHBORS:
|
case eGUI::NO_NEIGHBORS:
|
||||||
event(Event::STOP_COMBAT);
|
event(Event::STOP_COMBAT);
|
||||||
break;
|
break;
|
||||||
|
case eGUI::LOOT_CLOSE:
|
||||||
|
// BUG: need to resolve GUI events vs. FSM events better
|
||||||
|
event(Event::LOOT_OPEN);
|
||||||
|
break;
|
||||||
case eGUI::LOOT: {
|
case eGUI::LOOT: {
|
||||||
// auto &item = std::any_cast<InventoryItem&>(data);
|
// auto &item = std::any_cast<InventoryItem&>(data);
|
||||||
// $status_ui.log(fmt::format("You picked up a {}.",
|
// $status_ui.log(fmt::format("You picked up a {}.",
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "gui/loot_ui.hpp"
|
#include "gui/loot_ui.hpp"
|
||||||
#include "constants.hpp"
|
#include "constants.hpp"
|
||||||
#include "color.hpp"
|
|
||||||
#include <fmt/xchar.h>
|
#include <fmt/xchar.h>
|
||||||
#include "guecstra.hpp"
|
#include "guecstra.hpp"
|
||||||
|
|
||||||
|
@ -14,25 +13,40 @@ namespace gui {
|
||||||
RAY_VIEW_Y+RAY_VIEW_HEIGHT/2-200, 400, 400);
|
RAY_VIEW_Y+RAY_VIEW_HEIGHT/2-200, 400, 400);
|
||||||
|
|
||||||
$gui.layout(
|
$gui.layout(
|
||||||
"[button_0 | button_1|button_2 | button_3]"
|
"[item_0 | item_1|item_2 | item_3]"
|
||||||
"[button_4 | button_5|button_6 | button_7]"
|
"[item_4 | item_5|item_6 | item_7]"
|
||||||
"[button_8 | button_9|button_10 | button_11]"
|
"[item_8 | item_9|item_10 | item_11]"
|
||||||
"[button_12 | button_13|button_14 | button_15]"
|
"[button_12|button_13|button_14|button_15]"
|
||||||
|
"[_ | *%(200)close|_ | _]"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LootUI::init() {
|
void LootUI::init() {
|
||||||
$gui.set<Background>($gui.MAIN, {$gui.$parser, ColorValue::DARK_MID});
|
using guecs::THEME;
|
||||||
for(auto [name, cell] : $gui.cells()) {
|
auto bg_color = THEME.DARK_LIGHT;
|
||||||
auto id = $gui.entity(name);
|
bg_color.a = 140;
|
||||||
$gui.set<guecs::Rectangle>(id, {});
|
$gui.set<Background>($gui.MAIN, {$gui.$parser, bg_color});
|
||||||
if(id < 4) {
|
|
||||||
$gui.set<guecs::Clickable>(id, {
|
// fill in 4 slots for prototype
|
||||||
[=](auto, auto) { fmt::println("clicked {}", name); }
|
for(int i = 0; i < 4; i++) {
|
||||||
});
|
auto id = $gui.entity("item_", i);
|
||||||
$gui.set<guecs::Sprite>(id, {"broken_yoyo-64"});
|
|
||||||
}
|
$gui.set<guecs::Rectangle>(id, {THEME.PADDING,
|
||||||
|
THEME.TRANSPARENT, THEME.LIGHT_MID });
|
||||||
|
|
||||||
|
$gui.set<guecs::Effect>(id, {0.4f, "ui_shader"});
|
||||||
|
$gui.set<guecs::Clickable>(id, {
|
||||||
|
[=](auto, auto) { fmt::println("clicked button_{}", i); }
|
||||||
|
});
|
||||||
|
$gui.set<guecs::Sprite>(id, {"broken_yoyo-64"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto close = $gui.entity("close");
|
||||||
|
$gui.set<guecs::Rectangle>(close, {});
|
||||||
|
$gui.set<guecs::Label>(close, {L"CLOSE"});
|
||||||
|
$gui.set<guecs::Clickable>(close,
|
||||||
|
guecs::make_action(*$level.world, Events::GUI::LOOT_CLOSE));
|
||||||
|
|
||||||
$gui.init();
|
$gui.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "gui/overlay_ui.hpp"
|
#include "gui/overlay_ui.hpp"
|
||||||
#include "constants.hpp"
|
#include "constants.hpp"
|
||||||
#include "color.hpp"
|
|
||||||
#include "events.hpp"
|
#include "events.hpp"
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#include "gui/status_ui.hpp"
|
#include "gui/status_ui.hpp"
|
||||||
#include "components.hpp"
|
#include "components.hpp"
|
||||||
#include "inventory.hpp"
|
#include "inventory.hpp"
|
||||||
#include "color.hpp"
|
|
||||||
#include <guecs/ui.hpp>
|
#include <guecs/ui.hpp>
|
||||||
#include "rand.hpp"
|
#include "rand.hpp"
|
||||||
#include <fmt/xchar.h>
|
#include <fmt/xchar.h>
|
||||||
|
|
55
lel.hpp
55
lel.hpp
|
@ -1,55 +0,0 @@
|
||||||
#pragma once
|
|
||||||
#include <string>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <functional>
|
|
||||||
#include <optional>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace lel {
|
|
||||||
|
|
||||||
struct Cell {
|
|
||||||
int x = 0;
|
|
||||||
int y = 0;
|
|
||||||
int w = 0;
|
|
||||||
int h = 0;
|
|
||||||
int mid_x = 0;
|
|
||||||
int mid_y = 0;
|
|
||||||
int max_w = 0;
|
|
||||||
int max_h = 0;
|
|
||||||
int col = 0;
|
|
||||||
int row = 0;
|
|
||||||
bool right = false;
|
|
||||||
bool bottom = false;
|
|
||||||
bool expand = false;
|
|
||||||
bool center = false;
|
|
||||||
bool percent = false;
|
|
||||||
|
|
||||||
Cell(int col, int row) : col(col), row(row) {}
|
|
||||||
Cell() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
using Row = std::vector<std::string>;
|
|
||||||
using CellMap = std::unordered_map<std::string, Cell>;
|
|
||||||
|
|
||||||
struct Parser {
|
|
||||||
int grid_x = 0;
|
|
||||||
int grid_y = 0;
|
|
||||||
int grid_w = 0;
|
|
||||||
int grid_h = 0;
|
|
||||||
Cell cur;
|
|
||||||
std::vector<Row> grid;
|
|
||||||
CellMap cells;
|
|
||||||
|
|
||||||
Parser(int x, int y, int width, int height);
|
|
||||||
Parser();
|
|
||||||
|
|
||||||
void position(int x, int y, int width, int height);
|
|
||||||
void id(std::string name);
|
|
||||||
void reset();
|
|
||||||
bool parse(std::string input);
|
|
||||||
void finalize();
|
|
||||||
std::optional<std::string> hit(int x, int y);
|
|
||||||
};
|
|
||||||
|
|
||||||
Cell center(int width, int height, Cell &parent);
|
|
||||||
}
|
|
|
@ -139,7 +139,6 @@ executable('runtests', sources + [
|
||||||
'tests/easings.cpp',
|
'tests/easings.cpp',
|
||||||
'tests/fsm.cpp',
|
'tests/fsm.cpp',
|
||||||
'tests/inventory.cpp',
|
'tests/inventory.cpp',
|
||||||
'tests/lel.cpp',
|
|
||||||
'tests/levelmanager.cpp',
|
'tests/levelmanager.cpp',
|
||||||
'tests/lighting.cpp',
|
'tests/lighting.cpp',
|
||||||
'tests/map.cpp',
|
'tests/map.cpp',
|
||||||
|
@ -167,7 +166,8 @@ executable('zedcaster',
|
||||||
dependencies: dependencies)
|
dependencies: dependencies)
|
||||||
|
|
||||||
executable('fragviewer',
|
executable('fragviewer',
|
||||||
sources + [ 'tools/fragviewer.cpp' ],
|
[ 'textures.cpp', 'config.cpp',
|
||||||
|
'dbc.cpp', 'tools/fragviewer.cpp' ],
|
||||||
cpp_args: cpp_args,
|
cpp_args: cpp_args,
|
||||||
link_args: link_args,
|
link_args: link_args,
|
||||||
override_options: exe_defaults,
|
override_options: exe_defaults,
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
#include "lel.hpp"
|
|
||||||
#include <catch2/catch_test_macros.hpp>
|
|
||||||
#include <fmt/core.h>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
TEST_CASE("test basic ops", "[lel]") {
|
|
||||||
lel::Parser parser(0, 0, 500, 500);
|
|
||||||
|
|
||||||
bool good = parser.parse(
|
|
||||||
"[ label_1 | label3 | test1]"
|
|
||||||
"[ *(300,300)text1 | %(150)people | ^test2]"
|
|
||||||
"[ >label2 | _ | .test3]"
|
|
||||||
"[ =message | buttons | test4]");
|
|
||||||
|
|
||||||
REQUIRE(good);
|
|
||||||
|
|
||||||
for(size_t rowcount = 0; rowcount < parser.grid.size(); rowcount++) {
|
|
||||||
auto& row = parser.grid[rowcount];
|
|
||||||
|
|
||||||
for(size_t colcount = 0; colcount < row.size(); colcount++) {
|
|
||||||
auto &name = row[colcount];
|
|
||||||
if(name == "_") {
|
|
||||||
REQUIRE(!parser.cells.contains(name));
|
|
||||||
} else {
|
|
||||||
auto &cell = parser.cells.at(name);
|
|
||||||
REQUIRE(cell.row == int(rowcount));
|
|
||||||
REQUIRE(cell.col == int(colcount));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
REQUIRE(parser.cells.size() == 11);
|
|
||||||
REQUIRE(parser.cells.at("label2").right == true);
|
|
||||||
REQUIRE(parser.cells.at("text1").expand == true);
|
|
||||||
REQUIRE(parser.cells.at("text1").w == 300);
|
|
||||||
REQUIRE(parser.cells.at("text1").h == 300);
|
|
||||||
REQUIRE(parser.cells.at("people").expand == false);
|
|
||||||
REQUIRE(parser.cells.at("message").expand == false);
|
|
||||||
REQUIRE(parser.cells.at("message").center == true);
|
|
||||||
|
|
||||||
for(auto& [name, cell] : parser.cells) {
|
|
||||||
REQUIRE(cell.w > 0);
|
|
||||||
REQUIRE(cell.h > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto hit = parser.hit(10, 10);
|
|
||||||
REQUIRE(*hit == "label_1");
|
|
||||||
|
|
||||||
auto nohit = parser.hit(1000, 1000);
|
|
||||||
REQUIRE(!nohit);
|
|
||||||
REQUIRE(nohit == std::nullopt);
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue