mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-27 12:04:16 +01:00
Fix multiplayer dropdowns and proxy model
* Filters in the lobby properly remove rooms * Multiplayer menu items for Show Room and Leave Room work as intended
This commit is contained in:
parent
601fd81d5c
commit
a85511cd7d
@ -172,7 +172,8 @@ void GMainWindow::InitializeWidgets() {
|
||||
game_list = new GameList(this);
|
||||
ui.horizontalLayout->addWidget(game_list);
|
||||
|
||||
multiplayer_state = new MultiplayerState(this, game_list->GetModel());
|
||||
multiplayer_state = new MultiplayerState(this, game_list->GetModel(), ui.action_Leave_Room,
|
||||
ui.action_Show_Room);
|
||||
multiplayer_state->setVisible(false);
|
||||
|
||||
// Setup updater
|
||||
@ -436,11 +437,11 @@ void GMainWindow::ConnectMenuEvents() {
|
||||
&MultiplayerState::OnViewLobby);
|
||||
connect(ui.action_Start_Room, &QAction::triggered, multiplayer_state,
|
||||
&MultiplayerState::OnCreateRoom);
|
||||
connect(ui.action_Stop_Room, &QAction::triggered, multiplayer_state,
|
||||
connect(ui.action_Leave_Room, &QAction::triggered, multiplayer_state,
|
||||
&MultiplayerState::OnCloseRoom);
|
||||
connect(ui.action_Connect_To_Room, &QAction::triggered, multiplayer_state,
|
||||
&MultiplayerState::OnDirectConnectToRoom);
|
||||
connect(ui.action_Chat, &QAction::triggered, multiplayer_state,
|
||||
connect(ui.action_Show_Room, &QAction::triggered, multiplayer_state,
|
||||
&MultiplayerState::OnOpenNetworkRoom);
|
||||
|
||||
ui.action_Fullscreen->setShortcut(GetHotkey("Main Window", "Fullscreen", this)->key());
|
||||
@ -1331,18 +1332,6 @@ void GMainWindow::SyncMenuUISettings() {
|
||||
ui.action_Screen_Layout_Swap_Screens->setChecked(Settings::values.swap_screen);
|
||||
}
|
||||
|
||||
void GMainWindow::ChangeRoomState() {
|
||||
if (auto room = Network::GetRoom().lock()) {
|
||||
if (room->GetState() == Network::Room::State::Open) {
|
||||
ui.action_Start_Room->setDisabled(true);
|
||||
ui.action_Stop_Room->setEnabled(true);
|
||||
return;
|
||||
}
|
||||
ui.action_Start_Room->setEnabled(true);
|
||||
ui.action_Stop_Room->setDisabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef main
|
||||
#undef main
|
||||
#endif
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "common/announce_multiplayer_room.h"
|
||||
#include "core/core.h"
|
||||
#include "core/hle/service/am/am.h"
|
||||
#include "network/network.h"
|
||||
#include "ui_main.h"
|
||||
|
||||
class AboutDialog;
|
||||
@ -55,7 +54,6 @@ class GMainWindow : public QMainWindow {
|
||||
public:
|
||||
void filterBarSetChecked(bool state);
|
||||
void UpdateUITheme();
|
||||
void ChangeRoomState();
|
||||
|
||||
GameList* game_list;
|
||||
GMainWindow();
|
||||
|
@ -116,10 +116,10 @@
|
||||
</property>
|
||||
<addaction name="action_View_Lobby"/>
|
||||
<addaction name="action_Start_Room"/>
|
||||
<addaction name="action_Stop_Room"/>
|
||||
<addaction name="action_Connect_To_Room"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="action_Chat"/>
|
||||
<addaction name="action_Show_Room"/>
|
||||
<addaction name="action_Leave_Room"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_Help">
|
||||
<property name="title">
|
||||
@ -259,12 +259,12 @@
|
||||
<string>Create Room</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_Stop_Room">
|
||||
<action name="action_Leave_Room">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Close Room</string>
|
||||
<string>Leave Room</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_Connect_To_Room">
|
||||
@ -272,12 +272,12 @@
|
||||
<string>Direct Connect to Room</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_Chat">
|
||||
<action name="action_Show_Room">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Current Room</string>
|
||||
<string>Show Current Room</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_Fullscreen">
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>455</width>
|
||||
<height>239</height>
|
||||
<height>161</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -18,28 +18,6 @@
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="instructions_2">
|
||||
<property name="title">
|
||||
<string>Instructions</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QLabel" name="instructions">
|
||||
<property name="text">
|
||||
<string><html><head/><body><p>Directly connect to a friend by <span style=" font-weight:600;">Traversal server</span> or by<span style=" font-weight:600;"> IP address</span>. </p><p>To use the <span style=" font-weight:600;">Traversal Server</span>, ask the game host for their &quot;<span style=" font-weight:600;">Host Code</span>&quot; which will be visible on the create room screen after it is created.</p></body></html></string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::RichText</enum>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
|
@ -32,6 +32,7 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list,
|
||||
model = new QStandardItemModel(ui->room_list);
|
||||
proxy = new LobbyFilterProxyModel(this, game_list);
|
||||
proxy->setSourceModel(model);
|
||||
proxy->setDynamicSortFilter(true);
|
||||
proxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
proxy->setSortLocaleAware(true);
|
||||
ui->room_list->setModel(proxy);
|
||||
@ -45,7 +46,6 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list,
|
||||
ui->room_list->setSortingEnabled(true);
|
||||
ui->room_list->setEditTriggers(QHeaderView::NoEditTriggers);
|
||||
ui->room_list->setExpandsOnDoubleClick(false);
|
||||
// ui->room_list->setUniformRowHeights(true);
|
||||
ui->room_list->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
ui->nickname->setValidator(Validation::nickname);
|
||||
@ -54,7 +54,6 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list,
|
||||
// UI Buttons
|
||||
MultiplayerState* p = reinterpret_cast<MultiplayerState*>(parent);
|
||||
connect(ui->refresh_list, &QPushButton::pressed, this, &Lobby::RefreshLobby);
|
||||
connect(ui->chat, &QPushButton::pressed, p, &MultiplayerState::OnOpenNetworkRoom);
|
||||
connect(ui->games_owned, &QCheckBox::stateChanged, proxy,
|
||||
&LobbyFilterProxyModel::SetFilterOwned);
|
||||
connect(ui->hide_full, &QCheckBox::stateChanged, proxy, &LobbyFilterProxyModel::SetFilterFull);
|
||||
@ -68,28 +67,11 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list,
|
||||
// TODO(jroweboy): change this slot to OnConnected?
|
||||
connect(this, &Lobby::Connected, p, &MultiplayerState::OnOpenNetworkRoom);
|
||||
|
||||
// setup the callbacks for network updates
|
||||
if (auto member = Network::GetRoomMember().lock()) {
|
||||
member->BindOnStateChanged(
|
||||
[this](const Network::RoomMember::State& state) { emit StateChanged(state); });
|
||||
connect(this, &Lobby::StateChanged, this, &Lobby::OnStateChanged);
|
||||
} else {
|
||||
// TODO (jroweboy) network was not initialized?
|
||||
}
|
||||
|
||||
// manually start a refresh when the window is opening
|
||||
// TODO(jroweboy): if this refresh is slow for people with bad internet, then don't do it as
|
||||
// part of the constructor, but offload the refresh until after the window shown. perhaps emit a
|
||||
// refreshroomlist signal from places that open the lobby
|
||||
RefreshLobby();
|
||||
|
||||
if (auto member = Network::GetRoomMember().lock()) {
|
||||
if (member->IsConnected()) {
|
||||
ui->chat->setEnabled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
ui->chat->setDisabled(true);
|
||||
}
|
||||
|
||||
const QString Lobby::PasswordPrompt() {
|
||||
@ -148,16 +130,6 @@ void Lobby::OnJoinRoom(const QModelIndex& index) {
|
||||
Settings::Apply();
|
||||
}
|
||||
|
||||
void Lobby::OnStateChanged(const Network::RoomMember::State& state) {
|
||||
if (auto member = Network::GetRoomMember().lock()) {
|
||||
if (member->IsConnected()) {
|
||||
ui->chat->setEnabled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
ui->chat->setDisabled(true);
|
||||
}
|
||||
|
||||
void Lobby::ResetModel() {
|
||||
model->clear();
|
||||
model->insertColumns(0, Column::TOTAL);
|
||||
@ -218,7 +190,7 @@ void Lobby::OnRefreshLobby() {
|
||||
first_item->appendRow(new LobbyItemExpandedMemberList(members));
|
||||
}
|
||||
}
|
||||
ui->room_list->setModel(model);
|
||||
proxy->setSourceModel(model);
|
||||
|
||||
// Reenable the refresh button and resize the columns
|
||||
ui->refresh_list->setEnabled(true);
|
||||
@ -311,12 +283,12 @@ void LobbyFilterProxyModel::sort(int column, Qt::SortOrder order) {
|
||||
|
||||
void LobbyFilterProxyModel::SetFilterOwned(bool filter) {
|
||||
filter_owned = filter;
|
||||
invalidateFilter();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void LobbyFilterProxyModel::SetFilterFull(bool filter) {
|
||||
filter_full = filter;
|
||||
invalidateFilter();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void Lobby::OnConnection() {
|
||||
|
@ -68,8 +68,6 @@ private slots:
|
||||
*/
|
||||
void OnConnection();
|
||||
|
||||
void OnStateChanged(const Network::RoomMember::State&);
|
||||
|
||||
signals:
|
||||
/**
|
||||
* Signalled when the latest lobby data is retrieved.
|
||||
|
@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>850</width>
|
||||
<width>903</width>
|
||||
<height>487</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -25,26 +25,14 @@
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="general">
|
||||
<property name="title">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Nickname</string>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="nickname">
|
||||
<property name="placeholderText">
|
||||
@ -52,30 +40,26 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="filters">
|
||||
<property name="title">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Filters</string>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="search">
|
||||
<property name="placeholderText">
|
||||
@ -100,11 +84,19 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="refresh_list">
|
||||
<property name="text">
|
||||
@ -112,13 +104,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="chat">
|
||||
<property name="text">
|
||||
<string>Chat</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -2,6 +2,7 @@
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <QAction>
|
||||
#include <QIcon>
|
||||
#include <QMessageBox>
|
||||
#include <QStandardItemModel>
|
||||
@ -16,8 +17,10 @@
|
||||
#include "common/announce_multiplayer_room.h"
|
||||
#include "common/logging/log.h"
|
||||
|
||||
MultiplayerState::MultiplayerState(QWidget* parent, QStandardItemModel* game_list_model)
|
||||
: QWidget(parent), game_list_model(game_list_model) {
|
||||
MultiplayerState::MultiplayerState(QWidget* parent, QStandardItemModel* game_list_model,
|
||||
QAction* leave_room, QAction* show_room)
|
||||
: QWidget(parent), game_list_model(game_list_model), leave_room(leave_room),
|
||||
show_room(show_room) {
|
||||
if (auto member = Network::GetRoomMember().lock()) {
|
||||
// register the network structs to use in slots and signals
|
||||
state_callback_handle = member->BindOnStateChanged(
|
||||
@ -67,10 +70,14 @@ void MultiplayerState::OnNetworkStateChanged(const Network::RoomMember::State& s
|
||||
if (state == Network::RoomMember::State::Joined) {
|
||||
status_icon->setPixmap(QIcon::fromTheme("connected").pixmap(16));
|
||||
status_text->setText(tr("Connected"));
|
||||
leave_room->setEnabled(true);
|
||||
show_room->setEnabled(true);
|
||||
return;
|
||||
}
|
||||
status_icon->setPixmap(QIcon::fromTheme("disconnected").pixmap(16));
|
||||
status_text->setText(tr("Not Connected"));
|
||||
leave_room->setEnabled(false);
|
||||
show_room->setEnabled(false);
|
||||
}
|
||||
|
||||
void MultiplayerState::OnAnnounceFailed(const Common::WebResult& result) {
|
||||
@ -103,15 +110,21 @@ void MultiplayerState::OnCreateRoom() {
|
||||
}
|
||||
|
||||
void MultiplayerState::OnCloseRoom() {
|
||||
if (!NetworkMessage::WarnCloseRoom())
|
||||
return;
|
||||
if (auto room = Network::GetRoom().lock()) {
|
||||
// if you are in a room, leave it
|
||||
if (auto member = Network::GetRoomMember().lock()) {
|
||||
member->Leave();
|
||||
}
|
||||
|
||||
// if you are hosting a room, also stop hosting
|
||||
if (room->GetState() != Network::Room::State::Open) {
|
||||
return;
|
||||
}
|
||||
if (NetworkMessage::WarnCloseRoom()) {
|
||||
room->Destroy();
|
||||
announce_multiplayer_session->Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MultiplayerState::OnOpenNetworkRoom() {
|
||||
|
@ -21,7 +21,8 @@ class MultiplayerState : public QWidget {
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
explicit MultiplayerState(QWidget* parent, QStandardItemModel* game_list);
|
||||
explicit MultiplayerState(QWidget* parent, QStandardItemModel* game_list, QAction* leave_room,
|
||||
QAction* show_room);
|
||||
~MultiplayerState();
|
||||
|
||||
/**
|
||||
@ -58,6 +59,8 @@ private:
|
||||
ClickableLabel* status_icon = nullptr;
|
||||
ClickableLabel* status_text = nullptr;
|
||||
QStandardItemModel* game_list_model = nullptr;
|
||||
QAction* leave_room;
|
||||
QAction* show_room;
|
||||
std::shared_ptr<Core::AnnounceMultiplayerSession> announce_multiplayer_session;
|
||||
Network::RoomMember::CallbackHandle<Network::RoomMember::State> state_callback_handle;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user