Make it possible to zoom in/out, but I may make this a combat thing where it's zoomed out until you encounter an enemy.
This commit is contained in:
parent
02a45d890f
commit
9083582420
2 changed files with 32 additions and 19 deletions
45
gui.cpp
45
gui.cpp
|
@ -54,22 +54,11 @@ GUI::GUI() :
|
|||
$game_map(GAME_MAP_X, GAME_MAP_Y),
|
||||
$window(sf::VideoMode(VIDEO_X,VIDEO_Y), "Roguish"),
|
||||
$screen(SCREEN_X, SCREEN_Y),
|
||||
$map_screen(0,0)
|
||||
$map_screen(0,0),
|
||||
$map_font_size(BASE_MAP_FONT_SIZE)
|
||||
{
|
||||
$font.loadFromFile("./assets/text.otf");
|
||||
// calculate display size
|
||||
sf::Glyph base_glyph = $font.getGlyph(L'█', MAP_FONT_SIZE, false);
|
||||
auto bounds = base_glyph.bounds;
|
||||
$view_port = {
|
||||
size_t(std::ceil((VIDEO_X - GAME_MAP_POS) / bounds.width)),
|
||||
size_t(std::ceil(VIDEO_Y / bounds.height))
|
||||
};
|
||||
|
||||
// set canvas to best size
|
||||
$canvas = Canvas($view_port.x * 2, $view_port.y * 4);
|
||||
|
||||
$map_screen = Screen($view_port.x, $view_port.y);
|
||||
|
||||
resize_map(BASE_MAP_FONT_SIZE);
|
||||
int res = $hit_buf.loadFromFile("./assets/hit.wav");
|
||||
dbc::check(res, "failed to load hit.wav");
|
||||
$hit_sound.setBuffer($hit_buf);
|
||||
|
@ -128,6 +117,10 @@ bool GUI::handle_events() {
|
|||
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
|
||||
player_motion.dy = 1;
|
||||
event_happened = true;
|
||||
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Equal)) {
|
||||
resize_map($map_font_size + 10);
|
||||
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Hyphen)) {
|
||||
resize_map($map_font_size - 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -138,11 +131,12 @@ bool GUI::handle_events() {
|
|||
|
||||
sf::Sprite &GUI::get_text_sprite(wchar_t tile) {
|
||||
if(!$sprites.contains(tile)) {
|
||||
sf::Glyph glyph = $font.getGlyph(tile, MAP_FONT_SIZE, false);
|
||||
$sprites.clear();
|
||||
sf::Glyph glyph = $font.getGlyph(tile, $map_font_size, false);
|
||||
// WARNING! we actually have to do this here because SFML caches
|
||||
// the glyphs on the font texture, so this gets loaded each time
|
||||
// we get a new glyph from the font.
|
||||
$font_texture = $font.getTexture(MAP_FONT_SIZE);
|
||||
$font_texture = $font.getTexture($map_font_size);
|
||||
sf::Sprite sprite($font_texture);
|
||||
sprite.setTextureRect(glyph.textureRect);
|
||||
$sprites[tile] = sprite;
|
||||
|
@ -158,6 +152,21 @@ void GUI::run_systems() {
|
|||
System::combat($world, player);
|
||||
}
|
||||
|
||||
void GUI::resize_map(int new_size) {
|
||||
if(MIN_FONT_SIZE < new_size && new_size < MAX_FONT_SIZE) {
|
||||
$map_font_size = new_size;
|
||||
sf::Glyph base_glyph = $font.getGlyph(L'█', $map_font_size, false);
|
||||
auto bounds = base_glyph.bounds;
|
||||
$view_port = {
|
||||
size_t(std::ceil((VIDEO_X - GAME_MAP_POS) / bounds.width)),
|
||||
size_t(std::ceil(VIDEO_Y / bounds.height))
|
||||
};
|
||||
// set canvas to best size
|
||||
$canvas = Canvas($view_port.x * 2, $view_port.y * 4);
|
||||
$map_screen = Screen($view_port.x, $view_port.y);
|
||||
}
|
||||
}
|
||||
|
||||
void GUI::draw_screen(bool clear, float map_off_x, float map_off_y) {
|
||||
if(clear) $window.clear();
|
||||
std::string screenout = $screen.ToString();
|
||||
|
@ -170,8 +179,8 @@ void GUI::draw_screen(bool clear, float map_off_x, float map_off_y) {
|
|||
|
||||
float y = 0.0f;
|
||||
float x = GAME_MAP_POS;
|
||||
const float line_spacing = $font.getLineSpacing(MAP_FONT_SIZE);
|
||||
sf::Glyph base_glyph = $font.getGlyph(L'█', MAP_FONT_SIZE, false);
|
||||
const float line_spacing = $font.getLineSpacing($map_font_size);
|
||||
sf::Glyph base_glyph = $font.getGlyph(L'█', $map_font_size, false);
|
||||
auto bg_sprite = get_text_sprite(L'█');
|
||||
bg_sprite.setColor(sf::Color(20,20,20));
|
||||
auto add_sprite = get_text_sprite(L'!');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue