Skip to content

Commit 4b1fe70

Browse files
committed
Initial chat view toggle hotkey implementation (chat hides, but doesn't expand again)
1 parent d46e830 commit 4b1fe70

File tree

8 files changed

+76
-2
lines changed

8 files changed

+76
-2
lines changed

Source/Core/Core/HotkeyManager.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ constexpr std::array<const char*, NUM_HOTKEYS> s_hotkey_labels{{
3737
_trans("Unlock Cursor"),
3838
_trans("Center Mouse"),
3939
_trans("Activate NetPlay Chat"),
40+
_trans("Collapse NetPlay Chat"),
41+
_trans("Expand NetPlay Chat"),
4042
_trans("Control NetPlay Golf Mode"),
4143
#ifdef USE_RETRO_ACHIEVEMENTS
4244
_trans("Open Achievements"),
@@ -452,6 +454,8 @@ void HotkeyManager::LoadDefaults(const ControllerInterface& ciface)
452454
set_key_expression(HK_VOLUME_DOWN, "DOWN");
453455
set_key_expression(HK_VOLUME_UP, "UP");
454456
set_key_expression(HK_ACTIVATE_CHAT, "T");
457+
set_key_expression(HK_COLLAPSE_CHAT, "LEFT");
458+
set_key_expression(HK_EXPAND_CHAT, "RIGHT");
455459
#ifdef _WIN32
456460
set_key_expression(HK_STOP, "ESCAPE");
457461
set_key_expression(HK_FULLSCREEN, hotkey_string({"Alt", "RETURN"}));

Source/Core/Core/HotkeyManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ enum Hotkey
3131
HK_UNLOCK_CURSOR,
3232
HK_CENTER_MOUSE,
3333
HK_ACTIVATE_CHAT,
34+
HK_COLLAPSE_CHAT,
35+
HK_EXPAND_CHAT,
3436
HK_REQUEST_GOLF_CONTROL,
3537
#ifdef USE_RETRO_ACHIEVEMENTS
3638
HK_OPEN_ACHIEVEMENTS,

Source/Core/DolphinQt/HotkeyScheduler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ void HotkeyScheduler::Run()
255255
if (IsHotkey(HK_ACTIVATE_CHAT))
256256
emit ActivateChat();
257257

258+
if (IsHotkey(HK_COLLAPSE_CHAT))
259+
emit CollapseChat();
260+
261+
if (IsHotkey(HK_EXPAND_CHAT))
262+
emit ExpandChat();
263+
258264
if (IsHotkey(HK_REQUEST_GOLF_CONTROL))
259265
emit RequestGolfControl();
260266

Source/Core/DolphinQt/HotkeyScheduler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class HotkeyScheduler : public QObject
2828
void ExitHotkey();
2929
void UnlockCursor();
3030
void ActivateChat();
31+
void CollapseChat();
32+
void ExpandChat();
3133
void RequestGolfControl();
3234
void FullScreenHotkey();
3335
void StopHotkey();

Source/Core/DolphinQt/MainWindow.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,8 @@ void MainWindow::ConnectHotkeys()
639639
connect(m_hotkey_scheduler, &HotkeyScheduler::UnlockCursor, this, &MainWindow::UnlockCursor);
640640
connect(m_hotkey_scheduler, &HotkeyScheduler::TogglePauseHotkey, this, &MainWindow::TogglePause);
641641
connect(m_hotkey_scheduler, &HotkeyScheduler::ActivateChat, this, &MainWindow::OnActivateChat);
642+
connect(m_hotkey_scheduler, &HotkeyScheduler::CollapseChat, this, &MainWindow::OnCollapseChat);
643+
connect(m_hotkey_scheduler, &HotkeyScheduler::ExpandChat, this, &MainWindow::OnExpandChat);
642644
connect(m_hotkey_scheduler, &HotkeyScheduler::RequestGolfControl, this,
643645
&MainWindow::OnRequestGolfControl);
644646
connect(m_hotkey_scheduler, &HotkeyScheduler::RefreshGameListHotkey, this,
@@ -2050,6 +2052,18 @@ void MainWindow::OnActivateChat()
20502052
g_netplay_chat_ui->Activate();
20512053
}
20522054

2055+
void MainWindow::OnCollapseChat()
2056+
{
2057+
if (g_netplay_chat_ui)
2058+
g_netplay_chat_ui->Collapse();
2059+
}
2060+
2061+
void MainWindow::OnExpandChat()
2062+
{
2063+
if (g_netplay_chat_ui)
2064+
g_netplay_chat_ui->Expand();
2065+
}
2066+
20532067
void MainWindow::OnRequestGolfControl()
20542068
{
20552069
auto client = Settings::Instance().GetNetPlayClient();

Source/Core/DolphinQt/MainWindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ class MainWindow final : public QMainWindow
210210
void OnStopRecording();
211211
void OnExportRecording();
212212
void OnActivateChat();
213+
void OnCollapseChat();
214+
void OnExpandChat();
213215
void OnRequestGolfControl();
214216
void ShowTASInput();
215217

Source/Core/VideoCommon/NetPlayChatUI.cpp

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <imgui.h>
77

88
constexpr float DEFAULT_WINDOW_WIDTH = 220.0f;
9-
constexpr float DEFAULT_WINDOW_HEIGHT = 400.0f;
9+
constexpr float DEFAULT_WINDOW_HEIGHT = 220.0f;
1010

1111
constexpr size_t MAX_BACKLOG_SIZE = 100;
1212

@@ -23,7 +23,7 @@ void NetPlayChatUI::Display()
2323
{
2424
const float scale = ImGui::GetIO().DisplayFramebufferScale.x;
2525

26-
ImGui::SetNextWindowPos(ImVec2(10.0f * scale, 10.0f * scale), ImGuiCond_FirstUseEver);
26+
ImGui::SetNextWindowPos(ImVec2(10.0f * scale, 40.0f * scale), ImGuiCond_FirstUseEver);
2727
ImGui::SetNextWindowSizeConstraints(
2828
ImVec2(DEFAULT_WINDOW_WIDTH * scale, DEFAULT_WINDOW_HEIGHT * scale),
2929
ImGui::GetIO().DisplaySize);
@@ -68,6 +68,18 @@ void NetPlayChatUI::Display()
6868
m_activate = false;
6969
}
7070

71+
if (m_collapse)
72+
{
73+
NetPlayChatUI::Collapse();
74+
m_collapse = true;
75+
}
76+
77+
if (m_expand)
78+
{
79+
NetPlayChatUI::Expand();
80+
m_expand = true;
81+
}
82+
7183
ImGui::PopItemWidth();
7284

7385
ImGui::SameLine();
@@ -110,3 +122,31 @@ void NetPlayChatUI::Activate()
110122
else
111123
m_activate = true;
112124
}
125+
126+
void NetPlayChatUI::Collapse()
127+
{
128+
if (!ImGui::IsWindowCollapsed())
129+
{
130+
ImGui::SetWindowCollapsed(true);
131+
m_collapse = false;
132+
}
133+
else
134+
{
135+
ImGui::SetWindowCollapsed(false);
136+
m_collapse = true;
137+
}
138+
}
139+
140+
void NetPlayChatUI::Expand()
141+
{
142+
if (ImGui::IsWindowCollapsed())
143+
{
144+
ImGui::SetWindowCollapsed(false);
145+
m_collapse = true;
146+
}
147+
else
148+
{
149+
ImGui::SetWindowCollapsed(true);
150+
m_collapse = false;
151+
}
152+
}

Source/Core/VideoCommon/NetPlayChatUI.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ class NetPlayChatUI
2222
void AppendChat(std::string message, Color color);
2323
void SendMessage();
2424
void Activate();
25+
void Collapse();
26+
void Expand();
2527

2628
private:
2729
char m_message_buf[256] = {};
2830
bool m_scroll_to_bottom = false;
2931
bool m_activate = false;
32+
bool m_collapse = false;
33+
bool m_expand = true;
3034
bool m_is_scrolled_to_bottom = true;
3135

3236
std::deque<std::pair<std::string, Color>> m_messages;

0 commit comments

Comments
 (0)