And how i can do it? uiTeleport.py was not modified. I got it with the
as it is.
#author: dracaryS
#date: 25.07.2024 01:57
#static
import ui, operator, localeInfo, uiCommon
#dynamic
import grp, dbg, nonplayer, app, player, chat, net
IMG_DIR = "teleport_gui/"
BUTTON_REGEN_LOCATIONS = 0
BUTTON_REGEN_METIN_STONES = 1
BUTTON_REGEN_BOSSES = 2
TEST_MAKE_ALL_THINGS_MOVABLE_AND_PRINT_SYSSER_POSITION = False
rightBgButtons = {
BUTTON_REGEN_LOCATIONS : "Locatii",
BUTTON_REGEN_METIN_STONES : "Pietre Metin",
BUTTON_REGEN_BOSSES : "Bossi",
}
def IsWarpItems(itemVnum):
return True if itemVnum == 70058 else False
def LoadRegen(regenDirectory):
try:
lines = pack_open(regenDirectory, "r").readlines()
#lines = get_pack("", regenDirectory, "r", 5162191, 9587456321).readlines()
except IOError:
lines = []
dataDict = {}
for key, name in rightBgButtons.items():
dataDict[key] = {}
buttonKeys = {
"npc" : BUTTON_REGEN_LOCATIONS,
"stone" : BUTTON_REGEN_METIN_STONES,
"boss" : BUTTON_REGEN_BOSSES,
}
for line in lines:
if line.find("#") != -1:
continue
lineSplit = line.split("\t")
if len(lineSplit) == 10:
if not buttonKeys.has_key(lineSplit[0].lower()):
continue
key = buttonKeys[lineSplit[0].lower()]
vnum = int(lineSplit[3])
if key == BUTTON_REGEN_LOCATIONS:
newVnum = str(vnum) + "#" + str(app.GetRandom(1, 10000))
else:
newVnum = str(vnum) + "#0"
if not dataDict[key].has_key(newVnum):
dataDict[key][newVnum] = []
dataDict[key][newVnum].append({
"x" : int(lineSplit[1]),
"y" : int(lineSplit[2]),
"tpIdx" : int(lineSplit[4]),
"need_level" : [int(lineSplit[5]), int(lineSplit[6])],
"need_yang" : int(lineSplit[7]),
"mark" : int(lineSplit[8]),
"effect" : int(lineSplit[9]),
})
return dataDict
atlasData = []
def GetMapData(mapName):
global atlasData
if not len(atlasData):
try:
lines = pack_open("atlasinfo.txt", "r").readlines()
#lines = get_pack("", "locale/common/atlasinfo.txt", "r", 5162191, 9587456321).readlines()
except IOError:
lines = []
for line in lines:
try:
tokens = line.split("\t")
if len(tokens) != 5:
continue
map = [str(tokens[0])]
global_x = int(tokens[1])
map.append(global_x)
global_y = int(tokens[2])
map.append(global_y)
map_width = int(tokens[3])
map.append(map_width)
map_height = int(tokens[4])
map.append(map_height)
global_end_x = global_x + map_width * 25600
map.append(global_end_x)
global_end_y = global_y + map_height * 25600
map.append(global_end_y)
atlasData.append(map)
except:
pass
for map in atlasData:
if map[0] == mapName:
return map
return None
data = {
0 : {
"name" : "Teleport - Standart Maps",
"image" : IMG_DIR + "bg_map_0.png",
"maps" : {
1 : {
"map_name" : "Jinno",
"hover_image" : IMG_DIR + "hover_map/jinno.png",
"position" : (82, 18),
"regen" : LoadRegen("locale/ro/teleport/jinno.txt"),
"atlas" : "d:/ymir work/ui/atlas/metin2_map_c1/atlas.sub",
"map_file_name" : "metin2_map_c1",
"tp_points" : {
"Center" : {
"position" : (50, 20),
"need_level" : [1, 120],
"need_yang" : 0,
"tpIdx" : 1,
},
"Middle" : {
"position" : (42, 77),
"need_level" : [1, 120],
"need_yang" : 0,
"tpIdx" : 2,
},
},
},
2 : {
"map_name" : "Bakra",
"hover_image" : IMG_DIR + "hover_map/bakra.png",
"position" : (131, 100),
"regen" : LoadRegen("locale/ro/teleport/bakra.txt"),
"atlas" : "d:/ymir work/ui/atlas/metin2_map_c3/atlas.sub",
"map_file_name" : "metin2_map_c3",
"tp_points" : {
"Center" : {
"position" : (45, 13),
"need_level" : [1, 120],
"need_yang" : 0,
"tpIdx" : 3,
},
},
},
3 : {
"map_name" : "Temnita Maimutelor",
"hover_image" : IMG_DIR + "hover_map/monkey.png",
"position" : (206, 6),
"regen" : LoadRegen("locale/ro/teleport/monkey.txt"),
"atlas" : "d:/ymir work/ui/atlas/metin2_map_c3/atlas.sub",
"map_file_name" : "metin2_map_c3",
"tp_points" : {
"Center" : {
"position" : (32, 33),
"need_level" : [1, 120],
"need_yang" : 0,
"tpIdx" : 4,
},
},
},
4 : {
"map_name" : "Desertul Yongbi",
"hover_image" : IMG_DIR + "hover_map/desert.png",
"position" : (181, 67),
"regen" : LoadRegen("locale/ro/teleport/desert.txt"),
"atlas" : "d:/ymir work/ui/atlas/metin2_map_n_desert_01/atlas.sub",
"map_file_name" : "metin2_map_n_desert_01",
"tp_points" : {
"Center" : {
"position" : (89, 69),
"need_level" : [1, 120],
"need_yang" : 0,
"tpIdx" : 5,
},
},
},
5: {
"map_name" : "Tara de Foc",
"hover_image" : IMG_DIR + "hover_map/fireland.png",
"position" : (345, 58),
"regen" : LoadRegen("locale/ro/teleport/fireland.txt"),
"atlas" : "d:/ymir work/ui/atlas/metin2_map_n_flame_01/atlas.sub",
"map_file_name" : "metin2_map_n_flame_01",
"tp_points" : {
"Center" : {
"position" : (71, 56),
"need_level" : [1, 120],
"need_yang" : 0,
"tpIdx" : 7,
},
},
},
6: {
"map_name" : "Taramul Gigantilor",
"hover_image" : IMG_DIR + "hover_map/land_of_giants.png",
"position" : (311, 82),
"regen" : LoadRegen("locale/ro/teleport/land_of_giants.txt"),
"atlas" : "d:/ymir work/ui/atlas/metin2_map_n_flame_01/atlas.sub",
"map_file_name" : "metin2_map_n_flame_01",
"tp_points" : {
"Center" : {
"position" : (42, 79),
"need_level" : [1, 120],
"need_yang" : 0,
"tpIdx" : 6,
},
},
},
7: {
"map_name" : "Chunjo",
"hover_image" : IMG_DIR + "hover_map/chunjo.png",
"position" : (289, 217),
"regen" : LoadRegen("locale/ro/teleport/chunjo.txt"),
"atlas" : "d:/ymir work/ui/atlas/metin2_map_b1/atlas.sub",
"map_file_name" : "metin2_map_b1",
"tp_points" : {
"Center" : {
"position" : (71, 56),
"need_level" : [1, 120],
"need_yang" : 0,
"tpIdx" : 8,
},
},
},
8: {
"map_name" : "Bokjung",
"hover_image" : IMG_DIR + "hover_map/bokjung.png",
"position" : (261, 198),
"regen" : LoadRegen("locale/ro/teleport/bokjung.txt"),
"atlas" : "d:/ymir work/ui/atlas/metin2_map_b3/atlas.sub",
"map_file_name" : "metin2_map_b3",
"tp_points" : {
"Center" : {
"position" : (47, 64),
"need_level" : [1, 120],
"need_yang" : 0,
"tpIdx" : 9,
},
},
},
9: {
"map_name" : "Padurea Rosie",
"hover_image" : IMG_DIR + "hover_map/red_wood.png",
"position" : (108, 167),
"regen" : LoadRegen("locale/ro/teleport/red_wood.txt"),
"atlas" : "d:/ymir work/ui/atlas/metin2_map_trent/atlas.sub",
"map_file_name" : "metin2_map_trent",
"tp_points" : {
"Center" : {
"position" : (77, 71),
"need_level" : [1, 120],
"need_yang" : 0,
"tpIdx" : 10,
},
},
},
10: {
"map_name" : "Valea Orcilor",
"hover_image" : IMG_DIR + "hover_map/orc_valley.png",
"position" : (21, 107),
"regen" : LoadRegen("locale/ro/teleport/orc_valley.txt"),
"atlas" : "d:/ymir work/ui/atlas/map_c2/atlas.sub",
"map_file_name" : "map_c2",
"tp_points" : {
"Center" : {
"position" : (51, 59),
"need_level" : [1, 120],
"need_yang" : 0,
"tpIdx" : 11,
},
},
},
11: {
"map_name" : "Templul Hwang",
"hover_image" : IMG_DIR + "hover_map/hwang_temple.png",
"position" : (6, 196),
"regen" : LoadRegen("locale/ro/teleport/hwang_temple.txt"),
"atlas" : "d:/ymir work/ui/atlas/metin2_map_milgyo/atlas.sub",
"map_file_name" : "metin2_map_milgyo",
"tp_points" : {
"Center" : {
"position" : (37, 53),
"need_level" : [1, 120],
"need_yang" : 0,
"tpIdx" : 12,
},
},
},
12: {
"map_name" : "Muntele Sohan",
"hover_image" : IMG_DIR + "hover_map/sohan.png",
"position" : (29, 269),
"regen" : LoadRegen("locale/ro/teleport/sohan.txt"),
"atlas" : "d:/ymir work/ui/atlas/map_n_snowm_01/atlas.sub",
"map_file_name" : "map_n_snowm_01",
"tp_points" : {
"Center" : {
"position" : (85, 56),
"need_level" : [1, 120],
"need_yang" : 0,
"tpIdx" : 13,
},
},
},
13: {
"map_name" : "Padurea Fantomelor",
"hover_image" : IMG_DIR + "hover_map/ghost_wood.png",
"position" : (151, 262),
"regen" : LoadRegen("locale/ro/teleport/ghost_wood.txt"),
"atlas" : "d:/ymir work/ui/atlas/metin2_map_trent/atlas.sub",
"map_file_name" : "metin2_map_trent",
"tp_points" : {
"Center" : {
"position" : (68, 72),
"need_level" : [1, 120],
"need_yang" : 0,
"tpIdx" : 14,
},
},
},
},
}
}
class Window(ui.BoardWithTitleBar):
def __init__(self):
ui.BoardWithTitleBar.__init__(self)
self.__LoadWindow()
def Destroy(self):
self.__children = {}
self.Hide()
def __LoadWindow(self):
self.Destroy()
self.AddFlag("attach")
self.AddFlag("movable")
self.AddFlag("float")
self.SetCloseEvent(ui.__mem_func__(self.Close))
leftBg = CreateWindow(ui.ImageBox(), self, ["attach"], (10, 34), IMG_DIR + "left_bg.png")
self.__children["leftBg"] = leftBg
self.__children["leftBgImg"] = CreateWindow(ui.ImageBox(), leftBg, ["not_pick"], (0, 0), IMG_DIR + "left_bg_map.png")
for idx, info in data.items():
pageBg = CreateWindow(ui.ImageBox(), self.__children["leftBgImg"], ["not_pick"], (0, 0), info["image"])
for mapIdx, mapData in info["maps"].items():
if TEST_MAKE_ALL_THINGS_MOVABLE_AND_PRINT_SYSSER_POSITION:
map = CreateWindow(ui.ImageBox(), pageBg, ["movable"], mapData["position"], mapData["hover_image"])
self.__children["map" + str(mapIdx)] = map
else:
map = CreateWindow(ui.Button(), pageBg, [], mapData["position"])
map.SAFE_SetEvent(self.__ClickMap, mapIdx)
map.SetOverVisual(mapData["hover_image"])
self.__children["map" + str(mapIdx)] = map
for tpName, tpData in mapData["tp_points"].items():
if TEST_MAKE_ALL_THINGS_MOVABLE_AND_PRINT_SYSSER_POSITION:
self.__children["tp" + str(tpData["tpIdx"])] = CreateWindow(ui.ImageBox(), map, ["movable"], tpData["position"], IMG_DIR + "tp_map_normal.png")
else:
tp = CreateWindow(ui.Button(), map, [], tpData["position"], [IMG_DIR + "tp_map_normal.png", IMG_DIR + "tp_map_hover.png", IMG_DIR + "tp_map_down.png"])
tp.SAFE_SetEvent(self.__WarpToLocation, mapData["map_name"] + " - " + tpName, tpData["tpIdx"], tpData["need_level"], tpData["need_yang"], None)
tp.SetToolTipText(tpName)
self.__children["tp" + str(tpData["tpIdx"])] = tp
self.__children["pageBg" + str(idx)] = pageBg
rightBg = CreateWindow(ui.ImageBox(), self, ["attach"], (10 + leftBg.GetWidth() + 5, 34), IMG_DIR + "right_bg.png")
self.__children["rightBg"] = rightBg
self.__children["mapImg"] = CreateWindow(ui.ExpandedImageBox(), rightBg, ["not_pick"], (0, 0))
self.SetSize(rightBg.GetLocalPosition()[0] + rightBg.GetWidth() + 10, leftBg.GetLocalPosition()[1] + leftBg.GetHeight() + 13)
renderWnd = CreateWindow(ui.Window(), rightBg, ["not_pick"], (1 + 2, 248 + 7), "", "", (198, 175))
renderWnd.SetInsideRender(True)
self.__children["renderWnd"] = renderWnd
for key, name in rightBgButtons.items():
btn = CreateWindow(ui.ToggleButton(), renderWnd, [], (0, 0), [IMG_DIR + "btn_0.png", IMG_DIR + "btn_1.png", IMG_DIR + "btn_2.png"])
btn.SetListText(name)
btn.SetToggleUpEvent(ui.__mem_func__(self.__ClickBtn), "UP", key)
btn.SetToggleDownEvent(ui.__mem_func__(self.__ClickBtn), "DOWN", key)
btn.isOpened = False
self.__children["btn" + str(key)] = btn
self.__children["btnArrow" + str(key)] = CreateWindow(ui.ExpandedImageBox(), btn, ["not_pick"], (btn.GetWidth() - 25, btn.GetHeight() / 2 - 3), IMG_DIR + "arrow.png")
scrollBar = CreateWindow(ScrollBar(), renderWnd, [], (renderWnd.GetWidth() - 4, 0), "", "", (5, 180))
scrollBar.SetScrollEvent(ui.__mem_func__(self.__OnScroll))
self.__children["scrollBar"] = scrollBar
self.__ResetRightPage()
self.__SetPage(0)
def __ClickMap(self, mapIdx):
self.__children["selectedMap"] = mapIdx
self.__ResetRightPage()
mapData = {}
for idx, info in data.items():
if info["maps"].has_key(mapIdx):
mapData = info["maps"][mapIdx]
break
renderWnd = self.__children["renderWnd"]
for key, regenDict in mapData["regen"].items():
btnList = []
for vnum, regenInfo in regenDict.items():
realVnum = int(vnum.split("#")[0])
image = CreateWindow(ui.ExpandedImageBox(), renderWnd, [], (2, 0), IMG_DIR + "sub_cat.png")
image.SetEvent(ui.__mem_func__(self.__ClickSubCat), "mouse_click", realVnum, regenInfo)
text = CreateWindow(ui.TextLine(), image, ["not_pick"], (8, 5), nonplayer.GetMonsterName(realVnum))
if key == BUTTON_REGEN_LOCATIONS:
btn = CreateWindow(ui.Button(), image, [], (image.GetWidth() - 30, 0), [IMG_DIR + "teleport_normal.png", IMG_DIR + "teleport_hover.png", IMG_DIR + "teleport_down.png"])
btn.SAFE_SetEvent(self.__WarpToLocation, mapData["map_name"] + " - " + nonplayer.GetMonsterName(realVnum), regenInfo[0]["tpIdx"], regenInfo[0]["need_level"], regenInfo[0]["need_yang"], regenInfo)
else:
btn = CreateWindow(ui.Button(), image, [], (image.GetWidth() - 25, 0), [IMG_DIR + "tp_map_normal.png", IMG_DIR + "tp_map_hover.png", IMG_DIR + "tp_map_down.png"])
btn.SAFE_SetEvent(self.__ShowRegen, regenInfo)
btnList.append([image, text, btn])
self.__children["btnList" + str(key)] = btnList
self.__Refresh()
def __CloseQuestionDialog(self):
if self.__children.has_key("questionDialog"):
self.__children["questionDialog"].Close()
self.__children["questionDialog"].Destroy()
del self.__children["questionDialog"]
def __WarpToLocation(self, name, tpIdx, needLevel, needYang, regenInfo = None):
self.__CloseQuestionDialog()
if regenInfo != None:
self.__ShowRegen(regenInfo)
questionDialog = uiCommon.QuestionDialog2()
questionDialog.SetText1(name)
questionDialog.SetText2("Do you want teleport there for |cFFC0B149{}Yang?".format(localeInfo.NumberToDecimalString(needYang)))
questionDialog.SetAcceptEvent(ui.__mem_func__(self.__AcceptTeleport))
questionDialog.SetCancelEvent(ui.__mem_func__(self.__CloseQuestionDialog))
questionDialog.Open()
questionDialog.tpIdx = tpIdx
questionDialog.needLevel = needLevel
questionDialog.needYang = needYang
self.__children["questionDialog"] = questionDialog
def __AcceptTeleport(self):
questionDialog = self.__children["questionDialog"] if self.__children.has_key("questionDialog") else None
if questionDialog:
level = player.GetStatus(player.LEVEL)
if (questionDialog.needLevel[0] != 0 and level < questionDialog.needLevel[0]) or (level > questionDialog.needLevel[1] and questionDialog.needLevel[1] != 0):
chat.AppendChat(chat.CHAT_TYPE_INFO, "Nu te poti teleporta cu nivelul tau.. Nivel Necesar: {}~{}".format(questionDialog.needLevel[0], questionDialog.needLevel[1]))
self.__CloseQuestionDialog()
return
elif player.GetElk() < questionDialog.needYang:
chat.AppendChat(chat.CHAT_TYPE_INFO, "Nu te poti teleporta deoarece nu detii suficienti Yang. Yang Necesar: {}".format(localeInfo.NumberToDecimalString(questionDialog.needYang)))
self.__CloseQuestionDialog()
return
net.SendChatPacket("/tp_new " + str(questionDialog.tpIdx))
self.__CloseQuestionDialog()
def __ClickSubCat(self, emptyarg, mobVnum, regenInfo):
#to-do use mobVnum for wiki or something
pass
def __ShowRegen(self, regenInfo):
self.__children["regenMarks"] = []
self.__children["regenEffects"] = []
selectedMap = self.__children["selectedMap"] if self.__children.has_key("selectedMap") else 0
mapData = {}
for idx, info in data.items():
if info["maps"].has_key(selectedMap):
mapData = info["maps"][selectedMap]
break
if not mapData:
return
atlasInfo = GetMapData(mapData["map_file_name"])
base_x = atlasInfo[1]
base_y = atlasInfo[2]
TERRAIN_SIZE = 128.0 * 200.0
m_fAtlasMaxX = float(atlasInfo[3]) * TERRAIN_SIZE
m_fAtlasMaxY = float(atlasInfo[4]) * TERRAIN_SIZE
m_fAtlasImageSizeX = 201.0
m_fAtlasImageSizeY = 242.0
for regen in regenInfo:
if regen["mark"] == 0 and regen["effect"] == 0:
continue
sx = regen["x"]
sy = regen["y"]
ex = sx + 0 * 2
sx *= 100
ex *= 100
ey = sy + 0 * 2
sy *= 100
ey *= 100
sx += base_x;
ex += base_x;
sy += base_y;
ey += base_y;
lx = (sx + ex) / 2 - base_x
ly = (sy + ey) / 2 - base_y
#gx = base_x + regen["x"] * 100
#gy = base_y + regen["y"] * 100
#dbg.TraceError("global: ({}x{}), x: {} y: {} map: {}".format(gx, gy, new_x, new_y, atlasInfo))
if regen["mark"]:
mark_x = lx / m_fAtlasMaxX * m_fAtlasImageSizeX - 6.0 / 2.0
mark_y = ly / m_fAtlasMaxY * m_fAtlasImageSizeY - 6.0 / 2.0
markImg = CreateWindow(ui.ExpandedImageBox(), self.__children["mapImg"], [], (mark_x, mark_y), "d:/ymir work/ui/minimap/whitemark_new.tga")
self.__children["regenMarks"].append(markImg)
if regen["effect"]:
miniway_x = lx / m_fAtlasMaxX * m_fAtlasImageSizeX - 30.0 / 2.0
miniway_y = ly / m_fAtlasMaxY * m_fAtlasImageSizeY - 30.0 / 2.0
way_x = lx / m_fAtlasMaxX * m_fAtlasImageSizeX - 40.0 / 2.0
way_y = ly / m_fAtlasMaxY * m_fAtlasImageSizeY - 40.0 / 2.0
effect = CreateWindow(ui.AniImageBox(), self.__children["mapImg"], [], (0, 0))
for j in xrange(12):
effect.AppendImage("d:/ymir work/ui/minimap/mini_waypoint%02d.sub" % (j+1))
effect.SetPosition(miniway_x, miniway_y)
effect.SetDelay(3)
self.__children["regenEffects"].append(effect)
effect2 = CreateWindow(ui.AniImageBox(), self.__children["mapImg"], [], (0, 0))
for j in xrange(15):
effect2.AppendImage("d:/ymir work/ui/minimap/waypoint%02d.sub"% (j+1))
effect2.SetPosition(way_x, way_y)
effect2.SetDelay(3)
self.__children["regenEffects"].append(effect2)
def __SetPage(self, pageIdx):
self.__children["pageIdx"] = pageIdx
for idx, info in data.items():
if pageIdx == idx:
self.__children["pageBg" + str(pageIdx)].Show()
self.SetTitleName(info["name"])
else:
self.__children["pageBg" + str(pageIdx)].Hide()
self.__Refresh()
def __ResetRightPage(self):
self.__children["mapImg"].Hide()
self.__children["scrollBar"].SetPos(0)
self.__children["scrollBar"].Hide()
self.__children["regenMarks"] = []
self.__children["regenEffects"] = []
for key, name in rightBgButtons.items():
self.__children["btn" + str(key)].isOpened = False
self.__children["btn" + str(key)].SetUp()
self.__children["btn" + str(key)].Hide()
self.__children["btnArrow" + str(key)].SetRotation(0)
btnList = self.__children["btnList" + str(key)] if self.__children.has_key("btnList" + str(key)) else []
for child in btnList:
for x in child:
x.Destroy()
x.Hide()
self.__children["btnList" + str(key)] = []
def OnMouseWheel(self, length):
scrollBar = self.__children["scrollBar"] if self.__children.has_key("scrollBar") else None
if scrollBar:
if scrollBar.IsShow():
scrollBar.OnMouseWheel(length)
return True
return False
def __ClickBtn(self, eventType, btnIndex):
self.__children["btnArrow" + str(btnIndex)].SetRotation(0 if eventType == "UP" else 180)
self.__children["btn" + str(btnIndex)].isOpened = False if eventType == "UP" else True
self.__Refresh()
def __OnScroll(self):
pos = int(self.__children["scrollBar"].GetPos()*self.__children["scrollLen"])
for key, name in rightBgButtons.items():
btn = self.__children["btn" + str(key)]
(ex, ey) = btn.exPos
btn.SetPosition(ex, ey-pos)
if btn.isOpened:
btnList = self.__children["btnList" + str(key)]
for child in btnList:
(ex, ey) = child[0].exPos
child[0].SetPosition(ex, ey-pos)
def __Refresh(self):
selectedMap = self.__children["selectedMap"] if self.__children.has_key("selectedMap") else 0
mapData = {}
for idx, info in data.items():
if info["maps"].has_key(selectedMap):
mapData = info["maps"][selectedMap]
break
if not mapData:
self.__ResetRightPage()
else:
totalY = 0
windowHeight = self.__children["scrollBar"].GetHeight()
for key, name in rightBgButtons.items():
btn = self.__children["btn" + str(key)]
btn.SetPosition(0, totalY, True)
btn.Show()
totalY += 32
btnStatus = btn.isOpened
btnList = self.__children["btnList" + str(key)]
for child in btnList:
if btnStatus:
child[0].SetPosition(2, totalY, True)
child[0].Show()
totalY += 30
else:
child[0].Hide()
if totalY > windowHeight:
self.__children["scrollBar"].SetScale(windowHeight, totalY)
self.__children["scrollBar"].Show()
self.__children["scrollLen"] = totalY - windowHeight
else:
self.__children["scrollBar"].SetScale(windowHeight, windowHeight)
self.__children["scrollBar"].Hide()
self.__children["scrollLen"] = 0
mapImg = self.__children["mapImg"]
mapImg.LoadImage(mapData["atlas"])
mapImg.SetPosition(5, 5)
mapImg.SetScale(201.0 * (1.0 / mapImg.GetWidth()), 242.0 * (1.0 / mapImg.GetHeight()))
mapImg.Show()
def OnUpdate(self):
if TEST_MAKE_ALL_THINGS_MOVABLE_AND_PRINT_SYSSER_POSITION:
dbg.TraceError("")
for idx, info in data.items():
for mapIdx, mapData in info["maps"].items():
dbg.TraceError("map: {} pos: {}".format(mapIdx, self.__children["map" + str(mapIdx)].GetLocalPosition()))
for tpName, tpData in mapData["tp_points"].items():
dbg.TraceError("\ttp: {} pos: {}".format(tpName, self.__children["tp" + str(tpData["tpIdx"])].GetLocalPosition()))
def Open(self):
self.SetCenterPosition()
self.Show()
self.SetTop()
def Close(self):
self.Hide()
def OnPressEscapeKey(self):
self.Close()
return True
class ScrollBar(ui.Window):
BASE_COLOR = grp.GenerateColor(0.0, 0.0, 0.0, 1.0)
CORNERS_AND_LINES_COLOR = grp.GenerateColor(0.3411, 0.3411, 0.3411, 1.0)
BAR_NUMB = 9 # This is static value! Please dont touch!
SCROLL_WIDTH= 8
class MiddleBar(ui.DragButton):
MIDDLE_BAR_COLOR = grp.GenerateColor(86.0 / 255.0, 76.0 / 255.0, 64.0 / 255.0, 1.0)
def __init__(self, horizontal_scroll):
ui.DragButton.__init__(self)
self.AddFlag("movable")
self.horizontal_scroll = horizontal_scroll
self.middle = ui.Bar()
self.middle.SetParent(self)
self.middle.AddFlag("attach")
self.middle.AddFlag("not_pick")
self.middle.SetColor(self.MIDDLE_BAR_COLOR)
self.middle.SetSize(1, 1)
self.middle.Show()
def SetStaticScale(self, size):
(base_width, base_height) = (self.middle.GetWidth(), self.middle.GetHeight())
if not self.horizontal_scroll:
ui.DragButton.SetSize(self, base_width, size)
self.middle.SetSize(base_width, size)
else:
ui.DragButton.SetSize(self, size, base_height)
self.middle.SetSize(size, base_height)
def SetSize(self, selfSize, fullSize):
(base_width, base_height) = (self.middle.GetWidth(), self.middle.GetHeight())
if not self.horizontal_scroll:
ui.DragButton.SetSize(self, base_width, operator.truediv(int(selfSize), int(fullSize)) * selfSize)
self.middle.SetSize(base_width, operator.truediv(int(selfSize), int(fullSize)) * selfSize)
else:
ui.DragButton.SetSize(self, operator.truediv(int(selfSize), int(fullSize)) * selfSize, base_height)
self.middle.SetSize(operator.truediv(int(selfSize), int(fullSize)) * selfSize, base_height)
def SetStaticSize(self, size):
size = max(2, size)
if not self.horizontal_scroll:
ui.DragButton.SetSize(self, size, self.middle.GetHeight())
self.middle.SetSize(size, self.middle.GetHeight())
else:
ui.DragButton.SetSize(self, self.middle.GetWidth(), size)
self.middle.SetSize(self.middle.GetWidth(), size)
def __init__(self, horizontal_scroll = False):
ui.Window.__init__(self)
self.horizontal_scroll = horizontal_scroll
self.scrollEvent = None
self.scrollSpeed = 50
self.sizeScale = 1.0
self.bars = []
for i in xrange(self.BAR_NUMB):
br = ui.Bar()
br.SetParent(self)
br.AddFlag("attach")
br.AddFlag("not_pick")
br.SetColor([self.CORNERS_AND_LINES_COLOR, self.BASE_COLOR][i == (self.BAR_NUMB-1)])
if not (i % 2 == 0): br.SetSize(1, 1)
br.Show()
self.bars.append(br)
self.middleBar = self.MiddleBar(self.horizontal_scroll)
self.middleBar.SetParent(self)
self.middleBar.SetMoveEvent(ui.__mem_func__(self.OnScrollMove))
self.middleBar.Show()
def OnScrollMove(self):
if not self.scrollEvent:
return
arg = float(self.middleBar.GetLocalPosition()[1] - 1) / float(self.GetHeight() - 2 - self.middleBar.GetHeight()) if not self.horizontal_scroll else\
float(self.middleBar.GetLocalPosition()[0] - 1) / float(self.GetWidth() - 2 - self.middleBar.GetWidth())
self.scrollEvent(arg)
def SetScrollEvent(self, func):
self.scrollEvent = func
def SetScrollSpeed(self, speed):
self.scrollSpeed = speed
def OnMouseWheel(self, length):
if not self.IsShow():
return False
length = int((length * 0.01) * self.scrollSpeed)
if not self.horizontal_scroll:
val = min(max(1, self.middleBar.GetLocalPosition()[1] - (length * 0.01) * self.scrollSpeed * self.sizeScale), self.GetHeight() - self.middleBar.GetHeight() - 1)
self.middleBar.SetPosition(1, val)
else:
val = min(max(1, self.middleBar.GetLocalPosition()[0] - (length * 0.01) * self.scrollSpeed * self.sizeScale), self.GetWidth() - self.middleBar.GetWidth() - 1)
self.middleBar.SetPosition(val, 1)
self.OnScrollMove()
return True
def GetPos(self):
return float(self.middleBar.GetLocalPosition()[1] - 1) / float(self.GetHeight() - 2 - self.middleBar.GetHeight()) if not self.horizontal_scroll else float(self.middleBar.GetLocalPosition()[0] - 1) / float(self.GetWidth() - 2 - self.middleBar.GetWidth())
def OnMouseLeftButtonDown(self):
(xMouseLocalPosition, yMouseLocalPosition) = self.GetMouseLocalPosition()
if not self.horizontal_scroll:
if xMouseLocalPosition == 0 or xMouseLocalPosition == self.GetWidth():
return
y_pos = (yMouseLocalPosition - self.middleBar.GetHeight() / 2)
self.middleBar.SetPosition(1, y_pos)
else:
if yMouseLocalPosition == 0 or yMouseLocalPosition == self.GetHeight():
return
x_pos = (xMouseLocalPosition - self.middleBar.GetWidth() / 2)
self.middleBar.SetPosition(x_pos, 1)
self.OnScrollMove()
def SetSize(self, w, h):
(width, height) = (max(3, w), max(3, h))
ui.Window.SetSize(self, width, height)
self.bars[0].SetSize(1, (height - 2))
self.bars[0].SetPosition(0, 1)
self.bars[2].SetSize((width - 2), 1)
self.bars[2].SetPosition(1, 0)
self.bars[4].SetSize(1, (height - 2))
self.bars[4].SetPosition((width - 1), 1)
self.bars[6].SetSize((width - 2), 1)
self.bars[6].SetPosition(1, (height - 1))
self.bars[8].SetSize((width - 2), (height - 2))
self.bars[8].SetPosition(1, 1)
self.bars[1].SetPosition(0, 0)
self.bars[3].SetPosition((width - 1), 0)
self.bars[5].SetPosition((width - 1), (height - 1))
self.bars[7].SetPosition(0, (height - 1))
if not self.horizontal_scroll:
self.middleBar.SetStaticSize(width - 2)
self.middleBar.SetSize(12, self.GetHeight())
else:
self.middleBar.SetStaticSize(height - 2)
self.middleBar.SetSize(12, self.GetWidth())
self.middleBar.SetRestrictMovementArea(1, 1, width - 2, height - 2)
def SetScale(self, selfSize, fullSize):
self.sizeScale = float(selfSize)/float(fullSize)
if self.sizeScale <= 0.0305:
self.sizeScale = 0.05
self.middleBar.SetSize(selfSize, fullSize)
def SetStaticScale(self, r_size):
self.middleBar.SetStaticScale(r_size)
def SetPosScale(self, fScale):
pos = (math.ceil((self.GetHeight() - 2 - self.middleBar.GetHeight()) * fScale) + 1) if not self.horizontal_scroll else (math.ceil((self.GetWidth() - 2 - self.middleBar.GetWidth()) * fScale) + 1)
self.SetPos(pos)
def SetPos(self, pos):
wPos = (1, pos) if not self.horizontal_scroll else (pos, 1)
self.middleBar.SetPosition(*wPos)
def CreateWindow(window, parent, windowFlags, windowPos, windowArgument = "", windowPositionRule = "", windowSize = (-1, -1), windowFontName = -1):
if parent:
window.SetParent(parent)
for flag in windowFlags:
window.AddFlag(flag)
window.SetPosition(*windowPos)
if windowSize != (-1, -1):
window.SetSize(*windowSize)
if windowPositionRule:
splitList = windowPositionRule.split(":")
if len(splitList) == 2:
(type, mode) = (splitList[0], splitList[1])
if type == "all":
window.SetHorizontalAlignCenter()
window.SetVerticalAlignCenter()
window.SetWindowHorizontalAlignCenter()
window.SetWindowVerticalAlignCenter()
elif type == "horizontal":
if isinstance(window, ui.TextLine):
if mode == "center":
window.SetHorizontalAlignCenter()
elif mode == "right":
window.SetHorizontalAlignRight()
elif mode == "left":
window.SetHorizontalAlignLeft()
else:
if mode == "center":
window.SetWindowHorizontalAlignCenter()
elif mode == "right":
window.SetWindowHorizontalAlignRight()
elif mode == "left":
window.SetWindowHorizontalAlignLeft()
elif type == "vertical":
if isinstance(window, ui.TextLine):
if mode == "center":
window.SetVerticalAlignCenter()
elif mode == "top":
window.SetVerticalAlignTop()
elif mode == "bottom":
window.SetVerticalAlignBottom()
else:
if mode == "top":
window.SetWindowVerticalAlignTop()
elif mode == "center":
window.SetWindowVerticalAlignCenter()
elif mode == "bottom":
window.SetWindowVerticalAlignBottom()
if windowArgument:
if isinstance(window, ui.TextLine):
if windowFontName != -1:
window.SetFontName(windowFontName)
window.SetText(windowArgument)
elif isinstance(window, ui.NumberLine):
window.SetNumber(windowArgument)
elif isinstance(window, ui.Button) or isinstance(window, ui.RadioButton) or isinstance(window, ui.ToggleButton):
if isinstance(windowArgument, list):
window.SetUpVisual(windowArgument[0])
window.SetOverVisual(windowArgument[1] if len(windowArgument) >= 2 else windowArgument[0])
window.SetDownVisual(windowArgument[2] if len(windowArgument) >= 3 else windowArgument[0])
if len(windowArgument) == 4:
window.SetDisableVisual(windowArgument[3])
elif isinstance(window, ui.ExpandedImageBox) or isinstance(window, ui.ImageBox):
window.LoadImage(windowArgument if windowArgument.find("gr2") == -1 else "icon/item/27995.tga")
window.Show()
return window