|
1 | 1 | from fa.replay import replay
|
2 |
| - |
| 2 | +from model.game import GameState |
3 | 3 | import util
|
4 | 4 | from PyQt5 import QtWidgets, QtCore, QtGui
|
5 | 5 | import time
|
@@ -206,10 +206,36 @@ def pingWindow(self):
|
206 | 206 | @QtCore.pyqtSlot(QtCore.QUrl)
|
207 | 207 | def openUrl(self, url):
|
208 | 208 | logger.debug("Clicked on URL: " + url.toString())
|
209 |
| - if url.scheme() == "faflive": |
210 |
| - replay(url) |
211 |
| - elif url.scheme() == "fafgame": |
212 |
| - self.chat_widget.client.joinGameFromURL(url) |
| 209 | + if url.scheme() == "faflive" or url.scheme() == "fafgame": |
| 210 | + replay_id = int(QtCore.QUrlQuery(url).queryItemValue("uid")) |
| 211 | + if replay_id in self.chat_widget.client.gameset: |
| 212 | + game = self.chat_widget.client.gameset[replay_id] |
| 213 | + if game.state == GameState.OPEN: # and url.scheme() == "fafgame" |
| 214 | + self.chat_widget.client.joinGameFromURL(url) |
| 215 | + elif game.state == GameState.PLAYING: |
| 216 | + if game.has_live_replay: |
| 217 | + if url.scheme() == "faflive" or QtWidgets.QMessageBox.question( |
| 218 | + QtWidgets.QApplication.activeWindow(), "Live Game started", |
| 219 | + "Would you like to join and watch the live game?", |
| 220 | + QtWidgets.QMessageBox.Yes, |
| 221 | + QtWidgets.QMessageBox.No) == QtWidgets.QMessageBox.Yes: |
| 222 | + replay(game.url(game.host_player.id)) |
| 223 | + else: |
| 224 | + QtWidgets.QMessageBox.information( |
| 225 | + QtWidgets.QApplication.activeWindow(), "Live Game started", |
| 226 | + "But ... it is to early to join (5 minute delay)\n" |
| 227 | + "(Wait for the user/player status cross to turn silver)") |
| 228 | + elif url.scheme() == "faflive" and QtWidgets.QMessageBox.question( |
| 229 | + QtWidgets.QApplication.activeWindow(), "Live Game ended", |
| 230 | + "Would you like to look for it in Replays?", |
| 231 | + QtWidgets.QMessageBox.Yes, |
| 232 | + QtWidgets.QMessageBox.No) == QtWidgets.QMessageBox.Yes: |
| 233 | + player = QtCore.QUrlQuery(url).queryItemValue("player") |
| 234 | + self.chat_widget.client.searchUserReplays(player) |
| 235 | + elif url.scheme() == "fafgame": |
| 236 | + QtWidgets.QMessageBox.information( |
| 237 | + QtWidgets.QApplication.activeWindow(), "Game ended", |
| 238 | + "Host has abandoned game or the game already ended") |
213 | 239 | else:
|
214 | 240 | QtGui.QDesktopServices.openUrl(url)
|
215 | 241 |
|
|
0 commit comments