mirror of
https://github.com/Sneed-Group/Poodletooth-iLand
synced 2024-12-27 13:42:28 -06:00
239 lines
No EOL
8.1 KiB
Python
Executable file
239 lines
No EOL
8.1 KiB
Python
Executable file
from direct.directnotify import DirectNotifyGlobal
|
|
from direct.fsm import FSM
|
|
from direct.gui.DirectGui import *
|
|
from direct.task import Task
|
|
from pandac.PandaModules import *
|
|
import sys
|
|
|
|
from otp.chat.ChatInputTyped import ChatInputTyped
|
|
from otp.otpbase import OTPGlobals
|
|
from otp.otpbase import OTPLocalizer
|
|
from toontown.chat.ChatGlobals import *
|
|
|
|
|
|
class ChatInputWhiteListFrame(FSM.FSM, DirectFrame):
|
|
notify = DirectNotifyGlobal.directNotify.newCategory('ChatInputWhiteList')
|
|
|
|
def __init__(self, entryOptions, parent = None, **kw):
|
|
FSM.FSM.__init__(self, 'ChatInputWhiteListFrame')
|
|
self.receiverId = None
|
|
DirectFrame.__init__(self, parent=aspect2dp, pos=(0, 0, 0.3), relief=None, image=DGG.getDefaultDialogGeom(), image_scale=(1.6, 1, 1.4), image_pos=(0, 0, -0.05), image_color=OTPGlobals.GlobalDialogColor, borderWidth=(0.01, 0.01))
|
|
optiondefs = {'parent': self,
|
|
'relief': DGG.SUNKEN,
|
|
'scale': 0.05,
|
|
'frameSize': (-0.2,
|
|
25.3,
|
|
-0.5,
|
|
1.2),
|
|
'borderWidth': (0.1, 0.1),
|
|
'frameColor': (0.9, 0.9, 0.85, 0.8),
|
|
'pos': (-0.2, 0, 0.11),
|
|
'entryFont': OTPGlobals.getInterfaceFont(),
|
|
'width': 8.6,
|
|
'numLines': 3,
|
|
'cursorKeys': 1,
|
|
'backgroundFocus': 0,
|
|
'suppressKeys': 1,
|
|
'suppressMouse': 1,
|
|
'command': self.sendChat,
|
|
'focus': 0,
|
|
'text': '',
|
|
'sortOrder': DGG.FOREGROUND_SORT_INDEX}
|
|
entryOptions['parent'] = self
|
|
self.chatEntry = DirectEntry(**entryOptions)
|
|
self.whisperId = None
|
|
self.chatEntry.bind(DGG.OVERFLOW, self.chatOverflow)
|
|
self.wantHistory = base.config.GetBool('want-chat-history', 0)
|
|
self.history = ['']
|
|
self.historySize = base.config.GetInt('chat-history-size', 10)
|
|
self.historyIndex = 0
|
|
self.promoteWhiteList = 0
|
|
self.whiteList = None
|
|
self.active = 0
|
|
self.autoOff = 0
|
|
self.sendBy = 'Mode'
|
|
self.prefilter = 1
|
|
from direct.gui import DirectGuiGlobals
|
|
self.chatEntry.bind(DirectGuiGlobals.TYPE, self.applyFilter)
|
|
self.chatEntry.bind(DirectGuiGlobals.ERASE, self.applyFilter)
|
|
tpMgr = TextPropertiesManager.getGlobalPtr()
|
|
Red = tpMgr.getProperties('red')
|
|
Red.setTextColor(1.0, 0.0, 0.0, 1)
|
|
tpMgr.setProperties('WLRed', Red)
|
|
del tpMgr
|
|
self.origFrameColor = self.chatEntry['frameColor']
|
|
return
|
|
|
|
def destroy(self):
|
|
from direct.gui import DirectGuiGlobals
|
|
self.chatEntry.unbind(DGG.OVERFLOW)
|
|
self.chatEntry.unbind(DirectGuiGlobals.TYPE)
|
|
self.chatEntry.unbind(DirectGuiGlobals.ERASE)
|
|
self.chatEntry.ignoreAll()
|
|
DirectFrame.destroy(self)
|
|
|
|
def delete(self):
|
|
self.ignore('arrow_up-up')
|
|
self.ignore('arrow_down-up')
|
|
|
|
def requestMode(self, mode, *args):
|
|
return self.request(mode, *args)
|
|
|
|
def defaultFilter(self, request, *args):
|
|
if request == 'AllChat':
|
|
if not base.talkAssistant.checkAnyTypedChat():
|
|
messenger.send('Chat-Failed open typed chat test')
|
|
self.notify.warning('Chat-Failed open typed chat test')
|
|
return None
|
|
elif request == 'AvatarWhisper':
|
|
if not base.talkAssistant.checkWhisperTypedChatAvatar(self.whisperId):
|
|
messenger.send('Chat-Failed avatar typed chat test')
|
|
self.notify.warning('Chat-Failed avatar typed chat test')
|
|
return None
|
|
return FSM.FSM.defaultFilter(self, request, *args)
|
|
|
|
def enterOff(self):
|
|
self.deactivate()
|
|
localAvatar.chatMgr.fsm.request('mainMenu')
|
|
|
|
def exitOff(self):
|
|
self.activate()
|
|
|
|
def enterAllChat(self):
|
|
self.chatEntry['focus'] = 1
|
|
self.show()
|
|
|
|
def exitAllChat(self):
|
|
pass
|
|
|
|
def enterAvatarWhisper(self):
|
|
self.tempText = self.chatEntry.get()
|
|
self.activate()
|
|
|
|
def exitAvatarWhisper(self):
|
|
self.chatEntry.set(self.tempText)
|
|
self.whisperId = None
|
|
return
|
|
|
|
def activateByData(self, receiverId = None):
|
|
self.receiverId = receiverId
|
|
result = None
|
|
if not self.receiverId:
|
|
result = self.requestMode('AllChat')
|
|
elif self.receiverId:
|
|
self.whisperId = receiverId
|
|
result = self.requestMode('AvatarWhisper')
|
|
return result
|
|
|
|
def activate(self):
|
|
self.chatEntry['focus'] = 1
|
|
self.show()
|
|
self.active = 1
|
|
self.chatEntry.guiItem.setAcceptEnabled(True)
|
|
|
|
def deactivate(self):
|
|
self.chatEntry.set('')
|
|
self.chatEntry['focus'] = 0
|
|
self.hide()
|
|
self.active = 0
|
|
|
|
def isActive(self):
|
|
return self.active
|
|
|
|
def sendChat(self, text, overflow = False):
|
|
if not (len(text) > 0 and text[0] in ['~', '>']):
|
|
if self.prefilter:
|
|
words = text.split(' ')
|
|
newwords = []
|
|
for word in words:
|
|
if word == '' or self.whiteList.isWord(word) or self.promoteWhiteList:
|
|
newwords.append(word)
|
|
else:
|
|
newwords.append(base.whiteList.defaultWord)
|
|
|
|
text = ' '.join(newwords)
|
|
else:
|
|
text = self.chatEntry.get(plain=True)
|
|
|
|
if text:
|
|
self.chatEntry.set('')
|
|
|
|
try:
|
|
text.decode('ascii')
|
|
self.sendChatBySwitch(text)
|
|
|
|
if self.wantHistory:
|
|
self.addToHistory(text)
|
|
except UnicodeEncodeError:
|
|
base.localAvatar.setSystemMessage(0, OTPLocalizer.AsciiNotSupported)
|
|
|
|
if not overflow:
|
|
self.hide()
|
|
if self.autoOff:
|
|
self.requestMode('Off')
|
|
|
|
localAvatar.chatMgr.messageSent()
|
|
|
|
def sendChatBySwitch(self, text):
|
|
if len(text) > 0 and text[0] == '~':
|
|
base.talkAssistant.sendOpenTalk(text)
|
|
elif self.sendBy == 'Mode':
|
|
self.sendChatByMode(text)
|
|
elif self.sendBy == 'Data':
|
|
self.sendChatByData(text)
|
|
else:
|
|
self.sendChatByMode(text)
|
|
|
|
def sendChatByData(self, text):
|
|
if self.receiverId:
|
|
base.talkAssistant.sendWhisperTalk(text, self.receiverId)
|
|
else:
|
|
base.talkAssistant.sendOpenTalk(text)
|
|
|
|
def sendChatByMode(self, text):
|
|
state = self.getCurrentOrNextState()
|
|
messenger.send('sentRegularChat')
|
|
if state == 'AvatarWhisper':
|
|
base.talkAssistant.sendAvatarWhisperWLChat(text, self.whisperId)
|
|
else:
|
|
base.talkAssistant.sendOpenTalk(text)
|
|
|
|
def chatOverflow(self, overflowText):
|
|
self.notify.debug('chatOverflow')
|
|
self.sendChat(self.chatEntry.get(plain=True), overflow=True)
|
|
|
|
def addToHistory(self, text):
|
|
self.history = [text] + self.history[:self.historySize - 1]
|
|
self.historyIndex = 0
|
|
|
|
def getPrevHistory(self):
|
|
self.chatEntry.set(self.history[self.historyIndex])
|
|
self.historyIndex += 1
|
|
self.historyIndex %= len(self.history)
|
|
|
|
def getNextHistory(self):
|
|
self.chatEntry.set(self.history[self.historyIndex])
|
|
self.historyIndex -= 1
|
|
self.historyIndex %= len(self.history)
|
|
|
|
def applyFilter(self, keyArgs, strict = False):
|
|
text = self.chatEntry.get(plain=True)
|
|
|
|
if not text.startswith('~'):
|
|
words = text.split(' ')
|
|
newwords = []
|
|
self.notify.debug('%s' % words)
|
|
for word in words:
|
|
if word == '' or self.whiteList.isWord(word):
|
|
newwords.append(word)
|
|
else:
|
|
newwords.append('\x01WLEnter\x01' + word + '\x02')
|
|
|
|
if not strict:
|
|
lastword = words[-1]
|
|
if lastword == '' or self.whiteList.isPrefix(lastword):
|
|
newwords[-1] = lastword
|
|
else:
|
|
newwords[-1] = '\x01WLEnter\x01' + lastword + '\x02'
|
|
newtext = ' '.join(newwords)
|
|
self.chatEntry.set(newtext) |