Poodletooth-iLand/otp/chat/ChatManager.py

280 lines
9.6 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from direct.directnotify import DirectNotifyGlobal
from direct.fsm import ClassicFSM
from direct.fsm import State
from direct.gui.DirectGui import *
from direct.showbase import DirectObject
from panda3d.core import *
2015-03-03 16:10:12 -06:00
from otp.otpbase import OTPLocalizer
2015-06-24 12:44:04 -05:00
from otp.nametag.NametagConstants import *
2015-05-30 14:47:29 -05:00
import ChatUtil
2015-03-03 16:10:12 -06:00
ChatEvent = 'ChatEvent'
NormalChatEvent = 'NormalChatEvent'
SCChatEvent = 'SCChatEvent'
SCCustomChatEvent = 'SCCustomChatEvent'
SCEmoteChatEvent = 'SCEmoteChatEvent'
class ChatManager(DirectObject.DirectObject):
notify = DirectNotifyGlobal.directNotify.newCategory('ChatManager')
def __init__(self, cr, localAvatar):
self.cr = cr
self.localAvatar = localAvatar
self.wantBackgroundFocus = 1
self.__scObscured = 0
self.__normalObscured = 0
self.noTrueFriends = None
self.noSpeedchatPlus = None
2015-03-03 16:10:12 -06:00
self.fsm = ClassicFSM.ClassicFSM('chatManager', [State.State('off', self.enterOff, self.exitOff),
State.State('mainMenu', self.enterMainMenu, self.exitMainMenu),
State.State('speedChat', self.enterSpeedChat, self.exitSpeedChat),
State.State('normalChat', self.enterNormalChat, self.exitNormalChat),
State.State('whisper', self.enterWhisper, self.exitWhisper),
State.State('whisperChat', self.enterWhisperChat, self.exitWhisperChat),
State.State('whisperSpeedChat', self.enterWhisperSpeedChat, self.exitWhisperSpeedChat),
State.State('noTrueFriends', self.enterNoTrueFriends, self.exitNoTrueFriends),
State.State('noSpeedchatPlus', self.enterNoSpeedchatPlus, self.exitNoSpeedchatPlus),
2015-03-03 16:10:12 -06:00
State.State('otherDialog', self.enterOtherDialog, self.exitOtherDialog),
State.State('whiteListOpenChat', self.enterWhiteListOpenChat, self.exitWhiteListOpenChat),
2015-04-23 12:55:47 -05:00
State.State('whiteListAvatarChat', self.enterWhiteListAvatarChat, self.exitWhiteListAvatarChat)], 'off', 'off')
2015-03-03 16:10:12 -06:00
self.fsm.enterInitialState()
return
def delete(self):
self.ignoreAll()
del self.fsm
if hasattr(self.chatInputNormal, 'destroy'):
self.chatInputNormal.destroy()
self.chatInputNormal.delete()
del self.chatInputNormal
self.chatInputSpeedChat.delete()
del self.chatInputSpeedChat
if self.noTrueFriends:
self.noTrueFriends.destroy()
self.noTrueFriends = None
if self.noSpeedchatPlus:
self.noSpeedchatPlus.destroy()
self.noSpeedchatPlus = None
2015-03-03 16:10:12 -06:00
del self.localAvatar
del self.cr
return
def obscure(self, normal, sc):
self.__scObscured = sc
if self.__scObscured:
self.scButton.hide()
self.__normalObscured = normal
if self.__normalObscured:
self.normalButton.hide()
def isObscured(self):
return (self.__normalObscured, self.__scObscured)
def stop(self):
self.fsm.request('off')
self.ignoreAll()
def start(self):
self.fsm.request('mainMenu')
def announceChat(self):
messenger.send(ChatEvent)
def announceSCChat(self):
messenger.send(SCChatEvent)
self.announceChat()
def sendChatString(self, message):
chatFlags = CFSpeech | CFTimeout
2015-05-30 14:47:29 -05:00
if ChatUtil.isThought(message):
message = ChatUtil.removeThoughtPrefix(message)
2015-03-03 16:10:12 -06:00
chatFlags = CFThought
messenger.send(NormalChatEvent)
self.announceChat()
def sendWhisperString(self, message, whisperAvatarId):
pass
def sendSCChatMessage(self, msgIndex):
base.talkAssistant.sendOpenSpeedChat(1, msgIndex)
2015-04-23 12:55:47 -05:00
def sendSCWhisperMessage(self, msgIndex, whisperAvatarId):
base.talkAssistant.sendAvatarWhisperSpeedChat(1, msgIndex, whisperAvatarId)
2015-03-03 16:10:12 -06:00
def sendSCCustomChatMessage(self, msgIndex):
base.talkAssistant.sendOpenSpeedChat(3, msgIndex)
2015-04-23 12:55:47 -05:00
def sendSCCustomWhisperMessage(self, msgIndex, whisperAvatarId):
base.talkAssistant.sendAvatarWhisperSpeedChat(3, msgIndex, whisperAvatarId)
2015-03-03 16:10:12 -06:00
def sendSCEmoteChatMessage(self, emoteId):
base.talkAssistant.sendOpenSpeedChat(2, emoteId)
2015-04-23 12:55:47 -05:00
def sendSCEmoteWhisperMessage(self, emoteId, whisperAvatarId):
base.talkAssistant.sendAvatarWhisperSpeedChat(2, emoteId, whisperAvatarId)
2015-03-03 16:10:12 -06:00
def enterOff(self):
self.scButton.hide()
self.normalButton.hide()
self.ignoreAll()
def exitOff(self):
pass
def enterMainMenu(self):
self.checkObscurred()
2015-08-27 07:15:57 -05:00
if base.cr.wantTypedChat():
2015-03-03 16:10:12 -06:00
if self.wantBackgroundFocus:
self.chatInputNormal.chatEntry['backgroundFocus'] = 1
self.acceptOnce('enterNormalChat', self.fsm.request, ['normalChat'])
def checkObscurred(self):
if not self.__scObscured:
self.scButton.show()
if not self.__normalObscured:
self.normalButton.show()
def exitMainMenu(self):
self.scButton.hide()
self.normalButton.hide()
self.ignore('enterNormalChat')
if self.wantBackgroundFocus:
self.chatInputNormal.chatEntry['backgroundFocus'] = 0
2015-04-23 12:55:47 -05:00
def whisperTo(self, avatarName, avatarId):
self.fsm.request('whisper', [avatarName, avatarId])
2015-03-03 16:10:12 -06:00
def noWhisper(self):
self.fsm.request('mainMenu')
def handleWhiteListSelect(self):
self.fsm.request('whiteListOpenChat')
def enterWhiteListOpenChat(self):
self.checkObscurred()
if self.wantBackgroundFocus:
self.chatInputNormal.chatEntry['backgroundFocus'] = 0
base.localAvatar.chatMgr.chatInputWhiteList.activateByData()
def exitWhiteListOpenChat(self):
pass
def enterWhiteListAvatarChat(self, receiverId):
if self.wantBackgroundFocus:
self.chatInputNormal.chatEntry['backgroundFocus'] = 0
2015-04-23 12:55:47 -05:00
base.localAvatar.chatMgr.chatInputWhiteList.activateByData(receiverId)
2015-03-03 16:10:12 -06:00
def exitWhiteListAvatarChat(self):
pass
2015-04-23 12:55:47 -05:00
def enterWhisper(self, avatarName, avatarId):
self.whisperScButton['extraArgs'] = [avatarName, avatarId]
self.whisperButton['extraArgs'] = [avatarName, avatarId]
2015-03-03 16:10:12 -06:00
online = 0
if avatarId in self.cr.doId2do:
online = 1
elif self.cr.isFriend(avatarId):
online = self.cr.isFriendOnline(avatarId)
avatarUnderstandable = 0
av = None
if avatarId:
av = self.cr.identifyAvatar(avatarId)
if av != None:
avatarUnderstandable = av.isUnderstandable()
2015-04-23 12:55:47 -05:00
chatName = avatarName
2015-03-03 16:10:12 -06:00
normalButtonObscured, scButtonObscured = self.isObscured()
2015-04-23 12:55:47 -05:00
if avatarUnderstandable and online and not normalButtonObscured:
2015-03-03 16:10:12 -06:00
self.whisperButton['state'] = 'normal'
self.enablewhisperButton()
else:
self.whisperButton['state'] = 'inactive'
self.disablewhisperButton()
if online:
self.whisperScButton['state'] = 'normal'
self.whisperButton['state'] = 'normal'
self.changeFrameText(OTPLocalizer.ChatManagerWhisperToName % chatName)
else:
self.whisperScButton['state'] = 'inactive'
self.whisperButton['state'] = 'inactive'
self.changeFrameText(OTPLocalizer.ChatManagerWhisperOffline % chatName)
self.whisperFrame.show()
self.refreshWhisperFrame()
2015-04-23 12:55:47 -05:00
if avatarUnderstandable and online:
if self.wantBackgroundFocus:
self.chatInputNormal.chatEntry['backgroundFocus'] = 1
self.acceptOnce('enterNormalChat', self.fsm.request, ['whisperChat', [avatarName, avatarId]])
2015-03-03 16:10:12 -06:00
def disablewhisperButton(self):
pass
def enablewhisperButton(self):
pass
def refreshWhisperFrame(self):
pass
def changeFrameText(self, newText):
self.whisperFrame['text'] = newText
def exitWhisper(self):
self.whisperFrame.hide()
self.ignore('enterNormalChat')
self.chatInputNormal.chatEntry['backgroundFocus'] = 0
def enterWhisperSpeedChat(self, avatarId):
self.whisperFrame.show()
if self.wantBackgroundFocus:
self.chatInputNormal.chatEntry['backgroundFocus'] = 0
self.chatInputSpeedChat.show(avatarId)
def exitWhisperSpeedChat(self):
self.whisperFrame.hide()
self.chatInputSpeedChat.hide()
def enterWhisperChat(self, avatarName, avatarId):
result = self.chatInputNormal.activateByData(avatarId)
return result
def exitWhisperChat(self):
self.chatInputNormal.deactivate()
def enterSpeedChat(self):
messenger.send('enterSpeedChat')
if not self.__scObscured:
self.scButton.show()
if not self.__normalObscured:
self.normalButton.show()
if self.wantBackgroundFocus:
self.chatInputNormal.chatEntry['backgroundFocus'] = 0
self.chatInputSpeedChat.show()
def exitSpeedChat(self):
self.scButton.hide()
self.normalButton.hide()
self.chatInputSpeedChat.hide()
def enterNormalChat(self):
result = self.chatInputNormal.activateByData()
return result
def exitNormalChat(self):
self.chatInputNormal.deactivate()
def enterNoTrueFriends(self):
self.notify.error('called enterNoTrueFriends() on parent class')
2015-03-03 16:10:12 -06:00
def exitNoTrueFriends(self):
self.notify.error('called exitNoTrueFriends() on parent class')
2015-03-03 16:10:12 -06:00
def enterNoSpeedchatPlus(self):
self.notify.error('called enterNoSpeedchatPlus() on parent class')
2015-03-03 16:10:12 -06:00
def exitNoSpeedchatPlus(self):
self.notify.error('called exitNoSpeedchatPlus() on parent class')
2015-03-03 16:10:12 -06:00
def enterOtherDialog(self):
pass
def exitOtherDialog(self):
2015-07-05 18:59:25 -05:00
pass