Guest User

Untitled

a guest
Jul 25th, 2022
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.60 KB | None | 0 0
  1. import app, net, ui, dbg, os, localeInfo, constInfo, uiScriptLocale, uiCommon
  2. from _weakref import proxy
  3.  
  4. IMAGE_PATH = "d:/ymir work/ui/patchnote/"
  5.  
  6. MAX_VIEW_PATCHNOTES = 10
  7.  
  8. class PatchNoteWindow(ui.ScriptWindow):
  9. def __init__(self):
  10. ui.ScriptWindow.__init__(self)
  11. self.ScrollBarStep = 0.2
  12. self.curScrollbarPos = 0.0
  13.  
  14. self.LoadWindow()
  15.  
  16. def __del__(self):
  17. ui.ScriptWindow.__del__(self)
  18. self.ScrollBarStep = 0.2
  19. self.curScrollbarPos = 0.0
  20. self.destScrollbarPos = 0.0
  21.  
  22. def Show(self):
  23. ui.ScriptWindow.Show(self)
  24.  
  25. def Close(self):
  26. self.Hide()
  27.  
  28. def LoadWindow(self):
  29. try:
  30. pyScrLoader = ui.PythonScriptLoader()
  31. pyScrLoader.LoadScriptFile(self, "uiscript/patchnotes.py")
  32. except:
  33. import exception
  34. exception.Abort("PatchNoteWindow.LoadWindow.LoadObject")
  35.  
  36. try:
  37. self.GetChild("board").SetCloseEvent(self.Close)
  38.  
  39. self.boxPatchnotes = ListBoxItems()
  40. self.boxPatchnotes.SetParent(self.GetChild("patch_notes_area"))
  41. self.boxPatchnotes.SetGlobalParent(self)
  42. self.boxPatchnotes.SetPosition(0, 0)
  43. self.boxPatchnotes.SetSize(627, 489)
  44. self.boxPatchnotes.Show()
  45.  
  46. self.scrollBar = ScrollBar()
  47. self.scrollBar.SetParent(self.GetChild("patch_scrollbar_area"))
  48. self.scrollBar.SetScrollEvent(ui.__mem_func__(self.OnScroll))
  49. self.scrollBar.SetTexture(IMAGE_PATH + "patchnote_scrollbar.png")
  50. self.scrollBar.SetMovementArea(0, 0, 4, 493)
  51. self.scrollBar.SetPosition(0, 0)
  52. self.scrollBar.Show()
  53.  
  54. self.BuildPatchnotes()
  55.  
  56. except:
  57. import exception
  58. exception.Abort("PatchNoteWindow.LoadWindow.BindObject")
  59.  
  60.  
  61. def OnScroll(self):
  62. self.boxPatchnotes.OnScroll(self.scrollBar.GetPos())
  63.  
  64. def OnUpdate(self):
  65. self.curScrollbarPos = self.scrollBar.GetPos()
  66. self.destScrollbarPos = self.scrollBar.GetPos()
  67.  
  68. def BuildPatchnotes(self):
  69. try:
  70. patchnotes = open("%s/patchnotes.txt" % app.GetLocalePath(), "r")
  71. except:
  72. patchnotes = open("locale/pl/patchnotes.txt", "r")
  73.  
  74. count_patchnotes = 0
  75. isUpdate = False
  76. title = ["", ""]
  77. lines = []
  78.  
  79. for line in patchnotes:
  80. if "Version: " in line:
  81. title[0] = line.split()[1]
  82. if "Date: " in line:
  83. title[1] = line.split()[1]
  84. if "## UPDATE ##" in line:
  85. isUpdate = True
  86. continue
  87. if "## END ##" in line:
  88. self.boxPatchnotes.AppendObject(title, lines)
  89. isUpdate = False
  90. title = ["", ""]
  91. lines = []
  92. count_patchnotes += 1
  93. if MAX_VIEW_PATCHNOTES != 0 and MAX_VIEW_PATCHNOTES == count_patchnotes:
  94. break
  95.  
  96. if isUpdate:
  97. lines.append(self.SplitDescription(line, 120))
  98.  
  99. if count_patchnotes > 8:
  100. self.ScrollBarStep = 0.1
  101. if count_patchnotes > 12:
  102. self.ScrollBarStep = 0.07
  103. if count_patchnotes > 15:
  104. self.ScrollBarStep = 0.04
  105.  
  106. def SplitDescription(self, desc, limit):
  107. total_tokens = desc.split()
  108. line_tokens = []
  109. line_len = 0
  110. lines = []
  111. for token in total_tokens:
  112. if "|" in token:
  113. sep_pos = token.find("|")
  114. line_tokens.append(token[:sep_pos])
  115.  
  116. lines.append(" ".join(line_tokens))
  117. line_len = len(token) - (sep_pos + 1)
  118. line_tokens = [token[sep_pos+1:]]
  119. else:
  120. line_len += len(token)
  121. if len(line_tokens) + line_len > limit:
  122. lines.append(" ".join(line_tokens))
  123. line_len = len(token)
  124. line_tokens = [token]
  125. else:
  126. line_tokens.append(token)
  127.  
  128. if line_tokens:
  129. lines.append(" ".join(line_tokens))
  130.  
  131. return lines
  132.  
  133. class ListBoxItems(ui.Window):
  134. class Item(ui.Window):
  135. def __init__(self, parent, index, title, lines):
  136. ui.Window.__init__(self)
  137. ui.Window.SetParent(self, parent)
  138.  
  139. self.parent = proxy(parent)
  140. self.SetWindowName("ListBox_Patchnotes")
  141. self.xBase, self.yBase = 0, 0
  142.  
  143. self.index = index
  144.  
  145. self.image_title = ui.MakeExpandedImageBox(self, IMAGE_PATH + "patchnote_top.png", 0, 0, "not_pick")
  146. self.image_title.SetParent(self)
  147. self.image_title.Show()
  148.  
  149. self.textVersion = ui.TextLine()
  150. self.textVersion.SetParent(self.image_title)
  151. self.textVersion.SetHorizontalAlignCenter()
  152. self.textVersion.SetPosition(50, 4)
  153. self.textVersion.SetPackedFontColor(0xffffffff)
  154. self.textVersion.SetFontName(localeInfo.UI_DEF_FONT_LARGE)
  155. self.textVersion.SetOutline()
  156. self.textVersion.SetText(str(title[0]))
  157. self.textVersion.Show()
  158.  
  159. self.textDate = ui.TextLine()
  160. self.textDate.SetParent(self.image_title)
  161. self.textDate.SetHorizontalAlignCenter()
  162. self.textDate.SetPosition(580, 4)
  163. self.textDate.SetPackedFontColor(0xffffffff)
  164. self.textDate.SetFontName(localeInfo.UI_DEF_FONT_LARGE)
  165. self.textDate.SetOutline()
  166. self.textDate.SetText(str(title[1]))
  167. self.textDate.Show()
  168.  
  169. self.text_backgrounds = []
  170. self.text_rows = []
  171.  
  172. line_count = 0
  173. for row_lines in xrange(len(lines)):
  174. for sub_lines in xrange(len(lines[row_lines])):
  175. row_image = ui.MakeExpandedImageBox(self, IMAGE_PATH + "patchnote_middle.png", 0, 22 + 15 * line_count, "not_pick")
  176. row_image.SetParent(self)
  177. row_image.Show()
  178. self.text_backgrounds.append(row_image)
  179.  
  180. textLine = ui.TextLine()
  181. textLine.SetParent(row_image)
  182. textLine.SetPosition(5, 0)
  183. textLine.SetFontName("Tahoma:12")
  184. textLine.SetText(str(lines[row_lines][sub_lines]))
  185. textLine.Show()
  186. self.text_rows.append(textLine)
  187. line_count += 1
  188. row_image = ui.MakeExpandedImageBox(self, IMAGE_PATH + "patchnote_bottom.png", 0, 22 + 15 * line_count, "not_pick")
  189. row_image.SetParent(self)
  190. row_image.Show()
  191. self.text_backgrounds.append(row_image)
  192.  
  193. def __del__(self):
  194. ui.Window.__del__(self)
  195. self.xBase, self.yBase = 0, 0
  196. self.index = 0
  197.  
  198. def SetBasePosition(self, x, y):
  199. self.xBase = x
  200. self.yBase = y
  201.  
  202. def GetBasePosition(self):
  203. return (self.xBase, self.yBase)
  204.  
  205. def GetIndex(self):
  206. return self.index
  207.  
  208. def Show(self):
  209. ui.Window.Show(self)
  210.  
  211. def OnRender(self):
  212. xList, yList = self.parent.GetGlobalPosition()
  213.  
  214. self.image_title.SetClipRect(xList, yList, xList + self.parent.GetWidth(), yList + self.parent.GetHeight())
  215.  
  216. xText, yText = self.textVersion.GetGlobalPosition()
  217. wText, hText = self.textVersion.GetWidth(), 13
  218.  
  219. if yText < yList or (yText + hText > yList + self.parent.GetHeight()):
  220. self.textVersion.Hide()
  221. self.textDate.Hide()
  222. else:
  223. self.textVersion.Show()
  224. self.textDate.Show()
  225.  
  226. for i in xrange(len(self.text_backgrounds)):
  227. self.text_backgrounds[i].SetClipRect(xList, yList, xList + self.parent.GetWidth(), yList + self.parent.GetHeight())
  228.  
  229. for i in xrange(len(self.text_rows)):
  230. xText, yText = self.text_rows[i].GetGlobalPosition()
  231. wText, hText = self.text_rows[i].GetWidth(), 13
  232.  
  233. if yText < yList or (yText + hText > yList + self.parent.GetHeight()):
  234. self.text_rows[i].Hide()
  235. else:
  236. self.text_rows[i].Show()
  237.  
  238.  
  239. def __init__(self):
  240. ui.Window.__init__(self)
  241. self.SetWindowName("ListBox")
  242. self.globalParent = None
  243. self.size_y = 0
  244. self.index_list = 0
  245. self.object_list = []
  246.  
  247. def __del__(self):
  248. ui.Window.__del__(self)
  249. self.globalParent = None
  250. self.size_y = 0
  251. self.index_list = 0
  252. self.object_list = []
  253.  
  254. def GetObjectCount(self):
  255. count = 0
  256. for i in xrange(len(self.object_list)):
  257. count += 1
  258. return count
  259.  
  260. def GetSize(self):
  261. return self.size_y
  262.  
  263. def SetGlobalParent(self, parent):
  264. self.globalParent = proxy(parent)
  265.  
  266. def OnScroll(self, scrollPos):
  267. totalHeight = 0
  268. for item in self.object_list:
  269. totalHeight += item.GetHeight()
  270.  
  271. totalHeight -= self.GetHeight()
  272.  
  273. for i in xrange(len(self.object_list)):
  274. x, y = self.object_list[i].GetLocalPosition()
  275. xB, yB = self.object_list[i].GetBasePosition()
  276. setPos = yB - int(scrollPos * totalHeight)
  277. self.object_list[i].SetPosition(xB, setPos)
  278.  
  279. def AppendObject(self, title, lines):
  280. self.index_list += 1
  281. item = self.Item(self, self.index_list, title, lines)
  282.  
  283. line_count = 0
  284. for row_lines in xrange(len(lines)):
  285. for sub_lines in xrange(len(lines[row_lines])):
  286. line_count += 15
  287.  
  288. item.SetSize(639, 30 + line_count + 4 + 4)
  289. self.size_y += 22 + line_count + 4 + 4
  290.  
  291. if len(self.object_list) == 0:
  292. item.SetPosition(0, 0)
  293. item.SetBasePosition(0, 0)
  294. else:
  295. x, y = self.object_list[-1].GetLocalPosition()
  296. item.SetPosition(0, y + self.object_list[-1].GetHeight())
  297. item.SetBasePosition(0, y + self.object_list[-1].GetHeight())
  298.  
  299. item.Show()
  300. self.object_list.append(item)
  301.  
  302. def ClearList(self):
  303. self.index_list = 0
  304. self.object_list = []
  305.  
  306. class ScrollBar(ui.DragButton):
  307. def __init__(self):
  308. ui.DragButton.__init__(self)
  309. self.AddFlag("float")
  310. self.AddFlag("movable")
  311. self.AddFlag("restrict_x")
  312.  
  313. self.eventScroll = lambda *arg: None
  314. self.movearea = 0
  315. self.currentPos = 0.0
  316.  
  317. def __del__(self):
  318. ui.DragButton.__del__(self)
  319. self.movearea = 0
  320. self.currentPos = 0.0
  321. self.eventScroll = lambda *arg: None
  322.  
  323. def SetMovementArea(self, x, y, width, height):
  324. self.movearea = height - y - self.GetHeight()
  325. self.SetRestrictMovementArea(x, y, width, height)
  326.  
  327. def SetTexture(self, image):
  328. self.SetUpVisual(image)
  329. self.SetOverVisual(image)
  330. self.SetDownVisual(image)
  331.  
  332. def SetScrollEvent(self, event):
  333. self.eventScroll = event
  334.  
  335. def SetPos(self, pos):
  336. pos = max(0.0, pos)
  337. pos = min(1.0, pos)
  338.  
  339. yPos = float(pos * self.movearea)
  340.  
  341. self.SetPosition(12, yPos)
  342. self.OnMove()
  343.  
  344. def GetPos(self):
  345. return self.currentPos
  346.  
  347. def OnMove(self):
  348. (xLocal, yLocal) = self.GetLocalPosition()
  349. self.currentPos = float(yLocal) / float(self.movearea)
  350.  
  351. self.eventScroll()
Advertisement
Add Comment
Please, Sign In to add comment