- [NEW] Ficades les habitacions amb el nou format YAML

- [NEW] Afegit el fkYAML de una capçalera
- [NEW] El treeview ja funciona com deu mana
- [NEW] En el treeview ja funciona el scroll amb el mouse sheel
- [NEW] El treeview ja mostra les habitacions i els enemics (falten items)
This commit is contained in:
2025-11-18 13:13:07 +01:00
parent 22b62dd46b
commit f05dec21b1
186 changed files with 20401 additions and 6579 deletions

14726
source/fkYAML/node.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -4,15 +4,51 @@
#include "menu.h"
#include "toolbar.h"
#include "treeview.h"
#include "fkYAML/node.hpp"
#include <filesystem>
namespace fs = std::filesystem;
bool loop();
std::map<std::string, std::string> rooms;
fkyaml::node room;
std::string current_room = "";
void loadRoom(std::string room_file)
{
int filesize;
char *f = file::getFileBuffer(std::string("room/"+room_file+".yaml").c_str(), filesize, true);
room = fkyaml::node::deserialize(std::string(f));
current_room = room_file;
free(f);
//fkyaml::node name_node = room["room"]["name"];
//printf("%s\n", name_node.get_value<std::string>().c_str());
}
void game::init()
{
draw::init("DILEMMAKER v0.1", 800, 600);
game::setState(loop);
font::load("font/8bithud");
draw::cls(0x00000000);
std::vector<std::string> room_names;
for (const auto& entry : fs::directory_iterator("./data/room")) {
if (entry.is_regular_file() && entry.path().extension() == ".yaml") {
room_names.emplace_back(entry.path().stem());
}
}
std::sort(room_names.begin(), room_names.end(), [](const fs::path& a, const fs::path& b) {
return a.filename().string() < b.filename().string();
});
for (auto& entry : room_names) {
loadRoom(entry);
rooms[entry] = room["room"]["name"].get_value<std::string>();
}
}
bool loop()
@@ -42,17 +78,19 @@ bool loop()
toolbar::start();
treeview::start();
if (treeview::option("room01", 0)) {
treeview::option("abad", 1);
treeview::option("Jailer", 1);
}
if (treeview::option("room02", 0)) {
treeview::option("abad", 1);
treeview::option("Jailer", 1);
}
if (treeview::option("room03", 0)) {
treeview::option("abad", 1);
treeview::option("Jailer", 1);
for (auto p : rooms) {
const char *r = p.first.c_str();
//std::string room_label = r +
if (treeview::option(std::string(p.first + ": " + p.second).c_str(), 0)) {
if (current_room != r) {
loadRoom(r);
} else {
auto enemies = room.at("enemies").as_seq();
for (auto enemy : enemies) {
treeview::option(enemy["animation"].get_value<std::string>().c_str(), 1);
}
}
}
}
treeview::end();

View File

@@ -7,38 +7,66 @@ namespace treeview
{
int width = 200;
int scroll = 0;
int current = -1;
int selected = -1;
int current[2] = {-1, -1};
int selected[2] = {-1, -1};
int line = 0;
int element = 0;
int max_elements = 0;
void start()
{
draw::setClip(0,48,treeview::width, draw::getWindowSize().y-48);
draw::setColor(0xff181818);
draw::fillrect(0,48,treeview::width, draw::getWindowSize().y-48);
current = 0;
current[0] = current[1] = line = element = 0;
max_elements = (draw::getWindowSize().y-48) / 24;
int mx = input::mouseX();
int my = input::mouseY();
if (mx>=0 && my>=48 && mx<treeview::width && my<draw::getWindowSize().y) {
scroll -= input::mouseWheel();
if (scroll < 0) scroll = 0;
}
}
bool option(const char* label, const int level)
{
int mx = input::mouseX();
int my = input::mouseY();
const int opt_y = (48+current*24);
if (mx>=0 && my>=opt_y && mx<treeview::width && my<opt_y+24) {
if (input::mouseClk(input::mouse::button::left)) {
input::mouseDiscard();
selected = current;
if (element>=scroll && line<max_elements) {
int mx = input::mouseX();
int my = input::mouseY();
const int opt_y = (48+line*24);
if (mx>=0 && my>=opt_y && mx<treeview::width && my<opt_y+24) {
if (input::mouseClk(input::mouse::button::left)) {
input::mouseDiscard();
selected[level] = current[level];
if (level<1) selected[level+1] = -1;
}
draw::setColor(selected[level]==current[level] ? 0xff37373d : 0xff2a2d2e);
draw::fillrect(0, opt_y, treeview::width, 24);
} else if (selected[level] == current[level]) {
draw::setColor(0xff37373d);
draw::fillrect(0, opt_y, treeview::width, 24);
}
draw::setColor(selected==current ? 0xff37373d : 0xff2a2d2e);
draw::fillrect(0, opt_y, treeview::width, 24);
font::print(label, 8+16*level, opt_y+8);
line++;
}
font::print(label, 8+16*level, opt_y+8);
current++;
current[level]++;
element++;
return selected==current;
return selected[level]==current[level]-1;
}
void end()
{
draw::resetClip();
if (element>max_elements && line<max_elements) {
scroll -= max_elements-line;
}
}
const int getSelected(const int level)
{
return selected[level];
}
}

View File

@@ -5,4 +5,6 @@ namespace treeview
void start();
bool option(const char* label, const int level);
void end();
const int getSelected(const int level);
}