F.E.I.S/src/editor_state.hpp

179 lines
4.3 KiB
C++
Raw Normal View History

#pragma once
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
2021-12-31 14:59:39 +01:00
#include <optional>
#include "better_song.hpp"
#include "chart_state.hpp"
2022-03-26 00:23:13 +01:00
#include "generic_interval.hpp"
2021-12-31 00:57:06 +01:00
#include "history.hpp"
#include "history_actions.hpp"
2021-12-31 14:59:39 +01:00
#include "marker.hpp"
2022-03-23 02:20:07 +01:00
#include "metadata_in_gui.hpp"
#include "music_state.hpp"
2021-12-31 00:57:06 +01:00
#include "notes_clipboard.hpp"
2022-03-23 02:20:07 +01:00
#include "notifications_queue.hpp"
2022-02-28 23:10:22 +01:00
#include "precise_music.hpp"
#include "src/better_note.hpp"
2021-12-31 00:57:06 +01:00
#include "widgets/linear_view.hpp"
#include "widgets/playfield.hpp"
class ActionWithMessage;
class OpenChart;
enum saveChangesResponses {
saveChangesYes,
saveChangesNo,
saveChangesCancel,
saveChangesDidNotDisplayDialog
};
/*
2021-12-31 14:59:39 +01:00
* The god class, holds everything there is to know about the currently open
2022-03-17 02:50:30 +01:00
* file
*/
class EditorState {
public:
EditorState(
const better::Song& song,
2022-03-17 02:50:30 +01:00
const std::filesystem::path& assets,
const std::filesystem::path& save_path
);
2022-03-17 02:50:30 +01:00
std::optional<std::filesystem::path> song_path;
std::optional<ChartState> chart_state;
2019-03-26 00:04:29 +01:00
std::optional<MusicState> music_state;
2019-03-26 00:04:29 +01:00
2022-03-23 02:20:07 +01:00
std::optional<sf::Music> preview_audio;
Playfield playfield;
LinearView linear_view;
2019-03-26 00:04:29 +01:00
2022-03-23 02:20:07 +01:00
unsigned int snap = 1;
2019-01-16 22:10:20 +01:00
2022-03-17 02:50:30 +01:00
std::optional<sf::Texture> jacket;
bool playing;
sf::Time playback_position;
2022-03-23 02:20:07 +01:00
sf::Time previous_playback_position;
2019-04-09 23:07:22 +02:00
2022-03-26 00:23:13 +01:00
const Interval<sf::Time>& get_editable_range();
2022-03-17 02:50:30 +01:00
void set_playback_position(sf::Time new_position);
2019-02-09 16:05:46 +01:00
2022-03-23 02:20:07 +01:00
Fraction current_exact_beats() const;
Fraction current_snaped_beats() const;
Fraction beats_at(sf::Time time) const;
sf::Time time_at(Fraction beat) const;
Fraction get_snap_step() const;
2019-01-13 22:29:29 +01:00
bool showPlayfield = true;
2022-03-23 02:20:07 +01:00
void display_playfield(Marker& marker, MarkerEndingState markerEndingState);
bool showProperties;
2022-03-23 02:20:07 +01:00
void display_properties();
2019-01-12 03:13:30 +01:00
bool showStatus;
2022-03-23 02:20:07 +01:00
void display_status();
bool showPlaybackStatus = true;
2022-03-23 02:20:07 +01:00
void display_playback_status();
bool showTimeline = true;
2022-03-23 02:20:07 +01:00
void display_timeline();
bool showChartList;
void display_chart_list();
2022-03-23 02:20:07 +01:00
bool showLinearView;
void display_linear_view();
bool showNewChartDialog;
bool showChartProperties;
bool showHistory;
bool showSoundSettings;
2019-01-14 21:43:56 +01:00
saveChangesResponses alert_save_changes();
2022-03-26 00:23:13 +01:00
bool save_changes_or_cancel();
void toggle_note_at_current_time(const better::Position& pos);
2022-03-23 02:20:07 +01:00
void move_backwards_in_time();
void move_forwards_in_time();
void undo(NotificationsQueue& nq);
void redo(NotificationsQueue& nq);
void save(const std::filesystem::path& file);
private:
2022-03-23 02:20:07 +01:00
better::Song song;
2022-03-17 02:50:30 +01:00
/*
sf::Time bounds (in the audio file "coordinates") which are accessible
(and maybe editable) from the editor, can extend before and after
2022-03-23 02:20:07 +01:00
the audio file
2022-03-17 02:50:30 +01:00
*/
2022-03-26 00:23:13 +01:00
Interval<sf::Time> editable_range;
2022-03-17 02:50:30 +01:00
void reload_editable_range();
2022-03-23 02:20:07 +01:00
void reload_jacket();
void reload_music();
2022-03-23 02:20:07 +01:00
void reload_preview_audio();
2022-03-17 02:50:30 +01:00
better::Timing& applicable_timing;
void reload_applicable_timing();
void open_chart(better::Chart& chart, const std::string& name);
2022-03-17 02:50:30 +01:00
std::filesystem::path assets;
};
2019-01-13 22:29:29 +01:00
namespace ESHelper {
void open(std::optional<EditorState>& ed, std::filesystem::path assets, std::filesystem::path settings);
void openFromFile(
std::optional<EditorState>& ed,
std::filesystem::path file,
std::filesystem::path assets,
std::filesystem::path settings
);
bool saveOrCancel(std::optional<EditorState>& ed);
class NewChartDialog {
public:
std::optional<better::Chart> display(EditorState& editorState);
2021-12-31 14:59:39 +01:00
void resetValues() {
level = 1;
resolution = 240;
difficulty = "";
comboPreview = "";
showCustomDifName = false;
};
private:
int level = 1;
int resolution = 240;
std::string difficulty;
std::string comboPreview;
bool showCustomDifName = false;
};
class ChartPropertiesDialog {
public:
void display(EditorState& editorState, std::filesystem::path assets);
bool shouldRefreshValues = true;
private:
int level;
std::string difficulty_name;
std::string comboPreview;
std::set<std::string> difNamesInUse;
bool showCustomDifName = false;
};
2019-01-13 22:29:29 +01:00
}