├── gui ├── images │ ├── chess.png │ ├── profile.png │ ├── chess-icon.png │ ├── retrochess.png │ ├── chess-icon-32.png │ ├── chess-notify.png │ ├── chess.svg │ ├── chess-notify.svg │ ├── rook_black.svg │ ├── pawn_black.svg │ ├── rook_white.svg │ ├── pawn_white.svg │ ├── knight_black.svg │ ├── bishop_black.svg │ ├── knight_white.svg │ ├── bishop_white.svg │ ├── king_black.svg │ ├── queen_white.svg │ ├── queen_black.svg │ └── king_white.svg ├── validation.h ├── validation.cpp ├── RetroChess_images.qrc ├── tile.h ├── RetroChessNotify.cpp ├── RetroChessChatWidgetHolder.h ├── NEMainpage.h ├── chess.h ├── RetroChessNotify.h ├── tile.cpp ├── RetroChessChatWidgetHolder.cpp ├── chess.ui ├── NEMainpage.cpp ├── NEMainpage.ui └── chess.cpp ├── docs ├── TODO_List.md ├── Issues.md └── Tips.md ├── cptest ├── rename_plugin.sh ├── README.txt ├── RetroChess.pro ├── interface └── rsRetroChess.h ├── RetroChessPlugin.h ├── services ├── p3RetroChess.h ├── rsRetroChessItems.h ├── rsRetroChessItems.cc └── p3RetroChess.cc └── RetroChessPlugin.cpp /gui/images/chess.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RetroChess/master/gui/images/chess.png -------------------------------------------------------------------------------- /gui/images/profile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RetroChess/master/gui/images/profile.png -------------------------------------------------------------------------------- /gui/images/chess-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RetroChess/master/gui/images/chess-icon.png -------------------------------------------------------------------------------- /gui/images/retrochess.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RetroChess/master/gui/images/retrochess.png -------------------------------------------------------------------------------- /gui/images/chess-icon-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RetroChess/master/gui/images/chess-icon-32.png -------------------------------------------------------------------------------- /gui/images/chess-notify.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RetroChess/master/gui/images/chess-notify.png -------------------------------------------------------------------------------- /docs/TODO_List.md: -------------------------------------------------------------------------------- 1 | # TODO List: 2 | 3 | 1. modify gui: Tile(convert to QGraphicsItem), ChessBoard as QGraphicsView 4 | 5 | 2. 6 | 7 | 8 | -------------------------------------------------------------------------------- /cptest: -------------------------------------------------------------------------------- 1 | kdesudo -u retrotester cp lib*.so* /home/retrotester/.retroshare/extensions6/ 2 | kdesudo -u retrotester /home/chozabu/git/RetroShare/retroshare-gui/src/RetroShare 3 | 4 | -------------------------------------------------------------------------------- /gui/validation.h: -------------------------------------------------------------------------------- 1 | #ifndef VALIDATION_H 2 | #define VALIDATION_H 3 | #include "tile.h" 4 | 5 | 6 | class validation 7 | { 8 | 9 | int *tile; 10 | 11 | public: 12 | validation(); 13 | }; 14 | 15 | #endif // VALIDATION_H 16 | -------------------------------------------------------------------------------- /gui/validation.cpp: -------------------------------------------------------------------------------- 1 | #include "validation.h" 2 | #include 3 | #include "string" 4 | #include "chess.h" 5 | 6 | 7 | 8 | validation::validation() 9 | { 10 | //Nothing here 11 | // tile = ((RetroChessWindow*)parentWidget())->tile; 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /rename_plugin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | newname=$1 3 | oldname="RetroChess" 4 | echo "$newname" 5 | echo "$oldname" 6 | find . -not -path '*/\.*' -type f -print0 | xargs -0 sed -i "s/$oldname/$newname/g" 7 | #find . -type f -exec rename "s/$oldname/$newname/' '{}" \; 8 | find . | sed -e "p;s/$oldname/$newname/" | xargs -n2 git mv 9 | 10 | echo "now change 0xb00b5 in services/*items.h to a unique value of your choice to identify your plugin!" 11 | -------------------------------------------------------------------------------- /docs/Issues.md: -------------------------------------------------------------------------------- 1 | # some issues of RetroChess : 2 | 3 | 1. you can start a game without the friend accepted (not allow). 4 | 2. disable invite button when friend has no chess installed/running 5 | 3. when leave chess, feature to send info to friend that he leaved chess on Chat window or Chess Window... 6 | 4. on Chess maindow it shows the active games, maybe remove leaved ones 7 | 5. i can move friends chess figures not allow 8 | 6. chess window is not realy optimized to big to much wasted spaces 9 | 7. seems the timer doesnt works 10 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | RS .6 Chess Plugin 2 | ================== 3 | 4 | Both players must currently select each other and press "play game" - ensure your friend has their chess window open before making a move! 5 | 6 | 7 | this is a combination of an existing chess game, and the exampleplugin (rename script makes it easy to use as base for new plugin) 8 | https://github.com/RetroShare/ExampleRSPlugin 9 | 10 | 11 | --disclaimer-- 12 | may not support playing more than one game of chess 13 | may crash RS 14 | may kill your cat, dog, or other loved one. 15 | 16 | 17 | --extra info-- 18 | based on: https://github.com/chozabu/CHESS-in-Qt 19 | -------------------------------------------------------------------------------- /docs/Tips.md: -------------------------------------------------------------------------------- 1 | # tips: 2 | Cyril tips: 3 | 22:47 Cyril: I'm going to leave, but here's a few tips: 4 | 22:47 Cyril: - replace the friend list by a GxsId list. There's a widget for that in GUI already. See the one that is used in the message composer window. 5 | 22:48 Cyril: - when openning a game, request a tunnel to RsGxstunnel. As soon as the tunnel is open, notify the UI and start the game. Use the tunnel to send/serialize the chess data items 6 | 22:49 defnax: normaly let option play with direct or distant people 7 | 22:49 Cyril: well, it's probably simpler to do everything with GxsIds rather than attempting to manage the two kinds of ids at the same time 8 | -------------------------------------------------------------------------------- /gui/RetroChess_images.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/bishop_black.svg 4 | images/bishop_white.svg 5 | images/king_black.svg 6 | images/king_white.svg 7 | images/knight_black.svg 8 | images/knight_white.svg 9 | images/pawn_black.svg 10 | images/pawn_white.svg 11 | images/queen_black.svg 12 | images/queen_white.svg 13 | images/rook_black.svg 14 | images/rook_white.svg 15 | images/chess-icon.png 16 | images/chess-icon-32.png 17 | images/chess.png 18 | images/profile.png 19 | images/retrochess.png 20 | 21 | 22 | -------------------------------------------------------------------------------- /gui/tile.h: -------------------------------------------------------------------------------- 1 | #ifndef TILE_H 2 | #define TILE_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class Tile: public QLabel 9 | { 10 | public: 11 | //Constructors 12 | Tile(QWidget* pParent=0, Qt::WindowFlags f=0); 13 | Tile(const QString& text, QWidget* pParent = 0, Qt::WindowFlags f = 0); 14 | 15 | //Methods 16 | protected: 17 | void mousePressEvent(QMouseEvent *event); 18 | 19 | public: 20 | void display(char elem); 21 | void tileDisplay(); 22 | void validate(int c); 23 | 24 | void setChessWindow( const QWidget *board); 25 | const QWidget* getChessWindow() const; 26 | 27 | //Fields 28 | int tileColor,piece,pieceColor,row,col,tileNum; 29 | char pieceName; 30 | 31 | private: 32 | const QWidget *m_chess_window; //parent board 33 | }; 34 | 35 | void validate_tile(int row, int col, int c); 36 | 37 | #endif // TILE_H 38 | -------------------------------------------------------------------------------- /gui/RetroChessNotify.cpp: -------------------------------------------------------------------------------- 1 | #include "RetroChessNotify.h" 2 | 3 | RetroChessNotify::RetroChessNotify(QObject *parent) : QObject(parent) 4 | { 5 | 6 | } 7 | 8 | void RetroChessNotify::notifyReceivedPaint(const RsPeerId &peer_id, int x, int y) 9 | { 10 | std::cout << "pNotify Recvd paint from: " << peer_id; 11 | std::cout << " at " << x << " , " << y; 12 | std::cout << std::endl; 13 | } 14 | 15 | 16 | void RetroChessNotify::notifyReceivedMsg(const RsPeerId& peer_id, QString str) 17 | { 18 | std::cout << "pNotify Recvd Packet from: " << peer_id; 19 | std::cout << " saying " << str.toStdString(); 20 | std::cout << std::endl; 21 | emit NeMsgArrived(peer_id, str) ; 22 | } 23 | 24 | void RetroChessNotify::notifyChessStart(const RsPeerId &peer_id) 25 | { 26 | emit chessStart(peer_id) ; 27 | 28 | } 29 | void RetroChessNotify::notifyChessInvite(const RsPeerId &peer_id) 30 | { 31 | emit chessInvited(peer_id) ; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /gui/RetroChessChatWidgetHolder.h: -------------------------------------------------------------------------------- 1 | #ifndef RETROCHESSCHATWIDGETHOLDER_H 2 | #define RETROCHESSCHATWIDGETHOLDER_H 3 | 4 | #include "RetroChessChatWidgetHolder.h" 5 | #include 6 | #include 7 | #include 8 | 9 | class RetroChessChatWidgetHolder : public QObject, public ChatWidgetHolder 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | RetroChessChatWidgetHolder(ChatWidget *chatWidget, RetroChessNotify *notify); 15 | virtual ~RetroChessChatWidgetHolder(); 16 | 17 | public slots: 18 | void chessPressed(); 19 | void chessStart(); 20 | void chessnotify(RsPeerId from_peer_id); 21 | 22 | 23 | private slots: 24 | void botMouseEnter(); 25 | void botMouseLeave(); 26 | 27 | protected: 28 | QToolButton *playChessButton ; 29 | RetroChessNotify *mRetroChessNotify; 30 | 31 | typedef QMap button_map; 32 | button_map buttonMapTakeChess; 33 | }; 34 | 35 | #endif // RETROCHESSCHATWIDGETHOLDER_H 36 | -------------------------------------------------------------------------------- /gui/NEMainpage.h: -------------------------------------------------------------------------------- 1 | /* This is the main page displayed by the plugin 2 | * 3 | * For: 4 | * event handle 5 | * peer check 6 | * game launching 7 | */ 8 | 9 | #ifndef NEMAINPAGE_H 10 | #define NEMAINPAGE_H 11 | 12 | #include 13 | #include 14 | #include 15 | #include "gui/RetroChessNotify.h" 16 | 17 | #include "gui/chess.h" 18 | 19 | #include 20 | 21 | class QAction; 22 | 23 | namespace Ui { 24 | class NEMainpage; 25 | } 26 | 27 | class NEMainpage : public MainPage 28 | { 29 | Q_OBJECT 30 | 31 | public: 32 | explicit NEMainpage(QWidget *parent, RetroChessNotify *notify); 33 | ~NEMainpage(); 34 | 35 | private slots: 36 | void setupMenuActions(); 37 | void friendSelectionChanged(); 38 | void on_pingAllButton_clicked(); 39 | void NeMsgArrived(const RsPeerId &peer_id, QString str); 40 | void chessStart(const RsPeerId &peer_id); 41 | 42 | void on_broadcastButton_clicked(); 43 | 44 | void on_playButton_clicked(); 45 | 46 | void on_filterPeersButton_clicked(); 47 | 48 | private: 49 | Ui::NEMainpage *ui; 50 | RetroChessNotify *mNotify; 51 | 52 | QAction *mActionPlayChess; 53 | //RetroChessWindow *tempwindow; 54 | 55 | QMap activeGames; 56 | void create_chess_window(std::string peer_id, int player_id); 57 | }; 58 | 59 | #endif // NEMAINPAGE_H 60 | -------------------------------------------------------------------------------- /gui/chess.h: -------------------------------------------------------------------------------- 1 | #ifndef CHESS_H 2 | #define CHESS_H 3 | 4 | #include "tile.h" 5 | #include "validation.h" 6 | 7 | #include 8 | 9 | #include "retroshare/rspeers.h" 10 | 11 | namespace Ui 12 | { 13 | class RetroChessWindow; 14 | }; 15 | 16 | class RetroChessWindow : public QWidget 17 | { 18 | Q_OBJECT 19 | 20 | private: 21 | Ui::RetroChessWindow *m_ui; //ui 22 | 23 | void initAccessories(); 24 | void initChessBoard(); 25 | RsPeerId p1id; 26 | RsPeerId p2id; 27 | std::string p1name; 28 | std::string p2name; 29 | 30 | public: 31 | std::string mPeerId; 32 | explicit RetroChessWindow(std::string peerid, int player = 0, QWidget *parent = 0); 33 | ~RetroChessWindow(); 34 | int currentplayer; 35 | int myid; 36 | 37 | //from global 38 | 39 | int wR,wC,bR,bC; 40 | Tile *click1; 41 | 42 | Tile *tile[8][8]; 43 | 44 | int count,turn,max; 45 | int *texp; 46 | 47 | 48 | void disOrange(); 49 | void validate_tile(int row, int col, int c); 50 | 51 | 52 | int flag,retVal; 53 | int chooser(Tile *temp); 54 | int validateBishop(Tile *temp); 55 | int validateQueen(Tile *temp); 56 | int validateKing(Tile *temp); 57 | int validateHorse(Tile *temp); 58 | int validateRook(Tile *temp); 59 | int validatePawn(Tile *temp); 60 | void orange(); // draw orange background represent avaiable movement of tiles 61 | int check(Tile *temp); 62 | }; 63 | 64 | 65 | extern QWidget* make_board(); 66 | 67 | #endif // CHESS_H 68 | -------------------------------------------------------------------------------- /RetroChess.pro: -------------------------------------------------------------------------------- 1 | !include("../Common/retroshare_plugin.pri"): error("Could not include file ../Common/retroshare_plugin.pri") 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4) { 4 | # Qt 5 5 | QT += widgets 6 | } 7 | 8 | exists($$[QMAKE_MKSPECS]/features/mobility.prf) { 9 | CONFIG += mobility 10 | } else { 11 | QT += multimedia 12 | } 13 | CONFIG += qt uic qrc resources 14 | MOBILITY = multimedia 15 | 16 | DEPENDPATH += ../../retroshare-gui/src/temp/ui ../../libretroshare/src 17 | INCLUDEPATH += ../../retroshare-gui/src/temp/ui ../../libretroshare/src 18 | INCLUDEPATH += ../../retroshare-gui/src/retroshare-gui 19 | 20 | INCLUDEPATH += ../../rapidjson-1.1.0 21 | 22 | #################################### Windows ##################################### 23 | 24 | linux-* { 25 | #INCLUDEPATH += /usr/include 26 | #LIBS += $$system(pkg-config --libs opencv) 27 | } 28 | 29 | win32 { 30 | LIBS_DIR = $$PWD/../../../libs 31 | #LIBS += -L"$$LIBS_DIR/lib/opencv" 32 | 33 | #OPENCV_VERSION = 249 34 | #LIBS += -lopencv_core$$OPENCV_VERSION -lopencv_highgui$$OPENCV_VERSION -lopencv_imgproc$$OPENCV_VERSION -llibjpeg -llibtiff -llibpng -llibjasper -lIlmImf -lole32 -loleaut32 -luuid -lavicap32 -lavifil32 -lvfw32 -lz 35 | } 36 | 37 | QMAKE_CXXFLAGS *= -Wall 38 | 39 | SOURCES = RetroChessPlugin.cpp \ 40 | services/p3RetroChess.cc \ 41 | services/rsRetroChessItems.cc \ 42 | gui/NEMainpage.cpp \ 43 | gui/RetroChessNotify.cpp \ 44 | gui/chess.cpp \ 45 | gui/tile.cpp \ 46 | gui/validation.cpp \ 47 | gui/RetroChessChatWidgetHolder.cpp 48 | 49 | HEADERS = RetroChessPlugin.h \ 50 | services/p3RetroChess.h \ 51 | services/rsRetroChessItems.h \ 52 | interface/rsRetroChess.h \ 53 | gui/NEMainpage.h \ 54 | gui/RetroChessNotify.h \ 55 | gui/tile.h \ 56 | gui/validation.h \ 57 | gui/chess.h \ 58 | gui/RetroChessChatWidgetHolder.h 59 | 60 | #FORMS = gui/AudioInputConfig.ui 61 | 62 | TARGET = RetroChess 63 | 64 | RESOURCES = gui/RetroChess_images.qrc 65 | 66 | 67 | #LIBS += -lspeex -lspeexdsp 68 | 69 | FORMS += \ 70 | gui/NEMainpage.ui \ 71 | gui/chess.ui 72 | -------------------------------------------------------------------------------- /gui/RetroChessNotify.h: -------------------------------------------------------------------------------- 1 | /**************************************************************** 2 | * RetroShare is distributed under the following license: 3 | * 4 | * Copyright (C) 2015 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301, USA. 20 | ****************************************************************/ 21 | 22 | // This class is a Qt object to get notification from the plugin's service threads, 23 | // and responsible to pass the info the the GUI part. 24 | // 25 | // Because the GUI part is async-ed with the service, it is crucial to use the 26 | // QObject connect system to communicate between the p3Service and the gui part (handled by Qt) 27 | // 28 | #ifndef NETEXAMPLENOTIFY_H 29 | #define NETEXAMPLENOTIFY_H 30 | 31 | #include 32 | 33 | #include 34 | 35 | class RetroChessNotify : public QObject 36 | { 37 | Q_OBJECT 38 | public: 39 | explicit RetroChessNotify(QObject *parent = 0); 40 | void notifyReceivedPaint(const RsPeerId &peer_id, int x, int y) ; 41 | void notifyReceivedMsg(const RsPeerId &peer_id, QString str) ; 42 | void notifyChessStart(const RsPeerId &peer_id) ; 43 | void notifyChessInvite(const RsPeerId &peer_id) ; 44 | 45 | signals: 46 | void NeMsgArrived(const RsPeerId &peer_id, QString str) ; // emitted when the peer gets a msg 47 | 48 | void chessStart(const RsPeerId &peer_id) ; 49 | void chessInvited(const RsPeerId &peer_id) ; 50 | 51 | public slots: 52 | }; 53 | 54 | #endif // NETEXAMPLENOTIFY_H 55 | -------------------------------------------------------------------------------- /interface/rsRetroChess.h: -------------------------------------------------------------------------------- 1 | /* this is a simple class to make it easy for any part of the plugin to call its services */ 2 | /**************************************************************** 3 | * RetroShare is distributed under the following license: 4 | * 5 | * Copyright (C) 2015 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 | * Boston, MA 02110-1301, USA. 21 | ****************************************************************/ 22 | 23 | // interface class for p3RetroChess service 24 | // 25 | 26 | #pragma once 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | class RsRetroChess ; 38 | extern RsRetroChess *rsRetroChess; 39 | 40 | static const uint32_t CONFIG_TYPE_RetroChess_PLUGIN = 0xe001 ; 41 | 42 | class RsRetroChess 43 | { 44 | public: 45 | 46 | virtual void ping_all() = 0; 47 | virtual void broadcast_paint(int x, int y) = 0; 48 | virtual void msg_all(std::string msg) = 0; 49 | virtual void chess_click(std::string peer_id, int col, int row, int count) = 0; 50 | virtual void qvm_msg_peer(RsPeerId peerID, QVariantMap data) = 0; 51 | virtual void str_msg_peer(RsPeerId peerID, QString strdata) = 0; 52 | virtual void raw_msg_peer(RsPeerId peerID, std::string msg) = 0; 53 | virtual bool hasInviteFrom(RsPeerId peerID) = 0; 54 | virtual bool hasInviteTo(RsPeerId peerID) = 0; 55 | virtual void acceptedInvite(RsPeerId peerID) = 0; 56 | virtual void gotInvite(RsPeerId peerID) = 0; 57 | virtual void sendInvite(RsPeerId peerID) = 0; 58 | }; 59 | 60 | 61 | -------------------------------------------------------------------------------- /RetroChessPlugin.h: -------------------------------------------------------------------------------- 1 | /* this is the central part of the plugin */ 2 | /**************************************************************** 3 | * RetroShare is distributed under the following license: 4 | * 5 | * Copyright (C) 2015 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 | * Boston, MA 02110-1301, USA. 21 | ****************************************************************/ 22 | #pragma once 23 | 24 | /*RetroChess*/ 25 | #include "services/p3RetroChess.h" 26 | 27 | /*libretroshare"*/ 28 | #include 29 | 30 | #include "gui/NEMainpage.h" 31 | 32 | class RetroChessGUIHandler ; 33 | class RetroChessNotify ; 34 | 35 | class RetroChessPlugin: public RsPlugin 36 | { 37 | public: 38 | RetroChessPlugin() ; 39 | virtual ~RetroChessPlugin() {} 40 | 41 | virtual p3Service *p3_service() const ; 42 | virtual uint16_t rs_service_id() const { return RS_SERVICE_TYPE_RetroChess_PLUGIN ; } 43 | //virtual ConfigPage *qt_config_page() const ; 44 | virtual QDialog *qt_about_page() const ; 45 | virtual ChatWidgetHolder *qt_get_chat_widget_holder(ChatWidget *chatWidget) const ; 46 | 47 | virtual QIcon *qt_icon() const; 48 | virtual QTranslator *qt_translator(QApplication *app, const QString& languageCode, const QString& externalDir) const; 49 | virtual void qt_sound_events(SoundEvents &events) const; 50 | 51 | virtual void getPluginVersion(int& major, int& minor, int &build, int& svn_rev) const ; 52 | virtual void setPlugInHandler(RsPluginHandler *pgHandler); 53 | 54 | virtual std::string configurationFileName() const { return "RetroChess.cfg" ; } 55 | 56 | virtual std::string getShortPluginDescription() const ; 57 | virtual std::string getPluginName() const; 58 | virtual void setInterfaces(RsPlugInInterfaces& interfaces); 59 | 60 | //================================== RsPlugin Notify ==================================// 61 | //virtual ToasterNotify *qt_toasterNotify(); 62 | 63 | virtual MainPage *qt_page() const ; 64 | 65 | private: 66 | mutable p3RetroChess *mRetroChess ; 67 | mutable RsPluginHandler *mPlugInHandler; 68 | mutable RsPeers* mPeers; 69 | mutable ConfigPage *config_page ; 70 | mutable QIcon *mIcon; 71 | mutable MainPage* mainpage ; 72 | 73 | RetroChessNotify *mRetroChessNotify ; 74 | RetroChessGUIHandler *mRetroChessGUIHandler ; 75 | }; 76 | 77 | -------------------------------------------------------------------------------- /gui/images/chess.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | image/svg+xml -------------------------------------------------------------------------------- /gui/images/chess-notify.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | image/svg+xml -------------------------------------------------------------------------------- /gui/images/rook_black.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 73 | 74 | -------------------------------------------------------------------------------- /gui/images/pawn_black.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 76 | 77 | -------------------------------------------------------------------------------- /services/p3RetroChess.h: -------------------------------------------------------------------------------- 1 | /* this handles the networking service of this plugin */ 2 | /**************************************************************** 3 | * RetroShare is distributed under the following license: 4 | * 5 | * Copyright (C) 2015 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 | * Boston, MA 02110-1301, USA. 21 | ****************************************************************/ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include "services/rsRetroChessItems.h" 30 | #include "services/p3service.h" 31 | #include "serialiser/rstlvbase.h" 32 | #include "rsitems/rsconfigitems.h" 33 | #include "plugins/rspqiservice.h" 34 | #include 35 | 36 | class p3LinkMgr; 37 | class RetroChessNotify ; 38 | 39 | 40 | 41 | //!The RS VoIP Test service. 42 | /** 43 | * 44 | * This is only used to test Latency for the moment. 45 | */ 46 | 47 | class p3RetroChess: public RsPQIService, public RsRetroChess 48 | // Maybe we inherit from these later - but not needed for now. 49 | //, public p3Config, public pqiMonitor 50 | { 51 | public: 52 | p3RetroChess(RsPluginHandler *cm,RetroChessNotify *); 53 | 54 | /***** overloaded from rsRetroChess *****/ 55 | 56 | 57 | /***** overloaded from p3Service *****/ 58 | /*! 59 | * This retrieves all chat msg items and also (important!) 60 | * processes chat-status items that are in service item queue. chat msg item requests are also processed and not returned 61 | * (important! also) notifications sent to notify base on receipt avatar, immediate status and custom status 62 | * : notifyCustomState, notifyChatStatus, notifyPeerHasNewAvatar 63 | * @see NotifyBase 64 | */ 65 | virtual int tick(); 66 | virtual int status(); 67 | virtual bool recvItem(RsItem *item); 68 | 69 | /*************** pqiMonitor callback ***********************/ 70 | //virtual void statusChange(const std::list &plist); 71 | 72 | 73 | /************* from p3Config *******************/ 74 | virtual RsSerialiser *setupSerialiser() ; 75 | 76 | /*! 77 | * chat msg items and custom status are saved 78 | */ 79 | virtual bool saveList(bool& cleanup, std::list&) ; 80 | virtual bool loadList(std::list& load) ; 81 | virtual std::string configurationFileName() const { return "RetroChess.cfg" ; } 82 | 83 | virtual RsServiceInfo getServiceInfo() ; 84 | 85 | void ping_all(); 86 | 87 | void broadcast_paint(int x, int y); 88 | void msg_all(std::string msg); 89 | void str_msg_peer(RsPeerId peerID, QString strdata); 90 | void raw_msg_peer(RsPeerId peerID, std::string msg); 91 | void qvm_msg_peer(RsPeerId peerID, QVariantMap data); 92 | 93 | void chess_click(std::string peer_id, int col, int row, int count); 94 | //void set_peer(RsPeerId peer); 95 | 96 | bool hasInviteFrom(RsPeerId peerID); 97 | bool hasInviteTo(RsPeerId peerID); 98 | void gotInvite(RsPeerId peerID); 99 | void acceptedInvite(RsPeerId peerID); 100 | void sendInvite(RsPeerId peerID); 101 | private: 102 | 103 | 104 | std::set invitesTo; 105 | std::set invitesFrom; 106 | void handleData(RsRetroChessDataItem*) ; 107 | 108 | RsMutex mRetroChessMtx; 109 | 110 | //RsPeerId mPeerID; 111 | 112 | 113 | static RsTlvKeyValue push_int_value(const std::string& key,int value) ; 114 | static int pop_int_value(const std::string& s) ; 115 | 116 | 117 | RsServiceControl *mServiceControl; 118 | RetroChessNotify *mNotify ; 119 | 120 | }; 121 | -------------------------------------------------------------------------------- /services/rsRetroChessItems.h: -------------------------------------------------------------------------------- 1 | /* this describes the datatypes sent over the network, and how to (de)serialise them */ 2 | /**************************************************************** 3 | * RetroShare is distributed under the following license: 4 | * 5 | * Copyright (C) 2015 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 | * Boston, MA 02110-1301, USA. 21 | ****************************************************************/ 22 | 23 | #pragma once 24 | 25 | /* 26 | * libretroshare/src/serialiser: rsRetroChessItems.h 27 | * 28 | * RetroShare Serialiser. 29 | * 30 | * Copyright 2011 by Robert Fernie. 31 | * 32 | * This library is free software; you can redistribute it and/or 33 | * modify it under the terms of the GNU Library General Public 34 | * License Version 2 as published by the Free Software Foundation. 35 | * 36 | * This library is distributed in the hope that it will be useful, 37 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 38 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 39 | * Library General Public License for more details. 40 | * 41 | * You should have received a copy of the GNU Library General Public 42 | * License along with this library; if not, write to the Free Software 43 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 44 | * USA. 45 | * 46 | * Please report all bugs and problems to "retroshare@lunamutt.com". 47 | * 48 | */ 49 | 50 | #include 51 | 52 | #include "rsitems/rsserviceids.h" 53 | #include "serialiser/rsserial.h" 54 | #include "rsitems/rsitem.h" 55 | 56 | 57 | /**************************************************************************/ 58 | 59 | const uint16_t RS_SERVICE_TYPE_RetroChess_PLUGIN = 0xc4e55; 60 | 61 | const uint8_t RS_PKT_SUBTYPE_RetroChess_DATA = 0x01; 62 | 63 | const uint8_t QOS_PRIORITY_RS_RetroChess = 9 ; 64 | 65 | 66 | class RsRetroChessItem: public RsItem 67 | { 68 | public: 69 | RsRetroChessItem(uint8_t RetroChess_subtype) 70 | : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_RetroChess_PLUGIN,RetroChess_subtype) 71 | { 72 | setPriorityLevel(QOS_PRIORITY_RS_RetroChess) ; 73 | } 74 | 75 | virtual ~RsRetroChessItem() {}; 76 | virtual void clear() {}; 77 | virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) = 0 ; 78 | 79 | virtual bool serialise(void *data,uint32_t& size) = 0 ; // Isn't it better that items can serialise themselves ? 80 | virtual uint32_t serial_size() const = 0 ; // deserialise is handled using a constructor 81 | }; 82 | 83 | 84 | class RsRetroChessDataItem: public RsRetroChessItem 85 | { 86 | public: 87 | RsRetroChessDataItem() :RsRetroChessItem(RS_PKT_SUBTYPE_RetroChess_DATA) {} 88 | RsRetroChessDataItem(void *data,uint32_t size) ; // de-serialization 89 | 90 | virtual bool serialise(void *data,uint32_t& size) ; 91 | virtual uint32_t serial_size() const ; 92 | 93 | virtual ~RsRetroChessDataItem() 94 | { 95 | } 96 | virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); 97 | 98 | uint32_t flags ; 99 | uint32_t data_size ; 100 | std::string m_msg; 101 | }; 102 | 103 | 104 | class RsRetroChessSerialiser: public RsSerialType 105 | { 106 | public: 107 | RsRetroChessSerialiser() 108 | :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_RetroChess_PLUGIN) 109 | { 110 | } 111 | virtual ~RsRetroChessSerialiser() {} 112 | 113 | virtual uint32_t size (RsItem *item) 114 | { 115 | return dynamic_cast(item)->serial_size() ; 116 | } 117 | 118 | virtual bool serialise (RsItem *item, void *data, uint32_t *size) 119 | { 120 | return dynamic_cast(item)->serialise(data,*size) ; 121 | } 122 | virtual RsItem *deserialise(void *data, uint32_t *size); 123 | }; 124 | 125 | /**************************************************************************/ 126 | -------------------------------------------------------------------------------- /gui/images/rook_white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 83 | 84 | -------------------------------------------------------------------------------- /gui/images/pawn_white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 92 | 93 | -------------------------------------------------------------------------------- /gui/tile.cpp: -------------------------------------------------------------------------------- 1 | #include "tile.h" 2 | #include "validation.h" 3 | #include "chess.h" 4 | #include "../interface/rsRetroChess.h" 5 | 6 | validation *valid = new validation(); 7 | 8 | /*extern int count,turn; 9 | extern QWidget *myWidget; 10 | extern Tile *click1; 11 | extern Tile *tile[8][8]; 12 | */ 13 | void validate(Tile *temp,int c); 14 | void disOrange(); 15 | 16 | Tile::Tile(QWidget* pParent, Qt::WindowFlags f) : QLabel(pParent, f) 17 | {} 18 | 19 | Tile::Tile(const QString& text, QWidget* pParent, Qt::WindowFlags f) : QLabel(text, pParent, f) 20 | {} 21 | 22 | void Tile::mousePressEvent(QMouseEvent *event) 23 | { 24 | validate(++((RetroChessWindow*)m_chess_window)->count); 25 | std::string peer_id = ((RetroChessWindow*)m_chess_window)->mPeerId; 26 | rsRetroChess->chess_click(peer_id, this->row,this->col,((RetroChessWindow*)m_chess_window)->count); 27 | } 28 | 29 | void Tile::display(char elem) 30 | { 31 | this->pieceName=elem; 32 | 33 | if(this->pieceColor && this->piece) 34 | { 35 | switch(elem) 36 | { 37 | case 'P': 38 | this->setPixmap(QPixmap(":/images/pawn_white.svg")); 39 | break; 40 | case 'R': 41 | this->setPixmap(QPixmap(":/images/rook_white.svg")); 42 | break; 43 | case 'H': 44 | this->setPixmap(QPixmap(":/images/knight_white.svg")); 45 | break; 46 | case 'K': 47 | this->setPixmap(QPixmap(":/images/king_white.svg")); 48 | break; 49 | case 'Q': 50 | this->setPixmap(QPixmap(":/images/queen_white.svg")); 51 | break; 52 | case 'B': 53 | this->setPixmap(QPixmap(":/images/bishop_white.svg")); 54 | break; 55 | } 56 | } 57 | 58 | else if(this->piece) 59 | { 60 | switch(elem) 61 | { 62 | case 'P': 63 | this->setPixmap(QPixmap(":/images/pawn_black.svg")); 64 | break; 65 | case 'R': 66 | this->setPixmap(QPixmap(":/images/rook_black.svg")); 67 | break; 68 | case 'H': 69 | this->setPixmap(QPixmap(":/images/knight_black.svg")); 70 | break; 71 | case 'K': 72 | this->setPixmap(QPixmap(":/images/king_black.svg")); 73 | break; 74 | case 'Q': 75 | this->setPixmap(QPixmap(":/images/queen_black.svg")); 76 | break; 77 | case 'B': 78 | this->setPixmap(QPixmap(":/images/bishop_black.svg")); 79 | break; 80 | } 81 | } 82 | else 83 | this->clear(); 84 | } 85 | 86 | void Tile::validate(int c) 87 | { 88 | Tile *temp = this; 89 | int retValue,i; 90 | 91 | if(c==1) 92 | { 93 | if(temp->piece && (temp->pieceColor==((RetroChessWindow*)m_chess_window)->turn)) 94 | { 95 | //texp[max++]=temp->tileNum; 96 | retValue=((RetroChessWindow*)m_chess_window)->chooser(temp); 97 | 98 | if(retValue) 99 | { 100 | ((RetroChessWindow*)m_chess_window)->click1= new Tile(); 101 | temp->setStyleSheet("QLabel {background-color: green;}"); 102 | ((RetroChessWindow*)m_chess_window)->click1=temp; 103 | } 104 | else 105 | { 106 | //temp->setStyleSheet("QLabel {background-color: red;}"); 107 | ((RetroChessWindow*)m_chess_window)->count=0; 108 | } 109 | } 110 | else 111 | { 112 | //qDebug()<<"Rascel, clicking anywhere"; 113 | ((RetroChessWindow*)m_chess_window)->count=0; 114 | } 115 | } 116 | 117 | else 118 | { 119 | 120 | if(temp->tileNum==((RetroChessWindow*)m_chess_window)->click1->tileNum) 121 | { 122 | ((RetroChessWindow*)m_chess_window)->click1->tileDisplay(); 123 | ((RetroChessWindow*)m_chess_window)->disOrange(); 124 | ((RetroChessWindow*)m_chess_window)->max=0; 125 | ((RetroChessWindow*)m_chess_window)->count=0; 126 | } 127 | 128 | for(i=0; i<((RetroChessWindow*)m_chess_window)->max; i++) 129 | { 130 | if(temp->tileNum==((RetroChessWindow*)m_chess_window)->texp[i]) 131 | { 132 | ((RetroChessWindow*)m_chess_window)->click1->piece=0; 133 | temp->piece=1; 134 | 135 | temp->pieceColor=((RetroChessWindow*)m_chess_window)->click1->pieceColor; 136 | temp->pieceName=((RetroChessWindow*)m_chess_window)->click1->pieceName; 137 | 138 | ((RetroChessWindow*)m_chess_window)->click1->display(((RetroChessWindow*)m_chess_window)->click1->pieceName); 139 | temp->display(((RetroChessWindow*)m_chess_window)->click1->pieceName); 140 | 141 | ((RetroChessWindow*)m_chess_window)->click1->tileDisplay(); 142 | temp->tileDisplay(); 143 | 144 | retValue=((RetroChessWindow*)m_chess_window)->check(((RetroChessWindow*)m_chess_window)->click1); 145 | /* 146 | if(retValue) 147 | { 148 | tile[wR][wC]->setStyleSheet("QLabel {background-color: red;}"); 149 | } 150 | */ 151 | 152 | ((RetroChessWindow*)m_chess_window)->disOrange(); 153 | 154 | ((RetroChessWindow*)m_chess_window)->max=0; 155 | 156 | ((RetroChessWindow*)m_chess_window)->turn=(((RetroChessWindow*)m_chess_window)->turn+1)%2; 157 | ((RetroChessWindow*)m_chess_window)->count=0; 158 | } 159 | 160 | else 161 | ((RetroChessWindow*)m_chess_window)->count=1; 162 | } 163 | } 164 | } 165 | 166 | void Tile::tileDisplay() 167 | { 168 | 169 | if(this->tileColor) 170 | this->setStyleSheet("QLabel {background-color: rgb(120, 120, 90);}:hover{background-color: rgb(170,85,127);}"); 171 | else 172 | this->setStyleSheet("QLabel {background-color: rgb(211, 211, 158);}:hover{background-color: rgb(170,95,127);}"); 173 | } 174 | 175 | 176 | void Tile::setChessWindow(const QWidget *board) 177 | { m_chess_window = board; } 178 | 179 | const QWidget* Tile::getChessWindow() const 180 | { return m_chess_window; } 181 | -------------------------------------------------------------------------------- /services/rsRetroChessItems.cc: -------------------------------------------------------------------------------- 1 | /**************************************************************** 2 | * RetroShare is distributed under the following license: 3 | * 4 | * Copyright (C) 2015 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301, USA. 20 | ****************************************************************/ 21 | 22 | #include 23 | #include "serialiser/rsbaseserial.h" 24 | #include "serialiser/rstlvbase.h" 25 | 26 | #include "services/rsRetroChessItems.h" 27 | 28 | /*** 29 | #define RSSERIAL_DEBUG 1 30 | ***/ 31 | 32 | #include 33 | 34 | #define HOLLERITH_LEN_SPEC 4 35 | /*************************************************************************/ 36 | 37 | std::ostream& RsRetroChessDataItem::print(std::ostream &out, uint16_t indent) 38 | { 39 | printRsItemBase(out, "RsRetroChessDataItem", indent); 40 | uint16_t int_Indent = indent + 2; 41 | printIndent(out, int_Indent); 42 | out << "flags: " << flags << std::endl; 43 | 44 | printIndent(out, int_Indent); 45 | out << "data size: " << std::hex << data_size << std::dec << std::endl; 46 | 47 | printRsItemEnd(out, "RsRetroChessDataItem", indent); 48 | return out; 49 | } 50 | 51 | /*************************************************************************/ 52 | uint32_t RsRetroChessDataItem::serial_size() const 53 | { 54 | uint32_t s = 8; /* header */ 55 | s += 4; /* flags */ 56 | s += 4; /* data_size */ 57 | //s += m_msg.length()+HOLLERITH_LEN_SPEC; /* data */ 58 | s += getRawStringSize(m_msg); 59 | 60 | return s; 61 | } 62 | 63 | /* serialise the data to the buffer */ 64 | bool RsRetroChessDataItem::serialise(void *data, uint32_t& pktsize) 65 | { 66 | uint32_t tlvsize = serial_size() ; 67 | uint32_t offset = 0; 68 | 69 | if (pktsize < tlvsize) 70 | return false; /* not enough space */ 71 | 72 | pktsize = tlvsize; 73 | 74 | bool ok = true; 75 | 76 | ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); 77 | 78 | #ifdef RSSERIAL_DEBUG 79 | std::cerr << "RsRetroChessSerialiser::serialiseRetroChessDataItem() Header: " << ok << std::endl; 80 | std::cerr << "RsRetroChessSerialiser::serialiseRetroChessDataItem() Size: " << tlvsize << std::endl; 81 | #endif 82 | 83 | /* skip the header */ 84 | offset += 8; 85 | 86 | /* add mandatory parts first */ 87 | ok &= setRawUInt32(data, tlvsize, &offset, flags); 88 | ok &= setRawUInt32(data, tlvsize, &offset, data_size); 89 | 90 | 91 | ok &= setRawString(data, tlvsize, &offset, m_msg ); 92 | std::cout << "string sizes: " << getRawStringSize(m_msg) << " OR " << m_msg.size() << "\n"; 93 | 94 | if (offset != tlvsize) 95 | { 96 | ok = false; 97 | std::cerr << "RsRetroChessSerialiser::serialiseRetroChessPingItem() Size Error! " << std::endl; 98 | std::cerr << "expected " << tlvsize << " got " << offset << std::endl; 99 | std::cerr << "m_msg looks like " << m_msg << std::endl; 100 | } 101 | 102 | return ok; 103 | } 104 | /* serialise the data to the buffer */ 105 | 106 | /*************************************************************************/ 107 | /*************************************************************************/ 108 | 109 | RsRetroChessDataItem::RsRetroChessDataItem(void *data, uint32_t pktsize) 110 | : RsRetroChessItem(RS_PKT_SUBTYPE_RetroChess_DATA) 111 | { 112 | /* get the type and size */ 113 | uint32_t rstype = getRsItemId(data); 114 | uint32_t rssize = getRsItemSize(data); 115 | 116 | uint32_t offset = 0; 117 | 118 | if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_RetroChess_PLUGIN != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_RetroChess_DATA != getRsItemSubType(rstype))) 119 | throw std::runtime_error("Wrong packet subtype") ; 120 | 121 | if (pktsize < rssize) /* check size */ 122 | throw std::runtime_error("Not enough space") ; 123 | 124 | bool ok = true; 125 | 126 | /* skip the header */ 127 | offset += 8; 128 | 129 | /* get mandatory parts first */ 130 | ok &= getRawUInt32(data, rssize, &offset, &flags); 131 | ok &= getRawUInt32(data, rssize, &offset, &data_size); 132 | 133 | 134 | ok &= getRawString(data, rssize, &offset, m_msg ); 135 | 136 | if (offset != rssize) 137 | throw std::runtime_error("Serialization error.") ; 138 | 139 | if (!ok) 140 | throw std::runtime_error("Serialization error.") ; 141 | } 142 | /*************************************************************************/ 143 | 144 | RsItem* RsRetroChessSerialiser::deserialise(void *data, uint32_t *pktsize) 145 | { 146 | #ifdef RSSERIAL_DEBUG 147 | std::cerr << "RsRetroChessSerialiser::deserialise()" << std::endl; 148 | #endif 149 | 150 | /* get the type and size */ 151 | uint32_t rstype = getRsItemId(data); 152 | 153 | if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_RetroChess_PLUGIN != getRsItemService(rstype))) 154 | return NULL ; 155 | 156 | try 157 | { 158 | switch(getRsItemSubType(rstype)) 159 | { 160 | case RS_PKT_SUBTYPE_RetroChess_DATA: return new RsRetroChessDataItem(data, *pktsize); 161 | 162 | default: 163 | return NULL; 164 | } 165 | } 166 | catch(std::exception& e) 167 | { 168 | std::cerr << "RsRetroChessSerialiser: deserialization error: " << e.what() << std::endl; 169 | return NULL; 170 | } 171 | } 172 | 173 | 174 | /*************************************************************************/ 175 | 176 | -------------------------------------------------------------------------------- /gui/RetroChessChatWidgetHolder.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | #include "interface/rsRetroChess.h" 10 | 11 | #include "gui/chat/ChatWidget.h" 12 | 13 | #include "RetroChessChatWidgetHolder.h" 14 | 15 | #include 16 | #include 17 | 18 | #define IMAGE_RetroChess ":/images/chess.png" 19 | 20 | RetroChessChatWidgetHolder::RetroChessChatWidgetHolder(ChatWidget *chatWidget, RetroChessNotify *notify) 21 | : QObject(), ChatWidgetHolder(chatWidget), mRetroChessNotify(notify) 22 | { 23 | QIcon icon ; 24 | icon.addPixmap(QPixmap(IMAGE_RetroChess)) ; 25 | 26 | 27 | playChessButton = new QToolButton ; 28 | playChessButton->setIcon(icon) ; 29 | playChessButton->setToolTip(tr("Invite Friend to Chess")); 30 | playChessButton->setIconSize(QSize(35,35)) ; 31 | playChessButton->setAutoRaise(true) ; 32 | 33 | mChatWidget->addChatBarWidget(playChessButton); 34 | connect(playChessButton, SIGNAL(clicked()), this , SLOT(chessPressed())); 35 | connect(notify, SIGNAL(chessInvited(RsPeerId)), this , SLOT(chessnotify(RsPeerId))); 36 | 37 | } 38 | 39 | RetroChessChatWidgetHolder::~RetroChessChatWidgetHolder() 40 | { 41 | 42 | button_map::iterator it = buttonMapTakeChess.begin(); 43 | while (it != buttonMapTakeChess.end()) { 44 | it = buttonMapTakeChess.erase(it); 45 | } 46 | } 47 | 48 | void RetroChessChatWidgetHolder::chessnotify(RsPeerId from_peer_id) 49 | { 50 | RsPeerId peer_id = mChatWidget->getChatId().toPeerId();//TODO support GXSID 51 | //if (peer_id!=from_peer_id)return;//invite from another chat 52 | if (rsRetroChess->hasInviteFrom(peer_id)){ 53 | if (mChatWidget) { 54 | QString buttonName = QString::fromUtf8(rsPeers->getPeerName(peer_id).c_str()); 55 | if (buttonName.isEmpty()) buttonName = "Chess";//TODO maybe change all with GxsId 56 | //disable old buttons 57 | button_map::iterator it = buttonMapTakeChess.begin(); 58 | while (it != buttonMapTakeChess.end()) { 59 | it = buttonMapTakeChess.erase(it); 60 | } 61 | //button_map::iterator it = buttonMapTakeChess.find(buttonName); 62 | //if (it == buttonMapTakeChess.end()){ 63 | mChatWidget->addChatMsg(true, tr("Chess Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime() 64 | , tr("%1 inviting you to start Chess. Do you want to accept or decline the invitation?").arg(buttonName), ChatWidget::MSGTYPE_SYSTEM); 65 | RSButtonOnText *button = mChatWidget->getNewButtonOnTextBrowser(tr("Accept")); 66 | button->setToolTip(tr("Accept")); 67 | button->setStyleSheet(QString("border: 1px solid #199909;") 68 | .append("font-size: 12pt; color: white;") 69 | .append("min-width: 128px; min-height: 24px;") 70 | .append("border-radius: 6px;") 71 | .append("background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 0.67, " 72 | "stop: 0 #22c70d, stop: 1 #116a06);") 73 | 74 | ); 75 | 76 | button->updateImage(); 77 | 78 | connect(button,SIGNAL(clicked()),this,SLOT(chessStart())); 79 | connect(button,SIGNAL(mouseEnter()),this,SLOT(botMouseEnter())); 80 | connect(button,SIGNAL(mouseLeave()),this,SLOT(botMouseLeave())); 81 | 82 | buttonMapTakeChess.insert(buttonName, button); 83 | //} 84 | } 85 | 86 | 87 | } 88 | } 89 | 90 | void RetroChessChatWidgetHolder::chessPressed() 91 | { 92 | RsPeerId peer_id = mChatWidget->getChatId().toPeerId();//TODO support GXSID 93 | if (rsRetroChess->hasInviteFrom(peer_id)){ 94 | 95 | rsRetroChess->acceptedInvite(peer_id); 96 | mRetroChessNotify->notifyChessStart(peer_id); 97 | return; 98 | 99 | } 100 | rsRetroChess->sendInvite(peer_id); 101 | 102 | QString peerName = QString::fromUtf8(rsPeers->getPeerName(peer_id).c_str()); 103 | mChatWidget->addChatMsg(true, tr("Chess Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime() 104 | , tr("You're now inviting %1 to play Chess").arg(peerName), ChatWidget::MSGTYPE_SYSTEM); 105 | 106 | } 107 | 108 | void RetroChessChatWidgetHolder::chessStart() 109 | { 110 | RsPeerId peer_id = mChatWidget->getChatId().toPeerId();//TODO support GXSID 111 | 112 | rsRetroChess->acceptedInvite(peer_id); 113 | mRetroChessNotify->notifyChessStart(peer_id); 114 | return; 115 | } 116 | 117 | void RetroChessChatWidgetHolder::botMouseEnter() 118 | { 119 | RSButtonOnText *source = qobject_cast(QObject::sender()); 120 | if (source){ 121 | source->setStyleSheet(QString("border: 1px solid #333333;") 122 | .append("font-size: 12pt; color: white;") 123 | .append("min-width: 128px; min-height: 24px;") 124 | .append("border-radius: 6px;") 125 | .append("background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 0.67, " 126 | "stop: 0 #444444, stop: 1 #222222);") 127 | 128 | ); 129 | //source->setDown(true); 130 | } 131 | } 132 | 133 | void RetroChessChatWidgetHolder::botMouseLeave() 134 | { 135 | RSButtonOnText *source = qobject_cast(QObject::sender()); 136 | if (source){ 137 | source->setStyleSheet(QString("border: 1px solid #199909;") 138 | .append("font-size: 12pt; color: white;") 139 | .append("min-width: 128px; min-height: 24px;") 140 | .append("border-radius: 6px;") 141 | .append("background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 0.67, " 142 | "stop: 0 #22c70d, stop: 1 #116a06);") 143 | 144 | ); 145 | //source->setDown(false); 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /gui/chess.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | RetroChessWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 773 10 | 570 11 | 12 | 13 | 14 | 15 | 0 16 | 0 17 | 18 | 19 | 20 | 21 | 920 22 | 570 23 | 24 | 25 | 26 | Form 27 | 28 | 29 | 30 | 31 | 32 | Qt::Horizontal 33 | 34 | 35 | 36 | 37 | 0 38 | 0 39 | 40 | 41 | 42 | 43 | 320 44 | 16777215 45 | 46 | 47 | 48 | QFrame::StyledPanel 49 | 50 | 51 | QFrame::Raised 52 | 53 | 54 | 55 | 56 | 57 | 58 | 320 59 | 16777215 60 | 61 | 62 | 63 | QFrame::StyledPanel 64 | 65 | 66 | QFrame::Raised 67 | 68 | 69 | 70 | 71 | 72 | Player2 73 | 74 | 75 | 76 | 77 | 78 | 79 | m_player2_time 80 | 81 | 82 | 83 | 84 | 85 | 86 | Player2_avatar 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | QFrame::StyledPanel 97 | 98 | 99 | QFrame::Raised 100 | 101 | 102 | 103 | 104 | 105 | Player1 106 | 107 | 108 | 109 | 110 | 111 | 112 | m_player1_time 113 | 114 | 115 | 116 | 117 | 118 | 119 | Player1_avatar 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | Qt::Vertical 130 | 131 | 132 | 133 | 20 134 | 40 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | m_move_record 143 | 144 | 145 | 146 | 147 | 148 | 149 | Qt::Vertical 150 | 151 | 152 | 153 | 20 154 | 40 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 552 165 | 552 166 | 167 | 168 | 169 | 170 | 600 171 | 600 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | -------------------------------------------------------------------------------- /gui/images/knight_black.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 101 | 102 | -------------------------------------------------------------------------------- /RetroChessPlugin.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************** 2 | * RetroShare is distributed under the following license: 3 | * 4 | * Copyright (C) 2015 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301, USA. 20 | ****************************************************************/ 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "gui/chat/ChatWidget.h" 30 | 31 | #include "RetroChessPlugin.h" 32 | #include "interface/rsRetroChess.h" 33 | #include "gui/NEMainpage.h" 34 | #include "gui/RetroChessNotify.h" 35 | #include "gui/RetroChessChatWidgetHolder.h" 36 | 37 | 38 | #define IMAGE_RetroChess ":/images/chess.png" 39 | 40 | static void *inited = new RetroChessPlugin() ; 41 | 42 | extern "C" { 43 | 44 | // This is *the* functions required by RS plugin system to give RS access to the plugin. 45 | // Be careful to: 46 | // - always respect the C linkage convention 47 | // - always return an object of type RsPlugin* 48 | // 49 | void *RETROSHARE_PLUGIN_provide() 50 | { 51 | static RetroChessPlugin *p = new RetroChessPlugin() ; 52 | 53 | return (void*)p ; 54 | } 55 | 56 | // This symbol contains the svn revision number grabbed from the executable. 57 | // It will be tested by RS to load the plugin automatically, since it is safe to load plugins 58 | // with same revision numbers, assuming that the revision numbers are up-to-date. 59 | // 60 | uint32_t RETROSHARE_PLUGIN_revision = abs(atoi(RS_EXTRA_VERSION)) ; 61 | 62 | // This symbol contains the svn revision number grabbed from the executable. 63 | // It will be tested by RS to load the plugin automatically, since it is safe to load plugins 64 | // with same revision numbers, assuming that the revision numbers are up-to-date. 65 | // 66 | uint32_t RETROSHARE_PLUGIN_api = RS_PLUGIN_API_VERSION ; 67 | } 68 | 69 | void RetroChessPlugin::getPluginVersion(int& major, int& minor, int& build, int& svn_rev) const 70 | { 71 | major = RS_MAJOR_VERSION ; 72 | minor = RS_MINOR_VERSION ; 73 | build = RS_MINI_VERSION ; 74 | svn_rev = abs(atoi(RS_EXTRA_VERSION)) ; 75 | } 76 | 77 | RetroChessPlugin::RetroChessPlugin() 78 | { 79 | qRegisterMetaType("RsPeerId"); 80 | mainpage = NULL ; 81 | mRetroChess = NULL ; 82 | mPlugInHandler = NULL; 83 | mPeers = NULL; 84 | config_page = NULL ; 85 | mIcon = NULL ; 86 | 87 | mRetroChessNotify = new RetroChessNotify; 88 | } 89 | 90 | void RetroChessPlugin::setInterfaces(RsPlugInInterfaces &interfaces) 91 | { 92 | mPeers = interfaces.mPeers; 93 | } 94 | 95 | /*ConfigPage *RetroChessPlugin::qt_config_page() const 96 | { 97 | // The config pages are deleted when config is closed, so it's important not to static the 98 | // created object. 99 | // 100 | return new AudioInputConfig() ; 101 | }*/ 102 | 103 | QDialog *RetroChessPlugin::qt_about_page() const 104 | { 105 | static QMessageBox *about_dialog = NULL ; 106 | 107 | if(about_dialog == NULL) 108 | { 109 | about_dialog = new QMessageBox() ; 110 | 111 | QString text ; 112 | text += QObject::tr("

