Refactor dependancy on resources as HoldSharedResources class
This commit is contained in:
parent
019a776432
commit
b994459f74
@ -30,7 +30,7 @@ namespace Data {
|
||||
float panel_position_y = 602.f / 1360.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 panel_step() const {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;
|
||||
|
@ -11,9 +11,14 @@
|
||||
#include "SharedResources.hpp"
|
||||
|
||||
namespace MusicSelect {
|
||||
float Panel::get_size() const {
|
||||
return m_resources.preferences.layout.panel_size*m_resources.preferences.screen.width;
|
||||
Panel::Panel(SharedResources& resources) : HoldsSharedResources(resources) {
|
||||
|
||||
}
|
||||
|
||||
float Panel::get_size() const {
|
||||
return get_panel_size();
|
||||
}
|
||||
|
||||
void ColorPanel::draw(sf::RenderTarget& target, sf::RenderStates states) const {
|
||||
sf::RectangleShape panel{{get_size()*0.9f, get_size()*0.9f}};
|
||||
panel.setFillColor(m_color);
|
||||
|
@ -13,18 +13,16 @@
|
||||
namespace MusicSelect {
|
||||
|
||||
class Ribbon;
|
||||
class SharedResources;
|
||||
|
||||
// A Panel holds anything that can go under a button on the moving part
|
||||
// of the music select screen, be it nothing, a category indicator, or a song
|
||||
class Panel : public sf::Drawable, public sf::Transformable {
|
||||
class Panel : public sf::Drawable, public sf::Transformable, public HoldsSharedResources {
|
||||
public:
|
||||
Panel(SharedResources& resources) : m_resources(resources) {};
|
||||
explicit Panel(SharedResources& 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:
|
||||
SharedResources& m_resources;
|
||||
float get_size() const;
|
||||
};
|
||||
|
||||
|
@ -64,12 +64,7 @@ namespace MusicSelect {
|
||||
return clock.getElapsedTime() / m_time_factor > sf::milliseconds(300);
|
||||
}
|
||||
|
||||
Ribbon::Ribbon(SharedResources& t_resources) :
|
||||
m_layout(),
|
||||
m_move_animation(),
|
||||
m_resources(t_resources),
|
||||
empty_song()
|
||||
{
|
||||
Ribbon::Ribbon(SharedResources& t_resources) : HoldsSharedResources(t_resources) {
|
||||
std::cout << "Loaded MusicSelect::Ribbon" << std::endl;
|
||||
}
|
||||
|
||||
@ -273,19 +268,13 @@ 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) * (panel_step),
|
||||
row * (panel_step)
|
||||
(static_cast<float>(relative_column_zero + column_offset) - float_position) * (get_panel_step()),
|
||||
row * (get_panel_step())
|
||||
);
|
||||
target.draw(*panel, states);
|
||||
}
|
||||
@ -293,17 +282,11 @@ 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 * (panel_step), row * (panel_step));
|
||||
panel->setPosition(column * (get_panel_step()), row * (get_panel_step()));
|
||||
target.draw(*panel, states);
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ namespace MusicSelect {
|
||||
|
||||
// The Ribbon is the moving part of the Music Select Screen
|
||||
// It can be sorted in a number of ways
|
||||
class Ribbon final : public sf::Drawable, public sf::Transformable, public Toolkit::Debuggable {
|
||||
class Ribbon final : public sf::Drawable, public sf::Transformable, public HoldsSharedResources, public Toolkit::Debuggable {
|
||||
public:
|
||||
Ribbon(SharedResources& t_resources);
|
||||
void title_sort(const Data::SongList& song_list);
|
||||
@ -58,7 +58,6 @@ namespace MusicSelect {
|
||||
std::vector<std::array<std::shared_ptr<Panel>,3>> m_layout;
|
||||
std::size_t m_position = 0;
|
||||
mutable std::optional<MoveAnimation> m_move_animation;
|
||||
SharedResources& m_resources;
|
||||
float m_time_factor = 1.f;
|
||||
Data::Song empty_song;
|
||||
};
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "Panel.hpp"
|
||||
|
||||
namespace MusicSelect {
|
||||
SharedResources::SharedResources(Data::Preferences& p) :
|
||||
preferences(p),
|
||||
|
@ -10,8 +10,6 @@
|
||||
#include "../../Data/Preferences.hpp"
|
||||
#include "../../Data/SongList.hpp"
|
||||
|
||||
#include "Panel.hpp"
|
||||
|
||||
namespace MusicSelect {
|
||||
|
||||
class SelectablePanel;
|
||||
@ -41,4 +39,17 @@ namespace MusicSelect {
|
||||
sf::Color ADV_color = sf::Color{252,212,32};
|
||||
sf::Color EXT_color = sf::Color{234,46,32};
|
||||
};
|
||||
|
||||
struct HoldsSharedResources {
|
||||
HoldsSharedResources(SharedResources& resources) : m_resources(resources) {};
|
||||
float get_screen_width() const {return static_cast<float>(m_resources.preferences.screen.width);};
|
||||
float get_screen_height() const {return static_cast<float>(m_resources.preferences.screen.height);};
|
||||
float get_panel_size() const {return m_resources.preferences.layout.panel_size*get_screen_width();};
|
||||
float get_panel_spacing() const {return m_resources.preferences.layout.panel_spacing*get_screen_width();};
|
||||
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();};
|
||||
protected:
|
||||
SharedResources& m_resources;
|
||||
};
|
||||
}
|
@ -1,11 +1,14 @@
|
||||
#include "SongInfo.hpp"
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <SFML/Graphics/Sprite.hpp>
|
||||
|
||||
#include "Panel.hpp"
|
||||
|
||||
namespace MusicSelect {
|
||||
|
||||
BigCover::BigCover(SharedResources& resources) :
|
||||
m_resources(resources)
|
||||
HoldsSharedResources(resources)
|
||||
{
|
||||
m_cover_fallback.setSize({get_size(), get_size()});
|
||||
m_cover_fallback.setFillColor(sf::Color::Transparent);
|
||||
@ -45,7 +48,7 @@ namespace MusicSelect {
|
||||
}
|
||||
|
||||
SongInfo::SongInfo(SharedResources& resources) :
|
||||
m_resources(resources),
|
||||
HoldsSharedResources(resources),
|
||||
m_big_cover(resources)
|
||||
{
|
||||
m_big_cover.setOrigin(
|
||||
@ -79,7 +82,7 @@ namespace MusicSelect {
|
||||
song_title,
|
||||
m_resources.noto_sans_medium,
|
||||
static_cast<unsigned int>(
|
||||
0.026315789f*get_width()
|
||||
0.026315789f*get_screen_width()
|
||||
)
|
||||
};
|
||||
auto song_title_bounds = song_title_label.getLocalBounds();
|
||||
@ -90,7 +93,7 @@ namespace MusicSelect {
|
||||
auto cover_pos = m_big_cover.getPosition();
|
||||
song_title_label.setPosition(
|
||||
get_big_cover_x() - m_big_cover.get_size()/2.f,
|
||||
get_big_cover_y() + m_big_cover.get_size() + 0.01f*get_width()
|
||||
get_big_cover_y() + m_big_cover.get_size() + 0.01f*get_screen_width()
|
||||
);
|
||||
target.draw(song_title_label);
|
||||
}
|
||||
@ -100,7 +103,7 @@ namespace MusicSelect {
|
||||
song_artist,
|
||||
m_resources.noto_sans_medium,
|
||||
static_cast<unsigned int>(
|
||||
0.02f*get_width()
|
||||
0.02f*get_screen_width()
|
||||
)
|
||||
};
|
||||
song_artist_label.setStyle(sf::Text::Italic);
|
||||
@ -113,7 +116,7 @@ namespace MusicSelect {
|
||||
auto cover_pos = m_big_cover.getPosition();
|
||||
song_artist_label.setPosition(
|
||||
get_big_cover_x() - m_big_cover.get_size()/2.f,
|
||||
get_big_cover_y() + m_big_cover.get_size() + 0.05f*get_width()
|
||||
get_big_cover_y() + m_big_cover.get_size() + 0.05f*get_screen_width()
|
||||
);
|
||||
target.draw(song_artist_label);
|
||||
}
|
||||
|
@ -9,28 +9,23 @@
|
||||
|
||||
namespace MusicSelect {
|
||||
|
||||
class BigCover : public sf::Drawable, public sf::Transformable {
|
||||
class BigCover : public sf::Drawable, public sf::Transformable, public HoldsSharedResources {
|
||||
public:
|
||||
BigCover(SharedResources& resources);
|
||||
float get_size() const {return m_resources.preferences.layout.big_cover_size*m_resources.preferences.screen.width;};
|
||||
float get_size() const {return m_resources.preferences.layout.big_cover_size*get_screen_width();};
|
||||
private:
|
||||
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
||||
SharedResources& m_resources;
|
||||
sf::RectangleShape m_cover_fallback;
|
||||
const Toolkit::AffineTransform<float> m_seconds_to_alpha{0.0f, 0.3f, 0.f, 255.f};
|
||||
};
|
||||
|
||||
// Displays the song info on the top part of the screen
|
||||
class SongInfo : public sf::Drawable, public sf::Transformable {
|
||||
class SongInfo : public sf::Drawable, public sf::Transformable, public HoldsSharedResources {
|
||||
public:
|
||||
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;
|
||||
BigCover m_big_cover;
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user