diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a643eb..cfa2a18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,11 +46,13 @@ - Sort out the wierdness when hitting early - Score - compute + - display - Combo - compute - display - Shutter - compute +- Song Info ## Misc - Handling Resolution changes diff --git a/TODO.md b/TODO.md index 5234fff..e50500d 100644 --- a/TODO.md +++ b/TODO.md @@ -7,11 +7,10 @@ - Fullscreen handling ## Gameplay Screen -- Score - - display - Shutter - display - Density Graph +- Long Notes ## Results Screen diff --git a/meson.build b/meson.build index 0673f7c..4a08528 100644 --- a/meson.build +++ b/meson.build @@ -82,7 +82,8 @@ sources = [ 'src/Toolkit/GHCFilesystemPathHash.hpp', 'src/Toolkit/HSL.hpp', 'src/Toolkit/HSL.cpp', - 'src/Toolkit/NormalizedOrigin.hpp', + 'src/Toolkit/SFMLHelpers.hpp', + 'src/Toolkit/SFMLHelpers.cpp', 'src/Toolkit/QuickRNG.hpp', 'src/Toolkit/QuickRNG.cpp', 'src/Main.cpp', diff --git a/src/Data/Preferences.hpp b/src/Data/Preferences.hpp index a9fe163..d736247 100644 --- a/src/Data/Preferences.hpp +++ b/src/Data/Preferences.hpp @@ -74,6 +74,8 @@ namespace Data { float get_big_level_x() const {return preferences.layout.big_level_x*get_screen_width();}; float get_big_level_y() const {return preferences.layout.big_level_y*get_screen_width();}; float get_upper_part_height() const {return preferences.layout.upper_part_height*get_screen_width();}; + // Scales a length in pixels from the original jubeat resolution of 768x1360 to the current screen resolution + float scale(float length) const {return (length*get_screen_width())/768.f;}; Preferences& preferences; }; } diff --git a/src/Drawables/DensityGraph.hpp b/src/Drawables/DensityGraph.hpp index 5c1eaeb..b2e0e95 100644 --- a/src/Drawables/DensityGraph.hpp +++ b/src/Drawables/DensityGraph.hpp @@ -8,7 +8,7 @@ #include "../Data/Chart.hpp" #include "../Data/Song.hpp" #include "../Toolkit/Cache.hpp" -#include "../Toolkit/NormalizedOrigin.hpp" +#include "../Toolkit/SFMLHelpers.hpp" namespace Drawables { class DensityGraph : public sf::Drawable, public sf::Transformable { diff --git a/src/Screens/Gameplay/Gameplay.cpp b/src/Screens/Gameplay/Gameplay.cpp index ae3b7c2..1b17b3b 100644 --- a/src/Screens/Gameplay/Gameplay.cpp +++ b/src/Screens/Gameplay/Gameplay.cpp @@ -11,7 +11,7 @@ #include #include "../../Input/Buttons.hpp" -#include "../../Toolkit/NormalizedOrigin.hpp" +#include "../../Toolkit/SFMLHelpers.hpp" #include "PreciseMusic.hpp" #include "Silence.hpp" @@ -58,6 +58,9 @@ namespace Gameplay { case sf::Event::Resized: // update the view to the new size of the window window.setView(sf::View({0, 0, static_cast(event.size.width), static_cast(event.size.height)})); + shared.preferences.screen.height = event.size.height; + shared.preferences.screen.width = event.size.width; + shared.button_highlight.setPosition(get_ribbon_x(), get_ribbon_y()); break; default: break; @@ -80,6 +83,24 @@ namespace Gameplay { auto music_time = music->getPlayingOffset(); update_note_index(music_time); window.clear(sf::Color(7, 23, 53)); + + // Draw song info + // Cover is 40x40 @ (384,20) + if (song_selection.song.cover) { + auto cover = shared.covers.get(*song_selection.song.full_cover_path()); + if (cover) { + sf::Sprite cover_sprite{*cover->texture}; + auto cover_size = 40.f/768.f*get_screen_width(); + Toolkit::set_size_from_local_bounds(cover_sprite, cover_size, cover_size); + cover_sprite.setPosition( + 384.f/768.f*get_screen_width(), + 20.f/768.f*get_screen_width() + ); + window.draw(cover_sprite); + } + } + + // Draw Combo auto current_combo = combo.load(); if (current_combo >= 4) { @@ -95,6 +116,8 @@ namespace Gameplay { ); window.draw(combo_text); } + + // Draw score auto current_score = score.get_score(); sf::Text score_text; score_text.setFont(shared.fallback_font.black); @@ -108,6 +131,69 @@ namespace Gameplay { ); window.draw(score_text); + // Draw song info + auto song_title = song_selection.song.title; + if (not song_title.empty()) { + sf::Text song_title_label{ + sf::String::fromUtf8(song_title.begin(), song_title.end()), + shared.fallback_font.medium, + static_cast(scale(20.f)) + }; + Toolkit::set_local_origin_normalized(song_title_label, 0.f, 1.f); + song_title_label.setFillColor(sf::Color::White); + song_title_label.setPosition(scale(440.f), scale(40.f)); + window.draw(song_title_label); + } + auto song_artist = song_selection.song.artist; + if (not song_artist.empty()) { + sf::Text song_artist_label{ + sf::String::fromUtf8(song_artist.begin(), song_artist.end()), + shared.fallback_font.medium, + static_cast(scale(12.f)) + }; + song_artist_label.setStyle(sf::Text::Italic); + song_artist_label.setFillColor(sf::Color::White); + song_artist_label.setPosition(scale(440.f), scale(45.f)); + window.draw(song_artist_label); + } + sf::Text level_label{ + "LEVEL:", + shared.fallback_font.medium, + static_cast(scale(10.f)) + }; + Toolkit::set_origin_normalized(level_label, 1.f, 1.f); + level_label.setPosition(scale(322.f), scale(35.f)); + level_label.setFillColor(sf::Color::White); + window.draw(level_label); + + sf::Text level_number_label{ + std::to_string(chart.level), + shared.fallback_font.black, + static_cast(scale(35.f)) + }; + Toolkit::set_origin_normalized(level_number_label, 0.5f, 0.f); + level_number_label.setPosition(scale(351.f), scale(24.f)); + level_number_label.setFillColor(sf::Color::White); + window.draw(level_number_label); + + std::string full_difficulty = song_selection.difficulty; + if (full_difficulty == "BSC") { + full_difficulty = "BASIC"; + } else if (full_difficulty == "ADV") { + full_difficulty = "ADVANCED"; + } else if (full_difficulty == "EXT") { + full_difficulty = "EXTREME"; + } + + sf::Text chart_label{ + sf::String::fromUtf8(full_difficulty.begin(), full_difficulty.end()), + shared.fallback_font.medium, + static_cast(scale(16.f)) + }; + Toolkit::set_local_origin_normalized(chart_label, 1.f, 1.f); + chart_label.setPosition(scale(322.f), scale(55.f)); + chart_label.setFillColor(shared.get_chart_color(song_selection.difficulty)); + window.draw(chart_label); // Draw Notes for (auto i = note_index.load(); i < notes.size(); ++i) { @@ -125,8 +211,7 @@ namespace Gameplay { ); } if (sprite) { - auto rect = sprite->getLocalBounds(); - sprite->setScale(get_panel_size()/rect.width, get_panel_size()/rect.height); + Toolkit::set_size_from_local_bounds(*sprite, get_panel_size(), get_panel_size()); auto pos = Input::button_to_coords(note.position); sprite->setPosition( get_ribbon_x()+get_panel_step()*pos.x, diff --git a/src/Screens/MusicSelect/Drawables/ControlPanels.cpp b/src/Screens/MusicSelect/Drawables/ControlPanels.cpp index d6a8625..4e6665f 100644 --- a/src/Screens/MusicSelect/Drawables/ControlPanels.cpp +++ b/src/Screens/MusicSelect/Drawables/ControlPanels.cpp @@ -1,6 +1,6 @@ #include "ControlPanels.hpp" -#include "../../../Toolkit/NormalizedOrigin.hpp" +#include "../../../Toolkit/SFMLHelpers.hpp" namespace MusicSelect { void LeftButton::draw(sf::RenderTarget& target, sf::RenderStates states) const { diff --git a/src/Screens/MusicSelect/MusicSelect.cpp b/src/Screens/MusicSelect/MusicSelect.cpp index 86a7939..4f75fdd 100644 --- a/src/Screens/MusicSelect/MusicSelect.cpp +++ b/src/Screens/MusicSelect/MusicSelect.cpp @@ -9,7 +9,7 @@ #include "../../Input/Buttons.hpp" #include "../../Input/KeyMapping.hpp" -#include "../../Toolkit/NormalizedOrigin.hpp" +#include "../../Toolkit/SFMLHelpers.hpp" #include "Panels/Panel.hpp" #include "PanelLayout.hpp" diff --git a/src/Screens/MusicSelect/Options/InputRemap.cpp b/src/Screens/MusicSelect/Options/InputRemap.cpp index 9306f1c..105bf4a 100644 --- a/src/Screens/MusicSelect/Options/InputRemap.cpp +++ b/src/Screens/MusicSelect/Options/InputRemap.cpp @@ -6,7 +6,7 @@ #include #include "../../../Toolkit/HSL.hpp" -#include "../../../Toolkit/NormalizedOrigin.hpp" +#include "../../../Toolkit/SFMLHelpers.hpp" namespace MusicSelect { diff --git a/src/Screens/MusicSelect/Panels/Panel.cpp b/src/Screens/MusicSelect/Panels/Panel.cpp index d1c8161..0889452 100644 --- a/src/Screens/MusicSelect/Panels/Panel.cpp +++ b/src/Screens/MusicSelect/Panels/Panel.cpp @@ -5,7 +5,7 @@ #include #include "../../../Toolkit/HSL.hpp" -#include "../../../Toolkit/NormalizedOrigin.hpp" +#include "../../../Toolkit/SFMLHelpers.hpp" #include "../Ribbon.hpp" #include "../Resources.hpp" diff --git a/src/Screens/MusicSelect/SongInfo.cpp b/src/Screens/MusicSelect/SongInfo.cpp index 582958e..a06a1eb 100644 --- a/src/Screens/MusicSelect/SongInfo.cpp +++ b/src/Screens/MusicSelect/SongInfo.cpp @@ -6,7 +6,7 @@ #include #include "../../Toolkit/EasingFunctions.hpp" -#include "../../Toolkit/NormalizedOrigin.hpp" +#include "../../Toolkit/SFMLHelpers.hpp" #include "Panels/Panel.hpp" @@ -112,7 +112,6 @@ namespace MusicSelect { song_artist_label.setScale(m_big_cover.get_size() / song_artist_bounds.width, 1.0f); } song_artist_label.setFillColor(sf::Color::White); - song_artist_label.setFillColor(sf::Color::White); song_artist_label.setPosition( get_big_cover_x() - m_big_cover.get_size()/2.f, get_big_cover_y() + m_big_cover.get_size() + 0.04f*get_screen_width() diff --git a/src/Toolkit/SFMLHelpers.cpp b/src/Toolkit/SFMLHelpers.cpp new file mode 100644 index 0000000..b32046c --- /dev/null +++ b/src/Toolkit/SFMLHelpers.cpp @@ -0,0 +1,8 @@ +#include "SFMLHelpers.hpp" + +namespace Toolkit { + void set_size_from_local_bounds(sf::Sprite& s, float x, float y) { + auto const bounds = s.getLocalBounds(); + s.setScale(x/bounds.width,y/bounds.height); + } +} diff --git a/src/Toolkit/NormalizedOrigin.hpp b/src/Toolkit/SFMLHelpers.hpp similarity index 85% rename from src/Toolkit/NormalizedOrigin.hpp rename to src/Toolkit/SFMLHelpers.hpp index 6f32ae7..fd95377 100644 --- a/src/Toolkit/NormalizedOrigin.hpp +++ b/src/Toolkit/SFMLHelpers.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace Toolkit { template @@ -20,4 +20,6 @@ namespace Toolkit { auto bounds = s.getGlobalBounds(); s.setOrigin(x*bounds.width, y*bounds.height); } + + void set_size_from_local_bounds(sf::Sprite& s, float x, float y); } \ No newline at end of file