1
0
mirror of synced 2025-02-02 20:37:25 +01:00

Refactoring

This commit is contained in:
Stepland 2020-03-07 22:44:09 +01:00
parent 3f9c482d25
commit de51fb4fa5
22 changed files with 199 additions and 215 deletions

View File

@ -38,6 +38,8 @@ sources = [
'src/Data/Song.cpp', 'src/Data/Song.cpp',
'src/Drawables/BlackFrame.hpp', 'src/Drawables/BlackFrame.hpp',
'src/Drawables/BlackFrame.cpp', 'src/Drawables/BlackFrame.cpp',
'src/Drawables/ButtonHighlight.hpp',
'src/Drawables/ButtonHighlight.cpp',
'src/Resources/TextureCache.cpp', 'src/Resources/TextureCache.cpp',
'src/Resources/TextureCache.hpp', 'src/Resources/TextureCache.hpp',
'src/Resources/Marker.cpp', 'src/Resources/Marker.cpp',
@ -45,8 +47,6 @@ sources = [
# 'src/Resources/CoverAtlas.hpp', # 'src/Resources/CoverAtlas.hpp',
# 'src/Resources/CoverAtlas.cpp', # 'src/Resources/CoverAtlas.cpp',
# 'src/Screens/Gameplay.hpp', # 'src/Screens/Gameplay.hpp',
'src/Screens/MusicSelect/ButtonHighlight.hpp',
'src/Screens/MusicSelect/ButtonHighlight.cpp',
'src/Screens/MusicSelect/DensityGraph.hpp', 'src/Screens/MusicSelect/DensityGraph.hpp',
'src/Screens/MusicSelect/DensityGraph.cpp', 'src/Screens/MusicSelect/DensityGraph.cpp',
'src/Screens/MusicSelect/MusicPreview.hpp', 'src/Screens/MusicSelect/MusicPreview.hpp',

View File

@ -131,19 +131,19 @@ namespace Data {
}; };
struct HoldsPreferences { struct HoldsPreferences {
HoldsPreferences(Preferences& t_preferences) : m_preferences(t_preferences) {}; HoldsPreferences(Preferences& t_preferences) : preferences(t_preferences) {};
float get_screen_width() const {return static_cast<float>(m_preferences.screen.width);}; float get_screen_width() const {return static_cast<float>(preferences.screen.width);};
float get_screen_height() const {return static_cast<float>(m_preferences.screen.height);}; float get_screen_height() const {return static_cast<float>(preferences.screen.height);};
float get_panel_size() const {return m_preferences.layout.panel_size*get_screen_width();}; float get_panel_size() const {return preferences.layout.panel_size*get_screen_width();};
float get_panel_spacing() const {return m_preferences.layout.panel_spacing*get_screen_width();}; float get_panel_spacing() const {return preferences.layout.panel_spacing*get_screen_width();};
float get_ribbon_x() const {return m_preferences.layout.ribbon_x*get_screen_width();}; float get_ribbon_x() const {return preferences.layout.ribbon_x*get_screen_width();};
float get_ribbon_y() const {return m_preferences.layout.ribbon_y*get_screen_width();}; float get_ribbon_y() const {return preferences.layout.ribbon_y*get_screen_width();};
float get_panel_step() const {return m_preferences.layout.panel_step()*get_screen_width();}; float get_panel_step() const {return preferences.layout.panel_step()*get_screen_width();};
float get_big_cover_x() const {return m_preferences.layout.big_cover_x*get_screen_width();}; float get_big_cover_x() const {return preferences.layout.big_cover_x*get_screen_width();};
float get_big_cover_y() const {return m_preferences.layout.big_cover_y*get_screen_width();}; float get_big_cover_y() const {return preferences.layout.big_cover_y*get_screen_width();};
float get_big_level_x() const {return m_preferences.layout.big_level_x*get_screen_width();}; float get_big_level_x() const {return preferences.layout.big_level_x*get_screen_width();};
float get_big_level_y() const {return m_preferences.layout.big_level_y*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 m_preferences.layout.upper_part_height*get_screen_width();}; float get_upper_part_height() const {return preferences.layout.upper_part_height*get_screen_width();};
Preferences& m_preferences; Preferences& preferences;
}; };
} }

View File

@ -1,8 +1,8 @@
#include "ButtonHighlight.hpp" #include "ButtonHighlight.hpp"
namespace MusicSelect { namespace Drawables {
ButtonHighlight::ButtonHighlight(SharedResources& resources) : ButtonHighlight::ButtonHighlight(Data::Preferences& t_preferences) :
HoldsSharedResources(resources), Data::HoldsPreferences(t_preferences),
m_highlight(), m_highlight(),
m_time_to_alpha(0.f, 0.25f, 255.f, 0.f) m_time_to_alpha(0.f, 0.25f, 255.f, 0.f)
{ {

View File

@ -5,15 +5,14 @@
#include <SFML/System.hpp> #include <SFML/System.hpp>
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include "../../Data/Buttons.hpp" #include "../Data/Buttons.hpp"
#include "../../Toolkit/AffineTransform.hpp" #include "../Data/Preferences.hpp"
#include "../Toolkit/AffineTransform.hpp"
#include "SharedResources.hpp" namespace Drawables {
class ButtonHighlight : public sf::Drawable, public sf::Transformable, public Data::HoldsPreferences {
namespace MusicSelect {
class ButtonHighlight : public sf::Drawable, public sf::Transformable, public HoldsSharedResources {
public: public:
ButtonHighlight(SharedResources& resources); ButtonHighlight(Data::Preferences& t_preferences);
void button_pressed(Data::Button button); void button_pressed(Data::Button button);
private: private:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;

View File

@ -19,11 +19,6 @@ int main(int, char const **) {
const std::string jujube_path = whereami::executable_dir(); const std::string jujube_path = whereami::executable_dir();
Data::Preferences preferences{jujube_path}; Data::Preferences preferences{jujube_path};
auto markers = Resources::load_markers(jujube_path);
if (markers.find(preferences.options.marker) == markers.end()) {
preferences.options.marker = markers.begin()->first;
}
sf::ContextSettings settings; sf::ContextSettings settings;
settings.antialiasingLevel = 8; settings.antialiasingLevel = 8;
sf::RenderWindow window{ sf::RenderWindow window{
@ -36,12 +31,11 @@ int main(int, char const **) {
settings settings
}; };
Data::SongList song_list{jujube_path}; Data::SongList song_list{jujube_path};
MusicSelect::Screen music_select{ MusicSelect::SharedResources music_select_resources{preferences};
song_list, if (music_select_resources.markers.find(preferences.options.marker) == music_select_resources.markers.end()) {
preferences, preferences.options.marker = music_select_resources.markers.begin()->first;
markers, }
}; MusicSelect::Screen music_select{song_list, music_select_resources};
music_select.select_chart(window); music_select.select_chart(window);
/* /*
while (true) { while (true) {

View File

@ -13,20 +13,13 @@
#include "Panels/Panel.hpp" #include "Panels/Panel.hpp"
#include "PanelLayout.hpp" #include "PanelLayout.hpp"
MusicSelect::Screen::Screen( MusicSelect::Screen::Screen(const Data::SongList& t_song_list, SharedResources& t_resources) :
const Data::SongList& t_song_list, HoldsSharedResources(t_resources),
Data::Preferences& t_preferences,
const Resources::Markers& t_markers
) :
song_list(t_song_list), song_list(t_song_list),
resources(t_preferences, t_markers), ribbon(PanelLayout::title_sort(t_song_list, t_resources), t_resources),
markers(t_markers), song_info(t_resources),
ribbon(PanelLayout::title_sort(t_song_list, resources), resources), main_option_page(t_resources),
song_info(resources), black_frame(t_resources.preferences)
button_highlight(resources),
main_option_page(resources),
black_frame(t_preferences),
key_mapping()
{ {
panel_filter.setFillColor(sf::Color(0,0,0,128)); panel_filter.setFillColor(sf::Color(0,0,0,128));
std::cout << "loaded MusicSelect::Screen" << std::endl; std::cout << "loaded MusicSelect::Screen" << std::endl;
@ -37,14 +30,8 @@ void MusicSelect::Screen::select_chart(sf::RenderWindow& window) {
ImGui::SFML::Init(window); ImGui::SFML::Init(window);
bool chart_selected = false; bool chart_selected = false;
sf::Clock imguiClock; sf::Clock imguiClock;
ribbon.setPosition( ribbon.setPosition(get_ribbon_x(), get_ribbon_y());
resources.m_preferences.layout.ribbon_x*resources.m_preferences.screen.width, resources.button_highlight.setPosition(get_ribbon_x(), get_ribbon_y());
resources.m_preferences.layout.ribbon_y*resources.m_preferences.screen.width
);
button_highlight.setPosition(
resources.m_preferences.layout.ribbon_x*resources.m_preferences.screen.width,
resources.m_preferences.layout.ribbon_y*resources.m_preferences.screen.width
);
panel_filter.setSize(sf::Vector2f{window.getSize()}); panel_filter.setSize(sf::Vector2f{window.getSize()});
while ((not chart_selected) and window.isOpen()) { while ((not chart_selected) and window.isOpen()) {
sf::Event event; sf::Event event;
@ -63,19 +50,13 @@ void MusicSelect::Screen::select_chart(sf::RenderWindow& window) {
case sf::Event::Resized: case sf::Event::Resized:
// update the view to the new size of the window // update the view to the new size of the window
window.setView(sf::View({0, 0, static_cast<float>(event.size.width), static_cast<float>(event.size.height)})); window.setView(sf::View({0, 0, static_cast<float>(event.size.width), static_cast<float>(event.size.height)}));
resources.m_preferences.screen.height = event.size.height; resources.preferences.screen.height = event.size.height;
resources.m_preferences.screen.width = event.size.width; resources.preferences.screen.width = event.size.width;
ribbon.setPosition( ribbon.setPosition(get_ribbon_x(), get_ribbon_y());
resources.m_preferences.layout.ribbon_x*resources.m_preferences.screen.width, resources.button_highlight.setPosition(get_ribbon_x(), get_ribbon_y());
resources.m_preferences.layout.ribbon_y*resources.m_preferences.screen.width
);
button_highlight.setPosition(
resources.m_preferences.layout.ribbon_x*resources.m_preferences.screen.width,
resources.m_preferences.layout.ribbon_y*resources.m_preferences.screen.width
);
panel_filter.setSize(sf::Vector2f{window.getSize()}); panel_filter.setSize(sf::Vector2f{window.getSize()});
if (not resources.options_state.empty()) { if (not resources.options_state.empty()) {
resources.options_state.top().get().update(); resources.options_state.back().get().update();
} }
break; break;
default: default:
@ -88,9 +69,9 @@ void MusicSelect::Screen::select_chart(sf::RenderWindow& window) {
window.draw(song_info); window.draw(song_info);
if (not resources.options_state.empty()) { if (not resources.options_state.empty()) {
window.draw(panel_filter); window.draw(panel_filter);
window.draw(resources.options_state.top()); window.draw(resources.options_state.back());
} }
window.draw(button_highlight); window.draw(resources.button_highlight);
window.draw(black_frame); window.draw(black_frame);
ribbon.draw_debug(); ribbon.draw_debug();
draw_debug(); draw_debug();
@ -107,11 +88,11 @@ void MusicSelect::Screen::draw_debug() {
if (ImGui::CollapsingHeader("Preferences")) { if (ImGui::CollapsingHeader("Preferences")) {
if (ImGui::TreeNode("screen")) { if (ImGui::TreeNode("screen")) {
ImGui::TextUnformatted("width : "); ImGui::SameLine(); ImGui::TextUnformatted("width : "); ImGui::SameLine();
ImGui::Text("%s", std::to_string(resources.m_preferences.screen.width).c_str()); ImGui::Text("%s", std::to_string(resources.preferences.screen.width).c_str());
ImGui::TextUnformatted("height : "); ImGui::SameLine(); ImGui::TextUnformatted("height : "); ImGui::SameLine();
ImGui::Text("%s", std::to_string(resources.m_preferences.screen.height).c_str()); ImGui::Text("%s", std::to_string(resources.preferences.screen.height).c_str());
ImGui::TextUnformatted("fullscreen : "); ImGui::SameLine(); ImGui::TextUnformatted("fullscreen : "); ImGui::SameLine();
ImGui::Text("%s", resources.m_preferences.screen.fullscreen ? "true" : "false"); ImGui::Text("%s", resources.preferences.screen.fullscreen ? "true" : "false");
ImGui::TreePop(); ImGui::TreePop();
} }
if (ImGui::TreeNode("layout")) { if (ImGui::TreeNode("layout")) {
@ -120,10 +101,19 @@ void MusicSelect::Screen::draw_debug() {
} }
if (ImGui::TreeNode("options")) { if (ImGui::TreeNode("options")) {
ImGui::TextUnformatted("marker : "); ImGui::SameLine(); ImGui::TextUnformatted("marker : "); ImGui::SameLine();
ImGui::Text("%s", resources.m_preferences.options.marker.c_str()); ImGui::Text("%s", resources.preferences.options.marker.c_str());
ImGui::TreePop(); ImGui::TreePop();
} }
} }
if (ImGui::CollapsingHeader("Options Menu Stack")) {
if (resources.options_state.empty()) {
ImGui::TextUnformatted("- empty -");
} else {
for (auto &&i : resources.options_state) {
ImGui::Text("%s", typeid(i.get()).name());
}
}
}
} }
ImGui::End(); ImGui::End();
} }
@ -135,13 +125,13 @@ void MusicSelect::Screen::handle_key_press(const sf::Event::KeyEvent& key_event)
if (not resources.options_state.empty()) { if (not resources.options_state.empty()) {
// Safety measure, pressing escape will alway pop the menu page // Safety measure, pressing escape will alway pop the menu page
if (key_event.code == sf::Keyboard::Escape) { if (key_event.code == sf::Keyboard::Escape) {
resources.options_state.pop(); resources.options_state.pop_back();
if (not resources.options_state.empty()) { if (not resources.options_state.empty()) {
resources.options_state.top().get().update(); resources.options_state.back().get().update();
} }
output_used = true; output_used = true;
} else { } else {
output_used = resources.options_state.top().get().handle_raw_input(key_event); output_used = resources.options_state.back().get().handle_raw_input(key_event);
} }
} }
if (output_used) { if (output_used) {
@ -169,12 +159,10 @@ void MusicSelect::Screen::handle_mouse_click(const sf::Event::MouseButtonEvent&
sf::Vector2i mouse_position{mouse_button_event.x, mouse_button_event.y}; sf::Vector2i mouse_position{mouse_button_event.x, mouse_button_event.y};
sf::Vector2i ribbon_origin{ sf::Vector2i ribbon_origin{
static_cast<int>(resources.get_ribbon_x()), static_cast<int>(get_ribbon_x()),
static_cast<int>(resources.get_ribbon_y()) static_cast<int>(get_ribbon_y())
}; };
auto panels_area_size = static_cast<int>( auto panels_area_size = static_cast<int>(get_panel_size() * 4.f + get_panel_spacing() * 3.f);
resources.get_panel_size() * 4.f + resources.get_panel_spacing() * 3.f
);
sf::IntRect panels_area{ribbon_origin, sf::Vector2i{panels_area_size, panels_area_size}}; sf::IntRect panels_area{ribbon_origin, sf::Vector2i{panels_area_size, panels_area_size}};
if (not panels_area.contains(mouse_position)) { if (not panels_area.contains(mouse_position)) {
return; return;
@ -195,7 +183,7 @@ void MusicSelect::Screen::handle_mouse_click(const sf::Event::MouseButtonEvent&
} }
void MusicSelect::Screen::press_button(const Data::Button& button) { void MusicSelect::Screen::press_button(const Data::Button& button) {
button_highlight.button_pressed(button); resources.button_highlight.button_pressed(button);
auto button_index = Data::button_to_index(button); auto button_index = Data::button_to_index(button);
if (button_index < 12) { if (button_index < 12) {
ribbon.click_on(button); ribbon.click_on(button);
@ -208,8 +196,15 @@ void MusicSelect::Screen::press_button(const Data::Button& button) {
ribbon.move_right(); ribbon.move_right();
break; break;
case Data::Button::B15: // Options Menu case Data::Button::B15: // Options Menu
resources.options_state.push(main_option_page); if (resources.options_state.empty()) {
resources.options_state.top().get().update(); resources.options_state.push_back(main_option_page);
resources.options_state.back().get().update();
} else {
resources.options_state.pop_back();
if (not resources.options_state.empty()) {
resources.options_state.back().get().update();
}
}
break; break;
default: default:
break; break;

View File

@ -16,7 +16,6 @@
#include "Ribbon.hpp" #include "Ribbon.hpp"
#include "SongInfo.hpp" #include "SongInfo.hpp"
#include "SharedResources.hpp" #include "SharedResources.hpp"
#include "ButtonHighlight.hpp"
#include "OptionPage.hpp" #include "OptionPage.hpp"
namespace MusicSelect { namespace MusicSelect {
@ -24,12 +23,11 @@ namespace MusicSelect {
class SongPanel; class SongPanel;
// The music select screen is created only once // The music select screen is created only once
// it loads a cache of available songs in the song_list attribute // it loads a cache of available songs in the song_list attribute
class Screen : public Toolkit::Debuggable { class Screen : public Toolkit::Debuggable, public HoldsSharedResources {
public: public:
Screen( Screen(
const Data::SongList& t_song_list, const Data::SongList& t_song_list,
Data::Preferences& t_preferences, SharedResources& t_resources
const Resources::Markers& t_markers
); );
void select_chart(sf::RenderWindow& window); void select_chart(sf::RenderWindow& window);
void draw_debug() override; void draw_debug() override;
@ -37,14 +35,9 @@ namespace MusicSelect {
// Data // Data
const Data::SongList song_list; const Data::SongList song_list;
// Resources
SharedResources resources;
Resources::Markers markers;
// State // State
Ribbon ribbon; Ribbon ribbon;
SongInfo song_info; SongInfo song_info;
ButtonHighlight button_highlight;
MainOptionPage main_option_page; MainOptionPage main_option_page;
Drawables::BlackFrame black_frame; Drawables::BlackFrame black_frame;

View File

@ -14,19 +14,19 @@ namespace MusicSelect {
this->setPosition(get_ribbon_x(), get_ribbon_y()); this->setPosition(get_ribbon_x(), get_ribbon_y());
} }
RibbonPage::RibbonPage(const PanelLayout& layout, SharedResources& resources) : RibbonPage::RibbonPage(const PanelLayout& layout, SharedResources& t_resources) :
OptionPage(resources), OptionPage(t_resources),
m_ribbon(layout, resources) m_ribbon(layout, t_resources)
{ {
} }
bool MusicSelect::RibbonPage::handle_raw_input(const sf::Event::KeyEvent& key_event) { bool MusicSelect::RibbonPage::handle_raw_input(const sf::Event::KeyEvent& key_event) {
auto button = m_preferences.key_mapping.key_to_button(key_event.code); auto button = preferences.key_mapping.key_to_button(key_event.code);
if (not button) { if (not button) {
return false; return false;
} }
auto button_index = Data::button_to_index(*button); auto button_index = Data::button_to_index(*button);
if (button_index > 12) { if (button_index > 13) {
return false; return false;
} }
button_click(*button); button_click(*button);
@ -56,33 +56,33 @@ namespace MusicSelect {
target.draw(m_ribbon, states); target.draw(m_ribbon, states);
} }
MainOptionPage::MainOptionPage(SharedResources& resources) : MainOptionPage::MainOptionPage(SharedResources& t_resources) :
RibbonPage(MainOptionPage::create_layout(resources), resources) RibbonPage(MainOptionPage::create_layout(t_resources), t_resources)
{ {
} }
PanelLayout MainOptionPage::create_layout(SharedResources& resources) { PanelLayout MainOptionPage::create_layout(SharedResources& t_resources) {
std::vector<std::shared_ptr<Panel>> subpages; std::vector<std::shared_ptr<Panel>> subpages;
auto marker_select = std::make_shared<MarkerSelect>(resources); auto marker_select = std::make_shared<MarkerSelect>(t_resources);
subpages.emplace_back(std::make_shared<SubpagePanel>(resources, std::move(marker_select), "markers")); subpages.emplace_back(std::make_shared<SubpagePanel>(t_resources, std::move(marker_select), "markers"));
return PanelLayout{subpages, resources}; return PanelLayout{subpages, t_resources};
} }
MarkerSelect::MarkerSelect(SharedResources& resources) : MarkerSelect::MarkerSelect(SharedResources& t_resources) :
RibbonPage(MarkerSelect::create_layout(resources), resources) RibbonPage(MarkerSelect::create_layout(t_resources), t_resources)
{ {
} }
MarkerSelect::~MarkerSelect() { MarkerSelect::~MarkerSelect() {
m_resources.selected_marker.reset(); resources.selected_marker.reset();
} }
PanelLayout MarkerSelect::create_layout(SharedResources& resources) { PanelLayout MarkerSelect::create_layout(SharedResources& t_resources) {
std::vector<std::shared_ptr<Panel>> markers; std::vector<std::shared_ptr<Panel>> markers;
for (const auto &[name, marker] : resources.markers) { for (const auto &[name, marker] : t_resources.markers) {
markers.emplace_back(std::make_shared<MarkerPanel>(resources, marker)); markers.emplace_back(std::make_shared<MarkerPanel>(t_resources, marker));
} }
return PanelLayout{markers, resources}; return PanelLayout{markers, t_resources};
} }
} }

View File

@ -15,7 +15,7 @@ namespace MusicSelect {
class OptionPage : public sf::Drawable, public sf::Transformable, public HoldsSharedResources { class OptionPage : public sf::Drawable, public sf::Transformable, public HoldsSharedResources {
public: public:
OptionPage(SharedResources& resources) : HoldsSharedResources(resources) {update();}; OptionPage(SharedResources& t_resources) : HoldsSharedResources(t_resources) {update();};
// Returns true if input was used // Returns true if input was used
virtual bool handle_raw_input(const sf::Event::KeyEvent& event) = 0; virtual bool handle_raw_input(const sf::Event::KeyEvent& event) = 0;
virtual ~OptionPage() = default; virtual ~OptionPage() = default;
@ -24,7 +24,7 @@ namespace MusicSelect {
class RibbonPage : public OptionPage { class RibbonPage : public OptionPage {
public: public:
RibbonPage(const PanelLayout& layout, SharedResources& resources); RibbonPage(const PanelLayout& layout, SharedResources& t_resources);
bool handle_raw_input(const sf::Event::KeyEvent& event) override; bool handle_raw_input(const sf::Event::KeyEvent& event) override;
void button_click(const Data::Button& button); void button_click(const Data::Button& button);
private: private:
@ -34,16 +34,16 @@ namespace MusicSelect {
class MainOptionPage final : public RibbonPage { class MainOptionPage final : public RibbonPage {
public: public:
MainOptionPage(SharedResources& resources); MainOptionPage(SharedResources& t_resources);
private: private:
static PanelLayout create_layout(SharedResources& resources); static PanelLayout create_layout(SharedResources& t_resources);
}; };
class MarkerSelect final : public RibbonPage { class MarkerSelect final : public RibbonPage {
public: public:
MarkerSelect(SharedResources& resources); MarkerSelect(SharedResources& t_resources);
~MarkerSelect(); ~MarkerSelect();
private: private:
static PanelLayout create_layout(SharedResources& resources); static PanelLayout create_layout(SharedResources& t_resources);
}; };
} }

View File

@ -5,12 +5,12 @@
namespace MusicSelect { namespace MusicSelect {
PanelLayout::PanelLayout( PanelLayout::PanelLayout(
const std::map<std::string,std::vector<std::shared_ptr<Panel>>>& categories, const std::map<std::string,std::vector<std::shared_ptr<Panel>>>& categories,
SharedResources& resources SharedResources& t_resources
) { ) {
for (auto &&[category, panels] : categories) { for (auto &&[category, panels] : categories) {
if (not panels.empty()) { if (not panels.empty()) {
std::vector<std::shared_ptr<Panel>> current_column; std::vector<std::shared_ptr<Panel>> current_column;
current_column.emplace_back(std::make_shared<CategoryPanel>(resources, category)); current_column.emplace_back(std::make_shared<CategoryPanel>(t_resources, category));
for (auto& panel : panels) { for (auto& panel : panels) {
if (current_column.size() == 3) { if (current_column.size() == 3) {
push_back({current_column[0],current_column[1],current_column[2]}); push_back({current_column[0],current_column[1],current_column[2]});
@ -20,18 +20,18 @@ namespace MusicSelect {
} }
if (not current_column.empty()) { if (not current_column.empty()) {
while (current_column.size() < 3) { while (current_column.size() < 3) {
current_column.emplace_back(std::make_shared<EmptyPanel>(resources)); current_column.emplace_back(std::make_shared<EmptyPanel>(t_resources));
} }
push_back({current_column[0],current_column[1],current_column[2]}); push_back({current_column[0],current_column[1],current_column[2]});
} }
} }
} }
fill_layout(resources); fill_layout(t_resources);
} }
PanelLayout::PanelLayout( PanelLayout::PanelLayout(
const std::vector<std::shared_ptr<Panel>>& panels, const std::vector<std::shared_ptr<Panel>>& panels,
SharedResources& resources SharedResources& t_resources
) { ) {
std::vector<std::shared_ptr<Panel>> current_column; std::vector<std::shared_ptr<Panel>> current_column;
for (auto& panel : panels) { for (auto& panel : panels) {
@ -43,22 +43,22 @@ namespace MusicSelect {
} }
if (not current_column.empty()) { if (not current_column.empty()) {
while (current_column.size() < 3) { while (current_column.size() < 3) {
current_column.emplace_back(std::make_shared<EmptyPanel>(resources)); current_column.emplace_back(std::make_shared<EmptyPanel>(t_resources));
} }
push_back({current_column[0],current_column[1],current_column[2]}); push_back({current_column[0],current_column[1],current_column[2]});
} }
fill_layout(resources); fill_layout(t_resources);
} }
PanelLayout PanelLayout::red_empty_layout(SharedResources& resources) { PanelLayout PanelLayout::red_empty_layout(SharedResources& t_resources) {
std::vector<std::shared_ptr<Panel>> panels; std::vector<std::shared_ptr<Panel>> panels;
for (size_t i = 0; i < 3*4; i++) { for (size_t i = 0; i < 3*4; i++) {
panels.emplace_back(std::make_shared<ColoredMessagePanel>(resources, sf::Color::Red, "- EMPTY -")); panels.emplace_back(std::make_shared<ColoredMessagePanel>(t_resources, sf::Color::Red, "- EMPTY -"));
} }
return PanelLayout{panels, resources}; return PanelLayout{panels, t_resources};
} }
PanelLayout PanelLayout::title_sort(const Data::SongList& song_list, SharedResources& resources) { PanelLayout PanelLayout::title_sort(const Data::SongList& song_list, SharedResources& t_resources) {
std::vector<std::shared_ptr<const Data::Song>> songs; std::vector<std::shared_ptr<const Data::Song>> songs;
for (auto &&song : song_list.songs) { for (auto &&song : song_list.songs) {
songs.push_back(song); songs.push_back(song);
@ -75,27 +75,27 @@ namespace MusicSelect {
if ('A' <= letter and letter <= 'Z') { if ('A' <= letter and letter <= 'Z') {
categories categories
[std::string(1, letter)] [std::string(1, letter)]
.emplace_back(std::make_shared<SongPanel>(resources, song)); .emplace_back(std::make_shared<SongPanel>(t_resources, song));
} else if ('a' <= letter and letter <= 'z') { } else if ('a' <= letter and letter <= 'z') {
categories categories
[std::string(1, 'A' + (letter - 'a'))] [std::string(1, 'A' + (letter - 'a'))]
.emplace_back(std::make_shared<SongPanel>(resources, song)); .emplace_back(std::make_shared<SongPanel>(t_resources, song));
} else { } else {
categories["?"].emplace_back(std::make_shared<SongPanel>(resources, song)); categories["?"].emplace_back(std::make_shared<SongPanel>(t_resources, song));
} }
} else { } else {
categories["?"].emplace_back(std::make_shared<SongPanel>(resources, song)); categories["?"].emplace_back(std::make_shared<SongPanel>(t_resources, song));
} }
} }
return PanelLayout{categories, resources}; return PanelLayout{categories, t_resources};
} }
void PanelLayout::fill_layout(SharedResources& resources) { void PanelLayout::fill_layout(SharedResources& t_resources) {
while (size() < 4) { while (size() < 4) {
push_back({ push_back({
std::make_shared<EmptyPanel>(resources), std::make_shared<EmptyPanel>(t_resources),
std::make_shared<EmptyPanel>(resources), std::make_shared<EmptyPanel>(t_resources),
std::make_shared<EmptyPanel>(resources) std::make_shared<EmptyPanel>(t_resources)
}); });
} }
} }

View File

@ -14,14 +14,14 @@ namespace MusicSelect {
class PanelLayout : public std::vector<std::array<std::shared_ptr<Panel>,3>> { class PanelLayout : public std::vector<std::array<std::shared_ptr<Panel>,3>> {
public: public:
// Takes of map of category name and associated Panels, useful for all the sorted layouts // Takes of map of category name and associated Panels, useful for all the sorted layouts
explicit PanelLayout(const std::map<std::string,std::vector<std::shared_ptr<Panel>>>& categories, SharedResources& resources); explicit PanelLayout(const std::map<std::string,std::vector<std::shared_ptr<Panel>>>& categories, SharedResources& t_resources);
// Arranges all the panels in the vector in columns of three // Arranges all the panels in the vector in columns of three
explicit PanelLayout(const std::vector<std::shared_ptr<Panel>>& panels, SharedResources& resources); explicit PanelLayout(const std::vector<std::shared_ptr<Panel>>& panels, SharedResources& t_resources);
// Stepmania-like empty layout with big red panels that say EMPTY // Stepmania-like empty layout with big red panels that say EMPTY
static PanelLayout red_empty_layout(SharedResources& resources); static PanelLayout red_empty_layout(SharedResources& t_resources);
// Standard title sort with categories for each letter // Standard title sort with categories for each letter
static PanelLayout title_sort(const Data::SongList& song_list, SharedResources& resources); static PanelLayout title_sort(const Data::SongList& song_list, SharedResources& t_resources);
private: private:
void fill_layout(SharedResources& resources); void fill_layout(SharedResources& t_resources);
}; };
} }

View File

@ -3,19 +3,19 @@
#include <cmath> #include <cmath>
namespace MusicSelect { namespace MusicSelect {
MarkerPanel::MarkerPanel(SharedResources& resources, const Resources::Marker& marker) : MarkerPanel::MarkerPanel(SharedResources& t_resources, const Resources::Marker& marker) :
Panel(resources), Panel(t_resources),
m_marker(marker) m_marker(marker)
{ {
if (m_resources.m_preferences.options.marker == m_marker.m_metadata.name) { if (resources.preferences.options.marker == m_marker.m_metadata.name) {
select(); select();
} }
} }
void MarkerPanel::click(Ribbon&, const Data::Button&) { void MarkerPanel::click(Ribbon&, const Data::Button&) {
if (selected) { if (selected) {
m_resources.selected_marker->last_click.restart(); resources.selected_marker->last_click.restart();
m_resources.selected_marker->is_first_click = false; resources.selected_marker->is_first_click = false;
} else { } else {
select(); select();
} }
@ -25,7 +25,7 @@ namespace MusicSelect {
states.transform *= getTransform(); states.transform *= getTransform();
float animation_time = 0.f; float animation_time = 0.f;
if (selected) { if (selected) {
animation_time = std::fmod(m_resources.selected_marker->last_click.getElapsedTime().asSeconds(), 2.f) - 1.f; animation_time = std::fmod(resources.selected_marker->last_click.getElapsedTime().asSeconds(), 2.f) - 1.f;
} }
auto sprite = m_marker.get_sprite(Resources::MarkerAnimation::APPROACH, animation_time); auto sprite = m_marker.get_sprite(Resources::MarkerAnimation::APPROACH, animation_time);
if (sprite) { if (sprite) {
@ -36,11 +36,11 @@ namespace MusicSelect {
} }
void MarkerPanel::select() { void MarkerPanel::select() {
if (m_resources.selected_marker) { if (resources.selected_marker) {
m_resources.selected_marker->obj.unselect(); resources.selected_marker->obj.unselect();
} }
m_resources.selected_marker.emplace(*this); resources.selected_marker.emplace(*this);
m_resources.m_preferences.options.marker = m_marker.m_metadata.name; resources.preferences.options.marker = m_marker.m_metadata.name;
this->selected = true; this->selected = true;
} }

View File

@ -10,7 +10,7 @@
namespace MusicSelect { namespace MusicSelect {
class MarkerPanel final : public Panel { class MarkerPanel final : public Panel {
public: public:
MarkerPanel(SharedResources& resources, const Resources::Marker& marker); MarkerPanel(SharedResources& t_resources, const Resources::Marker& marker);
void click(Ribbon&, const Data::Button&) override; void click(Ribbon&, const Data::Button&) override;
private: private:
void draw(sf::RenderTarget& target, sf::RenderStates states) const override; void draw(sf::RenderTarget& target, sf::RenderStates states) const override;

View File

@ -11,7 +11,7 @@
#include "../SharedResources.hpp" #include "../SharedResources.hpp"
namespace MusicSelect { namespace MusicSelect {
Panel::Panel(SharedResources& resources) : HoldsSharedResources(resources) { Panel::Panel(SharedResources& t_resources) : HoldsSharedResources(t_resources) {
} }
@ -43,7 +43,7 @@ namespace MusicSelect {
sf::Text category_label{ sf::Text category_label{
"category", "category",
m_resources.fallback_font.medium, resources.fallback_font.medium,
static_cast<unsigned int>(get_size()*0.1f) static_cast<unsigned int>(get_size()*0.1f)
}; };
category_label.setFillColor(sf::Color::White); category_label.setFillColor(sf::Color::White);
@ -52,7 +52,7 @@ namespace MusicSelect {
sf::Text label_text{ sf::Text label_text{
m_label, m_label,
m_resources.fallback_font.black, resources.fallback_font.black,
static_cast<unsigned int>(get_size()*0.7f) static_cast<unsigned int>(get_size()*0.7f)
}; };
label_text.setFillColor(sf::Color::White); label_text.setFillColor(sf::Color::White);
@ -74,23 +74,23 @@ namespace MusicSelect {
} else { } else {
selected_chart = m_song->chart_levels.cbegin()->first; selected_chart = m_song->chart_levels.cbegin()->first;
} }
m_resources.selected_panel->last_click.restart(); resources.selected_panel->last_click.restart();
m_resources.selected_panel->is_first_click = false; resources.selected_panel->is_first_click = false;
} else { } else {
// Look for the first chart with dif greater or equal to the last select one // Look for the first chart with dif greater or equal to the last select one
// or else select the first chart // or else select the first chart
auto it = m_song->chart_levels.lower_bound(m_resources.get_last_selected_difficulty()); auto it = m_song->chart_levels.lower_bound(resources.get_last_selected_difficulty());
if (it != m_song->chart_levels.cend()) { if (it != m_song->chart_levels.cend()) {
selected_chart = it->first; selected_chart = it->first;
} else { } else {
selected_chart = m_song->chart_levels.cbegin()->first; selected_chart = m_song->chart_levels.cbegin()->first;
} }
// The song was not selected before : first unselect the last one // The song was not selected before : first unselect the last one
if (m_resources.selected_panel.has_value()) { if (resources.selected_panel.has_value()) {
m_resources.selected_panel->obj.unselect(); resources.selected_panel->obj.unselect();
} }
m_resources.selected_panel.emplace(*this); resources.selected_panel.emplace(*this);
m_resources.music_preview.play(m_song->full_audio_path(), m_song->preview); resources.music_preview.play(m_song->full_audio_path(), m_song->preview);
} }
} }
@ -108,11 +108,11 @@ namespace MusicSelect {
void SongPanel::draw(sf::RenderTarget& target, sf::RenderStates states) const { void SongPanel::draw(sf::RenderTarget& target, sf::RenderStates states) const {
states.transform *= getTransform(); states.transform *= getTransform();
auto last_selected_chart = m_resources.get_last_selected_difficulty(); auto last_selected_chart = resources.get_last_selected_difficulty();
// We should gray out the panel if the currently selected difficulty doesn't exist for this song // We should gray out the panel if the currently selected difficulty doesn't exist for this song
bool should_be_grayed_out = m_song->chart_levels.find(last_selected_chart) == m_song->chart_levels.end(); bool should_be_grayed_out = m_song->chart_levels.find(last_selected_chart) == m_song->chart_levels.end();
if (m_song->cover) { if (m_song->cover) {
auto loaded_texture = m_resources.covers.async_get(m_song->folder/m_song->cover.value()); auto loaded_texture = resources.covers.async_get(m_song->folder/m_song->cover.value());
if (loaded_texture) { if (loaded_texture) {
sf::Sprite cover{*(loaded_texture->texture)}; sf::Sprite cover{*(loaded_texture->texture)};
auto alpha = static_cast<std::uint8_t>( auto alpha = static_cast<std::uint8_t>(
@ -135,7 +135,7 @@ namespace MusicSelect {
chart_dif_badge.setFillColor(sf::Color(128,128,128)); chart_dif_badge.setFillColor(sf::Color(128,128,128));
} else { } else {
chart_dif_badge.setFillColor( chart_dif_badge.setFillColor(
m_resources.get_chart_color(last_selected_chart) resources.get_chart_color(last_selected_chart)
); );
} }
target.draw(chart_dif_badge, states); target.draw(chart_dif_badge, states);
@ -143,7 +143,7 @@ namespace MusicSelect {
auto dif = m_song->chart_levels.at(last_selected_chart); auto dif = m_song->chart_levels.at(last_selected_chart);
sf::Text dif_label{ sf::Text dif_label{
std::to_string(dif), std::to_string(dif),
m_resources.fallback_font.black, resources.fallback_font.black,
static_cast<unsigned int>(get_size()*0.15f) static_cast<unsigned int>(get_size()*0.15f)
}; };
dif_label.setFillColor(sf::Color::White); dif_label.setFillColor(sf::Color::White);
@ -152,7 +152,7 @@ namespace MusicSelect {
target.draw(dif_label, states); target.draw(dif_label, states);
} }
sf::Text song_title; sf::Text song_title;
song_title.setFont(m_resources.fallback_font.medium); song_title.setFont(resources.fallback_font.medium);
song_title.setString(sf::String::fromUtf8(m_song->title.begin(), m_song->title.end())); song_title.setString(sf::String::fromUtf8(m_song->title.begin(), m_song->title.end()));
song_title.setCharacterSize(static_cast<unsigned int>(0.06875f*get_size())); song_title.setCharacterSize(static_cast<unsigned int>(0.06875f*get_size()));
song_title.setFillColor(sf::Color::White); song_title.setFillColor(sf::Color::White);
@ -182,7 +182,7 @@ namespace MusicSelect {
target.draw(frame, states); target.draw(frame, states);
sf::Text message; sf::Text message;
message.setFont(m_resources.fallback_font.medium); message.setFont(resources.fallback_font.medium);
message.setString(sf::String::fromUtf8(m_message.begin(), m_message.end())); message.setString(sf::String::fromUtf8(m_message.begin(), m_message.end()));
message.setCharacterSize(static_cast<unsigned int>(0.1f*get_size())); message.setCharacterSize(static_cast<unsigned int>(0.1f*get_size()));
message.setFillColor(m_color); message.setFillColor(m_color);

View File

@ -19,7 +19,7 @@ namespace MusicSelect {
// of the music select screen, be it nothing, a category indicator, or a song // of the music select screen, be it nothing, a category indicator, or a song
class Panel : public sf::Drawable, public sf::Transformable, public HoldsSharedResources { class Panel : public sf::Drawable, public sf::Transformable, public HoldsSharedResources {
public: public:
explicit Panel(SharedResources& resources); explicit Panel(SharedResources& t_resources);
// What happens when you click on the panel // What happens when you click on the panel
virtual void click(Ribbon& ribbon, const Data::Button& button) = 0; virtual void click(Ribbon& ribbon, const Data::Button& button) = 0;
virtual ~Panel() = default; virtual ~Panel() = default;
@ -37,7 +37,7 @@ namespace MusicSelect {
class ColoredMessagePanel final : public Panel { class ColoredMessagePanel final : public Panel {
public: public:
ColoredMessagePanel(SharedResources& resources, const sf::Color& color, const std::string& message) : Panel(resources), m_color(color), m_message(message) {}; ColoredMessagePanel(SharedResources& t_resources, const sf::Color& color, const std::string& message) : Panel(t_resources), m_color(color), m_message(message) {};
void click(Ribbon&, const Data::Button&) override {return;}; void click(Ribbon&, const Data::Button&) override {return;};
private: private:
void draw(sf::RenderTarget& target, sf::RenderStates states) const override; void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
@ -47,7 +47,7 @@ namespace MusicSelect {
class ColorPanel final : public Panel { class ColorPanel final : public Panel {
public: public:
ColorPanel(SharedResources& resources, const sf::Color& t_color) : Panel(resources), m_color(t_color) {}; ColorPanel(SharedResources& t_resources, const sf::Color& t_color) : Panel(t_resources), m_color(t_color) {};
void click(Ribbon&, const Data::Button&) override {return;}; void click(Ribbon&, const Data::Button&) override {return;};
private: private:
void draw(sf::RenderTarget& target, sf::RenderStates states) const override; void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
@ -56,7 +56,7 @@ namespace MusicSelect {
class CategoryPanel final : public Panel { class CategoryPanel final : public Panel {
public: public:
CategoryPanel(SharedResources& resources, const std::string& t_label) : Panel(resources), m_label(t_label) {}; CategoryPanel(SharedResources& t_resources, const std::string& t_label) : Panel(t_resources), m_label(t_label) {};
void click(Ribbon& ribbon, const Data::Button& button) override; void click(Ribbon& ribbon, const Data::Button& button) override;
private: private:
void draw(sf::RenderTarget& target, sf::RenderStates states) const override; void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
@ -73,7 +73,7 @@ namespace MusicSelect {
class SongPanel final : public SelectablePanel { class SongPanel final : public SelectablePanel {
public: public:
explicit SongPanel(SharedResources& resources, const std::shared_ptr<const Data::Song>& t_song) : SelectablePanel(resources), m_song(t_song) {}; explicit SongPanel(SharedResources& t_resources, const std::shared_ptr<const Data::Song>& t_song) : SelectablePanel(t_resources), m_song(t_song) {};
void click(Ribbon& ribbon, const Data::Button& button) override; void click(Ribbon& ribbon, const Data::Button& button) override;
void unselect() override; void unselect() override;
std::optional<SongDifficulty> get_selected_difficulty() const override; std::optional<SongDifficulty> get_selected_difficulty() const override;

View File

@ -4,8 +4,8 @@
namespace MusicSelect { namespace MusicSelect {
void SubpagePanel::click(Ribbon&, const Data::Button&) { void SubpagePanel::click(Ribbon&, const Data::Button&) {
m_resources.options_state.push(*m_subpage); resources.options_state.push_back(*m_subpage);
m_resources.options_state.top().get().update(); resources.options_state.back().get().update();
} }
void SubpagePanel::draw(sf::RenderTarget& target, sf::RenderStates states) const { void SubpagePanel::draw(sf::RenderTarget& target, sf::RenderStates states) const {
@ -19,7 +19,7 @@ namespace MusicSelect {
target.draw(frame, states); target.draw(frame, states);
sf::Text message; sf::Text message;
message.setFont(m_resources.fallback_font.medium); message.setFont(resources.fallback_font.medium);
message.setString(sf::String::fromUtf8(m_name.begin(), m_name.end())); message.setString(sf::String::fromUtf8(m_name.begin(), m_name.end()));
message.setCharacterSize(static_cast<unsigned int>(0.1f*get_size())); message.setCharacterSize(static_cast<unsigned int>(0.1f*get_size()));
message.setFillColor(sf::Color::White); message.setFillColor(sf::Color::White);

View File

@ -14,11 +14,11 @@ namespace MusicSelect {
class SubpagePanel final : public Panel { class SubpagePanel final : public Panel {
public: public:
SubpagePanel( SubpagePanel(
SharedResources& resources, SharedResources& t_resources,
std::shared_ptr<OptionPage> subpage, std::shared_ptr<OptionPage> subpage,
const std::string& name const std::string& name
) : ) :
Panel(resources), Panel(t_resources),
m_subpage(subpage), m_subpage(subpage),
m_name(name) m_name(name)
{}; {};

View File

@ -65,8 +65,8 @@ namespace MusicSelect {
return clock.getElapsedTime() / m_time_factor > sf::milliseconds(300); return clock.getElapsedTime() / m_time_factor > sf::milliseconds(300);
} }
Ribbon::Ribbon(PanelLayout layout, SharedResources& resources) : Ribbon::Ribbon(PanelLayout layout, SharedResources& t_resources) :
HoldsSharedResources(resources), HoldsSharedResources(t_resources),
m_layout(layout) m_layout(layout)
{ {
std::cout << "Loaded MusicSelect::Ribbon" << std::endl; std::cout << "Loaded MusicSelect::Ribbon" << std::endl;

View File

@ -26,10 +26,11 @@ namespace MusicSelect {
} }
} }
SharedResources::SharedResources(Data::Preferences& p, const Resources::Markers& m) : SharedResources::SharedResources(Data::Preferences& p) :
Data::HoldsPreferences(p), Data::HoldsPreferences(p),
fallback_font(p.jujube_path), fallback_font(p.jujube_path),
markers(m) markers(Resources::load_markers(p.jujube_path)),
button_highlight(p)
{ {
covers.reserve(256); covers.reserve(256);
std::cout << "Loaded MusicSelect::SharedResources" << std::endl; std::cout << "Loaded MusicSelect::SharedResources" << std::endl;

View File

@ -10,10 +10,11 @@
#include <SFML/Graphics/Font.hpp> #include <SFML/Graphics/Font.hpp>
#include <SFML/System.hpp> #include <SFML/System.hpp>
#include "../../Resources/Marker.hpp"
#include "../../Resources/TextureCache.hpp"
#include "../../Data/Preferences.hpp" #include "../../Data/Preferences.hpp"
#include "../../Data/Song.hpp" #include "../../Data/Song.hpp"
#include "../../Drawables/ButtonHighlight.hpp"
#include "../../Resources/Marker.hpp"
#include "../../Resources/TextureCache.hpp"
#include "DensityGraph.hpp" #include "DensityGraph.hpp"
#include "MusicPreview.hpp" #include "MusicPreview.hpp"
@ -42,7 +43,7 @@ namespace MusicSelect {
// Holds everything that needs to be shared by all levels of the class hierarchy // Holds everything that needs to be shared by all levels of the class hierarchy
struct SharedResources : public Data::HoldsPreferences { struct SharedResources : public Data::HoldsPreferences {
SharedResources(Data::Preferences& p, const Resources::Markers& m); SharedResources(Data::Preferences& p);
Textures::TextureCache covers; Textures::TextureCache covers;
@ -62,17 +63,18 @@ namespace MusicSelect {
MusicPreview music_preview; MusicPreview music_preview;
std::stack<std::reference_wrapper<OptionPage>> options_state; std::vector<std::reference_wrapper<OptionPage>> options_state;
const Resources::Markers& markers;
Resources::Markers markers;
std::optional<Timed<MarkerPanel>> selected_marker; std::optional<Timed<MarkerPanel>> selected_marker;
Drawables::ButtonHighlight button_highlight;
}; };
// Proxy for HoldsPreferences // Proxy for HoldsPreferences
struct HoldsSharedResources : public Data::HoldsPreferences { struct HoldsSharedResources : public Data::HoldsPreferences {
HoldsSharedResources(SharedResources& resources) : Data::HoldsPreferences(resources.m_preferences), m_resources(resources) {}; HoldsSharedResources(SharedResources& t_resources) : Data::HoldsPreferences(t_resources.preferences), resources(t_resources) {};
protected: protected:
SharedResources& m_resources; SharedResources& resources;
}; };
} }

View File

@ -12,8 +12,8 @@
namespace MusicSelect { namespace MusicSelect {
BigCover::BigCover(SharedResources& resources) : BigCover::BigCover(SharedResources& t_resources) :
HoldsSharedResources(resources) HoldsSharedResources(t_resources)
{ {
m_cover_fallback.setFillColor(sf::Color::Transparent); m_cover_fallback.setFillColor(sf::Color::Transparent);
m_cover_fallback.setOutlineThickness(1.f); m_cover_fallback.setOutlineThickness(1.f);
@ -24,7 +24,7 @@ namespace MusicSelect {
states.transform *= getTransform(); states.transform *= getTransform();
m_cover_fallback.setSize({get_size(), get_size()}); m_cover_fallback.setSize({get_size(), get_size()});
target.draw(m_cover_fallback, states); target.draw(m_cover_fallback, states);
auto selected_panel = m_resources.selected_panel; auto selected_panel = resources.selected_panel;
if (not selected_panel.has_value()) { if (not selected_panel.has_value()) {
return; return;
} }
@ -36,7 +36,7 @@ namespace MusicSelect {
if (not cover_path.has_value()) { if (not cover_path.has_value()) {
return; return;
} }
auto cover_texture = m_resources.covers.async_get(*cover_path); auto cover_texture = resources.covers.async_get(*cover_path);
if (not cover_texture.has_value()) { if (not cover_texture.has_value()) {
return; return;
} }
@ -52,8 +52,8 @@ namespace MusicSelect {
target.draw(cover, states); target.draw(cover, states);
} }
SongInfo::SongInfo(SharedResources& resources) : SongInfo::SongInfo(SharedResources& t_resources) :
HoldsSharedResources(resources), HoldsSharedResources(t_resources),
m_big_cover(resources) m_big_cover(resources)
{} {}
@ -69,7 +69,7 @@ namespace MusicSelect {
} }
void SongInfo::draw_song_title(sf::RenderTarget& target, sf::RenderStates states) const { void SongInfo::draw_song_title(sf::RenderTarget& target, sf::RenderStates states) const {
auto selected_panel = m_resources.selected_panel; auto selected_panel = resources.selected_panel;
if (not selected_panel.has_value()) { if (not selected_panel.has_value()) {
return; return;
} }
@ -81,7 +81,7 @@ namespace MusicSelect {
if (not song_title.empty()) { if (not song_title.empty()) {
sf::Text song_title_label{ sf::Text song_title_label{
sf::String::fromUtf8(song_title.begin(), song_title.end()), sf::String::fromUtf8(song_title.begin(), song_title.end()),
m_resources.fallback_font.medium, resources.fallback_font.medium,
static_cast<unsigned int>( static_cast<unsigned int>(
0.026315789f*get_screen_width() 0.026315789f*get_screen_width()
) )
@ -101,7 +101,7 @@ namespace MusicSelect {
if (not song_artist.empty()) { if (not song_artist.empty()) {
sf::Text song_artist_label{ sf::Text song_artist_label{
sf::String::fromUtf8(song_artist.begin(), song_artist.end()), sf::String::fromUtf8(song_artist.begin(), song_artist.end()),
m_resources.fallback_font.medium, resources.fallback_font.medium,
static_cast<unsigned int>( static_cast<unsigned int>(
0.02f*get_screen_width() 0.02f*get_screen_width()
) )
@ -122,7 +122,7 @@ namespace MusicSelect {
} }
void SongInfo::draw_big_level(sf::RenderTarget& target, sf::RenderStates states) const { void SongInfo::draw_big_level(sf::RenderTarget& target, sf::RenderStates states) const {
auto selected_panel = m_resources.selected_panel; auto selected_panel = resources.selected_panel;
if (not selected_panel.has_value()) { if (not selected_panel.has_value()) {
return; return;
} }
@ -132,7 +132,7 @@ namespace MusicSelect {
} }
sf::Text level_label{ sf::Text level_label{
"LEVEL", "LEVEL",
m_resources.fallback_font.light, resources.fallback_font.light,
static_cast<unsigned int>(12.f/768.f*get_screen_width()) static_cast<unsigned int>(12.f/768.f*get_screen_width())
}; };
Toolkit::set_origin_normalized(level_label, 0.5f, 0.f); Toolkit::set_origin_normalized(level_label, 0.5f, 0.f);
@ -142,7 +142,7 @@ namespace MusicSelect {
sf::Text level_number_label{ sf::Text level_number_label{
std::to_string(selected_chart->song.chart_levels.at(selected_chart->difficulty)), std::to_string(selected_chart->song.chart_levels.at(selected_chart->difficulty)),
m_resources.fallback_font.black, resources.fallback_font.black,
static_cast<unsigned int>(130.f/768.f*get_screen_width()) static_cast<unsigned int>(130.f/768.f*get_screen_width())
}; };
Toolkit::set_origin_normalized(level_number_label, 0.5f, 0.f); Toolkit::set_origin_normalized(level_number_label, 0.5f, 0.f);
@ -161,17 +161,17 @@ namespace MusicSelect {
sf::Text chart_label{ sf::Text chart_label{
sf::String::fromUtf8(full_difficulty.begin(), full_difficulty.end()), sf::String::fromUtf8(full_difficulty.begin(), full_difficulty.end()),
m_resources.fallback_font.medium, resources.fallback_font.medium,
static_cast<unsigned int>(20.f/768.f*get_screen_width()) static_cast<unsigned int>(20.f/768.f*get_screen_width())
}; };
Toolkit::set_origin_normalized_no_position(chart_label, 0.5f, 0.f); 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.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->difficulty)); chart_label.setFillColor(resources.get_chart_color(selected_chart->difficulty));
target.draw(chart_label, states); target.draw(chart_label, states);
} }
void MusicSelect::SongInfo::draw_chart_list(sf::RenderTarget& target, sf::RenderStates states) const { void MusicSelect::SongInfo::draw_chart_list(sf::RenderTarget& target, sf::RenderStates states) const {
auto selected_panel = m_resources.selected_panel; auto selected_panel = resources.selected_panel;
if (not selected_panel.has_value()) { if (not selected_panel.has_value()) {
return; return;
} }
@ -187,7 +187,7 @@ namespace MusicSelect {
for (auto &&[difficulty, level] : selected_chart->song.chart_levels) { for (auto &&[difficulty, level] : selected_chart->song.chart_levels) {
sf::CircleShape dif_badge{dif_badge_radius}; sf::CircleShape dif_badge{dif_badge_radius};
Toolkit::set_origin_normalized(dif_badge, 0.5f, 0.5f); Toolkit::set_origin_normalized(dif_badge, 0.5f, 0.5f);
dif_badge.setFillColor(m_resources.get_chart_color(difficulty)); dif_badge.setFillColor(resources.get_chart_color(difficulty));
dif_badge.setPosition(dif_badge_x+dif_index*dif_badge_step, dif_badge_y); dif_badge.setPosition(dif_badge_x+dif_index*dif_badge_step, dif_badge_y);
target.draw(dif_badge, states); target.draw(dif_badge, states);
if (difficulty == selected_chart->difficulty) { if (difficulty == selected_chart->difficulty) {
@ -221,7 +221,7 @@ namespace MusicSelect {
line.setFillColor(sf::Color::White); line.setFillColor(sf::Color::White);
line.setPosition(get_screen_width()*0.5f,425.f/768.f*get_screen_width()); line.setPosition(get_screen_width()*0.5f,425.f/768.f*get_screen_width());
target.draw(line, states); target.draw(line, states);
auto selected_panel = m_resources.selected_panel; auto selected_panel = resources.selected_panel;
if (not selected_panel.has_value()) { if (not selected_panel.has_value()) {
return; return;
} }
@ -229,8 +229,8 @@ namespace MusicSelect {
if (not selected_difficulty.has_value()) { if (not selected_difficulty.has_value()) {
return; return;
} }
m_resources.density_graphs.load(*selected_difficulty); resources.density_graphs.load(*selected_difficulty);
auto densities = m_resources.density_graphs.get(*selected_difficulty); auto densities = resources.density_graphs.get(*selected_difficulty);
if (not densities.has_value()) { if (not densities.has_value()) {
return; return;
} }

View File

@ -11,8 +11,8 @@ namespace MusicSelect {
class BigCover : public sf::Drawable, public sf::Transformable, public HoldsSharedResources { class BigCover : public sf::Drawable, public sf::Transformable, public HoldsSharedResources {
public: public:
BigCover(SharedResources& resources); BigCover(SharedResources& t_resources);
float get_size() const {return m_preferences.layout.big_cover_size*get_screen_width();}; float get_size() const {return preferences.layout.big_cover_size*get_screen_width();};
private: private:
void draw(sf::RenderTarget& target, sf::RenderStates states) const override; void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
mutable sf::RectangleShape m_cover_fallback; mutable sf::RectangleShape m_cover_fallback;
@ -22,7 +22,7 @@ namespace MusicSelect {
// Displays the song info on the top part of the screen // Displays the song info on the top part of the screen
class SongInfo : public sf::Drawable, public sf::Transformable, public HoldsSharedResources { class SongInfo : public sf::Drawable, public sf::Transformable, public HoldsSharedResources {
public: public:
SongInfo(SharedResources& resources); SongInfo(SharedResources& t_resources);
private: private:
void draw(sf::RenderTarget& target, sf::RenderStates states) const override; void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
void draw_song_title(sf::RenderTarget& target, sf::RenderStates states) const; void draw_song_title(sf::RenderTarget& target, sf::RenderStates states) const;