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

175 lines
4.6 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 "chart_with_history.hpp"
2021-12-31 00:57:06 +01:00
#include "fumen.hpp"
#include "history.hpp"
#include "history_actions.hpp"
2021-12-31 14:59:39 +01:00
#include "marker.hpp"
2021-12-31 00:57:06 +01:00
#include "notes_clipboard.hpp"
2022-02-28 23:10:22 +01:00
#include "precise_music.hpp"
2021-12-31 14:59:39 +01:00
#include "time_selection.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
* .memon file
*/
class EditorState {
public:
EditorState(Fumen& fumen, std::filesystem::path assets);
std::optional<Chart_with_History> chart;
2019-03-26 00:04:29 +01:00
Fumen fumen;
2019-03-26 00:04:29 +01:00
Playfield playfield;
LinearView linearView;
2019-03-26 00:04:29 +01:00
2021-12-31 14:59:39 +01:00
// the snap but divided by 4 because you can't set a snap to anything lower
// than 4ths
int snap = 1;
2019-01-16 22:10:20 +01:00
2022-02-28 23:10:22 +01:00
std::optional<PreciseMusic> music;
2021-12-31 14:59:39 +01:00
int musicVolume = 10; // 0 -> 10
void setMusicVolume(int newMusicVolume);
2022-02-09 02:53:41 +01:00
void musicVolumeUp();
void musicVolumeDown();
2021-12-31 14:59:39 +01:00
int musicSpeed = 10; // 1 -> 20
void setMusicSpeed(int newMusicSpeed);
2022-02-09 02:53:41 +01:00
void musicSpeedUp();
void musicSpeedDown();
2019-01-16 22:10:20 +01:00
std::optional<sf::Texture> albumCover;
bool playing;
2019-01-17 03:02:37 +01:00
sf::Time previousPos;
sf::Time playbackPosition;
2019-04-09 23:07:22 +02:00
private:
sf::Time previewEnd; // sf::Time (in the audio file "coordinates") at which the chart preview stops, can be
// after the end of the actual audio file
2019-04-09 23:07:22 +02:00
public:
2021-12-31 14:59:39 +01:00
const sf::Time& getPreviewEnd();
2019-04-09 23:07:22 +02:00
public:
void setPlaybackAndMusicPosition(sf::Time newPosition);
2021-12-31 14:59:39 +01:00
float getBeats() { return getBeatsAt(playbackPosition.asSeconds()); };
float getBeatsAt(float seconds) {
return ((seconds + fumen.offset) / 60.f) * fumen.BPM;
};
float getCurrentTick() { return getTicksAt(playbackPosition.asSeconds()); };
float getTicksAt(float seconds) {
return getBeatsAt(seconds) * getResolution();
}
float getSecondsAt(int tick) {
return (60.f * tick) / (fumen.BPM * getResolution()) - fumen.offset;
};
int getResolution() { return chart ? chart->ref.getResolution() : 240; };
int getSnapStep() { return getResolution() / snap; };
2019-02-09 16:05:46 +01:00
2021-12-31 14:59:39 +01:00
float ticksToSeconds(int ticks) {
return (60.f * ticks) / (fumen.BPM * getResolution());
};
2021-12-31 14:59:39 +01:00
float getChartRuntime() {
return getPreviewEnd().asSeconds() + fumen.offset;
};
void reloadFromFumen(std::filesystem::path assets);
void reloadMusic();
void reloadAlbumCover();
2019-04-09 23:07:22 +02:00
void reloadPreviewEnd();
2019-01-13 22:29:29 +01:00
bool showPlayfield = true;
bool showProperties;
2019-01-12 03:13:30 +01:00
bool showStatus;
bool showPlaybackStatus = true;
bool showTimeline = true;
bool showChartList;
bool showNewChartDialog;
bool showChartProperties;
bool showHistory;
bool showSoundSettings;
2019-03-26 00:04:29 +01:00
bool showLinearView;
void displayPlayfield(Marker& marker, MarkerEndingState markerEndingState);
void displayProperties();
void displayStatus();
void displayPlaybackStatus();
void displayTimeline();
void displayChartList(std::filesystem::path assets);
2019-03-26 00:04:29 +01:00
void displayLinearView();
2019-01-14 21:43:56 +01:00
saveChangesResponses alertSaveChanges();
bool saveChangesOrCancel();
void updateVisibleNotes();
std::set<Note> visibleNotes;
void toggleNoteAtCurrentTime(int pos);
};
2019-01-13 22:29:29 +01:00
namespace ESHelper {
void save(EditorState& ed);
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<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
}