Renderer now knows how to render panels as grid/text based on how the panel is configured.
This commit is contained in:
parent
f79e7638c0
commit
7cb03594a3
5 changed files with 30 additions and 31 deletions
8
gui.cpp
8
gui.cpp
|
@ -33,7 +33,7 @@ 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!"}}),
|
||||||
$status_ui(SCREEN_X, SCREEN_Y, 0, 0),
|
$status_ui(SCREEN_X, SCREEN_Y, 0, 0),
|
||||||
$map_view(0, 0, GAME_MAP_POS, 0, false),
|
$map_view(0, 0, GAME_MAP_POS, 0, true),
|
||||||
$view_port{0,0},
|
$view_port{0,0},
|
||||||
$world(world),
|
$world(world),
|
||||||
$sounds("./assets"),
|
$sounds("./assets"),
|
||||||
|
@ -231,7 +231,7 @@ void GUI::shake() {
|
||||||
int x = Random::uniform<int>(-20,20);
|
int x = Random::uniform<int>(-20,20);
|
||||||
int y = Random::uniform<int>(-20,20);
|
int y = Random::uniform<int>(-20,20);
|
||||||
// add x/y back to draw screen
|
// add x/y back to draw screen
|
||||||
$renderer.draw_grid($map_view, x, y);
|
$renderer.draw($map_view, x, y);
|
||||||
$renderer.display();
|
$renderer.display();
|
||||||
std::this_thread::sleep_for(1ms);
|
std::this_thread::sleep_for(1ms);
|
||||||
}
|
}
|
||||||
|
@ -240,8 +240,8 @@ void GUI::shake() {
|
||||||
void GUI::render_scene() {
|
void GUI::render_scene() {
|
||||||
$renderer.clear();
|
$renderer.clear();
|
||||||
|
|
||||||
$renderer.draw_text($status_ui);
|
$renderer.draw($status_ui);
|
||||||
$renderer.draw_grid($map_view);
|
$renderer.draw($map_view);
|
||||||
|
|
||||||
$renderer.display();
|
$renderer.display();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ struct Panel {
|
||||||
int height;
|
int height;
|
||||||
bool has_border = false;
|
bool has_border = false;
|
||||||
bool must_clear = true;
|
bool must_clear = true;
|
||||||
|
bool grid = false;
|
||||||
sf::Color default_bg = sf::Color(0,0,0);
|
sf::Color default_bg = sf::Color(0,0,0);
|
||||||
sf::Color border_color = sf::Color::Red;
|
sf::Color border_color = sf::Color::Red;
|
||||||
int border_px = UI_PANEL_BORDER_PX;
|
int border_px = UI_PANEL_BORDER_PX;
|
||||||
|
@ -31,14 +32,15 @@ struct Panel {
|
||||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
|
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
|
||||||
std::wstring $screenout;
|
std::wstring $screenout;
|
||||||
|
|
||||||
Panel(int width, int height, int x, int y, bool must_clear=true) :
|
Panel(int width, int height, int x, int y, bool is_grid=false) :
|
||||||
x(x),
|
x(x),
|
||||||
y(y),
|
y(y),
|
||||||
width(width),
|
width(width),
|
||||||
height(height),
|
height(height),
|
||||||
must_clear(must_clear),
|
grid(is_grid),
|
||||||
$screen(Screen(width, height))
|
$screen(Screen(width, height))
|
||||||
{
|
{
|
||||||
|
must_clear = !is_grid;
|
||||||
};
|
};
|
||||||
|
|
||||||
void resize(int width, int height);
|
void resize(int width, int height);
|
||||||
|
|
22
render.cpp
22
render.cpp
|
@ -180,7 +180,7 @@ void SFMLRender::render_text(const std::wstring &text, float start_x, float star
|
||||||
$ui_text.setFillColor($default_fg);
|
$ui_text.setFillColor($default_fg);
|
||||||
|
|
||||||
$ansi.parse(text,
|
$ansi.parse(text,
|
||||||
[&](sf::Color fg, sf::Color bg){
|
[&](sf::Color fg, sf::Color bg) {
|
||||||
if(out.size() > 0 ) {
|
if(out.size() > 0 ) {
|
||||||
auto bounds = draw_chunk($window, $ui_bounds, $ui_text, bgcolor, x, y, out);
|
auto bounds = draw_chunk($window, $ui_bounds, $ui_text, bgcolor, x, y, out);
|
||||||
x += bounds.width;
|
x += bounds.width;
|
||||||
|
@ -216,7 +216,13 @@ void SFMLRender::render_text(const std::wstring &text, float start_x, float star
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SFMLRender::draw_text(Panel &panel) {
|
void SFMLRender::draw(Panel &panel, float x_offset, float y_offset) {
|
||||||
|
panel.render();
|
||||||
|
const std::wstring &panelout = panel.to_string();
|
||||||
|
|
||||||
|
if(panel.grid) {
|
||||||
|
render_grid(panelout, panel.x + x_offset, panel.y + y_offset);
|
||||||
|
} else {
|
||||||
sf::RectangleShape backing(
|
sf::RectangleShape backing(
|
||||||
sf::Vector2f($ui_bounds.width * panel.width + panel.border_px,
|
sf::Vector2f($ui_bounds.width * panel.width + panel.border_px,
|
||||||
$ui_bounds.height * panel.height + panel.border_px));
|
$ui_bounds.height * panel.height + panel.border_px));
|
||||||
|
@ -228,16 +234,8 @@ void SFMLRender::draw_text(Panel &panel) {
|
||||||
backing.setOutlineThickness(panel.border_px);
|
backing.setOutlineThickness(panel.border_px);
|
||||||
}
|
}
|
||||||
|
|
||||||
backing.setPosition(panel.x, panel.y);
|
backing.setPosition(panel.x + x_offset, panel.y + y_offset);
|
||||||
$window.draw(backing);
|
$window.draw(backing);
|
||||||
|
|
||||||
panel.render();
|
|
||||||
const std::wstring &panelout = panel.to_string();
|
|
||||||
render_text(panelout, panel.x, panel.y);
|
render_text(panelout, panel.x, panel.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SFMLRender::draw_grid(Panel &panel, float x, float y) {
|
|
||||||
panel.render();
|
|
||||||
const std::wstring &panelout = panel.to_string();
|
|
||||||
render_grid(panelout, panel.x + x, panel.y + y);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,8 +58,8 @@ struct SFMLRender {
|
||||||
bool resize_map(int new_size, Point &view_port);
|
bool resize_map(int new_size, Point &view_port);
|
||||||
void render_grid(const std::wstring &text, float x, float y);
|
void render_grid(const std::wstring &text, float x, float y);
|
||||||
void render_text(const std::wstring &text, float x, float y);
|
void render_text(const std::wstring &text, float x, float y);
|
||||||
void draw_text(Panel &panel);
|
|
||||||
void draw_grid(Panel &panel, float map_off_x=0.0f, float map_off_y=0.0f);
|
void draw(Panel &panel, float x_offset=0.0f, float y_offset=0.0f);
|
||||||
|
|
||||||
bool poll_event(sf::Event &event) {
|
bool poll_event(sf::Event &event) {
|
||||||
return $window.pollEvent(event);
|
return $window.pollEvent(event);
|
||||||
|
|
|
@ -2,7 +2,6 @@ TODAY'S GOAL:
|
||||||
|
|
||||||
* Clean up renderer.
|
* Clean up renderer.
|
||||||
* panels and everything except renderer should use character coodinates
|
* panels and everything except renderer should use character coodinates
|
||||||
* panels should know if they're text vs. grid rendered
|
|
||||||
* Image -> Text converter.
|
* Image -> Text converter.
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue