Basic Options Menu
This commit is contained in:
parent
d7427bcf51
commit
2e0921f707
@ -7,6 +7,7 @@
|
||||
|
||||
#include "../../Data/Buttons.hpp"
|
||||
#include "../../Data/KeyMapping.hpp"
|
||||
#include "../../Toolkit/NormalizedOrigin.hpp"
|
||||
#include "Panels/Panel.hpp"
|
||||
#include "PanelLayout.hpp"
|
||||
|
||||
@ -25,6 +26,12 @@ MusicSelect::Screen::Screen(
|
||||
black_frame(t_preferences),
|
||||
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;
|
||||
}
|
||||
|
||||
@ -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_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()) {
|
||||
sf::Event 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_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;
|
||||
default:
|
||||
break;
|
||||
@ -77,6 +107,10 @@ void MusicSelect::Screen::select_chart(sf::RenderWindow& window) {
|
||||
window.clear(sf::Color(7, 23, 53));
|
||||
ribbon.draw_debug();
|
||||
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(song_info);
|
||||
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) {
|
||||
button_highlight.button_pressed(button);
|
||||
auto button_index = Data::button_to_index(button);
|
||||
// Are we displaying the options menu ?
|
||||
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 {
|
||||
if (button_index < 12) {
|
||||
ribbon.click_on(button);
|
||||
} else {
|
||||
switch (button) {
|
||||
case Data::Button::B13:
|
||||
case Data::Button::B13: // Left Arrow
|
||||
ribbon.move_left();
|
||||
break;
|
||||
case Data::Button::B14:
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ namespace MusicSelect {
|
||||
ButtonHighlight button_highlight;
|
||||
|
||||
Drawables::BlackFrame black_frame;
|
||||
sf::RectangleShape panel_filter;
|
||||
|
||||
Data::KeyMapping key_mapping;
|
||||
// converts a key press into a button press
|
||||
|
@ -7,21 +7,48 @@
|
||||
#include "Panels/MarkerPanel.hpp"
|
||||
|
||||
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),
|
||||
Ribbon(MainOptionPage::create_layout(resources), resources)
|
||||
m_ribbon(layout, resources)
|
||||
{
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void MainOptionPage::click(const Data::Button& button) {
|
||||
click_on(button);
|
||||
void RibbonPage::click(const Data::Button& 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 {
|
||||
this->Ribbon::draw(target, states);
|
||||
void RibbonPage::draw(sf::RenderTarget& target, sf::RenderStates states) const {
|
||||
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) {
|
||||
std::vector<jbcoe::polymorphic_value<Panel>> subpages;
|
||||
jbcoe::polymorphic_value<OptionPage> marker_select{MarkerSelect{resources}};
|
||||
@ -30,18 +57,9 @@ namespace MusicSelect {
|
||||
}
|
||||
|
||||
MarkerSelect::MarkerSelect(SharedResources& resources) :
|
||||
OptionPage(resources),
|
||||
Ribbon(MarkerSelect::create_layout(resources), resources)
|
||||
RibbonPage(MarkerSelect::create_layout(resources), resources)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
update();
|
||||
}
|
||||
|
||||
PanelLayout MarkerSelect::create_layout(SharedResources& resources) {
|
||||
|
@ -15,27 +15,34 @@ namespace MusicSelect {
|
||||
class OptionPage : public sf::Drawable, public sf::Transformable, public HoldsSharedResources {
|
||||
public:
|
||||
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 ~OptionPage() = default;
|
||||
private:
|
||||
|
||||
void update();
|
||||
};
|
||||
|
||||
class MainOptionPage final : virtual public OptionPage, public Ribbon {
|
||||
class RibbonPage : public OptionPage {
|
||||
public:
|
||||
MainOptionPage(SharedResources& resources);
|
||||
RibbonPage(const PanelLayout& layout, SharedResources& resources);
|
||||
void click(const Data::Button& button) override;
|
||||
private:
|
||||
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);
|
||||
};
|
||||
|
||||
class MarkerSelect final : virtual public OptionPage, public Ribbon {
|
||||
class MarkerSelect final : public RibbonPage {
|
||||
public:
|
||||
MarkerSelect(SharedResources& resources);
|
||||
void click(const Data::Button& button) override;
|
||||
private:
|
||||
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
||||
static PanelLayout create_layout(SharedResources& resources);
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user