Advertisement
Guest User

uiminimap.py

a guest
Jan 24th, 2021
190
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.52 KB | None
  1. import ui
  2. import uiScriptLocale
  3. import wndMgr
  4. import player
  5. import miniMap
  6. import localeInfo
  7. import net
  8. import app
  9. import colorInfo
  10. import constInfo
  11. import background
  12. import uiDungeonInfo
  13.  
  14. class MapTextToolTip(ui.Window):
  15. def __init__(self):
  16. ui.Window.__init__(self)
  17.  
  18. textLine = ui.TextLine()
  19. textLine.SetParent(self)
  20. textLine.SetHorizontalAlignCenter()
  21. textLine.SetOutline()
  22. textLine.SetHorizontalAlignRight()
  23. textLine.Show()
  24. self.textLine = textLine
  25.  
  26. def __del__(self):
  27. ui.Window.__del__(self)
  28.  
  29. def SetText(self, text):
  30. self.textLine.SetText(text)
  31.  
  32. def SetTooltipPosition(self, PosX, PosY):
  33. if localeInfo.IsARABIC():
  34. w, h = self.textLine.GetTextSize()
  35. self.textLine.SetPosition(PosX - w - 5, PosY)
  36. else:
  37. self.textLine.SetPosition(PosX - 5, PosY)
  38.  
  39. def SetTextColor(self, TextColor):
  40. self.textLine.SetPackedFontColor(TextColor)
  41.  
  42. def GetTextSize(self):
  43. return self.textLine.GetTextSize()
  44.  
  45. class AtlasWindow(ui.ScriptWindow):
  46.  
  47. class AtlasRenderer(ui.Window):
  48. def __init__(self):
  49. ui.Window.__init__(self)
  50. self.AddFlag("not_pick")
  51.  
  52. def OnUpdate(self):
  53. miniMap.UpdateAtlas()
  54.  
  55. def OnRender(self):
  56. (x, y) = self.GetGlobalPosition()
  57. fx = float(x)
  58. fy = float(y)
  59. miniMap.RenderAtlas(fx, fy)
  60.  
  61. def HideAtlas(self):
  62. miniMap.HideAtlas()
  63.  
  64. def ShowAtlas(self):
  65. miniMap.ShowAtlas()
  66.  
  67. def __init__(self):
  68. self.tooltipInfo = MapTextToolTip()
  69. self.tooltipInfo.Hide()
  70. self.infoGuildMark = ui.MarkBox()
  71. self.infoGuildMark.Hide()
  72. self.AtlasMainWindow = None
  73. self.mapName = ""
  74. self.board = 0
  75.  
  76. ui.ScriptWindow.__init__(self)
  77.  
  78. def __del__(self):
  79. ui.ScriptWindow.__del__(self)
  80.  
  81. def SetMapName(self, mapName):
  82. if 949==app.GetDefaultCodePage():
  83. try:
  84. self.board.SetTitleName(localeInfo.MINIMAP_ZONE_NAME_DICT[mapName])
  85. except:
  86. pass
  87.  
  88. def LoadWindow(self):
  89. try:
  90. pyScrLoader = ui.PythonScriptLoader()
  91. pyScrLoader.LoadScriptFile(self, "UIScript/AtlasWindow.py")
  92. except:
  93. import exception
  94. exception.Abort("AtlasWindow.LoadWindow.LoadScript")
  95.  
  96. try:
  97. self.board = self.GetChild("board")
  98.  
  99. except:
  100. import exception
  101. exception.Abort("AtlasWindow.LoadWindow.BindObject")
  102.  
  103. self.AtlasMainWindow = self.AtlasRenderer()
  104. self.board.SetCloseEvent(self.Hide)
  105. self.AtlasMainWindow.SetParent(self.board)
  106. self.AtlasMainWindow.SetPosition(7, 30)
  107. self.tooltipInfo.SetParent(self.board)
  108. self.infoGuildMark.SetParent(self.board)
  109. self.SetPosition(wndMgr.GetScreenWidth() - 136 - 256 - 10, 0)
  110. self.Hide()
  111.  
  112. miniMap.RegisterAtlasWindow(self)
  113.  
  114. def Destroy(self):
  115. miniMap.UnregisterAtlasWindow()
  116. self.ClearDictionary()
  117. self.AtlasMainWindow = None
  118. self.tooltipAtlasClose = 0
  119. self.tooltipInfo = None
  120. self.infoGuildMark = None
  121. self.board = None
  122.  
  123. def OnUpdate(self):
  124.  
  125. if not self.tooltipInfo:
  126. return
  127.  
  128. if not self.infoGuildMark:
  129. return
  130.  
  131. self.infoGuildMark.Hide()
  132. self.tooltipInfo.Hide()
  133.  
  134. if False == self.board.IsIn():
  135. return
  136.  
  137. (mouseX, mouseY) = wndMgr.GetMousePosition()
  138. (bFind, sName, iPosX, iPosY, dwTextColor, dwGuildID) = miniMap.GetAtlasInfo(mouseX, mouseY)
  139.  
  140. if False == bFind:
  141. return
  142.  
  143. if "empty_guild_area" == sName:
  144. sName = localeInfo.GUILD_EMPTY_AREA
  145.  
  146. if localeInfo.IsARABIC() and sName[-1].isalnum():
  147. self.tooltipInfo.SetText("(%s)%d, %d" % (sName, iPosX, iPosY))
  148. else:
  149. self.tooltipInfo.SetText("%s(%d, %d)" % (sName, iPosX, iPosY))
  150.  
  151. (x, y) = self.GetGlobalPosition()
  152. self.tooltipInfo.SetTooltipPosition(mouseX - x, mouseY - y)
  153. self.tooltipInfo.SetTextColor(dwTextColor)
  154. self.tooltipInfo.Show()
  155. self.tooltipInfo.SetTop()
  156.  
  157. if 0 != dwGuildID:
  158. textWidth, textHeight = self.tooltipInfo.GetTextSize()
  159. self.infoGuildMark.SetIndex(dwGuildID)
  160. self.infoGuildMark.SetPosition(mouseX - x - textWidth - 18 - 5, mouseY - y)
  161. self.infoGuildMark.Show()
  162.  
  163. def Hide(self):
  164. if self.AtlasMainWindow:
  165. self.AtlasMainWindow.HideAtlas()
  166. self.AtlasMainWindow.Hide()
  167. ui.ScriptWindow.Hide(self)
  168.  
  169. def Show(self):
  170. if self.AtlasMainWindow:
  171. (bGet, iSizeX, iSizeY) = miniMap.GetAtlasSize()
  172. if bGet:
  173. self.SetSize(iSizeX + 15, iSizeY + 38)
  174.  
  175. if localeInfo.IsARABIC():
  176. self.board.SetPosition(iSizeX+15, 0)
  177.  
  178. self.board.SetSize(iSizeX + 15, iSizeY + 38)
  179. #self.AtlasMainWindow.SetSize(iSizeX, iSizeY)
  180. self.AtlasMainWindow.ShowAtlas()
  181. self.AtlasMainWindow.Show()
  182. ui.ScriptWindow.Show(self)
  183.  
  184. def SetCenterPositionAdjust(self, x, y):
  185. self.SetPosition((wndMgr.GetScreenWidth() - self.GetWidth()) / 2 + x, (wndMgr.GetScreenHeight() - self.GetHeight()) / 2 + y)
  186.  
  187. def OnPressEscapeKey(self):
  188. self.Hide()
  189. return True
  190.  
  191. def __RegisterMiniMapColor(type, rgb):
  192. miniMap.RegisterColor(type, rgb[0], rgb[1], rgb[2])
  193.  
  194. class MiniMap(ui.ScriptWindow):
  195.  
  196. CANNOT_SEE_INFO_MAP_DICT = {
  197. "metin2_map_monkeydungeon" : False,
  198. "metin2_map_monkeydungeon_02" : False,
  199. "metin2_map_monkeydungeon_03" : False,
  200. "metin2_map_devilsCatacomb" : False,
  201. }
  202.  
  203. def __init__(self):
  204. ui.ScriptWindow.__init__(self)
  205.  
  206. self.__Initialize()
  207.  
  208. miniMap.Create()
  209. miniMap.SetScale(2.0)
  210.  
  211. self.AtlasWindow = AtlasWindow()
  212. self.AtlasWindow.LoadWindow()
  213. self.AtlasWindow.Hide()
  214.  
  215. self.tooltipMiniMapOpen = MapTextToolTip()
  216. self.tooltipMiniMapOpen.SetText(localeInfo.MINIMAP)
  217. self.tooltipMiniMapOpen.Show()
  218. self.tooltipMiniMapClose = MapTextToolTip()
  219. self.tooltipMiniMapClose.SetText(localeInfo.UI_CLOSE)
  220. self.tooltipMiniMapClose.Show()
  221. self.tooltipScaleUp = MapTextToolTip()
  222. self.tooltipScaleUp.SetText(localeInfo.MINIMAP_INC_SCALE)
  223. self.tooltipScaleUp.Show()
  224. self.tooltipScaleDown = MapTextToolTip()
  225. self.tooltipScaleDown.SetText(localeInfo.MINIMAP_DEC_SCALE)
  226. self.tooltipScaleDown.Show()
  227. self.tooltipAtlasOpen = MapTextToolTip()
  228. self.tooltipAtlasOpen.SetText(localeInfo.MINIMAP_SHOW_AREAMAP)
  229. self.tooltipAtlasOpen.Show()
  230. self.tooltipInfo = MapTextToolTip()
  231. self.tooltipInfo.Show()
  232.  
  233. if miniMap.IsAtlas():
  234. self.tooltipAtlasOpen.SetText(localeInfo.MINIMAP_SHOW_AREAMAP)
  235. else:
  236. self.tooltipAtlasOpen.SetText(localeInfo.MINIMAP_CAN_NOT_SHOW_AREAMAP)
  237.  
  238. self.tooltipInfo = MapTextToolTip()
  239. self.tooltipInfo.Show()
  240.  
  241. self.mapName = ""
  242.  
  243. self.isLoaded = 0
  244. self.canSeeInfo = True
  245.  
  246. # AUTOBAN
  247. self.imprisonmentDuration = 0
  248. self.imprisonmentEndTime = 0
  249. self.imprisonmentEndTimeText = ""
  250. # END_OF_AUTOBAN
  251.  
  252. def __del__(self):
  253. miniMap.Destroy()
  254. ui.ScriptWindow.__del__(self)
  255.  
  256. def __Initialize(self):
  257. self.positionInfo = 0
  258. self.observerCount = 0
  259.  
  260. self.OpenWindow = 0
  261. self.CloseWindow = 0
  262. self.ScaleUpButton = 0
  263. self.ScaleDownButton = 0
  264. self.MiniMapHideButton = 0
  265. self.MiniMapShowButton = 0
  266. self.AtlasShowButton = 0
  267.  
  268. self.tooltipMiniMapOpen = 0
  269. self.tooltipMiniMapClose = 0
  270. self.tooltipScaleUp = 0
  271. self.tooltipScaleDown = 0
  272. self.tooltipAtlasOpen = 0
  273. self.tooltipInfo = None
  274. self.serverInfo = None
  275.  
  276. def SetMapName(self, mapName):
  277. self.mapName=mapName
  278. self.AtlasWindow.SetMapName(mapName)
  279.  
  280. if self.CANNOT_SEE_INFO_MAP_DICT.has_key(mapName):
  281. self.canSeeInfo = False
  282. self.HideMiniMap()
  283. self.tooltipMiniMapOpen.SetText(localeInfo.MINIMAP_CANNOT_SEE)
  284. else:
  285. self.canSeeInfo = True
  286. self.ShowMiniMap()
  287. self.tooltipMiniMapOpen.SetText(localeInfo.MINIMAP)
  288.  
  289. # AUTOBAN
  290. def SetImprisonmentDuration(self, duration):
  291. self.imprisonmentDuration = duration
  292. self.imprisonmentEndTime = app.GetGlobalTimeStamp() + duration
  293.  
  294. self.__UpdateImprisonmentDurationText()
  295.  
  296. def __UpdateImprisonmentDurationText(self):
  297. restTime = max(self.imprisonmentEndTime - app.GetGlobalTimeStamp(), 0)
  298.  
  299. imprisonmentEndTimeText = localeInfo.SecondToDHM(restTime)
  300. if imprisonmentEndTimeText != self.imprisonmentEndTimeText:
  301. self.imprisonmentEndTimeText = imprisonmentEndTimeText
  302. self.serverInfo.SetText("%s: %s" % (uiScriptLocale.AUTOBAN_QUIZ_REST_TIME, self.imprisonmentEndTimeText))
  303. # END_OF_AUTOBAN
  304.  
  305. def Show(self):
  306. self.__LoadWindow()
  307.  
  308. ui.ScriptWindow.Show(self)
  309.  
  310. def __LoadWindow(self):
  311. if self.isLoaded == 1:
  312. return
  313.  
  314. self.isLoaded = 1
  315.  
  316. try:
  317. pyScrLoader = ui.PythonScriptLoader()
  318. if localeInfo.IsARABIC():
  319. pyScrLoader.LoadScriptFile(self, uiScriptLocale.LOCALE_UISCRIPT_PATH + "Minimap.py")
  320. else:
  321. pyScrLoader.LoadScriptFile(self, "UIScript/MiniMap.py")
  322. except:
  323. import exception
  324. exception.Abort("MiniMap.LoadWindow.LoadScript")
  325.  
  326. try:
  327. self.OpenWindow = self.GetChild("OpenWindow")
  328. self.MiniMapWindow = self.GetChild("MiniMapWindow")
  329. self.ScaleUpButton = self.GetChild("ScaleUpButton")
  330. self.ScaleDownButton = self.GetChild("ScaleDownButton")
  331. self.DungeonInfo = self.GetChild("DungeonInfo")
  332. self.MiniMapHideButton = self.GetChild("MiniMapHideButton")
  333. self.AtlasShowButton = self.GetChild("AtlasShowButton")
  334. self.CloseWindow = self.GetChild("CloseWindow")
  335. self.MiniMapShowButton = self.GetChild("MiniMapShowButton")
  336. self.positionInfo = self.GetChild("PositionInfo")
  337. self.observerCount = self.GetChild("ObserverCount")
  338. self.serverInfo = self.GetChild("ServerInfo")
  339. except:
  340. import exception
  341. exception.Abort("MiniMap.LoadWindow.Bind")
  342.  
  343. if constInfo.MINIMAP_POSITIONINFO_ENABLE==0:
  344. self.positionInfo.Hide()
  345.  
  346. self.serverInfo.SetText(net.GetServerInfo())
  347. self.ScaleUpButton.SetEvent(ui.__mem_func__(self.ScaleUp))
  348. self.ScaleDownButton.SetEvent(ui.__mem_func__(self.ScaleDown))
  349. self.MiniMapHideButton.SetEvent(ui.__mem_func__(self.HideMiniMap))
  350. self.MiniMapShowButton.SetEvent(ui.__mem_func__(self.ShowMiniMap))
  351. self.DungeonInfo.SetEvent(ui.__mem_func__(self.__DungeonInfo))
  352.  
  353. if miniMap.IsAtlas():
  354. self.AtlasShowButton.SetEvent(ui.__mem_func__(self.ShowAtlas))
  355.  
  356. (ButtonPosX, ButtonPosY) = self.MiniMapShowButton.GetGlobalPosition()
  357. self.tooltipMiniMapOpen.SetTooltipPosition(ButtonPosX, ButtonPosY)
  358.  
  359. (ButtonPosX, ButtonPosY) = self.MiniMapHideButton.GetGlobalPosition()
  360. self.tooltipMiniMapClose.SetTooltipPosition(ButtonPosX, ButtonPosY)
  361.  
  362. (ButtonPosX, ButtonPosY) = self.ScaleUpButton.GetGlobalPosition()
  363. self.tooltipScaleUp.SetTooltipPosition(ButtonPosX, ButtonPosY)
  364.  
  365. (ButtonPosX, ButtonPosY) = self.ScaleDownButton.GetGlobalPosition()
  366. self.tooltipScaleDown.SetTooltipPosition(ButtonPosX, ButtonPosY)
  367.  
  368. (ButtonPosX, ButtonPosY) = self.AtlasShowButton.GetGlobalPosition()
  369. self.tooltipAtlasOpen.SetTooltipPosition(ButtonPosX, ButtonPosY)
  370.  
  371. self.ShowMiniMap()
  372.  
  373. def Destroy(self):
  374. self.HideMiniMap()
  375.  
  376. self.AtlasWindow.Destroy()
  377. self.AtlasWindow = None
  378.  
  379. self.ClearDictionary()
  380.  
  381. self.__Initialize()
  382.  
  383. def UpdateObserverCount(self, observerCount):
  384. if observerCount>0:
  385. self.observerCount.Show()
  386. elif observerCount<=0:
  387. self.observerCount.Hide()
  388.  
  389. self.observerCount.SetText(localeInfo.MINIMAP_OBSERVER_COUNT % observerCount)
  390.  
  391. def OnUpdate(self):
  392. (x, y, z) = player.GetMainCharacterPosition()
  393. miniMap.Update(x, y)
  394.  
  395. self.positionInfo.SetText("(%.0f, %.0f)" % (x/100, y/100))
  396.  
  397. if self.tooltipInfo:
  398. if True == self.MiniMapWindow.IsIn():
  399. (mouseX, mouseY) = wndMgr.GetMousePosition()
  400. (bFind, sName, iPosX, iPosY, dwTextColor) = miniMap.GetInfo(mouseX, mouseY)
  401. if bFind == 0:
  402. self.tooltipInfo.Hide()
  403. elif not self.canSeeInfo:
  404. self.tooltipInfo.SetText("%s(%s)" % (sName, localeInfo.UI_POS_UNKNOWN))
  405. self.tooltipInfo.SetTooltipPosition(mouseX - 5, mouseY)
  406. self.tooltipInfo.SetTextColor(dwTextColor)
  407. self.tooltipInfo.Show()
  408. else:
  409. if localeInfo.IsARABIC() and sName[-1].isalnum():
  410. self.tooltipInfo.SetText("(%s)%d, %d" % (sName, iPosX, iPosY))
  411. else:
  412. self.tooltipInfo.SetText("%s(%d, %d)" % (sName, iPosX, iPosY))
  413. self.tooltipInfo.SetTooltipPosition(mouseX - 5, mouseY)
  414. self.tooltipInfo.SetTextColor(dwTextColor)
  415. self.tooltipInfo.Show()
  416. else:
  417. self.tooltipInfo.Hide()
  418.  
  419. # AUTOBAN
  420. if self.imprisonmentDuration:
  421. self.__UpdateImprisonmentDurationText()
  422. # END_OF_AUTOBAN
  423.  
  424. if True == self.MiniMapShowButton.IsIn():
  425. self.tooltipMiniMapOpen.Show()
  426. else:
  427. self.tooltipMiniMapOpen.Hide()
  428.  
  429. if True == self.MiniMapHideButton.IsIn():
  430. self.tooltipMiniMapClose.Show()
  431. else:
  432. self.tooltipMiniMapClose.Hide()
  433.  
  434. if True == self.ScaleUpButton.IsIn():
  435. self.tooltipScaleUp.Show()
  436. else:
  437. self.tooltipScaleUp.Hide()
  438.  
  439. if True == self.ScaleDownButton.IsIn():
  440. self.tooltipScaleDown.Show()
  441. else:
  442. self.tooltipScaleDown.Hide()
  443.  
  444. if True == self.AtlasShowButton.IsIn():
  445. self.tooltipAtlasOpen.Show()
  446. else:
  447. self.tooltipAtlasOpen.Hide()
  448.  
  449. def OnRender(self):
  450. (x, y) = self.GetGlobalPosition()
  451. fx = float(x)
  452. fy = float(y)
  453. miniMap.Render(fx + 4.0, fy + 5.0)
  454.  
  455. def Close(self):
  456. self.HideMiniMap()
  457.  
  458. def HideMiniMap(self):
  459. miniMap.Hide()
  460. self.OpenWindow.Hide()
  461. self.CloseWindow.Show()
  462.  
  463. def ShowMiniMap(self):
  464. if not self.canSeeInfo:
  465. return
  466.  
  467. miniMap.Show()
  468. self.OpenWindow.Show()
  469. self.CloseWindow.Hide()
  470.  
  471. def __DungeonInfo(self):
  472. self.wndDungeonInfo = None
  473. self.wndDungeonInfo.Open()
  474.  
  475. def isShowMiniMap(self):
  476. return miniMap.isShow()
  477.  
  478. def ScaleUp(self):
  479. miniMap.ScaleUp()
  480.  
  481. def ScaleDown(self):
  482. miniMap.ScaleDown()
  483.  
  484. def ShowAtlas(self):
  485. if not miniMap.IsAtlas():
  486. return
  487. if not self.AtlasWindow.IsShow():
  488. self.AtlasWindow.Show()
  489.  
  490. def ToggleAtlasWindow(self):
  491. if not miniMap.IsAtlas():
  492. return
  493. if self.AtlasWindow.IsShow():
  494. self.AtlasWindow.Hide()
  495. else:
  496. self.AtlasWindow.Show()
  497.  
Advertisement
RAW Paste Data Copied
Advertisement