Advertisement
Guest User

Untitled

a guest
Jul 10th, 2015
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.83 KB | None | 0 0
  1. import app
  2. import ui
  3. import player
  4. import net
  5. import wndMgr
  6. import messenger
  7. import guild
  8. import chr
  9. import nonplayer
  10. import localeInfo
  11. import constInfo
  12. import uiChatBlock
  13. import uiHealth
  14. import constInfo
  15. import event
  16.  
  17. class TargetBoard(ui.ThinBoard3):
  18.  
  19. BUTTON_NAME_LIST = (
  20. localeInfo.TARGET_BUTTON_WHISPER,
  21. localeInfo.TARGET_BUTTON_EXCHANGE,
  22. localeInfo.TARGET_BUTTON_FIGHT,
  23. localeInfo.TARGET_BUTTON_ACCEPT_FIGHT,
  24. localeInfo.TARGET_BUTTON_AVENGE,
  25. localeInfo.TARGET_BUTTON_FRIEND,
  26. localeInfo.TARGET_BUTTON_INVITE_PARTY,
  27. localeInfo.TARGET_BUTTON_LEAVE_PARTY,
  28. localeInfo.TARGET_BUTTON_EXCLUDE,
  29. localeInfo.TARGET_BUTTON_INVITE_GUILD,
  30. localeInfo.TARGET_BUTTON_DISMOUNT,
  31. localeInfo.TARGET_BUTTON_EXIT_OBSERVER,
  32. localeInfo.TARGET_BUTTON_VIEW_EQUIPMENT,
  33. localeInfo.TARGET_BUTTON_REQUEST_ENTER_PARTY,
  34. localeInfo.TARGET_BUTTON_BUILDING_DESTROY,
  35. localeInfo.TARGET_BUTTON_EMOTION_ALLOW,
  36. "Kidobás",
  37. "Chat Tiltás",
  38. "Megölés",
  39. "Felszerelés",
  40. )
  41.  
  42. GRADE_NAME = {
  43. nonplayer.PAWN : localeInfo.TARGET_LEVEL_PAWN,
  44. nonplayer.S_PAWN : localeInfo.TARGET_LEVEL_S_PAWN,
  45. nonplayer.KNIGHT : localeInfo.TARGET_LEVEL_KNIGHT,
  46. nonplayer.S_KNIGHT : localeInfo.TARGET_LEVEL_S_KNIGHT,
  47. nonplayer.BOSS : localeInfo.TARGET_LEVEL_BOSS,
  48. nonplayer.KING : localeInfo.TARGET_LEVEL_KING,
  49. }
  50. EXCHANGE_LIMIT_RANGE = 3000
  51.  
  52. def __init__(self):
  53. self.healthBoard = uiHealth.HealthBoard()
  54. ui.ThinBoard3.__init__(self)
  55.  
  56. name = ui.TextLine()
  57. name.SetParent(self)
  58. name.SetDefaultFontName()
  59. name.SetOutline()
  60. name.Show()
  61.  
  62. hpGauge = ui.Gauge()
  63. hpGauge.SetParent(self)
  64. hpGauge.MakeGauge(130, "red")
  65. hpGauge.Hide()
  66.  
  67. hpPercenttxt = ui.TextLine()
  68. hpPercenttxt.SetParent(self)
  69. hpPercenttxt.SetPosition(160, 13)
  70. hpPercenttxt.SetText("")
  71. hpPercenttxt.Hide()
  72.  
  73. closeButton = ui.Button()
  74. closeButton.SetParent(self)
  75. closeButton.SetUpVisual("d:/ymir work/ui/public/close_button_01.sub")
  76. closeButton.SetOverVisual("d:/ymir work/ui/public/close_button_02.sub")
  77. closeButton.SetDownVisual("d:/ymir work/ui/public/close_button_03.sub")
  78. closeButton.SetPosition(30, 13)
  79.  
  80. if localeInfo.IsARABIC():
  81. hpGauge.SetPosition(55, 17)
  82. hpGauge.SetWindowHorizontalAlignLeft()
  83. closeButton.SetWindowHorizontalAlignLeft()
  84. else:
  85. hpGauge.SetPosition(175, 17)
  86. hpGauge.SetWindowHorizontalAlignRight()
  87. closeButton.SetWindowHorizontalAlignRight()
  88.  
  89. closeButton.SetEvent(ui.__mem_func__(self.OnPressedCloseButton))
  90. closeButton.Show()
  91.  
  92. self.buttonDict = {}
  93. self.showingButtonList = []
  94. for buttonName in self.BUTTON_NAME_LIST:
  95. button = ui.Button()
  96. button.SetParent(self)
  97.  
  98. if localeInfo.IsARABIC():
  99. button.SetUpVisual("d:/ymir work/ui/public/Small_Button_01.sub")
  100. button.SetOverVisual("d:/ymir work/ui/public/Small_Button_02.sub")
  101. button.SetDownVisual("d:/ymir work/ui/public/Small_Button_03.sub")
  102. else:
  103. button.SetUpVisual("d:/ymir work/ui/public/small_thin_button_01.sub")
  104. button.SetOverVisual("d:/ymir work/ui/public/small_thin_button_02.sub")
  105. button.SetDownVisual("d:/ymir work/ui/public/small_thin_button_03.sub")
  106.  
  107. button.SetWindowHorizontalAlignCenter()
  108. button.SetText(buttonName)
  109. button.Hide()
  110. self.buttonDict[buttonName] = button
  111. self.showingButtonList.append(button)
  112.  
  113. self.buttonDict[localeInfo.TARGET_BUTTON_WHISPER].SetEvent(ui.__mem_func__(self.OnWhisper))
  114. self.buttonDict[localeInfo.TARGET_BUTTON_EXCHANGE].SetEvent(ui.__mem_func__(self.OnExchange))
  115. self.buttonDict[localeInfo.TARGET_BUTTON_FIGHT].SetEvent(ui.__mem_func__(self.OnPVP))
  116. self.buttonDict[localeInfo.TARGET_BUTTON_ACCEPT_FIGHT].SetEvent(ui.__mem_func__(self.OnPVP))
  117. self.buttonDict[localeInfo.TARGET_BUTTON_AVENGE].SetEvent(ui.__mem_func__(self.OnPVP))
  118. self.buttonDict[localeInfo.TARGET_BUTTON_FRIEND].SetEvent(ui.__mem_func__(self.OnAppendToMessenger))
  119. self.buttonDict[localeInfo.TARGET_BUTTON_FRIEND].SetEvent(ui.__mem_func__(self.OnAppendToMessenger))
  120. self.buttonDict[localeInfo.TARGET_BUTTON_INVITE_PARTY].SetEvent(ui.__mem_func__(self.OnPartyInvite))
  121. self.buttonDict[localeInfo.TARGET_BUTTON_LEAVE_PARTY].SetEvent(ui.__mem_func__(self.OnPartyExit))
  122. self.buttonDict[localeInfo.TARGET_BUTTON_EXCLUDE].SetEvent(ui.__mem_func__(self.OnPartyRemove))
  123. self.buttonDict["Kidobás"].SetEvent(ui.__mem_func__(self.OnKick))
  124. self.buttonDict["Megölés"].SetEvent(ui.__mem_func__(self.OnKill))
  125. self.buttonDict["Chat Tiltás"].SetEvent(ui.__mem_func__(self.OnChatBlock))
  126. self.buttonDict["Felszerelés"].SAFE_SetEvent(self.__OnViewEquipment)
  127.  
  128. self.buttonDict[localeInfo.TARGET_BUTTON_INVITE_GUILD].SAFE_SetEvent(self.__OnGuildAddMember)
  129. self.buttonDict[localeInfo.TARGET_BUTTON_DISMOUNT].SAFE_SetEvent(self.__OnDismount)
  130. self.buttonDict[localeInfo.TARGET_BUTTON_EXIT_OBSERVER].SAFE_SetEvent(self.__OnExitObserver)
  131. self.buttonDict[localeInfo.TARGET_BUTTON_VIEW_EQUIPMENT].SAFE_SetEvent(self.__OnViewEquipment)
  132. self.buttonDict[localeInfo.TARGET_BUTTON_REQUEST_ENTER_PARTY].SAFE_SetEvent(self.__OnRequestParty)
  133. self.buttonDict[localeInfo.TARGET_BUTTON_BUILDING_DESTROY].SAFE_SetEvent(self.__OnDestroyBuilding)
  134. self.buttonDict[localeInfo.TARGET_BUTTON_EMOTION_ALLOW].SAFE_SetEvent(self.__OnEmotionAllow)
  135.  
  136. self.name = name
  137. dlgChatBlock = uiChatBlock.ChatBlockDialog()
  138. dlgChatBlock.LoadDialog()
  139. dlgChatBlock.SetTitleName("Chat Tiltás")
  140. dlgChatBlock.Hide()
  141. self.dlgChatBlock = dlgChatBlock
  142. self.dlgChatBlock = dlgChatBlock
  143. self.hpGauge = hpGauge
  144. self.hpPercenttxt = hpPercenttxt
  145. self.closeButton = closeButton
  146. self.nameString = 0
  147. self.nameLength = 0
  148. self.vid = 0
  149. self.eventWhisper = None
  150. self.isShowButton = False
  151.  
  152. self.__Initialize()
  153. self.ResetTargetBoard()
  154.  
  155. def __del__(self):
  156. ui.ThinBoard3.__del__(self)
  157.  
  158. print "===================================================== DESTROYED TARGET BOARD"
  159.  
  160. def __Initialize(self):
  161. self.nameString = ""
  162. self.nameLength = 0
  163. self.vid = 0
  164. self.isShowButton = False
  165.  
  166. def Destroy(self):
  167. self.dlgChatBlock.Destroy()
  168. self.dlgChatBlock = 0
  169. self.eventWhisper = None
  170. self.closeButton = None
  171. self.showingButtonList = None
  172. self.buttonDict = None
  173. self.name = None
  174. self.hpGauge = None
  175. self.__Initialize()
  176.  
  177. def OnKick(self):
  178. net.SendChatPacket("/dc " + str(chr.GetNameByVID(self.vid)))
  179.  
  180. def OnKill(self):
  181. net.SendChatPacket("/kill " + str(chr.GetNameByVID(self.vid)))
  182.  
  183. def OnChatBlock(self):
  184. if str(player.GetName())[0] == "[":
  185. self.dlgChatBlock.SetTitleName("Chat Tiltás: " + str(chr.GetNameByVID(self.vid)))
  186. self.dlgChatBlock.Open(str(chr.GetNameByVID(self.vid)))
  187.  
  188. def OnPressedCloseButton(self):
  189. player.ClearTarget()
  190. self.Close()
  191.  
  192. def Close(self):
  193. self.healthBoard.Hide()
  194. self.__Initialize()
  195. self.Hide()
  196.  
  197. def Open(self, vid, name):
  198. if vid:
  199. if not constInfo.GET_VIEW_OTHER_EMPIRE_PLAYER_TARGET_BOARD():
  200. if not player.IsSameEmpire(vid):
  201. self.Hide()
  202. return
  203.  
  204. if vid != self.GetTargetVID():
  205. self.ResetTargetBoard()
  206. self.SetTargetVID(vid)
  207. self.SetTargetName(name)
  208.  
  209. if player.IsMainCharacterIndex(vid):
  210. self.__ShowMainCharacterMenu()
  211. elif chr.INSTANCE_TYPE_BUILDING == chr.GetInstanceType(self.vid):
  212. self.Hide()
  213. else:
  214. self.RefreshButton()
  215. self.Show()
  216. else:
  217. self.HideAllButton()
  218. self.__ShowButton(localeInfo.TARGET_BUTTON_WHISPER)
  219. self.__ShowButton("VOTE_BLOCK_CHAT")
  220. self.__ArrangeButtonPosition()
  221. self.SetTargetName(name)
  222. self.Show()
  223.  
  224. def Refresh(self):
  225. if self.IsShow():
  226. if self.IsShowButton():
  227. self.RefreshButton()
  228.  
  229. def RefreshByVID(self, vid):
  230. if vid == self.GetTargetVID():
  231. self.Refresh()
  232.  
  233. def RefreshByName(self, name):
  234. if name == self.GetTargetName():
  235. self.Refresh()
  236.  
  237. def __ShowMainCharacterMenu(self):
  238. canShow=0
  239.  
  240. self.HideAllButton()
  241.  
  242. if player.IsMountingHorse():
  243. self.__ShowButton(localeInfo.TARGET_BUTTON_DISMOUNT)
  244. canShow=1
  245.  
  246. if player.IsObserverMode():
  247. self.__ShowButton(localeInfo.TARGET_BUTTON_EXIT_OBSERVER)
  248. canShow=1
  249.  
  250. if canShow:
  251. self.__ArrangeButtonPosition()
  252. self.Show()
  253. else:
  254. self.Hide()
  255.  
  256. def __ShowNameOnlyMenu(self):
  257. self.HideAllButton()
  258.  
  259. def SetWhisperEvent(self, event):
  260. self.eventWhisper = event
  261.  
  262. def UpdatePosition(self):
  263. self.SetPosition(wndMgr.GetScreenWidth()/2 - self.GetWidth()/2, 10)
  264.  
  265. def ResetTargetBoard(self):
  266.  
  267. for btn in self.buttonDict.values():
  268. btn.Hide()
  269.  
  270. self.__Initialize()
  271.  
  272. self.name.SetPosition(0, 13)
  273. self.name.SetHorizontalAlignCenter()
  274. self.name.SetWindowHorizontalAlignCenter()
  275. self.hpGauge.Hide()
  276. self.SetSize(250, 40)
  277.  
  278. def SetTargetVID(self, vid):
  279. self.vid = vid
  280.  
  281. def SetEnemyVID(self, vid):
  282. self.SetTargetVID(vid)
  283.  
  284. name = chr.GetNameByVID(vid)
  285. level = nonplayer.GetLevelByVID(vid)
  286. grade = nonplayer.GetGradeByVID(vid)
  287.  
  288. nameFront = ""
  289. if -1 != level:
  290. nameFront += "Lv." + str(level) + " "
  291. if self.GRADE_NAME.has_key(grade):
  292. nameFront += "(" + self.GRADE_NAME[grade] + ") "
  293.  
  294. self.SetTargetName(nameFront + name)
  295.  
  296. def GetTargetVID(self):
  297. return self.vid
  298.  
  299. def GetTargetName(self):
  300. return self.nameString
  301.  
  302. def SetTargetName(self, name):
  303. self.nameString = name
  304. self.nameLength = len(name)
  305. self.name.SetText(name)
  306.  
  307. def SetHP(self, hpPercentage):
  308. if not self.hpGauge.IsShow():
  309.  
  310. self.SetSize(200 + 7*self.nameLength, self.GetHeight())
  311.  
  312. if localeInfo.IsARABIC():
  313. self.name.SetPosition( self.GetWidth()-23, 13)
  314. else:
  315. self.name.SetPosition(23, 13)
  316.  
  317. self.name.SetWindowHorizontalAlignLeft()
  318. self.name.SetHorizontalAlignLeft()
  319. self.hpGauge.Show()
  320. self.UpdatePosition()
  321. self.hpPercenttxt.SetPosition(200 + 7*self.nameLength-205, 13)
  322. self.hpPercenttxt.Show()
  323. if player.IsPVPInstance(self.vid):
  324. self.hpPercenttxt.Hide()
  325.  
  326. self.hpGauge.SetPercentage(hpPercentage, 100)
  327. self.hpPercenttxt.SetText("%d%%" % (hpPercentage))
  328.  
  329. def ShowDefaultButton(self):
  330.  
  331. self.isShowButton = True
  332. self.showingButtonList.append(self.buttonDict[localeInfo.TARGET_BUTTON_WHISPER])
  333. self.showingButtonList.append(self.buttonDict[localeInfo.TARGET_BUTTON_EXCHANGE])
  334. self.showingButtonList.append(self.buttonDict[localeInfo.TARGET_BUTTON_FIGHT])
  335. self.showingButtonList.append(self.buttonDict[localeInfo.TARGET_BUTTON_EMOTION_ALLOW])
  336. #self.showingButtonList.append(self.buttonDict[localeInfo.TARGET_BUTTON_VIEW_EQUIPMENT])
  337. for button in self.showingButtonList:
  338. button.Show()
  339.  
  340. def HideAllButton(self):
  341. self.isShowButton = False
  342. for button in self.showingButtonList:
  343. button.Hide()
  344. self.showingButtonList = []
  345.  
  346. def __ShowButton(self, name):
  347.  
  348. if not self.buttonDict.has_key(name):
  349. return
  350.  
  351. self.buttonDict[name].Show()
  352. self.showingButtonList.append(self.buttonDict[name])
  353.  
  354. def __HideButton(self, name):
  355.  
  356. if not self.buttonDict.has_key(name):
  357. return
  358.  
  359. button = self.buttonDict[name]
  360. button.Hide()
  361.  
  362. for btnInList in self.showingButtonList:
  363. if btnInList == button:
  364. self.showingButtonList.remove(button)
  365. break
  366.  
  367. def OnWhisper(self):
  368. if None != self.eventWhisper:
  369. self.eventWhisper(self.nameString)
  370.  
  371. def OnExchange(self):
  372. net.SendExchangeStartPacket(self.vid)
  373.  
  374. def OnPVP(self):
  375. net.SendChatPacket("/pvp %d" % (self.vid))
  376.  
  377. def OnAppendToMessenger(self):
  378. net.SendMessengerAddByVIDPacket(self.vid)
  379.  
  380. def OnPartyInvite(self):
  381. net.SendPartyInvitePacket(self.vid)
  382.  
  383. def OnPartyExit(self):
  384. net.SendPartyExitPacket()
  385.  
  386. def OnPartyRemove(self):
  387. net.SendPartyRemovePacket(self.vid)
  388.  
  389. def __OnGuildAddMember(self):
  390. net.SendGuildAddMemberPacket(self.vid)
  391.  
  392. def __OnDismount(self):
  393. net.SendChatPacket("/unmount")
  394.  
  395. def __OnExitObserver(self):
  396. net.SendChatPacket("/observer_exit")
  397.  
  398. def __OnViewEquipment(self):
  399. net.SendChatPacket("/view_equip " + str(self.vid))
  400.  
  401. def __OnRequestParty(self):
  402. net.SendChatPacket("/party_request " + str(self.vid))
  403.  
  404. def __OnDestroyBuilding(self):
  405. net.SendChatPacket("/build d %d" % (self.vid))
  406.  
  407. def __OnEmotionAllow(self):
  408. net.SendChatPacket("/emotion_allow %d" % (self.vid))
  409.  
  410. def __OnVoteBlockChat(self):
  411. cmd = "/vote_block_chat %s" % (self.nameString)
  412. net.SendChatPacket(cmd)
  413.  
  414. def OnPressEscapeKey(self):
  415. self.OnPressedCloseButton()
  416. return True
  417.  
  418. def IsShowButton(self):
  419. return self.isShowButton
  420.  
  421. def RefreshButton(self):
  422.  
  423. self.HideAllButton()
  424.  
  425. if chr.INSTANCE_TYPE_BUILDING == chr.GetInstanceType(self.vid):
  426. #self.__ShowButton(localeInfo.TARGET_BUTTON_BUILDING_DESTROY)
  427. #self.__ArrangeButtonPosition()
  428. return
  429.  
  430. if player.IsPVPInstance(self.vid) or player.IsObserverMode():
  431. # PVP_INFO_SIZE_BUG_FIX
  432. self.SetSize(200 + 7*self.nameLength, 40)
  433. self.UpdatePosition()
  434. # END_OF_PVP_INFO_SIZE_BUG_FIX
  435. return
  436.  
  437. self.ShowDefaultButton()
  438.  
  439. if str(player.GetName())[0] == "[":
  440. self.__ShowButton("Megölés")
  441. self.__ShowButton("Kidobás")
  442. self.__ShowButton("Chat Tiltás")
  443. self.__ShowButton("Felszerelés")
  444.  
  445. if guild.MainPlayerHasAuthority(guild.AUTH_ADD_MEMBER):
  446. if not guild.IsMemberByName(self.nameString):
  447. if 0 == chr.GetGuildID(self.vid):
  448. self.__ShowButton(localeInfo.TARGET_BUTTON_INVITE_GUILD)
  449.  
  450. if not messenger.IsFriendByName(self.nameString):
  451. self.__ShowButton(localeInfo.TARGET_BUTTON_FRIEND)
  452.  
  453. if player.IsPartyMember(self.vid):
  454.  
  455. self.__HideButton(localeInfo.TARGET_BUTTON_FIGHT)
  456.  
  457. if player.IsPartyLeader(self.vid):
  458. self.__ShowButton(localeInfo.TARGET_BUTTON_LEAVE_PARTY)
  459. elif player.IsPartyLeader(player.GetMainCharacterIndex()):
  460. self.__ShowButton(localeInfo.TARGET_BUTTON_EXCLUDE)
  461.  
  462. else:
  463. if player.IsPartyMember(player.GetMainCharacterIndex()):
  464. if player.IsPartyLeader(player.GetMainCharacterIndex()):
  465. self.__ShowButton(localeInfo.TARGET_BUTTON_INVITE_PARTY)
  466. else:
  467. if chr.IsPartyMember(self.vid):
  468. self.__ShowButton(localeInfo.TARGET_BUTTON_REQUEST_ENTER_PARTY)
  469. else:
  470. self.__ShowButton(localeInfo.TARGET_BUTTON_INVITE_PARTY)
  471.  
  472. if player.IsRevengeInstance(self.vid):
  473. self.__HideButton(localeInfo.TARGET_BUTTON_FIGHT)
  474. self.__ShowButton(localeInfo.TARGET_BUTTON_AVENGE)
  475. elif player.IsChallengeInstance(self.vid):
  476. self.__HideButton(localeInfo.TARGET_BUTTON_FIGHT)
  477. self.__ShowButton(localeInfo.TARGET_BUTTON_ACCEPT_FIGHT)
  478. elif player.IsCantFightInstance(self.vid):
  479. self.__HideButton(localeInfo.TARGET_BUTTON_FIGHT)
  480.  
  481. if not player.IsSameEmpire(self.vid):
  482. self.__HideButton(localeInfo.TARGET_BUTTON_INVITE_PARTY)
  483. self.__HideButton(localeInfo.TARGET_BUTTON_FRIEND)
  484. self.__HideButton(localeInfo.TARGET_BUTTON_FIGHT)
  485.  
  486. distance = player.GetCharacterDistance(self.vid)
  487. if distance > self.EXCHANGE_LIMIT_RANGE:
  488. self.__HideButton(localeInfo.TARGET_BUTTON_EXCHANGE)
  489. self.__ArrangeButtonPosition()
  490.  
  491. self.__ArrangeButtonPosition()
  492.  
  493. def __ArrangeButtonPosition(self):
  494. showingButtonCount = len(self.showingButtonList)
  495.  
  496. pos = -(showingButtonCount / 2) * 68
  497. if 0 == showingButtonCount % 2:
  498. pos += 34
  499.  
  500. for button in self.showingButtonList:
  501. button.SetPosition(pos, 33)
  502. pos += 68
  503.  
  504. self.SetSize(max(150, showingButtonCount * 75), 65)
  505. self.UpdatePosition()
  506.  
  507. def OnUpdate(self):
  508. if player.IsPVPInstance(self.vid):
  509. constInfo.VID = self.vid
  510. event.QuestButtonClick(constInfo.STHX)
  511. if not self.healthBoard.IsShow() and self.vid != 0:
  512. self.healthBoard.Show()
  513. else:
  514. self.healthBoard.Hide()
  515.  
  516. if self.isShowButton:
  517.  
  518. exchangeButton = self.buttonDict[localeInfo.TARGET_BUTTON_EXCHANGE]
  519. distance = player.GetCharacterDistance(self.vid)
  520.  
  521. if distance < 0:
  522. return
  523.  
  524. if exchangeButton.IsShow():
  525. if distance > self.EXCHANGE_LIMIT_RANGE:
  526. self.RefreshButton()
  527.  
  528. else:
  529. if distance < self.EXCHANGE_LIMIT_RANGE:
  530. self.RefreshButton()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement