1
0
mirror of synced 2024-11-14 10:37:40 +01:00

OptionPages can now handle raw input if needed

This commit is contained in:
Stepland 2020-03-07 18:21:39 +01:00
parent e473f8c2c0
commit 3f9c482d25
4 changed files with 56 additions and 38 deletions

View File

@ -24,9 +24,11 @@
- cd
- Sound
- Sound Effects
- Options menu
- Global Offset
- Volume Settings
### Options menu
- Global Offset
- Volume Settings
- Give marker selection the timing check feature when your re-click on the same panel
## memo Compatibility

View File

@ -130,6 +130,23 @@ void MusicSelect::Screen::draw_debug() {
}
void MusicSelect::Screen::handle_key_press(const sf::Event::KeyEvent& key_event) {
// Option Menu takes raw input for potential remapping of keys
bool output_used = false;
if (not resources.options_state.empty()) {
// Safety measure, pressing escape will alway pop the menu page
if (key_event.code == sf::Keyboard::Escape) {
resources.options_state.pop();
if (not resources.options_state.empty()) {
resources.options_state.top().get().update();
}
output_used = true;
} else {
output_used = resources.options_state.top().get().handle_raw_input(key_event);
}
}
if (output_used) {
return;
}
auto button = key_mapping.key_to_button(key_event.code);
if (button) {
press_button(*button);
@ -180,36 +197,22 @@ 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().get().click(button);
} else {
if (button == Data::Button::B15) {
resources.options_state.pop();
if (not resources.options_state.empty()) {
resources.options_state.top().get().update();
}
}
}
if (button_index < 12) {
ribbon.click_on(button);
} else {
if (button_index < 12) {
ribbon.click_on(button);
} else {
switch (button) {
case Data::Button::B13: // Left Arrow
ribbon.move_left();
break;
case Data::Button::B14: // Right Arrow
ribbon.move_right();
break;
case Data::Button::B15: // Options Menu
resources.options_state.push(main_option_page);
resources.options_state.top().get().update();
break;
default:
break;
}
switch (button) {
case Data::Button::B13: // Left Arrow
ribbon.move_left();
break;
case Data::Button::B14: // Right Arrow
ribbon.move_right();
break;
case Data::Button::B15: // Options Menu
resources.options_state.push(main_option_page);
resources.options_state.top().get().update();
break;
default:
break;
}
}
}

View File

@ -20,7 +20,20 @@ namespace MusicSelect {
{
}
void RibbonPage::click(const Data::Button& button) {
bool MusicSelect::RibbonPage::handle_raw_input(const sf::Event::KeyEvent& key_event) {
auto button = m_preferences.key_mapping.key_to_button(key_event.code);
if (not button) {
return false;
}
auto button_index = Data::button_to_index(*button);
if (button_index > 12) {
return false;
}
button_click(*button);
return true;
}
void RibbonPage::button_click(const Data::Button& button) {
auto button_index = Data::button_to_index(button);
if (button_index < 12) {
m_ribbon.click_on(button);

View File

@ -2,6 +2,7 @@
#include <jbcoe/polymorphic_value.h>
#include <SFML/Graphics.hpp>
#include <SFML/Window/Event.hpp>
#include "../../Data/Buttons.hpp"
#include "Ribbon.hpp"
@ -15,10 +16,8 @@ namespace MusicSelect {
class OptionPage : public sf::Drawable, public sf::Transformable, public HoldsSharedResources {
public:
OptionPage(SharedResources& resources) : HoldsSharedResources(resources) {update();};
// 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;
// Returns true if input was used
virtual bool handle_raw_input(const sf::Event::KeyEvent& event) = 0;
virtual ~OptionPage() = default;
void update();
};
@ -26,7 +25,8 @@ namespace MusicSelect {
class RibbonPage : public OptionPage {
public:
RibbonPage(const PanelLayout& layout, SharedResources& resources);
void click(const Data::Button& button) override;
bool handle_raw_input(const sf::Event::KeyEvent& event) override;
void button_click(const Data::Button& button);
private:
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
Ribbon m_ribbon;