Guest User

uiofflineshop_history.py

a guest
Jan 15th, 2025
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.82 KB | None | 0 0
  1. import app
  2. import player
  3. import net
  4. import offlineshop
  5. import ui
  6. import item
  7.  
  8. import uiToolTip
  9. import localeInfo
  10. import ime
  11. import uiPickMoney
  12. import grp
  13. import mouseModule
  14.  
  15. from _weakref import proxy
  16.  
  17. PATH_ROOT = "cream/shopeditor/"
  18. PATH_ROOT_SEARCH = "cream/searchshop/"
  19.  
  20. class HistoryWindow(ui.Window):
  21. class NewItem(ui.Window):
  22. def __init__(self, index, data):
  23. ui.Window.__init__(self)
  24. self.background = None
  25. self.bSelected = False
  26. self.OnResetThings()
  27. self.Index = index
  28. self.Data = data
  29.  
  30. self.background = ui.ExpandedImageBox()
  31. self.background.SetParent(self)
  32. if self.Index != 0:
  33. self.background.LoadImage(PATH_ROOT + "bar_without_top.tga")
  34. else:
  35. self.background.LoadImage(PATH_ROOT + "bar_complete.tga")
  36.  
  37. self.background.OnMouseOverIn = ui.__mem_func__(self.OnMouseOverInImage)
  38. self.background.OnMouseOverOut = ui.__mem_func__(self.OnMouseOverOutImage)
  39. self.background.Show()
  40.  
  41. self.SetSize(self.background.GetWidth(), 26)
  42.  
  43. self.wndIcon = ui.ExpandedImageBox()
  44. self.wndIcon.SetParent(self)
  45. self.wndIcon.AddFlag("not_pick")
  46. self.wndIcon.LoadImage(PATH_ROOT_SEARCH + "yang.dds")
  47. self.wndIcon.SetPosition(26, 7)
  48. self.wndIcon.SetWindowHorizontalAlignRight()
  49. self.wndIcon.Show()
  50.  
  51. item.SelectItem(data["vnum"])
  52.  
  53. itemName = item.GetItemName()
  54. itemName = itemName if len(itemName) < 15 else itemName[:15] + "..."
  55.  
  56. self.wndName = ui.MakeTextLineNew(self, 6, 6, self.HasAttrItem(data) + itemName)
  57. self.wndPrice = ui.MakeTextLineNew(self, 35, 6, localeInfo.NumberToMoneyString(data["price"]))
  58. self.wndPrice.SetWindowHorizontalAlignRight()
  59. self.wndPrice.SetHorizontalAlignRight()
  60.  
  61. self.wndReason = ui.MakeTextLineNew(self, 0, 6, "Item Bought")
  62. self.wndReason.SetWindowHorizontalAlignCenter()
  63. self.wndReason.SetHorizontalAlignCenter()
  64.  
  65. self.OnMouseOverOutImage()
  66.  
  67. def HasAttrItem(self, Data):
  68. attrs = [(Data["attr"][num]['type'], Data["attr"][num]['value']) for num in xrange(player.ATTRIBUTE_SLOT_MAX_NUM)]
  69. if attrs:
  70. for i in xrange(player.ATTRIBUTE_SLOT_MAX_NUM):
  71. apply = attrs[i][0]
  72. if 0 > apply:
  73. return "|cFFFFC700"
  74.  
  75. return "|cFFF1E6C0"
  76.  
  77. def __del__(self):
  78. ui.Window.__del__(self)
  79.  
  80. def OnMouseOverInImage(self):
  81. if self.tooltipItem:
  82. sockets = [self.Data["socket"][num] for num in xrange(player.METIN_SOCKET_MAX_NUM)]
  83. attrs = [(self.Data["attr"][num]['type'], self.Data["attr"][num]['value']) for num in xrange(player.ATTRIBUTE_SLOT_MAX_NUM)]
  84.  
  85. self.tooltipItem.ClearToolTip()
  86.  
  87. self.tooltipItem.AppendIcon(self.Data["vnum"], self.Data["count"])
  88. self.tooltipItem.AddItemData(self.Data["vnum"], sockets, attrs)
  89.  
  90. self.tooltipItem.UpdateRect()
  91.  
  92. self.background.SetAlpha(1.0)
  93.  
  94. def OnMouseOverOutImage(self):
  95. if self.tooltipItem:
  96. self.tooltipItem.HideToolTip()
  97.  
  98. self.background.SetAlpha(0.8)
  99.  
  100. def SetItemToolTip(self, tooltip):
  101. self.tooltipItem = tooltip
  102.  
  103. def OnResetThings(self):
  104. self.IsSelected = False
  105. self.bIsBlocked = False
  106. self.vnum = 0
  107. self.xBase = 0
  108. self.yBase = 0
  109.  
  110. self.clickEvent = None
  111. if self.background != None:
  112. self.background.Hide()
  113. self.background = None
  114. self.wndIcon = None
  115. self.tooltipItem = None
  116. self.Data = None
  117.  
  118. def SetParent(self, parent):
  119. ui.Window.SetParent(self, parent)
  120. self.parent = proxy(parent)
  121.  
  122. def SetBasePosition(self, x, y):
  123. self.xBase = x
  124. self.yBase = y
  125.  
  126. def GetBasePosition(self):
  127. return (self.xBase, self.yBase)
  128.  
  129. def SetClickEvent(self, event):
  130. self.clickEvent = event
  131.  
  132. def Destroy(self):
  133. self.OnResetThings()
  134.  
  135. def OnRender(self):
  136. xList, yList = self.parent.GetGlobalPosition()
  137. widthList, heightList = self.parent.GetWidth(), self.parent.GetHeight()
  138.  
  139. images = [self.background, self.wndIcon]
  140. for img in images:
  141. if img:
  142. img.SetClipRect(xList, yList, xList + widthList, yList + heightList)
  143.  
  144. textList = [self.wndName, self.wndPrice, self.wndReason]
  145. for text in textList:
  146. if text:
  147. xText, yText = text.GetGlobalPosition()
  148.  
  149. if yText < yList or yText + text.GetTextSize()[1] > yList + heightList:
  150. text.Hide()
  151. else:
  152. text.Show()
  153.  
  154. def __init__(self):
  155. ui.Window.__init__(self)
  156. self.OnResetThings()
  157.  
  158. def __del__(self):
  159. ui.Window.__del__(self)
  160. self.OnResetThings()
  161.  
  162. def SetItemToolTip(self, tooltip):
  163. self.tooltipItem = tooltip
  164.  
  165. def Destroy(self):
  166. self.OnResetThings()
  167.  
  168. def OnResetThings(self):
  169. self.SetFuncDown = None
  170. self.SelectIndexFunc = None
  171. self.itemList = []
  172. self.scrollBar = None
  173.  
  174. self.selectEvent = None
  175. self.tooltipItem = None
  176.  
  177. def SetEventSelect(self, event):
  178. self.SelectIndexFunc = event
  179.  
  180. def SetScrollBar(self, scrollBar):
  181. scrollBar.SetScrollEvent(ui.__mem_func__(self.__OnScroll))
  182. scrollBar.SetScrollStep(0.2)
  183. self.scrollBar=scrollBar
  184.  
  185. def SetSelectEvent(self, event):
  186. self.selectEvent = event
  187.  
  188. def __OnScroll(self):
  189. self.RefreshItemPosition(True)
  190.  
  191. def GetTotalHeightItems(self):
  192. totalHeight = 0
  193.  
  194. if self.itemList:
  195. for itemH in self.itemList:
  196. totalHeight += itemH.GetHeight()
  197.  
  198. return totalHeight
  199.  
  200. def GetItemCount(self):
  201. return len(self.itemList)
  202.  
  203. def AppendItem(self, index, data):
  204. item = self.NewItem(index, data)
  205. item.SetParent(self)
  206. item.SetItemToolTip(self.tooltipItem)
  207.  
  208. if len(self.itemList) == 0:
  209. item.SetBasePosition(0, 0)
  210. else:
  211. x, y = self.itemList[-1].GetLocalPosition()
  212. y += 2
  213. item.SetBasePosition(0, y + self.itemList[-1].GetHeight())
  214.  
  215. item.Show()
  216. self.itemList.append(item)
  217.  
  218. self.ResetPosScrollBar()
  219. self.ResizeScrollBar()
  220. self.RefreshItemPosition()
  221.  
  222. if len(self.itemList) <= 13:
  223. self.scrollBar.Hide()
  224. else:
  225. self.scrollBar.Show()
  226.  
  227. def ResizeScrollBar(self):
  228. totalHeight = float(self.GetTotalHeightItems())
  229. if totalHeight:
  230. scrollBarHeight = min(float(self.GetHeight() - 10) / totalHeight, 1.0)
  231. else:
  232. scrollBarHeight = 1.0
  233.  
  234. self.scrollBar.SetMiddleBarSize(scrollBarHeight)
  235.  
  236. def ResetPosScrollBar(self):
  237. self.scrollBar.SetPos(0)
  238.  
  239. def RefreshItemPosition(self, bScroll = False):
  240. scrollPos = self.scrollBar.GetPos()
  241. totalHeight = self.GetTotalHeightItems() - self.GetHeight()
  242.  
  243. idx, CurIdx, yAccumulate = 0, 0, 0
  244. for item in self.itemList[idx:]:
  245. if bScroll:
  246. setPos = yAccumulate - int(scrollPos * totalHeight)
  247. item.SetPosition(0, setPos)
  248. else:
  249. item.SetPosition(0, yAccumulate)
  250.  
  251. item.SetBasePosition(0, yAccumulate)
  252.  
  253. CurIdx += 1
  254. yAccumulate += item.GetHeight()
  255.  
  256. def Clear(self):
  257. range = len(self.itemList)
  258.  
  259. if range > 0:
  260. for item in self.itemList:
  261. item.OnResetThings()
  262. item.Hide()
  263. del item
  264.  
  265. self.itemList = []
  266.  
Advertisement
Add Comment
Please, Sign In to add comment