From 6a0fc4c438dcc827b6ed4e0a22a2e54676682ea0 Mon Sep 17 00:00:00 2001 From: Aestek Date: Tue, 2 Feb 2016 16:35:27 +0100 Subject: Improve netplay setup dialog UX * Focus "Hash Code" / "IP address" text box by default in "Connect" * Focus game list in "Host" tab * RETURN keypress now host/join depending on selected tab * Remember last hosted game * Remove PanicAlertT: * Simply log message to netplay window * Remove them when they are useless * Show some netplay message in OSD * Chat messages * Pad buffer changes * Desync alerts * Stop the game consistently when another player disconnects / crashes * Prettify chat textbox * Log netplay ping to OSD Join scenario: * Copy netplay code * Open netplay * Paste code * Press enter Host scenario: * Open netplay * Go to host tab * Press enter --- Source/Core/VideoCommon/OnScreenDisplay.cpp | 67 +++++++++++++++++------------ 1 file changed, 40 insertions(+), 27 deletions(-) (limited to 'Source/Core/VideoCommon/OnScreenDisplay.cpp') diff --git a/Source/Core/VideoCommon/OnScreenDisplay.cpp b/Source/Core/VideoCommon/OnScreenDisplay.cpp index 3cc2e823d8..62997cd150 100644 --- a/Source/Core/VideoCommon/OnScreenDisplay.cpp +++ b/Source/Core/VideoCommon/OnScreenDisplay.cpp @@ -17,21 +17,30 @@ namespace OSD { -struct Message +static std::multimap s_callbacks; +static std::multimap s_messages; +static std::mutex s_messages_mutex; + +void AddTypedMessage(MessageType type, const std::string& message, u32 ms, u32 rgba) { - Message() {} - Message(const std::string& s, u32 ts, u32 rgba) : m_str(s), m_timestamp(ts), m_rgba(rgba) {} - std::string m_str; - u32 m_timestamp; - u32 m_rgba; -}; + std::lock_guard lock(s_messages_mutex); + s_messages.erase(type); + s_messages.emplace(type, Message(message, Common::Timer::GetTimeMs() + ms, rgba)); +} -static std::multimap s_callbacks; -static std::list s_msgList; +void AddMessage(const std::string& message, u32 ms, u32 rgba) +{ + std::lock_guard lock(s_messages_mutex); + s_messages.emplace(MessageType::Typeless, + Message(message, Common::Timer::GetTimeMs() + ms, rgba)); +} -void AddMessage(const std::string& str, u32 ms, u32 rgba) +void DrawMessage(const Message& msg, int top, int left, int time_left) { - s_msgList.emplace_back(str, Common::Timer::GetTimeMs() + ms, rgba); + float alpha = std::min(1.0f, std::max(0.0f, time_left / 1024.0f)); + u32 color = (msg.m_rgba & 0xFFFFFF) | ((u32)((msg.m_rgba >> 24) * alpha) << 24); + + g_renderer->RenderText(msg.m_str, left, top, color); } void DrawMessages() @@ -39,28 +48,32 @@ void DrawMessages() if (!SConfig::GetInstance().bOnScreenDisplayMessages) return; - int left = 25, top = 15; - auto it = s_msgList.begin(); - while (it != s_msgList.end()) { - int time_left = (int)(it->m_timestamp - Common::Timer::GetTimeMs()); - float alpha = std::max(1.0f, std::min(0.0f, time_left / 1024.0f)); - u32 color = (it->m_rgba & 0xFFFFFF) | ((u32)((it->m_rgba >> 24) * alpha) << 24); - - g_renderer->RenderText(it->m_str, left, top, color); - - top += 15; - - if (time_left <= 0) - it = s_msgList.erase(it); - else - ++it; + std::lock_guard lock(s_messages_mutex); + + u32 now = Common::Timer::GetTimeMs(); + int left = 20, top = 35; + + auto it = s_messages.begin(); + while (it != s_messages.end()) + { + const Message& msg = it->second; + int time_left = (int)(msg.m_timestamp - now); + DrawMessage(msg, top, left, time_left); + + if (time_left <= 0) + it = s_messages.erase(it); + else + ++it; + top += 15; + } } } void ClearMessages() { - s_msgList.clear(); + std::lock_guard lock(s_messages_mutex); + s_messages.clear(); } // On-Screen Display Callbacks -- cgit v1.2.3