mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-24 23:53:54 -07:00
tell logged in clients about new replays
This commit is contained in:
parent
2487476fcc
commit
a876a0bf5f
14 changed files with 95 additions and 11 deletions
|
|
@ -14,6 +14,7 @@
|
|||
#include "pb/event_user_joined.pb.h"
|
||||
#include "pb/event_user_left.pb.h"
|
||||
#include "pb/event_game_joined.pb.h"
|
||||
#include "pb/event_replay_added.pb.h"
|
||||
#include "get_pb_extension.h"
|
||||
#include <google/protobuf/descriptor.h>
|
||||
|
||||
|
|
@ -55,6 +56,7 @@ void AbstractClient::processProtocolItem(const ServerMessage &item)
|
|||
case SessionEvent::USER_JOINED: emit userJoinedEventReceived(event.GetExtension(Event_UserJoined::ext)); break;
|
||||
case SessionEvent::USER_LEFT: emit userLeftEventReceived(event.GetExtension(Event_UserLeft::ext)); break;
|
||||
case SessionEvent::GAME_JOINED: emit gameJoinedEventReceived(event.GetExtension(Event_GameJoined::ext)); break;
|
||||
case SessionEvent::REPLAY_ADDED: emit replayAddedEventReceived(event.GetExtension(Event_ReplayAdded::ext)); break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ class Event_GameJoined;
|
|||
class Event_UserMessage;
|
||||
class Event_ConnectionClosed;
|
||||
class Event_ServerShutdown;
|
||||
class Event_ReplayAdded;
|
||||
|
||||
enum ClientStatus {
|
||||
StatusDisconnected,
|
||||
|
|
@ -57,6 +58,7 @@ signals:
|
|||
void userInfoChanged(const ServerInfo_User &userInfo);
|
||||
void buddyListReceived(const QList<ServerInfo_User> &buddyList);
|
||||
void ignoreListReceived(const QList<ServerInfo_User> &ignoreList);
|
||||
void replayAddedEventReceived(const Event_ReplayAdded &event);
|
||||
private:
|
||||
int nextCmdId;
|
||||
protected slots:
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ RemoteReplayList_TreeModel::MatchNode::MatchNode(const ServerInfo_ReplayMatch &_
|
|||
: RemoteReplayList_TreeModel::Node(QString::fromStdString(_matchInfo.game_name())), matchInfo(_matchInfo)
|
||||
{
|
||||
for (int i = 0; i < matchInfo.replay_list_size(); ++i)
|
||||
append(new ReplayNode(matchInfo.replay_list(i)));
|
||||
append(new ReplayNode(matchInfo.replay_list(i), this));
|
||||
}
|
||||
|
||||
RemoteReplayList_TreeModel::MatchNode::~MatchNode()
|
||||
|
|
@ -200,6 +200,15 @@ void RemoteReplayList_TreeModel::refreshTree()
|
|||
client->sendCommand(pend);
|
||||
}
|
||||
|
||||
void RemoteReplayList_TreeModel::addMatchInfo(const ServerInfo_ReplayMatch &matchInfo)
|
||||
{
|
||||
beginInsertRows(QModelIndex(), replayMatches.size(), replayMatches.size());
|
||||
replayMatches.append(new MatchNode(matchInfo));
|
||||
endInsertRows();
|
||||
|
||||
emit treeRefreshed();
|
||||
}
|
||||
|
||||
void RemoteReplayList_TreeModel::replayListFinished(const Response &r)
|
||||
{
|
||||
const Response_ReplayList &resp = r.GetExtension(Response_ReplayList::ext);
|
||||
|
|
@ -236,3 +245,8 @@ ServerInfo_Replay const *RemoteReplayList_TreeWidget::getCurrentReplay() const
|
|||
{
|
||||
return treeModel->getReplay(proxyModel->mapToSource(selectionModel()->currentIndex()));
|
||||
}
|
||||
|
||||
void RemoteReplayList_TreeWidget::addMatchInfo(const ServerInfo_ReplayMatch &matchInfo)
|
||||
{
|
||||
treeModel->addMatchInfo(matchInfo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ private:
|
|||
MatchNode *parent;
|
||||
ServerInfo_Replay replayInfo;
|
||||
public:
|
||||
ReplayNode(const ServerInfo_Replay &_replayInfo, MatchNode *_parent = 0)
|
||||
ReplayNode(const ServerInfo_Replay &_replayInfo, MatchNode *_parent)
|
||||
: Node(QString::fromStdString(_replayInfo.replay_name())), parent(_parent), replayInfo(_replayInfo) { }
|
||||
MatchNode *getParent() const { return parent; }
|
||||
const ServerInfo_Replay &getReplayInfo() { return replayInfo; }
|
||||
|
|
@ -67,6 +67,7 @@ public:
|
|||
void refreshTree();
|
||||
ServerInfo_Replay const* getReplay(const QModelIndex &index) const;
|
||||
ServerInfo_ReplayMatch const* getReplayMatch(const QModelIndex &index) const;
|
||||
void addMatchInfo(const ServerInfo_ReplayMatch &matchInfo);
|
||||
};
|
||||
|
||||
class RemoteReplayList_TreeWidget : public QTreeView {
|
||||
|
|
@ -79,6 +80,7 @@ public:
|
|||
ServerInfo_Replay const *getCurrentReplay() const;
|
||||
ServerInfo_ReplayMatch const *getCurrentReplayMatch() const;
|
||||
void refreshTree();
|
||||
void addMatchInfo(const ServerInfo_ReplayMatch &matchInfo);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
#include "pb/response.pb.h"
|
||||
#include "pb/response_replay_download.pb.h"
|
||||
#include "pb/command_replay_download.pb.h"
|
||||
#include "pb/event_replay_added.pb.h"
|
||||
|
||||
TabReplays::TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client)
|
||||
: Tab(_tabSupervisor), client(_client)
|
||||
|
|
@ -90,6 +91,8 @@ TabReplays::TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client)
|
|||
|
||||
retranslateUi();
|
||||
setLayout(hbox);
|
||||
|
||||
connect(client, SIGNAL(replayAddedEventReceived(const Event_ReplayAdded &)), this, SLOT(replayAddedEventReceived(const Event_ReplayAdded &)));
|
||||
}
|
||||
|
||||
void TabReplays::retranslateUi()
|
||||
|
|
@ -183,3 +186,8 @@ void TabReplays::downloadFinished(const Response &r)
|
|||
f.write((const char *) data.data(), data.size());
|
||||
f.close();
|
||||
}
|
||||
|
||||
void TabReplays::replayAddedEventReceived(const Event_ReplayAdded &event)
|
||||
{
|
||||
serverDirView->addMatchInfo(event.match_info());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
#define TAB_REPLAYS_H
|
||||
|
||||
#include "tab.h"
|
||||
#include "pb/response.pb.h"
|
||||
|
||||
class Response;
|
||||
class AbstractClient;
|
||||
class QTreeView;
|
||||
class QFileSystemModel;
|
||||
|
|
@ -12,6 +12,7 @@ class QToolBar;
|
|||
class QGroupBox;
|
||||
class RemoteReplayList_TreeWidget;
|
||||
class GameReplay;
|
||||
class Event_ReplayAdded;
|
||||
|
||||
class TabReplays : public Tab {
|
||||
Q_OBJECT
|
||||
|
|
@ -33,6 +34,8 @@ private slots:
|
|||
|
||||
void actDownload();
|
||||
void downloadFinished(const Response &r);
|
||||
|
||||
void replayAddedEventReceived(const Event_ReplayAdded &event);
|
||||
signals:
|
||||
void openReplay(GameReplay *replay);
|
||||
public:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue