1
0
mirror of synced 2024-11-14 18:47:41 +01:00

Basic Options Menu

This commit is contained in:
Stepland 2020-03-02 18:32:15 +01:00
parent d7427bcf51
commit 2e0921f707
4 changed files with 117 additions and 35 deletions

View File

@ -7,6 +7,7 @@
#include "../../Data/Buttons.hpp" #include "../../Data/Buttons.hpp"
#include "../../Data/KeyMapping.hpp" #include "../../Data/KeyMapping.hpp"
#include "../../Toolkit/NormalizedOrigin.hpp"
#include "Panels/Panel.hpp" #include "Panels/Panel.hpp"
#include "PanelLayout.hpp" #include "PanelLayout.hpp"
@ -25,6 +26,12 @@ MusicSelect::Screen::Screen(
black_frame(t_preferences), black_frame(t_preferences),
key_mapping() key_mapping()
{ {
panel_filter.setSize(sf::Vector2f(
resources.m_preferences.layout.panel_step()*resources.m_preferences.screen.width*4.f,
resources.m_preferences.layout.panel_step()*resources.m_preferences.screen.width*4.f
));
Toolkit::set_origin_normalized(panel_filter, 0.5f, 0.5f);
panel_filter.setFillColor(sf::Color(0,0,0,128));
std::cout << "loaded MusicSelect::Screen" << std::endl; std::cout << "loaded MusicSelect::Screen" << std::endl;
} }
@ -41,6 +48,16 @@ void MusicSelect::Screen::select_chart(sf::RenderWindow& window) {
resources.m_preferences.layout.ribbon_x*resources.m_preferences.screen.width, resources.m_preferences.layout.ribbon_x*resources.m_preferences.screen.width,
resources.m_preferences.layout.ribbon_y*resources.m_preferences.screen.width resources.m_preferences.layout.ribbon_y*resources.m_preferences.screen.width
); );
panel_filter.setPosition(
sf::Vector2f{resources.m_preferences.layout.ribbon_x + (
3.f*resources.m_preferences.layout.panel_spacing +
4.f*resources.m_preferences.layout.panel_size
) / 2.f,
resources.m_preferences.layout.ribbon_y + (
3.f*resources.m_preferences.layout.panel_spacing +
4.f*resources.m_preferences.layout.panel_size
) / 2.f}*static_cast<float>(resources.m_preferences.screen.width)
);
while ((not chart_selected) and window.isOpen()) { while ((not chart_selected) and window.isOpen()) {
sf::Event event; sf::Event event;
while (window.pollEvent(event)) { while (window.pollEvent(event)) {
@ -68,6 +85,19 @@ void MusicSelect::Screen::select_chart(sf::RenderWindow& window) {
resources.m_preferences.layout.ribbon_x*resources.m_preferences.screen.width, resources.m_preferences.layout.ribbon_x*resources.m_preferences.screen.width,
resources.m_preferences.layout.ribbon_y*resources.m_preferences.screen.width resources.m_preferences.layout.ribbon_y*resources.m_preferences.screen.width
); );
panel_filter.setPosition(
resources.m_preferences.layout.ribbon_x + (
3.f*resources.m_preferences.layout.panel_spacing +
4.f*resources.m_preferences.layout.panel_size
) / 2.f,
resources.m_preferences.layout.ribbon_y + (
3.f*resources.m_preferences.layout.panel_spacing +
4.f*resources.m_preferences.layout.panel_size
) / 2.f
);
if (not resources.options_state.empty()) {
resources.options_state.top()->update();
}
break; break;
default: default:
break; break;
@ -77,6 +107,10 @@ void MusicSelect::Screen::select_chart(sf::RenderWindow& window) {
window.clear(sf::Color(7, 23, 53)); window.clear(sf::Color(7, 23, 53));
ribbon.draw_debug(); ribbon.draw_debug();
window.draw(ribbon); window.draw(ribbon);
if (not resources.options_state.empty()) {
window.draw(panel_filter);
window.draw(*resources.options_state.top());
}
window.draw(button_highlight); window.draw(button_highlight);
window.draw(song_info); window.draw(song_info);
window.draw(black_frame); window.draw(black_frame);
@ -117,17 +151,39 @@ 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); 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) { // Are we displaying the options menu ?
ribbon.click_on(button); if (not resources.options_state.empty()) {
if (button_index < 14) {
resources.options_state.top()->click(button);
} else {
if (button == Data::Button::B15) {
resources.options_state.pop();
if (not resources.options_state.empty()) {
resources.options_state.top()->update();
}
}
}
} else { } else {
switch (button) { if (button_index < 12) {
case Data::Button::B13: ribbon.click_on(button);
ribbon.move_left(); } else {
break; switch (button) {
case Data::Button::B14: case Data::Button::B13: // Left Arrow
ribbon.move_right(); ribbon.move_left();
default: break;
break; case Data::Button::B14: // Right Arrow
ribbon.move_right();
break;
case Data::Button::B15: // Options Menu
resources.options_state.push(
jbcoe::polymorphic_value<OptionPage>(
MainOptionPage{resources}
)
);
break;
default:
break;
}
} }
} }
} }

View File

@ -47,6 +47,7 @@ namespace MusicSelect {
ButtonHighlight button_highlight; ButtonHighlight button_highlight;
Drawables::BlackFrame black_frame; Drawables::BlackFrame black_frame;
sf::RectangleShape panel_filter;
Data::KeyMapping key_mapping; Data::KeyMapping key_mapping;
// converts a key press into a button press // converts a key press into a button press

View File

@ -7,21 +7,48 @@
#include "Panels/MarkerPanel.hpp" #include "Panels/MarkerPanel.hpp"
namespace MusicSelect { namespace MusicSelect {
MainOptionPage::MainOptionPage(SharedResources& resources) :
void OptionPage::update() {
this->setPosition(get_ribbon_x(), get_ribbon_y());
}
RibbonPage::RibbonPage(const PanelLayout& layout, SharedResources& resources) :
OptionPage(resources), OptionPage(resources),
Ribbon(MainOptionPage::create_layout(resources), resources) m_ribbon(layout, resources)
{ {
update();
} }
void MainOptionPage::click(const Data::Button& button) { void RibbonPage::click(const Data::Button& button) {
click_on(button); auto button_index = Data::button_to_index(button);
if (button_index < 12) {
m_ribbon.click_on(button);
} else {
switch (button) {
case Data::Button::B13:
m_ribbon.move_left();
break;
case Data::Button::B14:
m_ribbon.move_right();
break;
default:
break;
}
}
} }
void MainOptionPage::draw(sf::RenderTarget& target, sf::RenderStates states) const { void RibbonPage::draw(sf::RenderTarget& target, sf::RenderStates states) const {
this->Ribbon::draw(target, states); states.transform *= getTransform();
target.draw(m_ribbon, states);
} }
MainOptionPage::MainOptionPage(SharedResources& resources) :
RibbonPage(MainOptionPage::create_layout(resources), resources)
{
update();
}
PanelLayout MainOptionPage::create_layout(SharedResources& resources) { PanelLayout MainOptionPage::create_layout(SharedResources& resources) {
std::vector<jbcoe::polymorphic_value<Panel>> subpages; std::vector<jbcoe::polymorphic_value<Panel>> subpages;
jbcoe::polymorphic_value<OptionPage> marker_select{MarkerSelect{resources}}; jbcoe::polymorphic_value<OptionPage> marker_select{MarkerSelect{resources}};
@ -30,18 +57,9 @@ namespace MusicSelect {
} }
MarkerSelect::MarkerSelect(SharedResources& resources) : MarkerSelect::MarkerSelect(SharedResources& resources) :
OptionPage(resources), RibbonPage(MarkerSelect::create_layout(resources), resources)
Ribbon(MarkerSelect::create_layout(resources), resources)
{ {
update();
}
void MarkerSelect::click(const Data::Button& button) {
click_on(button);
}
void MarkerSelect::draw(sf::RenderTarget& target, sf::RenderStates states) const {
this->Ribbon::draw(target, states);
} }
PanelLayout MarkerSelect::create_layout(SharedResources& resources) { PanelLayout MarkerSelect::create_layout(SharedResources& resources) {

View File

@ -15,27 +15,34 @@ 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) {}; OptionPage(SharedResources& resources) : HoldsSharedResources(resources) {};
// An option page should only every recive button presses ranging for 1 to 14
// Going back a menu should be handled by the MusicSelect screen to avoid destroying the menu
// while still being in a click() call on it
virtual void click(const Data::Button& button) = 0; virtual void click(const Data::Button& button) = 0;
virtual ~OptionPage() = default; virtual ~OptionPage() = default;
private: void update();
}; };
class MainOptionPage final : virtual public OptionPage, public Ribbon { class RibbonPage : public OptionPage {
public: public:
MainOptionPage(SharedResources& resources); RibbonPage(const PanelLayout& layout, SharedResources& resources);
void click(const Data::Button& button) override; void click(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;
Ribbon m_ribbon;
};
class MainOptionPage final : public RibbonPage {
public:
MainOptionPage(SharedResources& resources);
private:
static PanelLayout create_layout(SharedResources& resources); static PanelLayout create_layout(SharedResources& resources);
}; };
class MarkerSelect final : virtual public OptionPage, public Ribbon { class MarkerSelect final : public RibbonPage {
public: public:
MarkerSelect(SharedResources& resources); MarkerSelect(SharedResources& resources);
void click(const Data::Button& button) override;
private: private:
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
static PanelLayout create_layout(SharedResources& resources); static PanelLayout create_layout(SharedResources& resources);
}; };
} }