Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.21 KB | None | 0 0
  1. import os
  2. import binascii
  3. import ui
  4. import dbg
  5. import app
  6. import net, player
  7. import item
  8. import chat
  9. import time
  10. import uiToolTip
  11. import wndMgr
  12. import localeInfo
  13. items = [
  14. [27101, 0], # 0
  15. [27104, 0], # 1
  16. [50813, 0], # 2
  17. [50814, 0], # 3
  18. [50817, 0], # 4
  19. [50818, 0], # 5
  20. [50819, 0], # 6
  21. [50820, 0], # 7
  22. [50821, 0], # 8
  23. [50822, 0], # 9
  24. [50823, 0], # 10
  25. [50824, 0], # 11
  26. [50825, 0], # 12
  27. [50826, 0], # 13
  28. [39024, 0], # 14
  29. [39025, 0], # 15
  30. [39017, 0], # 16
  31. [39018, 0], # 17
  32. [39020, 0], # 18
  33. [50840, 0], # 19
  34. [50841, 0], # 20
  35. [50842, 0], # 21
  36. [50843, 0], # 22
  37. [46000, 0], # 23
  38. [46001, 0], # 24
  39. [46002, 0], # 25
  40.  
  41. ]
  42.  
  43. class Dopalacze(ui.Window):
  44. strengthen = []
  45. PATH = ''
  46. power_cube = 0
  47.  
  48. def __init__(self):
  49. ui.Window.__init__(self)
  50.  
  51. self.Board = ui.BoardWithTitleBar()
  52. self.use = ui.Button()
  53. self.Rosa = []
  54. self.Woda = []
  55. self.EventDopalacze1 = []
  56. self.EventDopalacze2 = []
  57. self.EventDopalacze3 = []
  58. self.ZielarstwoSlot = []
  59. self.ZielarstwoSlot2 = []
  60. self.ZielarstwoSlot3 = []
  61. self.OtherItems = []
  62. self.OtherItems2 = []
  63. self.roski_text = ui.TextLine()
  64. self.event_dopalacze_text = ui.TextLine()
  65. self.zielarstwo_text = ui.TextLine()
  66. self.other_text = ui.TextLine()
  67. self.PATH = "dane/dopalacze/" + str(player.GetName()) + '_dops.dll'
  68.  
  69. self.BuildWindow()
  70. self.ReadFromFile()
  71. self.CreateButtons()
  72. self.CreateZielarstwo()
  73. self.CreateRoski()
  74. self.CreateOther()
  75. self.SetToolTips()
  76.  
  77. def __del__(self):
  78. ui.Window.__del__(self)
  79.  
  80. def BuildWindow(self):
  81. self.Board.SetSize(320,235)
  82. self.Board.SetCenterPosition()
  83. self.Board.AddFlag('movable')
  84. self.Board.SetTitleName('Wzmocnienia Postaci')
  85. self.Board.SetCloseEvent(self.Close)
  86. self.Board.Show()
  87.  
  88. #self.MainImage = ui.ImageBox()
  89. #self.MainImage.SetParent(self.Board)
  90. #self.MainImage.LoadImage("dopalacze.tga")
  91. #self.MainImage.SetPosition(13, 38)
  92. #self.MainImage.SetSize(300,260)
  93. #self.MainImage.Show()
  94.  
  95. def SetItemToolTip(self, tooltipItem):
  96. self.tooltipItem = tooltipItem
  97.  
  98. def WriteToFileEmptyData(self):
  99. file = open(self.PATH, 'w+')
  100. for x in items:
  101. value = binascii.b2a_base64("%d %d\n" % (x[0], x[1]))
  102. file.write(value)
  103. file.close()
  104. self.ReadFromFile()
  105.  
  106. def WriteToFile(self):
  107. file = open(self.PATH, 'w')
  108. for x in self.strengthen:
  109. value = binascii.b2a_base64("%d %d\n" % (x[0], x[1]))
  110. file.write(value)
  111. file.close()
  112.  
  113. def ReadFromFile(self):
  114. if os.path.exists(self.PATH):
  115. try:
  116. file = open(self.PATH, 'r')
  117. for x in file:
  118. x = str(binascii.a2b_base64(x))
  119. x = x.split()
  120. x[1] = int(x[1])
  121. x[0] = int(x[0])
  122. self.strengthen.append(x)
  123. file.close()
  124.  
  125. if len(self.strengthen) < len(items):
  126. os.remove(self.PATH)
  127. self.WriteToFileEmptyData()
  128. except:
  129. self.WriteToFileEmptyData()
  130. else:
  131. self.WriteToFileEmptyData()
  132.  
  133. def SetToolTips(self):
  134. for x in xrange(len(self.Woda)):
  135. self.Woda[x].SetToolTip()
  136.  
  137. for x in xrange(len(self.Rosa)):
  138. self.Rosa[x].SetToolTip()
  139.  
  140.  
  141. def CreateRoski(self):
  142.  
  143. self.Wody = None
  144. self.Rosy = None
  145.  
  146. for x in xrange(0, 7):
  147. self.Wody = Wzmocnienia(self.Board, 15, 30, x, self.strengthen[x][1], self.strengthen[x][0], self)
  148. self.Woda.append(self.Wody)
  149. for x2 in xrange(7, 14):
  150. self.Rosy = Wzmocnienia(self.Board, 15, 75, x2 - 7, self.strengthen[x2][1], self.strengthen[x2][0], self)
  151. self.Rosa.append(self.Rosy)
  152. for x3 in xrange(14, 21):
  153. self.Rosy = Wzmocnienia(self.Board, 15, 120, x3 - 14, self.strengthen[x3][1], self.strengthen[x3][0], self)
  154. self.Rosa.append(self.Rosy)
  155. for x4 in xrange(21, 26):
  156. self.Rosy = Wzmocnienia(self.Board, 15, 165, x4 - 21, self.strengthen[x4][1], self.strengthen[x4][0], self)
  157. self.Rosa.append(self.Rosy)
  158.  
  159.  
  160.  
  161.  
  162. def CreateZielarstwo(self):
  163.  
  164. self.zielarstwo = None
  165.  
  166.  
  167. def CreateOther(self):
  168.  
  169.  
  170. self.Other = None
  171. self.Other2 = None
  172.  
  173.  
  174. def CreateButtons(self):
  175. self.use.SetParent(self.Board)
  176. self.use.SetPosition(80, 210)
  177. self.use.SetUpVisual('d:/ymir work/ui/public/xlarge_button_01.sub')
  178. self.use.SetOverVisual('d:/ymir work/ui/public/xlarge_button_02.sub')
  179. self.use.SetDownVisual('d:/ymir work/ui/public/xlarge_button_03.sub')
  180. self.use.SetText('Aktywuj Wzmocnienia')
  181. self.use.SetEvent(self.OdpalWzmocnienia)
  182. self.use.Show()
  183.  
  184. def OdpalWzmocnienia(self):
  185. #net.SendChatPacket("/lacostia_config dopalacze")
  186. self.RosyWody()
  187. self.EventDopalaczes1()
  188. self.Zielarstwo()
  189. self.OtherClick()
  190. #chat.AppendChat(chat.CHAT_TYPE_NOTICE, "<Informacja> Wybrane wzmocnienia zostaly aktywowane.")
  191.  
  192. def RosyWody(self):
  193. for x in self.Woda:
  194. x.UseOdpal()
  195. x.Refresh()
  196. for x in self.Rosa:
  197. x.UseOdpal()
  198. x.Refresh()
  199.  
  200. def EventDopalaczes1(self):
  201. for x in self.EventDopalacze1:
  202. x.UseOdpal()
  203. x.Refresh()
  204. for x in self.EventDopalacze2:
  205. x.UseOdpal()
  206. x.Refresh()
  207. for x in self.EventDopalacze3:
  208. x.UseOdpal()
  209. x.Refresh()
  210.  
  211. def Zielarstwo(self):
  212. for x in self.ZielarstwoSlot:
  213. x.UseOdpal()
  214. x.Refresh()
  215. for x in self.ZielarstwoSlot2:
  216. x.UseOdpal()
  217. x.Refresh()
  218. for x in self.ZielarstwoSlot3:
  219. x.UseOdpal()
  220. x.Refresh()
  221.  
  222. def OtherClick(self):
  223. for x in self.OtherItems:
  224. x.UseOdpal()
  225. x.Refresh()
  226. for x in self.OtherItems2:
  227. x.UseOdpal()
  228. x.Refresh()
  229.  
  230. # def Destroy(self):
  231. # dbg.TraceError("Destroy uiDew")
  232.  
  233. def OpenWindow(self):
  234. self.Board.Hide() if self.Board.IsShow() else self.Board.Show()
  235.  
  236. def OnPressEscapeKey(self):
  237. self.Close()
  238. return TRUE
  239.  
  240. def Close(self):
  241. self.Board.Hide()
  242.  
  243. class Wzmocnienia:
  244. button = None
  245. _item = None
  246. name = ''
  247. status = None
  248. x = 0
  249. y = 0
  250. vNum = 0
  251. elemNum = 0
  252. window = None
  253. background = None
  254.  
  255. def __init__(self, parent, x, y, elemNum, status, vNum, window):
  256. self.window = window
  257. self.x = x
  258. self.y = y
  259. self.vNum = vNum
  260. self.elemNum = elemNum
  261. self.tooltipItem = uiToolTip.ItemToolTip()
  262. self.tooltipItem.Hide()
  263. self.CreateBackground(parent)
  264. self.CreateImage(parent)
  265. self.CreateButton(parent, status)
  266.  
  267. def __del__(self):
  268. self.Destroy()
  269.  
  270. def Refresh(self):
  271. self.SetToolTip()
  272.  
  273. def SetToolTipPos(self):
  274. width = self.tooltipItem.GetWidth()
  275. height = self.tooltipItem.toolTipHeight
  276.  
  277. (x,y) = wndMgr.GetMousePosition()
  278.  
  279. x = max(x, 0)
  280. y = max(y, 0)
  281. x = min(x + width / 2, wndMgr.GetScreenWidth() - width / 2) - width / 2
  282. y = min(y + self.tooltipItem.GetHeight(), wndMgr.GetScreenHeight()) - self.tooltipItem.GetHeight()
  283.  
  284. self.tooltipItem.SetToolTipPosition(x, y + self.tooltipItem.GetHeight() + 34)
  285.  
  286. def SetToolTip(self):
  287. if None != self.tooltipItem:
  288. self.tooltipItem.ClearToolTip()
  289. self.SetByItemInInventory()
  290. self.SetToolTipPos()
  291. self.tooltipItem.Hide()
  292.  
  293. def SetByVNum(self):
  294. self.tooltipItem.SetItemToolTip(self.vNum)
  295.  
  296. def SetByItemInInventory(self):
  297. itemx = item.SelectItem(self.vNum)
  298. for i in xrange(90*4):
  299. ItemValue = player.GetItemIndex(i)
  300. if ItemValue == self.vNum:
  301. self.tooltipItem.SetInventoryItem(i)
  302. return
  303. ItemValue = player.GetItemIndex(player.INVENTORY, i)
  304. if ItemValue == self.vNum:
  305. self.tooltipItem.SetInventoryItem(i, player.INVENTORY)
  306. return
  307. self.tooltipItem.AppendTextLine(self.name, self.tooltipItem.TITLE_COLOR)
  308. self.tooltipItem.AppendTextLine("Nie posiadasz tego przedmiotu", self.tooltipItem.DISABLE_COLOR)
  309.  
  310. def OnMouseOverIn(self):
  311. if self.tooltipItem:
  312. self.SetToolTipPos()
  313. self.tooltipItem.SetTop()
  314. self.tooltipItem.Show()
  315.  
  316. def OnMouseOverOut(self):
  317. if self.tooltipItem:
  318. self.tooltipItem.Hide()
  319.  
  320. def CreateBackground(self, parent):
  321. self.background = ui.ExpandedImageBox()
  322. self.background.SetParent(parent)
  323. try:
  324. self.background.LoadImage("d:/ymir work/ui/public/Slot_Base.sub")
  325. self.background.SetPosition(self.x + 40 * self.elemNum + 5, self.y + 11)
  326. self.background.SAFE_SetStringEvent("MOUSE_OVER_IN", self.OnMouseOverIn)
  327. self.background.SAFE_SetStringEvent("MOUSE_OVER_OUT", self.OnMouseOverOut)
  328. self.background.Show()
  329. except:
  330. dbg.TraceError("No found item")
  331.  
  332. def CreateImage(self, parent):
  333. self._item = ui.ExpandedImageBox()
  334. self._item.SetParent(self.background)
  335. item.SelectItem(self.vNum)
  336. try:
  337. self._img = item.GetIconImageFileName()
  338. self.name = item.GetItemName()
  339. self._item.LoadImage(self._img)
  340. self._item.SAFE_SetStringEvent("MOUSE_OVER_IN", self.OnMouseOverIn)
  341. self._item.SAFE_SetStringEvent("MOUSE_OVER_OUT", self.OnMouseOverOut)
  342. self._item.SetPosition(0, 0)
  343. self._item.Show()
  344. except:
  345. dbg.TraceError("No found item")
  346.  
  347. def CreateButton(self, parent, status):
  348. self.button = ui.ToggleButton()
  349. if self._item != None:
  350. self.button.SetParent(self._item)
  351. self.button.SetSize(32, 32)
  352. self.button.SetPosition(16, 16)
  353. self.button.SetWindowVerticalAlignBottom()
  354. self.button.SetWindowHorizontalAlignRight()
  355. self.button.SetUpVisual('usun.tga')
  356. self.button.SetOverVisual('usun.tga')
  357. self.button.SetDownVisual('wczytaj.tga')
  358. self.button.SetText("")
  359. self.button.SetToggleUpEvent(self.TurnOff)
  360. self.button.SetToggleDownEvent(self.TurnOn)
  361. self.status = status
  362. if self.status is 1:
  363. self.button.Down()
  364. self.button.Show()
  365.  
  366. def UseOdpal(self):
  367. if self.status is 1:
  368. for i in xrange(225):
  369. ItemValue = player.GetItemIndex(i)
  370. if ItemValue == self.vNum:
  371. net.SendItemUsePacket(i)
  372. break
  373. ItemValue = player.GetItemIndex(player.INVENTORY, i)
  374. if ItemValue == self.vNum:
  375. net.SendItemUsePacket(player.INVENTORY, i)
  376. break
  377.  
  378. def getStatus(self):
  379. return self.status
  380.  
  381. def TurnOn(self):
  382. self.status = 1
  383. for x in xrange(len(self.window.strengthen)):
  384. if self.window.strengthen[x][0] is self.vNum:
  385. self.window.strengthen[x][1] = 1
  386. self.window.WriteToFile()
  387.  
  388. def TurnOff(self):
  389. self.button.SetUp()
  390. self.status = 0
  391. y = 0
  392. for x in xrange(len(self.window.strengthen)):
  393. if self.window.strengthen[x][0] is self.vNum:
  394. self.window.strengthen[x][1] = 0
  395. self.window.WriteToFile()
  396.  
  397. def Destroy(self):
  398. del self.button
  399. del self._item
  400. del self.x
  401. del self.y
  402. del self.vNum
  403. del self.name
  404. del self.tooltipItem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement