summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/OnScreenDisplay.cpp
diff options
context:
space:
mode:
authorAestek <thib.gilles@gmail.com>2016-02-02 16:35:27 +0100
committerAestek <thib.gilles@gmail.com>2016-07-23 20:58:51 +0200
commit6a0fc4c438dcc827b6ed4e0a22a2e54676682ea0 (patch)
treeb44ade2f80ade233a2e82965af0717b18257e4f6 /Source/Core/VideoCommon/OnScreenDisplay.cpp
parentaa34e5e20e5f66cfdbace167b98c30c1fedcf522 (diff)
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
Diffstat (limited to 'Source/Core/VideoCommon/OnScreenDisplay.cpp')
-rw-r--r--Source/Core/VideoCommon/OnScreenDisplay.cpp67
1 files changed, 40 insertions, 27 deletions
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<CallbackType, Callback> s_callbacks;
+static std::multimap<MessageType, Message> 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<std::mutex> lock(s_messages_mutex);
+ s_messages.erase(type);
+ s_messages.emplace(type, Message(message, Common::Timer::GetTimeMs() + ms, rgba));
+}
-static std::multimap<CallbackType, Callback> s_callbacks;
-static std::list<Message> s_msgList;
+void AddMessage(const std::string& message, u32 ms, u32 rgba)
+{
+ std::lock_guard<std::mutex> 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<std::mutex> 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<std::mutex> lock(s_messages_mutex);
+ s_messages.clear();
}
// On-Screen Display Callbacks