1
0
mirror of synced 2025-02-02 12:27:20 +01:00

Add debug interface for MusicSelect::Screen

This commit is contained in:
Stepland 2020-03-03 02:42:16 +01:00
parent dc4c69c0cb
commit f092804f16
9 changed files with 83 additions and 25 deletions

View File

@ -82,6 +82,6 @@ namespace Resources {
sf::Texture m_perfect;
};
using Markers = std::multimap<std::string, Marker>;
using Markers = std::map<std::string, Marker>;
Markers load_markers();
}

View File

@ -1,7 +1,8 @@
#include "MusicSelect.hpp"
#include "imgui/imgui.h"
#include "imgui-sfml/imgui-SFML.h"
#include <imgui/imgui.h>
#include <imgui/misc/cpp/imgui_stdlib.h>
#include <imgui-sfml/imgui-SFML.h>
#include <iostream>
@ -31,6 +32,9 @@ MusicSelect::Screen::Screen(
resources.m_preferences.layout.panel_step()*resources.m_preferences.screen.width*4.f
));
Toolkit::set_origin_normalized(panel_filter, 0.5f, 0.5f);
if (resources.m_preferences.options.marker.empty()) {
resources.m_preferences.options.marker = markers.begin()->second.m_metadata.name;
}
panel_filter.setFillColor(sf::Color(0,0,0,128));
std::cout << "loaded MusicSelect::Screen" << std::endl;
}
@ -114,6 +118,7 @@ void MusicSelect::Screen::select_chart(sf::RenderWindow& window) {
window.draw(button_highlight);
window.draw(song_info);
window.draw(black_frame);
draw_debug();
ImGui::SFML::Render(window);
window.display();
resources.music_preview.update();
@ -121,6 +126,34 @@ void MusicSelect::Screen::select_chart(sf::RenderWindow& window) {
ImGui::SFML::Shutdown();
}
void MusicSelect::Screen::draw_debug() {
if (debug) {
if (ImGui::Begin("MusicSelect::Screen")) {
if (ImGui::CollapsingHeader("Preferences")) {
if (ImGui::TreeNode("screen")) {
ImGui::TextUnformatted("width : "); ImGui::SameLine();
ImGui::Text("%s", std::to_string(resources.m_preferences.screen.width).c_str());
ImGui::TextUnformatted("height : "); ImGui::SameLine();
ImGui::Text("%s", std::to_string(resources.m_preferences.screen.height).c_str());
ImGui::TextUnformatted("fullscreen : "); ImGui::SameLine();
ImGui::Text("%s", resources.m_preferences.screen.fullscreen ? "true" : "false");
ImGui::TreePop();
}
if (ImGui::TreeNode("layout")) {
ImGui::TreePop();
}
if (ImGui::TreeNode("options")) {
ImGui::TextUnformatted("marker : "); ImGui::SameLine();
ImGui::Text("%s", resources.m_preferences.options.marker.c_str());
ImGui::TreePop();
}
}
}
ImGui::End();
}
}
void MusicSelect::Screen::handle_key_press(const sf::Event::KeyEvent& key_event) {
auto button = key_mapping.key_to_button(key_event.code);
if (button) {
@ -129,6 +162,7 @@ void MusicSelect::Screen::handle_key_press(const sf::Event::KeyEvent& key_event)
switch (key_event.code){
case sf::Keyboard::F12:
ribbon.debug = not ribbon.debug;
debug = not debug;
break;
default:
break;

View File

@ -12,6 +12,7 @@
#include "../../Drawables/BlackFrame.hpp"
#include "../../Resources/Marker.hpp"
#include "../../Toolkit/AffineTransform.hpp"
#include "../../Toolkit/Debuggable.hpp"
#include "Ribbon.hpp"
#include "SongInfo.hpp"
#include "SharedResources.hpp"
@ -23,7 +24,7 @@ namespace MusicSelect {
class SongPanel;
// The music select screen is created only once
// it loads a cache of available songs in the song_list attribute
class Screen {
class Screen : public Toolkit::Debuggable {
public:
Screen(
const Data::SongList& t_song_list,
@ -31,7 +32,7 @@ namespace MusicSelect {
const Resources::Markers& t_markers
);
void select_chart(sf::RenderWindow& window);
void draw_debug() override;
private:
// Data
const Data::SongList song_list;

View File

@ -8,26 +8,43 @@ namespace MusicSelect {
m_marker(marker)
{
if (m_resources.m_preferences.options.marker == marker.m_metadata.name) {
selected_since.emplace();
select();
}
}
void MarkerPanel::click(Ribbon&, const Data::Button&) {
if (not selected_since) {
selected_since.emplace();
m_resources.m_preferences.options.marker = m_marker.m_metadata.name;
if (selected) {
m_resources.selected_marker->last_click.restart();
m_resources.selected_marker->is_first_click = false;
} else {
select();
}
}
void MarkerPanel::draw(sf::RenderTarget& target, sf::RenderStates states) const {
states.transform *= getTransform();
float animation_time = 0.f;
if (selected_since) {
animation_time = std::fmod(selected_since->getElapsedTime().asSeconds(), 2.f) - 1.f;
if (selected) {
animation_time = std::fmod(m_resources.selected_marker->last_click.getElapsedTime().asSeconds(), 2.f) - 1.f;
}
auto sprite = m_marker.get_sprite(Resources::MarkerAnimation::APPROACH, animation_time);
if (sprite) {
auto bounds = sprite->getGlobalBounds();
sprite->setScale(get_panel_size()/bounds.width, get_panel_size()/bounds.height);
target.draw(*sprite, states);
}
}
void MarkerPanel::select() {
if (m_resources.selected_marker) {
m_resources.selected_marker->obj.unselect();
}
m_resources.selected_marker.emplace(*this);
m_resources.m_preferences.options.marker == m_marker.m_metadata.name;
this->selected = true;
}
void MarkerPanel::unselect() {
this->selected = false;
}
}

View File

@ -14,7 +14,9 @@ namespace MusicSelect {
void click(Ribbon&, const Data::Button&) override;
private:
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
void select();
void unselect();
const Resources::Marker& m_marker;
mutable std::optional<sf::Clock> selected_since;
bool selected = false;
};
}

View File

@ -87,9 +87,9 @@ namespace MusicSelect {
}
// The song was not selected before : first unselect the last one
if (m_resources.selected_panel.has_value()) {
m_resources.selected_panel->panel.unselect();
m_resources.selected_panel->obj.unselect();
}
m_resources.selected_panel.emplace(TimedSelectedPanel{*this});
m_resources.selected_panel.emplace(*this);
m_resources.music_preview.play(m_song->full_audio_path(), m_song->preview);
}
}

View File

@ -44,7 +44,7 @@ namespace MusicSelect {
if (not selected_panel.has_value()) {
return {};
}
auto chart_selection = selected_panel->panel.get_selected_difficulty();
auto chart_selection = selected_panel->obj.get_selected_difficulty();
if (not chart_selection.has_value()) {
return {};
}
@ -55,7 +55,7 @@ namespace MusicSelect {
if (not selected_panel.has_value()) {
return {};
}
auto chart_selection = selected_panel->panel.get_selected_difficulty();
auto chart_selection = selected_panel->obj.get_selected_difficulty();
if (not chart_selection.has_value()) {
return {};
}

View File

@ -19,11 +19,13 @@
namespace MusicSelect {
class SelectablePanel;
class MarkerPanel;
class OptionPage;
struct TimedSelectedPanel {
TimedSelectedPanel(SelectablePanel& s) : panel(s), first_click(), last_click() {};
SelectablePanel& panel;
template<class Object>
struct Timed {
Timed(Object& t_obj) : obj(t_obj), first_click(), last_click() {};
Object& obj;
sf::Clock first_click;
sf::Clock last_click;
bool is_first_click = true;
@ -47,7 +49,7 @@ namespace MusicSelect {
MusicSelect::DensityGraphCache density_graphs;
std::optional<TimedSelectedPanel> selected_panel;
std::optional<Timed<SelectablePanel>> selected_panel;
std::string get_last_selected_difficulty();
std::optional<std::string> get_selected_difficulty();
std::optional<std::reference_wrapper<const Data::Song>> get_selected_song();
@ -62,6 +64,8 @@ namespace MusicSelect {
std::stack<jbcoe::polymorphic_value<OptionPage>> options_state;
const Resources::Markers& markers;
std::optional<Timed<MarkerPanel>> selected_marker;
};
// Proxy for HoldsPreferences

View File

@ -28,7 +28,7 @@ namespace MusicSelect {
if (not selected_panel.has_value()) {
return;
}
auto selected_chart = selected_panel->panel.get_selected_difficulty();
auto selected_chart = selected_panel->obj.get_selected_difficulty();
if (not selected_chart.has_value()) {
return;
}
@ -73,7 +73,7 @@ namespace MusicSelect {
if (not selected_panel.has_value()) {
return;
}
auto selected_chart = selected_panel->panel.get_selected_difficulty();
auto selected_chart = selected_panel->obj.get_selected_difficulty();
if (not selected_chart.has_value()) {
return;
}
@ -126,7 +126,7 @@ namespace MusicSelect {
if (not selected_panel.has_value()) {
return;
}
auto selected_chart = selected_panel->panel.get_selected_difficulty();
auto selected_chart = selected_panel->obj.get_selected_difficulty();
if (not selected_chart.has_value()) {
return;
}
@ -175,7 +175,7 @@ namespace MusicSelect {
if (not selected_panel.has_value()) {
return;
}
auto selected_chart = selected_panel->panel.get_selected_difficulty();
auto selected_chart = selected_panel->obj.get_selected_difficulty();
if (not selected_chart.has_value()) {
return;
}
@ -225,7 +225,7 @@ namespace MusicSelect {
if (not selected_panel.has_value()) {
return;
}
auto selected_difficulty = selected_panel->panel.get_selected_difficulty();
auto selected_difficulty = selected_panel->obj.get_selected_difficulty();
if (not selected_difficulty.has_value()) {
return;
}