Guest User

Untitled

a guest
Jul 8th, 2020
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.08 KB | None | 0 0
  1. import ui
  2. import quest
  3. import localeInfo
  4. import grp
  5. import event
  6. import chat
  7.  
  8. class QuestCategoryWindow(ui.Window):
  9.  
  10. MAX_CATEGORY = 6
  11. MAX_QUEST = 6
  12. MAX_CATEGORY_SIZE = 304
  13.  
  14. class QuestList(ui.Window):
  15. def __init__(self, parent):
  16. ui.Window.__init__(self)
  17.  
  18. self.__questList = {}
  19. self.__parentWnd = parent
  20. self.x = 0
  21. self.y = 0
  22.  
  23. def __del__(self):
  24. del self.__questList
  25. del self.__parentWnd
  26. ui.Window.__del__(self)
  27.  
  28. def Open(self):
  29. count = self.GetCount()
  30. if count > QuestCategoryWindow.MAX_QUEST:
  31. count = QuestCategoryWindow.MAX_QUEST
  32.  
  33. for i in xrange(count):
  34. self.__questList[i].Show()
  35. self.RefreshQuest()
  36.  
  37. def Close(self):
  38. for i in xrange(len(self.__questList)):
  39. self.__questList[i].Hide()
  40.  
  41. def OnScroll(self, i):
  42. self.Close()
  43. self.Open()
  44. for a in xrange(i):
  45. self.__questList[a].Hide()
  46. self.__questList[QuestCategoryWindow.MAX_QUEST + a].Show()
  47.  
  48. self.SetScrollPosition(i)
  49.  
  50. def SetScrollPosition(self, i):
  51. for a in xrange(len(self.__questList)):
  52. b = a - i
  53. self.__questList[a].SetPosition(self.x, self.y + b * 30)
  54.  
  55. def AppendItem(self, questName, questIndex):
  56. for i in xrange(len(self.__questList)):
  57. if self.__questList[i].text.GetText() == questName and self.__questList[i].questIndex == questIndex:
  58. return
  59.  
  60. bar = ui.Bar()
  61. bar.SetParent(self.__parentWnd)
  62. bar.SetSize(15+145+35, 10)
  63. bar.SetColor(grp.GenerateColor(1.0, 1.0, 1.0, 0.0))
  64. bar.OnMouseLeftButtonDown = lambda x=len(self.__questList), arg=questIndex: self.__SelectQuest(x, arg)
  65. bar.Hide()
  66.  
  67. bar.btn = ui.Button()
  68. bar.btn.SetParent(bar)
  69. bar.btn.SetUpVisual("Other/questcategory/quest_checkbox.tga")
  70. bar.btn.SetOverVisual("Other/questcategory/quest_checkbox.tga")
  71. bar.btn.SetDownVisual("Other/questcategory/quest_checkbox.tga")
  72. bar.btn.SetPosition(0, 0)
  73. bar.btn.Show()
  74.  
  75. bar.checked = ui.ImageBox()
  76. bar.checked.SetParent(bar.btn)
  77. bar.checked.LoadImage("Other/questcategory/quest_checked.tga")
  78. bar.checked.SetPosition(0,-2)
  79. bar.checked.Hide()
  80.  
  81. bar.text = ui.TextLine()
  82. bar.text.SetParent(bar)
  83. bar.text.SetText(questName)
  84. bar.text.SetPosition(15+145+35, -2)
  85. bar.text.SetWindowHorizontalAlignLeft()
  86. bar.text.SetHorizontalAlignLeft()
  87. bar.text.Show()
  88.  
  89. bar.text.clock = ui.TextLine()
  90. bar.text.clock.SetParent(bar.text)
  91. bar.text.clock.SetText(localeInfo.QUEST_UNLIMITED_TIME)
  92. bar.text.clock.SetPosition(15+145-10-55-45-75,10)
  93. bar.text.clock.SetWindowHorizontalAlignLeft()
  94. bar.text.clock.SetHorizontalAlignLeft()
  95. bar.text.clock.Show()
  96.  
  97. bar.text.counter = ui.TextLine()
  98. bar.text.counter.SetParent(bar.text)
  99. bar.text.counter.SetText("")
  100. bar.text.counter.SetPosition(15+145-10-55-45-75,20)
  101. bar.text.counter.SetWindowHorizontalAlignLeft()
  102. bar.text.counter.SetHorizontalAlignLeft()
  103. bar.text.counter.Show()
  104.  
  105. bar.questIndex = questIndex
  106.  
  107. self.__questList[len(self.__questList)] = bar
  108.  
  109. def SetPosition(self, x, y):
  110. for i in xrange(len(self.__questList)):
  111. self.__questList[i].SetPosition(x, y + i*30)
  112. self.x = x
  113. self.y = y
  114.  
  115. def GetCount(self):
  116. return len(self.__questList)
  117.  
  118. def GetHeight(self):
  119. return self.GetCount() * 30
  120.  
  121. def SetClockText(self, questIdx, text):
  122. self.__questList[questIdx].text.clock.SetText(text)
  123.  
  124. def SetCounterText(self, questIdx, text):
  125. self.__questList[questIdx].text.counter.SetText(text)
  126.  
  127. def __SelectQuest(self, qIdx, questIndex):
  128. self.__questList[qIdx].checked.Show()
  129. event.QuestButtonClick(questIndex)
  130.  
  131. def RefreshQuest(self):
  132. questCount = self.GetCount()
  133.  
  134. for i in xrange(questCount):
  135. (questName, questIcon, questCounterName, questCounterValue) = quest.GetQuestData(i)
  136.  
  137. if i >= questCount or i >= QuestCategoryWindow.MAX_QUEST:
  138. break
  139.  
  140. if questCounterName != "":
  141. self.SetCounterText(i, "%s : %d" % (questCounterName, questCounterValue))
  142. else:
  143. self.SetCounterText(i, "")
  144.  
  145. self.RefreshClock()
  146.  
  147. def RefreshClock(self):
  148. for i in xrange(self.GetCount()):
  149. try:
  150. (lastName, lastTime) = quest.GetQuestLastTime(i)
  151.  
  152. clockText = ""
  153. if len(lastName) > 0:
  154. clockText = localeInfo.QUEST_UNLIMITED_TIME
  155. if lastTime <= 0:
  156. clockText = localeInfo.QUEST_TIMEOVER
  157. else:
  158. questLastMinute = lastTime / 60
  159. questLastSecond = lastTime % 60
  160.  
  161. clockText = lastName + " : "
  162.  
  163. if questLastMinute > 0:
  164. clockText += str(questLastMinute) + localeInfo.QUEST_MIN
  165. if questLastSecond > 0:
  166. clockText += " "
  167.  
  168. if questLastSecond > 0:
  169. clockText += str(questLastSecond) + localeInfo.QUEST_SEC
  170.  
  171. if len(clockText) > 0:
  172. self.SetClockText(i, clockText)
  173. else:
  174. self.SetClockText(i, localeInfo.QUEST_UNLIMITED_TIME)
  175. except:
  176. pass
  177.  
  178. def __init__(self, parent):
  179. ui.Window.__init__(self)
  180. self.SetParent(parent)
  181. self.__questCategorySlot = []
  182. self.__questList = {}
  183. self.Diff = 0
  184. self.ScollPos = 0
  185. self.OpenCat = -1
  186. self.__MakeCategorySlot(parent)
  187.  
  188. def __del__(self):
  189. del self.__questCategorySlot
  190. del self.__questList
  191. ui.Window.__del__(self)
  192.  
  193. def __MakeCategorySlot(self, parent):
  194. for i in xrange(self.MAX_CATEGORY):
  195. self.__questCategorySlot.append(ui.Button())
  196. self.__questCategorySlot[i].SetParent(parent)
  197. self.__questCategorySlot[i].SetPosition(7, 5 + i*20)
  198. self.__questCategorySlot[i].SetSize(253, 23)
  199. self.__questCategorySlot[i].SetUpVisual("Other/questcategory/quest_category.tga")
  200. self.__questCategorySlot[i].SetOverVisual("Other/questcategory/quest_category.tga")
  201. self.__questCategorySlot[i].SetDownVisual("Other/questcategory/quest_category.tga")
  202. self.__questCategorySlot[i].SetTextAlignLeft("%s (0)" % getattr(localeInfo, "QUESTCATEGORY_%d" % i))
  203. self.__questCategorySlot[i].SetTextColor(0xFFFFE3AD)
  204. self.__questCategorySlot[i].SAFE_SetEvent(self.__OnClickQuestCategory, i)
  205. self.__questCategorySlot[i].Show()
  206. self.__questCategorySlot[i].openImage = ui.Button()
  207. self.__questCategorySlot[i].openImage.SetParent(self.__questCategorySlot[i])
  208. self.__questCategorySlot[i].openImage.SetUpVisual("Other/questcategory/quest_category_open.tga")
  209. self.__questCategorySlot[i].openImage.SetOverVisual("Other/questcategory/quest_category_open.tga")
  210. self.__questCategorySlot[i].openImage.SetDownVisual("Other/questcategory/quest_category_close.tga")
  211. self.__questCategorySlot[i].openImage.SetPosition(10,5)
  212. self.__questCategorySlot[i].openImage.SAFE_SetEvent(self.__OnClickQuestCategory, i)
  213. self.__questCategorySlot[i].openImage.Show()
  214. self.__questCategorySlot[i].closeImage = ui.Button()
  215. self.__questCategorySlot[i].closeImage.SetParent(self.__questCategorySlot[i])
  216. self.__questCategorySlot[i].closeImage.SetUpVisual("Other/questcategory/quest_category_open.tga")
  217. self.__questCategorySlot[i].closeImage.SetOverVisual("Other/questcategory/quest_category_open.tga")
  218. self.__questCategorySlot[i].closeImage.SetDownVisual("Other/questcategory/quest_category_close.tga")
  219. self.__questCategorySlot[i].closeImage.SetPosition(10,5)
  220. self.__questCategorySlot[i].closeImage.SAFE_SetEvent(self.__CloseCategories, i)
  221. self.__questCategorySlot[i].openImage.Show()
  222.  
  223. self.__questList[i] = self.QuestList(parent)
  224. self.__questList[i].Close()
  225.  
  226. self.questScrollBar = ui.ScrollBar()
  227. self.questScrollBar.SetParent(parent)
  228. self.questScrollBar.SetPosition(220, 10)
  229. self.questScrollBar.SetScrollBarSize(300)
  230. self.questScrollBar.Show()
  231. self.questScrollBar.SetScrollEvent(ui.__mem_func__(self.OnScroll))
  232.  
  233. def __IsCategoryOpen(self, categoryIndex):
  234. return self.__questCategorySlot[categoryIndex].openImage.IsDown()
  235.  
  236. def __CloseCategories(self):
  237. for i in xrange(self.MAX_CATEGORY):
  238. self.__questList[i].Close()
  239. self.__questCategorySlot[i].openImage.SetUp()
  240. self.__questCategorySlot[i].SetPosition(7, 5 + i*20)
  241.  
  242. self.OpenCat = -1
  243.  
  244. def __GetOpenedCategories(self):
  245. indexes = []
  246. for i in xrange(self.MAX_CATEGORY):
  247. if self.__IsCategoryOpen(i):
  248. indexes.append(i)
  249. return indexes
  250.  
  251. def __ArrangeQuestListPosition(self):
  252. for i in xrange(self.MAX_CATEGORY):
  253. (x,y) = self.__questCategorySlot[i].GetLocalPosition()
  254. self.__questList[i].SetPosition(20, y + 20)
  255.  
  256. def __OnClickQuestCategory(self, categoryIndex):
  257. isAlreadyOpen = self.__IsCategoryOpen(categoryIndex)
  258. self.__CloseCategories()
  259.  
  260. if isAlreadyOpen:
  261. return
  262.  
  263. self.__questCategorySlot[categoryIndex].openImage.Down()
  264. (x,y) = self.__questCategorySlot[categoryIndex].GetLocalPosition()
  265. self.__questList[categoryIndex].SetPosition(20, y + 20)
  266. self.__questList[categoryIndex].Open()
  267.  
  268. btnCount = self.__questList[categoryIndex].GetCount()
  269.  
  270. if btnCount <= 0:
  271. return
  272.  
  273. if btnCount > QuestCategoryWindow.MAX_QUEST:
  274. listHeight = 180 * len(self.__GetOpenedCategories())
  275. else:
  276. listHeight = self.__questList[categoryIndex].GetHeight() * len(self.__GetOpenedCategories())
  277. for i in xrange(categoryIndex + 1, self.MAX_CATEGORY):
  278. slotY = listHeight + (5 + i * 20)
  279. self.__questCategorySlot[i].SetPosition(7, slotY)
  280. self.__questList[i].SetPosition(20, slotY + 20)
  281.  
  282. self.Diff = btnCount - (QuestCategoryWindow.MAX_QUEST)
  283. stepSize = 1.0 / self.Diff
  284. self.questScrollBar.SetScrollStep(stepSize)
  285. self.OpenCat = categoryIndex
  286.  
  287. def RecvQuest(self, func, index, name):
  288. try:
  289. category = int(name[0])
  290. name = name[1:]
  291. except:
  292. category = 0
  293.  
  294. if func:
  295. func(index, name, "file", localeInfo.GetLetterImageName())
  296.  
  297. self.__questList[category].AppendItem(name, index)
  298. self.__questCategorySlot[category].SetTextAlignLeft("%s (%d)" % (getattr(localeInfo, "QUESTCATEGORY_%d" % category), self.__questList[category].GetCount()))
  299.  
  300. def OnUpdate(self):
  301. for i in xrange(self.MAX_CATEGORY):
  302. self.__questList[i].RefreshClock()
  303.  
  304. def OnScroll(self):
  305. if self.OpenCat == -1 :
  306. return
  307. self.ScollPos = int(self.questScrollBar.GetPos() * self.Diff)
  308. if self.ScollPos >= 0:
  309. self.__questList[self.OpenCat].OnScroll(self.ScollPos)
Add Comment
Please, Sign In to add comment