Skip to content

Commit

Permalink
Add Notification if you game is full #233
Browse files Browse the repository at this point in the history
  • Loading branch information
IDragonfire committed Oct 29, 2015
1 parent 1a65ded commit f9c7ef5
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
Binary file added res/client/flag.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/games/_gameswidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ def processGameInfo(self, message):
else:
self.games[uid].update(message, self.client)

# Notification if I am in the game and it is full
if self.client.login in message['teams'] \
and message.get('num_players', 0) >= message.get('max_players', 12):
self.client.notificationSystem.on_event(ns.NotificationSystem.GAME_FULL,{})

# Hide private games
if self.hideGamesWithPw.isChecked() and message['state'] == 'open' and not message['password_protected']:
self.games[uid].setHidden(True)
Expand Down
5 changes: 5 additions & 0 deletions src/notificatation_system/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class NotificationSystem():
USER_ONLINE = 'user_online'
NEW_GAME = 'new_game'
GAME_FULL = 'team_full'

def __init__(self, client):
self.client = client
Expand All @@ -26,6 +27,7 @@ def __init__(self, client):
self.settings = NsSettingsDialog(self.client)

self.user = util.icon("client/user.png", pix=True)
self.flag = util.icon("client/flag.png", pix=True)

def isDisabled(self):
return self.disabledStartup or not self.settings.enabled
Expand Down Expand Up @@ -94,6 +96,9 @@ def showEvent(self):

modhtml = '' if (modstr == '') else '<br><font size="-4"><font color="red">mods</font> %s</font>' % modstr
text = '<html>%s<br><font color="silver" size="-2">on</font> %s%s</html>' % (data['title'], maps.getDisplayName(data['mapname']), modhtml)
elif eventType == self.GAME_FULL:
pixmap = self.flag
text = '<html>Game is full.</html>'

self.dialog.newEvent(pixmap, text, self.settings.popup_lifetime, self.settings.soundEnabled(eventType))

Expand Down
12 changes: 12 additions & 0 deletions src/notificatation_system/hook_game_full.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from PyQt4 import QtCore
import util
from notificatation_system.ns_hook import NsHook
import notificatation_system as ns

"""
Settings for notifications: if a my joined game is full.
"""
class NsHookTeamFull(NsHook):
def __init__(self):
NsHook.__init__(self, ns.NotificationSystem.GAME_FULL)
self.button.setEnabled(False)
4 changes: 2 additions & 2 deletions src/notificatation_system/ns_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def newEvent(self, pixmap, text, lifetime, sound):
""" Called to display a new popup
Keyword arguments:
pixmap -- Icon for the event (displayed left)
text- HTMl-Text of the vent (displayed right)
text- HTMl-Text of the event (displayed right)
lifetime -- Display duration
sound -- true|false if should played
"""
Expand All @@ -56,4 +56,4 @@ def hide(self):
# mouseReleaseEvent sometimes not fired
def mousePressEvent(self, event):
if event.button() == QtCore.Qt.RightButton:
self.hide()
self.hide()
7 changes: 4 additions & 3 deletions src/notificatation_system/ns_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import notificatation_system as ns
from notificatation_system.hook_useronline import NsHookUserOnline
from notificatation_system.hook_newgame import NsHookNewGame
from notificatation_system.hook_game_full import NsHookTeamFull

"""
The UI of the Notification System Settings Frame.
Expand All @@ -22,9 +23,9 @@ def __init__(self, client):
self.setWindowFlags(self.windowFlags() & (~QtCore.Qt.WindowContextHelpButtonHint))

# init hooks
self.hooks = {}
self.hooks[ns.NotificationSystem.USER_ONLINE] = NsHookUserOnline()
self.hooks[ns.NotificationSystem.NEW_GAME] = NsHookNewGame()
self.hooks = {ns.NotificationSystem.USER_ONLINE: NsHookUserOnline(),
ns.NotificationSystem.NEW_GAME: NsHookNewGame(),
ns.NotificationSystem.GAME_FULL: NsHookTeamFull()}

model = NotificationHooks(self, self.hooks.values())
self.tableView.setModel(model)
Expand Down

0 comments on commit f9c7ef5

Please sign in to comment.