Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions RetroChess.pro
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ SOURCES = RetroChessPlugin.cpp \
gui/validation.cpp \
gui/RetroChessChatWidgetHolder.cpp \
gui/RetroChessSettings.cpp \
gui/RetroChessUserNotify.cpp
gui/RetroChessUserNotify.cpp \
gui/RetroChessLeaderboard.cpp

HEADERS = RetroChessPlugin.h \
services/p3RetroChess.h \
Expand All @@ -66,7 +67,8 @@ HEADERS = RetroChessPlugin.h \
gui/chess.h \
gui/RetroChessChatWidgetHolder.h \
gui/RetroChessSettings.h \
gui/RetroChessUserNotify.h
gui/RetroChessUserNotify.h \
gui/RetroChessLeaderboard.h

FORMS += \
gui/NEMainpage.ui \
Expand Down
46 changes: 45 additions & 1 deletion gui/NEMainpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <algorithm>
#include <string>
#include <QTime>
#include <QDateTime>
#include <QMenu>
#include <QMessageBox>
#include <QToolButton>
Expand All @@ -39,9 +40,12 @@

#include "gui/RetroChessSettings.h"
#include "gui/RetroChessUserNotify.h"
#include "gui/RetroChessLeaderboard.h"

#include "gui/chat/ChatDialog.h"
#include <retroshare/rsidentity.h>
#include <QTableWidget>
#include <QVBoxLayout>


NEMainpage::NEMainpage(QWidget *parent, RetroChessNotify *notify) :
Expand All @@ -50,9 +54,23 @@ NEMainpage::NEMainpage(QWidget *parent, RetroChessNotify *notify) :
mNotify(notify),
mOfficialLobbyTimer(new QTimer(this)),
mOfficialLobbyDialog(nullptr),
mLobbyUnreadCount(0)
mLobbyUnreadCount(0),
mLeaderboard(new RetroChessLeaderboard(this)),
mLeaderboardTable(new QTableWidget(this)),
mLeaderboardInfo(nullptr)
{
ui->setupUi(this);
QWidget *leaderboardPage = new QWidget(ui->tabWidget);
QVBoxLayout *leaderboardLayout = new QVBoxLayout(leaderboardPage);
mLeaderboardInfo = new QLabel(
tr("Standard Glicko-2 rating. A game is counted after both players publish the same signed result."),
leaderboardPage);
mLeaderboardInfo->setWordWrap(true);
leaderboardLayout->addWidget(mLeaderboardInfo);
leaderboardLayout->addWidget(mLeaderboardTable);
ui->tabWidget->insertTab(1, leaderboardPage, tr("Leaderboard"));
connect(mLeaderboard, SIGNAL(changed()), this, SLOT(refreshLeaderboard()));
refreshLeaderboard();
setupMenuActions();

connect(mNotify, SIGNAL(NeMsgArrived(RsPeerId,QString)), this, SLOT(NeMsgArrived(RsPeerId,QString)));
Expand All @@ -64,6 +82,8 @@ NEMainpage::NEMainpage(QWidget *parent, RetroChessNotify *notify) :
connect(mNotify, SIGNAL(chessPlayerLeftGxs(RsGxsId)), this, SLOT(chessPlayerLeftGxs(RsGxsId)));
connect(mNotify, SIGNAL(chessRematchGxs(RsGxsId,int)), this, SLOT(chessRematchGxs(RsGxsId,int)));
connect(mNotify, SIGNAL(chessGameActionGxs(RsGxsId,QString)), this, SLOT(chessGameActionGxs(RsGxsId,QString)));
connect(mNotify, SIGNAL(ratedResultGxs(RsGxsId,QString,RsGxsId,RsGxsId,QString,qint64)),
this, SLOT(ratedResultGxs(RsGxsId,QString,RsGxsId,RsGxsId,QString,qint64)));

connect(mOfficialLobbyTimer, SIGNAL(timeout()), this, SLOT(autoJoinOfficialLobby()));
mOfficialLobbyTimer->setInterval(15000);
Expand Down Expand Up @@ -179,6 +199,16 @@ void NEMainpage::officialLobbyNewMessage(ChatWidget *)
emit lobbyUnreadCountChanged();
}

