More cleanup then starting to sort out how to make systems extensible easily.
This commit is contained in:
parent
6a0c9e8d46
commit
cbff127b40
13 changed files with 106 additions and 769 deletions
|
|
@ -49,11 +49,7 @@ namespace gui {
|
|||
// BUG: maybe this is a function on main_ui?
|
||||
auto cell = $main_ui.overlay_cell("left");
|
||||
$debug_ui.init(cell);
|
||||
|
||||
$status_ui.init();
|
||||
$map_ui.init();
|
||||
$map_ui.log(L"Welcome to the game!");
|
||||
|
||||
run_systems();
|
||||
|
||||
state(State::IDLE);
|
||||
|
|
@ -154,14 +150,10 @@ namespace gui {
|
|||
$main_ui.plan_rotate(1, DEFAULT_ROTATE);
|
||||
state(State::ROTATING);
|
||||
break;
|
||||
case MAP_OPEN:
|
||||
$map_open = !$map_open;
|
||||
break;
|
||||
case ATTACK:
|
||||
state(State::ATTACKING);
|
||||
break;
|
||||
case COMBAT_START:
|
||||
$map_open = false;
|
||||
state(State::IN_COMBAT);
|
||||
break;
|
||||
case CLOSE:
|
||||
|
|
@ -362,10 +354,6 @@ namespace gui {
|
|||
if($loot_ui.active) $loot_ui.render($window);
|
||||
|
||||
if(in_state(State::LOOTING)) $dnd_loot.render();
|
||||
|
||||
if($map_open) {
|
||||
$map_ui.render($window, $main_ui.$compass_dir);
|
||||
}
|
||||
}
|
||||
|
||||
void FSM::update() {
|
||||
|
|
@ -409,18 +397,6 @@ namespace gui {
|
|||
switch(evt) {
|
||||
case eGUI::COMBAT: {
|
||||
auto &damage = std::any_cast<components::CombatResult&>(data);
|
||||
|
||||
if(damage.enemy_did > 0) {
|
||||
$map_ui.log($F(L"Enemy HIT YOU for {} damage!", damage.enemy_did));
|
||||
} else {
|
||||
$map_ui.log(L"Enemy MISSED YOU.");
|
||||
}
|
||||
|
||||
if(damage.player_did > 0) {
|
||||
$map_ui.log($F(L"You HIT enemy for {} damage!", damage.player_did));
|
||||
} else {
|
||||
$map_ui.log(L"You MISSED the enemy.");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case eGUI::COMBAT_START:
|
||||
|
|
@ -463,9 +439,6 @@ namespace gui {
|
|||
$loot_ui.update();
|
||||
event(Event::LOOT_OPEN);
|
||||
} break;
|
||||
case eGUI::HP_STATUS:
|
||||
System::player_status();
|
||||
break;
|
||||
case eGUI::ATTACK:
|
||||
event(Event::ATTACK, data);
|
||||
break;
|
||||
|
|
@ -483,7 +456,6 @@ namespace gui {
|
|||
case eGUI::NOOP: {
|
||||
if(data.type() == typeid(std::string)) {
|
||||
auto name = std::any_cast<std::string>(data);
|
||||
$map_ui.log($F(L"NOOP EVENT! {},{}", evt, entity));
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
#include "gui/main_ui.hpp"
|
||||
#include "gui/status_ui.hpp"
|
||||
#include "gui/loot_ui.hpp"
|
||||
#include "gui/map_view.hpp"
|
||||
#include "events.hpp"
|
||||
#include "gui/event_router.hpp"
|
||||
#include "gui/dnd_loot.hpp"
|
||||
|
|
@ -30,11 +29,9 @@ namespace gui {
|
|||
sf::RenderWindow $window;
|
||||
bool $draw_stats = false;
|
||||
bool autowalking = false;
|
||||
bool $map_open = false;
|
||||
DebugUI $debug_ui;
|
||||
MainUI $main_ui;
|
||||
StatusUI $status_ui{STATUS_UI_X, STATUS_UI_Y, STATUS_UI_WIDTH, STATUS_UI_HEIGHT};
|
||||
MapViewUI $map_ui;
|
||||
LootUI $loot_ui;
|
||||
gui::routing::Router $router;
|
||||
DNDLoot $dnd_loot;
|
||||
|
|
|
|||
|
|
@ -1,75 +0,0 @@
|
|||
#include "map_view.hpp"
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include "dbc.hpp"
|
||||
#include "game/components.hpp"
|
||||
#include "algos/rand.hpp"
|
||||
#include "game/systems.hpp"
|
||||
#include "algos/rand.hpp"
|
||||
#include <codecvt>
|
||||
#include <iostream>
|
||||
#include <fmt/xchar.h>
|
||||
#include <fstream>
|
||||
#include "graphics/palette.hpp"
|
||||
#include "game/level.hpp"
|
||||
|
||||
constexpr const int MAP_WIDTH=13;
|
||||
constexpr const int MAP_HEIGHT=13;
|
||||
|
||||
namespace gui {
|
||||
using namespace components;
|
||||
using namespace guecs;
|
||||
|
||||
MapViewUI::MapViewUI() :
|
||||
$map_render(std::make_shared<sf::RenderTexture>()),
|
||||
$map_sprite($map_render->getTexture()),
|
||||
$map_tiles(matrix::make(MAP_WIDTH, MAP_HEIGHT))
|
||||
{
|
||||
auto world = GameDB::current_world();
|
||||
auto player = GameDB::the_player();
|
||||
$player_display = world->get<Tile>(player).display;
|
||||
}
|
||||
|
||||
void MapViewUI::init() {
|
||||
$gui.position(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
$gui.layout("[log_view| *%(200)map_grid | _ ]");
|
||||
$gui.set<Background>($gui.MAIN, {$gui.$parser, palette::get("tiles/fg:wall_plain")});
|
||||
|
||||
$log_to = $gui.entity("log_view");
|
||||
$gui.set<Rectangle>($log_to, {10, THEME.DARK_MID, THEME.BORDER_COLOR, 10});
|
||||
$gui.set<Text>($log_to, {L"Welcome to the Game!", 25, THEME.TEXT_COLOR, 10});
|
||||
|
||||
auto map_cell = lel::center(MAP_TILE_DIM * MAP_WIDTH, MAP_TILE_DIM * MAP_HEIGHT, $gui.cell_for("map_grid"));
|
||||
$map_sprite.setPosition({(float)map_cell.x, (float)map_cell.y + 30});
|
||||
|
||||
$gui.init();
|
||||
}
|
||||
|
||||
void MapViewUI::render(sf::RenderWindow &window, int compass_dir) {
|
||||
$gui.render(window);
|
||||
System::draw_map($map_tiles, $entity_map);
|
||||
System::render_map($map_tiles, $entity_map, *$map_render, compass_dir, $player_display);
|
||||
$map_sprite.setTexture($map_render->getTexture(), true);
|
||||
window.draw($map_sprite);
|
||||
// $gui.debug_layout(window);
|
||||
}
|
||||
|
||||
void MapViewUI::update() {
|
||||
if(auto text = $gui.get_if<Text>($log_to)) {
|
||||
//BUG: I'm calling this what it is, fix it
|
||||
wstring log_garbage;
|
||||
for(auto msg : $messages) {
|
||||
log_garbage += msg + L"\n";
|
||||
}
|
||||
text->update(log_garbage);
|
||||
}
|
||||
}
|
||||
|
||||
void MapViewUI::log(wstring msg) {
|
||||
$messages.push_front(msg);
|
||||
if($messages.size() > MAX_LOG_MESSAGES) {
|
||||
$messages.pop_back();
|
||||
}
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
#pragma once
|
||||
#include "graphics/textures.hpp"
|
||||
#include "algos/matrix.hpp"
|
||||
#include <guecs/ui.hpp>
|
||||
#include <string>
|
||||
#include "algos/dinkyecs.hpp"
|
||||
#include "game/map.hpp"
|
||||
|
||||
namespace gui {
|
||||
class MapViewUI {
|
||||
public:
|
||||
guecs::UI $gui;
|
||||
wchar_t $player_display = L'@';
|
||||
DinkyECS::Entity $log_to;
|
||||
EntityGrid $entity_map;
|
||||
std::deque<std::wstring> $messages;
|
||||
std::shared_ptr<sf::RenderTexture> $map_render;
|
||||
sf::Sprite $map_sprite;
|
||||
matrix::Matrix $map_tiles;
|
||||
|
||||
MapViewUI();
|
||||
void init();
|
||||
void render(sf::RenderWindow &window, int compass_dir);
|
||||
void log(std::wstring msg);
|
||||
void update();
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue