Small preference persistency system
This commit is contained in:
parent
f9b38e8661
commit
c8e80e8ac2
2
TODO.md
2
TODO.md
@ -22,7 +22,7 @@
|
||||
- Handling Resolution changes
|
||||
- Compute panel size from resolution
|
||||
- Top Screen Part Handling
|
||||
- Fullscreen handling
|
||||
- Fullscreen handling
|
||||
- Song Panel click
|
||||
- Chart Panel
|
||||
- Visible controls
|
||||
|
@ -30,6 +30,7 @@ sources = [
|
||||
'src/Data/KeyMapping.cpp',
|
||||
'src/Data/Note.hpp',
|
||||
'src/Data/Note.cpp',
|
||||
'src/Data/Preferences.hpp',
|
||||
'src/Data/Score.hpp',
|
||||
'src/Data/SongList.hpp',
|
||||
'src/Data/SongList.cpp',
|
||||
|
@ -1,7 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
namespace Data {
|
||||
struct Preferences {
|
||||
#include <cstddef>
|
||||
|
||||
#include <SFML/System.hpp>
|
||||
|
||||
namespace Data {
|
||||
|
||||
struct Screen {
|
||||
std::size_t width;
|
||||
std::size_t height;
|
||||
bool fullscreen;
|
||||
|
||||
template<class Archive>
|
||||
void serialize(Archive & archive) {
|
||||
archive(
|
||||
CEREAL_NVP(width),
|
||||
CEREAL_NVP(height),
|
||||
CEREAL_NVP(fullscreen)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
struct Layout {
|
||||
float panel_position_x;
|
||||
float panel_position_y;
|
||||
float panel_size;
|
||||
float panel_spacing;
|
||||
|
||||
template<class Archive>
|
||||
void serialize(Archive & archive) {
|
||||
archive(
|
||||
CEREAL_NVP(panel_position_x),
|
||||
CEREAL_NVP(panel_position_y),
|
||||
CEREAL_NVP(panel_size),
|
||||
CEREAL_NVP(panel_spacing)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// RAII style class which saves preferences when destructed
|
||||
struct Preferences {
|
||||
Screen screen;
|
||||
Layout layout;
|
||||
|
||||
template<class Archive>
|
||||
void serialize(Archive & archive) {
|
||||
archive(
|
||||
CEREAL_NVP(version),
|
||||
CEREAL_NVP(screen),
|
||||
CEREAL_NVP(layout)
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
12
src/Main.cpp
12
src/Main.cpp
@ -1,6 +1,11 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <cereal/archives/json.hpp>
|
||||
|
||||
#include "Data/SongList.hpp"
|
||||
#include "Data/Preferences.hpp"
|
||||
// #include "Data/Chart.hpp"
|
||||
// #include "Data/Score.hpp"
|
||||
|
||||
@ -10,10 +15,13 @@
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
|
||||
sf::RenderWindow window(sf::VideoMode(800,600), "jujube");
|
||||
window.setFramerateLimit(60);
|
||||
std::cout << ss.str() << std::endl;
|
||||
return 0;
|
||||
|
||||
sf::RenderWindow window;
|
||||
|
||||
Data::SongList song_list;
|
||||
Data::Preferences preferences;
|
||||
MusicSelect::Screen music_select{song_list};
|
||||
|
||||
music_select.select_chart(window);
|
||||
|
@ -31,13 +31,13 @@ MusicSelect::Screen::Screen(const Data::SongList& t_song_list) :
|
||||
}
|
||||
|
||||
void MusicSelect::Screen::select_chart(sf::RenderWindow& window) {
|
||||
window.create(sf::VideoMode(768, 768), "jujube", sf::Style::Titlebar);
|
||||
window.create(sf::VideoMode(768, 1360), "jujube", sf::Style::Titlebar);
|
||||
window.setFramerateLimit(60);
|
||||
ImGui::SFML::Init(window);
|
||||
bool chart_selected = false;
|
||||
sf::Clock imguiClock;
|
||||
ribbon.setPosition(8.f, 8.f);
|
||||
button_highlight.setPosition(8.f, 8.f);
|
||||
ribbon.setPosition(8.f, 602.f);
|
||||
button_highlight.setPosition(8.f, 602.f);
|
||||
while (not chart_selected) {
|
||||
sf::Event event;
|
||||
while (window.pollEvent(event)) {
|
||||
@ -53,7 +53,7 @@ void MusicSelect::Screen::select_chart(sf::RenderWindow& window) {
|
||||
}
|
||||
}
|
||||
ImGui::SFML::Update(window, imguiClock.restart());
|
||||
window.clear(sf::Color::Black);
|
||||
window.clear(sf::Color(252, 201, 0, 255));
|
||||
ribbon.draw_debug();
|
||||
window.draw(ribbon);
|
||||
window.draw(button_highlight);
|
||||
|
@ -68,6 +68,7 @@ namespace MusicSelect {
|
||||
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
||||
const Data::Song& m_song;
|
||||
const Toolkit::AffineTransform<float> m_seconds_to_alpha{0.0f, 0.15f, 0.f, 255.f};
|
||||
std::optional<std::reference_wrapper<std::string>> selected_chart;
|
||||
};
|
||||
|
||||
void set_to_global_bounds(sf::RectangleShape& rect, const sf::Text& text);
|
||||
|
Loading…
Reference in New Issue
Block a user