mirror of
https://git.citron-emu.org/citron/emulator
synced 2025-12-29 06:33:44 +00:00
Merge branch 'fix/multiplayer-room-overlay' into 'main'
Fix: Resolve multiplayer overlay notification and state bugs See merge request citron/emulator!115
This commit is contained in:
@@ -28,7 +28,7 @@ MultiplayerRoomOverlay::MultiplayerRoomOverlay(GMainWindow* parent)
|
||||
border_color = QColor(60, 60, 60, 120);
|
||||
|
||||
main_layout = new QGridLayout(this);
|
||||
main_layout->setContentsMargins(padding, padding, 0, 0); // No margins on bottom/right for grip
|
||||
main_layout->setContentsMargins(padding, padding, 0, 0);
|
||||
main_layout->setSpacing(6);
|
||||
|
||||
players_online_label = new QLabel(this);
|
||||
@@ -71,7 +71,6 @@ MultiplayerRoomOverlay::~MultiplayerRoomOverlay() {
|
||||
}
|
||||
|
||||
void MultiplayerRoomOverlay::OnEmulationStarting() {
|
||||
// When emulation starts, resume updates if we are visible.
|
||||
if (is_visible) {
|
||||
ConnectToRoom();
|
||||
update_timer.start(500);
|
||||
@@ -79,7 +78,6 @@ void MultiplayerRoomOverlay::OnEmulationStarting() {
|
||||
}
|
||||
|
||||
void MultiplayerRoomOverlay::OnEmulationStopping() {
|
||||
// CRASH FIX: When emulation stops, immediately disconnect from network objects.
|
||||
update_timer.stop();
|
||||
DisconnectFromRoom();
|
||||
}
|
||||
@@ -90,7 +88,6 @@ void MultiplayerRoomOverlay::SetVisible(bool visible) {
|
||||
|
||||
if (visible) {
|
||||
show();
|
||||
// Only start connecting and updating if emulation is running.
|
||||
if (main_window && main_window->IsEmulationRunning()) {
|
||||
ConnectToRoom();
|
||||
update_timer.start(500);
|
||||
@@ -116,19 +113,26 @@ void MultiplayerRoomOverlay::paintEvent(QPaintEvent* event) {
|
||||
void MultiplayerRoomOverlay::resizeEvent(QResizeEvent* event) { QWidget::resizeEvent(event); if (!has_been_moved) UpdatePosition(); }
|
||||
bool MultiplayerRoomOverlay::eventFilter(QObject* watched, QEvent* event) { if (event->type() == QEvent::MouseButtonPress) { if (chat_room_widget->hasFocus()) { chat_room_widget->clearFocus(); } } return QObject::eventFilter(watched, event); }
|
||||
|
||||
|
||||
#if defined(Q_OS_LINUX)
|
||||
void MultiplayerRoomOverlay::mousePressEvent(QMouseEvent* event) {
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
if (size_grip->geometry().contains(event->pos())) {
|
||||
// Let the size grip handle the event
|
||||
} else if (!childAt(event->pos()) || childAt(event->pos()) == this) {
|
||||
if (windowHandle()) windowHandle()->startSystemMove();
|
||||
if (windowHandle()) {
|
||||
QTimer::singleShot(0, this, [this] { windowHandle()->startSystemMove(); });
|
||||
}
|
||||
}
|
||||
}
|
||||
QWidget::mousePressEvent(event);
|
||||
}
|
||||
void MultiplayerRoomOverlay::mouseMoveEvent(QMouseEvent* event) { QWidget::mouseMoveEvent(event); }
|
||||
#else
|
||||
|
||||
void MultiplayerRoomOverlay::mouseMoveEvent(QMouseEvent* event) {
|
||||
QWidget::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
#else // Windows and other platforms
|
||||
void MultiplayerRoomOverlay::mousePressEvent(QMouseEvent* event) {
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
if (size_grip->geometry().contains(event->pos())) {
|
||||
@@ -142,12 +146,14 @@ void MultiplayerRoomOverlay::mousePressEvent(QMouseEvent* event) {
|
||||
}
|
||||
QWidget::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void MultiplayerRoomOverlay::mouseMoveEvent(QMouseEvent* event) {
|
||||
if (is_dragging) {
|
||||
QPoint delta = event->globalPosition().toPoint() - drag_start_pos;
|
||||
move(widget_start_pos + delta);
|
||||
has_been_moved = true;
|
||||
}
|
||||
QWidget::mouseMoveEvent(event); // Corrected typo here
|
||||
QWidget::mouseMoveEvent(event);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -168,7 +174,7 @@ void MultiplayerRoomOverlay::ConnectToRoom() {
|
||||
if (multiplayer_state->IsClientRoomVisible()) {
|
||||
chat_room_widget->setEnabled(false);
|
||||
chat_room_widget->Clear();
|
||||
chat_room_widget->AppendStatusMessage(tr("Chat available in main window."));
|
||||
chat_room_widget->AppendStatusMessage(tr("In order to use chat functionality in the Overlay, please close the Multiplayer Room Window."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -177,7 +183,10 @@ void MultiplayerRoomOverlay::ConnectToRoom() {
|
||||
room_member = room_network.GetRoomMember().lock();
|
||||
|
||||
if (room_member) {
|
||||
chat_room_widget->Initialize(&room_network);
|
||||
if (!is_chat_initialized) {
|
||||
chat_room_widget->Initialize(&room_network);
|
||||
is_chat_initialized = true;
|
||||
}
|
||||
} else {
|
||||
chat_room_widget->Clear();
|
||||
chat_room_widget->AppendStatusMessage(tr("Not connected to a room."));
|
||||
@@ -185,10 +194,17 @@ void MultiplayerRoomOverlay::ConnectToRoom() {
|
||||
}
|
||||
|
||||
void MultiplayerRoomOverlay::DisconnectFromRoom() {
|
||||
chat_room_widget->Clear();
|
||||
ClearUI();
|
||||
room_member.reset();
|
||||
multiplayer_state = nullptr;
|
||||
is_chat_initialized = false;
|
||||
}
|
||||
|
||||
void MultiplayerRoomOverlay::ClearUI() {
|
||||
players_online_label->setText(QString::fromUtf8("Players Online: 0"));
|
||||
chat_room_widget->Clear();
|
||||
chat_room_widget->AppendStatusMessage(tr("Not connected to a room."));
|
||||
chat_room_widget->SetPlayerList({});
|
||||
}
|
||||
|
||||
void MultiplayerRoomOverlay::UpdateRoomData() {
|
||||
@@ -201,28 +217,26 @@ void MultiplayerRoomOverlay::UpdateRoomData() {
|
||||
if (chat_room_widget->isEnabled()) {
|
||||
chat_room_widget->setEnabled(false);
|
||||
chat_room_widget->Clear();
|
||||
chat_room_widget->AppendStatusMessage(tr("Chat available in main window."));
|
||||
}
|
||||
} else {
|
||||
if (!chat_room_widget->isEnabled()) {
|
||||
ConnectToRoom();
|
||||
chat_room_widget->AppendStatusMessage(tr("In order to use chat functionality in the Overlay, please close the Multiplayer Room Window."));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!chat_room_widget->isEnabled()) {
|
||||
ConnectToRoom();
|
||||
}
|
||||
|
||||
if (room_member && room_member->GetState() >= Network::RoomMember::State::Joined) {
|
||||
const auto& members = room_member->GetMemberInformation();
|
||||
QString label_text = QString::fromStdString("Players Online: <span style='color: #4CAF50;'>%1</span>").arg(members.size());
|
||||
players_online_label->setText(label_text);
|
||||
|
||||
if (chat_room_widget->isEnabled()) {
|
||||
chat_room_widget->SetPlayerList(members);
|
||||
}
|
||||
} else {
|
||||
players_online_label->setText(QString::fromUtf8("Players Online: 0"));
|
||||
if (!room_member && !multiplayer_state->IsClientRoomVisible()) {
|
||||
chat_room_widget->Clear();
|
||||
chat_room_widget->AppendStatusMessage(tr("Not connected to a room."));
|
||||
ConnectToRoom();
|
||||
}
|
||||
ClearUI();
|
||||
room_member.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,4 +246,4 @@ void MultiplayerRoomOverlay::UpdatePosition() {
|
||||
QPoint main_window_pos = main_window->mapToGlobal(QPoint(0, 0));
|
||||
move(main_window_pos.x() + main_window->width() - this->width() - 10, main_window_pos.y() + 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@
|
||||
#include <QPainter>
|
||||
#include <QLabel>
|
||||
#include <QGridLayout>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "citron/multiplayer/state.h"
|
||||
#include "citron/multiplayer/chat_room.h"
|
||||
@@ -45,6 +47,7 @@ private:
|
||||
void UpdatePosition();
|
||||
void ConnectToRoom();
|
||||
void DisconnectFromRoom();
|
||||
void ClearUI();
|
||||
|
||||
GMainWindow* main_window;
|
||||
QTimer update_timer;
|
||||
@@ -74,4 +77,7 @@ private:
|
||||
bool has_been_moved = false;
|
||||
QPoint drag_start_pos;
|
||||
QPoint widget_start_pos;
|
||||
|
||||
// State tracking
|
||||
bool is_chat_initialized = false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user