Merge pull request #7929 from spycrab/np_chat_toggle

NetPlayChatUI: Add activate chat hotkey
This commit is contained in:
spycrab 2019-03-26 22:35:26 +01:00 committed by GitHub
commit e222b91953
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 33 additions and 2 deletions

View File

@ -20,7 +20,7 @@
#include "InputCommon/GCPadStatus.h" #include "InputCommon/GCPadStatus.h"
// clang-format off // clang-format off
constexpr std::array<const char*, 131> s_hotkey_labels{{ constexpr std::array<const char*, 132> s_hotkey_labels{{
_trans("Open"), _trans("Open"),
_trans("Change Disc"), _trans("Change Disc"),
_trans("Eject Disc"), _trans("Eject Disc"),
@ -31,6 +31,7 @@ constexpr std::array<const char*, 131> s_hotkey_labels{{
_trans("Toggle Fullscreen"), _trans("Toggle Fullscreen"),
_trans("Take Screenshot"), _trans("Take Screenshot"),
_trans("Exit"), _trans("Exit"),
_trans("Activate NetPlay Chat"),
_trans("Volume Down"), _trans("Volume Down"),
_trans("Volume Up"), _trans("Volume Up"),
@ -274,7 +275,7 @@ struct HotkeyGroupInfo
}; };
constexpr std::array<HotkeyGroupInfo, NUM_HOTKEY_GROUPS> s_groups_info = { constexpr std::array<HotkeyGroupInfo, NUM_HOTKEY_GROUPS> s_groups_info = {
{{_trans("General"), HK_OPEN, HK_EXIT}, {{_trans("General"), HK_OPEN, HK_ACTIVATE_CHAT},
{_trans("Volume"), HK_VOLUME_DOWN, HK_VOLUME_TOGGLE_MUTE}, {_trans("Volume"), HK_VOLUME_DOWN, HK_VOLUME_TOGGLE_MUTE},
{_trans("Emulation Speed"), HK_DECREASE_EMULATION_SPEED, HK_TOGGLE_THROTTLE}, {_trans("Emulation Speed"), HK_DECREASE_EMULATION_SPEED, HK_TOGGLE_THROTTLE},
{_trans("Frame Advance"), HK_FRAME_ADVANCE, HK_FRAME_ADVANCE_RESET_SPEED}, {_trans("Frame Advance"), HK_FRAME_ADVANCE, HK_FRAME_ADVANCE_RESET_SPEED},

View File

@ -29,6 +29,7 @@ enum Hotkey
HK_FULLSCREEN, HK_FULLSCREEN,
HK_SCREENSHOT, HK_SCREENSHOT,
HK_EXIT, HK_EXIT,
HK_ACTIVATE_CHAT,
HK_VOLUME_DOWN, HK_VOLUME_DOWN,
HK_VOLUME_UP, HK_VOLUME_UP,

View File

@ -196,6 +196,10 @@ void HotkeyScheduler::Run()
auto& settings = Settings::Instance(); auto& settings = Settings::Instance();
// Toggle Chat
if (IsHotkey(HK_ACTIVATE_CHAT))
emit ActivateChat();
// Recording // Recording
if (IsHotkey(HK_START_RECORDING)) if (IsHotkey(HK_START_RECORDING))
emit StartRecording(); emit StartRecording();

View File

@ -26,6 +26,7 @@ signals:
void ChangeDisc(); void ChangeDisc();
void ExitHotkey(); void ExitHotkey();
void ActivateChat();
void FullScreenHotkey(); void FullScreenHotkey();
void StopHotkey(); void StopHotkey();
void ResetHotkey(); void ResetHotkey();

View File

@ -106,6 +106,7 @@
#include "UICommon/UICommon.h" #include "UICommon/UICommon.h"
#include "VideoCommon/NetPlayChatUI.h"
#include "VideoCommon/VideoConfig.h" #include "VideoCommon/VideoConfig.h"
#if defined(HAVE_XRANDR) && HAVE_XRANDR #if defined(HAVE_XRANDR) && HAVE_XRANDR
@ -482,6 +483,7 @@ void MainWindow::ConnectHotkeys()
connect(m_hotkey_scheduler, &HotkeyScheduler::EjectDisc, this, &MainWindow::EjectDisc); connect(m_hotkey_scheduler, &HotkeyScheduler::EjectDisc, this, &MainWindow::EjectDisc);
connect(m_hotkey_scheduler, &HotkeyScheduler::ExitHotkey, this, &MainWindow::close); connect(m_hotkey_scheduler, &HotkeyScheduler::ExitHotkey, this, &MainWindow::close);
connect(m_hotkey_scheduler, &HotkeyScheduler::TogglePauseHotkey, this, &MainWindow::TogglePause); connect(m_hotkey_scheduler, &HotkeyScheduler::TogglePauseHotkey, this, &MainWindow::TogglePause);
connect(m_hotkey_scheduler, &HotkeyScheduler::ActivateChat, this, &MainWindow::OnActivateChat);
connect(m_hotkey_scheduler, &HotkeyScheduler::RefreshGameListHotkey, this, connect(m_hotkey_scheduler, &HotkeyScheduler::RefreshGameListHotkey, this,
&MainWindow::RefreshGameList); &MainWindow::RefreshGameList);
connect(m_hotkey_scheduler, &HotkeyScheduler::StopHotkey, this, &MainWindow::RequestStop); connect(m_hotkey_scheduler, &HotkeyScheduler::StopHotkey, this, &MainWindow::RequestStop);
@ -1587,6 +1589,12 @@ void MainWindow::OnExportRecording()
Core::SetState(Core::State::Running); Core::SetState(Core::State::Running);
} }
void MainWindow::OnActivateChat()
{
if (g_netplay_chat_ui)
g_netplay_chat_ui->Activate();
}
void MainWindow::ShowTASInput() void MainWindow::ShowTASInput()
{ {
for (int i = 0; i < num_gc_controllers; i++) for (int i = 0; i < num_gc_controllers; i++)

View File

@ -168,6 +168,7 @@ private:
void OnStartRecording(); void OnStartRecording();
void OnStopRecording(); void OnStopRecording();
void OnExportRecording(); void OnExportRecording();
void OnActivateChat();
void ShowTASInput(); void ShowTASInput();
void ChangeDisc(); void ChangeDisc();

View File

@ -60,7 +60,12 @@ void NetPlayChatUI::Display()
ImGuiInputTextFlags_EnterReturnsTrue)) ImGuiInputTextFlags_EnterReturnsTrue))
{ {
SendMessage(); SendMessage();
}
if (m_activate)
{
ImGui::SetKeyboardFocusHere(-1); ImGui::SetKeyboardFocusHere(-1);
m_activate = false;
} }
ImGui::PopItemWidth(); ImGui::PopItemWidth();
@ -97,3 +102,11 @@ void NetPlayChatUI::SendMessage()
m_message_buf[0] = '\0'; m_message_buf[0] = '\0';
} }
} }
void NetPlayChatUI::Activate()
{
if (ImGui::IsItemFocused())
ImGui::SetWindowFocus(NULL);
else
m_activate = true;
}

View File

@ -22,10 +22,12 @@ public:
void Display(); void Display();
void AppendChat(const std::string& message, Color color); void AppendChat(const std::string& message, Color color);
void SendMessage(); void SendMessage();
void Activate();
private: private:
char m_message_buf[256] = {}; char m_message_buf[256] = {};
bool m_scroll_to_bottom = false; bool m_scroll_to_bottom = false;
bool m_activate = false;
bool m_is_scrolled_to_bottom = true; bool m_is_scrolled_to_bottom = true;
std::deque<std::pair<std::string, Color>> m_messages; std::deque<std::pair<std::string, Color>> m_messages;