Figured out the easiest way to set a panel to be centered, but a lot of these config things need to be unified and cleaned up.
This commit is contained in:
parent
269af02993
commit
fc61ef42ac
6 changed files with 48 additions and 33 deletions
|
@ -3,35 +3,37 @@
|
|||
/*
|
||||
* Eventually move most of these into runtime locations.
|
||||
*/
|
||||
const int INV_WALL = 0;
|
||||
const int INV_SPACE = 1;
|
||||
const int WALL_VALUE = 1;
|
||||
const int SPACE_VALUE = 0;
|
||||
const int WALL_PATH_LIMIT = 1000;
|
||||
const int WALL_LIGHT_LEVEL = 3;
|
||||
const int WORLDBUILD_DIVISION = 4;
|
||||
const int WORLDBUILD_SHRINK = 2;
|
||||
const int WORLDBUILD_MAX_PATH = 200;
|
||||
const int VIDEO_WINDOW_X=1600;
|
||||
const int VIDEO_WINDOW_Y=900;
|
||||
const int UI_FONT_SIZE=30;
|
||||
const int BASE_MAP_FONT_SIZE=90;
|
||||
const int GAME_MAP_PIXEL_POS = 600;
|
||||
const int MAX_FONT_SIZE = 140;
|
||||
const int MIN_FONT_SIZE = 20;
|
||||
const int STATUS_UI_WIDTH = 40;
|
||||
const int STATUS_UI_HEIGHT = 30;
|
||||
const float PERCENT = 0.01f;
|
||||
const wchar_t BG_TILE = L'█';
|
||||
const wchar_t UI_BASE_CHAR = L'█';
|
||||
const int BG_BOX_OFFSET=5;
|
||||
constexpr int INV_WALL = 0;
|
||||
constexpr int INV_SPACE = 1;
|
||||
constexpr int WALL_VALUE = 1;
|
||||
constexpr int SPACE_VALUE = 0;
|
||||
constexpr int WALL_PATH_LIMIT = 1000;
|
||||
constexpr int WALL_LIGHT_LEVEL = 3;
|
||||
constexpr int WORLDBUILD_DIVISION = 4;
|
||||
constexpr int WORLDBUILD_SHRINK = 2;
|
||||
constexpr int WORLDBUILD_MAX_PATH = 200;
|
||||
constexpr int VIDEO_WINDOW_X=1600;
|
||||
constexpr int VIDEO_WINDOW_Y=900;
|
||||
constexpr int UI_FONT_SIZE=30;
|
||||
constexpr int BASE_MAP_FONT_SIZE=90;
|
||||
constexpr int GAME_MAP_PIXEL_POS = 600;
|
||||
constexpr int MAX_FONT_SIZE = 140;
|
||||
constexpr int MIN_FONT_SIZE = 20;
|
||||
constexpr int STATUS_UI_WIDTH = 40;
|
||||
constexpr int STATUS_UI_HEIGHT = 30;
|
||||
constexpr float PERCENT = 0.01f;
|
||||
constexpr wchar_t BG_TILE = L'█';
|
||||
constexpr wchar_t UI_BASE_CHAR = L'█';
|
||||
constexpr int BG_BOX_OFFSET=5;
|
||||
|
||||
// NOTE: max seems to be about x=240, y=120
|
||||
const int GAME_MAP_X=80;
|
||||
const int GAME_MAP_Y=40;
|
||||
const int INVENTORY_PIXEL_X=50;
|
||||
const int INVENTORY_PIXEL_Y=50;
|
||||
const int INVENTORY_WIDTH=99;
|
||||
const int INVENTORY_HEIGHT=STATUS_UI_HEIGHT-3;
|
||||
#define FONT_FILE_NAME "./assets/text.otf"
|
||||
#define TILE_MAP_CONFIG "./assets/tiles.json"
|
||||
constexpr int GAME_MAP_X=80;
|
||||
constexpr int GAME_MAP_Y=40;
|
||||
constexpr int INVENTORY_PIXEL_X=50;
|
||||
constexpr int INVENTORY_PIXEL_Y=50;
|
||||
constexpr int INVENTORY_WIDTH=99;
|
||||
constexpr int INVENTORY_HEIGHT=STATUS_UI_HEIGHT-3;
|
||||
constexpr int NEXT_LEVEL_WIDTH=60;
|
||||
constexpr int NEXT_LEVEL_HEIGHT=15;
|
||||
constexpr const char *FONT_FILE_NAME="./assets/text.otf";
|
||||
constexpr const char *TILE_MAP_CONFIG="./assets/tiles.json";
|
||||
|
|
1
gui.cpp
1
gui.cpp
|
@ -209,6 +209,7 @@ GUI::GUI(DinkyECS::World &world, Map& game_map) :
|
|||
$sounds.load("combat_enemy_hit", "combat_enemy_hit.mp3");
|
||||
$sounds.load("combat_miss", "combat_miss.mp3");
|
||||
resize_map(MAX_FONT_SIZE);
|
||||
$renderer.center_panel($next_level_ui);
|
||||
init_shaders();
|
||||
}
|
||||
|
||||
|
|
3
gui.hpp
3
gui.hpp
|
@ -66,8 +66,7 @@ class NextLevelUI : public Panel {
|
|||
Component $no_button = nullptr;
|
||||
std::string $message = "Are you ready to go further down?";
|
||||
|
||||
NextLevelUI() :
|
||||
Panel(INVENTORY_PIXEL_X, INVENTORY_PIXEL_Y, INVENTORY_WIDTH, INVENTORY_HEIGHT) {}
|
||||
NextLevelUI() : Panel(0, 0, NEXT_LEVEL_WIDTH, NEXT_LEVEL_HEIGHT) {}
|
||||
|
||||
void create_render();
|
||||
};
|
||||
|
|
11
render.cpp
11
render.cpp
|
@ -13,7 +13,6 @@
|
|||
#include <io.h>
|
||||
#endif
|
||||
|
||||
|
||||
using namespace fmt;
|
||||
|
||||
SFMLRender::SFMLRender() :
|
||||
|
@ -33,6 +32,8 @@ SFMLRender::SFMLRender() :
|
|||
$ui_text.setFillColor(ColorValue::LIGHT_MID);
|
||||
sf::Glyph glyph = $font.getGlyph($config.ui_base_char, $config.ui_font_size, false);
|
||||
$text_bounds = glyph.bounds;
|
||||
$cells_w = std::ceil($config.video_x / $text_bounds.width);
|
||||
$cells_h = std::ceil($config.video_y / $text_bounds.height);
|
||||
}
|
||||
|
||||
sf::Sprite &SFMLRender::get_text_sprite(wchar_t tile) {
|
||||
|
@ -57,6 +58,14 @@ void SFMLRender::clear_cache() {
|
|||
$ui_text.setFont($font);
|
||||
}
|
||||
|
||||
void SFMLRender::center_panel(Panel &panel) {
|
||||
int cell_center_x = ($cells_w - panel.width) / 2;
|
||||
int cell_center_y = ($cells_h - panel.height) / 2;
|
||||
|
||||
panel.x = cell_center_x * $text_bounds.width;
|
||||
panel.y = cell_center_y * $text_bounds.height;
|
||||
}
|
||||
|
||||
void SFMLRender::resize_grid(int new_size, Panel &panel_out) {
|
||||
auto glyph = $font.getGlyph($config.bg_tile, new_size, false);
|
||||
int view_x = std::ceil(($config.video_x - panel_out.x) / glyph.bounds.width);
|
||||
|
|
|
@ -30,6 +30,8 @@ struct RenderConfig {
|
|||
};
|
||||
|
||||
struct SFMLRender {
|
||||
int $cells_w = 0;
|
||||
int $cells_h = 0;
|
||||
RenderConfig $config;
|
||||
sf::RenderWindow $window;
|
||||
int $map_font_size;
|
||||
|
@ -59,6 +61,7 @@ struct SFMLRender {
|
|||
|
||||
void draw(Panel &panel, float x_offset=0.0f, float y_offset=0.0f);
|
||||
void draw_sprite(sf::Sprite &sprite, sf::Shader *shader);
|
||||
void center_panel(Panel &panel);
|
||||
|
||||
bool poll_event(sf::Event &event) {
|
||||
return $window.pollEvent(event);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
TODAY'S GOAL:
|
||||
|
||||
* Config is all over the place. Can I get rid of constant.hpp? Or most of it? Also renderer.cpp:RenderConfig is weird too. Too much indirection all around.
|
||||
* GUI needs to become a statemachine now. Too many panels open at too many times.
|
||||
* Panels should be able to take a width/height and center theirself for me
|
||||
* Linux on Arch catch2 fails with catch2-main missing and xwayland displays weird when small (gentoo plasma6 wayland).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue