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

View File

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

View File

@ -1,5 +1,6 @@
#include "OptionPage.hpp"
#include <iostream>
#include <vector>
#include "Ribbon.hpp"

View File

@ -4,7 +4,7 @@
namespace MusicSelect {
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 {

View File

@ -163,7 +163,7 @@ namespace MusicSelect {
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();
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(
(static_cast<float>(relative_column_zero + column_offset) - float_position) * (get_panel_step()),
row * (get_panel_step())
@ -177,7 +177,7 @@ namespace MusicSelect {
for (int column = -1; column <= 4; column++) {
int actual_column_index = (column + m_position + m_layout.size()) % m_layout.size();
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()));
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_without_animation(sf::RenderTarget& target, sf::RenderStates states) 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;
mutable std::optional<MoveAnimation> m_move_animation;
float m_time_factor = 1.f;

View File

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