Cleaned up the gui display some more for future GUI elements.
This commit is contained in:
parent
2ced72a475
commit
7b5c84b5f7
5 changed files with 58 additions and 34 deletions
31
gui.cpp
31
gui.cpp
|
@ -33,11 +33,11 @@ GUI::GUI(DinkyECS::World &world, Map& game_map) :
|
||||||
$game_map(game_map),
|
$game_map(game_map),
|
||||||
$log({{"Welcome to the game!"}}),
|
$log({{"Welcome to the game!"}}),
|
||||||
$view_port{0,0},
|
$view_port{0,0},
|
||||||
$screen(SCREEN_X, SCREEN_Y),
|
$status_screen(SCREEN_X, SCREEN_Y),
|
||||||
$map_screen(0,0),
|
$map_screen(0,0),
|
||||||
$world(world),
|
$world(world),
|
||||||
$sounds("./assets"),
|
$sounds("./assets"),
|
||||||
$renderer($canvas, $map_screen, $screen)
|
$renderer()
|
||||||
{
|
{
|
||||||
// this needs a config file soon
|
// this needs a config file soon
|
||||||
// $sounds.load("ambient", "ambient_sound.mp3");
|
// $sounds.load("ambient", "ambient_sound.mp3");
|
||||||
|
@ -70,7 +70,12 @@ void GUI::create_renderer() {
|
||||||
return canvas($canvas);
|
return canvas($canvas);
|
||||||
});
|
});
|
||||||
|
|
||||||
$document = Renderer([&, player]{
|
$prompt = Renderer([&] {
|
||||||
|
return hbox({hflow(vbox(text("HELLO!")))}) | border;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$status_ui = Renderer([&, player]{
|
||||||
const auto& player_combat = $world.get<Combat>(player.entity);
|
const auto& player_combat = $world.get<Combat>(player.entity);
|
||||||
const auto& inventory = $world.get<Inventory>(player.entity);
|
const auto& inventory = $world.get<Inventory>(player.entity);
|
||||||
$status_text = player_combat.hp > 0 ? "NOT DEAD" : "DEAD!!!!!!";
|
$status_text = player_combat.hp > 0 ? "NOT DEAD" : "DEAD!!!!!!";
|
||||||
|
@ -192,17 +197,29 @@ void GUI::shake() {
|
||||||
int x = Random::uniform<int>(-10,10);
|
int x = Random::uniform<int>(-10,10);
|
||||||
int y = Random::uniform<int>(-10,10);
|
int y = Random::uniform<int>(-10,10);
|
||||||
// add x/y back to draw screen
|
// add x/y back to draw screen
|
||||||
$renderer.draw_screen(true, x, y);
|
$renderer.draw_screen($map_screen, x, y);
|
||||||
std::this_thread::sleep_for(1ms);
|
std::this_thread::sleep_for(1ms);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::render_scene() {
|
void GUI::render_scene() {
|
||||||
$screen.Clear();
|
$renderer.clear();
|
||||||
|
|
||||||
|
$status_screen.Clear();
|
||||||
|
Render($status_screen, $status_ui->Render());
|
||||||
|
$renderer.draw_text_ui($status_screen, 0, 0);
|
||||||
|
|
||||||
$map_screen.Clear();
|
$map_screen.Clear();
|
||||||
Render($map_screen, $map_view->Render());
|
Render($map_screen, $map_view->Render());
|
||||||
Render($screen, $document->Render());
|
$renderer.draw_screen($map_screen);
|
||||||
$renderer.draw_screen();
|
|
||||||
|
/*
|
||||||
|
Screen prompt_screen(30,10);
|
||||||
|
Render(prompt_screen, $prompt->Render());
|
||||||
|
$renderer.draw_text_ui(prompt_screen, 700, 300);
|
||||||
|
*/
|
||||||
|
|
||||||
|
$renderer.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
int GUI::main() {
|
int GUI::main() {
|
||||||
|
|
5
gui.hpp
5
gui.hpp
|
@ -35,12 +35,13 @@ struct ActionLog {
|
||||||
class GUI {
|
class GUI {
|
||||||
string $status_text = "NOT DEAD";
|
string $status_text = "NOT DEAD";
|
||||||
Canvas $canvas;
|
Canvas $canvas;
|
||||||
Component $document;
|
Component $status_ui;
|
||||||
|
Component $prompt;
|
||||||
Component $map_view;
|
Component $map_view;
|
||||||
Map& $game_map;
|
Map& $game_map;
|
||||||
ActionLog $log;
|
ActionLog $log;
|
||||||
Point $view_port;
|
Point $view_port;
|
||||||
Screen $screen;
|
Screen $status_screen;
|
||||||
Screen $map_screen;
|
Screen $map_screen;
|
||||||
DinkyECS::World& $world;
|
DinkyECS::World& $world;
|
||||||
SoundManager $sounds;
|
SoundManager $sounds;
|
||||||
|
|
41
render.cpp
41
render.cpp
|
@ -28,13 +28,10 @@ sf::Color SFMLRender::color(Value val) {
|
||||||
return VALUES[size_t(val)];
|
return VALUES[size_t(val)];
|
||||||
}
|
}
|
||||||
|
|
||||||
SFMLRender::SFMLRender(Canvas &canvas, Screen &map_screen, Screen &screen) :
|
SFMLRender::SFMLRender() :
|
||||||
$window(sf::VideoMode(VIDEO_X,VIDEO_Y), "Roguish"),
|
$window(sf::VideoMode(VIDEO_X,VIDEO_Y), "Roguish"),
|
||||||
$map_font_size(0),
|
$map_font_size(0),
|
||||||
$line_spacing(0),
|
$line_spacing(0),
|
||||||
$canvas(canvas),
|
|
||||||
$map_screen(map_screen),
|
|
||||||
$screen(screen),
|
|
||||||
$default_fg(color(Value::LIGHT_MID)),
|
$default_fg(color(Value::LIGHT_MID)),
|
||||||
$default_bg(color(Value::BLACK)),
|
$default_bg(color(Value::BLACK)),
|
||||||
$ansi($default_fg, $default_bg)
|
$ansi($default_fg, $default_bg)
|
||||||
|
@ -44,7 +41,9 @@ SFMLRender::SFMLRender(Canvas &canvas, Screen &map_screen, Screen &screen) :
|
||||||
$ui_text.setFont($font);
|
$ui_text.setFont($font);
|
||||||
$ui_text.setPosition(0,0);
|
$ui_text.setPosition(0,0);
|
||||||
$ui_text.setCharacterSize(UI_FONT_SIZE);
|
$ui_text.setCharacterSize(UI_FONT_SIZE);
|
||||||
$ui_text.setFillColor(color(Value::LIGHT_LIGHT));
|
$ui_text.setFillColor(color(Value::LIGHT_MID));
|
||||||
|
sf::Glyph glyph = $font.getGlyph(L'H', UI_FONT_SIZE, false);
|
||||||
|
$ui_bounds = glyph.bounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
sf::Sprite &SFMLRender::get_text_sprite(wchar_t tile) {
|
sf::Sprite &SFMLRender::get_text_sprite(wchar_t tile) {
|
||||||
|
@ -96,13 +95,6 @@ bool SFMLRender::resize_map(int new_size, Point &view_port) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SFMLRender::draw_main_ui() {
|
|
||||||
std::string screenout = $screen.ToString();
|
|
||||||
std::wstring main_screen_utf8 = $converter.from_bytes(screenout);
|
|
||||||
$ui_text.setString(main_screen_utf8);
|
|
||||||
$window.draw($ui_text);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void configure_tile(const sf::Sprite &sprite, sf::FloatRect &sp_bounds, sf::FloatRect bg_bounds, float &width_delta, float &height_delta) {
|
inline void configure_tile(const sf::Sprite &sprite, sf::FloatRect &sp_bounds, sf::FloatRect bg_bounds, float &width_delta, float &height_delta) {
|
||||||
// should look into caching all this instead of calcing it each time
|
// should look into caching all this instead of calcing it each time
|
||||||
sp_bounds = sprite.getLocalBounds();
|
sp_bounds = sprite.getLocalBounds();
|
||||||
|
@ -149,11 +141,24 @@ void SFMLRender::render_text(std::string &text, float x, float y) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void SFMLRender::draw_screen(bool clear, float map_off_x, float map_off_y) {
|
void SFMLRender::draw_text_ui(Screen &screen, float x, float y) {
|
||||||
if(clear) $window.clear();
|
sf::RectangleShape backing(
|
||||||
draw_main_ui();
|
sf::Vector2f($ui_bounds.width * screen.dimx() * 1.4,
|
||||||
|
$ui_bounds.height * screen.dimy() * 1.6));
|
||||||
|
|
||||||
std::string map_screenout = $map_screen.ToString();
|
backing.setFillColor(sf::Color(0, 0, 0));
|
||||||
render_text(map_screenout, GAME_MAP_POS+map_off_x, map_off_y);
|
backing.setPosition(x, y);
|
||||||
$window.display();
|
$window.draw(backing);
|
||||||
|
|
||||||
|
std::string screenout = screen.ToString();
|
||||||
|
std::wstring main_screen_utf8 = $converter.from_bytes(screenout);
|
||||||
|
|
||||||
|
$ui_text.setPosition(x, y);
|
||||||
|
$ui_text.setString(main_screen_utf8);
|
||||||
|
$window.draw($ui_text);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SFMLRender::draw_screen(Screen &screen, float x, float y) {
|
||||||
|
std::string screenout = screen.ToString();
|
||||||
|
render_text(screenout, GAME_MAP_POS+x, y);
|
||||||
}
|
}
|
||||||
|
|
13
render.hpp
13
render.hpp
|
@ -38,16 +38,14 @@ struct SFMLRender {
|
||||||
sf::Glyph $base_glyph;
|
sf::Glyph $base_glyph;
|
||||||
sf::Sprite $bg_sprite;
|
sf::Sprite $bg_sprite;
|
||||||
sf::FloatRect $bg_bounds;
|
sf::FloatRect $bg_bounds;
|
||||||
Canvas& $canvas;
|
|
||||||
Screen& $map_screen;
|
|
||||||
Screen& $screen;
|
|
||||||
sf::Text $ui_text;
|
sf::Text $ui_text;
|
||||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
|
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
|
||||||
sf::Color $default_fg;
|
sf::Color $default_fg;
|
||||||
sf::Color $default_bg;
|
sf::Color $default_bg;
|
||||||
ANSIParser $ansi;
|
ANSIParser $ansi;
|
||||||
|
sf::FloatRect $ui_bounds;
|
||||||
|
|
||||||
SFMLRender(Canvas &canvas, Screen &map_screen, Screen &screen);
|
SFMLRender();
|
||||||
|
|
||||||
// disable copy
|
// disable copy
|
||||||
SFMLRender(SFMLRender &other) = delete;
|
SFMLRender(SFMLRender &other) = delete;
|
||||||
|
@ -57,8 +55,8 @@ struct SFMLRender {
|
||||||
sf::Sprite &get_text_sprite(wchar_t tile);
|
sf::Sprite &get_text_sprite(wchar_t tile);
|
||||||
bool resize_map(int new_size, Point &view_port);
|
bool resize_map(int new_size, Point &view_port);
|
||||||
void render_text(std::string &text, float x, float y);
|
void render_text(std::string &text, float x, float y);
|
||||||
void draw_main_ui();
|
void draw_text_ui(Screen &screen, float x, float y);
|
||||||
void draw_screen(bool clear=true, float map_off_x=0.0f, float map_off_y=0.0f);
|
void draw_screen(Screen &screen, float map_off_x=0.0f, float map_off_y=0.0f);
|
||||||
|
|
||||||
bool poll_event(sf::Event &event) {
|
bool poll_event(sf::Event &event) {
|
||||||
return $window.pollEvent(event);
|
return $window.pollEvent(event);
|
||||||
|
@ -69,5 +67,6 @@ struct SFMLRender {
|
||||||
bool is_open() { return $window.isOpen(); }
|
bool is_open() { return $window.isOpen(); }
|
||||||
|
|
||||||
int font_size() { return $map_font_size; }
|
int font_size() { return $map_font_size; }
|
||||||
|
void clear() { $window.clear(); }
|
||||||
|
void display() { $window.display(); }
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,3 +16,5 @@ TODO:
|
||||||
* Lua integration?
|
* Lua integration?
|
||||||
|
|
||||||
* check out SoLoud.
|
* check out SoLoud.
|
||||||
|
|
||||||
|
* BUG: When enemies die they can be overlapping another enemy.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue