Guest User

Untitled

a guest
Aug 9th, 2018
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.84 KB | None | 0 0
  1. import ui
  2. import net
  3. import chat
  4. import player
  5. import app
  6. import localeInfo
  7. import ime
  8. import chr
  9.  
  10. if app.ENABLE_RENEW_MESSENGER_WHISPER:
  11. import uicontact
  12.  
  13. class WhisperButton(ui.Button):
  14. def __init__(self):
  15. ui.Button.__init__(self, "TOP_MOST")
  16.  
  17. def __del__(self):
  18. ui.Button.__del__(self)
  19.  
  20. def SetToolTipText(self, text, x=0, y = 32):
  21. ui.Button.SetToolTipText(self, text, x, y)
  22. self.ToolTipText.Show()
  23.  
  24. def SetToolTipTextWithColor(self, text, color, x=0, y = 32):
  25. ui.Button.SetToolTipText(self, text, x, y)
  26. self.ToolTipText.SetPackedFontColor(color)
  27. self.ToolTipText.Show()
  28.  
  29. def ShowToolTip(self):
  30. if 0 != self.ToolTipText:
  31. self.ToolTipText.Show()
  32.  
  33. def HideToolTip(self):
  34. if 0 != self.ToolTipText:
  35. self.ToolTipText.Show()
  36.  
  37. class WhisperDialog(ui.ScriptWindow):
  38.  
  39. class TextRenderer(ui.Window):
  40. def SetTargetName(self, targetName):
  41. self.targetName = targetName
  42.  
  43. def OnRender(self):
  44. (x, y) = self.GetGlobalPosition()
  45. chat.RenderWhisper(self.targetName, x, y)
  46.  
  47. class ResizeButton(ui.DragButton):
  48.  
  49. def __init__(self):
  50. ui.DragButton.__init__(self)
  51.  
  52. def __del__(self):
  53. ui.DragButton.__del__(self)
  54.  
  55. def OnMouseOverIn(self):
  56. app.SetCursor(app.HVSIZE)
  57.  
  58. def OnMouseOverOut(self):
  59. app.SetCursor(app.NORMAL)
  60.  
  61. def __init__(self, eventMinimize, eventClose):
  62. print "NEW WHISPER DIALOG ----------------------------------------------------------------------------"
  63. ui.ScriptWindow.__init__(self)
  64. self.targetName = ""
  65. self.eventMinimize = eventMinimize
  66. self.eventClose = eventClose
  67. self.eventAcceptTarget = None
  68. if app.ENABLE_RENEW_MESSENGER_WHISPER:
  69. self.InitializeProfileData()
  70.  
  71. def __del__(self):
  72. print "---------------------------------------------------------------------------- DELETE WHISPER DIALOG"
  73. ui.ScriptWindow.__del__(self)
  74.  
  75. def LoadDialog(self):
  76. try:
  77. pyScrLoader = ui.PythonScriptLoader()
  78. if app.ENABLE_RENEW_MESSENGER_WHISPER:
  79. pyScrLoader.LoadScriptFile(self, "UIScript/NewWhisperDialog.py")
  80. else:
  81. pyScrLoader.LoadScriptFile(self, "UIScript/WhisperDialog.py")
  82. except:
  83. import exception
  84. exception.Abort("WhisperDialog.LoadDialog.LoadScript")
  85.  
  86. try:
  87. GetObject=self.GetChild
  88. self.scrollBar = GetObject("scrollbar")
  89. self.titleNameEdit = GetObject("titlename_edit")
  90.  
  91. if not app.ENABLE_RENEW_MESSENGER_WHISPER:
  92. self.titleName = GetObject("titlename")
  93. self.ignoreButton = GetObject("ignorebutton")
  94. self.reportViolentWhisperButton = GetObject("reportviolentwhisperbutton")
  95. self.closeButton = GetObject("closebutton")
  96.  
  97. if app.ENABLE_RENEW_MESSENGER_WHISPER:
  98. self.titleNameEditBar = GetObject("titlename_editBar")
  99.  
  100. self.chatLine = GetObject("chatline")
  101. self.minimizeButton = GetObject("minimizebutton")
  102. self.acceptButton = GetObject("acceptbutton")
  103. self.sendButton = GetObject("sendbutton")
  104. self.board = GetObject("board")
  105. self.editBar = GetObject("editbar")
  106. self.gamemasterMark = GetObject("gamemastermark")
  107. self.acceptButton = GetObject("acceptbutton")
  108.  
  109. if app.ENABLE_RENEW_MESSENGER_WHISPER:
  110. self.Whisper_Profile_Photo_Icon = GetObject("Whisper_Profile_Photo_Icon")
  111. self.Whisper_Profile_Empire_Icon = GetObject("Whisper_Profile_Empire_Icon")
  112. self.Whisper_Profile_Language_Icon = GetObject("Whisper_Profile_Language_Icon")
  113. self.Whisper_Profile_Name_Value = GetObject("Whisper_Profile_Name_Value")
  114. self.Whisper_Profile_Level_Value = GetObject("Whisper_Profile_Level_Value")
  115. self.Whisper_Profile_Status_Value = GetObject("Whisper_Profile_Status_Value")
  116. self.Whisper_Profile_Guild_Value = GetObject("Whisper_Profile_Guild_Value")
  117. self.Whisper_Profile_Birthday_Value = GetObject("Whisper_Profile_Birthday_Value")
  118. self.Whisper_Profile_Location_Value = GetObject("Whisper_Profile_Location_Value")
  119. except:
  120. import exception
  121. exception.Abort("DialogWindow.LoadDialog.BindObject")
  122.  
  123. self.titleNameEdit.SetText("")
  124. self.gamemasterMark.Hide()
  125. self.minimizeButton.SetEvent(ui.__mem_func__(self.Minimize))
  126. self.closeButton.SetEvent(ui.__mem_func__(self.Close))
  127. self.scrollBar.SetPos(1.0)
  128. self.scrollBar.SetScrollEvent(ui.__mem_func__(self.OnScroll))
  129. self.chatLine.SetReturnEvent(ui.__mem_func__(self.SendWhisper))
  130. self.chatLine.SetEscapeEvent(ui.__mem_func__(self.Minimize))
  131. self.chatLine.SetMultiLine()
  132. self.chatLine.OnIMEKeyDown = ui.__mem_func__(self.OnIMEKeyDown)
  133.  
  134. self.sendButton.SetEvent(ui.__mem_func__(self.SendWhisper))
  135. self.titleNameEdit.SetReturnEvent(ui.__mem_func__(self.AcceptTarget))
  136. self.titleNameEdit.SetEscapeEvent(ui.__mem_func__(self.Close))
  137. self.acceptButton.SetEvent(ui.__mem_func__(self.AcceptTarget))
  138.  
  139. self.textRenderer = self.TextRenderer()
  140. self.textRenderer.SetParent(self)
  141. self.textRenderer.SetPosition(20, 28)
  142. self.textRenderer.SetTargetName("")
  143. self.textRenderer.Show()
  144.  
  145. if not app.ENABLE_RENEW_MESSENGER_WHISPER:
  146. self.titleName.SetText("")
  147. self.closeButton.SetEvent(ui.__mem_func__(self.Close))
  148. self.ignoreButton.SetToggleDownEvent(ui.__mem_func__(self.IgnoreTarget))
  149. self.ignoreButton.SetToggleUpEvent(ui.__mem_func__(self.IgnoreTarget))
  150. self.reportViolentWhisperButton.SetEvent(ui.__mem_func__(self.ReportViolentWhisper))
  151.  
  152. self.resizeButton = self.ResizeButton()
  153. self.resizeButton.SetParent(self)
  154. self.resizeButton.SetSize(20, 20)
  155. self.resizeButton.SetPosition(280, 180)
  156. self.resizeButton.SetMoveEvent(ui.__mem_func__(self.ResizeWhisperDialog))
  157. self.resizeButton.Show()
  158.  
  159. self.ResizeWhisperDialog()
  160.  
  161. if app.ENABLE_RENEW_MESSENGER_WHISPER:
  162. self.SetWhisperDialogSize(410, 280)
  163. self.emoticonsDict = {}
  164. for objectEmoticons in xrange(len(uicontact.DICTIONARY['EMOTICONS_NAME_LIST'])):
  165. self.emoticonsDict.update({objectEmoticons : [uicontact.EmoticonDialog(self.board, 10 + (objectEmoticons * 20), 205, lambda argument = objectEmoticons: self.OnSelectEmoticon(argument), objectEmoticons)]})
  166.  
  167. def Destroy(self):
  168.  
  169. self.eventMinimize = None
  170. self.eventClose = None
  171. self.eventAcceptTarget = None
  172.  
  173. if app.ENABLE_RENEW_MESSENGER_WHISPER:
  174. self.InitializeProfileData()
  175.  
  176. self.ClearDictionary()
  177. self.scrollBar.Destroy()
  178. self.titleName = None
  179. self.titleNameEdit = None
  180. self.closeButton = None
  181. self.scrollBar = None
  182. self.chatLine = None
  183. self.sendButton = None
  184. self.minimizeButton = None
  185. self.textRenderer = None
  186. self.board = None
  187. self.editBar = None
  188.  
  189. if not app.ENABLE_RENEW_MESSENGER_WHISPER:
  190. self.ignoreButton = None
  191. self.reportViolentWhisperButton = None
  192. self.acceptButton = None
  193. self.resizeButton = None
  194. self.closeButton = None
  195. self.titleName = None
  196.  
  197. if not app.ENABLE_RENEW_MESSENGER_WHISPER:
  198. def ResizeWhisperDialog(self):
  199. (xPos, yPos) = self.resizeButton.GetLocalPosition()
  200. if xPos < 280:
  201. self.resizeButton.SetPosition(280, yPos)
  202. return
  203. if yPos < 150:
  204. self.resizeButton.SetPosition(xPos, 150)
  205. return
  206. self.SetWhisperDialogSize(xPos + 20, yPos + 20)
  207.  
  208. def SetWhisperDialogSize(self, width, height):
  209. try:
  210.  
  211. max = int((width-90)/6) * 3 - 6
  212.  
  213. self.board.SetSize(width, height)
  214. self.scrollBar.SetPosition(width-25, 35)
  215. self.scrollBar.SetScrollBarSize(height-100)
  216. self.scrollBar.SetPos(1.0)
  217. self.editBar.SetSize(width-18, 50)
  218. self.chatLine.SetSize(width-90, 40)
  219. self.chatLine.SetLimitWidth(width-90)
  220. self.SetSize(width, height)
  221.  
  222. if 0 != self.targetName:
  223. chat.SetWhisperBoxSize(self.targetName, width - 50, height - 90)
  224.  
  225. if localeInfo.IsARABIC():
  226. self.textRenderer.SetPosition(width-20, 28)
  227. self.scrollBar.SetPosition(width-25+self.scrollBar.GetWidth(), 35)
  228. self.editBar.SetPosition(10 + self.editBar.GetWidth(), height-60)
  229. self.sendButton.SetPosition(width - 80 + self.sendButton.GetWidth(), 10)
  230. self.minimizeButton.SetPosition(width - 42 + self.minimizeButton.GetWidth(), 12)
  231. if not app.ENABLE_RENEW_MESSENGER_WHISPER:
  232. self.closeButton.SetPosition(width - 24 + self.closeButton.GetWidth(), 12)
  233. self.chatLine.SetPosition(5 + self.chatLine.GetWidth(), 5)
  234. self.board.SetPosition(self.board.GetWidth(), 0)
  235. else:
  236. self.textRenderer.SetPosition(20, 28)
  237. self.scrollBar.SetPosition(width - 25, 35)
  238. self.editBar.SetPosition(10, height - 60)
  239. self.sendButton.SetPosition(width - 80, 10)
  240.  
  241. if app.ENABLE_RENEW_MESSENGER_WHISPER:
  242. self.minimizeButton.SetPosition(width - 44, 10)
  243. else:
  244. self.minimizeButton.SetPosition(width - 42, 12)
  245.  
  246. if not app.ENABLE_RENEW_MESSENGER_WHISPER:
  247. self.closeButton.SetPosition(width - 24, 12)
  248.  
  249. self.SetChatLineMax(max)
  250.  
  251. except:
  252. import exception
  253. exception.Abort("WhisperDialog.SetWhisperDialogSize.BindObject")
  254.  
  255. def SetChatLineMax(self, max):
  256. self.chatLine.SetMax(max)
  257.  
  258. from grpText import GetSplitingTextLine
  259.  
  260. text = self.chatLine.GetText()
  261. if text:
  262. self.chatLine.SetText(GetSplitingTextLine(text, max, 0))
  263.  
  264. def OpenWithTarget(self, targetName):
  265. if app.ENABLE_RENEW_MESSENGER_WHISPER:
  266. net.SendRequestContactProfilePacket(targetName, 1, "")
  267. chat.CreateWhisper(targetName)
  268.  
  269. if app.ENABLE_RENEW_MESSENGER_WHISPER:
  270. chat.SetWhisperBoxSize(targetName, self.GetWidth() - 60, self.GetHeight() - 110)
  271. self.titleNameEditBar.Hide()
  272. self.SetPosition(170, 0)
  273. else:
  274. chat.SetWhisperBoxSize(targetName, self.GetWidth() - 60, self.GetHeight() - 90)
  275.  
  276. if not app.ENABLE_RENEW_MESSENGER_WHISPER:
  277. self.titleName.SetText(targetName)
  278. self.ignoreButton.Hide()
  279. if app.IsDevStage():
  280. self.reportViolentWhisperButton.Show()
  281. else:
  282. self.reportViolentWhisperButton.Hide()
  283.  
  284. self.chatLine.SetFocus()
  285. self.titleName.SetText(targetName)
  286. self.targetName = targetName
  287. self.textRenderer.SetTargetName(targetName)
  288. self.gamemasterMark.Hide()
  289. self.minimizeButton.Show()
  290. self.titleNameEdit.Hide()
  291. self.ignoreButton.Hide()
  292. if app.IsDevStage():
  293. self.reportViolentWhisperButton.Show()
  294. else:
  295. self.reportViolentWhisperButton.Hide()
  296. self.acceptButton.Hide()
  297. self.gamemasterMark.Hide()
  298. self.minimizeButton.Show()
  299.  
  300. def OpenWithoutTarget(self, event):
  301. if app.ENABLE_RENEW_MESSENGER_WHISPER:
  302. self.titleNameEditBar.Show()
  303. self.SetPosition(250, 0)
  304.  
  305. self.eventAcceptTarget = event
  306. self.gamemasterMark.Hide()
  307. self.titleName.SetText("")
  308. self.titleNameEdit.SetText("")
  309. self.titleNameEdit.SetFocus()
  310. self.targetName = 0
  311. self.titleNameEdit.Show()
  312. self.ignoreButton.Hide()
  313. self.reportViolentWhisperButton.Hide()
  314. self.acceptButton.Show()
  315.  
  316. if not app.ENABLE_RENEW_MESSENGER_WHISPER:
  317. self.titleName.SetText("")
  318. self.minimizeButton.Hide()
  319. self.gamemasterMark.Hide()
  320. self.ignoreButton.Hide()
  321. self.reportViolentWhisperButton.Hide()
  322.  
  323. def SetGameMasterLook(self):
  324. self.gamemasterMark.Show()
  325. self.reportViolentWhisperButton.Hide()
  326.  
  327. def Minimize(self):
  328. self.titleNameEdit.KillFocus()
  329. if app.ENABLE_RENEW_MESSENGER_WHISPER:
  330. self.titleNameEditBar.Hide()
  331. self.acceptButton.Hide()
  332. self.chatLine.KillFocus()
  333. self.Hide()
  334. if None != self.eventMinimize:
  335. if app.ENABLE_RENEW_MESSENGER_WHISPER:
  336. self.eventMinimize(self.targetName, self.job, self.level, self.empire, self.guild, self.language, self.status, self.location, self.year, self.month, self.day)
  337. else:
  338. self.eventMinimize(self.targetName)
  339.  
  340. def Close(self):
  341. chat.ClearWhisper(self.targetName)
  342. self.titleNameEdit.KillFocus()
  343. if app.ENABLE_RENEW_MESSENGER_WHISPER:
  344. self.titleNameEditBar.Hide()
  345. self.acceptButton.Hide()
  346. self.chatLine.KillFocus()
  347. self.Hide()
  348.  
  349. if None != self.eventClose:
  350. self.eventClose(self.targetName)
  351.  
  352. def ReportViolentWhisper(self):
  353. net.SendChatPacket("/reportviolentwhisper " + self.targetName)
  354.  
  355. def IgnoreTarget(self):
  356. net.SendChatPacket("/ignore " + self.targetName)
  357.  
  358. def AcceptTarget(self):
  359. name = self.titleNameEdit.GetText()
  360. if len(name) <= 0:
  361. self.Close()
  362. return
  363.  
  364. if None != self.eventAcceptTarget:
  365. self.titleNameEdit.KillFocus()
  366. self.eventAcceptTarget(name)
  367.  
  368. def OnScroll(self):
  369. chat.SetWhisperPosition(self.targetName, self.scrollBar.GetPos())
  370.  
  371. if app.ENABLE_RENEW_MESSENGER_WHISPER:
  372. def InitializeProfileData(self):
  373. self.job = -1
  374. self.level = -1
  375. self.empire = -1
  376. self.guild = ""
  377. self.language = ""
  378. self.status = ""
  379. self.location = ""
  380. self.year = ""
  381. self.month = ""
  382. self.day = ""
  383. self.lastSentenceStack = []
  384. self.lastSentencePos = 0
  385.  
  386. def OnIMEKeyDown(self, key):
  387. if app.VK_UP == key:
  388. self.__PrevLastSentenceStack()
  389. return TRUE
  390.  
  391. if app.VK_DOWN == key:
  392. self.__NextLastSentenceStack()
  393. return TRUE
  394.  
  395. return FALSE
  396.  
  397. def __PrevLastSentenceStack(self):
  398. if self.lastSentenceStack and self.lastSentencePos < len(self.lastSentenceStack):
  399. self.lastSentencePos += 1
  400. lastSentence = self.lastSentenceStack[- self.lastSentencePos]
  401. self.chatLine.SetText(lastSentence)
  402. self.chatLine.SetEndPosition()
  403.  
  404. def __NextLastSentenceStack(self):
  405. if self.lastSentenceStack and self.lastSentencePos > 1:
  406. self.lastSentencePos -= 1
  407. lastSentence = self.lastSentenceStack[- self.lastSentencePos]
  408. self.chatLine.SetText(lastSentence)
  409. self.chatLine.SetEndPosition()
  410.  
  411. def __PushLastSentenceStack(self, text):
  412. if len(text) <= 0:
  413. return
  414.  
  415. LAST_SENTENCE_STACK_SIZE = 32
  416. if len(self.lastSentenceStack) > LAST_SENTENCE_STACK_SIZE:
  417. self.lastSentenceStack.pop(0)
  418.  
  419. self.lastSentenceStack.append(text)
  420.  
  421. def OnSelectEmoticon(self, key):
  422. self.chatLine.SetText("%s %s" % (self.chatLine.GetText(), uicontact.DICTIONARY['EMOTICONS_KEY_LIST'][key]))
  423. self.chatLine.OnSetFocus()
  424.  
  425. def RecvWhisperProfile(self, job, level, empire, guild, language, status, location, year, month, day):
  426. def get(text):
  427. if not text:
  428. return localeInfo.PROFILE_SELECT_DEFAULT
  429. return text
  430.  
  431. self.job = job
  432. self.level = level
  433. self.empire = empire
  434. self.guild = guild
  435. self.language = language
  436. self.status = status
  437. self.location = location
  438. self.year = year
  439. self.month = month
  440. self.day = day
  441.  
  442. if empire in uicontact.DICTIONARY['EMPIRE_IMAGE_LIST']:
  443. self.Whisper_Profile_Empire_Icon.LoadImage(uicontact.DICTIONARY['EMPIRE_IMAGE_LIST'][empire])
  444.  
  445. if job in uicontact.DICTIONARY['FACE_IMAGE_LIST']:
  446. self.Whisper_Profile_Photo_Icon.LoadImage(uicontact.DICTIONARY['FACE_IMAGE_LIST'][job])
  447.  
  448. if language:
  449. self.Whisper_Profile_Language_Icon.LoadImage(uicontact.DICTIONARY['LANGUAGE_IMAGE_STRING'] % (language))
  450.  
  451. self.Whisper_Profile_Name_Value.SetText(str(self.targetName))
  452. self.Whisper_Profile_Level_Value.SetText(str(level))
  453. self.Whisper_Profile_Guild_Value.SetText(str(guild))
  454. self.Whisper_Profile_Birthday_Value.SetText("%s/%s/%s" % (get(year), get(month), get(day)))
  455.  
  456. if len(location) > 19:
  457. location = location[:16] + "..."
  458. if len(status) > 19:
  459. status = status[:16] + "..."
  460.  
  461. self.Whisper_Profile_Location_Value.SetText(str(location))
  462. self.Whisper_Profile_Status_Value.SetText(str(status))
  463.  
  464. def SendWhisper(self):
  465.  
  466. text = self.chatLine.GetText()
  467. textLength = len(text)
  468.  
  469. if textLength > 0:
  470. if net.IsInsultIn(text):
  471. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.CHAT_INSULT_STRING)
  472. return
  473.  
  474. net.SendWhisperPacket(self.targetName, text)
  475. self.chatLine.SetText("")
  476.  
  477. if app.ENABLE_RENEW_MESSENGER_WHISPER:
  478. self.__PushLastSentenceStack(text)
  479. chat.AppendWhisper(chat.WHISPER_TYPE_CHAT, self.targetName, "%s %s : %s" % (uicontact.GetWhisperSendedTime(), player.GetName(), text))
  480. else:
  481. chat.AppendWhisper(chat.WHISPER_TYPE_CHAT, self.targetName, player.GetName() + " : " + text)
  482.  
  483. def OnTop(self):
  484. if self.chatLine:
  485. self.chatLine.SetFocus()
  486.  
  487. def BindInterface(self, interface):
  488. self.interface = interface
  489.  
  490. def OnMouseLeftButtonDown(self):
  491. hyperlink = ui.GetHyperlink()
  492. if hyperlink:
  493. if app.IsPressed(app.DIK_LALT):
  494. link = chat.GetLinkFromHyperlink(hyperlink)
  495. ime.PasteString(link)
  496. else:
  497. self.interface.MakeHyperlinkTooltip(hyperlink)
  498.  
  499. if "__main__" == __name__:
  500. import uiTest
  501.  
  502. class TestApp(uiTest.App):
  503. def OnInit(self):
  504. wnd = WhisperDialog(self.OnMax, self.OnMin)
  505. wnd.LoadDialog()
  506. wnd.OpenWithoutTarget(self.OnNew)
  507. wnd.SetPosition(0, 0)
  508. wnd.Show()
  509.  
  510. self.wnd = wnd
  511.  
  512. def OnMax(self):
  513. pass
  514.  
  515. def OnMin(self):
  516. pass
  517.  
  518. def OnNew(self):
  519. pass
  520.  
  521. TestApp().MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment