2019-01-03 23:20:35 +01:00
//
// Created by Symeon on 23/12/2018.
//
# ifndef FEIS_EDITORSTATE_H
# define FEIS_EDITORSTATE_H
# include <optional>
# include <SFML/Audio.hpp>
2019-01-12 17:16:20 +01:00
# include <SFML/Graphics.hpp>
2019-01-03 23:20:35 +01:00
# include "Fumen.h"
2019-01-13 22:29:29 +01:00
# include "Marker.h"
2019-01-14 21:43:56 +01:00
# include "Widgets.h"
2019-01-03 23:20:35 +01:00
class EditorState {
public :
Fumen fumen ;
2019-01-16 22:10:20 +01:00
std : : optional < Chart > selectedChart ; // Ok this was a pretty terrible design choice, be EXTRA careful about this still being in sync with what's actually in the std::map of fumen
2019-01-14 21:43:56 +01:00
Widgets : : Playfield playfield ;
2019-01-17 01:08:38 +01:00
int snap = 1 ;
2019-01-16 22:10:20 +01:00
2019-01-03 23:20:35 +01:00
std : : optional < sf : : Music > music ;
2019-01-17 01:08:38 +01:00
int musicVolume = 10 ; // 0 -> 10
void updateMusicVolume ( ) ;
2019-01-16 22:10:20 +01:00
2019-01-12 17:16:20 +01:00
std : : optional < sf : : Texture > jacket ;
2019-01-17 03:02:37 +01:00
sf : : Time previousPos ;
2019-01-14 12:21:58 +01:00
sf : : Time playbackPosition ;
2019-01-17 01:08:38 +01:00
sf : : Time chartRuntime ; // sf::Time at which the chart preview stops, can be after the end of the audio
void setPlaybackAndMusicPosition ( sf : : Time newPosition ) ;
2019-01-14 12:21:58 +01:00
bool playing ;
2019-01-17 01:08:38 +01:00
2019-01-14 21:43:56 +01:00
float getBeats ( ) { return getBeatsAt ( playbackPosition . asSeconds ( ) ) ; } ;
float getBeatsAt ( float seconds ) { return ( ( seconds + fumen . offset ) / 60.f ) * fumen . BPM ; } ;
float getTicks ( ) { return getTicksAt ( playbackPosition . asSeconds ( ) ) ; } ;
2019-01-17 01:08:38 +01:00
float getTicksAt ( float seconds ) { return getBeatsAt ( seconds ) * getResolution ( ) ; }
float getSecondsAt ( int tick ) { return ( 60.f * tick ) / ( fumen . BPM * getResolution ( ) ) - fumen . offset ; } ;
int getResolution ( ) { return selectedChart ? selectedChart - > getResolution ( ) : 240 ; } ;
int getSnapStep ( ) { return getResolution ( ) / snap ; } ;
2019-01-14 12:21:58 +01:00
2019-01-13 03:53:42 +01:00
void reloadFromFumen ( ) ;
2019-01-12 17:16:20 +01:00
void reloadMusic ( ) ;
2019-01-14 04:20:30 +01:00
void reloadPlaybackPositionAndChartRuntime ( ) ;
2019-01-12 17:16:20 +01:00
void reloadJacket ( ) ;
2019-01-13 22:29:29 +01:00
bool showPlayfield = true ;
2019-01-03 23:20:35 +01:00
bool showProperties ;
2019-01-12 03:13:30 +01:00
bool showStatus ;
2019-01-12 17:16:20 +01:00
bool showPlaybackStatus = true ;
2019-01-13 03:53:42 +01:00
bool showTimeline = true ;
2019-01-16 01:59:02 +01:00
bool showChartList ;
bool showNewChartDialog ;
2019-01-16 19:12:01 +01:00
bool showChartProperties ;
2019-01-12 17:16:20 +01:00
2019-01-13 22:29:29 +01:00
void displayPlayfield ( ) ;
2019-01-12 17:16:20 +01:00
void displayProperties ( ) ;
void displayStatus ( ) ;
void displayPlaybackStatus ( ) ;
2019-01-13 03:53:42 +01:00
void displayTimeline ( ) ;
2019-01-16 01:59:02 +01:00
void displayChartList ( ) ;
2019-01-14 21:43:56 +01:00
2019-01-17 03:02:37 +01:00
void updateVisibleNotes ( ) ;
std : : vector < Note > visibleNotes ;
2019-01-14 21:43:56 +01:00
2019-01-12 03:13:30 +01:00
explicit EditorState ( Fumen & fumen ) ;
2019-01-03 23:20:35 +01:00
} ;
2019-01-13 22:29:29 +01:00
namespace ESHelper {
void save ( EditorState & ed ) ;
void open ( std : : optional < EditorState > & ed ) ;
void openFromFile ( std : : optional < EditorState > & ed , std : : filesystem : : path path ) ;
2019-01-16 01:59:02 +01:00
class NewChartDialog {
public :
std : : optional < Chart > display ( EditorState & editorState ) ;
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 ;
} ;
2019-01-16 19:12:01 +01:00
class ChartPropertiesDialog {
public :
void display ( EditorState & editorState ) ;
bool shouldRefreshValues = true ;
private :
int level ;
std : : string difficulty ;
std : : string comboPreview ;
std : : set < std : : string > difNamesInUse ;
bool showCustomDifName = false ;
} ;
2019-01-13 22:29:29 +01:00
}
2019-01-03 23:20:35 +01:00
# endif //FEIS_EDITORSTATE_H