Now have a full map and a mini map, but I think the mini map will stop rendering sometimes.

master
Zed A. Shaw 1 week ago
parent 193d97eb48
commit 322797f787
  1. 3
      assets/config.json
  2. BIN
      assets/full_screen_paper.png
  3. 13
      guecs.cpp
  4. 1
      guecs.hpp
  5. 23
      gui_fsm.cpp
  6. 5
      gui_fsm.hpp
  7. 1
      main_ui.cpp
  8. 26
      map_view.cpp
  9. 4
      map_view.hpp
  10. 1
      meson.build
  11. 39
      mini_map.cpp
  12. 20
      mini_map.hpp
  13. 3
      overlay_ui.cpp
  14. 14
      status_ui.cpp
  15. 3
      status_ui.hpp

@ -54,7 +54,8 @@
"tunnel_with_rocks_stage": "assets/tunnel_with_rocks_stage.png",
"ritual_crafting_area": "assets/ritual_crafting_area.png",
"the_ritual_circle": "assets/the_ritual_circle.png",
"paper_ui_background": "assets/paper_ui_background.png"
"paper_ui_background": "assets/paper_ui_background.png",
"full_screen_paper": "assets/full_screen_paper.png"
},
"worldgen": {
"enemy_probability": 50,

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

@ -40,6 +40,7 @@ namespace guecs {
bg.init();
}
$world.query<Background>([](auto, auto& bg) {
bg.init();
});
@ -75,7 +76,17 @@ namespace guecs {
$world.query<lel::Cell, Sprite>([&](auto, auto &cell, auto &sprite) {
sprite.init(cell);
});
}
void UI::debug_layout(sf::RenderWindow& window) {
$world.query<lel::Cell>([&](const auto, auto &cell) {
sf::RectangleShape rect{{float(cell.w), float(cell.h)}};
rect.setPosition({float(cell.x), float(cell.y)});
rect.setFillColor(sf::Color::Transparent);
rect.setOutlineColor(sf::Color::Red);
rect.setOutlineThickness(2.0f);
window.draw(rect);
});
}
void UI::render(sf::RenderWindow& window) {
@ -114,6 +125,8 @@ namespace guecs {
$world.query<Textual>([&](auto, auto& text) {
window.draw(*text.text);
});
}
bool UI::mouse(float x, float y) {

@ -212,6 +212,7 @@ namespace guecs {
void init();
void render(sf::RenderWindow& window);
bool mouse(float x, float y);
void debug_layout(sf::RenderWindow& window);
template <typename Comp>
void set(DinkyECS::Entity ent, Comp val) {

@ -18,6 +18,8 @@ namespace gui {
$level($levels.current()),
$combat_ui($level),
$status_ui($level),
$map_ui($level),
$mini_map($level),
$font{FONT_FILE_NAME}
{
}
@ -42,12 +44,15 @@ namespace gui {
$main_ui.init();
$combat_ui.init();
$status_ui.init();
$status_ui.log("Welcome to the game!");
$status_ui.update();
$boss_fight_ui = $levels.create_bossfight($level.world);
$boss_fight_ui->init();
$map_ui.init();
$mini_map.init($main_ui.$overlay_ui.$gui);
run_systems();
state(State::IDLE);
}
@ -126,13 +131,13 @@ namespace gui {
state(State::ROTATING);
break;
case MAP_OPEN:
$status_ui.map_open = !$status_ui.map_open;
$map_open = !$map_open;
break;
case ATTACK:
state(State::ATTACKING);
break;
case START_COMBAT:
$main_ui.$overlay_ui.show_sprite("top_right", "cinqueda");
$map_open = false;
state(State::IN_COMBAT);
break;
case CLOSE:
@ -291,10 +296,13 @@ namespace gui {
$boss_fight_ui->render($window);
} else {
$main_ui.render();
$status_ui.render($window);
$combat_ui.render($window);
if($map_open) {
$map_ui.render($window);
} else {
$mini_map.render($window);
}
}
}
@ -359,7 +367,6 @@ namespace gui {
// $status_ui.log(fmt::format("You picked up a {}.",
// std::string(item.data["name"])));
$status_ui.log("You picked up an item.");
$status_ui.update();
} break;
case eGUI::ATTACK:
event(Event::ATTACK);
@ -378,11 +385,9 @@ namespace gui {
auto name = std::any_cast<std::string>(data);
$status_ui.log(fmt::format("NOOP EVENT! {},{} name={}", evt, entity, name));
}
$status_ui.update();
} break;
default:
$status_ui.log(fmt::format("INVALID EVENT! {},{}", evt, entity));
$status_ui.update();
}
}
}
@ -392,8 +397,10 @@ namespace gui {
$level = $levels.next();
$status_ui.update_level($level);
$map_ui.update_level($level);
$combat_ui.update_level($level);
$main_ui.update_level($level);
$boss_fight_ui = $levels.create_bossfight($level.world);
$boss_fight_ui->init();

@ -7,6 +7,8 @@
#include "combat_ui.hpp"
#include "status_ui.hpp"
#include "boss_fight_ui.hpp"
#include "map_view.hpp"
#include "mini_map.hpp"
namespace gui {
enum class State {
@ -44,12 +46,15 @@ namespace gui {
sf::RenderWindow $window;
bool $draw_stats = false;
bool autowalking = false;
bool $map_open = false;
LevelManager $levels;
MainUI $main_ui;
GameLevel $level;
shared_ptr<BossFightUI> $boss_fight_ui = nullptr;
CombatUI $combat_ui;
StatusUI $status_ui;
MapViewUI $map_ui;
MiniMapUI $mini_map;
sf::Font $font;
FSM();

@ -61,6 +61,7 @@ namespace gui {
void MainUI::draw_blood() {
auto player = $level.world->get_the<Player>();
auto player_combat = $level.world->get<Combat>(player.entity);
if(float(player_combat.hp) / float(player_combat.max_hp) < 0.5) {
$overlay_ui.show_sprite("middle", "blood_splatter");
} else {

@ -15,8 +15,7 @@ namespace gui {
MapViewUI::MapViewUI(GameLevel &level) :
$level(level),
$tiles(level.map->width(),
level.map->height())
$paper(textures::get("full_screen_paper"))
{
}
@ -24,28 +23,37 @@ namespace gui {
$level = level;
}
void MapViewUI::init(int x, int y, int w, int h) {
$gui.position(x, y, w, h);
$gui.layout("[map_grid]");
void MapViewUI::init() {
//auto top_right = overlay.entity("top_right");
//auto cell = overlay.cell_for(top_right);
$gui.position(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
$gui.layout(
"[status| *%(200)map_grid | _ ]"
);
auto grid = $gui.entity("map_grid");
$gui.set<guecs::WideText>(grid,
{L"Loading...", 45, ColorValue::DARK_LIGHT, 10});
{L"Loading...", 65, {27, 26, 23, 150}, 10});
$gui.set<guecs::Sprite>(grid, {"paper_ui_background"});
auto status = $gui.entity("status");
$gui.set<guecs::Textual>(status,
{"Loading...", 25, {37, 36, 33}, 25});
$paper.sprite->setPosition({0, 0});
$gui.init();
}
void MapViewUI::render(sf::RenderWindow &window) {
$tiles = $level.map->tiles();
window.draw(*$paper.sprite);
auto grid = $gui.entity("map_grid");
std::wstring map_out = System::draw_map($level, 13, 6);
std::wstring map_out = System::draw_map($level, 23, 9);
auto& map_text = $gui.get<guecs::WideText>(grid);
map_text.update(map_out);
$gui.render(window);
// $gui.debug_layout(window);
}
}

@ -9,10 +9,10 @@ namespace gui {
public:
guecs::UI $gui;
GameLevel $level;
TileMap $tiles;
textures::SpriteTexture $paper;
MapViewUI(GameLevel &level);
void init(int x, int y, int w, int h);
void init();
void render(sf::RenderWindow &window);
void update_level(GameLevel &level);
};

@ -102,6 +102,7 @@ sources = [
'main_ui.cpp',
'map.cpp',
'map_view.cpp',
'mini_map.cpp',
'matrix.cpp',
'matrix.cpp',
'overlay_ui.cpp',

@ -0,0 +1,39 @@
#include "mini_map.hpp"
#include <functional>
#include <string>
#include "dbc.hpp"
#include "components.hpp"
#include "rand.hpp"
#include "animation.hpp"
#include "systems.hpp"
#include "rand.hpp"
#include <codecvt>
#include <iostream>
#include <memory>
namespace gui {
using namespace components;
MiniMapUI::MiniMapUI(GameLevel &level) :
$map_grid{L"...", 45, {200, 200, 200, 100}, 10},
$level(level)
{
$font = std::make_shared<sf::Font>(FONT_FILE_NAME);
}
void MiniMapUI::update_level(GameLevel &level) {
$level = level;
}
void MiniMapUI::init(guecs::UI& overlay) {
auto top_right = overlay.entity("top_right");
auto cell = overlay.cell_for(top_right);
$map_grid.init(cell, $font);
}
void MiniMapUI::render(sf::RenderWindow &window) {
std::wstring map_out = System::draw_map($level, 5, 3);
$map_grid.update(map_out);
window.draw(*$map_grid.text);
}
}

@ -0,0 +1,20 @@
#pragma once
#include "levelmanager.hpp"
#include "textures.hpp"
#include "guecs.hpp"
#include "tilemap.hpp"
namespace gui {
class MiniMapUI {
public:
guecs::WideText $map_grid;
guecs::UI $gui;
GameLevel $level;
shared_ptr<sf::Font> $font = nullptr;
MiniMapUI(GameLevel &level);
void init(guecs::UI& overlay);
void render(sf::RenderWindow &window);
void update_level(GameLevel &level);
};
}

@ -11,7 +11,7 @@ namespace gui {
OverlayUI::OverlayUI() {
$gui.position(RAY_VIEW_X, RAY_VIEW_Y, RAY_VIEW_WIDTH, RAY_VIEW_HEIGHT);
$gui.layout(
"[top_left|top|top_right]"
"[top_left|top|>(170)top_right]"
"[*%(300,300)middle|_|_]"
"[_|_|_]"
"[_|_|_]"
@ -25,6 +25,7 @@ namespace gui {
void OverlayUI::render(sf::RenderWindow& window) {
$gui.render(window);
// $gui.debug_layout(window);
}
void OverlayUI::show_sprite(string region, string sprite_name) {

@ -10,8 +10,7 @@ namespace gui {
using std::any, std::any_cast, std::string, std::make_any;
StatusUI::StatusUI(GameLevel level) :
$level(level), $ritual_ui(level),
$map_ui($level)
$level(level), $ritual_ui(level)
{
$gui.position(STATUS_UI_X, STATUS_UI_Y, STATUS_UI_WIDTH, STATUS_UI_HEIGHT);
$gui.layout(
@ -38,8 +37,6 @@ namespace gui {
$log_to = $gui.entity("log_view");
$gui.set<Rectangle>($log_to, {});
$gui.set<Textual>($log_to, {"Welcome to the Game!", 20});
$map_ui.init(cell.x, cell.y, cell.w, cell.h);
} else {
auto button = $gui.entity(name);
$gui.set<Rectangle>(button, {});
@ -92,8 +89,6 @@ namespace gui {
} else {
log(fmt::format("You are out of {}.", name));
}
update();
}
}
}
@ -137,11 +132,6 @@ namespace gui {
void StatusUI::render(sf::RenderWindow &window) {
$gui.render(window);
if(map_open) {
$map_ui.render(window);
}
$ritual_ui.render(window);
}
@ -150,11 +140,11 @@ namespace gui {
if($messages.size() > MAX_LOG_MESSAGES) {
$messages.pop_back();
}
update();
}
void StatusUI::update_level(GameLevel &level) {
$level = level;
$map_ui.update_level($level);
init();
}
}

@ -5,19 +5,16 @@
#include "textures.hpp"
#include "guecs.hpp"
#include "ritual_ui.hpp"
#include "map_view.hpp"
namespace gui {
class StatusUI {
public:
bool map_open = false;
guecs::UI $gui;
DinkyECS::Entity $log_to;
std::map<std::string, size_t> $slots;
std::deque<std::string> $messages;
GameLevel $level;
RitualUI $ritual_ui;
MapViewUI $map_ui;
StatusUI(GameLevel level);
void select_slot(DinkyECS::Entity ent, std::any data);

Loading…
Cancel
Save