Better UI for the ritual crafting that almost works, but need to get the selected items to move down. Might need some state machine love soon.
This commit is contained in:
parent
9d55b2954a
commit
14619558fa
9 changed files with 99 additions and 48 deletions
2
Makefile
2
Makefile
|
@ -26,7 +26,7 @@ tracy_build:
|
|||
meson compile -j 10 -C builddir
|
||||
|
||||
test: build
|
||||
./builddir/runtests
|
||||
./builddir/runtests "[rituals-belt]"
|
||||
|
||||
run: build test
|
||||
ifeq '$(OS)' 'Windows_NT'
|
||||
|
|
|
@ -197,6 +197,6 @@
|
|||
}
|
||||
},
|
||||
"starting_junk": [
|
||||
"mushroom", "rusty_nails"
|
||||
"dirty_kerchief", "pocket_watch", "chess_pawn", "mushroom", "severed_finger", "rusty_nails"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -151,6 +151,10 @@ namespace guecs {
|
|||
return $name_ents.at(name);
|
||||
}
|
||||
|
||||
DinkyECS::Entity UI::entity(std::string name, int id) {
|
||||
return entity(fmt::format("{}{}", name, id));
|
||||
}
|
||||
|
||||
void UI::init() {
|
||||
if($world.has_the<Background>()) {
|
||||
auto& bg = $world.get_the<Background>();
|
||||
|
|
|
@ -139,6 +139,7 @@ namespace guecs {
|
|||
void layout(std::string grid);
|
||||
DinkyECS::Entity init_entity(std::string name);
|
||||
DinkyECS::Entity entity(std::string name);
|
||||
DinkyECS::Entity entity(std::string name, int id);
|
||||
|
||||
inline lel::CellMap& cells() {
|
||||
return $parser.cells;
|
||||
|
|
|
@ -20,23 +20,39 @@ namespace gui {
|
|||
"[inv_slot4 | inv_slot5 | inv_slot6| inv_slot7]"
|
||||
"[inv_slot8 | inv_slot9 | inv_slot10| inv_slot11]"
|
||||
"[inv_slot12 | inv_slot13 | inv_slot14| inv_slot15]"
|
||||
"[*%(100,600)circle_area]"
|
||||
"[_]"
|
||||
"[_]"
|
||||
"[_]"
|
||||
"[_]"
|
||||
"[_]"
|
||||
"[reset |*%(200,400)result_text|_]"
|
||||
"[*%(100,200)result_image|_ |_]"
|
||||
"[_|_|_]"
|
||||
"[combine|_|_]"
|
||||
"[_|craft1|craft2|craft3|craft4|_]"
|
||||
"[_|craft5|craft6|craft7|craft8|_]"
|
||||
"[ ritual_ui ]");
|
||||
}
|
||||
|
||||
void RitualUI::init() {
|
||||
update_items();
|
||||
|
||||
auto circle = $gui.entity("circle_area");
|
||||
$gui.set<Effect>(circle, {0.4f});
|
||||
$gui.set<Sprite>(circle, {"the_ritual_circle"});
|
||||
$gui.set<Clickable>(circle, {
|
||||
[&](auto ent, auto){ ritual_circle_clicked(ent); }
|
||||
auto combine = $gui.entity("combine");
|
||||
$gui.set<Effect>(combine, {0.4f});
|
||||
$gui.set<Sprite>(combine, {"the_ritual_circle"});
|
||||
$gui.set<Clickable>(combine, {
|
||||
[&](auto ent, auto){ combine_clicked(ent); }
|
||||
});
|
||||
|
||||
auto result_image = $gui.entity("result_image");
|
||||
$gui.set<Sprite>(result_image, {"severed_finger-128"});
|
||||
$gui.set<Rectangle>(result_image, {10, {60, 60, 60, 30}});
|
||||
|
||||
auto result_text = $gui.entity("result_text");
|
||||
$gui.set<Rectangle>(result_text, {15, {60, 60, 60, 30}});
|
||||
$gui.set<Textual>(result_text, {
|
||||
L"Celiac migas\nunicorn hexagon.\nBrooklyn williamsburg\ntruffaut pickled\nchillwave raclette\nchurch-key sus.", 16, ColorValue::LIGHT_LIGHT, 10});
|
||||
|
||||
auto reset = $gui.entity("reset");
|
||||
$gui.set<Rectangle>(reset, {});
|
||||
$gui.set<Label>(reset, L"reset");
|
||||
$gui.set<Clickable>(reset, {
|
||||
[&](auto ent, auto){ reset_clicked(ent); }
|
||||
});
|
||||
|
||||
auto open_close_toggle = $gui.entity("ritual_ui");
|
||||
|
@ -56,31 +72,27 @@ namespace gui {
|
|||
return $ritual_state != RitualUIState::CLOSED;
|
||||
}
|
||||
|
||||
void RitualUI::inv_slot_clicked(DinkyECS::Entity ent) {
|
||||
void RitualUI::inv_slot_clicked(DinkyECS::Entity ent, DinkyECS::Entity item_id) {
|
||||
if($gui.has<Sprite>(ent)) {
|
||||
auto& bs = $gui.get<Sprite>(ent);
|
||||
auto ritual_circle = $gui.entity("circle_area");
|
||||
auto& ritual_cell = $gui.cell_for(ritual_circle);
|
||||
dbc::log(fmt::format("inv_slot clicked {}", bs.name));
|
||||
// auto& bs = $gui.get<Sprite>(ent);
|
||||
// auto combine = $gui.entity("combine");
|
||||
|
||||
int inner_x = ritual_cell.x + ritual_cell.x / 2;
|
||||
int inner_y = ritual_cell.y + ritual_cell.y / 2;
|
||||
// do things to the combine button
|
||||
|
||||
float x = Random::uniform(inner_x, inner_x + ritual_cell.w / 2);
|
||||
float y = Random::uniform(inner_y, inner_y + ritual_cell.h / 2);
|
||||
bs.sprite->setPosition({float(x), float(y)});
|
||||
auto& blanket = $level.world->get_the<ritual::Blanket>();
|
||||
auto& junk_item = blanket.get(item_id);
|
||||
|
||||
$engine.load_junk($craft_state, junk_item);
|
||||
}
|
||||
|
||||
// BUG: get the actual thing they clicked on
|
||||
$engine.set_state($craft_state, "has_magick", true);
|
||||
}
|
||||
|
||||
void RitualUI::reset_inv_positions() {
|
||||
auto ritual_circle = $gui.entity("circle_area");
|
||||
$craft_state.reset();
|
||||
auto combine = $gui.entity("combine");
|
||||
|
||||
$gui.world().query<lel::Cell, Sprite>(
|
||||
[&](const auto ent, auto &cell, auto &bs) {
|
||||
if(ent == ritual_circle) {
|
||||
if(ent == combine) {
|
||||
bs.sprite->setColor({255,255,255,255});
|
||||
bs.sprite->setRotation(sf::degrees(0.0));
|
||||
} else {
|
||||
|
@ -89,11 +101,16 @@ namespace gui {
|
|||
});
|
||||
}
|
||||
|
||||
void RitualUI::ritual_circle_clicked(DinkyECS::Entity ent) {
|
||||
auto cell = $gui.cell_for(ent);
|
||||
void RitualUI::reset_clicked(DinkyECS::Entity ent) {
|
||||
(void)ent; // make button animate
|
||||
reset_inv_positions();
|
||||
}
|
||||
|
||||
void RitualUI::combine_clicked(DinkyECS::Entity ent) {
|
||||
// auto cell = $gui.cell_for(ent);
|
||||
auto& bs = $gui.get<Sprite>(ent);
|
||||
bs.sprite->setColor({200, 0, 0});
|
||||
animation::center(*bs.sprite, {(float)cell.x, (float)cell.y});
|
||||
// animation::center(*bs.sprite, {(float)cell.x, (float)cell.y});
|
||||
animation::rotate(*bs.sprite, 20.0);
|
||||
|
||||
// finalize here ritual here
|
||||
|
@ -102,8 +119,8 @@ namespace gui {
|
|||
if($craft_state.is_combined()) {
|
||||
// add it to the belt
|
||||
auto ritual = $engine.finalize($craft_state);
|
||||
// remove the items from the blanket now
|
||||
|
||||
// remove the items from the blanket now
|
||||
auto& the_belt = $level.world->get_the<ritual::Belt>();
|
||||
|
||||
the_belt.equip(the_belt.next(), ritual);
|
||||
|
@ -112,6 +129,7 @@ namespace gui {
|
|||
reset_inv_positions();
|
||||
} else {
|
||||
fmt::println("Failed to combine!");
|
||||
reset_inv_positions();
|
||||
sound::play("ui_click");
|
||||
}
|
||||
}
|
||||
|
@ -124,9 +142,8 @@ namespace gui {
|
|||
auto& blanket = $level.world->get_the<ritual::Blanket>();
|
||||
int i = 0;
|
||||
|
||||
blanket.contents.query<ritual::JunkItem>([&](const auto, auto& item) {
|
||||
std::string slot = fmt::format("inv_slot{}", i++);
|
||||
auto button = $gui.entity(slot);
|
||||
blanket.contents.query<ritual::JunkItem>([&](const auto item_id, auto& item) {
|
||||
auto button = $gui.entity("inv_slot", i++);
|
||||
std::string sprite_name = fmt::format("{}-64", item);
|
||||
|
||||
if($gui.has<Clickable>(button)) {
|
||||
|
@ -136,7 +153,7 @@ namespace gui {
|
|||
$gui.set<Effect>(button, {0.4f});
|
||||
$gui.set<Sound>(button, {"ui_click"});
|
||||
$gui.set<Clickable>(button, {
|
||||
[&](auto ent, auto){ inv_slot_clicked(ent); }
|
||||
[&, item_id](auto ent, auto){ inv_slot_clicked(ent, item_id); }
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -174,6 +191,9 @@ namespace gui {
|
|||
}
|
||||
|
||||
window.draw(*$ritual_ui.sprite);
|
||||
if($ritual_state == OPEN) $gui.render(window);
|
||||
if($ritual_state == OPEN) {
|
||||
$gui.render(window);
|
||||
// $gui.debug_layout(window);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,8 +35,9 @@ namespace gui {
|
|||
void update();
|
||||
|
||||
void update_items();
|
||||
void ritual_circle_clicked(DinkyECS::Entity ent);
|
||||
void inv_slot_clicked(DinkyECS::Entity ent);
|
||||
void reset_clicked(DinkyECS::Entity ent);
|
||||
void combine_clicked(DinkyECS::Entity ent);
|
||||
void inv_slot_clicked(DinkyECS::Entity ent, DinkyECS::Entity item_id);
|
||||
void reset_inv_positions();
|
||||
};
|
||||
}
|
||||
|
|
21
rituals.cpp
21
rituals.cpp
|
@ -35,6 +35,19 @@ namespace ritual {
|
|||
return $states.at(name);
|
||||
}
|
||||
|
||||
void Engine::load_junk(CraftingState& ritual, const JunkItem& item) {
|
||||
Config config("assets/rituals.json");
|
||||
auto& junk = config["junk"];
|
||||
auto& item_desc = junk[item];
|
||||
|
||||
fmt::print("Item {} provides: ", item);
|
||||
for(auto& effect : item_desc["provides"]) {
|
||||
fmt::print("{} ", (std::string)effect);
|
||||
set_state(ritual, effect, true);
|
||||
}
|
||||
fmt::print("\n");
|
||||
}
|
||||
|
||||
ai::Action Engine::load_action(std::string name) {
|
||||
return $actions.at(name);
|
||||
}
|
||||
|
@ -55,6 +68,8 @@ namespace ritual {
|
|||
|
||||
void CraftingState::reset() {
|
||||
start = original;
|
||||
plan.complete = false;
|
||||
plan.script.clear();
|
||||
}
|
||||
|
||||
void Engine::plan(CraftingState& ritual) {
|
||||
|
@ -79,9 +94,11 @@ namespace ritual {
|
|||
}
|
||||
|
||||
bool CraftingState::is_combined() {
|
||||
dbc::check(!plan.script.empty(), "you are attempting to check an empty plan");
|
||||
// it's only combined if it has > 1 and last is combined
|
||||
if(plan.script.size() <= 1) return false;
|
||||
|
||||
auto& last = plan.script.back();
|
||||
return plan.script.size() > 1 && last.name == "combined";
|
||||
return last.name == "combined";
|
||||
}
|
||||
|
||||
Action Engine::finalize(CraftingState& ritual) {
|
||||
|
|
13
rituals.hpp
13
rituals.hpp
|
@ -5,6 +5,12 @@
|
|||
#include "dinkyecs.hpp"
|
||||
|
||||
namespace ritual {
|
||||
using JunkItem = std::string;
|
||||
|
||||
struct JunkPile {
|
||||
std::vector<JunkItem> contents;
|
||||
};
|
||||
|
||||
enum class Element {
|
||||
NONE=0, FIRE=1, LIGHTNING=2
|
||||
};
|
||||
|
@ -59,6 +65,7 @@ namespace ritual {
|
|||
void set_state(CraftingState& ritual, std::string name, bool setting);
|
||||
void plan(CraftingState& ritual);
|
||||
Action finalize(CraftingState& ritual);
|
||||
void load_junk(CraftingState& ritual, const JunkItem& item);
|
||||
};
|
||||
|
||||
struct Belt {
|
||||
|
@ -73,12 +80,6 @@ namespace ritual {
|
|||
int next();
|
||||
};
|
||||
|
||||
using JunkItem = std::string;
|
||||
|
||||
struct JunkPile {
|
||||
std::vector<JunkItem> contents;
|
||||
};
|
||||
|
||||
struct Blanket {
|
||||
DinkyECS::World contents;
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "fsm.hpp"
|
||||
#include "dinkyecs.hpp"
|
||||
#include "levelmanager.hpp"
|
||||
#include "ai_debug.hpp"
|
||||
|
||||
TEST_CASE("ritual::Engine basic tests", "[rituals]") {
|
||||
ritual::Engine re("assets/rituals.json");
|
||||
|
@ -68,7 +69,7 @@ TEST_CASE("craft_state can be finalized for the end result", "[rituals]") {
|
|||
}
|
||||
|
||||
|
||||
TEST_CASE("the ritual belt works", "[rituals]") {
|
||||
TEST_CASE("the ritual belt works", "[rituals-belt]") {
|
||||
ritual::Belt the_belt;
|
||||
ritual::Engine re;
|
||||
auto craft_state = re.start();
|
||||
|
@ -93,6 +94,12 @@ TEST_CASE("the ritual belt works", "[rituals]") {
|
|||
the_belt.unequip(0);
|
||||
REQUIRE(!the_belt.has(0));
|
||||
}
|
||||
|
||||
craft_state.reset();
|
||||
REQUIRE(craft_state.plan.script.size() == 0);
|
||||
REQUIRE(!craft_state.plan.complete);
|
||||
REQUIRE(craft_state.start == craft_state.original);
|
||||
REQUIRE(!craft_state.is_combined());
|
||||
}
|
||||
|
||||
TEST_CASE("ritual blanket basic operations", "[rituals]") {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue