mirror of
https://git.eden-emu.dev/archive/citron
synced 2026-04-04 10:30:12 -04: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);
|
border_color = QColor(60, 60, 60, 120);
|
||||||
|
|
||||||
main_layout = new QGridLayout(this);
|
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);
|
main_layout->setSpacing(6);
|
||||||
|
|
||||||
players_online_label = new QLabel(this);
|
players_online_label = new QLabel(this);
|
||||||
@@ -71,7 +71,6 @@ MultiplayerRoomOverlay::~MultiplayerRoomOverlay() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MultiplayerRoomOverlay::OnEmulationStarting() {
|
void MultiplayerRoomOverlay::OnEmulationStarting() {
|
||||||
// When emulation starts, resume updates if we are visible.
|
|
||||||
if (is_visible) {
|
if (is_visible) {
|
||||||
ConnectToRoom();
|
ConnectToRoom();
|
||||||
update_timer.start(500);
|
update_timer.start(500);
|
||||||
@@ -79,7 +78,6 @@ void MultiplayerRoomOverlay::OnEmulationStarting() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MultiplayerRoomOverlay::OnEmulationStopping() {
|
void MultiplayerRoomOverlay::OnEmulationStopping() {
|
||||||
// CRASH FIX: When emulation stops, immediately disconnect from network objects.
|
|
||||||
update_timer.stop();
|
update_timer.stop();
|
||||||
DisconnectFromRoom();
|
DisconnectFromRoom();
|
||||||
}
|
}
|
||||||
@@ -90,7 +88,6 @@ void MultiplayerRoomOverlay::SetVisible(bool visible) {
|
|||||||
|
|
||||||
if (visible) {
|
if (visible) {
|
||||||
show();
|
show();
|
||||||
// Only start connecting and updating if emulation is running.
|
|
||||||
if (main_window && main_window->IsEmulationRunning()) {
|
if (main_window && main_window->IsEmulationRunning()) {
|
||||||
ConnectToRoom();
|
ConnectToRoom();
|
||||||
update_timer.start(500);
|
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(); }
|
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); }
|
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)
|
#if defined(Q_OS_LINUX)
|
||||||
void MultiplayerRoomOverlay::mousePressEvent(QMouseEvent* event) {
|
void MultiplayerRoomOverlay::mousePressEvent(QMouseEvent* event) {
|
||||||
if (event->button() == Qt::LeftButton) {
|
if (event->button() == Qt::LeftButton) {
|
||||||
if (size_grip->geometry().contains(event->pos())) {
|
if (size_grip->geometry().contains(event->pos())) {
|
||||||
// Let the size grip handle the event
|
// Let the size grip handle the event
|
||||||
} else if (!childAt(event->pos()) || childAt(event->pos()) == this) {
|
} 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);
|
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) {
|
void MultiplayerRoomOverlay::mousePressEvent(QMouseEvent* event) {
|
||||||
if (event->button() == Qt::LeftButton) {
|
if (event->button() == Qt::LeftButton) {
|
||||||
if (size_grip->geometry().contains(event->pos())) {
|
if (size_grip->geometry().contains(event->pos())) {
|
||||||
@@ -142,12 +146,14 @@ void MultiplayerRoomOverlay::mousePressEvent(QMouseEvent* event) {
|
|||||||
}
|
}
|
||||||
QWidget::mousePressEvent(event);
|
QWidget::mousePressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiplayerRoomOverlay::mouseMoveEvent(QMouseEvent* event) {
|
void MultiplayerRoomOverlay::mouseMoveEvent(QMouseEvent* event) {
|
||||||
if (is_dragging) {
|
if (is_dragging) {
|
||||||
QPoint delta = event->globalPosition().toPoint() - drag_start_pos;
|
QPoint delta = event->globalPosition().toPoint() - drag_start_pos;
|
||||||
move(widget_start_pos + delta);
|
move(widget_start_pos + delta);
|
||||||
|
has_been_moved = true;
|
||||||
}
|
}
|
||||||
QWidget::mouseMoveEvent(event); // Corrected typo here
|
QWidget::mouseMoveEvent(event);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -168,7 +174,7 @@ void MultiplayerRoomOverlay::ConnectToRoom() {
|
|||||||
if (multiplayer_state->IsClientRoomVisible()) {
|
if (multiplayer_state->IsClientRoomVisible()) {
|
||||||
chat_room_widget->setEnabled(false);
|
chat_room_widget->setEnabled(false);
|
||||||
chat_room_widget->Clear();
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +183,10 @@ void MultiplayerRoomOverlay::ConnectToRoom() {
|
|||||||
room_member = room_network.GetRoomMember().lock();
|
room_member = room_network.GetRoomMember().lock();
|
||||||
|
|
||||||
if (room_member) {
|
if (room_member) {
|
||||||
chat_room_widget->Initialize(&room_network);
|
if (!is_chat_initialized) {
|
||||||
|
chat_room_widget->Initialize(&room_network);
|
||||||
|
is_chat_initialized = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
chat_room_widget->Clear();
|
chat_room_widget->Clear();
|
||||||
chat_room_widget->AppendStatusMessage(tr("Not connected to a room."));
|
chat_room_widget->AppendStatusMessage(tr("Not connected to a room."));
|
||||||
@@ -185,10 +194,17 @@ void MultiplayerRoomOverlay::ConnectToRoom() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MultiplayerRoomOverlay::DisconnectFromRoom() {
|
void MultiplayerRoomOverlay::DisconnectFromRoom() {
|
||||||
chat_room_widget->Clear();
|
ClearUI();
|
||||||
room_member.reset();
|
room_member.reset();
|
||||||
multiplayer_state = nullptr;
|
multiplayer_state = nullptr;
|
||||||
|
is_chat_initialized = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MultiplayerRoomOverlay::ClearUI() {
|
||||||
players_online_label->setText(QString::fromUtf8("Players Online: 0"));
|
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() {
|
void MultiplayerRoomOverlay::UpdateRoomData() {
|
||||||
@@ -201,28 +217,26 @@ void MultiplayerRoomOverlay::UpdateRoomData() {
|
|||||||
if (chat_room_widget->isEnabled()) {
|
if (chat_room_widget->isEnabled()) {
|
||||||
chat_room_widget->setEnabled(false);
|
chat_room_widget->setEnabled(false);
|
||||||
chat_room_widget->Clear();
|
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."));
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!chat_room_widget->isEnabled()) {
|
|
||||||
ConnectToRoom();
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!chat_room_widget->isEnabled()) {
|
||||||
|
ConnectToRoom();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (room_member && room_member->GetState() >= Network::RoomMember::State::Joined) {
|
if (room_member && room_member->GetState() >= Network::RoomMember::State::Joined) {
|
||||||
const auto& members = room_member->GetMemberInformation();
|
const auto& members = room_member->GetMemberInformation();
|
||||||
QString label_text = QString::fromStdString("Players Online: <span style='color: #4CAF50;'>%1</span>").arg(members.size());
|
QString label_text = QString::fromStdString("Players Online: <span style='color: #4CAF50;'>%1</span>").arg(members.size());
|
||||||
players_online_label->setText(label_text);
|
players_online_label->setText(label_text);
|
||||||
|
|
||||||
if (chat_room_widget->isEnabled()) {
|
if (chat_room_widget->isEnabled()) {
|
||||||
chat_room_widget->SetPlayerList(members);
|
chat_room_widget->SetPlayerList(members);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
players_online_label->setText(QString::fromUtf8("Players Online: 0"));
|
ClearUI();
|
||||||
if (!room_member && !multiplayer_state->IsClientRoomVisible()) {
|
room_member.reset();
|
||||||
chat_room_widget->Clear();
|
|
||||||
chat_room_widget->AppendStatusMessage(tr("Not connected to a room."));
|
|
||||||
ConnectToRoom();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,4 +246,4 @@ void MultiplayerRoomOverlay::UpdatePosition() {
|
|||||||
QPoint main_window_pos = main_window->mapToGlobal(QPoint(0, 0));
|
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);
|
move(main_window_pos.x() + main_window->width() - this->width() - 10, main_window_pos.y() + 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,8 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
|
#include <set>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "citron/multiplayer/state.h"
|
#include "citron/multiplayer/state.h"
|
||||||
#include "citron/multiplayer/chat_room.h"
|
#include "citron/multiplayer/chat_room.h"
|
||||||
@@ -45,6 +47,7 @@ private:
|
|||||||
void UpdatePosition();
|
void UpdatePosition();
|
||||||
void ConnectToRoom();
|
void ConnectToRoom();
|
||||||
void DisconnectFromRoom();
|
void DisconnectFromRoom();
|
||||||
|
void ClearUI();
|
||||||
|
|
||||||
GMainWindow* main_window;
|
GMainWindow* main_window;
|
||||||
QTimer update_timer;
|
QTimer update_timer;
|
||||||
@@ -74,4 +77,7 @@ private:
|
|||||||
bool has_been_moved = false;
|
bool has_been_moved = false;
|
||||||
QPoint drag_start_pos;
|
QPoint drag_start_pos;
|
||||||
QPoint widget_start_pos;
|
QPoint widget_start_pos;
|
||||||
|
|
||||||
|
// State tracking
|
||||||
|
bool is_chat_initialized = false;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user