OptionPages can now handle raw input if needed
This commit is contained in:
parent
e473f8c2c0
commit
3f9c482d25
4
TODO.md
4
TODO.md
@ -24,9 +24,11 @@
|
|||||||
- cd
|
- cd
|
||||||
- Sound
|
- Sound
|
||||||
- Sound Effects
|
- Sound Effects
|
||||||
- Options menu
|
### Options menu
|
||||||
- Global Offset
|
- Global Offset
|
||||||
- Volume Settings
|
- Volume Settings
|
||||||
|
- Give marker selection the timing check feature when your re-click on the same panel
|
||||||
|
|
||||||
|
|
||||||
## memo Compatibility
|
## memo Compatibility
|
||||||
|
|
||||||
|
@ -130,6 +130,23 @@ void MusicSelect::Screen::draw_debug() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MusicSelect::Screen::handle_key_press(const sf::Event::KeyEvent& key_event) {
|
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);
|
auto button = key_mapping.key_to_button(key_event.code);
|
||||||
if (button) {
|
if (button) {
|
||||||
press_button(*button);
|
press_button(*button);
|
||||||
@ -180,19 +197,6 @@ 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);
|
||||||
// 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (button_index < 12) {
|
if (button_index < 12) {
|
||||||
ribbon.click_on(button);
|
ribbon.click_on(button);
|
||||||
} else {
|
} else {
|
||||||
@ -212,4 +216,3 @@ void MusicSelect::Screen::press_button(const Data::Button& button) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -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);
|
auto button_index = Data::button_to_index(button);
|
||||||
if (button_index < 12) {
|
if (button_index < 12) {
|
||||||
m_ribbon.click_on(button);
|
m_ribbon.click_on(button);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <jbcoe/polymorphic_value.h>
|
#include <jbcoe/polymorphic_value.h>
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
|
#include <SFML/Window/Event.hpp>
|
||||||
|
|
||||||
#include "../../Data/Buttons.hpp"
|
#include "../../Data/Buttons.hpp"
|
||||||
#include "Ribbon.hpp"
|
#include "Ribbon.hpp"
|
||||||
@ -15,10 +16,8 @@ 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& resources) : HoldsSharedResources(resources) {update();};
|
||||||
// An option page should only every recive button presses ranging for 1 to 14
|
// Returns true if input was used
|
||||||
// Going back a menu should be handled by the MusicSelect screen to avoid destroying the menu
|
virtual bool handle_raw_input(const sf::Event::KeyEvent& event) = 0;
|
||||||
// while still being in a click() call on it
|
|
||||||
virtual void click(const Data::Button& button) = 0;
|
|
||||||
virtual ~OptionPage() = default;
|
virtual ~OptionPage() = default;
|
||||||
void update();
|
void update();
|
||||||
};
|
};
|
||||||
@ -26,7 +25,8 @@ namespace MusicSelect {
|
|||||||
class RibbonPage : public OptionPage {
|
class RibbonPage : public OptionPage {
|
||||||
public:
|
public:
|
||||||
RibbonPage(const PanelLayout& layout, SharedResources& resources);
|
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:
|
private:
|
||||||
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
||||||
Ribbon m_ribbon;
|
Ribbon m_ribbon;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user