|
|
@ -54,22 +54,11 @@ GUI::GUI() : |
|
|
|
$game_map(GAME_MAP_X, GAME_MAP_Y), |
|
|
|
$game_map(GAME_MAP_X, GAME_MAP_Y), |
|
|
|
$window(sf::VideoMode(VIDEO_X,VIDEO_Y), "Roguish"), |
|
|
|
$window(sf::VideoMode(VIDEO_X,VIDEO_Y), "Roguish"), |
|
|
|
$screen(SCREEN_X, SCREEN_Y), |
|
|
|
$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"); |
|
|
|
$font.loadFromFile("./assets/text.otf"); |
|
|
|
// calculate display size
|
|
|
|
resize_map(BASE_MAP_FONT_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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int res = $hit_buf.loadFromFile("./assets/hit.wav"); |
|
|
|
int res = $hit_buf.loadFromFile("./assets/hit.wav"); |
|
|
|
dbc::check(res, "failed to load hit.wav"); |
|
|
|
dbc::check(res, "failed to load hit.wav"); |
|
|
|
$hit_sound.setBuffer($hit_buf); |
|
|
|
$hit_sound.setBuffer($hit_buf); |
|
|
@ -128,6 +117,10 @@ bool GUI::handle_events() { |
|
|
|
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { |
|
|
|
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { |
|
|
|
player_motion.dy = 1; |
|
|
|
player_motion.dy = 1; |
|
|
|
event_happened = true; |
|
|
|
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) { |
|
|
|
sf::Sprite &GUI::get_text_sprite(wchar_t tile) { |
|
|
|
if(!$sprites.contains(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
|
|
|
|
// WARNING! we actually have to do this here because SFML caches
|
|
|
|
// the glyphs on the font texture, so this gets loaded each time
|
|
|
|
// the glyphs on the font texture, so this gets loaded each time
|
|
|
|
// we get a new glyph from the font.
|
|
|
|
// 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); |
|
|
|
sf::Sprite sprite($font_texture); |
|
|
|
sprite.setTextureRect(glyph.textureRect); |
|
|
|
sprite.setTextureRect(glyph.textureRect); |
|
|
|
$sprites[tile] = sprite; |
|
|
|
$sprites[tile] = sprite; |
|
|
@ -158,6 +152,21 @@ void GUI::run_systems() { |
|
|
|
System::combat($world, player); |
|
|
|
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) { |
|
|
|
void GUI::draw_screen(bool clear, float map_off_x, float map_off_y) { |
|
|
|
if(clear) $window.clear(); |
|
|
|
if(clear) $window.clear(); |
|
|
|
std::string screenout = $screen.ToString(); |
|
|
|
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 y = 0.0f; |
|
|
|
float x = GAME_MAP_POS; |
|
|
|
float x = GAME_MAP_POS; |
|
|
|
const float line_spacing = $font.getLineSpacing(MAP_FONT_SIZE); |
|
|
|
const float line_spacing = $font.getLineSpacing($map_font_size); |
|
|
|
sf::Glyph base_glyph = $font.getGlyph(L'█', MAP_FONT_SIZE, false); |
|
|
|
sf::Glyph base_glyph = $font.getGlyph(L'█', $map_font_size, false); |
|
|
|
auto bg_sprite = get_text_sprite(L'█'); |
|
|
|
auto bg_sprite = get_text_sprite(L'█'); |
|
|
|
bg_sprite.setColor(sf::Color(20,20,20)); |
|
|
|
bg_sprite.setColor(sf::Color(20,20,20)); |
|
|
|
auto add_sprite = get_text_sprite(L'!'); |
|
|
|
auto add_sprite = get_text_sprite(L'!'); |
|
|
|