feat: port AVA2 native channel dialog and preserve warp endpoint
This commit is contained in:
@@ -341,6 +341,11 @@ def LoadChildren(self, parent, dicChildren):
|
||||
parent.Children[Index].SetParent(parent)
|
||||
self.LoadElementThinBoard(parent.Children[Index], ElementValue, parent)
|
||||
|
||||
elif Type == "thinboard_circle":
|
||||
parent.Children[Index] = ThinBoardCircle()
|
||||
parent.Children[Index].SetParent(parent)
|
||||
self.LoadElementThinBoard(parent.Children[Index], ElementValue, parent)
|
||||
|
||||
elif Type == "box":
|
||||
parent.Children[Index] = Box()
|
||||
parent.Children[Index].SetParent(parent)
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
// AVA2 uisystem.MoveChannelDialog; native server warp replaces logout/relogin switching.
|
||||
static const char c_szNativeChannelScript[] = R"PY(# -*- coding: utf-8 -*-
|
||||
import app,background,chat,game,localeInfo,mt_channel,mt_live_endpoint,net,serverInfo,ui
|
||||
L=__import__('player').AutoHuntLocalize
|
||||
for key,text in {'MOVE_CHANNEL_TITLE':'切换频道','MOVE_CHANNEL_SELECT':'切换','MOVE_CHANNEL_CANCEL':'取消'}.items():setattr(localeInfo,key,L(text))
|
||||
_channels=[]
|
||||
_current=0
|
||||
_window=None
|
||||
class MoveChannelDialog(ui.ScriptWindow):
|
||||
def __init__(self):
|
||||
ui.ScriptWindow.__init__(self)
|
||||
self.Destroy()
|
||||
self.__LoadDialog()
|
||||
|
||||
def __del__(self):
|
||||
ui.ScriptWindow.__del__(self)
|
||||
|
||||
def Destroy(self):
|
||||
self.ClearDictionary()
|
||||
self.ParentBoard = 0
|
||||
self.ChildBoard = 0
|
||||
self.ChannelList = 0
|
||||
self.DlgWidht = 0
|
||||
self.channel = 0
|
||||
self.BlackBoardHeight = 0
|
||||
self.DlgHeight = 0
|
||||
self.AcceptBtn = 0
|
||||
self.CloseBtn = 0
|
||||
self.ChangeChannelNumber = 0
|
||||
|
||||
def __LoadDialog(self):
|
||||
try:
|
||||
pyScrLoader = ui.PythonScriptLoader()
|
||||
pyScrLoader.LoadScriptFile(self, "UIScript/MoveChannelDialog.py")
|
||||
except:
|
||||
import exception
|
||||
exception.Abort("MoveChannelDialog.__LoadDialog")
|
||||
|
||||
self.ParentBoard = self.GetChild("MoveChannelBoard")
|
||||
self.ChildBoard = self.GetChild("BlackBoard")
|
||||
self.GetChild("MoveChannelTitle").SetCloseEvent(ui.__mem_func__(self.Close))
|
||||
|
||||
self.ChannelList = []
|
||||
cnt = len(_channels)
|
||||
|
||||
self.DlgWidht = 190
|
||||
self.BlackBoardHeight = 23*cnt + 5*(cnt-1) + 13
|
||||
self.DlgHeight = self.BlackBoardHeight + 75
|
||||
|
||||
self.AcceptBtn = ui.MakeButton(self.ParentBoard, 13, self.DlgHeight - 33, "", "d:/ymir work/ui/public/", "middle_button_01.sub", "middle_button_02.sub", "middle_button_03.sub")
|
||||
self.AcceptBtn.SetText( localeInfo.MOVE_CHANNEL_SELECT )
|
||||
self.AcceptBtn.SetEvent(ui.__mem_func__(self.AcceptButton))
|
||||
self.CloseBtn = ui.MakeButton(self.ParentBoard, self.DlgWidht - 73, self.DlgHeight - 33, "", "d:/ymir work/ui/public/", "middle_button_01.sub", "middle_button_02.sub", "middle_button_03.sub")
|
||||
self.CloseBtn.SetText( localeInfo.MOVE_CHANNEL_CANCEL )
|
||||
self.CloseBtn.SetEvent(ui.__mem_func__(self.Close))
|
||||
|
||||
for i in xrange(cnt):
|
||||
btn = ui.MakeButton(self.ChildBoard, 8, 6 + i*28, "", "d:/ymir work/ui/game/myshop_deco/", "select_btn_01.sub", "select_btn_02.sub", "select_btn_03.sub")
|
||||
btn.SetText("CH %d"%(_channels[i]))
|
||||
btn.SetEvent(ui.__mem_func__(self.__SelectChannel), _channels[i])
|
||||
self.ChannelList.append(btn)
|
||||
|
||||
self.ParentBoard.SetSize(self.DlgWidht, self.DlgHeight)
|
||||
self.ChildBoard.SetSize(self.DlgWidht - 26, self.BlackBoardHeight)
|
||||
self.SetSize(self.DlgWidht, self.DlgHeight)
|
||||
|
||||
self.UpdateRect()
|
||||
|
||||
def __SelectChannel(self, idx):
|
||||
self.ChangeChannelNumber = idx
|
||||
if idx not in _channels:return
|
||||
|
||||
if self.ChangeChannelNumber >= 8:
|
||||
return
|
||||
for btn in self.ChannelList:
|
||||
btn.SetUp()
|
||||
btn.Enable()
|
||||
|
||||
self.ChannelList[_channels.index(idx)].Down()
|
||||
self.ChannelList[_channels.index(idx)].Disable()
|
||||
|
||||
def AcceptButton(self):
|
||||
#if self.CheckIsBlockMap(): # already have in gamesrc.
|
||||
# return
|
||||
|
||||
if self.ChangeChannelNumber == self.StartChannelNumber:
|
||||
return
|
||||
|
||||
net.SendChatPacket("/move_channel %d" % self.ChangeChannelNumber)
|
||||
self.__SaveChannelInfo()
|
||||
self.StartChannelNumber = self.ChangeChannelNumber
|
||||
self.Close()
|
||||
|
||||
def Show(self):
|
||||
ui.ScriptWindow.Show(self)
|
||||
|
||||
self.StartChannelNumber = self.GetChannelNumber()
|
||||
self.__SelectChannel(self.StartChannelNumber)
|
||||
|
||||
def Close(self):
|
||||
self.Hide()
|
||||
|
||||
def OnPressEscapeKey(self):
|
||||
self.Close()
|
||||
return True
|
||||
|
||||
def GetChannelNumber(self):
|
||||
return _current
|
||||
|
||||
def CheckIsBlockMap(self):
|
||||
blockmapList = ["metin2_map_a1", "metin2_map_deviltower1", "metin2_map_b1","metin2_map_c1","metin2_map_wedding_01","metin2_map_oxevent","metin2_map_t3","metin2_map_t4","metin2_map_sungzi","metin2_map_sungzi_flame_hill_01","metin2_map_sungzi_flame_hill_02","metin2_map_sungzi_flame_hill_03","metin2_map_sungzi_snow","metin2_map_sungzi_snow_pass01","metin2_map_sungzi_snow_pass02","metin2_map_sungzi_snow_pass03","metin2_map_sungzi_desert_01","metin2_map_sungzi_desert_hill_01","metin2_map_sungzi_desert_hill_02","metin2_map_sungzi_desert_hill_03","metin2_map_empirewar01","metin2_map_empirewar02","metin2_map_empirewar03","metin2_map_guild_02","metin2_map_guild_03","metin2_map_kingdoomswar","metin2_map_duel"]
|
||||
if background.GetCurrentMapName() in blockmapList:
|
||||
#chat.AppendChat(1, localeInfo.CHANNEL_CHANGE_BLOCK)
|
||||
return True
|
||||
return False
|
||||
|
||||
def IsShowWindow(self):
|
||||
return self.IsShow()
|
||||
|
||||
def __SaveChannelInfo(self):
|
||||
if not any(self.ChangeChannelNumber in server.get("channel",{}) for region in serverInfo.REGION_DICT.values() for server in region.values()):return
|
||||
loadRegionID, loadServerID, loadChannelID = self.__LoadChannelInfo()
|
||||
try:
|
||||
file = open("channel.inf", "w+")
|
||||
file.write("%d %d %d" % (loadServerID, self.ChangeChannelNumber, loadRegionID))
|
||||
file.close()
|
||||
except:
|
||||
return
|
||||
|
||||
def __LoadChannelInfo(self):
|
||||
try:
|
||||
file = open("channel.inf")
|
||||
lines = file.readlines()
|
||||
file.close()
|
||||
if len(lines) > 0:
|
||||
tokens = lines[0].split()
|
||||
selServerID = int(tokens[0])
|
||||
selChannelID = int(tokens[1])
|
||||
if len(tokens) == 3:
|
||||
regionID = int(tokens[2])
|
||||
return regionID, selServerID, selChannelID
|
||||
except:
|
||||
return -1, -1, -1
|
||||
|
||||
def RequestOpen(self):
|
||||
self.Show()
|
||||
net.SendChatPacket('/channel_list')
|
||||
MoveChannelDialog.Open=RequestOpen
|
||||
MoveChannelDialog.Refresh=lambda self:None
|
||||
_oldOpen=game.GameWindow.Open
|
||||
_oldClose=game.GameWindow.Close
|
||||
_oldCommand=game.GameWindow.BINARY_ServerCommand_Run
|
||||
|
||||
def Open(self):
|
||||
result=_oldOpen(self)
|
||||
net.SendChatPacket('/channel_list')
|
||||
return result
|
||||
|
||||
def Close(self):
|
||||
global _window,_channels,_current
|
||||
if _window:_window.Hide()
|
||||
_window=None;_channels=[];_current=0
|
||||
return _oldClose(self)
|
||||
|
||||
def Command(self,line):
|
||||
global _window,_channels,_current
|
||||
words=line.split()
|
||||
if words and words[0]=='ChannelList':
|
||||
if len(words)!=3:return 1
|
||||
try:
|
||||
current=int(words[1]);channels=[int(v) for v in words[2].split(',')]
|
||||
if (not 1<=current<=7 or any(not 1<=v<=7 for v in channels)) and not (current==99 and channels==[99]):return 1
|
||||
if len(channels)>7 or current not in channels:return 1
|
||||
except (ValueError,OverflowError):return 1
|
||||
_current=current;channels=sorted(set(channels))
|
||||
if _window and _channels==channels:
|
||||
_window.channel=current
|
||||
if _window.IsShow():_window.Show()
|
||||
return 1
|
||||
shown=bool(mt_channel.g_window and mt_channel.g_window.IsShow())
|
||||
if mt_channel.g_window:
|
||||
mt_channel.g_window.Hide();mt_channel.g_window.Destroy()
|
||||
_channels=channels;_window=MoveChannelDialog();_window.channel=current
|
||||
mt_channel.g_window=_window
|
||||
if shown:_window.Show()
|
||||
return 1
|
||||
if words and words[0]=='UpdateServerInfo':
|
||||
if len(words)==2:
|
||||
try:
|
||||
channel=int(words[1])
|
||||
if 1<=channel<=7:
|
||||
_current=channel
|
||||
if _window:_window.channel=channel
|
||||
net.SetServerInfo('Metin2, CH %d'%channel)
|
||||
except (ValueError,OverflowError):pass
|
||||
return 1
|
||||
if words and words[0]=='ChannelEndpoint':
|
||||
if len(words)!=4:return 1
|
||||
try:
|
||||
channel=int(words[1]);port=int(words[3]);octets=words[2].split('.')
|
||||
if not 1<=channel<=7 or not 1<=port<=65535 or len(octets)!=4 or any(not v.isdigit() or not 0<=int(v)<=255 for v in octets):return 1
|
||||
mt_live_endpoint.Configure(self.stream,words[2],port,self.stream.account_addr,self.stream.account_port)
|
||||
except (ValueError,OverflowError):pass
|
||||
return 1
|
||||
if words and words[0]=='ChannelError':
|
||||
chat.AppendChat(chat.CHAT_TYPE_INFO,L('当前位置或状态不能换线,或目标频道尚未开放。'))
|
||||
return 1
|
||||
return _oldCommand(self,line)
|
||||
|
||||
game.GameWindow.Open=Open
|
||||
game.GameWindow.Close=Close
|
||||
game.GameWindow.BINARY_ServerCommand_Run=Command
|
||||
)PY";
|
||||
@@ -1043,6 +1043,7 @@ namespace PythonBoot
|
||||
#include "ItemActionsScript.inc"
|
||||
#include "AttrLockScript.inc"
|
||||
#include "LiveEndpointScript.inc"
|
||||
#include "NativeChannelScript.inc"
|
||||
#include "MinimapOuterRingScript.inc"
|
||||
#ifdef MT_HAS_MESHPORT
|
||||
#include "MeshPortScript.inc"
|
||||
@@ -1148,6 +1149,7 @@ bool RunMainScript(const char* lpCmdLine, std::string* error)
|
||||
install_script_module("mt_item_actions", c_szItemActionsScript);
|
||||
install_script_module("mt_attr_lock", c_szAttrLockScript);
|
||||
install_script_module("mt_live_endpoint", c_szLiveEndpointScript);
|
||||
install_script_module("mt_native_channel", c_szNativeChannelScript);
|
||||
install_script_module("mt_minimap_buttons", c_szMinimapOuterRingScript);
|
||||
if (g_touch_input)
|
||||
install_script_module("mt_mobile_hud", c_szMobileHUDScript);
|
||||
|
||||
Reference in New Issue
Block a user