Permalink
Browse files

friends (partial)

  • Loading branch information...
cflavio committed Jan 10, 2018
1 parent 78a5ffb commit 375edba86291a291326844095eb39f603674c963
Showing with 55 additions and 6 deletions.
  1. +52 −4 menu/multiplayerfrm.py
  2. +2 −1 project.py
  3. +1 −1 yyagl
View
@@ -19,7 +19,7 @@
class UserFrm(Subject):
def __init__(self, name, name_full, is_supporter, pos, parent, menu_args, msg_btn_x=.65):
def __init__(self, name, name_full, is_supporter, pos, parent, menu_args, msg_btn_x=.58):
Subject.__init__(self)
self.name_full = name_full
self.menu_args = menu_args
@@ -108,7 +108,7 @@ def destroy(self):
class UserFrmList(UserFrm):
def __init__(self, name, name_full, is_supporter, pos, parent, menu_args):
def __init__(self, name, name_full, is_supporter, is_friend, pos, parent, menu_args):
UserFrm.__init__(self, name, name_full, is_supporter, pos, parent, menu_args)
lab_args = menu_args.label_args
lab_args['scale'] = .046
@@ -117,7 +117,7 @@ def __init__(self, name, name_full, is_supporter, pos, parent, menu_args):
self.invite_btn = ImgBtn(
parent=self.frm,
scale=.024,
pos=(.72, 1, .01),
pos=(.65, 1, .01),
frameColor=(1, 1, 1, 1),
frameTexture='assets/images/gui/invite.txo',
command=self.on_invite,
@@ -133,6 +133,25 @@ def __init__(self, name, name_full, is_supporter, pos, parent, menu_args):
text_wordwrap=10, **lab_args)
self.invite_tooltip.set_bin('gui-popup', 10)
self.invite_tooltip.hide()
self.friend_btn = ImgBtn(
parent=self.frm,
scale=.024,
pos=(.72, 1, .01),
frameColor=(1, 1, 1, 1),
frameTexture='assets/images/gui/friend.txo',
command=self.on_friend,
extraArgs=[self.name_full],
**menu_args.imgbtn_args)
self.friend_btn.bind(ENTER, self.on_enter_friend)
self.friend_btn.bind(EXIT, self.on_exit_friend)
self.friend_btn.hide()
self.friend_tooltip = DirectLabel(
text=_('add to xmpp friends'),
pos=self.friend_btn.get_pos() + (.01, 0, -.08), parent=self.frm,
text_bg=(.2, .2, .2, .8), text_align=TextNode.A_right,
text_wordwrap=10, **lab_args)
self.friend_tooltip.set_bin('gui-popup', 10)
self.friend_tooltip.hide()
def show_invite_btn(self, show=True):
self.__show_invite_btn = show
@@ -142,10 +161,13 @@ def on_enter(self, pos):
if self.invite_btn.is_hidden():
self.invite_btn.show()
if not self.__show_invite_btn: self.invite_btn.disable()
if self.friend_btn.is_hidden():
self.friend_btn.show()
def on_exit(self, pos):
UserFrm.on_exit(self, pos)
if not self.invite_btn.is_hidden(): self.invite_btn.hide()
if not self.friend_btn.is_hidden(): self.friend_btn.hide()
def on_invite(self, usr):
print 'invite ' + usr.name
@@ -160,6 +182,19 @@ def on_exit_invite(self, pos):
self.on_exit(pos)
self.invite_tooltip.hide()
def on_friend(self, usr):
print 'friend ' + usr.name
self.friend_btn.disable()
self.notify('on_friend', usr)
def on_enter_friend(self, pos):
self.on_enter(pos)
self.friend_tooltip.show()
def on_exit_friend(self, pos):
self.on_exit(pos)
self.friend_tooltip.hide()
class MultiplayerFrm(GameObject):
@@ -249,9 +284,17 @@ def on_users(self):
label_users = [lab.lab['text'] for lab in self.labels]
for i, user in enumerate(self.eng.xmpp.users):
if self.trunc(user.name, 20) not in label_users:
lab = UserFrmList(self.trunc(user.name, 20), user, user.is_supporter, (0, 1, top - .08 -.08 * i), self.frm.getCanvas(), self.menu_args)
lab = UserFrmList(
self.trunc(user.name, 20),
user,
user.is_supporter,
self.eng.xmpp.is_friend(user.name),
(0, 1, top - .08 -.08 * i),
self.frm.getCanvas(),
self.menu_args)
self.labels += [lab]
lab.attach(self.on_invite)
lab.attach(self.on_friend)
else:
lab = [lab for lab in self.labels if lab.lab['text'] == self.trunc(user.name, 20)][0]
lab.show_invite_btn(invite_btn and user.name not in self.invited_users)
@@ -267,6 +310,11 @@ def on_invite(self, usr):
self.on_users() # refactor: it's slow - don't recreate but edit
# current entries
def on_friend(self, usr):
self.eng.xmpp.xmpp.send_presence_subscription(
usr.name,
pfrom=self.eng.xmpp.xmpp.boundjid.full)
def on_start(self):
print 'start'
View
@@ -3,8 +3,9 @@
# TODO LIST =====
# 0.9 (network)
# keepalive: use domethodlaters in place of active polling
# scons generate pdf for server
# manage friends
# try managing presences only with xmpp
# do a message box with a top bar with left/right arrow for changing the room
# do a rapid start for network
# bind a unique code to each fired weapon (so, don't lookup)
2 yyagl
Submodule yyagl updated 1 files
+15 −0 engine/network/xmpp.py

0 comments on commit 375edba

Please sign in to comment.