mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
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
This commit is contained in:
@ -17,21 +17,30 @@
|
||||
|
||||
namespace OSD
|
||||
{
|
||||
struct Message
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
||||
static std::multimap<CallbackType, Callback> s_callbacks;
|
||||
static std::list<Message> s_msgList;
|
||||
static std::multimap<MessageType, Message> s_messages;
|
||||
static std::mutex s_messages_mutex;
|
||||
|
||||
void AddMessage(const std::string& str, u32 ms, u32 rgba)
|
||||
void AddTypedMessage(MessageType type, const std::string& message, u32 ms, u32 rgba)
|
||||
{
|
||||
s_msgList.emplace_back(str, Common::Timer::GetTimeMs() + ms, 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));
|
||||
}
|
||||
|
||||
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 DrawMessage(const Message& msg, int top, int left, int time_left)
|
||||
{
|
||||
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);
|
||||
std::lock_guard<std::mutex> lock(s_messages_mutex);
|
||||
|
||||
g_renderer->RenderText(it->m_str, left, top, color);
|
||||
u32 now = Common::Timer::GetTimeMs();
|
||||
int left = 20, top = 35;
|
||||
|
||||
top += 15;
|
||||
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_msgList.erase(it);
|
||||
else
|
||||
++it;
|
||||
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
|
||||
|
Reference in New Issue
Block a user