Advertisement
deadx2

Untitled

Sep 15th, 2017
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.75 KB | None | 0 0
  1. import uimg
  2. import net
  3. import chat
  4. import player
  5. import app
  6. import localemg
  7. import ime
  8. import chr
  9.  
  10. class WhisperButton(uimg.Button):
  11.     def __init__(self):
  12.         uimg.Button.__init__(self, "TOP_MOST")
  13.  
  14.     def __del__(self):
  15.         uimg.Button.__del__(self)
  16.  
  17.     def SetToolTipText(self, text, x=0, y = 32):
  18.         uimg.Button.SetToolTipText(self, text, x, y)
  19.         self.ToolTipText.Show()
  20.  
  21.     def SetToolTipTextWithColor(self, text, color, x=0, y = 32):
  22.         uimg.Button.SetToolTipText(self, text, x, y)
  23.         self.ToolTipText.SetPackedFontColor(color)
  24.         self.ToolTipText.Show()
  25.  
  26.     def ShowToolTip(self):
  27.         if 0 != self.ToolTipText:
  28.             self.ToolTipText.Show()
  29.  
  30.     def HideToolTip(self):
  31.         if 0 != self.ToolTipText:
  32.             self.ToolTipText.Show()
  33.  
  34. class WhisperDialog(uimg.ScriptWindow):
  35.  
  36.     class TextRenderer(uimg.Window):
  37.         def SetTargetName(self, targetName):
  38.             self.targetName = targetName
  39.  
  40.         def OnRender(self):
  41.             (x, y) = self.GetGlobalPosition()
  42.             chat.RenderWhisper(self.targetName, x, y)
  43.  
  44.     class ResizeButton(uimg.DragButton):
  45.  
  46.         def __init__(self):
  47.             uimg.DragButton.__init__(self)
  48.  
  49.         def __del__(self):
  50.             uimg.DragButton.__del__(self)
  51.  
  52.         def OnMouseOverIn(self):
  53.             app.SetCursor(app.HVSIZE)
  54.  
  55.         def OnMouseOverOut(self):
  56.             app.SetCursor(app.NORMAL)
  57.  
  58.     def __init__(self, eventMinimize, eventClose):
  59.         print "NEW WHISPER DIALOG  ----------------------------------------------------------------------------"
  60.         uimg.ScriptWindow.__init__(self)
  61.         self.targetName = ""
  62.         self.eventMinimize = eventMinimize
  63.         self.eventClose = eventClose
  64.         self.eventAcceptTarget = None
  65.     def __del__(self):
  66.         print "---------------------------------------------------------------------------- DELETE WHISPER DIALOG"
  67.         uimg.ScriptWindow.__del__(self)    
  68.  
  69.     def LoadDialog(self):
  70.         try:
  71.             pyScrLoader = uimg.PythonScriptLoader()
  72.             pyScrLoader.LoadScriptFile(self, "UIScript/WhisperDialog.py")
  73.         except:
  74.             import exception
  75.             exception.Abort("WhisperDialog.LoadDialog.LoadScript")
  76.  
  77.         try:
  78.             GetObject=self.GetChild
  79.             self.titleName = GetObject("titlename")
  80.             self.titleNameEdit = GetObject("titlename_edit")
  81.             self.closeButton = GetObject("closebutton")
  82.             self.scrollBar = GetObject("scrollbar")
  83.             self.chatLine = GetObject("chatline")
  84.             self.minimizeButton = GetObject("minimizebutton")
  85.             self.ignoreButton = GetObject("ignorebutton")
  86.             self.reportViolentWhisperButton = GetObject("reportviolentwhisperbutton")
  87.             self.acceptButton = GetObject("acceptbutton")
  88.             self.sendButton = GetObject("sendbutton")
  89.             self.board = GetObject("board")
  90.             self.editBar = GetObject("editbar")
  91.             self.gamemasterMark = GetObject("gamemastermark")
  92.         except:
  93.             import exception
  94.             exception.Abort("DialogWindow.LoadDialog.BindObject")
  95.  
  96.         self.gamemasterMark.Hide()
  97.         self.titleName.SetFontColorNew(230, 208, 162)
  98.         self.titleName.SetText("")
  99.         self.titleNameEdit.SetFontColorNew(230, 208, 162)
  100.         self.titleNameEdit.SetText("")
  101.         self.minimizeButton.SetEvent(uimg.__mem_func__(self.Minimize))
  102.         self.closeButton.SetEvent(uimg.__mem_func__(self.Close))
  103.         self.scrollBar.SetPos(1.0)
  104.         self.scrollBar.SetScrollEvent(uimg.__mem_func__(self.OnScroll))
  105.         self.chatLine.SetReturnEvent(uimg.__mem_func__(self.SendWhisper))
  106.         self.chatLine.SetEscapeEvent(uimg.__mem_func__(self.Minimize))
  107.         self.chatLine.SetMultiLine()
  108.         self.sendButton.SetEvent(uimg.__mem_func__(self.SendWhisper))
  109.         self.titleNameEdit.SetReturnEvent(uimg.__mem_func__(self.AcceptTarget))
  110.         self.titleNameEdit.SetEscapeEvent(uimg.__mem_func__(self.Close))
  111.         self.ignoreButton.SetToggleDownEvent(uimg.__mem_func__(self.IgnoreTarget))
  112.         self.ignoreButton.SetToggleUpEvent(uimg.__mem_func__(self.IgnoreTarget))
  113.         self.reportViolentWhisperButton.SetEvent(uimg.__mem_func__(self.ReportViolentWhisper))
  114.         self.acceptButton.SetEvent(uimg.__mem_func__(self.AcceptTarget))
  115.  
  116.         self.textRenderer = self.TextRenderer()
  117.         self.textRenderer.SetParent(self)
  118.         self.textRenderer.SetPosition(20, 28)
  119.     #   self.textRenderer.SetFontColorNew(230, 208, 162)
  120.         self.textRenderer.SetTargetName("")
  121.         self.textRenderer.Show()
  122.  
  123.         self.resizeButton = self.ResizeButton()
  124.         self.resizeButton.SetParent(self)
  125.         self.resizeButton.SetSize(20, 20)
  126.         self.resizeButton.SetPosition(280, 180)
  127.         self.resizeButton.SetMoveEvent(uimg.__mem_func__(self.ResizeWhisperDialog))
  128.         self.resizeButton.Show()
  129.  
  130.         self.ResizeWhisperDialog()
  131.  
  132.     def Destroy(self):
  133.  
  134.         self.eventMinimize = None
  135.         self.eventClose = None
  136.         self.eventAcceptTarget = None
  137.  
  138.         self.ClearDictionary()
  139.         self.scrollBar.Destroy()
  140.         self.titleName = None
  141.         self.titleNameEdit = None
  142.         self.closeButton = None
  143.         self.scrollBar = None
  144.         self.chatLine = None
  145.         self.sendButton = None
  146.         self.ignoreButton = None
  147.         self.reportViolentWhisperButton = None
  148.         self.acceptButton = None
  149.         self.minimizeButton = None
  150.         self.textRenderer = None
  151.         self.board = None
  152.         self.editBar = None
  153.         self.resizeButton = None
  154.  
  155.     def ResizeWhisperDialog(self):
  156.         (xPos, yPos) = self.resizeButton.GetLocalPosition()
  157.         if xPos < 280:
  158.             self.resizeButton.SetPosition(280, yPos)
  159.             return
  160.         if yPos < 150:
  161.             self.resizeButton.SetPosition(xPos, 150)
  162.             return
  163.         self.SetWhisperDialogSize(xPos + 20, yPos + 20)
  164.  
  165.     def SetWhisperDialogSize(self, width, height):
  166.         try:
  167.  
  168.             max = int((width-90)/6) * 3 - 6
  169.  
  170.             self.board.SetSize(width, height)
  171.             self.scrollBar.SetPosition(width-25, 35)
  172.             self.scrollBar.SetScrollBarSize(height-100)
  173.             self.scrollBar.SetPos(1.0)
  174.             self.editBar.SetSize(width-18, 50)
  175.             self.chatLine.SetSize(width-90, 40)
  176.             self.chatLine.SetLimitWidth(width-90)
  177.             self.SetSize(width, height)
  178.  
  179.             if 0 != self.targetName:
  180.                 chat.SetWhisperBoxSize(self.targetName, width - 50, height - 90)           
  181.            
  182.             if localemg.IsARABIC():
  183.                 self.textRenderer.SetPosition(width-20, 28)
  184.                 self.scrollBar.SetPosition(width-25+self.scrollBar.GetWidth(), 35)
  185.                 self.editBar.SetPosition(10 + self.editBar.GetWidth(), height-60)
  186.                 self.sendButton.SetPosition(width - 80-5 + self.sendButton.GetWidth(), 10)
  187.                 self.minimizeButton.SetPosition(width-42 + self.minimizeButton.GetWidth(), 12)
  188.                 self.closeButton.SetPosition(width-24+self.closeButton.GetWidth(), 12)             
  189.                 self.chatLine.SetPosition(5 + self.chatLine.GetWidth(), 5)
  190.                 self.board.SetPosition(self.board.GetWidth(), 0)
  191.             else:
  192.                 self.textRenderer.SetPosition(20, 28)
  193.                 self.scrollBar.SetPosition(width-25, 35)
  194.                 self.editBar.SetPosition(10, height-60)
  195.                 self.sendButton.SetPosition(width-80-5, 10)
  196.                 self.minimizeButton.SetPosition(width-42, 12)
  197.                 self.closeButton.SetPosition(width-24, 12)
  198.  
  199.             self.SetChatLineMax(max)
  200.  
  201.         except:
  202.             import exception
  203.             exception.Abort("WhisperDialog.SetWhisperDialogSize.BindObject")
  204.  
  205.     def SetChatLineMax(self, max):
  206.         self.chatLine.SetMax(max)
  207.  
  208.         from grpText import GetSplitingTextLine
  209.  
  210.         text = self.chatLine.GetText()
  211.         if text:
  212.             self.chatLine.SetFontColorNew(160, 121, 112)
  213.             self.chatLine.SetText(GetSplitingTextLine(text, max, 0))
  214.  
  215.     def OpenWithTarget(self, targetName):
  216.         chat.CreateWhisper(targetName)
  217.         chat.SetWhisperBoxSize(targetName, self.GetWidth() - 60, self.GetHeight() - 90)
  218.         self.chatLine.SetFocus()
  219.         self.titleName.SetText(targetName)
  220.         self.targetName = targetName
  221.         self.textRenderer.SetTargetName(targetName)
  222.         self.titleNameEdit.Hide()
  223.         self.ignoreButton.Hide()
  224.         if app.IsDevStage():
  225.             self.reportViolentWhisperButton.Show()
  226.         else:
  227.             self.reportViolentWhisperButton.Hide()
  228.         self.acceptButton.Hide()
  229.         self.gamemasterMark.Hide()
  230.         self.minimizeButton.Show()
  231.  
  232.     def OpenWithoutTarget(self, event):
  233.         self.eventAcceptTarget = event
  234.         self.titleName.SetFontColorNew(230, 208, 162)
  235.         self.titleName.SetText("")
  236.         self.titleNameEdit.SetFontColorNew(230, 208, 162)
  237.         self.titleNameEdit.SetText("")
  238.         self.titleNameEdit.SetFocus()
  239.         self.targetName = 0
  240.         self.titleNameEdit.Show()
  241.         self.ignoreButton.Hide()
  242.         self.reportViolentWhisperButton.Hide()
  243.         self.acceptButton.Show()
  244.         self.minimizeButton.Hide()
  245.         self.gamemasterMark.Hide()
  246.  
  247.     def SetGameMasterLook(self):
  248.         self.gamemasterMark.Show()
  249.         self.reportViolentWhisperButton.Hide()
  250.  
  251.     def Minimize(self):
  252.         self.titleNameEdit.KillFocus()
  253.         self.chatLine.KillFocus()
  254.         self.Hide()
  255.  
  256.         if None != self.eventMinimize:
  257.             self.eventMinimize(self.targetName)
  258.  
  259.     def Close(self):
  260.         chat.ClearWhisper(self.targetName)
  261.         self.titleNameEdit.KillFocus()
  262.         self.chatLine.KillFocus()
  263.         self.Hide()
  264.  
  265.         if None != self.eventClose:
  266.             self.eventClose(self.targetName)
  267.  
  268.     def ReportViolentWhisper(self):
  269.         net.SendChatPacket("/reportviolentwhisper " + self.targetName)
  270.  
  271.     def IgnoreTarget(self):
  272.         net.SendChatPacket("/ignore " + self.targetName)
  273.  
  274.     def AcceptTarget(self):
  275.         name = self.titleNameEdit.GetText()
  276.         if len(name) <= 0:
  277.             self.Close()
  278.             return
  279.  
  280.         if None != self.eventAcceptTarget:
  281.             self.titleNameEdit.KillFocus()
  282.             self.eventAcceptTarget(name)
  283.  
  284.     def OnScroll(self):
  285.         chat.SetWhisperPosition(self.targetName, self.scrollBar.GetPos())
  286.  
  287.     def SendWhisper(self):
  288.  
  289.         text = self.chatLine.GetText()
  290.         textLength = len(text)
  291.  
  292.         if textLength > 0:
  293.             if net.IsInsultIn(text):
  294.                 chat.AppendChat(chat.CHAT_TYPE_INFO, localemg.CHAT_INSULT_STRING)
  295.                 return
  296.  
  297.             net.SendWhisperPacket(self.targetName, text)
  298.             self.chatLine.SetFontColorNew(160, 121, 112)
  299.             self.chatLine.SetText("")
  300.  
  301.             chat.AppendWhisper(chat.WHISPER_TYPE_CHAT, self.targetName, player.GetName() + " : " + text)
  302.  
  303.     def OnTop(self):
  304.         self.chatLine.SetFocus()
  305.        
  306.     def BindInterface(self, interface):
  307.         self.interface = interface
  308.        
  309.     def OnMouseLeftButtonDown(self):
  310.         hyperlink = uimg.GetHyperlink()
  311.         if hyperlink:
  312.             if app.IsPressed(app.DIK_LALT):
  313.                 link = chat.GetLinkFromHyperlink(hyperlink)
  314.                 ime.PasteString(link)
  315.             else:
  316.                 self.interface.MakeHyperlinkTooltip(hyperlink)
  317.  
  318. if "__main__" == __name__:
  319.     import uiTest
  320.  
  321.     class TestApp(uiTest.App):
  322.         def OnInit(self):
  323.             wnd = WhisperDialog(self.OnMax, self.OnMin)
  324.             wnd.LoadDialog()
  325.             wnd.OpenWithoutTarget(self.OnNew)
  326.             wnd.SetPosition(0, 0)
  327.             wnd.Show()
  328.  
  329.             self.wnd = wnd
  330.  
  331.         def OnMax(self):
  332.             pass
  333.  
  334.         def OnMin(self):
  335.             pass
  336.  
  337.         def OnNew(self):
  338.             pass
  339.  
  340.     TestApp().MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement