Make everything on screen resolution-dependant
This commit is contained in:
parent
629a54172a
commit
a1242a1376
@ -28,8 +28,15 @@ namespace Data {
|
||||
struct Layout {
|
||||
float panel_position_x = 8.f / 768.f;
|
||||
float panel_position_y = 602.f / 1360.f;
|
||||
float panel_size = 120.f / 768.f;
|
||||
float panel_size = 160.f / 768.f;
|
||||
float panel_spacing = (112.f / 3.f) / 768.f;
|
||||
float panel_step() {return panel_size+panel_spacing;};
|
||||
float ribbon_x = 8.f / 768.f;
|
||||
float ribbon_y = 602.f / 768.f;
|
||||
float big_cover_size = 320.f / 768.f;
|
||||
float big_cover_x = 0.5f;
|
||||
float big_cover_y = 0.017f;
|
||||
float upper_part_height = 464.f / 768.f;
|
||||
|
||||
template<class Archive>
|
||||
void serialize(Archive & archive) {
|
||||
@ -37,7 +44,11 @@ namespace Data {
|
||||
CEREAL_NVP(panel_position_x),
|
||||
CEREAL_NVP(panel_position_y),
|
||||
CEREAL_NVP(panel_size),
|
||||
CEREAL_NVP(panel_spacing)
|
||||
CEREAL_NVP(panel_spacing),
|
||||
CEREAL_NVP(ribbon_x),
|
||||
CEREAL_NVP(ribbon_y),
|
||||
CEREAL_NVP(big_cover_size),
|
||||
CEREAL_NVP(upper_part_height)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
@ -27,7 +27,7 @@ int main(int argc, char const *argv[]) {
|
||||
settings
|
||||
};
|
||||
Data::SongList song_list;
|
||||
MusicSelect::Screen music_select{song_list};
|
||||
MusicSelect::Screen music_select{song_list, preferences};
|
||||
|
||||
music_select.select_chart(window);
|
||||
/*
|
||||
|
@ -1,12 +1,15 @@
|
||||
#include "ButtonHighlight.hpp"
|
||||
|
||||
namespace MusicSelect {
|
||||
ButtonHighlight::ButtonHighlight(const float& panel_size, const float& panel_spacing) :
|
||||
m_panel_size(panel_size),
|
||||
m_panel_spacing(panel_spacing),
|
||||
m_highlight({static_cast<float>(panel_size-3), static_cast<float>(panel_size-3)}),
|
||||
ButtonHighlight::ButtonHighlight(SharedResources& resources) :
|
||||
m_resources(resources),
|
||||
m_highlight(),
|
||||
m_time_to_alpha(0.f, 0.25f, 255.f, 0.f)
|
||||
{
|
||||
m_highlight.setSize({
|
||||
(m_resources.preferences.layout.panel_size-3.f/768.f)*m_resources.preferences.screen.width,
|
||||
(m_resources.preferences.layout.panel_size-3.f/768.f)*m_resources.preferences.screen.width,
|
||||
});
|
||||
m_highlight.setFillColor(sf::Color::Transparent);
|
||||
m_highlight.setOutlineThickness(1.f);
|
||||
m_highlight.setOrigin(m_highlight.getSize().x / 2.f, m_highlight.getSize().y / 2.f);
|
||||
@ -18,6 +21,8 @@ namespace MusicSelect {
|
||||
|
||||
void ButtonHighlight::draw(sf::RenderTarget& target, sf::RenderStates states) const {
|
||||
states.transform *= getTransform();
|
||||
auto panel_step = m_resources.preferences.layout.panel_step()*m_resources.preferences.screen.width;
|
||||
auto panel_size = m_resources.preferences.layout.panel_size*m_resources.preferences.screen.width;
|
||||
auto it = m_button_presses_history.begin();
|
||||
while (it != m_button_presses_history.end()) {
|
||||
auto elapsed = it->second.getElapsedTime();
|
||||
@ -28,8 +33,8 @@ namespace MusicSelect {
|
||||
auto alpha = m_time_to_alpha.transform(elapsed.asSeconds());
|
||||
m_highlight.setOutlineColor(sf::Color(255,255,0,static_cast<std::size_t>(alpha)));
|
||||
m_highlight.setPosition({
|
||||
static_cast<float>(coords.x * (m_panel_size+m_panel_spacing)) + m_panel_size/2.f,
|
||||
static_cast<float>(coords.y * (m_panel_size+m_panel_spacing)) + m_panel_size/2.f
|
||||
static_cast<float>(coords.x * panel_step) + panel_size/2.f,
|
||||
static_cast<float>(coords.y * panel_step) + panel_size/2.f
|
||||
});
|
||||
target.draw(m_highlight, states);
|
||||
++it;
|
||||
|
@ -8,15 +8,16 @@
|
||||
#include "../../Data/KeyMapping.hpp"
|
||||
#include "../../Toolkit/AffineTransform.hpp"
|
||||
|
||||
#include "SharedResources.hpp"
|
||||
|
||||
namespace MusicSelect {
|
||||
class ButtonHighlight : public sf::Drawable, public sf::Transformable {
|
||||
public:
|
||||
ButtonHighlight(const float& panel_size, const float& panel_spacing);
|
||||
ButtonHighlight(SharedResources& resources);
|
||||
void button_pressed(Button button);
|
||||
private:
|
||||
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
|
||||
const float& m_panel_size;
|
||||
const float& m_panel_spacing;
|
||||
SharedResources& m_resources;
|
||||
mutable sf::RectangleShape m_highlight;
|
||||
mutable std::map<Button, sf::Clock> m_button_presses_history;
|
||||
Toolkit::AffineTransform<float> m_time_to_alpha;
|
||||
|
@ -7,13 +7,13 @@
|
||||
|
||||
#include "../../Data/KeyMapping.hpp"
|
||||
|
||||
MusicSelect::Screen::Screen(const Data::SongList& t_song_list) :
|
||||
MusicSelect::Screen::Screen(const Data::SongList& t_song_list, Data::Preferences& t_preferences) :
|
||||
song_list(t_song_list),
|
||||
resources(),
|
||||
ribbon(resources, m_panel_size, m_panel_spacing),
|
||||
song_info(resources, m_upper_part_width, m_upper_part_height),
|
||||
resources(t_preferences),
|
||||
ribbon(resources),
|
||||
song_info(resources),
|
||||
selected_panel(),
|
||||
button_highlight(m_panel_size, m_panel_spacing),
|
||||
button_highlight(resources),
|
||||
key_mapping()
|
||||
{
|
||||
ribbon.title_sort(song_list);
|
||||
@ -25,8 +25,14 @@ void MusicSelect::Screen::select_chart(sf::RenderWindow& window) {
|
||||
ImGui::SFML::Init(window);
|
||||
bool chart_selected = false;
|
||||
sf::Clock imguiClock;
|
||||
ribbon.setPosition(8.f, 602.f);
|
||||
button_highlight.setPosition(8.f, 602.f);
|
||||
ribbon.setPosition(
|
||||
resources.preferences.layout.ribbon_x*resources.preferences.screen.width,
|
||||
resources.preferences.layout.ribbon_y*resources.preferences.screen.width
|
||||
);
|
||||
button_highlight.setPosition(
|
||||
resources.preferences.layout.ribbon_x*resources.preferences.screen.width,
|
||||
resources.preferences.layout.ribbon_y*resources.preferences.screen.width
|
||||
);
|
||||
while ((not chart_selected) and window.isOpen()) {
|
||||
sf::Event event;
|
||||
while (window.pollEvent(event)) {
|
||||
@ -73,6 +79,7 @@ void MusicSelect::Screen::handle_key_press(const sf::Event::KeyEvent& key_event)
|
||||
}
|
||||
|
||||
void MusicSelect::Screen::handle_mouse_click(const sf::Event::MouseButtonEvent& mouse_button_event) {
|
||||
/*
|
||||
if (mouse_button_event.button == sf::Mouse::Left) {
|
||||
int clicked_panel_index = (mouse_button_event.x / m_panel_size) + 4 * (mouse_button_event.y / m_panel_size);
|
||||
auto button = fromIndex(clicked_panel_index);
|
||||
@ -80,6 +87,7 @@ void MusicSelect::Screen::handle_mouse_click(const sf::Event::MouseButtonEvent&
|
||||
press_button(*button);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void MusicSelect::Screen::press_button(const Button& button) {
|
||||
|
@ -19,16 +19,12 @@ namespace MusicSelect {
|
||||
// it loads a cache of available songs in the song_list attribute
|
||||
class Screen {
|
||||
public:
|
||||
Screen(const Data::SongList& t_song_list);
|
||||
Screen(const Data::SongList& t_song_list, Data::Preferences& t_preferences);
|
||||
void select_chart(sf::RenderWindow& window);
|
||||
|
||||
private:
|
||||
// Data
|
||||
const Data::SongList song_list;
|
||||
float m_panel_size = 160.0f;
|
||||
float m_panel_spacing = 112.0f / 3.0f;
|
||||
float m_upper_part_width = 768.0f;
|
||||
float m_upper_part_height = 464.0f;
|
||||
|
||||
// Resources
|
||||
SharedResources resources;
|
||||
|
@ -11,8 +11,11 @@
|
||||
#include "SharedResources.hpp"
|
||||
|
||||
namespace MusicSelect {
|
||||
float Panel::get_size() const {
|
||||
return m_resources.preferences.layout.panel_size*m_resources.preferences.screen.width;
|
||||
}
|
||||
void ColorPanel::draw(sf::RenderTarget& target, sf::RenderStates states) const {
|
||||
sf::RectangleShape panel{{m_size*0.9f, m_size*0.9f}};
|
||||
sf::RectangleShape panel{{get_size()*0.9f, get_size()*0.9f}};
|
||||
panel.setFillColor(m_color);
|
||||
states.transform *= getTransform();
|
||||
target.draw(panel, states);
|
||||
@ -24,49 +27,38 @@ namespace MusicSelect {
|
||||
|
||||
void CategoryPanel::draw(sf::RenderTarget& target, sf::RenderStates states) const {
|
||||
states.transform *= getTransform();
|
||||
sf::RectangleShape red_rectangle;
|
||||
red_rectangle.setFillColor(sf::Color::Transparent);
|
||||
red_rectangle.setOutlineColor(sf::Color::Red);
|
||||
red_rectangle.setOutlineThickness(1.f);
|
||||
|
||||
sf::RectangleShape frame{{m_size*0.9f, m_size*0.9f}};
|
||||
sf::RectangleShape frame{{get_size()*0.9f, get_size()*0.9f}};
|
||||
frame.setFillColor(sf::Color::Black);
|
||||
frame.setOutlineThickness(1.f);
|
||||
frame.setOutlineColor(sf::Color::White);
|
||||
Toolkit::setNormOrigin(frame, 0.5f, 0.5f);
|
||||
frame.setPosition(m_size/2.f, m_size/2.f);
|
||||
frame.setPosition(get_size()*0.5f, get_size()*0.5f);
|
||||
target.draw(frame, states);
|
||||
|
||||
sf::Text top_text;
|
||||
top_text.setFont(m_resources.noto_sans_medium);
|
||||
top_text.setString("category");
|
||||
top_text.setCharacterSize(50U);
|
||||
top_text.setFillColor(sf::Color::White);
|
||||
auto bounds = top_text.getLocalBounds();
|
||||
top_text.setScale(m_size*0.45f / bounds.width, m_size*0.45f / bounds.width);
|
||||
top_text.setPosition(m_size*0.07f, m_size*0.07f);
|
||||
target.draw(top_text, states);
|
||||
sf::Text category_label{
|
||||
"category",
|
||||
m_resources.noto_sans_medium,
|
||||
static_cast<unsigned int>(get_size()*0.1f)
|
||||
};
|
||||
category_label.setFillColor(sf::Color::White);
|
||||
auto bounds = category_label.getLocalBounds();
|
||||
category_label.setPosition(get_size()*0.1f, get_size()*0.1f);
|
||||
target.draw(category_label, states);
|
||||
|
||||
set_to_global_bounds(red_rectangle, top_text);
|
||||
target.draw(red_rectangle, states);
|
||||
|
||||
sf::Text label_text;
|
||||
label_text.setFont(m_resources.noto_sans_medium);
|
||||
label_text.setString(m_label);
|
||||
label_text.setCharacterSize(100U);
|
||||
sf::Text label_text{
|
||||
m_label,
|
||||
m_resources.noto_sans_medium,
|
||||
static_cast<unsigned int>(get_size()*0.7f)
|
||||
};
|
||||
label_text.setFillColor(sf::Color::White);
|
||||
auto text_bounds = label_text.getLocalBounds();
|
||||
Toolkit::setNormOrigin(label_text, 0.5f, 0.5f);
|
||||
if (text_bounds.height > text_bounds.width) {
|
||||
label_text.setScale(m_size*0.8f/text_bounds.height, m_size*0.8f/text_bounds.height);
|
||||
} else {
|
||||
label_text.setScale(m_size*0.8f/text_bounds.width, m_size*0.8f/text_bounds.width);
|
||||
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);
|
||||
}
|
||||
label_text.setPosition(m_size / 2.f, m_size / 2.f);
|
||||
label_text.setPosition(get_size()*0.5f, get_size()*0.55f);
|
||||
target.draw(label_text, states);
|
||||
|
||||
set_to_global_bounds(red_rectangle, label_text);
|
||||
target.draw(red_rectangle, states);
|
||||
}
|
||||
|
||||
void SongPanel::click(Ribbon& ribbon, std::size_t from_button_index) {
|
||||
@ -79,18 +71,18 @@ namespace MusicSelect {
|
||||
selected_chart = m_song.chart_levels.cbegin()->first;
|
||||
}
|
||||
} else {
|
||||
// The song was not selected before : unselect the last one
|
||||
if (m_resources.selected_panel.has_value()) {
|
||||
m_resources.selected_panel->panel.unselect();
|
||||
}
|
||||
// Look for the first chart with dif greater or equal to the last select one
|
||||
// or else select the first chart
|
||||
auto it = m_song.chart_levels.lower_bound(ribbon.m_global_chart_dif);
|
||||
auto it = m_song.chart_levels.lower_bound(m_resources.get_last_selected_chart());
|
||||
if (it != m_song.chart_levels.cend()) {
|
||||
selected_chart = it->first;
|
||||
} else {
|
||||
selected_chart = m_song.chart_levels.cbegin()->first;
|
||||
}
|
||||
// The song was not selected before : first unselect the last one
|
||||
if (m_resources.selected_panel.has_value()) {
|
||||
m_resources.selected_panel->panel.unselect();
|
||||
}
|
||||
m_resources.selected_panel.emplace(TimedSelectedPanel{*this});
|
||||
}
|
||||
}
|
||||
@ -124,14 +116,14 @@ namespace MusicSelect {
|
||||
auto grey = should_be_grayed_out ? 2 : 1;
|
||||
cover.setColor(sf::Color(255/grey, 255/grey, 255/grey, alpha));
|
||||
auto bounds = cover.getGlobalBounds();
|
||||
cover.setScale(m_size*0.8f/bounds.width, m_size*0.8f/bounds.height);
|
||||
cover.setPosition(m_size*0.1f,m_size*0.1563f);
|
||||
cover.setScale(get_size()*0.8f/bounds.width, get_size()*0.8f/bounds.height);
|
||||
cover.setPosition(get_size()*0.1f,get_size()*0.1563f);
|
||||
target.draw(cover, states);
|
||||
}
|
||||
}
|
||||
sf::CircleShape chart_dif_badge{m_size*0.1f, 30};
|
||||
sf::CircleShape chart_dif_badge{get_size()*0.1f, 30};
|
||||
Toolkit::setNormOrigin(chart_dif_badge, 0.5f, 0.5f);
|
||||
chart_dif_badge.setPosition(m_size*0.1f, m_size*(0.1563f + 0.15f));
|
||||
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 {
|
||||
@ -157,22 +149,22 @@ namespace MusicSelect {
|
||||
sf::Text dif_label{
|
||||
std::to_string(dif),
|
||||
m_resources.noto_sans_medium,
|
||||
static_cast<unsigned int>(m_size*0.15f)
|
||||
static_cast<unsigned int>(get_size()*0.15f)
|
||||
};
|
||||
dif_label.setFillColor(sf::Color::White);
|
||||
Toolkit::setNormOrigin(dif_label, 0.5f, 0.5f);
|
||||
dif_label.setPosition(m_size*0.1f, m_size*(0.1563f + 0.15f));
|
||||
dif_label.setPosition(get_size()*0.1f, get_size()*(0.1563f + 0.15f));
|
||||
target.draw(dif_label, states);
|
||||
}
|
||||
sf::Text song_title;
|
||||
song_title.setFont(m_resources.noto_sans_medium);
|
||||
song_title.setString(m_song.title);
|
||||
song_title.setCharacterSize(static_cast<unsigned int>(0.06875f*m_size));
|
||||
song_title.setCharacterSize(static_cast<unsigned int>(0.06875f*get_size()));
|
||||
song_title.setFillColor(sf::Color::White);
|
||||
auto song_title_bounds = song_title.getLocalBounds();
|
||||
// text is too long : scale it
|
||||
if (song_title_bounds.width > 0.88f * m_size) {
|
||||
song_title.setScale(0.88f * m_size / song_title_bounds.width, 1.0f);
|
||||
if (song_title_bounds.width > 0.88f * get_size()) {
|
||||
song_title.setScale(0.88f * get_size() / song_title_bounds.width, 1.0f);
|
||||
}
|
||||
song_title.setPosition(18.f/160.f,9.f/160.f);
|
||||
target.draw(song_title, states);
|
||||
@ -186,26 +178,26 @@ namespace MusicSelect {
|
||||
|
||||
void ColoredMessagePanel::draw(sf::RenderTarget& target, sf::RenderStates states) const {
|
||||
states.transform *= getTransform();
|
||||
sf::RectangleShape frame{{m_size*0.9f, m_size*0.9f}};
|
||||
sf::RectangleShape frame{{get_size()*0.9f, get_size()*0.9f}};
|
||||
frame.setFillColor(sf::Color::Black);
|
||||
frame.setOutlineThickness(1.f);
|
||||
frame.setOutlineColor(m_color);
|
||||
frame.setOrigin(frame.getSize().x / 2.f, frame.getSize().y / 2.f);
|
||||
frame.setPosition(m_size/2.f, m_size/2.f);
|
||||
frame.setPosition(get_size()/2.f, get_size()/2.f);
|
||||
target.draw(frame, states);
|
||||
|
||||
sf::Text message;
|
||||
message.setFont(m_resources.noto_sans_medium);
|
||||
message.setString(m_message);
|
||||
message.setCharacterSize(static_cast<unsigned int>(0.1f*m_size));
|
||||
message.setCharacterSize(static_cast<unsigned int>(0.1f*get_size()));
|
||||
message.setFillColor(m_color);
|
||||
auto bounds = message.getLocalBounds();
|
||||
message.setOrigin(bounds.left+bounds.width*0.5f, bounds.top+bounds.height*0.5f);
|
||||
auto biggest_side = std::max(bounds.width, bounds.height);
|
||||
if (biggest_side > m_size*0.8f) {
|
||||
message.setScale(m_size*0.8f / biggest_side, m_size*0.8f / biggest_side);
|
||||
if (biggest_side > get_size()*0.8f) {
|
||||
message.setScale(get_size()*0.8f / biggest_side, get_size()*0.8f / biggest_side);
|
||||
}
|
||||
message.setPosition(m_size*0.5f, m_size*0.5f);
|
||||
message.setPosition(get_size()*0.5f, get_size()*0.5f);
|
||||
target.draw(message, states);
|
||||
}
|
||||
}
|
||||
|
@ -19,13 +19,13 @@ namespace MusicSelect {
|
||||
// of the music select screen, be it nothing, a category indicator, or a song
|
||||
class Panel : public sf::Drawable, public sf::Transformable {
|
||||
public:
|
||||
Panel(const float& size, SharedResources& resources) : m_size(size), m_resources(resources) {};
|
||||
Panel(SharedResources& resources) : m_resources(resources) {};
|
||||
// What happens when you click on the panel
|
||||
virtual void click(Ribbon& ribbon, std::size_t from_button_index) = 0;
|
||||
virtual ~Panel() = default;
|
||||
protected:
|
||||
const float& m_size;
|
||||
SharedResources& m_resources;
|
||||
float get_size() const;
|
||||
};
|
||||
|
||||
class EmptyPanel final : public Panel {
|
||||
@ -38,7 +38,7 @@ namespace MusicSelect {
|
||||
|
||||
class ColoredMessagePanel final : public Panel {
|
||||
public:
|
||||
ColoredMessagePanel(const float& size, SharedResources& resources, const sf::Color& color, const std::string& message) : Panel(size, resources), m_color(color), m_message(message) {};
|
||||
ColoredMessagePanel(SharedResources& resources, const sf::Color& color, const std::string& message) : Panel(resources), m_color(color), m_message(message) {};
|
||||
void click(Ribbon& ribbon, std::size_t from_button_index) override {return;};
|
||||
private:
|
||||
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
||||
@ -48,7 +48,7 @@ namespace MusicSelect {
|
||||
|
||||
class ColorPanel final : public Panel {
|
||||
public:
|
||||
ColorPanel(const float& size, SharedResources& resources, const sf::Color& t_color) : Panel(size, resources), m_color(t_color) {};
|
||||
ColorPanel(SharedResources& resources, const sf::Color& t_color) : Panel(resources), m_color(t_color) {};
|
||||
void click(Ribbon& ribbon, std::size_t from_button_index) override {return;};
|
||||
private:
|
||||
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
||||
@ -57,7 +57,7 @@ namespace MusicSelect {
|
||||
|
||||
class CategoryPanel final : public Panel {
|
||||
public:
|
||||
explicit CategoryPanel(const float& size, SharedResources& resources, const std::string& t_label) : Panel(size, resources), m_label(t_label) {};
|
||||
explicit CategoryPanel(SharedResources& resources, const std::string& t_label) : Panel(resources), m_label(t_label) {};
|
||||
void click(Ribbon& ribbon, std::size_t from_button_index) override;
|
||||
private:
|
||||
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
||||
@ -79,7 +79,7 @@ namespace MusicSelect {
|
||||
|
||||
class SongPanel final : public SelectablePanel {
|
||||
public:
|
||||
explicit SongPanel(const float& size, SharedResources& resources, const Data::Song& t_song) : SelectablePanel(size, resources), m_song(t_song) {};
|
||||
explicit SongPanel(SharedResources& resources, const Data::Song& t_song) : SelectablePanel(resources), m_song(t_song) {};
|
||||
void click(Ribbon& ribbon, std::size_t from_button_index) override;
|
||||
void unselect() override;
|
||||
std::optional<ChartSelection> get_selected_chart() const override;
|
||||
|
@ -64,13 +64,11 @@ namespace MusicSelect {
|
||||
return clock.getElapsedTime() / m_time_factor > sf::milliseconds(300);
|
||||
}
|
||||
|
||||
Ribbon::Ribbon(SharedResources& t_resources, float& panel_size, float& panel_spacing) :
|
||||
Ribbon::Ribbon(SharedResources& t_resources) :
|
||||
m_layout(),
|
||||
m_move_animation(),
|
||||
m_resources(t_resources),
|
||||
empty_song(),
|
||||
m_panel_size(panel_size),
|
||||
m_panel_spacing(panel_spacing)
|
||||
empty_song()
|
||||
{
|
||||
std::cout << "Loaded MusicSelect::Ribbon" << std::endl;
|
||||
}
|
||||
@ -89,19 +87,19 @@ namespace MusicSelect {
|
||||
categories
|
||||
[std::string(1, letter)]
|
||||
.push_back(
|
||||
std::make_shared<SongPanel>(m_panel_size, m_resources, song)
|
||||
std::make_shared<SongPanel>(m_resources, song)
|
||||
);
|
||||
} else if ('a' <= letter and letter <= 'z') {
|
||||
categories
|
||||
[std::string(1, 'A' + (letter - 'a'))]
|
||||
.push_back(
|
||||
std::make_shared<SongPanel>(m_panel_size, m_resources, song)
|
||||
std::make_shared<SongPanel>(m_resources, song)
|
||||
);
|
||||
} else {
|
||||
categories["?"].push_back(std::make_shared<SongPanel>(m_panel_size, m_resources, song));
|
||||
categories["?"].push_back(std::make_shared<SongPanel>(m_resources, song));
|
||||
}
|
||||
} else {
|
||||
categories["?"].push_back(std::make_shared<SongPanel>(m_panel_size, m_resources, song));
|
||||
categories["?"].push_back(std::make_shared<SongPanel>(m_resources, song));
|
||||
}
|
||||
}
|
||||
layout_from_category_map(categories);
|
||||
@ -110,15 +108,15 @@ namespace MusicSelect {
|
||||
void Ribbon::test_sort() {
|
||||
m_layout.clear();
|
||||
m_layout.push_back({
|
||||
std::make_shared<EmptyPanel>(m_panel_size, m_resources),
|
||||
std::make_shared<CategoryPanel>(m_panel_size, m_resources, "A"),
|
||||
std::make_shared<CategoryPanel>(m_panel_size, m_resources, "truc")
|
||||
std::make_shared<EmptyPanel>(m_resources),
|
||||
std::make_shared<CategoryPanel>(m_resources, "A"),
|
||||
std::make_shared<CategoryPanel>(m_resources, "truc")
|
||||
});
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
m_layout.push_back({
|
||||
std::make_shared<EmptyPanel>(m_panel_size, m_resources),
|
||||
std::make_shared<EmptyPanel>(m_panel_size, m_resources),
|
||||
std::make_shared<EmptyPanel>(m_panel_size, m_resources)
|
||||
std::make_shared<EmptyPanel>(m_resources),
|
||||
std::make_shared<EmptyPanel>(m_resources),
|
||||
std::make_shared<EmptyPanel>(m_resources)
|
||||
});
|
||||
}
|
||||
fill_layout();
|
||||
@ -134,7 +132,7 @@ namespace MusicSelect {
|
||||
for (int i = 0; i < category_size; i++) {
|
||||
categories[std::string(1, letter)].push_back(
|
||||
std::make_shared<ColorPanel>(
|
||||
m_panel_size, m_resources,
|
||||
m_resources,
|
||||
sf::Color(
|
||||
panel_hue_generator.generate(),
|
||||
panel_hue_generator.generate(),
|
||||
@ -155,7 +153,7 @@ namespace MusicSelect {
|
||||
auto category_size = category_size_generator.generate();
|
||||
for (int i = 0; i < category_size; i++) {
|
||||
categories[std::string(1, letter)].push_back(
|
||||
std::make_shared<SongPanel>(m_panel_size, m_resources, this->empty_song)
|
||||
std::make_shared<SongPanel>(m_resources, this->empty_song)
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -184,7 +182,7 @@ namespace MusicSelect {
|
||||
for (auto &&[category, panels] : categories) {
|
||||
if (not panels.empty()) {
|
||||
std::vector<std::shared_ptr<Panel>> current_column;
|
||||
current_column.push_back(std::make_shared<CategoryPanel>(m_panel_size, m_resources, category));
|
||||
current_column.push_back(std::make_shared<CategoryPanel>(m_resources, category));
|
||||
for (auto &&panel : panels) {
|
||||
if (current_column.size() == 3) {
|
||||
m_layout.push_back({current_column[0], current_column[1], current_column[2]});
|
||||
@ -195,7 +193,7 @@ namespace MusicSelect {
|
||||
}
|
||||
if (not current_column.empty()) {
|
||||
while (current_column.size() < 3) {
|
||||
current_column.push_back(std::make_shared<EmptyPanel>(m_panel_size, m_resources));
|
||||
current_column.push_back(std::make_shared<EmptyPanel>(m_resources));
|
||||
}
|
||||
m_layout.push_back({current_column[0], current_column[1], current_column[2]});
|
||||
}
|
||||
@ -275,14 +273,19 @@ namespace MusicSelect {
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
auto panel_step = (
|
||||
(
|
||||
m_resources.preferences.layout.panel_size +
|
||||
m_resources.preferences.layout.panel_spacing
|
||||
) * m_resources.preferences.screen.width
|
||||
);
|
||||
for (int column_offset = -1; column_offset <= 4; column_offset++) {
|
||||
std::size_t actual_column = (column_zero + column_offset + m_layout.size()) % m_layout.size();
|
||||
for (int row = 0; row < 3; row++) {
|
||||
auto panel = m_layout.at(actual_column).at(row);
|
||||
panel->setPosition(
|
||||
(static_cast<float>(relative_column_zero + column_offset) - float_position) * (m_panel_size+m_panel_spacing),
|
||||
row * (m_panel_size+m_panel_spacing)
|
||||
(static_cast<float>(relative_column_zero + column_offset) - float_position) * (panel_step),
|
||||
row * (panel_step)
|
||||
);
|
||||
target.draw(*panel, states);
|
||||
}
|
||||
@ -290,11 +293,17 @@ namespace MusicSelect {
|
||||
}
|
||||
|
||||
void Ribbon::draw_without_animation(sf::RenderTarget &target, sf::RenderStates states) const {
|
||||
auto panel_step = (
|
||||
(
|
||||
m_resources.preferences.layout.panel_size +
|
||||
m_resources.preferences.layout.panel_spacing
|
||||
) * m_resources.preferences.screen.width
|
||||
);
|
||||
for (int column = -1; column <= 4; column++) {
|
||||
int actual_column_index = (column + m_position + m_layout.size()) % m_layout.size();
|
||||
for (int row = 0; row < 3; row++) {
|
||||
auto panel = m_layout.at(actual_column_index).at(row);
|
||||
panel->setPosition(column * (m_panel_size+m_panel_spacing), row * (m_panel_size+m_panel_spacing));
|
||||
panel->setPosition(column * (panel_step), row * (panel_step));
|
||||
target.draw(*panel, states);
|
||||
}
|
||||
}
|
||||
@ -304,6 +313,7 @@ namespace MusicSelect {
|
||||
if (debug) {
|
||||
ImGui::Begin("Ribbon Debug", &debug); {
|
||||
ImGui::SliderFloat("Time Slowdown Factor", &m_time_factor, 1.f, 10.f);
|
||||
/*
|
||||
if (ImGui::CollapsingHeader("Panels")) {
|
||||
auto panel_size = static_cast<int>(m_panel_size);
|
||||
if(ImGui::InputInt("Size", &panel_size)) {
|
||||
@ -320,6 +330,7 @@ namespace MusicSelect {
|
||||
m_panel_spacing = static_cast<std::size_t>(panel_spacing);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
@ -329,22 +340,22 @@ namespace MusicSelect {
|
||||
void Ribbon::fill_layout() {
|
||||
if (m_layout.empty()) {
|
||||
m_layout.push_back({
|
||||
std::make_shared<ColoredMessagePanel>(m_panel_size, m_resources, sf::Color::Red, "- EMPTY -"),
|
||||
std::make_shared<ColoredMessagePanel>(m_panel_size, m_resources, sf::Color::Red, "- EMPTY -"),
|
||||
std::make_shared<ColoredMessagePanel>(m_panel_size, m_resources, sf::Color::Red, "- EMPTY -"),
|
||||
std::make_shared<ColoredMessagePanel>(m_resources, sf::Color::Red, "- EMPTY -"),
|
||||
std::make_shared<ColoredMessagePanel>(m_resources, sf::Color::Red, "- EMPTY -"),
|
||||
std::make_shared<ColoredMessagePanel>(m_resources, sf::Color::Red, "- EMPTY -"),
|
||||
});
|
||||
m_layout.push_back({
|
||||
std::make_shared<ColoredMessagePanel>(m_panel_size, m_resources, sf::Color::Red, "- EMPTY -"),
|
||||
std::make_shared<ColoredMessagePanel>(m_panel_size, m_resources, sf::Color::Red, "- EMPTY -"),
|
||||
std::make_shared<ColoredMessagePanel>(m_panel_size, m_resources, sf::Color::Red, "- EMPTY -"),
|
||||
std::make_shared<ColoredMessagePanel>(m_resources, sf::Color::Red, "- EMPTY -"),
|
||||
std::make_shared<ColoredMessagePanel>(m_resources, sf::Color::Red, "- EMPTY -"),
|
||||
std::make_shared<ColoredMessagePanel>(m_resources, sf::Color::Red, "- EMPTY -"),
|
||||
});
|
||||
return;
|
||||
}
|
||||
while (m_layout.size() < 4) {
|
||||
m_layout.push_back({
|
||||
std::make_shared<EmptyPanel>(m_panel_size, m_resources),
|
||||
std::make_shared<EmptyPanel>(m_panel_size, m_resources),
|
||||
std::make_shared<EmptyPanel>(m_panel_size, m_resources),
|
||||
std::make_shared<EmptyPanel>(m_resources),
|
||||
std::make_shared<EmptyPanel>(m_resources),
|
||||
std::make_shared<EmptyPanel>(m_resources),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <SFML/Graphics/Drawable.hpp>
|
||||
#include <SFML/Graphics/Transformable.hpp>
|
||||
|
||||
#include "../../Data/Preferences.hpp"
|
||||
#include "../../Data/SongList.hpp"
|
||||
#include "../../Toolkit/AffineTransform.hpp"
|
||||
#include "../../Toolkit/Debuggable.hpp"
|
||||
@ -36,7 +37,7 @@ namespace MusicSelect {
|
||||
// It can be sorted in a number of ways
|
||||
class Ribbon final : public sf::Drawable, public sf::Transformable, public Toolkit::Debuggable {
|
||||
public:
|
||||
Ribbon(SharedResources& t_resources, float& panel_size, float& panel_spacing);
|
||||
Ribbon(SharedResources& t_resources);
|
||||
void title_sort(const Data::SongList& song_list);
|
||||
void test_sort();
|
||||
void test2_sort();
|
||||
@ -47,7 +48,6 @@ namespace MusicSelect {
|
||||
void move_left();
|
||||
void move_to_next_category(const std::size_t& from_button_index);
|
||||
void draw_debug() override;
|
||||
std::string m_global_chart_dif;
|
||||
private:
|
||||
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
||||
void draw_with_animation(sf::RenderTarget& target, sf::RenderStates states) const;
|
||||
@ -61,7 +61,5 @@ namespace MusicSelect {
|
||||
SharedResources& m_resources;
|
||||
float m_time_factor = 1.f;
|
||||
Data::Song empty_song;
|
||||
float& m_panel_size;
|
||||
float& m_panel_spacing;
|
||||
};
|
||||
}
|
@ -3,7 +3,8 @@
|
||||
#include <iostream>
|
||||
|
||||
namespace MusicSelect {
|
||||
SharedResources::SharedResources() :
|
||||
SharedResources::SharedResources(Data::Preferences& p) :
|
||||
preferences(p),
|
||||
covers(),
|
||||
fallback_cover(),
|
||||
noto_sans_medium()
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <SFML/System.hpp>
|
||||
|
||||
#include "../../Resources/Autoloader.hpp"
|
||||
#include "../../Data/Preferences.hpp"
|
||||
#include "../../Data/SongList.hpp"
|
||||
|
||||
#include "Panel.hpp"
|
||||
@ -22,8 +23,10 @@ namespace MusicSelect {
|
||||
};
|
||||
|
||||
struct SharedResources {
|
||||
SharedResources();
|
||||
SharedResources(Data::Preferences& p);
|
||||
|
||||
Data::Preferences& preferences;
|
||||
|
||||
Textures::Autoloader covers;
|
||||
sf::Texture fallback_cover;
|
||||
|
||||
|
@ -4,11 +4,10 @@
|
||||
|
||||
namespace MusicSelect {
|
||||
|
||||
BigCover::BigCover(SharedResources& resources, const float& size) :
|
||||
m_resources(resources),
|
||||
m_size(size),
|
||||
m_cover_fallback({size,size})
|
||||
BigCover::BigCover(SharedResources& resources) :
|
||||
m_resources(resources)
|
||||
{
|
||||
m_cover_fallback.setSize({get_size(), get_size()});
|
||||
m_cover_fallback.setFillColor(sf::Color::Transparent);
|
||||
m_cover_fallback.setOutlineThickness(1.f);
|
||||
m_cover_fallback.setOutlineColor(sf::Color::White);
|
||||
@ -35,7 +34,7 @@ namespace MusicSelect {
|
||||
}
|
||||
sf::Sprite cover{*(cover_texture->texture)};
|
||||
auto bounds = cover.getGlobalBounds();
|
||||
cover.setScale(m_size/bounds.width, m_size/bounds.height);
|
||||
cover.setScale(get_size()/bounds.width, get_size()/bounds.height);
|
||||
auto alpha = static_cast<std::uint8_t>(
|
||||
m_seconds_to_alpha.clampedTransform(
|
||||
selected_panel->selected_since.getElapsedTime().asSeconds()
|
||||
@ -45,14 +44,18 @@ namespace MusicSelect {
|
||||
target.draw(cover, states);
|
||||
}
|
||||
|
||||
SongInfo::SongInfo(SharedResources& resources, const float& width, const float& height) :
|
||||
SongInfo::SongInfo(SharedResources& resources) :
|
||||
m_resources(resources),
|
||||
m_width(width),
|
||||
m_height(height),
|
||||
m_big_cover(resources, width*0.42f)
|
||||
m_big_cover(resources)
|
||||
{
|
||||
m_big_cover.setOrigin(width*0.42f*0.5f, 0.f);
|
||||
m_big_cover.setPosition(width*0.5f, width*0.017f);
|
||||
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()
|
||||
);
|
||||
}
|
||||
|
||||
void SongInfo::draw(sf::RenderTarget& target, sf::RenderStates states) const {
|
||||
@ -76,18 +79,18 @@ namespace MusicSelect {
|
||||
song_title,
|
||||
m_resources.noto_sans_medium,
|
||||
static_cast<unsigned int>(
|
||||
0.026315789f*m_width
|
||||
0.026315789f*get_width()
|
||||
)
|
||||
};
|
||||
auto song_title_bounds = song_title_label.getLocalBounds();
|
||||
if (song_title_bounds.width > 0.42f * m_width) {
|
||||
song_title_label.setScale(0.42f * m_width / song_title_bounds.width, 1.0f);
|
||||
if (song_title_bounds.width > m_big_cover.get_size()) {
|
||||
song_title_label.setScale(m_big_cover.get_size() / song_title_bounds.width, 1.0f);
|
||||
}
|
||||
song_title_label.setFillColor(sf::Color::White);
|
||||
auto cover_pos = m_big_cover.getPosition();
|
||||
song_title_label.setPosition(
|
||||
m_width*(0.5f - (0.42f/2.f)),
|
||||
m_width*(0.017f + 0.42f + 0.01f)
|
||||
get_big_cover_x() - m_big_cover.get_size()/2.f,
|
||||
get_big_cover_y() + m_big_cover.get_size() + 0.01f*get_width()
|
||||
);
|
||||
target.draw(song_title_label);
|
||||
}
|
||||
@ -97,23 +100,22 @@ namespace MusicSelect {
|
||||
song_artist,
|
||||
m_resources.noto_sans_medium,
|
||||
static_cast<unsigned int>(
|
||||
0.02f*m_width
|
||||
0.02f*get_width()
|
||||
)
|
||||
};
|
||||
song_artist_label.setStyle(sf::Text::Italic);
|
||||
auto song_artist_bounds = song_artist_label.getLocalBounds();
|
||||
if (song_artist_bounds.width > 0.42f * m_width) {
|
||||
song_artist_label.setScale(0.42f * m_width / song_artist_bounds.width, 1.0f);
|
||||
if (song_artist_bounds.width > m_big_cover.get_size()) {
|
||||
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);
|
||||
auto cover_pos = m_big_cover.getPosition();
|
||||
song_artist_label.setPosition(
|
||||
m_width*(0.5f - (0.42f/2.f)),
|
||||
m_width*(0.017f + 0.42f + 0.01f + 0.04f)
|
||||
get_big_cover_x() - m_big_cover.get_size()/2.f,
|
||||
get_big_cover_y() + m_big_cover.get_size() + 0.05f*get_width()
|
||||
);
|
||||
target.draw(song_artist_label);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,11 @@ namespace MusicSelect {
|
||||
|
||||
class BigCover : public sf::Drawable, public sf::Transformable {
|
||||
public:
|
||||
BigCover(SharedResources& resources, const float& size);
|
||||
BigCover(SharedResources& resources);
|
||||
float get_size() const {return m_resources.preferences.layout.big_cover_size*m_resources.preferences.screen.width;};
|
||||
private:
|
||||
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
||||
SharedResources& m_resources;
|
||||
float m_size;
|
||||
sf::RectangleShape m_cover_fallback;
|
||||
const Toolkit::AffineTransform<float> m_seconds_to_alpha{0.0f, 0.3f, 0.f, 255.f};
|
||||
};
|
||||
@ -23,13 +23,14 @@ namespace MusicSelect {
|
||||
// Displays the song info on the top part of the screen
|
||||
class SongInfo : public sf::Drawable, public sf::Transformable {
|
||||
public:
|
||||
SongInfo(SharedResources& resources, const float& width, const float& height);
|
||||
SongInfo(SharedResources& resources);
|
||||
float get_width() const {return m_resources.preferences.screen.width;};
|
||||
float get_big_cover_x() const {return m_resources.preferences.layout.big_cover_x*get_width();};
|
||||
float get_big_cover_y() const {return m_resources.preferences.layout.big_cover_y*get_width();};
|
||||
private:
|
||||
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
||||
void draw_song_title(sf::RenderTarget& target) const;
|
||||
SharedResources& m_resources;
|
||||
const float& m_width;
|
||||
const float& m_height;
|
||||
BigCover m_big_cover;
|
||||
};
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ import argparse
|
||||
from path import Path
|
||||
from PIL import Image
|
||||
import json
|
||||
import random
|
||||
from functools import partial
|
||||
from faker import Faker
|
||||
fake = Faker()
|
||||
|
||||
@ -14,6 +16,13 @@ parser.add_argument("--random-name", action="store_true", dest="random_name")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
DIF_NAMES = [
|
||||
lambda : "BSC",
|
||||
lambda : "ADV",
|
||||
lambda : "EXT",
|
||||
partial(fake.lexify, text="????", letters="abcdefghijklmnopqrstuvwxyz"),
|
||||
]
|
||||
|
||||
def create_song_folder_from_image(image: Path):
|
||||
song_name = fake.sentence().strip(".") if args.random_name else image.stem
|
||||
song_artist = fake.name()
|
||||
@ -30,15 +39,16 @@ def create_song_folder_from_image(image: Path):
|
||||
"album cover path": output_image.name,
|
||||
"BPM": 120,
|
||||
"offset": 0,
|
||||
},
|
||||
"data": {
|
||||
"BSC" : {
|
||||
"level": 1,
|
||||
"resolution": 4,
|
||||
"notes": []
|
||||
}
|
||||
}
|
||||
}
|
||||
data = memon.setdefault("data", {})
|
||||
for i in range(random.randint(1,6)):
|
||||
data[DIF_NAMES[3 if i > 3 else i]()] = {
|
||||
"level": random.randint(1,10),
|
||||
"notes": [],
|
||||
"resolution": 4
|
||||
}
|
||||
|
||||
json.dump(
|
||||
memon,
|
||||
open(song_folder/f"{song_name}.memon", "w"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user