Guest User

uicaracterdetails

a guest
Dec 23rd, 2024
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.68 KB | None | 0 0
  1. import ui, player, item, net, app, localeInfo, constInfo
  2. from uiToolTip import ItemToolTip
  3.  
  4. IMG_DIR = "d:/ymir work/ui/game/characterdetails/"
  5.  
  6. bonus_list = [
  7. [localeInfo.BONUS_TABLE_TITLE_1,
  8. [
  9. [item.APPLY_ATTBONUS_MONSTER,53],
  10. # [item.APPLY_ATTBONUS_STONE,196],
  11. # [item.APPLY_ATTBONUS_BOSS,197],
  12. [item.APPLY_ATTBONUS_UNDEAD,47],
  13. [item.APPLY_ATTBONUS_DEVIL,48],
  14. [item.APPLY_ATTBONUS_ORC,45],
  15. [item.APPLY_ATTBONUS_ANIMAL,44],
  16. [item.APPLY_ATTBONUS_MILGYO,46],
  17. [item.APPLY_STEAL_HP,63],
  18. [item.APPLY_HP_REGEN,32],
  19. [item.APPLY_EXP_DOUBLE_BONUS,83],
  20. [item.APPLY_GOLD_DOUBLE_BONUS,84],
  21. [item.APPLY_ITEM_DROP_BONUS,85],
  22. [item.APPLY_ATT_GRADE_BONUS,79],
  23. ]
  24. ],
  25. [localeInfo.BONUS_TABLE_TITLE_2,
  26. [
  27. [item.APPLY_ATTBONUS_HUMAN,43],
  28. [item.APPLY_ATTBONUS_WARRIOR,54],
  29. [item.APPLY_ATTBONUS_ASSASSIN,55],
  30. [item.APPLY_ATTBONUS_SURA,56],
  31. [item.APPLY_ATTBONUS_SHAMAN,57],
  32. [item.APPLY_RESIST_WARRIOR,59],
  33. [item.APPLY_RESIST_ASSASSIN,60],
  34. [item.APPLY_RESIST_SURA,61],
  35. [item.APPLY_RESIST_SHAMAN,62],
  36. [item.APPLY_RESIST_SWORD,69],
  37. [item.APPLY_RESIST_TWOHAND,70],
  38. [item.APPLY_RESIST_DAGGER,71],
  39. [item.APPLY_RESIST_BELL,72],
  40. [item.APPLY_RESIST_FAN,73],
  41. [item.APPLY_RESIST_BOW,74],
  42. [item.APPLY_RESIST_MAGIC,77],
  43. [item.APPLY_MAGIC_ATTBONUS_PER,78],
  44. ]
  45. ],
  46. [localeInfo.BONUS_TABLE_TITLE_3,
  47. [
  48. [item.APPLY_SKILL_DAMAGE_BONUS,121],
  49. [item.APPLY_NORMAL_HIT_DAMAGE_BONUS,122],
  50. [item.APPLY_CRITICAL_PCT,40],
  51. [item.APPLY_PENETRATE_PCT,41],
  52. [item.APPLY_POISON_PCT,37],
  53. [item.APPLY_SLOW_PCT,39],
  54. [item.APPLY_STUN_PCT,38],
  55. [item.APPLY_CAST_SPEED,21],
  56. ]
  57. ],
  58. [localeInfo.BONUS_TABLE_TITLE_4,
  59. [
  60. [item.APPLY_SKILL_DEFEND_BONUS,123],
  61. [item.APPLY_NORMAL_HIT_DEFEND_BONUS,124],
  62. [item.APPLY_ANTI_CRITICAL_PCT,136],
  63. [item.APPLY_ANTI_PENETRATE_PCT,137],
  64. [item.APPLY_BLOCK,67],
  65. [item.APPLY_REFLECT_MELEE,79],
  66. [item.APPLY_DODGE,68],
  67. [item.APPLY_POISON_REDUCE,81],
  68. [item.APPLY_RESIST_FIRE,75],
  69. [item.APPLY_RESIST_ELEC,76],
  70. [item.APPLY_RESIST_WIND,78],
  71. [item.APPLY_DEF_GRADE_BONUS,79],
  72. [item.APPLY_MELEE_MAGIC_ATTBONUS_PER,80],
  73. ]
  74. ],
  75. ]
  76.  
  77. stat_list = [
  78. [localeInfo.BONUS_TABLE_1, player.POINT_BLUE_PLAYER_KILLED],
  79. [localeInfo.BONUS_TABLE_2, player.POINT_YELLOW_PLAYER_KILLED],
  80. [localeInfo.BONUS_TABLE_3, player.POINT_RED_PLAYER_KILLED],
  81. [localeInfo.BONUS_TABLE_4, player.POINT_ALL_PLAYER_KILLED],
  82. [localeInfo.BONUS_TABLE_5, player.POINT_KILL_DUELWON],
  83. [localeInfo.BONUS_TABLE_6, player.POINT_KILL_DUELLOST],
  84. [localeInfo.BONUS_TABLE_7, player.POINT_MONSTER_KILLED],
  85. [localeInfo.BONUS_TABLE_8, player.POINT_BOSS_KILLED],
  86. [localeInfo.BONUS_TABLE_9, player.POINT_STONE_KILLED]
  87. ]
  88.  
  89. class CharacterDetailsUI(ui.ScriptWindow):
  90. def __del__(self):
  91. ui.ScriptWindow.__del__(self)
  92. def Destroy(self):
  93. self.ClearDictionary()
  94. self.btnIndex = 0
  95. self.isPacketLoaded = False
  96. def Show(self):
  97. ui.ScriptWindow.Show(self)
  98. self.SetTop()
  99. self.Refresh()
  100. def Close(self):
  101. self.Hide()
  102. def AdjustPosition(self, x, y):
  103. self.SetPosition(x + self.GetWidth(), y)
  104. def __ClickRadioButton(self, buttonList, buttonIndex):
  105. try:
  106. radioBtn = buttonList[buttonIndex]
  107. except IndexError:
  108. return
  109. for eachButton in buttonList:
  110. eachButton.SetUp()
  111. radioBtn.Down()
  112. def __init__(self, parent):
  113. self.uiCharacterStatus = parent
  114. ui.ScriptWindow.__init__(self)
  115. self.Destroy()
  116. self.__LoadScript()
  117. def __LoadScript(self):
  118. try:
  119. pyScrLoader = ui.PythonScriptLoader()
  120. pyScrLoader.LoadScriptFile(self, "UIScript/CharacterDetailsWindow.py")
  121.  
  122. self.GetChild("bonus_button").SAFE_SetEvent(self.SetCategory,0)
  123. self.GetChild("stat_button").SAFE_SetEvent(self.SetCategory,1)
  124.  
  125. except:
  126. import exception
  127. exception.Abort("CharacterDetailsUI.__LoadScript")
  128.  
  129. elementList = self.ElementDictionary
  130. statWindow = self.GetChild("stat_window")
  131. for i in xrange(len(stat_list)):
  132. statName = ui.TextLine()
  133. statName.SetParent(statWindow)
  134. statName.AddFlag("not_pick")
  135. statName.SetPosition(70,15+(i*40))
  136. statName.SetFontName("Tahoma:13")
  137. statName.SetHorizontalAlignCenter()
  138. statName.SetText(stat_list[i][0])
  139. statName.Show()
  140. elementList["%d_stat_name"%i] = statName
  141.  
  142. statValue = ui.TextLine()
  143. statValue.AddFlag("not_pick")
  144. statValue.SetParent(statWindow)
  145. statValue.SetPosition(180,15+(i*40))
  146. statValue.SetFontName("Tahoma:13")
  147. statValue.SetHorizontalAlignCenter()
  148. statValue.Show()
  149. elementList["%d_stat"%i] = statValue
  150.  
  151. bonusWindow = self.GetChild("bonus_window")
  152.  
  153. searchBoard = SearchSlotBoard()
  154. searchBoard.SetParent(bonusWindow)
  155. searchBoard.SetPosition((bonusWindow.GetWidth()/2)-(129/2),11)
  156. searchBoard.SetSize(129,23)
  157. searchBoard.Show()
  158. elementList["searchBoard"] = searchBoard
  159.  
  160. itemSearch = ui.EditLine()
  161. itemSearch.SetParent(searchBoard)
  162. itemSearch.SetMax(40)
  163. itemSearch.SetPosition(5,5)
  164. itemSearch.SetSize(searchBoard.GetWidth(), searchBoard.GetHeight())
  165. itemSearch.OnIMEUpdate = ui.__mem_func__(self.__OnValueUpdate)
  166. itemSearch.Show()
  167. elementList["itemSearch"] = itemSearch
  168.  
  169. searchBtn = ui.Button()
  170. searchBtn.SetParent(searchBoard)
  171. searchBtn.SetUpVisual(IMG_DIR+"search_btn_0.tga")
  172. searchBtn.SetOverVisual(IMG_DIR+"search_btn_1.tga")
  173. searchBtn.SetDownVisual(IMG_DIR+"search_btn_2.tga")
  174. searchBtn.SetEvent(self.__OnValueUpdate)
  175. searchBtn.SetPosition(itemSearch.GetWidth()-searchBtn.GetWidth(),2)
  176. searchBtn.Show()
  177. elementList["searchBtn"] = searchBtn
  178.  
  179. scrollBar = ScrollBarNew()
  180. scrollBar.SetParent(bonusWindow)
  181. scrollBar.SetPosition((bonusWindow.GetWidth()-scrollBar.GetWidth())-3,43)
  182. scrollBar.SetScrollBarSize((bonusWindow.GetHeight()-46)-5)
  183. scrollBar.SetScrollEvent(ui.__mem_func__(self.Refresh))
  184. scrollBar.Show()
  185. elementList["scrollBar"] = scrollBar
  186.  
  187. for i in xrange(len(bonus_list)):
  188. bonus_data = bonus_list[i][1]
  189.  
  190. category = ui.ExpandedImageBox()
  191. category.SetParent(bonusWindow)
  192. category.LoadImage(IMG_DIR+"category_item.tga")
  193. category.buttonStatus = 0
  194. category.SetEvent(ui.__mem_func__(self.SetBonusCategory),"mouse_click", i)
  195. category.Show()
  196. elementList["%d_category"%i] = category
  197.  
  198. categoryText = ui.TextLine()
  199. categoryText.SetParent(category)
  200. categoryText.SetHorizontalAlignLeft()
  201. categoryText.SetPosition(8,3)
  202. categoryText.SetText("|Eemoji/plus|e "+bonus_list[i][0])
  203. categoryText.Show()
  204. elementList["%d_categoryText"%i] = categoryText
  205.  
  206. for j in xrange(len(bonus_data)):
  207. bonusImage = ui.ExpandedImageBox()
  208. bonusImage.SetParent(bonusWindow)
  209. bonusImage.LoadImage(IMG_DIR+"bonus_item.tga")
  210. bonusImage.Show()
  211. elementList["%d_%d_image"%(i,j)] = bonusImage
  212.  
  213. bonusText = ItemToolTip.AFFECT_DICT[bonus_data[j][0]](0)
  214.  
  215. disabledStr = ["%","+"]
  216. newText = ""
  217. for x in bonusText:
  218. if x in disabledStr:
  219. continue
  220. if x.isdigit():
  221. continue
  222. newText+=x
  223. bonusText=newText
  224. bonusImage.SAFE_SetStringEvent("OnMouseOverIn",self.OverInBonus, bonusText)
  225. bonusImage.SAFE_SetStringEvent("OnMouseOverOut",self.OverOutBonus)
  226.  
  227. bonusName = ui.TextLine()
  228. bonusName.AddFlag("not_pick")
  229. bonusName.SetParent(bonusImage)
  230. bonusName.SetHorizontalAlignCenter()
  231. bonusName.SetPosition(72,3)
  232. bonusName.SetFontName("Tahoma:13")
  233. bonusName.SetText(bonusText)
  234.  
  235. newText = ""
  236. if bonusName.GetTextSize()[0] > 134:
  237. for o in xrange(100):
  238. if bonusName.GetTextSize()[0] > 134:
  239. newText = bonusName.GetText()[:len(bonusName.GetText())-2]+"..."
  240. bonusName.SetText(bonusName.GetText()[:len(bonusName.GetText())-2])
  241. else:
  242. break
  243.  
  244. if newText != "":
  245. bonusName.SetText(newText)
  246.  
  247. bonusName.Show()
  248. elementList["%d_%d_name"%(i,j)] = bonusName
  249.  
  250. bonusValue = ui.TextLine()
  251. bonusValue.AddFlag("not_pick")
  252. bonusValue.SetParent(bonusImage)
  253. bonusValue.SetHorizontalAlignCenter()
  254. bonusValue.SetPosition(170,3)
  255. bonusValue.SetFontName("Tahoma:13")
  256. bonusValue.SetText("0")
  257. bonusValue.Show()
  258. elementList["%d_%d_value"%(i,j)] = bonusValue
  259.  
  260. self.SetCategory(0)
  261.  
  262. def OverOutBonus(self):
  263. interface = constInfo.GetInterfaceInstance()
  264. if interface:
  265. if interface.tooltipItem:
  266. interface.tooltipItem.HideToolTip()
  267. def OverInBonus(self, bonusName):
  268. interface = constInfo.GetInterfaceInstance()
  269. if interface:
  270. if interface.tooltipItem:
  271. interface.tooltipItem.ClearToolTip()
  272. interface.tooltipItem.AppendTextLine(bonusName)
  273. interface.tooltipItem.ShowToolTip()
  274.  
  275. def OnRunMouseWheel(self, nLen):
  276. if self.btnIndex == 0:
  277. if self.ElementDictionary.has_key("scrollBar"):
  278. scrollBar = self.ElementDictionary["scrollBar"]
  279. if scrollBar.IsShow():
  280. if nLen > 0:
  281. scrollBar.OnUp()
  282. else:
  283. scrollBar.OnDown()
  284. return True
  285. return False
  286.  
  287. def __OnValueUpdate(self):
  288. elementList = self.ElementDictionary
  289. itemSearch = elementList["itemSearch"]
  290. ui.EditLine.OnIMEUpdate(itemSearch)
  291. bonusWindow = self.GetChild("bonus_window")
  292. searchText = itemSearch.GetText()
  293. board = elementList["searchBoard"]
  294. totalWidth = 129
  295. if len(searchText) > 0:
  296. self.ElementDictionary["scrollBar"].SetPos(0, True)
  297. totalWidth-=25
  298. windowHeight = bonusWindow.GetWidth()-15
  299. textSize = itemSearch.GetTextSize()[0]
  300. if textSize >= totalWidth:
  301. if textSize >= windowHeight:
  302. totalWidth = windowHeight
  303. else:
  304. totalWidth = textSize
  305. totalWidth+=25
  306. if totalWidth >= windowHeight:
  307. totalWidth = windowHeight
  308. board.SetSize(totalWidth,23)
  309. itemSearch.SetSize(totalWidth,23)
  310. board.SetPosition((bonusWindow.GetWidth()/2)-(board.GetWidth()/2),11)
  311. searchBtn = elementList["searchBtn"]
  312. searchBtn.SetPosition(itemSearch.GetWidth()-searchBtn.GetWidth(),2)
  313. self.Refresh()
  314.  
  315. def SetBonusCategory(self, emptyArg, categoryIndex):
  316. category = self.ElementDictionary["%d_category"%categoryIndex]
  317. category.buttonStatus = not category.buttonStatus
  318. if category.buttonStatus == 0:
  319. self.ElementDictionary["%d_categoryText"%categoryIndex].SetText("|Eemoji/plus|e "+bonus_list[categoryIndex][0])
  320. else:
  321. self.ElementDictionary["%d_categoryText"%categoryIndex].SetText("|Eemoji/negative|e "+bonus_list[categoryIndex][0])
  322. self.Refresh()
  323.  
  324. def Refresh(self):
  325. elementList = self.ElementDictionary
  326. (X_POS,Y_POS) = (3,43)
  327. CATEGORY_Y_RANGE = 25
  328. CATEGORY_Y_FIRST_BONUS_RANGE = 29
  329. BONUS_X = 13
  330.  
  331. if self.btnIndex == 0:
  332. bonusWindow = self.GetChild("bonus_window")
  333. scrollBar = self.GetChild("scrollBar")
  334. (basePos,windowHeight) = (0,bonusWindow.GetHeight()-46)
  335.  
  336. searchText = elementList["itemSearch"].GetText().lower()
  337.  
  338. maxHeight = 0
  339. if len(searchText) > 0:
  340. for i in xrange(len(bonus_list)):
  341. bonus_data = bonus_list[i][1]
  342. for j in xrange(len(bonus_data)):
  343. text = elementList["%d_%d_name"%(i,j)].GetText().lower()
  344. if text.find(searchText) != -1:
  345. maxHeight += CATEGORY_Y_FIRST_BONUS_RANGE
  346. else:
  347. for i in xrange(len(bonus_list)):
  348. bonus_data = bonus_list[i][1]
  349. if elementList.has_key("%d_category"%i):
  350. categoryBtn = elementList["%d_category"%i]
  351. if categoryBtn.buttonStatus == 0:
  352. maxHeight += CATEGORY_Y_RANGE
  353. else:
  354. maxHeight += CATEGORY_Y_FIRST_BONUS_RANGE
  355. for j in xrange(len(bonus_data)):
  356. maxHeight += CATEGORY_Y_FIRST_BONUS_RANGE
  357.  
  358. if maxHeight > windowHeight:
  359. scrollLen = maxHeight-windowHeight
  360. basePos = int(scrollBar.GetPos()*scrollLen)
  361. stepSize = 1.0 / (scrollLen/100.0)
  362. scrollBar.SetScrollStep(stepSize)
  363. scrollBar.SetMiddleBarSize(float(windowHeight-5)/float(maxHeight))
  364. scrollBar.Show()
  365. else:
  366. scrollBar.Hide()
  367.  
  368. textLines = []
  369. images = []
  370. _wy = bonusWindow.GetGlobalPosition()[1]+43
  371.  
  372. if len(searchText) > 0:
  373. for i in xrange(len(bonus_list)):
  374. bonus_data = bonus_list[i][1]
  375. if elementList.has_key("%d_category"%i):
  376. elementList["%d_category"%i].Hide()
  377. for j in xrange(len(bonus_data)):
  378. text = elementList["%d_%d_name"%(i,j)].GetText().lower()
  379. if text.find(searchText) != -1:
  380. elementList["%d_%d_image"%(i,j)].Show()
  381. elementList["%d_%d_image"%(i,j)].SetPosition(BONUS_X, Y_POS - basePos)
  382. elementList["%d_%d_value"%(i,j)].SetText(str(player.GetStatus(bonus_data[j][1])))
  383. Y_POS += CATEGORY_Y_FIRST_BONUS_RANGE
  384. images.append(elementList["%d_%d_image"%(i,j)])
  385. textLines.append(elementList["%d_%d_name"%(i,j)])
  386. textLines.append(elementList["%d_%d_value"%(i,j)])
  387. else:
  388. elementList["%d_%d_image"%(i,j)].Hide()
  389. else:
  390. for i in xrange(len(bonus_list)):
  391. bonus_data = bonus_list[i][1]
  392. if elementList.has_key("%d_category"%i):
  393. categoryBtn = elementList["%d_category"%i]
  394. categoryBtn.SetPosition(X_POS, Y_POS - basePos)
  395. categoryBtn.Show()
  396.  
  397. images.append(categoryBtn)
  398. textLines.append(elementList["%d_categoryText"%i])
  399.  
  400. if categoryBtn.buttonStatus == 0:
  401. Y_POS += CATEGORY_Y_RANGE
  402. for j in xrange(len(bonus_data)):
  403. elementList["%d_%d_image"%(i,j)].Hide()
  404. else:
  405. Y_POS += CATEGORY_Y_FIRST_BONUS_RANGE
  406. for j in xrange(len(bonus_data)):
  407. elementList["%d_%d_image"%(i,j)].Show()
  408. elementList["%d_%d_image"%(i,j)].SetPosition(BONUS_X, Y_POS - basePos)
  409. elementList["%d_%d_value"%(i,j)].SetText(str(player.GetStatus(bonus_data[j][1])))
  410. Y_POS += CATEGORY_Y_FIRST_BONUS_RANGE
  411.  
  412. images.append(elementList["%d_%d_image"%(i,j)])
  413. textLines.append(elementList["%d_%d_name"%(i,j)])
  414. textLines.append(elementList["%d_%d_value"%(i,j)])
  415.  
  416. for childItem in textLines:
  417. (_x,_y) = childItem.GetGlobalPosition()
  418. if _y < _wy:
  419. if childItem.IsShow():
  420. childItem.Hide()
  421. elif _y > (_wy+windowHeight-20):
  422. if childItem.IsShow():
  423. childItem.Hide()
  424. else:
  425. if not childItem.IsShow():
  426. childItem.Show()
  427.  
  428. for childItem in images:
  429. childHeight = childItem.GetHeight()
  430. (_x,_y) = childItem.GetGlobalPosition()
  431. if _y < _wy:
  432. childItem.SetRenderingRect(0,ui.calculateRect(childHeight-abs(_y-_wy),childHeight),0,0)
  433. elif _y+childHeight > (_wy+windowHeight-4):
  434. calculate = (_wy+windowHeight-4) - (_y+childHeight)
  435. if calculate == 0:
  436. return
  437. f = ui.calculateRect(childHeight-abs(calculate),childHeight)
  438. childItem.SetRenderingRect(0,0,0,f)
  439. else:
  440. childItem.SetRenderingRect(0,0,0,0)
  441.  
  442. elif self.btnIndex == 1:
  443. for i in xrange(len(stat_list)):
  444. if elementList.has_key("%d_stat"%i):
  445. elementList["%d_stat"%i].SetText(localeInfo.DottedNumber(player.GetStatus(stat_list[i][1])))
  446.  
  447. def OnUpdate(self):
  448. self.Refresh()
  449.  
  450. def SetCategory(self, categoryIndex):
  451. self.btnIndex = categoryIndex
  452. self.__ClickRadioButton([self.GetChild("bonus_button"),self.GetChild("stat_button")],categoryIndex)
  453. self.ElementDictionary["itemSearch"].KillFocus()
  454. if self.btnIndex == 0:
  455. self.GetChild("bonus_window").Show()
  456. self.GetChild("stat_window").Hide()
  457. elif self.btnIndex == 1:
  458. self.GetChild("bonus_window").Hide()
  459. self.GetChild("stat_window").Show()
  460.  
  461. self.Refresh()
  462.  
  463. def OnScroll(self):
  464. pass
  465.  
  466. def OnPressEscapeKey(self):
  467. self.Close()
  468. return True
  469.  
  470.  
  471. class ScrollBarNew(ui.Window):
  472. SCROLLBAR_WIDTH = 7
  473. SCROLL_BTN_XDIST = 0
  474. SCROLL_BTN_YDIST = 0
  475. class MiddleBar(ui.DragButton):
  476. def __init__(self):
  477. ui.DragButton.__init__(self)
  478. self.AddFlag("movable")
  479. self.SetWindowName("scrollbar_middlebar")
  480. def MakeImage(self):
  481. top = ui.ExpandedImageBox()
  482. top.SetParent(self)
  483. top.LoadImage(IMG_DIR+"scrollbar/scrollbar_top.tga")
  484. top.AddFlag("not_pick")
  485. top.Show()
  486. topScale = ui.ExpandedImageBox()
  487. topScale.SetParent(self)
  488. topScale.SetPosition(0, top.GetHeight())
  489. topScale.LoadImage(IMG_DIR+"scrollbar/scrollbar_scale.tga")
  490. topScale.AddFlag("not_pick")
  491. topScale.Show()
  492. bottom = ui.ExpandedImageBox()
  493. bottom.SetParent(self)
  494. bottom.LoadImage(IMG_DIR+"scrollbar/scrollbar_bottom.tga")
  495. bottom.AddFlag("not_pick")
  496. bottom.Show()
  497. bottomScale = ui.ExpandedImageBox()
  498. bottomScale.SetParent(self)
  499. bottomScale.LoadImage(IMG_DIR+"scrollbar/scrollbar_scale.tga")
  500. bottomScale.AddFlag("not_pick")
  501. bottomScale.Show()
  502. middle = ui.ExpandedImageBox()
  503. middle.SetParent(self)
  504. middle.LoadImage(IMG_DIR+"scrollbar/scrollbar_mid.tga")
  505. middle.AddFlag("not_pick")
  506. middle.Show()
  507. self.top = top
  508. self.topScale = topScale
  509. self.bottom = bottom
  510. self.bottomScale = bottomScale
  511. self.middle = middle
  512. def SetSize(self, height):
  513. minHeight = self.top.GetHeight() + self.bottom.GetHeight() + self.middle.GetHeight()
  514. height = max(minHeight, height)
  515. ui.DragButton.SetSize(self, 10, height)
  516. scale = (height - minHeight) / 2
  517. extraScale = 0
  518. if (height - minHeight) % 2 == 1:
  519. extraScale = 1
  520. self.topScale.SetRenderingRect(0, 0, 0, scale - 1)
  521. self.middle.SetPosition(0, self.top.GetHeight() + scale)
  522. self.bottomScale.SetPosition(0, self.middle.GetBottom())
  523. self.bottomScale.SetRenderingRect(0, 0, 0, scale - 1 + extraScale)
  524. self.bottom.SetPosition(0, height - self.bottom.GetHeight())
  525. def __init__(self):
  526. ui.Window.__init__(self)
  527. self.pageSize = 1
  528. self.curPos = 0.0
  529. self.eventScroll = None
  530. self.eventArgs = None
  531. self.lockFlag = False
  532. self.CreateScrollBar()
  533. self.SetScrollBarSize(0)
  534. self.scrollStep = 0.4
  535. self.SetWindowName("NONAME_ScrollBar")
  536. def __del__(self):
  537. ui.Window.__del__(self)
  538. def CreateScrollBar(self):
  539. topImage = ui.ExpandedImageBox()
  540. topImage.SetParent(self)
  541. topImage.AddFlag("not_pick")
  542. topImage.LoadImage(IMG_DIR+"scrollbar/scroll_top.tga")
  543. topImage.Show()
  544. bottomImage = ui.ExpandedImageBox()
  545. bottomImage.SetParent(self)
  546. bottomImage.AddFlag("not_pick")
  547. bottomImage.LoadImage(IMG_DIR+"scrollbar/scroll_bottom.tga")
  548. bottomImage.Show()
  549. middleImage = ui.ExpandedImageBox()
  550. middleImage.SetParent(self)
  551. middleImage.AddFlag("not_pick")
  552. middleImage.SetPosition(0, topImage.GetHeight())
  553. middleImage.LoadImage(IMG_DIR+"scrollbar/scroll_mid.tga")
  554. middleImage.Show()
  555. self.topImage = topImage
  556. self.bottomImage = bottomImage
  557. self.middleImage = middleImage
  558. middleBar = self.MiddleBar()
  559. middleBar.SetParent(self)
  560. middleBar.SetMoveEvent(ui.__mem_func__(self.OnMove))
  561. middleBar.Show()
  562. middleBar.MakeImage()
  563. middleBar.SetSize(12)
  564. self.middleBar = middleBar
  565. def Destroy(self):
  566. self.eventScroll = None
  567. self.eventArgs = None
  568. def SetScrollEvent(self, event, *args):
  569. self.eventScroll = event
  570. self.eventArgs = args
  571. def SetMiddleBarSize(self, pageScale):
  572. self.middleBar.SetSize(int(pageScale * float(self.GetHeight() - (self.SCROLL_BTN_YDIST*2))))
  573. realHeight = self.GetHeight() - (self.SCROLL_BTN_YDIST*2) - self.middleBar.GetHeight()
  574. self.pageSize = realHeight
  575.  
  576. def SetScrollBarSize(self, height):
  577. self.SetSize(self.SCROLLBAR_WIDTH, height)
  578. self.pageSize = height - self.SCROLL_BTN_YDIST*2 - self.middleBar.GetHeight()
  579. middleImageScale = float((height - self.SCROLL_BTN_YDIST*2) - self.middleImage.GetHeight()) / float(self.middleImage.GetHeight())
  580. self.middleImage.SetRenderingRect(0, 0, 0, middleImageScale)
  581. self.bottomImage.SetPosition(0, height - self.bottomImage.GetHeight())
  582. self.middleBar.SetRestrictMovementArea(self.SCROLL_BTN_XDIST, self.SCROLL_BTN_YDIST, \
  583. self.middleBar.GetWidth(), height - self.SCROLL_BTN_YDIST * 2)
  584. self.middleBar.SetPosition(self.SCROLL_BTN_XDIST, self.SCROLL_BTN_YDIST)
  585. def SetScrollStep(self, step):
  586. self.scrollStep = step
  587. def OnUp(self):
  588. self.SetPos(self.curPos-self.scrollStep)
  589. def OnDown(self):
  590. self.SetPos(self.curPos+self.scrollStep)
  591. def GetScrollStep(self):
  592. return self.scrollStep
  593. def GetPos(self):
  594. return self.curPos
  595. def OnUp(self):
  596. self.SetPos(self.curPos-self.scrollStep)
  597. def OnDown(self):
  598. self.SetPos(self.curPos+self.scrollStep)
  599. def SetPos(self, pos, moveEvent = True):
  600. pos = max(0.0, pos)
  601. pos = min(1.0, pos)
  602. newPos = float(self.pageSize) * pos
  603. self.middleBar.SetPosition(self.SCROLL_BTN_XDIST, int(newPos) + self.SCROLL_BTN_YDIST)
  604. if moveEvent == True:
  605. self.OnMove()
  606. def OnMove(self):
  607. if self.lockFlag:
  608. return
  609. if 0 == self.pageSize:
  610. return
  611. (xLocal, yLocal) = self.middleBar.GetLocalPosition()
  612. self.curPos = float(yLocal - self.SCROLL_BTN_YDIST) / float(self.pageSize)
  613. if self.eventScroll:
  614. apply(self.eventScroll, self.eventArgs)
  615. def OnMouseLeftButtonDown(self):
  616. (xMouseLocalPosition, yMouseLocalPosition) = self.GetMouseLocalPosition()
  617. newPos = float(yMouseLocalPosition) / float(self.GetHeight())
  618. self.SetPos(newPos)
  619. def LockScroll(self):
  620. self.lockFlag = True
  621. def UnlockScroll(self):
  622. self.lockFlag = False
  623.  
  624. class SearchSlotBoard(ui.Window):
  625. CORNER_WIDTH = 7
  626. CORNER_HEIGHT = 7
  627. LINE_WIDTH = 7
  628. LINE_HEIGHT = 7
  629. LT = 0
  630. LB = 1
  631. RT = 2
  632. RB = 3
  633. L = 0
  634. R = 1
  635. T = 2
  636. B = 3
  637. def __init__(self):
  638. ui.Window.__init__(self)
  639. self.MakeBoard()
  640. self.MakeBase()
  641. def MakeBoard(self):
  642. cornerPath = IMG_DIR+"board/corner_"
  643. linePath = IMG_DIR+"board/"
  644. CornerFileNames = [ cornerPath+dir+".tga" for dir in ("left_top", "left_bottom", "right_top", "right_bottom") ]
  645. LineFileNames = [ linePath+dir+".tga" for dir in ("left", "right", "top", "bottom") ]
  646. self.Corners = []
  647. for fileName in CornerFileNames:
  648. Corner = ui.ExpandedImageBox()
  649. Corner.AddFlag("not_pick")
  650. Corner.LoadImage(fileName)
  651. Corner.SetParent(self)
  652. Corner.SetPosition(0, 0)
  653. Corner.Show()
  654. self.Corners.append(Corner)
  655. self.Lines = []
  656. for fileName in LineFileNames:
  657. Line = ui.ExpandedImageBox()
  658. Line.AddFlag("not_pick")
  659. Line.LoadImage(fileName)
  660. Line.SetParent(self)
  661. Line.SetPosition(0, 0)
  662. Line.Show()
  663. self.Lines.append(Line)
  664. self.Lines[self.L].SetPosition(0, self.CORNER_HEIGHT)
  665. self.Lines[self.T].SetPosition(self.CORNER_WIDTH, 0)
  666. def MakeBase(self):
  667. self.Base = ui.ExpandedImageBox()
  668. self.Base.AddFlag("not_pick")
  669. self.Base.LoadImage(IMG_DIR+"board/base.tga")
  670. self.Base.SetParent(self)
  671. self.Base.SetPosition(self.CORNER_WIDTH, self.CORNER_HEIGHT)
  672. self.Base.Show()
  673. def __del__(self):
  674. ui.Window.__del__(self)
  675. def Destroy(self):
  676. self.Base=0
  677. self.Corners=0
  678. self.Lines=0
  679. self.CORNER_WIDTH = 0
  680. self.CORNER_HEIGHT = 0
  681. self.LINE_WIDTH = 0
  682. self.LINE_HEIGHT = 0
  683. self.LT = 0
  684. self.LB = 0
  685. self.RT = 0
  686. self.RB = 0
  687. self.L = 0
  688. self.R = 0
  689. self.T = 0
  690. self.B = 0
  691. def SetSize(self, width, height):
  692. width = max(self.CORNER_WIDTH*2, width)
  693. height = max(self.CORNER_HEIGHT*2, height)
  694. ui.Window.SetSize(self, width, height)
  695. self.Corners[self.LB].SetPosition(0, height - self.CORNER_HEIGHT)
  696. self.Corners[self.RT].SetPosition(width - self.CORNER_WIDTH, 0)
  697. self.Corners[self.RB].SetPosition(width - self.CORNER_WIDTH, height - self.CORNER_HEIGHT)
  698. self.Lines[self.R].SetPosition(width - self.CORNER_WIDTH, self.CORNER_HEIGHT)
  699. self.Lines[self.B].SetPosition(self.CORNER_HEIGHT, height - self.CORNER_HEIGHT)
  700. verticalShowingPercentage = float((height - self.CORNER_HEIGHT*2) - self.LINE_HEIGHT) / self.LINE_HEIGHT
  701. horizontalShowingPercentage = float((width - self.CORNER_WIDTH*2) - self.LINE_WIDTH) / self.LINE_WIDTH
  702. self.Lines[self.L].SetRenderingRect(0, 0, 0, verticalShowingPercentage)
  703. self.Lines[self.R].SetRenderingRect(0, 0, 0, verticalShowingPercentage)
  704. self.Lines[self.T].SetRenderingRect(0, 0, horizontalShowingPercentage, 0)
  705. self.Lines[self.B].SetRenderingRect(0, 0, horizontalShowingPercentage, 0)
  706. if self.Base:
  707. self.Base.SetRenderingRect(0, 0, horizontalShowingPercentage, verticalShowingPercentage)
  708.  
Advertisement
Add Comment
Please, Sign In to add comment