void NEMainpage::refreshLeaderboard()
{
mLeaderboard->populate(mLeaderboardTable);
const RsGxsGroupId groupId = mLeaderboard->ledgerGroupId();
mLeaderboardInfo->setText(groupId.isNull()
? tr("Searching for the distributed RetroChess leaderboard GXS group…")
: tr("Synchronized GXS ledger: %1 — games count after both signed results match.")
.arg(QString::fromStdString(groupId.toStdString())));
}

void NEMainpage::showEvent(QShowEvent *event)
{
if (mLobbyUnreadCount) {
Expand Down Expand Up @@ -245,6 +275,7 @@ void NEMainpage::removeActiveGameListing(QString gameId)

void NEMainpage::requestRematchGxs(const RsGxsId &gxs_id, int localColor)
{
rsRetroChess->startNewGameIdForPeer(gxs_id);
if (!rsRetroChess->sendRematchGxs(gxs_id, localColor))
return;

Expand Down Expand Up @@ -284,6 +315,12 @@ void NEMainpage::chessGameActionGxs(const RsGxsId &gxs_id, QString action)
activeGames.value(key)->applyGameAction(action, true);
}

void NEMainpage::ratedResultGxs(RsGxsId signer, QString gameId, RsGxsId white,
RsGxsId black, QString result, qint64 finishedAt)
{
mLeaderboard->receiveResult(signer, gameId, white, black, result, finishedAt);
}

// decode received message here
void NEMainpage::NeMsgArrived(const RsPeerId &peer_id, QString str)
{
Expand Down Expand Up @@ -428,6 +465,13 @@ void NEMainpage::create_chess_window_gxs(const RsGxsId &gxs_id, int player_id)
this, SLOT(requestRematchGxs(RsGxsId,int)));
connect(win, SIGNAL(gameClosed(QString)), this, SLOT(removeActiveGame(QString)));
connect(win, SIGNAL(gameEnded(QString)), this, SLOT(removeActiveGameListing(QString)));
connect(win, &RetroChessWindow::ratedResult, this,
[this, gxs_id](const QString &gameId, const RsGxsId &white,
const RsGxsId &black, const QString &result) {
mLeaderboard->submitResult(gameId, white, black, result);
rsRetroChess->sendRatedResultGxs(gxs_id, gameId, white, black, result,
QDateTime::currentSecsSinceEpoch());
});
win->show();

// Track the game so GXS moves can be routed to it
Expand Down
9 changes: 9 additions & 0 deletions gui/NEMainpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class ChatDialog;
class ChatWidget;
class UserNotify;
class QShowEvent;
class QTableWidget;
class QLabel;
class RetroChessLeaderboard;

namespace Ui
{
Expand Down Expand Up @@ -72,18 +75,24 @@ private slots:
void chessPlayerLeftGxs(const RsGxsId &gxs_id);
void chessRematchGxs(const RsGxsId &gxs_id, int remoteColor);
void chessGameActionGxs(const RsGxsId &gxs_id, QString action);
void ratedResultGxs(RsGxsId signer, QString gameId, RsGxsId white,
RsGxsId black, QString result, qint64 finishedAt);
void requestRematchGxs(const RsGxsId &gxs_id, int localColor);
void requestRematchPeer(QString peerId, int localColor);
void removeActiveGame(QString gameId);
void removeActiveGameListing(QString gameId);
void autoJoinOfficialLobby();
void officialLobbyNewMessage(ChatWidget *chatWidget);
void refreshLeaderboard();
private:
Ui::NEMainpage *ui;
RetroChessNotify *mNotify;
QTimer *mOfficialLobbyTimer;
ChatDialog *mOfficialLobbyDialog;
unsigned int mLobbyUnreadCount;
RetroChessLeaderboard *mLeaderboard;
QTableWidget *mLeaderboardTable;
QLabel *mLeaderboardInfo;

QMap<std::string, RetroChessWindow*> activeGames;
void create_chess_window(std::string peer_id, int player_id);
Expand Down
Loading