2016-02-19 18:05:04 +00:00
# include " stdafx.h "
2015-07-02 03:17:14 +00:00
2015-08-29 01:01:18 +00:00
# include <algorithm>
2015-07-02 03:17:14 +00:00
# include "MessageManager.h"
2016-02-19 18:05:04 +00:00
# include "EmulationSettings.h"
std : : unordered_map < string , string > MessageManager : : _enResources = {
{ " Cheats " , u8 " Cheats " } ,
{ " Debug " , u8 " Debug " } ,
{ " EmulationSpeed " , u8 " Emulation Speed " } ,
{ " Error " , u8 " Error " } ,
{ " GameInfo " , u8 " Game Info " } ,
{ " GameLoaded " , u8 " Game loaded " } ,
{ " Movies " , u8 " Movies " } ,
{ " NetPlay " , u8 " Net Play " } ,
{ " SaveStates " , u8 " Save States " } ,
{ " ScreenshotSaved " , u8 " Screenshot Saved " } ,
{ " Test " , u8 " Test " } ,
2016-05-23 00:02:02 +00:00
2016-02-19 18:05:04 +00:00
{ " CheatApplied " , u8 " 1 cheat applied. " } ,
{ " CheatsApplied " , u8 " %1 cheats applied. " } ,
{ " ConnectedToServer " , u8 " Connected to server. " } ,
{ " ConnectedAsPlayer " , u8 " Connected as player %1 " } ,
{ " ConnectedAsSpectator " , u8 " Connected as spectator. " } ,
{ " ConnectionLost " , u8 " Connection to server lost. " } ,
{ " CouldNotConnect " , u8 " Could not connect to the server. " } ,
{ " CouldNotIniitalizeAudioSystem " , u8 " Could not initialize audio system " } ,
{ " CouldNotFindRom " , u8 " Could not find matching game ROM. " } ,
{ " CouldNotLoadFile " , u8 " Could not load file: %1 " } ,
{ " EmulationMaximumSpeed " , u8 " Maximum speed " } ,
{ " EmulationSpeedPercent " , u8 " %1% " } ,
{ " GameCrash " , u8 " Game has crashed (%1) " } ,
{ " Mapper " , u8 " Mapper: %1 " } ,
{ " MovieEnded " , u8 " Movie ended. " } ,
{ " MovieInvalid " , u8 " Invalid movie file. " } ,
{ " MovieMissingRom " , u8 " Missing ROM required (%1) to play movie. " } ,
{ " MovieNewerVersion " , u8 " Cannot load movies created by a more recent version of Mesen. Please download the latest version. " } ,
{ " MovieIncompatibleVersion " , u8 " This movie is incompatible with this version of Mesen. " } ,
{ " MoviePlaying " , u8 " Playing movie: %1 " } ,
{ " MovieRecordingTo " , u8 " Recording to: %1 " } ,
{ " MovieSaved " , u8 " Movie saved to file: %1 " } ,
{ " NetplayVersionMismatch " , u8 " %1 is not running the same version of Mesen and has been disconnected. " } ,
{ " PrgSizeWarning " , u8 " PRG size is smaller than 32kb " } ,
{ " SaveStateEmpty " , u8 " Slot is empty. " } ,
{ " SaveStateIncompatibleVersion " , u8 " State #%1 is incompatible with this version of Mesen. " } ,
{ " SaveStateInvalidFile " , u8 " Invalid save state file. " } ,
{ " SaveStateLoaded " , u8 " State #%1 loaded. " } ,
{ " SaveStateNewerVersion " , u8 " Cannot load save states created by a more recent version of Mesen. Please download the latest version. " } ,
{ " SaveStateSaved " , u8 " State #%1 saved. " } ,
{ " ServerStarted " , u8 " Server started (Port: %1) " } ,
{ " ServerStopped " , u8 " Server stopped " } ,
{ " TestFileSavedTo " , u8 " Test file saved to: %1 " } ,
{ " UnsupportedMapper " , u8 " Unsupported mapper, cannot load game. " } ,
2016-05-23 00:02:02 +00:00
{ " GoogleDrive " , u8 " Google Drive " } ,
{ " SynchronizationStarted " , u8 " Synchronization started. " } ,
{ " SynchronizationFailed " , u8 " Synchronization failed. " } ,
{ " SynchronizationCompleted " , u8 " Synchronization completed. " } ,
2016-02-19 18:05:04 +00:00
} ;
std : : unordered_map < string , string > MessageManager : : _frResources = {
{ " Cheats " , u8 " Codes " } ,
{ " Debug " , u8 " Debug " } ,
{ " EmulationSpeed " , u8 " Vitesse " } ,
{ " Error " , u8 " Erreur " } ,
{ " GameInfo " , u8 " Info sur le ROM " } ,
{ " GameLoaded " , u8 " Jeu chargé " } ,
{ " Movies " , u8 " Films " } ,
{ " NetPlay " , u8 " Jeu en ligne " } ,
{ " SaveStates " , u8 " Sauvegardes " } ,
{ " ScreenshotSaved " , u8 " Capture d'écran " } ,
{ " Test " , u8 " Test " } ,
{ " CheatApplied " , u8 " %1 code activé. " } ,
{ " CheatsApplied " , u8 " %1 codes activés. " } ,
{ " ConnectedToServer " , u8 " Connecté avec succès au serveur. " } ,
{ " ConnectedAsPlayer " , u8 " Connecté en tant que joueur #%1 " } ,
{ " ConnectedAsSpectator " , u8 " Connecté en tant que spectateur. " } ,
{ " ConnectionLost " , u8 " La connexion avec le serveur a été perdue. " } ,
{ " CouldNotConnect " , u8 " Impossible de se connecter au serveur. " } ,
{ " CouldNotIniitalizeAudioSystem " , u8 " L'initialisation du système de son à échoué " } ,
{ " CouldNotFindRom " , u8 " Impossible de trouvé un rom correspondant. " } ,
{ " CouldNotLoadFile " , u8 " Impossible de charger le fichier : %1 " } ,
{ " EmulationMaximumSpeed " , u8 " Vitesse maximale " } ,
{ " EmulationSpeedPercent " , u8 " %1% " } ,
{ " GameCrash " , u8 " Le jeu a planté (%1) " } ,
{ " Mapper " , u8 " Mapper : %1 " } ,
{ " MovieEnded " , u8 " Fin du film. " } ,
{ " MovieInvalid " , u8 " Fichier de film invalide. " } ,
{ " MovieMissingRom " , u8 " Le rom (%1) correspondant au film sélectionné est introuvable. " } ,
{ " MovieNewerVersion " , u8 " Impossible de charger un film qui a été créé avec une version plus récente de Mesen. Veuillez mettre à jour Mesen pour jouer ce film. " } ,
{ " MovieIncompatibleVersion " , u8 " Ce film est incompatible avec votre version de Mesen. " } ,
{ " MoviePlaying " , u8 " Film démarré: %1 " } ,
{ " MovieRecordingTo " , u8 " En cours d'enregistrement : %1 " } ,
{ " MovieSaved " , u8 " Film sauvegardé : %1 " } ,
{ " NetplayVersionMismatch " , u8 " %1 ne roule pas la même version de Mesen que vous et a été déconnecté automatiquement. " } ,
{ " PrgSizeWarning " , u8 " PRG size is smaller than 32kb " } ,
{ " SaveStateEmpty " , u8 " Cette sauvegarde est vide. " } ,
{ " SaveStateIncompatibleVersion " , u8 " La sauvegarde #%1 est incompatible avec cette version de Mesen. " } ,
{ " SaveStateInvalidFile " , u8 " Fichier de sauvegarde invalide ou corrompu. " } ,
{ " SaveStateLoaded " , u8 " Sauvegarde #%1 chargée. " } ,
{ " SaveStateNewerVersion " , u8 " Impossible de charger une sauvegarde qui a été créée avec une version plus récente de Mesen. Veuillez mettre à jour Mesen. " } ,
{ " SaveStateSaved " , u8 " Sauvegarde #%1 sauvegardée. " } ,
{ " ServerStarted " , u8 " Le serveur a été démarré (Port: %1) " } ,
{ " ServerStopped " , u8 " Le serveur a été arrêté " } ,
{ " TestFileSavedTo " , u8 " Test sauvegardé: %1 " } ,
{ " UnsupportedMapper " , u8 " Ce mapper n'est pas encore supporté - le jeu ne peut pas être démarré. " } ,
2016-05-23 00:02:02 +00:00
{ " GoogleDrive " , u8 " Google Drive " } ,
{ " SynchronizationStarted " , u8 " Synchronisation en cours. " } ,
{ " SynchronizationFailed " , u8 " La synchronisation a échoué. " } ,
{ " SynchronizationCompleted " , u8 " Synchronisation terminée. " } ,
2016-02-19 18:05:04 +00:00
} ;
std : : unordered_map < string , string > MessageManager : : _jaResources = {
{ " Cheats " , u8 " チート " } ,
{ " Debug " , u8 " Debug " } ,
{ " EmulationSpeed " , u8 " 速度 " } ,
{ " Error " , u8 " エラー " } ,
{ " GameInfo " , u8 " ゲーム情報 " } ,
{ " GameLoaded " , u8 " ゲーム開始 " } ,
{ " Movies " , u8 " 動画 " } ,
{ " NetPlay " , u8 " ネットプレー " } ,
{ " SaveStates " , u8 " クイックセーブ " } ,
{ " ScreenshotSaved " , u8 " スクリーンショット " } ,
{ " Test " , u8 " テスト " } ,
{ " CheatApplied " , u8 " チートコード%1個を有効にしました。 " } ,
{ " CheatsApplied " , u8 " チートコード%1個を有効にしました。 " } ,
{ " ConnectedToServer " , u8 " サーバに接続しました。 " } ,
{ " ConnectedAsPlayer " , u8 " プレーヤー %1として接続しました。 " } ,
{ " ConnectedAsSpectator " , u8 " 観客として接続しました。 " } ,
2016-02-21 20:32:21 +00:00
{ " ConnectionLost " , u8 " サーバから切断されました。 " } ,
{ " CouldNotConnect " , u8 " サーバに接続出来ませんでした。 " } ,
2016-02-19 18:05:04 +00:00
{ " CouldNotIniitalizeAudioSystem " , u8 " オーディオデバイスを初期化出来ませんでした。 " } ,
2016-02-21 20:32:21 +00:00
{ " CouldNotFindRom " , u8 " 該当するゲームファイルは見つかりませんでした。 " } ,
2016-02-19 18:05:04 +00:00
{ " CouldNotLoadFile " , u8 " ファイルをロードできませんでした: %1 " } ,
{ " EmulationMaximumSpeed " , u8 " 最高速度 " } ,
{ " EmulationSpeedPercent " , u8 " %1% " } ,
2016-02-21 20:32:21 +00:00
{ " GameCrash " , u8 " ゲームは停止しました (%1) " } ,
2016-02-19 18:05:04 +00:00
{ " Mapper " , u8 " Mapper: %1 " } ,
2016-02-21 20:32:21 +00:00
{ " MovieEnded " , u8 " 動画の再生が終了しました。 " } ,
{ " MovieInvalid " , u8 " 動画データの読み込みに失敗しました。 " } ,
{ " MovieMissingRom " , u8 " 動画に必要なゲームファイルを見つかりませんでした。(%1) " } ,
{ " MovieNewerVersion " , u8 " この動画は使用中のMesenより新しいバージョンで作られたため、ロードできません。 Mesenのサイトで最新のバージョンをダウンロードしてください。 " } ,
2016-02-19 18:05:04 +00:00
{ " MovieIncompatibleVersion " , u8 " この動画は古いMesenのバージョンで作られたもので、ロードできませんでした。 " } ,
{ " MoviePlaying " , u8 " 動画再生: %1 " } ,
{ " MovieRecordingTo " , u8 " %1に録画しています。 " } ,
2016-02-21 20:32:21 +00:00
{ " MovieSaved " , u8 " 録画を終了しました: %1 " } ,
2016-02-19 18:05:04 +00:00
{ " NetplayVersionMismatch " , u8 " %1さんはMesenの別のバージョンを使っているため、接続はできませんでした。 " } ,
{ " PrgSizeWarning " , u8 " PRG size is smaller than 32kb " } ,
{ " SaveStateEmpty " , u8 " セーブデータがありませんでした。 " } ,
{ " SaveStateIncompatibleVersion " , u8 " クイックセーブ%1は古いMesenのバージョンで作られたもので、ロードできませんでした。 " } ,
2016-02-21 20:32:21 +00:00
{ " SaveStateInvalidFile " , u8 " クイックセーブデータを読めませんでした。 " } ,
2016-02-19 18:05:04 +00:00
{ " SaveStateLoaded " , u8 " クイックセーブ%1をロードしました。 " } ,
2016-02-21 20:32:21 +00:00
{ " SaveStateNewerVersion " , u8 " クイックセーブデータは使用中のMesenより新しいバージョンで作られたため、ロードできません。 Mesenのサイトで最新のバージョンをダウンロードしてください。 " } ,
2016-02-19 18:05:04 +00:00
{ " SaveStateSaved " , u8 " クイックセーブ%1をセーブしました。 " } ,
{ " ServerStarted " , u8 " サーバは起動しました (ポート: %1) " } ,
2016-02-21 20:32:21 +00:00
{ " ServerStopped " , u8 " サーバは停止しました。 " } ,
2016-02-19 18:05:04 +00:00
{ " TestFileSavedTo " , u8 " Test file saved to: %1 " } ,
{ " UnsupportedMapper " , u8 " このMapperを使うゲームはロードできません。 " } ,
2016-05-23 00:02:02 +00:00
{ " GoogleDrive " , u8 " Google Drive " } ,
2016-05-23 13:26:05 +00:00
{ " SynchronizationStarted " , u8 " 同期中。 " } ,
2016-05-23 00:02:02 +00:00
{ " SynchronizationFailed " , u8 " 同期は失敗しました。 " } ,
{ " SynchronizationCompleted " , u8 " 同期完了。 " } ,
2016-02-19 18:05:04 +00:00
} ;
2015-07-02 03:17:14 +00:00
IMessageManager * MessageManager : : _messageManager = nullptr ;
2015-08-09 02:36:39 +00:00
vector < INotificationListener * > MessageManager : : _notificationListeners ;
2015-07-02 03:17:14 +00:00
void MessageManager : : RegisterMessageManager ( IMessageManager * messageManager )
{
MessageManager : : _messageManager = messageManager ;
}
2016-02-19 18:05:04 +00:00
string MessageManager : : Localize ( string key )
{
std : : unordered_map < string , string > * resources = nullptr ;
switch ( EmulationSettings : : GetDisplayLanguage ( ) ) {
case Language : : English : resources = & _enResources ; break ;
case Language : : French : resources = & _frResources ; break ;
case Language : : Japanese : resources = & _jaResources ; break ;
}
if ( resources ) {
if ( resources - > find ( key ) ! = resources - > end ( ) ) {
return ( * resources ) [ key ] ;
}
}
return " " ;
}
void MessageManager : : DisplayMessage ( string title , string message , string param1 )
2015-07-02 03:17:14 +00:00
{
if ( MessageManager : : _messageManager ) {
2016-02-19 18:05:04 +00:00
std : : unordered_map < string , string > * resources = nullptr ;
switch ( EmulationSettings : : GetDisplayLanguage ( ) ) {
case Language : : English : resources = & _enResources ; break ;
case Language : : French : resources = & _frResources ; break ;
case Language : : Japanese : resources = & _jaResources ; break ;
}
if ( resources ) {
if ( resources - > find ( title ) ! = resources - > end ( ) ) {
title = ( * resources ) [ title ] ;
}
if ( resources - > find ( message ) ! = resources - > end ( ) ) {
message = ( * resources ) [ message ] ;
size_t startPos = message . find ( u8 " %1 " ) ;
if ( startPos ! = std : : string : : npos ) {
message . replace ( startPos , 2 , param1 ) ;
}
}
}
2015-07-02 03:17:14 +00:00
MessageManager : : _messageManager - > DisplayMessage ( title , message ) ;
}
}
2015-07-11 12:27:22 +00:00
void MessageManager : : DisplayToast ( string title , string message , uint8_t * iconData , uint32_t iconSize )
2015-07-02 03:17:14 +00:00
{
if ( MessageManager : : _messageManager ) {
2016-02-06 23:33:24 +00:00
MessageManager : : _messageManager - > DisplayToast ( shared_ptr < ToastInfo > ( new ToastInfo ( title , message , 4000 , iconData , iconSize ) ) ) ;
2015-07-02 03:17:14 +00:00
}
}
void MessageManager : : RegisterNotificationListener ( INotificationListener * notificationListener )
{
MessageManager : : _notificationListeners . push_back ( notificationListener ) ;
}
void MessageManager : : UnregisterNotificationListener ( INotificationListener * notificationListener )
{
2015-08-09 02:36:39 +00:00
MessageManager : : _notificationListeners . erase ( std : : remove ( MessageManager : : _notificationListeners . begin ( ) , MessageManager : : _notificationListeners . end ( ) , notificationListener ) , MessageManager : : _notificationListeners . end ( ) ) ;
2015-07-02 03:17:14 +00:00
}
2015-12-26 22:11:00 +00:00
void MessageManager : : SendNotification ( ConsoleNotificationType type , void * parameter )
2015-07-02 03:17:14 +00:00
{
//Iterate on a copy to prevent issues if a notification causes a listener to unregister itself
2015-08-09 02:36:39 +00:00
vector < INotificationListener * > listeners = MessageManager : : _notificationListeners ;
vector < INotificationListener * > processedListeners ;
for ( size_t i = 0 , len = listeners . size ( ) ; i < len ; i + + ) {
INotificationListener * notificationListener = listeners [ i ] ;
if ( std : : find ( processedListeners . begin ( ) , processedListeners . end ( ) , notificationListener ) = = processedListeners . end ( ) ) {
//Only send notification if it hasn't been processed already
2015-12-26 22:11:00 +00:00
notificationListener - > ProcessNotification ( type , parameter ) ;
2015-08-09 02:36:39 +00:00
}
processedListeners . push_back ( notificationListener ) ;
if ( len ! = MessageManager : : _notificationListeners . size ( ) ) {
//Vector changed, start from the beginning again (can occur when sending a notification caused listeners to unregister themselves)
i = 0 ;
len = MessageManager : : _notificationListeners . size ( ) ;
listeners = MessageManager : : _notificationListeners ;
}
2015-07-02 03:17:14 +00:00
}
}