Poodletooth-iLand/toontown/friends/FriendsListManager.py

136 lines
5.2 KiB
Python
Raw Normal View History

from panda3d.core import *
2015-03-03 16:10:12 -06:00
import FriendsListPanel
import FriendInviter
import FriendInvitee
from direct.directnotify import DirectNotifyGlobal
from toontown.toon import ToonTeleportPanel
2015-07-31 06:45:00 -05:00
from toontown.friends import ToontownFriendSecret
2015-03-03 16:10:12 -06:00
from toontown.pets import PetAvatarPanel
from toontown.toon import ToonAvatarPanel
from toontown.suit import SuitAvatarPanel
from toontown.toon import ToonDNA
from toontown.toon import ToonAvatarDetailPanel
from toontown.toonbase import ToontownGlobals
from toontown.toon import Toon
import FriendHandle
from otp.otpbase import OTPGlobals
2015-06-24 13:09:51 -05:00
from otp.nametag import NametagGlobals
2015-03-03 16:10:12 -06:00
class FriendsListManager:
notify = DirectNotifyGlobal.directNotify.newCategory('FriendsListManager')
def __init__(self):
self.avatarPanel = None
self._preserveFriendsList = False
self._entered = False
self.friendsRequestQueue = []
def load(self):
2015-08-14 11:30:11 -05:00
pass
2015-03-03 16:10:12 -06:00
def unload(self):
self.exitFLM()
if self.avatarPanel:
del self.avatarPanel
FriendInviter.unloadFriendInviter()
ToonAvatarDetailPanel.unloadAvatarDetail()
ToonTeleportPanel.unloadTeleportPanel()
return
def enterFLM(self):
self.notify.debug('FriendsListManager: enterFLM()')
if self._preserveFriendsList:
self._preserveFriendsList = 0
return
self._entered = True
self.accept('openFriendsList', self.__openFriendsList)
self.accept('clickedNametag', self.__handleClickedNametag)
base.localAvatar.setFriendsListButtonActive(1)
2015-06-24 13:09:51 -05:00
NametagGlobals.setMasterNametagsActive(1)
2015-03-03 16:10:12 -06:00
self.accept('gotoAvatar', self.__handleGotoAvatar)
self.accept('friendAvatar', self.__handleFriendAvatar)
self.accept('avatarDetails', self.__handleAvatarDetails)
self.accept('friendInvitation', self.__handleFriendInvitation)
if base.cr.friendManager:
base.cr.friendManager.setAvailable(1)
def exitFLM(self):
self.notify.debug('FriendsListManager: exitFLM()')
if self._preserveFriendsList:
return
if not self._entered:
return
self._entered = False
self.ignore('openFriendsList')
self.ignore('clickedNametag')
base.localAvatar.setFriendsListButtonActive(0)
2015-06-24 13:09:51 -05:00
NametagGlobals.setMasterNametagsActive(0)
2015-03-03 16:10:12 -06:00
if self.avatarPanel:
self.avatarPanel.cleanup()
self.avatarPanel = None
self.ignore('gotoAvatar')
self.ignore('friendAvatar')
self.ignore('avatarDetails')
FriendsListPanel.hideFriendsList()
2015-07-31 06:45:00 -05:00
ToontownFriendSecret.hideFriendSecret()
2015-03-03 16:10:12 -06:00
if base.cr.friendManager:
base.cr.friendManager.setAvailable(0)
self.ignore('friendInvitation')
FriendInviter.hideFriendInviter()
ToonAvatarDetailPanel.hideAvatarDetail()
ToonTeleportPanel.hideTeleportPanel()
return
def __openFriendsList(self):
FriendsListPanel.showFriendsList()
2015-04-23 12:55:47 -05:00
def __handleClickedNametag(self, avatar):
2015-03-03 16:10:12 -06:00
self.notify.debug('__handleClickedNametag. doId = %s' % avatar.doId)
if avatar.isPet():
self.avatarPanel = PetAvatarPanel.PetAvatarPanel(avatar)
elif isinstance(avatar, Toon.Toon) or isinstance(avatar, FriendHandle.FriendHandle):
if hasattr(self, 'avatarPanel'):
if self.avatarPanel:
if not hasattr(self.avatarPanel, 'getAvId') or self.avatarPanel.getAvId() == avatar.doId:
if not self.avatarPanel.isHidden():
if self.avatarPanel.getType() == 'toon':
return
2015-04-23 12:55:47 -05:00
self.avatarPanel = ToonAvatarPanel.ToonAvatarPanel(avatar)
2015-03-03 16:10:12 -06:00
else:
self.avatarPanel = SuitAvatarPanel.SuitAvatarPanel(avatar)
def __handleGotoAvatar(self, avId, avName, avDisableName):
ToonTeleportPanel.showTeleportPanel(avId, avName, avDisableName)
def __handleFriendAvatar(self, avId, avName, avDisableName):
FriendInviter.showFriendInviter(avId, avName, avDisableName)
def __handleFriendInvitation(self, avId, avName, inviterDna, context):
dna = ToonDNA.ToonDNA()
dna.makeFromNetString(inviterDna)
2015-04-07 13:43:25 -05:00
if not base.localAvatar.isIgnored(avId):
2015-03-03 16:10:12 -06:00
FriendInvitee.FriendInvitee(avId, avName, dna, context)
def processQueuedRequests(self):
if len(self.friendsRequestQueue):
request = self.friendsRequestQueue.pop(0)
self.__processFriendRequest(request[0], request[1], request[2], request[3])
def __processFriendRequest(self, avId, avName, inviterDna = None, context = None):
self.notify.debug('__handleAvatarFriendInvitation')
askerToon = base.cr.doId2do.get(avId)
if askerToon:
self.notify.debug('got toon')
dna = askerToon.getStyle()
2015-04-07 13:43:25 -05:00
if not base.localAvatar.isIgnored(avId):
2015-03-03 16:10:12 -06:00
FriendInvitee.FriendInvitee(avId, avName, dna, context)
else:
self.notify.debug('no toon')
2015-04-23 12:55:47 -05:00
def __handleAvatarDetails(self, avId, avName):
ToonAvatarDetailPanel.showAvatarDetail(avId, avName)
2015-03-03 16:10:12 -06:00
def preserveFriendsList(self):
self.notify.debug('Preserving Friends List')
self._preserveFriendsList = True