2023-06-30 17:15:49 +02:00
# pragma once
# include <string>
# include <vector>
# include <mutex>
// Shows a visible message to the user.
// The default implementation in NativeApp.cpp uses our "osm" system (on screen messaging).
enum class OSDType {
MESSAGE_INFO ,
MESSAGE_SUCCESS ,
MESSAGE_WARNING ,
MESSAGE_ERROR ,
MESSAGE_ERROR_DUMP , // displays lots of text (after the first line), small size
MESSAGE_FILE_LINK ,
ACHIEVEMENT_UNLOCKED ,
2023-06-27 23:31:15 +02:00
// Side entries
2023-07-03 14:39:49 +02:00
ACHIEVEMENT_PROGRESS , // Achievement icon + "measured_progress" text, auto-hide after 2s
ACHIEVEMENT_CHALLENGE_INDICATOR , // Achievement icon ONLY, no auto-hide
2023-07-24 14:39:40 +02:00
2023-07-03 14:39:49 +02:00
LEADERBOARD_TRACKER ,
2023-08-01 12:52:09 +02:00
LEADERBOARD_STARTED_FAILED ,
2023-08-01 11:57:28 +02:00
LEADERBOARD_SUBMITTED ,
2023-07-31 23:13:52 +02:00
PROGRESS_BAR ,
VALUE_COUNT ,
} ;
2023-06-30 17:15:49 +02:00
// Data holder for on-screen messages.
class OnScreenDisplay {
public :
// If you specify 0.0f as duration, a duration will be chosen automatically depending on type.
void Show ( OSDType type , const std : : string & text , float duration_s = 0.0f , const char * id = nullptr ) {
Show ( type , text , " " , duration_s , id ) ;
}
void Show ( OSDType type , const std : : string & text , const std : : string & text2 , float duration_s = 0.0f , const char * id = nullptr ) {
Show ( type , text , text2 , " " , duration_s , id ) ;
}
void Show ( OSDType type , const std : : string & text , const std : : string & text2 , const std : : string & icon , float duration_s = 0.0f , const char * id = nullptr ) ;
2023-06-27 23:31:15 +02:00
2023-06-30 17:15:49 +02:00
void ShowOnOff ( const std : : string & message , bool on , float duration_s = 0.0f ) ;
bool IsEmpty ( ) const { return entries_ . empty ( ) ; } // Shortcut to skip rendering.
// Call this every frame, cleans up old entries.
void Update ( ) ;
2023-07-03 14:39:49 +02:00
// Specialized achievement-related types. These go to the side notifications, not the top-middle.
void ShowAchievementUnlocked ( int achievementID ) ;
2023-07-30 10:55:55 +02:00
void ShowAchievementProgress ( int achievementID , bool show ) ; // call with show=false to hide. There can only be one of these. When hiding it's ok to not pass a valid achievementID.
2023-07-03 14:39:49 +02:00
void ShowChallengeIndicator ( int achievementID , bool show ) ; // call with show=false to hide.
void ShowLeaderboardTracker ( int leaderboardTrackerID , const char * trackerText , bool show ) ; // show=true is used both for create and update.
2023-08-01 11:57:28 +02:00
void ShowLeaderboardStartEnd ( const std : : string & title , const std : : string & description , bool started ) ; // started = true for started, false for ended.
void ShowLeaderboardSubmitted ( const std : : string & title , const std : : string & value ) ;
2023-07-03 14:39:49 +02:00
2023-06-30 17:15:49 +02:00
// Progress bar controls
2023-07-03 14:39:49 +02:00
// Set is both create and update. If you set maxValue <= minValue, you'll create an "indeterminate" progress
// bar that doesn't show a specific amount of progress.
2023-07-18 15:13:44 +02:00
void SetProgressBar ( std : : string id , std : : string & & message , float minValue , float maxValue , float progress , float delay_s ) ;
void RemoveProgressBar ( std : : string id , bool success , float delay_s ) ;
2023-06-30 17:15:49 +02:00
2023-07-16 08:55:48 +02:00
// Call every frame to keep the sidebar visible. Otherwise it'll fade out.
void NudgeSidebar ( ) ;
float SidebarAlpha ( ) const ;
2023-07-10 10:39:44 +02:00
2023-07-10 21:04:22 +02:00
// Fades out everything related to achievements. Should be used on game shutdown.
void ClearAchievementStuff ( ) ;
2023-06-30 17:15:49 +02:00
struct Entry {
OSDType type ;
std : : string text ;
std : : string text2 ;
std : : string iconName ;
int numericID ;
2023-07-31 23:13:52 +02:00
std : : string id ;
2023-06-30 17:15:49 +02:00
double startTime ;
double endTime ;
2023-07-31 23:13:52 +02:00
// Progress-bar-only data:
2023-07-18 15:13:44 +02:00
float minValue ;
float maxValue ;
float progress ;
2023-06-30 17:15:49 +02:00
} ;
std : : vector < Entry > Entries ( ) ;
2023-09-04 10:01:07 +02:00
// TODO: Use something more stable than the index.
void DismissEntry ( size_t index , double now ) ;
2023-07-31 23:13:52 +02:00
static float FadeinTime ( ) { return 0.1f ; }
2023-07-03 14:39:49 +02:00
static float FadeoutTime ( ) { return 0.25f ; }
2023-06-30 17:15:49 +02:00
private :
std : : vector < Entry > entries_ ;
std : : mutex mutex_ ;
2023-07-10 10:39:44 +02:00
2023-07-16 08:55:48 +02:00
double sideBarShowTime_ = 0.0 ;
2023-06-30 17:15:49 +02:00
} ;
extern OnScreenDisplay g_OSD ;