RetroShare RetroChess plugin


* Contributors: Cyril Soler, Josselin Jacquard
") ; 113 | text += QObject::tr("
The RetroChess plugin adds RetroChess to the private chat window of RetroShare. to use it, proceed as follows:
    ") ; 114 | text += QObject::tr("
  • setup microphone levels using the configuration panel
  • ") ; 115 | text += QObject::tr("
  • check your microphone by looking at the VU-metters
  • ") ; 116 | text += QObject::tr("
  • in the private chat, enable sound input/output by clicking on the two RetroChess icons
") ; 117 | text += QObject::tr("Your friend needs to run the plugin to talk/listen to you, or course.") ; 118 | text += QObject::tr("

This is an experimental feature. Don't hesitate to send comments and suggestion to the RS dev team.") ; 119 | 120 | about_dialog->setText(text) ; 121 | about_dialog->setStandardButtons(QMessageBox::Ok) ; 122 | } 123 | 124 | return about_dialog ; 125 | } 126 | 127 | ChatWidgetHolder *RetroChessPlugin::qt_get_chat_widget_holder(ChatWidget *chatWidget) const 128 | { 129 | switch (chatWidget->chatType()) { 130 | case ChatWidget::CHATTYPE_PRIVATE: 131 | return new RetroChessChatWidgetHolder(chatWidget, mRetroChessNotify); 132 | case ChatWidget::CHATTYPE_UNKNOWN: 133 | case ChatWidget::CHATTYPE_LOBBY: 134 | case ChatWidget::CHATTYPE_DISTANT: 135 | break; 136 | } 137 | 138 | return NULL; 139 | } 140 | 141 | p3Service *RetroChessPlugin::p3_service() const 142 | { 143 | if(mRetroChess == NULL) 144 | rsRetroChess = mRetroChess = new p3RetroChess(mPlugInHandler,mRetroChessNotify) ; // , 3600 * 24 * 30 * 6); // 6 Months 145 | 146 | return mRetroChess ; 147 | } 148 | 149 | void RetroChessPlugin::setPlugInHandler(RsPluginHandler *pgHandler) 150 | { 151 | mPlugInHandler = pgHandler; 152 | } 153 | 154 | QIcon *RetroChessPlugin::qt_icon() const 155 | { 156 | if (mIcon == NULL) { 157 | Q_INIT_RESOURCE(RetroChess_images); 158 | 159 | mIcon = new QIcon(IMAGE_RetroChess); 160 | } 161 | 162 | return mIcon; 163 | } 164 | MainPage *RetroChessPlugin::qt_page() const 165 | { 166 | // return chess game's main page here(which used for display) 167 | if(mainpage == NULL){ 168 | mainpage = new NEMainpage(0, mRetroChessNotify);//mPeers, mFiles) ; 169 | //tpage = new NEMainpage( ); 170 | //mainpage = tpage; 171 | } 172 | 173 | return mainpage ; 174 | } 175 | 176 | std::string RetroChessPlugin::getShortPluginDescription() const 177 | { 178 | return "RetroChess"; 179 | } 180 | 181 | std::string RetroChessPlugin::getPluginName() const 182 | { 183 | return "RetroChess"; 184 | } 185 | 186 | QTranslator* RetroChessPlugin::qt_translator(QApplication */*app*/, const QString& languageCode, const QString& externalDir) const 187 | { 188 | return NULL; 189 | } 190 | 191 | void RetroChessPlugin::qt_sound_events(SoundEvents &/*events*/) const 192 | { 193 | // events.addEvent(QApplication::translate("RetroChess", "RetroChess"), QApplication::translate("RetroChess", "Incoming call"), RetroChess_SOUND_INCOMING_CALL); 194 | } 195 | 196 | /*ToasterNotify *RetroChessPlugin::qt_toasterNotify(){ 197 | if (!mRetroChessToasterNotify) { 198 | mRetroChessToasterNotify = new RetroChessToasterNotify(mRetroChess, mRetroChessNotify); 199 | } 200 | return mRetroChessToasterNotify; 201 | }*/ 202 | -------------------------------------------------------------------------------- /gui/images/bishop_black.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 116 | 117 | -------------------------------------------------------------------------------- /gui/images/knight_white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 123 | 124 | -------------------------------------------------------------------------------- /gui/images/bishop_white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 124 | 125 | -------------------------------------------------------------------------------- /gui/NEMainpage.cpp: -------------------------------------------------------------------------------- 1 | #include "NEMainpage.h" 2 | #include "ui_NEMainpage.h" 3 | 4 | //#include "services/p3RetroChess.h" 5 | #include "interface/rsRetroChess.h" 6 | #include "services/rsRetroChessItems.h" 7 | #include "retroshare/rsservicecontrol.h" 8 | #include "gui/notifyqt.h" 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "gui/chat/ChatDialog.h" 18 | 19 | 20 | NEMainpage::NEMainpage(QWidget *parent, RetroChessNotify *notify) : 21 | MainPage(parent), 22 | mNotify(notify), 23 | ui(new Ui::NEMainpage) 24 | { 25 | ui->setupUi(this); 26 | setupMenuActions(); 27 | 28 | connect(mNotify, SIGNAL(NeMsgArrived(RsPeerId,QString)), this , SLOT(NeMsgArrived(RsPeerId,QString))); 29 | connect(mNotify, SIGNAL(chessStart(RsPeerId)), this , SLOT(chessStart(RsPeerId))); 30 | connect(ui->friendSelectionWidget, SIGNAL(itemSelectionChanged()), this, SLOT(friendSelectionChanged())); 31 | 32 | ui->friendSelectionWidget->start(); 33 | ui->friendSelectionWidget->setModus(FriendSelectionWidget::MODUS_SINGLE); 34 | ui->friendSelectionWidget->setShowType(FriendSelectionWidget::SHOW_SSL); 35 | 36 | connect(ui->friendSelectionWidget, SIGNAL(contentChanged()), this, SLOT(on_filterPeersButton_clicked())); 37 | connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(const QString&,int)), this, SLOT(on_filterPeersButton_clicked())); 38 | 39 | QString welcomemessage = QTime::currentTime().toString() +" "; 40 | welcomemessage+= tr("Welcome to RetroChess lobby"); 41 | ui->listWidget->addItem(welcomemessage); 42 | 43 | } 44 | 45 | NEMainpage::~NEMainpage() 46 | { 47 | delete ui; 48 | } 49 | 50 | 51 | void NEMainpage::on_pingAllButton_clicked() 52 | { 53 | 54 | } 55 | 56 | 57 | void NEMainpage::chessStart(const RsPeerId &peer_id){ 58 | 59 | create_chess_window(peer_id.toStdString(), 0); 60 | } 61 | 62 | void NEMainpage::NeMsgArrived(const RsPeerId &peer_id, QString str) 63 | { 64 | QJsonDocument jdoc = QJsonDocument::fromJson(str.toUtf8()); 65 | QVariantMap vmap = jdoc.toVariant().toMap(); 66 | std::cout << "GUI got Packet from: " << peer_id; 67 | std::cout << " saying " << str.toStdString(); 68 | std::cout << std::endl; 69 | QString type = vmap.value("type").toString(); 70 | if (type == "chat"){ 71 | QString output = QTime::currentTime().toString() +" "; 72 | output+= QString::fromStdString(rsPeers->getPeerName(peer_id)); 73 | output+=": "; 74 | output+=vmap.value("message").toString(); 75 | ui->listWidget->addItem(output); 76 | }else if (type == "chessclick"){ 77 | int row = vmap.value("row").toInt(); 78 | int col = vmap.value("col").toInt(); 79 | int count = vmap.value("count").toInt(); 80 | RetroChessWindow* rcw = activeGames.value(peer_id.toStdString()); 81 | rcw->validate_tile(row,col,count); 82 | }else if (type == "chess_init"){ 83 | create_chess_window(peer_id.toStdString(), 1); 84 | }else if (type == "chess_invite"){ 85 | ChatDialog::chatFriend(ChatId(peer_id)); 86 | rsRetroChess->gotInvite(peer_id); 87 | mNotify->notifyChessInvite(peer_id); 88 | }else if (type == "chess_accept"){ 89 | if (rsRetroChess->hasInviteTo(peer_id)){ 90 | create_chess_window(peer_id.toStdString(), 1); 91 | rsRetroChess->acceptedInvite(peer_id); 92 | } 93 | }else{ 94 | QString output = QTime::currentTime().toString() +" "; 95 | output+= QString::fromStdString(rsPeers->getPeerName(peer_id)); 96 | output+=": "; 97 | output+=str; 98 | ui->listWidget->addItem(output); 99 | } 100 | 101 | { 102 | QString output = QTime::currentTime().toString() +" "; 103 | output+= QString::fromStdString(rsPeers->getPeerName(peer_id)); 104 | output+=": "; 105 | output+=str; 106 | ui->netLogWidget->addItem(output); 107 | } 108 | } 109 | 110 | void NEMainpage::on_broadcastButton_clicked() 111 | { 112 | rsRetroChess->msg_all(ui->msgInput->text().toStdString()); 113 | NeMsgArrived(rsPeers->getOwnId(),ui->msgInput->text()); 114 | ui->msgInput->clear(); 115 | } 116 | 117 | void NEMainpage::create_chess_window(std::string peer_id, int player_id){ 118 | RetroChessWindow *rcw = new RetroChessWindow(peer_id, player_id); 119 | rcw->show(); 120 | 121 | activeGames.insert(peer_id, rcw); 122 | ui->active_games->addItem(QString::fromStdString(peer_id)); 123 | } 124 | 125 | void NEMainpage::on_playButton_clicked() 126 | { 127 | //get peer 128 | FriendSelectionWidget::IdType idType; 129 | std::string fid = ui->friendSelectionWidget->selectedId(idType); 130 | //make_board(); 131 | create_chess_window(fid, 0); 132 | 133 | QVariantMap map; 134 | map.insert("type", "chess_init"); 135 | 136 | rsRetroChess->qvm_msg_peer(RsPeerId(fid),map); 137 | 138 | std::cout << fid; 139 | } 140 | 141 | void NEMainpage::on_filterPeersButton_clicked() 142 | { 143 | std::cout << "\n\n filter peers \n"; 144 | 145 | std::list ssllist ; 146 | rsPeers->getFriendList(ssllist); 147 | 148 | 149 | RsPeerServiceInfo ownServices; 150 | rsServiceControl->getOwnServices(ownServices); 151 | 152 | std::vector peer_ids ; 153 | std::vector service_ids ; 154 | 155 | for(std::list::const_iterator it(ssllist.begin());it!=ssllist.end();++it) 156 | peer_ids.push_back(*it) ; 157 | service_ids.clear() ; 158 | uint32_t service_id; 159 | for(std::map::const_iterator sit(ownServices.mServiceList.begin());sit!=ownServices.mServiceList.end();++sit) 160 | { 161 | RsServiceInfo rsi = sit->second; 162 | service_ids.push_back(sit->first) ; 163 | std::cout << rsi.mServiceName << rsi.mServiceType << "\n"; 164 | if (strcmp(rsi.mServiceName.c_str(), "RetroChess") == 0){ 165 | service_id = rsi.mServiceType; 166 | std::cout << "setting service ID\n"; 167 | } 168 | } 169 | 170 | for(std::list::const_iterator it(ssllist.begin());it!=ssllist.end();++it) 171 | { 172 | RsPeerServiceInfo local_service_perms ; 173 | RsPeerServiceInfo remote_service_perms ; 174 | RsPeerId id = *it; 175 | 176 | rsServiceControl->getServicesAllowed (*it, local_service_perms) ; 177 | rsServiceControl->getServicesProvided(*it,remote_service_perms) ; 178 | 179 | bool local_allowed = local_service_perms.mServiceList.find(service_id) != local_service_perms.mServiceList.end() ; 180 | bool remote_allowed = remote_service_perms.mServiceList.find(service_id) != remote_service_perms.mServiceList.end() ; 181 | bool allowed = (local_allowed && remote_allowed); 182 | //QString la = 183 | QString serviceinfos = QString("peerlocal: ") + QString(local_allowed?"yes":"no") + QString(" remote: ") + QString(remote_allowed?"yes":"no"); 184 | ui->netLogWidget->addItem(serviceinfos); 185 | std::cout << serviceinfos.toStdString() << "\n"; 186 | //if (allowed){ 187 | QList items; 188 | ui->friendSelectionWidget->itemsFromId(FriendSelectionWidget::IDTYPE_SSL,id.toStdString(),items); 189 | 190 | std::cout << items.size() << "\n"; 191 | if (items.size()){ 192 | QTreeWidgetItem* item = items.first(); 193 | item->setHidden(!allowed); 194 | } 195 | } 196 | 197 | 198 | // 199 | } 200 | 201 | void NEMainpage::setupMenuActions() 202 | { 203 | mActionPlayChess = new QAction(QIcon(), tr("Play Chess"), this); 204 | connect(mActionPlayChess, SIGNAL(triggered(bool)), this, SLOT(on_playButton_clicked())); 205 | 206 | ui->friendSelectionWidget->addContextMenuAction(mActionPlayChess); 207 | 208 | } 209 | 210 | void NEMainpage::friendSelectionChanged() 211 | { 212 | std::set peerIds; 213 | ui->friendSelectionWidget->selectedIds(peerIds, false); 214 | 215 | std::set gxsIds; 216 | ui->friendSelectionWidget->selectedIds(gxsIds, false); 217 | 218 | int selectedCount = peerIds.size() + gxsIds.size(); 219 | 220 | mActionPlayChess->setEnabled(selectedCount); 221 | 222 | FriendSelectionWidget::IdType idType; 223 | ui->friendSelectionWidget->selectedId(idType); 224 | 225 | } 226 | -------------------------------------------------------------------------------- /gui/images/king_black.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 135 | 136 | -------------------------------------------------------------------------------- /gui/NEMainpage.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | NEMainpage 4 | 5 | 6 | 7 | 0 8 | 0 9 | 684 10 | 578 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 0 19 | 20 | 21 | 0 22 | 23 | 24 | 0 25 | 26 | 27 | 0 28 | 29 | 30 | 31 | 32 | 33 | 0 34 | 0 35 | 36 | 37 | 38 | QFrame::NoFrame 39 | 40 | 41 | QFrame::Raised 42 | 43 | 44 | 45 | 2 46 | 47 | 48 | 2 49 | 50 | 51 | 2 52 | 53 | 54 | 2 55 | 56 | 57 | 58 | 59 | 60 | 24 61 | 24 62 | 63 | 64 | 65 | 66 | 67 | 68 | :/images/retrochess.png 69 | 70 | 71 | true 72 | 73 | 74 | 75 | 76 | 77 | 78 | RetroChess 79 | 80 | 81 | 82 | 83 | 84 | 85 | Qt::Horizontal 86 | 87 | 88 | 89 | 123 90 | 13 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | Qt::NoFocus 99 | 100 | 101 | 102 | :/icons/help_64.png:/icons/help_64.png 103 | 104 | 105 | true 106 | 107 | 108 | true 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 0 119 | 120 | 121 | 122 | Chess Lobby 123 | 124 | 125 | 126 | 127 | 128 | Qt::Horizontal 129 | 130 | 131 | 132 | Invite Friends 133 | 134 | 135 | 136 | 137 | 138 | Qt::CustomContextMenu 139 | 140 | 141 | 142 | 143 | 144 | 145 | CheckPeers 146 | 147 | 148 | 149 | 150 | 151 | 152 | Qt::Horizontal 153 | 154 | 155 | 156 | 41 157 | 20 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | Play Chess 172 | 173 | 174 | 175 | 176 | 177 | 178 | Qt::Horizontal 179 | 180 | 181 | 182 | 475 183 | 20 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | Type a message here 197 | 198 | 199 | 200 | 201 | 202 | 203 | Send 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | Net log 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 0 230 | 0 231 | 232 | 233 | 234 | 235 | 16777215 236 | 150 237 | 238 | 239 | 240 | Active Games 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | StyledLabel 254 | QLabel 255 |
gui/common/StyledLabel.h
256 |
257 | 258 | FriendSelectionWidget 259 | QWidget 260 |
gui/common/FriendSelectionWidget.h
261 | 1 262 |
263 |
264 | 265 | 266 | 267 | 268 |
269 | -------------------------------------------------------------------------------- /gui/images/queen_white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 139 | 140 | -------------------------------------------------------------------------------- /gui/images/queen_black.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 141 | 142 | -------------------------------------------------------------------------------- /gui/images/king_white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 143 | 144 | -------------------------------------------------------------------------------- /services/p3RetroChess.cc: -------------------------------------------------------------------------------- 1 | /**************************************************************** 2 | * RetroShare is distributed under the following license: 3 | * 4 | * Copyright (C) 2015 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301, USA. 20 | ****************************************************************/ 21 | 22 | #include "util/rsdir.h" 23 | #include "retroshare/rsiface.h" 24 | #include "pqi/pqibin.h" 25 | #include "pqi/pqistore.h" 26 | #include "pqi/p3linkmgr.h" 27 | #include 28 | #include 29 | 30 | #include // for std::istringstream 31 | 32 | #include "services/p3RetroChess.h" 33 | #include "services/rsRetroChessItems.h" 34 | 35 | #include 36 | 37 | #include "gui/RetroChessNotify.h" 38 | 39 | 40 | //#define DEBUG_RetroChess 1 41 | 42 | 43 | /* DEFINE INTERFACE POINTER! */ 44 | RsRetroChess *rsRetroChess = NULL; 45 | 46 | 47 | 48 | #ifdef WINDOWS_SYS 49 | #include 50 | #include 51 | #endif 52 | 53 | static double getCurrentTS() 54 | { 55 | 56 | #ifndef WINDOWS_SYS 57 | struct timeval cts_tmp; 58 | gettimeofday(&cts_tmp, NULL); 59 | double cts = (cts_tmp.tv_sec) + ((double) cts_tmp.tv_usec) / 1000000.0; 60 | #else 61 | struct _timeb timebuf; 62 | _ftime( &timebuf); 63 | double cts = (timebuf.time) + ((double) timebuf.millitm) / 1000.0; 64 | #endif 65 | return cts; 66 | } 67 | 68 | static uint64_t convertTsTo64bits(double ts) 69 | { 70 | uint32_t secs = (uint32_t) ts; 71 | uint32_t usecs = (uint32_t) ((ts - (double) secs) * 1000000); 72 | uint64_t bits = (((uint64_t) secs) << 32) + usecs; 73 | return bits; 74 | } 75 | 76 | static double convert64bitsToTs(uint64_t bits) 77 | { 78 | uint32_t usecs = (uint32_t) (bits & 0xffffffff); 79 | uint32_t secs = (uint32_t) ((bits >> 32) & 0xffffffff); 80 | double ts = (secs) + ((double) usecs) / 1000000.0; 81 | 82 | return ts; 83 | } 84 | 85 | p3RetroChess::p3RetroChess(RsPluginHandler *handler,RetroChessNotify *notifier) 86 | : RsPQIService(RS_SERVICE_TYPE_RetroChess_PLUGIN,0,handler), mRetroChessMtx("p3RetroChess"), mServiceControl(handler->getServiceControl()) , mNotify(notifier) 87 | { 88 | addSerialType(new RsRetroChessSerialiser()); 89 | 90 | 91 | //plugin default configuration 92 | 93 | } 94 | RsServiceInfo p3RetroChess::getServiceInfo() 95 | { 96 | const std::string TURTLE_APP_NAME = "RetroChess"; 97 | const uint16_t TURTLE_APP_MAJOR_VERSION = 1; 98 | const uint16_t TURTLE_APP_MINOR_VERSION = 0; 99 | const uint16_t TURTLE_MIN_MAJOR_VERSION = 1; 100 | const uint16_t TURTLE_MIN_MINOR_VERSION = 0; 101 | 102 | return RsServiceInfo(RS_SERVICE_TYPE_RetroChess_PLUGIN, 103 | TURTLE_APP_NAME, 104 | TURTLE_APP_MAJOR_VERSION, 105 | TURTLE_APP_MINOR_VERSION, 106 | TURTLE_MIN_MAJOR_VERSION, 107 | TURTLE_MIN_MINOR_VERSION); 108 | } 109 | 110 | int p3RetroChess::tick() 111 | { 112 | #ifdef DEBUG_RetroChess 113 | std::cerr << "ticking p3RetroChess" << std::endl; 114 | #endif 115 | 116 | //processIncoming(); 117 | //sendPackets(); 118 | 119 | return 0; 120 | } 121 | 122 | int p3RetroChess::status() 123 | { 124 | return 1; 125 | } 126 | #include 127 | void p3RetroChess::str_msg_peer(RsPeerId peerID, QString strdata){ 128 | QVariantMap map; 129 | map.insert("type", "chat"); 130 | map.insert("message", strdata); 131 | 132 | qvm_msg_peer(peerID,map); 133 | } 134 | 135 | void p3RetroChess::qvm_msg_peer(RsPeerId peerID, QVariantMap data){ 136 | QJsonDocument jsondoc = QJsonDocument::fromVariant(data); 137 | std::string msg = jsondoc.toJson().toStdString(); 138 | raw_msg_peer(peerID, msg); 139 | } 140 | 141 | void p3RetroChess::chess_click(std::string peer_id, int col, int row, int count) 142 | { 143 | QVariantMap map; 144 | map.insert("type", "chessclick"); 145 | map.insert("col", col); 146 | map.insert("row", row); 147 | map.insert("count", count); 148 | 149 | RsPeerId peerID = RsPeerId(peer_id); 150 | qvm_msg_peer(peerID,map); 151 | 152 | } 153 | 154 | bool p3RetroChess::hasInviteFrom(RsPeerId peerID) 155 | { 156 | return invitesFrom.find(peerID)!=invitesFrom.end(); 157 | } 158 | bool p3RetroChess::hasInviteTo(RsPeerId peerID) 159 | { 160 | return invitesTo.find(peerID)!=invitesTo.end(); 161 | } 162 | 163 | void p3RetroChess::acceptedInvite(RsPeerId peerID) 164 | { 165 | std::set::iterator it =invitesTo.find(peerID); 166 | if (it != invitesTo.end()){ 167 | invitesTo.erase(it); 168 | } 169 | 170 | it =invitesFrom.find(peerID); 171 | if (it != invitesFrom.end()){ 172 | invitesFrom.erase(it); 173 | } 174 | raw_msg_peer(peerID, "{\"type\":\"chess_accept\"}"); 175 | } 176 | 177 | void p3RetroChess::gotInvite(RsPeerId peerID) 178 | { 179 | 180 | std::set::iterator it =invitesFrom.find(peerID); 181 | if (it == invitesFrom.end()){ 182 | invitesFrom.insert(peerID); 183 | } 184 | } 185 | void p3RetroChess::sendInvite(RsPeerId peerID) 186 | { 187 | 188 | std::set::iterator it =invitesTo.find(peerID); 189 | if (it == invitesTo.end()){ 190 | invitesTo.insert(peerID); 191 | } 192 | raw_msg_peer(peerID, "{\"type\":\"chess_invite\"}"); 193 | } 194 | 195 | /*void p3RetroChess::set_peer(RsPeerId peer) 196 | { 197 | mPeerID = peer; 198 | }*/ 199 | void p3RetroChess::raw_msg_peer(RsPeerId peerID, std::string msg){ 200 | std::cout << "MSging: " << peerID.toStdString() << "\n"; 201 | std::cout << "MSging: " << msg << "\n"; 202 | /* create the packet */ 203 | RsRetroChessDataItem *pingPkt = new RsRetroChessDataItem(); 204 | pingPkt->PeerId(peerID); 205 | pingPkt->m_msg = msg; 206 | pingPkt->data_size = msg.size(); 207 | //pingPkt->mSeqNo = mCounter; 208 | //pingPkt->mPingTS = convertTsTo64bits(ts); 209 | 210 | //storePingAttempt(*it, ts, mCounter); 211 | 212 | #ifdef DEBUG_RetroChess 213 | std::cerr << "p3RetroChess::msg_all() With Packet:"; 214 | std::cerr << std::endl; 215 | pingPkt->print(std::cerr, 10); 216 | #endif 217 | 218 | sendItem(pingPkt); 219 | } 220 | 221 | void p3RetroChess::msg_all(std::string msg){ 222 | /* we ping our peers */ 223 | //if(!mServiceControl) 224 | // return ; 225 | 226 | //std::set onlineIds; 227 | std::list< RsPeerId > onlineIds; 228 | // mServiceControl->getPeersConnected(getServiceInfo().mServiceType, onlineIds); 229 | rsPeers->getOnlineList(onlineIds); 230 | 231 | double ts = getCurrentTS(); 232 | 233 | #ifdef DEBUG_RetroChess 234 | std::cerr << "p3RetroChess::msg_all() @ts: " << ts; 235 | std::cerr << std::endl; 236 | #endif 237 | 238 | std::cout << "READY TO BCast: " << onlineIds.size() << "\n"; 239 | /* prepare packets */ 240 | std::list::iterator it; 241 | for(it = onlineIds.begin(); it != onlineIds.end(); it++) 242 | { 243 | str_msg_peer(RsPeerId(*it),QString::fromStdString(msg)); 244 | } 245 | } 246 | 247 | void p3RetroChess::ping_all(){ 248 | //TODO ping all! 249 | } 250 | 251 | void p3RetroChess::broadcast_paint(int x, int y) 252 | { 253 | std::list< RsPeerId > onlineIds; 254 | // mServiceControl->getPeersConnected(getServiceInfo().mServiceType, onlineIds); 255 | rsPeers->getOnlineList(onlineIds); 256 | 257 | double ts = getCurrentTS(); 258 | 259 | 260 | std::cout << "READY TO PAINT: " << onlineIds.size() << "\n"; 261 | /* prepare packets */ 262 | std::list::iterator it; 263 | for(it = onlineIds.begin(); it != onlineIds.end(); it++) 264 | { 265 | 266 | std::cout << "painting to: " << (*it).toStdString() << "\n"; 267 | QVariantMap map; 268 | map.insert("type", "paint"); 269 | map.insert("x", x); 270 | map.insert("y", y); 271 | 272 | qvm_msg_peer(RsPeerId(*it),map); 273 | /* create the packet */ 274 | //TODO send paint packets 275 | } 276 | } 277 | 278 | //TODO mNotify->notifyReceivedPaint(item->PeerId(), item->x,item->y); 279 | 280 | 281 | 282 | void p3RetroChess::handleData(RsRetroChessDataItem *item) 283 | { 284 | RsStackMutex stack(mRetroChessMtx); /****** LOCKED MUTEX *******/ 285 | 286 | // store the data in a queue. 287 | 288 | 289 | mNotify->notifyReceivedMsg(item->PeerId(), QString::fromStdString(item->m_msg)); 290 | } 291 | 292 | bool p3RetroChess::recvItem(RsItem *item) 293 | { 294 | std::cout << "recvItem type: " << item->PacketSubType() << "\n"; 295 | /* pass to specific handler */ 296 | bool keep = false ; 297 | 298 | switch(item->PacketSubType()) 299 | { 300 | case RS_PKT_SUBTYPE_RetroChess_DATA: 301 | handleData(dynamic_cast(item)); 302 | keep = true ; 303 | break; 304 | /*case RS_PKT_SUBTYPE_RetroChess_INVITE: 305 | if (invites.find(item->PeerId()!=invites.end())){ 306 | invites.insert(item->PeerId()); 307 | } 308 | mNotify-> 309 | 310 | //keep = true ; 311 | break;*/ 312 | 313 | default: 314 | break; 315 | } 316 | 317 | /* clean up */ 318 | if(!keep) 319 | delete item; 320 | return true ; 321 | } 322 | 323 | 324 | 325 | RsTlvKeyValue p3RetroChess::push_int_value(const std::string& key,int value) 326 | { 327 | RsTlvKeyValue kv ; 328 | kv.key = key ; 329 | rs_sprintf(kv.value, "%d", value); 330 | 331 | return kv ; 332 | } 333 | int p3RetroChess::pop_int_value(const std::string& s) 334 | { 335 | std::istringstream is(s) ; 336 | 337 | int val ; 338 | is >> val ; 339 | 340 | return val ; 341 | } 342 | 343 | bool p3RetroChess::saveList(bool& cleanup, std::list& lst) 344 | { 345 | cleanup = true ; 346 | 347 | RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ; 348 | 349 | /*vitem->tlvkvs.pairs.push_back(push_int_value("P3RetroChess_CONFIG_ATRANSMIT",_atransmit)) ; 350 | vitem->tlvkvs.pairs.push_back(push_int_value("P3RetroChess_CONFIG_VOICEHOLD",_voice_hold)) ; 351 | vitem->tlvkvs.pairs.push_back(push_int_value("P3RetroChess_CONFIG_VADMIN" ,_vadmin)) ; 352 | vitem->tlvkvs.pairs.push_back(push_int_value("P3RetroChess_CONFIG_VADMAX" ,_vadmax)) ; 353 | vitem->tlvkvs.pairs.push_back(push_int_value("P3RetroChess_CONFIG_NOISE_SUP",_noise_suppress)) ; 354 | vitem->tlvkvs.pairs.push_back(push_int_value("P3RetroChess_CONFIG_MIN_LOUDN",_min_loudness)) ; 355 | vitem->tlvkvs.pairs.push_back(push_int_value("P3RetroChess_CONFIG_ECHO_CNCL",_echo_cancel)) ;*/ 356 | 357 | lst.push_back(vitem) ; 358 | 359 | return true ; 360 | } 361 | bool p3RetroChess::loadList(std::list& load) 362 | { 363 | for(std::list::const_iterator it(load.begin());it!=load.end();++it) 364 | { 365 | #ifdef P3TURTLE_DEBUG 366 | assert(item!=NULL) ; 367 | #endif 368 | RsConfigKeyValueSet *vitem = dynamic_cast(*it) ; 369 | /* 370 | if(vitem != NULL) 371 | for(std::list::const_iterator kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit) 372 | if(kit->key == "P3RetroChess_CONFIG_ATRANSMIT") 373 | _atransmit = pop_int_value(kit->value) ; 374 | else if(kit->key == "P3RetroChess_CONFIG_VOICEHOLD") 375 | _voice_hold = pop_int_value(kit->value) ; 376 | else if(kit->key == "P3RetroChess_CONFIG_VADMIN") 377 | _vadmin = pop_int_value(kit->value) ; 378 | else if(kit->key == "P3RetroChess_CONFIG_VADMAX") 379 | _vadmax = pop_int_value(kit->value) ; 380 | else if(kit->key == "P3RetroChess_CONFIG_NOISE_SUP") 381 | _noise_suppress = pop_int_value(kit->value) ; 382 | else if(kit->key == "P3RetroChess_CONFIG_MIN_LOUDN") 383 | _min_loudness = pop_int_value(kit->value) ; 384 | else if(kit->key == "P3RetroChess_CONFIG_ECHO_CNCL") 385 | _echo_cancel = pop_int_value(kit->value) ; 386 | 387 | delete vitem ; 388 | */ 389 | } 390 | 391 | return true ; 392 | } 393 | 394 | RsSerialiser *p3RetroChess::setupSerialiser() 395 | { 396 | RsSerialiser *rsSerialiser = new RsSerialiser(); 397 | rsSerialiser->addSerialType(new RsRetroChessSerialiser()); 398 | rsSerialiser->addSerialType(new RsGeneralConfigSerialiser()); 399 | 400 | return rsSerialiser ; 401 | } 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | -------------------------------------------------------------------------------- /gui/chess.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "chess.h" 4 | #include "ui_chess.h" 5 | 6 | #include "gui/common/AvatarDefs.h" 7 | 8 | RetroChessWindow::RetroChessWindow(std::string peerid, int player, QWidget *parent) : 9 | QWidget(parent), 10 | m_ui( new Ui::RetroChessWindow() ), 11 | mPeerId(peerid) 12 | //ui(new Ui::RetroChessWindow) 13 | { 14 | m_ui->setupUi( this ); 15 | 16 | //tile = { { NULL } }; 17 | count=0; 18 | turn=1; 19 | max=0; 20 | texp = new int[60]; 21 | setGeometry(0,0,1370,700); 22 | 23 | QString player_str; 24 | if (player ) 25 | { 26 | p1id = rsPeers->getOwnId(); 27 | p2id = RsPeerId(peerid); 28 | player_str = " (1)"; 29 | } 30 | else 31 | { 32 | p1id = RsPeerId(peerid); 33 | p2id = rsPeers->getOwnId(); 34 | player_str = " (2)"; 35 | } 36 | 37 | p1name = rsPeers->getPeerName(p1id); 38 | p2name = rsPeers->getPeerName(p2id); 39 | 40 | QString title = QString::fromStdString(p2name); 41 | title += " Playing Chess against "; 42 | title += QString::fromStdString(p1name); 43 | title+=player_str; 44 | 45 | 46 | this->setWindowTitle(title); 47 | 48 | this->initAccessories(); 49 | this->initChessBoard(); 50 | } 51 | 52 | RetroChessWindow::~RetroChessWindow() 53 | { 54 | delete m_ui; 55 | } 56 | 57 | class Border 58 | { 59 | public: 60 | Border(); 61 | void outline(QWidget *baseWidget, int xPos, int yPos, int Pos) 62 | { 63 | QLabel *outLabel = new QLabel(baseWidget); 64 | 65 | if(!Pos) 66 | outLabel->setGeometry(xPos,yPos,552,20); //Horizontal Borders 67 | 68 | else 69 | outLabel->setGeometry(xPos,yPos,20,512); //Vertical Borders 70 | 71 | outLabel->setStyleSheet("QLabel { background-color :rgb(170, 170, 127); color : black; }"); 72 | } 73 | }; 74 | 75 | void RetroChessWindow::initAccessories() 76 | { 77 | // display player's name 78 | m_ui->m_player1_name->setText( p1name.c_str() ); 79 | m_ui->m_player2_name->setText( p2name.c_str() ); 80 | 81 | QPixmap p1avatar; 82 | AvatarDefs::getAvatarFromSslId(p1id, p1avatar); 83 | m_ui->m_player1_avatar->setPixmap(p1avatar);//QPixmap(":/images/profile.png")); 84 | 85 | AvatarDefs::getAvatarFromSslId(p2id, p1avatar); 86 | m_ui->m_player2_avatar->setPixmap(p1avatar);//QPixmap(":/images/profile.png")); 87 | 88 | 89 | 90 | /* 91 | QWidget *baseWidget = this; 92 | QLabel *player2 = new QLabel(baseWidget); 93 | QLabel *name2 = new QLabel(p2name.c_str(), baseWidget); 94 | QLabel *time2 = new QLabel("00:00:00", baseWidget); 95 | 96 | QLabel *player1 = new QLabel(baseWidget); 97 | QLabel *name1 = new QLabel(p1name.c_str(), baseWidget); 98 | QLabel *time1 = new QLabel("00:00:00", baseWidget); 99 | 100 | QLabel *moves = new QLabel(baseWidget); 101 | 102 | name1->setGeometry(125,610,80,20); 103 | time1->setGeometry(120,635,80,20); 104 | player1->setGeometry(100,500,100,100); 105 | 106 | QPixmap p1avatar; 107 | AvatarDefs::getAvatarFromSslId(p1id, p1avatar); 108 | player1->setPixmap(p1avatar);//QPixmap(":/images/profile.png")); 109 | 110 | 111 | name2->setGeometry(125,210,80,20); 112 | time2->setGeometry(120,235,80,20); 113 | player2->setGeometry(100,100,100,100); 114 | QPixmap p2avatar; 115 | AvatarDefs::getAvatarFromSslId(p2id, p2avatar); 116 | player2->setPixmap(p2avatar);//QPixmap(":/images/profile.png")); 117 | 118 | moves->setGeometry(1000,105,250,550); 119 | moves->setStyleSheet("QLabel {background-color: white;}"); 120 | */ 121 | 122 | m_ui->m_move_record->setStyleSheet("QLabel {background-color: white;}"); 123 | } 124 | 125 | void RetroChessWindow::disOrange() 126 | { 127 | int i; 128 | 129 | for(i=0; itileDisplay(); 131 | 132 | } 133 | 134 | void RetroChessWindow::validate_tile(int row, int col, int c) 135 | { 136 | Tile *clickedtile = tile[col][row]; 137 | //if (!click1)click1=clickedtile; 138 | clickedtile->validate(++count); 139 | } 140 | 141 | void RetroChessWindow::initChessBoard() 142 | { 143 | //QWidget *baseWidget, Tile *tile[8][8] 144 | //QWidget *baseWidget = this; 145 | QWidget *baseWidget = m_ui->m_chess_board; 146 | int i,j,k=0,hor,ver; 147 | Border *border[4] = { NULL }; 148 | 149 | //borderDisplay (border size: 552 * 552) 150 | { 151 | border[0]->outline( baseWidget, 0, 0, 0); 152 | border[1]->outline( baseWidget, 0, 532, 0); 153 | border[2]->outline( baseWidget, 0, 20, 1); 154 | border[2]->outline( baseWidget, 532, 20, 1); 155 | } 156 | 157 | //Create 64 tiles (allocating memories to the objects of Tile class) 158 | //ver=125; 159 | ver = 20; 160 | 161 | for(i=0; i<8; i++) 162 | { 163 | //hor=350; 164 | hor = 20; 165 | for(j=0; j<8; j++) 166 | { 167 | tile[i][j] = new Tile(baseWidget); 168 | tile[i][j]->setChessWindow( this ); 169 | tile[i][j]->tileColor=(i+j)%2; 170 | tile[i][j]->piece=0; 171 | tile[i][j]->row=i; 172 | tile[i][j]->col=j; 173 | tile[i][j]->tileNum=k++; 174 | tile[i][j]->tileDisplay(); 175 | tile[i][j]->setGeometry(hor,ver,64,64); 176 | tile[i][j]->resize( 64, 64 ); 177 | 178 | hor+=64; 179 | } 180 | ver+=64; 181 | } 182 | 183 | //white pawns 184 | for(j=0; j<8; j++) 185 | { 186 | tile[1][j]->piece=1; 187 | tile[1][j]->pieceColor=0; 188 | tile[1][j]->display('P'); 189 | } 190 | 191 | //black pawns 192 | for(j=0; j<8; j++) 193 | { 194 | tile[6][j]->piece=1; 195 | tile[6][j]->pieceColor=1; 196 | tile[6][j]->display('P'); 197 | } 198 | 199 | //white and black remaining elements 200 | for(j=0; j<8; j++) 201 | { 202 | tile[0][j]->piece=1; 203 | tile[0][j]->pieceColor=0; 204 | tile[7][j]->piece=1; 205 | tile[7][j]->pieceColor=1; 206 | } 207 | 208 | { 209 | tile[0][0]->display('R'); 210 | tile[0][1]->display('H'); 211 | tile[0][2]->display('B'); 212 | tile[0][3]->display('Q'); 213 | tile[0][4]->display('K'); 214 | tile[0][5]->display('B'); 215 | tile[0][6]->display('H'); 216 | tile[0][7]->display('R'); 217 | } 218 | 219 | 220 | { 221 | tile[7][0]->display('R'); 222 | tile[7][1]->display('H'); 223 | tile[7][2]->display('B'); 224 | tile[7][3]->display('Q'); 225 | tile[7][4]->display('K'); 226 | tile[7][5]->display('B'); 227 | tile[7][6]->display('H'); 228 | tile[7][7]->display('R'); 229 | } 230 | 231 | wR=7; 232 | wC=4; 233 | 234 | bR=0; 235 | bC=4; 236 | } 237 | 238 | 239 | 240 | int RetroChessWindow::chooser(Tile *temp) 241 | { 242 | switch(temp->pieceName) 243 | { 244 | case 'P': 245 | flag=validatePawn(temp); 246 | break; 247 | 248 | case 'R': 249 | flag=validateRook(temp); 250 | break; 251 | 252 | case 'H': 253 | flag=validateHorse(temp); 254 | break; 255 | 256 | case 'K': 257 | flag=validateKing(temp); 258 | break; 259 | 260 | case 'Q': 261 | flag=validateQueen(temp); 262 | break; 263 | 264 | case 'B': 265 | flag=validateBishop(temp); 266 | break; 267 | 268 | } 269 | 270 | orange(); 271 | 272 | return flag; 273 | } 274 | 275 | //PAWN 276 | int RetroChessWindow::validatePawn(Tile *temp) 277 | { 278 | int row,col; 279 | 280 | row=temp->row; 281 | col=temp->col; 282 | retVal=0; 283 | 284 | //White Pawn 285 | if(temp->pieceColor) 286 | { 287 | if(row-1>=0 && !tile[row-1][col]->piece) 288 | { 289 | /*int tnum = tile[row-1][col]->tileNum; 290 | std::cout << "tile: " << texp[max] << std::endl; 291 | int a = texp[max]; 292 | texp[max] = tnum; 293 | max++;*/ 294 | texp[max++]=tile[row-1][col]->tileNum; 295 | retVal=1; 296 | } 297 | 298 | if(row==6 && !tile[5][col]->piece && !tile[4][col]->piece) 299 | { 300 | texp[max++]=tile[row-2][col]->tileNum; 301 | retVal=1; 302 | } 303 | 304 | if(row-1>=0 && col-1>=0) 305 | { 306 | if(tile[row-1][col-1]->pieceColor!=temp->pieceColor && tile[row-1][col-1]->piece) 307 | { 308 | texp[max++]=tile[row-1][col-1]->tileNum; 309 | retVal=1; 310 | } 311 | } 312 | 313 | if(row-1>=0 && col+1<=7) 314 | { 315 | if(tile[row-1][col+1]->pieceColor!=temp->pieceColor && tile[row-1][col+1]->piece) 316 | { 317 | texp[max++]=tile[row-1][col+1]->tileNum; 318 | retVal=1; 319 | } 320 | } 321 | } 322 | else 323 | { 324 | if(row+1<=7 && !tile[row+1][col]->piece) 325 | { 326 | texp[max++]=tile[row+1][col]->tileNum; 327 | retVal=1; 328 | } 329 | 330 | if(row==1 && !tile[2][col]->piece && !tile[3][col]->piece) 331 | { 332 | texp[max++]=tile[row+2][col]->tileNum; 333 | retVal=1; 334 | } 335 | 336 | if(row+1<=7 && col-1>=0) 337 | { 338 | if(tile[row+1][col-1]->pieceColor!=temp->pieceColor && tile[row+1][col-1]->piece) 339 | { 340 | texp[max++]=tile[row+1][col-1]->tileNum; 341 | retVal=1; 342 | } 343 | } 344 | 345 | if(row+1<=7 && col+1<=7) 346 | { 347 | if(tile[row+1][col+1]->pieceColor!=temp->pieceColor && tile[row+1][col+1]->piece) 348 | { 349 | texp[max++]=tile[row+1][col+1]->tileNum; 350 | retVal=1; 351 | } 352 | } 353 | } 354 | 355 | return retVal; 356 | } 357 | 358 | 359 | //ROOK 360 | int RetroChessWindow::validateRook(Tile *temp) 361 | { 362 | int r,c; 363 | 364 | retVal=0; 365 | 366 | r=temp->row; 367 | c=temp->col; 368 | while(r-->0) 369 | { 370 | if(!tile[r][c]->piece) 371 | { 372 | texp[max++]=tile[r][c]->tileNum; 373 | retVal=1; 374 | } 375 | 376 | else if(tile[r][c]->pieceColor==temp->pieceColor) 377 | break; 378 | 379 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 380 | { 381 | texp[max++]=tile[r][c]->tileNum; 382 | retVal=1; 383 | break; 384 | } 385 | } 386 | 387 | r=temp->row; 388 | c=temp->col; 389 | while(r++<7) 390 | { 391 | if(!tile[r][c]->piece) 392 | { 393 | texp[max++]=tile[r][c]->tileNum; 394 | retVal=1; 395 | } 396 | 397 | else if(tile[r][c]->pieceColor==temp->pieceColor) 398 | break; 399 | 400 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 401 | { 402 | texp[max++]=tile[r][c]->tileNum; 403 | retVal=1; 404 | break; 405 | } 406 | } 407 | 408 | r=temp->row; 409 | c=temp->col; 410 | while(c++<7) 411 | { 412 | if(!tile[r][c]->piece) 413 | { 414 | texp[max++]=tile[r][c]->tileNum; 415 | retVal=1; 416 | } 417 | 418 | else if(tile[r][c]->pieceColor==temp->pieceColor) 419 | break; 420 | 421 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 422 | { 423 | texp[max++]=tile[r][c]->tileNum; 424 | retVal=1; 425 | break; 426 | } 427 | } 428 | 429 | r=temp->row; 430 | c=temp->col; 431 | while(c-->0) 432 | { 433 | if(!tile[r][c]->piece) 434 | { 435 | texp[max++]=tile[r][c]->tileNum; 436 | retVal=1; 437 | } 438 | 439 | else if(tile[r][c]->pieceColor==temp->pieceColor) 440 | break; 441 | 442 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 443 | { 444 | texp[max++]=tile[r][c]->tileNum; 445 | retVal=1; 446 | break; 447 | } 448 | } 449 | 450 | 451 | return retVal; 452 | } 453 | 454 | 455 | //HORSE 456 | int RetroChessWindow::validateHorse(Tile *temp) 457 | { 458 | int r,c; 459 | retVal=0; 460 | 461 | r=temp->row; 462 | c=temp->col; 463 | 464 | if(r-2>=0 && c-1>=0) 465 | { 466 | if(tile[r-2][c-1]->pieceColor!=temp->pieceColor || !tile[r-2][c-1]->piece) 467 | { 468 | texp[max++]=tile[r-2][c-1]->tileNum; 469 | retVal=1; 470 | } 471 | } 472 | 473 | if(r-2>=0 && c+1<=7) 474 | { 475 | if(tile[r-2][c+1]->pieceColor!=temp->pieceColor || !tile[r-2][c+1]->piece) 476 | { 477 | texp[max++]=tile[r-2][c+1]->tileNum; 478 | retVal=1; 479 | } 480 | } 481 | 482 | if(r-1>=0 && c-2>=0) 483 | { 484 | if(tile[r-1][c-2]->pieceColor!=temp->pieceColor || !tile[r-1][c-2]->piece) 485 | { 486 | texp[max++]=tile[r-1][c-2]->tileNum; 487 | retVal=1; 488 | } 489 | } 490 | 491 | if(r-1>=0 && c+2<=7) 492 | { 493 | if(tile[r-1][c+2]->pieceColor!=temp->pieceColor || !tile[r-1][c+2]->piece) 494 | { 495 | texp[max++]=tile[r-1][c+2]->tileNum; 496 | retVal=1; 497 | } 498 | } 499 | 500 | if(r+2<=7 && c+1<=7) 501 | { 502 | if(tile[r+2][c+1]->pieceColor!=temp->pieceColor || !tile[r+2][c+1]->piece) 503 | { 504 | texp[max++]=tile[r+2][c+1]->tileNum; 505 | retVal=1; 506 | } 507 | } 508 | 509 | if(r+2<=7 && c-1>=0) 510 | { 511 | if(tile[r+2][c-1]->pieceColor!=temp->pieceColor || !tile[r+2][c-1]->piece) 512 | { 513 | texp[max++]=tile[r+2][c-1]->tileNum; 514 | retVal=1; 515 | } 516 | } 517 | 518 | if(r+1<=7 && c-2>=0) 519 | { 520 | if(tile[r+1][c-2]->pieceColor!=temp->pieceColor || !tile[r+1][c-2]->piece) 521 | { 522 | texp[max++]=tile[r+1][c-2]->tileNum; 523 | retVal=1; 524 | } 525 | } 526 | 527 | if(r+1<=7 && c+2<=7) 528 | { 529 | if(tile[r+1][c+2]->pieceColor!=temp->pieceColor || !tile[r+1][c+2]->piece) 530 | { 531 | texp[max++]=tile[r+1][c+2]->tileNum; 532 | retVal=1; 533 | } 534 | } 535 | 536 | return retVal; 537 | } 538 | 539 | 540 | //KING 541 | int RetroChessWindow::validateKing(Tile *temp) 542 | { 543 | int r,c; 544 | retVal=0; 545 | 546 | r=temp->row; 547 | c=temp->col; 548 | 549 | if(r-1>=0) 550 | { 551 | if(!tile[r-1][c]->piece || tile[r-1][c]->pieceColor!=temp->pieceColor) 552 | { 553 | texp[max++]=tile[r-1][c]->tileNum; 554 | retVal=1; 555 | } 556 | } 557 | 558 | if(r+1<=7) 559 | { 560 | if(!tile[r+1][c]->piece || tile[r+1][c]->pieceColor!=temp->pieceColor) 561 | { 562 | texp[max++]=tile[r+1][c]->tileNum; 563 | retVal=1; 564 | } 565 | } 566 | 567 | if(c-1>=0) 568 | { 569 | if(!tile[r][c-1]->piece || tile[r][c-1]->pieceColor!=temp->pieceColor) 570 | { 571 | texp[max++]=tile[r][c-1]->tileNum; 572 | retVal=1; 573 | } 574 | } 575 | 576 | if(c+1<=7) 577 | { 578 | if(!tile[r][c+1]->piece || tile[r][c+1]->pieceColor!=temp->pieceColor) 579 | { 580 | texp[max++]=tile[r][c+1]->tileNum; 581 | retVal=1; 582 | } 583 | } 584 | 585 | if(r-1>=0 && c-1>=0) 586 | { 587 | if(!tile[r-1][c-1]->piece || tile[r-1][c-1]->pieceColor!=temp->pieceColor) 588 | { 589 | texp[max++]=tile[r-1][c-1]->tileNum; 590 | retVal=1; 591 | } 592 | } 593 | 594 | if(r-1>=0 && c+1<=7) 595 | { 596 | if(!tile[r-1][c+1]->piece || tile[r-1][c+1]->pieceColor!=temp->pieceColor) 597 | { 598 | texp[max++]=tile[r-1][c+1]->tileNum; 599 | retVal=1; 600 | } 601 | } 602 | 603 | if(r+1<=7 && c-1>=0) 604 | { 605 | if(!tile[r+1][c-1]->piece || tile[r+1][c-1]->pieceColor!=temp->pieceColor) 606 | { 607 | texp[max++]=tile[r+1][c-1]->tileNum; 608 | retVal=1; 609 | } 610 | } 611 | 612 | if(r+1<=7 && c+1<=7) 613 | { 614 | if(!tile[r+1][c+1]->piece || tile[r+1][c+1]->pieceColor!=temp->pieceColor) 615 | { 616 | texp[max++]=tile[r+1][c+1]->tileNum; 617 | retVal=1; 618 | } 619 | } 620 | 621 | return retVal; 622 | } 623 | 624 | 625 | //QUEEN 626 | int RetroChessWindow::validateQueen(Tile *temp) 627 | { 628 | int r,c; 629 | 630 | retVal=0; 631 | 632 | r=temp->row; 633 | c=temp->col; 634 | while(r-->0) 635 | { 636 | if(!tile[r][c]->piece) 637 | { 638 | texp[max++]=tile[r][c]->tileNum; 639 | retVal=1; 640 | } 641 | 642 | else if(tile[r][c]->pieceColor==temp->pieceColor) 643 | break; 644 | 645 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 646 | { 647 | texp[max++]=tile[r][c]->tileNum; 648 | retVal=1; 649 | break; 650 | } 651 | } 652 | 653 | r=temp->row; 654 | c=temp->col; 655 | while(r++<7) 656 | { 657 | if(!tile[r][c]->piece) 658 | { 659 | texp[max++]=tile[r][c]->tileNum; 660 | retVal=1; 661 | } 662 | 663 | else if(tile[r][c]->pieceColor==temp->pieceColor) 664 | break; 665 | 666 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 667 | { 668 | texp[max++]=tile[r][c]->tileNum; 669 | retVal=1; 670 | break; 671 | } 672 | } 673 | 674 | r=temp->row; 675 | c=temp->col; 676 | while(c++<7) 677 | { 678 | if(!tile[r][c]->piece) 679 | { 680 | texp[max++]=tile[r][c]->tileNum; 681 | retVal=1; 682 | } 683 | 684 | else if(tile[r][c]->pieceColor==temp->pieceColor) 685 | break; 686 | 687 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 688 | { 689 | texp[max++]=tile[r][c]->tileNum; 690 | retVal=1; 691 | break; 692 | } 693 | } 694 | 695 | r=temp->row; 696 | c=temp->col; 697 | while(c-->0) 698 | { 699 | if(!tile[r][c]->piece) 700 | { 701 | texp[max++]=tile[r][c]->tileNum; 702 | retVal=1; 703 | } 704 | 705 | else if(tile[r][c]->pieceColor==temp->pieceColor) 706 | break; 707 | 708 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 709 | { 710 | texp[max++]=tile[r][c]->tileNum; 711 | retVal=1; 712 | break; 713 | } 714 | } 715 | 716 | r=temp->row; 717 | c=temp->col; 718 | while(r-->0 && c++<7) 719 | { 720 | if(!tile[r][c]->piece) 721 | { 722 | texp[max++]=tile[r][c]->tileNum; 723 | retVal=1; 724 | } 725 | 726 | else if(tile[r][c]->pieceColor==temp->pieceColor) 727 | break; 728 | 729 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 730 | { 731 | texp[max++]=tile[r][c]->tileNum; 732 | retVal=1; 733 | break; 734 | } 735 | } 736 | 737 | r=temp->row; 738 | c=temp->col; 739 | while(r-->0 && c-->0) 740 | { 741 | if(!tile[r][c]->piece) 742 | { 743 | texp[max++]=tile[r][c]->tileNum; 744 | retVal=1; 745 | } 746 | 747 | else if(tile[r][c]->pieceColor==temp->pieceColor) 748 | break; 749 | 750 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 751 | { 752 | texp[max++]=tile[r][c]->tileNum; 753 | retVal=1; 754 | break; 755 | } 756 | } 757 | 758 | r=temp->row; 759 | c=temp->col; 760 | while(r++<7 && c++<7) 761 | { 762 | if(!tile[r][c]->piece) 763 | { 764 | texp[max++]=tile[r][c]->tileNum; 765 | retVal=1; 766 | } 767 | 768 | else if(tile[r][c]->pieceColor==temp->pieceColor) 769 | break; 770 | 771 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 772 | { 773 | texp[max++]=tile[r][c]->tileNum; 774 | retVal=1; 775 | break; 776 | } 777 | } 778 | 779 | r=temp->row; 780 | c=temp->col; 781 | while(r++<7 && c-->0) 782 | { 783 | if(!tile[r][c]->piece) 784 | { 785 | texp[max++]=tile[r][c]->tileNum; 786 | retVal=1; 787 | } 788 | 789 | else if(tile[r][c]->pieceColor==temp->pieceColor) 790 | break; 791 | 792 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 793 | { 794 | texp[max++]=tile[r][c]->tileNum; 795 | retVal=1; 796 | break; 797 | } 798 | } 799 | 800 | 801 | return retVal; 802 | } 803 | 804 | //BISHOP 805 | int RetroChessWindow::validateBishop(Tile *temp) 806 | { 807 | int r,c; 808 | retVal=0; 809 | 810 | r=temp->row; 811 | c=temp->col; 812 | while(r-->0 && c++<7) 813 | { 814 | if(!tile[r][c]->piece) 815 | { 816 | texp[max++]=tile[r][c]->tileNum; 817 | retVal=1; 818 | } 819 | 820 | else if(tile[r][c]->pieceColor==temp->pieceColor) 821 | break; 822 | 823 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 824 | { 825 | texp[max++]=tile[r][c]->tileNum; 826 | retVal=1; 827 | break; 828 | } 829 | } 830 | 831 | r=temp->row; 832 | c=temp->col; 833 | while(r-->0 && c-->0) 834 | { 835 | if(!tile[r][c]->piece) 836 | { 837 | texp[max++]=tile[r][c]->tileNum; 838 | retVal=1; 839 | } 840 | 841 | else if(tile[r][c]->pieceColor==temp->pieceColor) 842 | break; 843 | 844 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 845 | { 846 | texp[max++]=tile[r][c]->tileNum; 847 | retVal=1; 848 | break; 849 | } 850 | } 851 | 852 | r=temp->row; 853 | c=temp->col; 854 | while(r++<7 && c++<7) 855 | { 856 | if(!tile[r][c]->piece) 857 | { 858 | texp[max++]=tile[r][c]->tileNum; 859 | retVal=1; 860 | } 861 | 862 | else if(tile[r][c]->pieceColor==temp->pieceColor) 863 | break; 864 | 865 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 866 | { 867 | texp[max++]=tile[r][c]->tileNum; 868 | retVal=1; 869 | break; 870 | } 871 | } 872 | 873 | r=temp->row; 874 | c=temp->col; 875 | while(r++<7 && c-->0) 876 | { 877 | if(!tile[r][c]->piece) 878 | { 879 | texp[max++]=tile[r][c]->tileNum; 880 | retVal=1; 881 | } 882 | 883 | else if(tile[r][c]->pieceColor==temp->pieceColor) 884 | break; 885 | 886 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 887 | { 888 | texp[max++]=tile[r][c]->tileNum; 889 | retVal=1; 890 | break; 891 | } 892 | } 893 | 894 | return retVal; 895 | } 896 | 897 | int RetroChessWindow::check(Tile *temp) 898 | { 899 | int r,c,flag; 900 | retVal=0; 901 | 902 | return retVal; 903 | } 904 | 905 | void RetroChessWindow::orange() 906 | { 907 | int i,n; 908 | 909 | for(i=0; isetStyleSheet("QLabel {background-color: orange;}"); 911 | } 912 | --------------------------------------------------------------------------------