1
0
mirror of synced 2025-02-02 20:37:25 +01:00

Switch to reference_wrapper instead of polymorphic_value

This commit is contained in:
Stepland 2020-03-03 19:47:30 +01:00
parent bb17574c63
commit 4b5bb697c0
7 changed files with 18 additions and 19 deletions

View File

@ -1,11 +1,12 @@
#include "MusicSelect.hpp" #include "MusicSelect.hpp"
#include <functional>
#include <iostream>
#include <imgui/imgui.h> #include <imgui/imgui.h>
#include <imgui/misc/cpp/imgui_stdlib.h> #include <imgui/misc/cpp/imgui_stdlib.h>
#include <imgui-sfml/imgui-SFML.h> #include <imgui-sfml/imgui-SFML.h>
#include <iostream>
#include "../../Data/Buttons.hpp" #include "../../Data/Buttons.hpp"
#include "../../Data/KeyMapping.hpp" #include "../../Data/KeyMapping.hpp"
#include "../../Toolkit/NormalizedOrigin.hpp" #include "../../Toolkit/NormalizedOrigin.hpp"
@ -22,8 +23,8 @@ MusicSelect::Screen::Screen(
markers(t_markers), markers(t_markers),
ribbon(PanelLayout::title_sort(t_song_list, resources), resources), ribbon(PanelLayout::title_sort(t_song_list, resources), resources),
song_info(resources), song_info(resources),
selected_panel(),
button_highlight(resources), button_highlight(resources),
main_option_page(resources),
black_frame(t_preferences), black_frame(t_preferences),
key_mapping() key_mapping()
{ {
@ -97,7 +98,7 @@ void MusicSelect::Screen::select_chart(sf::RenderWindow& window) {
) / 2.f}*static_cast<float>(resources.m_preferences.screen.width) ) / 2.f}*static_cast<float>(resources.m_preferences.screen.width)
); );
if (not resources.options_state.empty()) { if (not resources.options_state.empty()) {
resources.options_state.top()->update(); resources.options_state.top().get().update();
} }
break; break;
default: default:
@ -110,7 +111,7 @@ void MusicSelect::Screen::select_chart(sf::RenderWindow& window) {
window.draw(ribbon); window.draw(ribbon);
if (not resources.options_state.empty()) { if (not resources.options_state.empty()) {
window.draw(panel_filter); window.draw(panel_filter);
window.draw(*resources.options_state.top()); window.draw(resources.options_state.top());
} }
window.draw(button_highlight); window.draw(button_highlight);
window.draw(song_info); window.draw(song_info);
@ -185,12 +186,12 @@ void MusicSelect::Screen::press_button(const Data::Button& button) {
// Are we displaying the options menu ? // Are we displaying the options menu ?
if (not resources.options_state.empty()) { if (not resources.options_state.empty()) {
if (button_index < 14) { if (button_index < 14) {
resources.options_state.top()->click(button); resources.options_state.top().get().click(button);
} else { } else {
if (button == Data::Button::B15) { if (button == Data::Button::B15) {
resources.options_state.pop(); resources.options_state.pop();
if (not resources.options_state.empty()) { if (not resources.options_state.empty()) {
resources.options_state.top()->update(); resources.options_state.top().get().update();
} }
} }
} }
@ -206,11 +207,7 @@ void MusicSelect::Screen::press_button(const Data::Button& button) {
ribbon.move_right(); ribbon.move_right();
break; break;
case Data::Button::B15: // Options Menu case Data::Button::B15: // Options Menu
resources.options_state.push( resources.options_state.push(main_option_page);
jbcoe::polymorphic_value<OptionPage>(
MainOptionPage{resources}
)
);
break; break;
default: default:
break; break;

View File

@ -44,8 +44,8 @@ namespace MusicSelect {
// State // State
Ribbon ribbon; Ribbon ribbon;
SongInfo song_info; SongInfo song_info;
std::optional<std::reference_wrapper<SongPanel>> selected_panel;
ButtonHighlight button_highlight; ButtonHighlight button_highlight;
MainOptionPage main_option_page;
Drawables::BlackFrame black_frame; Drawables::BlackFrame black_frame;
sf::RectangleShape panel_filter; sf::RectangleShape panel_filter;

View File

@ -1,5 +1,6 @@
#include "OptionPage.hpp" #include "OptionPage.hpp"
#include <iostream>
#include <vector> #include <vector>
#include "Ribbon.hpp" #include "Ribbon.hpp"
@ -63,7 +64,7 @@ namespace MusicSelect {
} }
MarkerSelect::~MarkerSelect() { MarkerSelect::~MarkerSelect() {
m_resources.selected_marker.reset(); m_resources.selected_marker.reset();
} }
PanelLayout MarkerSelect::create_layout(SharedResources& resources) { PanelLayout MarkerSelect::create_layout(SharedResources& resources) {

View File

@ -4,7 +4,7 @@
namespace MusicSelect { namespace MusicSelect {
void SubpagePanel::click(Ribbon&, const Data::Button&) { void SubpagePanel::click(Ribbon&, const Data::Button&) {
m_resources.options_state.push(m_subpage); m_resources.options_state.push(*m_subpage);
} }
void SubpagePanel::draw(sf::RenderTarget& target, sf::RenderStates states) const { void SubpagePanel::draw(sf::RenderTarget& target, sf::RenderStates states) const {

View File

@ -163,7 +163,7 @@ namespace MusicSelect {
for (int column_offset = -1; column_offset <= 4; column_offset++) { 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(); std::size_t actual_column = (column_zero + column_offset + m_layout.size()) % m_layout.size();
for (int row = 0; row < 3; row++) { for (int row = 0; row < 3; row++) {
auto panel = m_layout.at(actual_column).at(row); auto& panel = m_layout.at(actual_column).at(row);
panel->setPosition( panel->setPosition(
(static_cast<float>(relative_column_zero + column_offset) - float_position) * (get_panel_step()), (static_cast<float>(relative_column_zero + column_offset) - float_position) * (get_panel_step()),
row * (get_panel_step()) row * (get_panel_step())
@ -177,7 +177,7 @@ namespace MusicSelect {
for (int column = -1; column <= 4; column++) { for (int column = -1; column <= 4; column++) {
int actual_column_index = (column + m_position + m_layout.size()) % m_layout.size(); int actual_column_index = (column + m_position + m_layout.size()) % m_layout.size();
for (int row = 0; row < 3; row++) { for (int row = 0; row < 3; row++) {
auto panel = m_layout.at(actual_column_index).at(row); auto& panel = m_layout.at(actual_column_index).at(row);
panel->setPosition(column * (get_panel_step()), row * (get_panel_step())); panel->setPosition(column * (get_panel_step()), row * (get_panel_step()));
target.draw(*panel, states); target.draw(*panel, states);
} }

View File

@ -54,7 +54,7 @@ namespace MusicSelect {
void draw_with_animation(sf::RenderTarget& target, sf::RenderStates states) const; void draw_with_animation(sf::RenderTarget& target, sf::RenderStates states) const;
void draw_without_animation(sf::RenderTarget& target, sf::RenderStates states) const; void draw_without_animation(sf::RenderTarget& target, sf::RenderStates states) const;
std::size_t get_layout_column(const Data::Button& button) const; std::size_t get_layout_column(const Data::Button& button) const;
PanelLayout m_layout; mutable PanelLayout m_layout;
std::size_t m_position = 0; std::size_t m_position = 0;
mutable std::optional<MoveAnimation> m_move_animation; mutable std::optional<MoveAnimation> m_move_animation;
float m_time_factor = 1.f; float m_time_factor = 1.f;

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <cstddef> #include <cstddef>
#include <functional>
#include <optional> #include <optional>
#include <jbcoe/polymorphic_value.h> #include <jbcoe/polymorphic_value.h>
@ -61,7 +62,7 @@ namespace MusicSelect {
MusicPreview music_preview; MusicPreview music_preview;
std::stack<jbcoe::polymorphic_value<OptionPage>> options_state; std::stack<std::reference_wrapper<OptionPage>> options_state;
const Resources::Markers& markers; const Resources::Markers& markers;