Commit 51828209 authored by Max-Wilhelm Bruker's avatar Max-Wilhelm Bruker
Browse files

merged from master

parents ccfdc0a0 332ca29d
...@@ -20,7 +20,7 @@ GameSelector::GameSelector(AbstractClient *_client, TabSupervisor *_tabSuperviso ...@@ -20,7 +20,7 @@ GameSelector::GameSelector(AbstractClient *_client, TabSupervisor *_tabSuperviso
{ {
gameListView = new QTreeView; gameListView = new QTreeView;
gameListModel = new GamesModel(_rooms, _gameTypes, this); gameListModel = new GamesModel(_rooms, _gameTypes, this);
gameListProxyModel = new GamesProxyModel(this); gameListProxyModel = new GamesProxyModel(this, tabSupervisor->getUserInfo());
gameListProxyModel->setSourceModel(gameListModel); gameListProxyModel->setSourceModel(gameListModel);
gameListProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); gameListProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
gameListView->setModel(gameListProxyModel); gameListView->setModel(gameListProxyModel);
...@@ -31,12 +31,10 @@ GameSelector::GameSelector(AbstractClient *_client, TabSupervisor *_tabSuperviso ...@@ -31,12 +31,10 @@ GameSelector::GameSelector(AbstractClient *_client, TabSupervisor *_tabSuperviso
gameListView->header()->hideSection(1); gameListView->header()->hideSection(1);
gameListView->header()->setResizeMode(1, QHeaderView::ResizeToContents); gameListView->header()->setResizeMode(1, QHeaderView::ResizeToContents);
showFullGamesCheckBox = new QCheckBox; showUnavailableGamesCheckBox = new QCheckBox;
showRunningGamesCheckBox = new QCheckBox;
QVBoxLayout *filterLayout = new QVBoxLayout; QVBoxLayout *filterLayout = new QVBoxLayout;
filterLayout->addWidget(showFullGamesCheckBox); filterLayout->addWidget(showUnavailableGamesCheckBox);
filterLayout->addWidget(showRunningGamesCheckBox);
if (room) { if (room) {
createButton = new QPushButton; createButton = new QPushButton;
...@@ -68,20 +66,14 @@ GameSelector::GameSelector(AbstractClient *_client, TabSupervisor *_tabSuperviso ...@@ -68,20 +66,14 @@ GameSelector::GameSelector(AbstractClient *_client, TabSupervisor *_tabSuperviso
setMinimumWidth((qreal) (gameListView->columnWidth(0) * gameListModel->columnCount()) / 1.5); setMinimumWidth((qreal) (gameListView->columnWidth(0) * gameListModel->columnCount()) / 1.5);
setMinimumHeight(200); setMinimumHeight(200);
connect(showFullGamesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(showFullGamesChanged(int))); connect(showUnavailableGamesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(showUnavailableGamesChanged(int)));
connect(showRunningGamesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(showRunningGamesChanged(int)));
connect(joinButton, SIGNAL(clicked()), this, SLOT(actJoin())); connect(joinButton, SIGNAL(clicked()), this, SLOT(actJoin()));
connect(spectateButton, SIGNAL(clicked()), this, SLOT(actJoin())); connect(spectateButton, SIGNAL(clicked()), this, SLOT(actJoin()));
} }
void GameSelector::showFullGamesChanged(int state) void GameSelector::showUnavailableGamesChanged(int state)
{ {
gameListProxyModel->setFullGamesVisible(state); gameListProxyModel->setUnavailableGamesVisible(state);
}
void GameSelector::showRunningGamesChanged(int state)
{
gameListProxyModel->setRunningGamesVisible(state);
} }
void GameSelector::actCreate() void GameSelector::actCreate()
...@@ -152,8 +144,7 @@ void GameSelector::actJoin() ...@@ -152,8 +144,7 @@ void GameSelector::actJoin()
void GameSelector::retranslateUi() void GameSelector::retranslateUi()
{ {
setTitle(tr("Games")); setTitle(tr("Games"));
showFullGamesCheckBox->setText(tr("Show &full games")); showUnavailableGamesCheckBox->setText(tr("Show u&navailable games"));
showRunningGamesCheckBox->setText(tr("Show &running games"));
if (createButton) if (createButton)
createButton->setText(tr("C&reate")); createButton->setText(tr("C&reate"));
joinButton->setText(tr("&Join")); joinButton->setText(tr("&Join"));
......
...@@ -19,8 +19,7 @@ class ServerInfo_Game; ...@@ -19,8 +19,7 @@ class ServerInfo_Game;
class GameSelector : public QGroupBox { class GameSelector : public QGroupBox {
Q_OBJECT Q_OBJECT
private slots: private slots:
void showFullGamesChanged(int state); void showUnavailableGamesChanged(int state);
void showRunningGamesChanged(int state);
void actCreate(); void actCreate();
void actJoin(); void actJoin();
void checkResponse(Response::ResponseCode response); void checkResponse(Response::ResponseCode response);
...@@ -35,11 +34,11 @@ private: ...@@ -35,11 +34,11 @@ private:
GamesModel *gameListModel; GamesModel *gameListModel;
GamesProxyModel *gameListProxyModel; GamesProxyModel *gameListProxyModel;
QPushButton *createButton, *joinButton, *spectateButton; QPushButton *createButton, *joinButton, *spectateButton;
QCheckBox *showFullGamesCheckBox, *showRunningGamesCheckBox; QCheckBox *showUnavailableGamesCheckBox;
public: public:
GameSelector(AbstractClient *_client, TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QWidget *parent = 0); GameSelector(AbstractClient *_client, TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QWidget *parent = 0);
void retranslateUi(); void retranslateUi();
void processGameInfo(const ServerInfo_Game &info); void processGameInfo(const ServerInfo_Game &info);
}; };
#endif #endif
\ No newline at end of file
...@@ -98,21 +98,15 @@ void GamesModel::updateGameList(const ServerInfo_Game &game) ...@@ -98,21 +98,15 @@ void GamesModel::updateGameList(const ServerInfo_Game &game)
endInsertRows(); endInsertRows();
} }
GamesProxyModel::GamesProxyModel(QObject *parent) GamesProxyModel::GamesProxyModel(QObject *parent, ServerInfo_User *_ownUser)
: QSortFilterProxyModel(parent), fullGamesVisible(false) : QSortFilterProxyModel(parent), ownUser(_ownUser), unavailableGamesVisible(false)
{ {
setDynamicSortFilter(true); setDynamicSortFilter(true);
} }
void GamesProxyModel::setFullGamesVisible(bool _fullGamesVisible) void GamesProxyModel::setUnavailableGamesVisible(bool _unavailableGamesVisible)
{ {
fullGamesVisible = _fullGamesVisible; unavailableGamesVisible = _unavailableGamesVisible;
invalidateFilter();
}
void GamesProxyModel::setRunningGamesVisible(bool _runningGamesVisible)
{
runningGamesVisible = _runningGamesVisible;
invalidateFilter(); invalidateFilter();
} }
...@@ -123,10 +117,15 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sourc ...@@ -123,10 +117,15 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sourc
return false; return false;
const ServerInfo_Game &game = model->getGame(sourceRow); const ServerInfo_Game &game = model->getGame(sourceRow);
if ((game.player_count() == game.max_players()) && !fullGamesVisible) if (!unavailableGamesVisible) {
return false; if (game.player_count() == game.max_players())
if (game.started() && !runningGamesVisible) return false;
return false; if (game.started())
return false;
if (!(ownUser->user_level() & ServerInfo_User::IsRegistered))
if (game.only_registered())
return false;
}
return true; return true;
} }
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "gametypemap.h" #include "gametypemap.h"
class ServerInfo_Game; class ServerInfo_Game;
class ServerInfo_User;
class GamesModel : public QAbstractTableModel { class GamesModel : public QAbstractTableModel {
Q_OBJECT Q_OBJECT
...@@ -29,12 +30,11 @@ public: ...@@ -29,12 +30,11 @@ public:
class GamesProxyModel : public QSortFilterProxyModel { class GamesProxyModel : public QSortFilterProxyModel {
Q_OBJECT Q_OBJECT
private: private:
bool fullGamesVisible; ServerInfo_User *ownUser;
bool runningGamesVisible; bool unavailableGamesVisible;
public: public:
GamesProxyModel(QObject *parent = 0); GamesProxyModel(QObject *parent = 0, ServerInfo_User *_ownUser = 0);
void setFullGamesVisible(bool _fullGamesVisible); void setUnavailableGamesVisible(bool _unavailableGamesVisible);
void setRunningGamesVisible(bool _runningGamesVisible);
protected: protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
}; };
......
...@@ -25,8 +25,8 @@ ...@@ -25,8 +25,8 @@
#include "pb/event_room_say.pb.h" #include "pb/event_room_say.pb.h"
#include "pending_command.h" #include "pending_command.h"
TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, const QString &_ownName, const ServerInfo_Room &info) TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, ServerInfo_User *_ownUser, const ServerInfo_Room &info)
: Tab(_tabSupervisor), client(_client), roomId(info.room_id()), roomName(QString::fromStdString(info.name())), ownName(_ownName) : Tab(_tabSupervisor), client(_client), roomId(info.room_id()), roomName(QString::fromStdString(info.name())), ownUser(_ownUser)
{ {
const int gameTypeListSize = info.gametype_list_size(); const int gameTypeListSize = info.gametype_list_size();
for (int i = 0; i < gameTypeListSize; ++i) for (int i = 0; i < gameTypeListSize; ++i)
...@@ -38,7 +38,7 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q ...@@ -38,7 +38,7 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
userList = new UserList(tabSupervisor, client, UserList::RoomList); userList = new UserList(tabSupervisor, client, UserList::RoomList);
connect(userList, SIGNAL(openMessageDialog(const QString &, bool)), this, SIGNAL(openMessageDialog(const QString &, bool))); connect(userList, SIGNAL(openMessageDialog(const QString &, bool)), this, SIGNAL(openMessageDialog(const QString &, bool)));
chatView = new ChatView(ownName, true); chatView = new ChatView(QString::fromStdString(ownUser->name()), true);
connect(chatView, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString))); connect(chatView, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString)));
connect(chatView, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString))); connect(chatView, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString)));
sayLabel = new QLabel; sayLabel = new QLabel;
......
...@@ -23,6 +23,7 @@ class Event_RoomSay; ...@@ -23,6 +23,7 @@ class Event_RoomSay;
class GameSelector; class GameSelector;
class Response; class Response;
class PendingCommand; class PendingCommand;
class ServerInfo_User;
class TabRoom : public Tab { class TabRoom : public Tab {
Q_OBJECT Q_OBJECT
...@@ -30,7 +31,7 @@ private: ...@@ -30,7 +31,7 @@ private:
AbstractClient *client; AbstractClient *client;
int roomId; int roomId;
QString roomName; QString roomName;
QString ownName; ServerInfo_User *ownUser;
QMap<int, QString> gameTypes; QMap<int, QString> gameTypes;
GameSelector *gameSelector; GameSelector *gameSelector;
...@@ -55,7 +56,7 @@ private slots: ...@@ -55,7 +56,7 @@ private slots:
void processLeaveRoomEvent(const Event_LeaveRoom &event); void processLeaveRoomEvent(const Event_LeaveRoom &event);
void processRoomSayEvent(const Event_RoomSay &event); void processRoomSayEvent(const Event_RoomSay &event);
public: public:
TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, const QString &_ownName, const ServerInfo_Room &info); TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, ServerInfo_User *_ownUser, const ServerInfo_Room &info);
~TabRoom(); ~TabRoom();
void retranslateUi(); void retranslateUi();
void closeRequest(); void closeRequest();
......
...@@ -273,7 +273,7 @@ void TabSupervisor::gameLeft(TabGame *tab) ...@@ -273,7 +273,7 @@ void TabSupervisor::gameLeft(TabGame *tab)
void TabSupervisor::addRoomTab(const ServerInfo_Room &info, bool setCurrent) void TabSupervisor::addRoomTab(const ServerInfo_Room &info, bool setCurrent)
{ {
TabRoom *tab = new TabRoom(this, client, QString::fromStdString(userInfo->name()), info); TabRoom *tab = new TabRoom(this, client, userInfo, info);
connect(tab, SIGNAL(roomClosing(TabRoom *)), this, SLOT(roomLeft(TabRoom *))); connect(tab, SIGNAL(roomClosing(TabRoom *)), this, SLOT(roomLeft(TabRoom *)));
connect(tab, SIGNAL(openMessageDialog(const QString &, bool)), this, SLOT(addMessageTab(const QString &, bool))); connect(tab, SIGNAL(openMessageDialog(const QString &, bool)), this, SLOT(addMessageTab(const QString &, bool)));
int tabIndex = myAddTab(tab); int tabIndex = myAddTab(tab);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment