1
0
mirror of synced 2025-02-09 07:09:42 +01:00

Song Info displays chart level

This commit is contained in:
Stepland 2020-02-16 16:20:10 +01:00
parent d7ebce49be
commit d6f204b191
9 changed files with 99 additions and 34 deletions

View File

@ -19,6 +19,7 @@
- Cover
- Title
- Artist
- Chart
- Song Panel click
- difficulty cycle
- Handling Resolution changes
@ -29,7 +30,6 @@
### Music Select Screen
- Top Screen Part Handling
- Chart
- Chart List
- Density graph
- Sound

View File

@ -58,6 +58,7 @@ sources = [
'src/Toolkit/EasingFunctions.cpp',
'src/Toolkit/HSL.hpp',
'src/Toolkit/HSL.cpp',
'src/Toolkit/NormalizedOrigin.hpp',
'src/Toolkit/QuickRNG.hpp',
'src/Toolkit/QuickRNG.cpp',
]

View File

@ -34,6 +34,8 @@ namespace Data {
float big_cover_size = 320.f / 768.f;
float big_cover_x = 0.5f;
float big_cover_y = 0.017f;
float big_level_x = 656.f / 768.f;
float big_level_y = 30.f / 768.f;
float upper_part_height = 464.f / 768.f;
template<class Archive>
@ -49,7 +51,7 @@ namespace Data {
}
};
// RAII style class which loads preferences from the dedicated file and saves them when destructed
// RAII style class which loads preferences from the dedicated file when constructed and saves them when destructed
struct Preferences {
Screen screen;
Layout layout;

View File

@ -37,7 +37,7 @@ namespace MusicSelect {
frame.setFillColor(sf::Color::Black);
frame.setOutlineThickness(1.f);
frame.setOutlineColor(sf::Color::White);
Toolkit::setNormOrigin(frame, 0.5f, 0.5f);
Toolkit::set_origin_normalized(frame, 0.5f, 0.5f);
frame.setPosition(get_size()*0.5f, get_size()*0.5f);
target.draw(frame, states);
@ -57,7 +57,7 @@ namespace MusicSelect {
static_cast<unsigned int>(get_size()*0.7f)
};
label_text.setFillColor(sf::Color::White);
Toolkit::setNormOrigin(label_text, 0.5f, 0.5f);
Toolkit::set_origin_normalized(label_text, 0.5f, 0.5f);
auto text_bounds = label_text.getGlobalBounds();
if (text_bounds.width > get_size()*0.6f) {
label_text.setScale(get_size()*0.6f / text_bounds.width, get_size()*0.6f / text_bounds.width);
@ -127,27 +127,15 @@ namespace MusicSelect {
}
}
sf::CircleShape chart_dif_badge{get_size()*0.1f, 30};
Toolkit::setNormOrigin(chart_dif_badge, 0.5f, 0.5f);
Toolkit::set_origin_normalized(chart_dif_badge, 0.5f, 0.5f);
chart_dif_badge.setPosition(get_size()*0.1f, get_size()*(0.1563f + 0.15f));
if (should_be_grayed_out) {
chart_dif_badge.setFillColor(sf::Color(128,128,128));
} else {
if (selected_chart == "BSC") {
chart_dif_badge.setFillColor(m_resources.BSC_color);
} else if (selected_chart == "ADV") {
chart_dif_badge.setFillColor(m_resources.ADV_color);
} else if (selected_chart == "EXT") {
chart_dif_badge.setFillColor(m_resources.EXT_color);
} else {
chart_dif_badge.setFillColor(
Toolkit::HSL(
static_cast<int>(std::hash<std::string>{}(selected_chart)),
83,
49
).TurnToRGB()
m_resources.get_chart_color(selected_chart)
);
}
}
target.draw(chart_dif_badge, states);
if (not should_be_grayed_out) {
auto dif = m_song.chart_levels.at(selected_chart);
@ -157,7 +145,7 @@ namespace MusicSelect {
static_cast<unsigned int>(get_size()*0.15f)
};
dif_label.setFillColor(sf::Color::White);
Toolkit::setNormOrigin(dif_label, 0.5f, 0.5f);
Toolkit::set_origin_normalized(dif_label, 0.5f, 0.5f);
dif_label.setPosition(get_size()*0.1f, get_size()*(0.1563f + 0.15f));
target.draw(dif_label, states);
}

View File

@ -2,6 +2,8 @@
#include <iostream>
#include "../../Toolkit/HSL.hpp"
#include "Panel.hpp"
namespace MusicSelect {
@ -45,4 +47,20 @@ namespace MusicSelect {
}
return chart_selection->song;
}
sf::Color SharedResources::get_chart_color(const std::string& chart) {
if (chart == "BSC") {
return BSC_color;
} else if (chart == "ADV") {
return ADV_color;
} else if (chart == "EXT") {
return EXT_color;
} else {
return Toolkit::HSL(
static_cast<int>(std::hash<std::string>{}(chart)),
83,
49
).TurnToRGB();
}
}
}

View File

@ -38,6 +38,7 @@ namespace MusicSelect {
sf::Color BSC_color = sf::Color{34,216,92};
sf::Color ADV_color = sf::Color{252,212,32};
sf::Color EXT_color = sf::Color{234,46,32};
sf::Color get_chart_color(const std::string& chart);
};
struct HoldsSharedResources {
@ -49,6 +50,8 @@ namespace MusicSelect {
float get_panel_step() const {return m_resources.preferences.layout.panel_step()*get_screen_width();};
float get_big_cover_x() const {return m_resources.preferences.layout.big_cover_x*get_screen_width();};
float get_big_cover_y() const {return m_resources.preferences.layout.big_cover_y*get_screen_width();};
float get_big_level_x() const {return m_resources.preferences.layout.big_level_x*get_screen_width();};
float get_big_level_y() const {return m_resources.preferences.layout.big_level_y*get_screen_width();};
protected:
SharedResources& m_resources;
};

View File

@ -1,8 +1,12 @@
#include "SongInfo.hpp"
#include <cmath>
#include <SFML/Graphics.hpp>
#include <SFML/Graphics/Sprite.hpp>
#include "../../Toolkit/NormalizedOrigin.hpp"
#include "Panel.hpp"
namespace MusicSelect {
@ -56,10 +60,11 @@ namespace MusicSelect {
m_big_cover.setOrigin(m_big_cover.get_size()*0.5f, 0.f);
m_big_cover.setPosition(get_big_cover_x(), get_big_cover_y());
target.draw(m_big_cover, states);
draw_song_title(target);
draw_song_title(target, states);
draw_big_level(target, states);
}
void SongInfo::draw_song_title(sf::RenderTarget& target) const {
void SongInfo::draw_song_title(sf::RenderTarget& target, sf::RenderStates states) const {
auto selected_panel = m_resources.selected_panel;
if (not selected_panel.has_value()) {
return;
@ -87,7 +92,7 @@ namespace MusicSelect {
get_big_cover_x() - m_big_cover.get_size()/2.f,
get_big_cover_y() + m_big_cover.get_size() + 0.01f*get_screen_width()
);
target.draw(song_title_label);
target.draw(song_title_label, states);
}
auto song_artist = selected_chart->song.artist;
if (not song_artist.empty()) {
@ -110,7 +115,55 @@ namespace MusicSelect {
get_big_cover_x() - m_big_cover.get_size()/2.f,
get_big_cover_y() + m_big_cover.get_size() + 0.05f*get_screen_width()
);
target.draw(song_artist_label);
target.draw(song_artist_label, states);
}
}
void SongInfo::draw_big_level(sf::RenderTarget& target, sf::RenderStates states) const {
auto selected_panel = m_resources.selected_panel;
if (not selected_panel.has_value()) {
return;
}
auto selected_chart = selected_panel->panel.get_selected_chart();
if (not selected_chart.has_value()) {
return;
}
sf::Text level_label{
"LEVEL",
m_resources.noto_sans_medium,
static_cast<unsigned int>(12.f/768.f*get_screen_width())
};
Toolkit::set_origin_normalized(level_label, 0.5f, 0.f);
level_label.setPosition(get_big_level_x(), get_big_level_y());
level_label.setFillColor(sf::Color::White);
target.draw(level_label, states);
sf::Text level_number_label{
std::to_string(selected_chart->song.chart_levels.at(selected_chart->chart)),
m_resources.noto_sans_medium,
static_cast<unsigned int>(130.f/768.f*get_screen_width())
};
Toolkit::set_origin_normalized(level_number_label, 0.5f, 0.f);
level_number_label.setPosition(get_big_level_x(), get_big_level_y()+(30.f/768.f*get_screen_width()));
level_number_label.setFillColor(sf::Color::White);
target.draw(level_number_label, states);
std::string full_chart_name = selected_chart->chart;
if (selected_chart->chart == "BSC") {
full_chart_name = "BASIC";
} else if (selected_chart->chart == "ADV") {
full_chart_name = "ADVANCED";
} else if (selected_chart->chart == "EXT") {
full_chart_name = "EXTREME";
}
sf::Text chart_label{
full_chart_name,
m_resources.noto_sans_medium,
static_cast<unsigned int>(20.f/768.f*get_screen_width())
};
Toolkit::set_origin_normalized_no_position(chart_label, 0.5f, 0.f);
chart_label.setPosition(get_big_level_x(), get_big_level_y()+(145.f/768.f*get_screen_width()));
chart_label.setFillColor(m_resources.get_chart_color(selected_chart->chart));
target.draw(chart_label, states);
}
}

View File

@ -25,7 +25,8 @@ namespace MusicSelect {
SongInfo(SharedResources& resources);
private:
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
void draw_song_title(sf::RenderTarget& target) const;
void draw_song_title(sf::RenderTarget& target, sf::RenderStates states) const;
void draw_big_level(sf::RenderTarget& target, sf::RenderStates states) const;
mutable BigCover m_big_cover;
};
}

View File

@ -3,16 +3,15 @@
#include <SFML/Graphics.hpp>
namespace Toolkit {
void setNormOrigin(sf::Shape& s, float x, float y) {
auto bounds = s.getGlobalBounds();
s.setOrigin(bounds.left+x*bounds.width, bounds.top+y*bounds.height);
};
void setNormOrigin(sf::Sprite& s, float x, float y) {
template<class T>
void set_origin_normalized(T& s, float x, float y) {
auto bounds = s.getGlobalBounds();
s.setOrigin(bounds.left+x*bounds.width, bounds.top+y*bounds.height);
}
void setNormOrigin(sf::Text& t, float x, float y) {
auto bounds = t.getGlobalBounds();
t.setOrigin(bounds.left+x*bounds.width, bounds.top+y*bounds.height);
template<class T>
void set_origin_normalized_no_position(T& s, float x, float y) {
auto bounds = s.getGlobalBounds();
s.setOrigin(x*bounds.width, y*bounds.height);
}
}