2015-06-23 18:11:48 -05:00
|
|
|
from panda3d.core import *
|
2015-03-03 16:10:12 -06:00
|
|
|
from direct.gui.DirectGui import *
|
|
|
|
from direct.fsm import StateData
|
|
|
|
from toontown.toon import ToonAvatarPanel
|
2015-07-31 06:45:00 -05:00
|
|
|
from toontown.friends import ToontownFriendSecret
|
2015-03-03 16:10:12 -06:00
|
|
|
from toontown.toonbase import ToontownGlobals
|
|
|
|
from toontown.toonbase import TTLocalizer
|
2015-06-24 12:44:04 -05:00
|
|
|
from otp.nametag.NametagGroup import *
|
2015-08-12 06:17:43 -05:00
|
|
|
from otp.nametag.NametagConstants import *
|
2015-03-03 16:10:12 -06:00
|
|
|
from otp.otpbase import OTPGlobals
|
|
|
|
FLPPets = 1
|
|
|
|
FLPOnline = 2
|
|
|
|
FLPAll = 3
|
|
|
|
globalFriendsList = None
|
|
|
|
|
2015-05-31 06:12:48 -05:00
|
|
|
def determineFriendName(friendId):
|
|
|
|
handle = base.cr.identifyFriend(friendId)
|
2015-03-03 16:10:12 -06:00
|
|
|
|
2015-05-31 06:12:48 -05:00
|
|
|
return handle.getName() if handle else ''
|
2015-03-03 16:10:12 -06:00
|
|
|
|
|
|
|
def compareFriends(f1, f2):
|
|
|
|
name1 = determineFriendName(f1)
|
|
|
|
name2 = determineFriendName(f2)
|
|
|
|
if name1 > name2:
|
|
|
|
return 1
|
|
|
|
elif name1 == name2:
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
return -1
|
|
|
|
|
|
|
|
def showFriendsList():
|
|
|
|
global globalFriendsList
|
|
|
|
if globalFriendsList == None:
|
|
|
|
globalFriendsList = FriendsListPanel()
|
|
|
|
globalFriendsList.enter()
|
|
|
|
return
|
|
|
|
|
|
|
|
def hideFriendsList():
|
|
|
|
if globalFriendsList != None:
|
|
|
|
globalFriendsList.exit()
|
|
|
|
return
|
|
|
|
|
|
|
|
def showFriendsListTutorial():
|
|
|
|
global globalFriendsList
|
|
|
|
if globalFriendsList == None:
|
|
|
|
globalFriendsList = FriendsListPanel()
|
|
|
|
globalFriendsList.enter()
|
|
|
|
globalFriendsList.closeCommand = globalFriendsList.close['command']
|
|
|
|
globalFriendsList.close['command'] = None
|
|
|
|
return
|
|
|
|
|
|
|
|
def hideFriendsListTutorial():
|
|
|
|
if globalFriendsList != None:
|
|
|
|
if hasattr(globalFriendsList, 'closeCommand'):
|
|
|
|
globalFriendsList.close['command'] = globalFriendsList.closeCommand
|
|
|
|
globalFriendsList.exit()
|
|
|
|
return
|
|
|
|
|
|
|
|
def isFriendsListShown():
|
|
|
|
if globalFriendsList != None:
|
|
|
|
return globalFriendsList.isEntered
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def unloadFriendsList():
|
|
|
|
global globalFriendsList
|
|
|
|
if globalFriendsList != None:
|
|
|
|
globalFriendsList.unload()
|
|
|
|
globalFriendsList = None
|
|
|
|
return
|
|
|
|
|
|
|
|
class FriendsListPanel(DirectFrame, StateData.StateData):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.leftmostPanel = FLPPets
|
2015-04-23 12:55:47 -05:00
|
|
|
self.rightmostPanel = FLPAll
|
2015-03-03 16:10:12 -06:00
|
|
|
DirectFrame.__init__(self, relief=None)
|
|
|
|
self.listScrollIndex = [0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0]
|
|
|
|
self.initialiseoptions(FriendsListPanel)
|
|
|
|
StateData.StateData.__init__(self, 'friends-list-done')
|
|
|
|
self.friends = {}
|
|
|
|
self.textRolloverColor = Vec4(1, 1, 0, 1)
|
|
|
|
self.textDownColor = Vec4(0.5, 0.9, 1, 1)
|
|
|
|
self.textDisabledColor = Vec4(0.4, 0.8, 0.4, 1)
|
|
|
|
self.panelType = FLPOnline
|
|
|
|
|
|
|
|
def load(self):
|
|
|
|
if self.isLoaded == 1:
|
|
|
|
return None
|
|
|
|
self.isLoaded = 1
|
|
|
|
gui = loader.loadModel('phase_3.5/models/gui/friendslist_gui')
|
|
|
|
auxGui = loader.loadModel('phase_3.5/models/gui/avatar_panel_gui')
|
|
|
|
self.title = DirectLabel(parent=self, relief=None, text='', text_scale=TTLocalizer.FLPtitle, text_fg=(0, 0.1, 0.4, 1), pos=(0.007, 0.0, 0.2))
|
|
|
|
background_image = gui.find('**/FriendsBox_Open')
|
|
|
|
self['image'] = background_image
|
|
|
|
self.reparentTo(base.a2dTopRight)
|
|
|
|
self.setPos(-0.233, 0, -0.46)
|
|
|
|
self.scrollList = DirectScrolledList(parent=self, relief=None, incButton_image=(gui.find('**/FndsLst_ScrollUp'),
|
|
|
|
gui.find('**/FndsLst_ScrollDN'),
|
|
|
|
gui.find('**/FndsLst_ScrollUp_Rllvr'),
|
|
|
|
gui.find('**/FndsLst_ScrollUp')), incButton_relief=None, incButton_pos=(0.0, 0.0, -0.316), incButton_image3_color=Vec4(0.6, 0.6, 0.6, 0.6), incButton_scale=(1.0, 1.0, -1.0), decButton_image=(gui.find('**/FndsLst_ScrollUp'),
|
|
|
|
gui.find('**/FndsLst_ScrollDN'),
|
|
|
|
gui.find('**/FndsLst_ScrollUp_Rllvr'),
|
|
|
|
gui.find('**/FndsLst_ScrollUp')), decButton_relief=None, decButton_pos=(0.0, 0.0, 0.117), decButton_image3_color=Vec4(0.6, 0.6, 0.6, 0.6), itemFrame_pos=(-0.17, 0.0, 0.06), itemFrame_relief=None, numItemsVisible=8, items=[])
|
|
|
|
clipper = PlaneNode('clipper')
|
|
|
|
clipper.setPlane(Plane(Vec3(-1, 0, 0), Point3(0.2, 0, 0)))
|
|
|
|
clipNP = self.scrollList.attachNewNode(clipper)
|
|
|
|
self.scrollList.setClipPlane(clipNP)
|
|
|
|
self.close = DirectButton(parent=self, relief=None, image=(auxGui.find('**/CloseBtn_UP'), auxGui.find('**/CloseBtn_DN'), auxGui.find('**/CloseBtn_Rllvr')), pos=(0.01, 0, -0.38), command=self.__close)
|
|
|
|
self.left = DirectButton(parent=self, relief=None, image=(gui.find('**/Horiz_Arrow_UP'),
|
|
|
|
gui.find('**/Horiz_Arrow_DN'),
|
|
|
|
gui.find('**/Horiz_Arrow_Rllvr'),
|
|
|
|
gui.find('**/Horiz_Arrow_UP')), image3_color=Vec4(0.6, 0.6, 0.6, 0.6), pos=(-0.15, 0.0, -0.38), scale=(-1.0, 1.0, 1.0), command=self.__left)
|
|
|
|
self.right = DirectButton(parent=self, relief=None, image=(gui.find('**/Horiz_Arrow_UP'),
|
|
|
|
gui.find('**/Horiz_Arrow_DN'),
|
|
|
|
gui.find('**/Horiz_Arrow_Rllvr'),
|
|
|
|
gui.find('**/Horiz_Arrow_UP')), image3_color=Vec4(0.6, 0.6, 0.6, 0.6), pos=(0.17, 0, -0.38), command=self.__right)
|
|
|
|
self.newFriend = DirectButton(parent=self, relief=None, pos=(-0.14, 0.0, 0.14), image=(auxGui.find('**/Frnds_Btn_UP'), auxGui.find('**/Frnds_Btn_DN'), auxGui.find('**/Frnds_Btn_RLVR')), text=('', TTLocalizer.FriendsListPanelNewFriend, TTLocalizer.FriendsListPanelNewFriend), text_scale=TTLocalizer.FLPnewFriend, text_fg=(0, 0, 0, 1), text_bg=(1, 1, 1, 1), text_pos=(0.1, -0.085), textMayChange=0, command=self.__newFriend)
|
2015-07-31 06:45:00 -05:00
|
|
|
self.trueFriends = DirectButton(parent=self, relief=None, pos=TTLocalizer.FLPtruefriendsPos, image=(auxGui.find('**/ChtBx_ChtBtn_UP'), auxGui.find('**/ChtBx_ChtBtn_DN'), auxGui.find('**/ChtBx_ChtBtn_RLVR')), text=('',
|
|
|
|
TTLocalizer.FriendsListPanelTrueFriends,
|
|
|
|
TTLocalizer.FriendsListPanelTrueFriends,
|
|
|
|
''), text_scale=TTLocalizer.FLPtruefriends, text_fg=(0, 0, 0, 1), text_bg=(1, 1, 1, 1), text_pos=(-0.04, -0.085), textMayChange=0, command=self.__trueFriends)
|
2015-03-03 16:10:12 -06:00
|
|
|
gui.removeNode()
|
|
|
|
auxGui.removeNode()
|
|
|
|
|
|
|
|
def unload(self):
|
|
|
|
if self.isLoaded == 0:
|
|
|
|
return None
|
|
|
|
self.isLoaded = 0
|
|
|
|
self.exit()
|
|
|
|
del self.title
|
|
|
|
del self.scrollList
|
|
|
|
del self.close
|
|
|
|
del self.left
|
|
|
|
del self.right
|
|
|
|
del self.friends
|
|
|
|
DirectFrame.destroy(self)
|
|
|
|
|
2015-05-31 06:12:48 -05:00
|
|
|
def makeFriendButton(self, avId, color):
|
2015-03-03 16:10:12 -06:00
|
|
|
handle = base.cr.identifyFriend(avId)
|
2015-05-31 06:12:48 -05:00
|
|
|
|
|
|
|
if not handle:
|
2015-04-23 12:55:47 -05:00
|
|
|
base.cr.fillUpFriendsMap()
|
|
|
|
return
|
2015-05-31 06:12:48 -05:00
|
|
|
|
|
|
|
return DirectButton(relief=None, text=handle.getName(), text_scale=0.04, text_align=TextNode.ALeft, text_fg=color, text_shadow=None, text1_bg=self.textDownColor, text2_bg=self.textRolloverColor, text3_fg=self.textDisabledColor, text_font=ToontownGlobals.getToonFont(), textMayChange=0, command=self.__choseFriend, extraArgs=[avId])
|
2015-03-03 16:10:12 -06:00
|
|
|
|
|
|
|
def enter(self):
|
|
|
|
if self.isEntered == 1:
|
|
|
|
return None
|
|
|
|
self.isEntered = 1
|
|
|
|
if self.isLoaded == 0:
|
|
|
|
self.load()
|
|
|
|
base.localAvatar.obscureFriendsListButton(1)
|
|
|
|
if ToonAvatarPanel.ToonAvatarPanel.currentAvatarPanel:
|
|
|
|
ToonAvatarPanel.ToonAvatarPanel.currentAvatarPanel.cleanup()
|
|
|
|
ToonAvatarPanel.ToonAvatarPanel.currentAvatarPanel = None
|
|
|
|
self.__updateScrollList()
|
|
|
|
self.__updateTitle()
|
|
|
|
self.__updateArrows()
|
|
|
|
self.show()
|
|
|
|
self.accept('friendOnline', self.__friendOnline)
|
|
|
|
self.accept('friendOffline', self.__friendOffline)
|
|
|
|
self.accept('friendsListChanged', self.__friendsListChanged)
|
|
|
|
self.accept('friendsMapComplete', self.__friendsListChanged)
|
|
|
|
return
|
|
|
|
|
|
|
|
def exit(self):
|
|
|
|
if self.isEntered == 0:
|
|
|
|
return None
|
|
|
|
self.isEntered = 0
|
|
|
|
self.listScrollIndex[self.panelType] = self.scrollList.index
|
|
|
|
self.hide()
|
|
|
|
base.cr.cleanPetsFromFriendsMap()
|
|
|
|
self.ignore('friendOnline')
|
|
|
|
self.ignore('friendOffline')
|
|
|
|
self.ignore('friendsListChanged')
|
|
|
|
self.ignore('friendsMapComplete')
|
|
|
|
base.localAvatar.obscureFriendsListButton(-1)
|
|
|
|
messenger.send(self.doneEvent)
|
|
|
|
return None
|
|
|
|
|
|
|
|
def __close(self):
|
|
|
|
messenger.send('wakeup')
|
|
|
|
self.exit()
|
|
|
|
|
|
|
|
def __left(self):
|
|
|
|
messenger.send('wakeup')
|
|
|
|
self.listScrollIndex[self.panelType] = self.scrollList.index
|
|
|
|
if self.panelType > self.leftmostPanel:
|
|
|
|
self.panelType -= 1
|
|
|
|
self.__updateScrollList()
|
|
|
|
self.__updateTitle()
|
|
|
|
self.__updateArrows()
|
|
|
|
|
|
|
|
def __right(self):
|
|
|
|
messenger.send('wakeup')
|
|
|
|
self.listScrollIndex[self.panelType] = self.scrollList.index
|
|
|
|
if self.panelType < self.rightmostPanel:
|
|
|
|
self.panelType += 1
|
|
|
|
self.__updateScrollList()
|
|
|
|
self.__updateTitle()
|
|
|
|
self.__updateArrows()
|
|
|
|
|
2015-07-31 06:45:00 -05:00
|
|
|
def __trueFriends(self):
|
|
|
|
messenger.send('wakeup')
|
|
|
|
ToontownFriendSecret.showFriendSecret()
|
|
|
|
|
2015-03-03 16:10:12 -06:00
|
|
|
def __newFriend(self):
|
|
|
|
messenger.send('wakeup')
|
|
|
|
messenger.send('friendAvatar', [None, None, None])
|
|
|
|
|
2015-04-23 12:55:47 -05:00
|
|
|
def __choseFriend(self, friendId):
|
2015-03-03 16:10:12 -06:00
|
|
|
messenger.send('wakeup')
|
|
|
|
handle = base.cr.identifyFriend(friendId)
|
|
|
|
if handle != None:
|
|
|
|
messenger.send('clickedNametag', [handle])
|
|
|
|
|
2015-05-31 06:12:48 -05:00
|
|
|
def createButtons(self, avIds, nametag):
|
|
|
|
avIds.sort(compareFriends)
|
|
|
|
|
|
|
|
for avId in avIds:
|
|
|
|
if avId not in self.friends:
|
|
|
|
button = self.makeFriendButton(avId, nametag)
|
|
|
|
|
|
|
|
if button:
|
|
|
|
self.scrollList.addItem(button, refresh=0)
|
|
|
|
self.friends[avId] = button
|
|
|
|
|
2015-03-03 16:10:12 -06:00
|
|
|
def __updateScrollList(self):
|
|
|
|
petFriends = []
|
2015-05-31 06:12:48 -05:00
|
|
|
trueFriends = []
|
|
|
|
friends = []
|
2015-03-03 16:10:12 -06:00
|
|
|
|
|
|
|
if self.panelType == FLPAll or self.panelType == FLPOnline:
|
|
|
|
if base.wantPets and base.localAvatar.hasPet():
|
2015-05-31 06:12:48 -05:00
|
|
|
petFriends.insert(0, base.localAvatar.getPetId())
|
|
|
|
|
|
|
|
for friendId in base.localAvatar.friendsList:
|
|
|
|
if self.panelType != FLPOnline or base.cr.isFriendOnline(friendId):
|
2015-06-02 12:44:55 -05:00
|
|
|
handle = base.cr.identifyFriend(friendId)
|
|
|
|
|
|
|
|
if not handle:
|
|
|
|
base.cr.fillUpFriendsMap()
|
|
|
|
return
|
|
|
|
|
2015-08-12 06:17:43 -05:00
|
|
|
if base.localAvatar.isTrueFriends(friendId):
|
2015-05-31 06:12:48 -05:00
|
|
|
trueFriends.insert(0, friendId)
|
|
|
|
else:
|
|
|
|
friends.insert(0, friendId)
|
|
|
|
elif self.panelType == FLPPets and base.wantPets:
|
|
|
|
for avId, av in base.cr.doId2do.items():
|
|
|
|
from toontown.pets import DistributedPet
|
|
|
|
if isinstance(av, DistributedPet.DistributedPet):
|
|
|
|
petFriends.append(avId)
|
|
|
|
|
|
|
|
for friendId in self.friends.keys():
|
|
|
|
friendButton = self.friends[friendId]
|
2015-03-03 16:10:12 -06:00
|
|
|
self.scrollList.removeItem(friendButton, refresh=0)
|
|
|
|
friendButton.destroy()
|
2015-05-31 06:12:48 -05:00
|
|
|
del self.friends[friendId]
|
|
|
|
|
2015-06-26 02:09:27 -05:00
|
|
|
self.createButtons(petFriends, NAMETAG_COLORS[CCNonPlayer][0][0])
|
|
|
|
self.createButtons(trueFriends, NAMETAG_COLORS[CCNormal][0][0])
|
|
|
|
self.createButtons(friends, NAMETAG_COLORS[CCSpeedChat][0][0])
|
2015-03-03 16:10:12 -06:00
|
|
|
|
|
|
|
self.scrollList.index = self.listScrollIndex[self.panelType]
|
|
|
|
self.scrollList.refresh()
|
|
|
|
|
|
|
|
def __updateTitle(self):
|
|
|
|
if self.panelType == FLPOnline:
|
|
|
|
self.title['text'] = TTLocalizer.FriendsListPanelOnlineFriends
|
|
|
|
elif self.panelType == FLPAll:
|
|
|
|
self.title['text'] = TTLocalizer.FriendsListPanelAllFriends
|
|
|
|
else:
|
2015-04-23 12:55:47 -05:00
|
|
|
self.title['text'] = TTLocalizer.FriendsListPanelPets
|
2015-03-03 16:10:12 -06:00
|
|
|
self.title.resetFrameSize()
|
|
|
|
|
|
|
|
def __updateArrows(self):
|
|
|
|
if self.panelType == self.leftmostPanel:
|
|
|
|
self.left['state'] = 'inactive'
|
|
|
|
else:
|
|
|
|
self.left['state'] = 'normal'
|
|
|
|
if self.panelType == self.rightmostPanel:
|
|
|
|
self.right['state'] = 'inactive'
|
|
|
|
else:
|
|
|
|
self.right['state'] = 'normal'
|
|
|
|
|
2015-05-30 11:09:41 -05:00
|
|
|
def __friendOnline(self, doId):
|
2015-03-03 16:10:12 -06:00
|
|
|
if self.panelType == FLPOnline:
|
|
|
|
self.__updateScrollList()
|
|
|
|
|
|
|
|
def __friendOffline(self, doId):
|
|
|
|
if self.panelType == FLPOnline:
|
|
|
|
self.__updateScrollList()
|
|
|
|
|
|
|
|
def __friendsListChanged(self, arg1 = None, arg2 = None):
|
2015-07-05 18:59:25 -05:00
|
|
|
self.__updateScrollList()
|