Jump to content

Recommended Posts

Hi! Here you have a small improvement to the channel change system. I made the modifications to MoveChannel based on Martysama's code.

All the modifications are made in the uiMoveChannel.py file.
 

Spoiler
##Add imports:
import player
import os
import json


## add Before class MoveChannelWindow(ui.ScriptWindow)

path = "data/user/data/channel/"

def GetFilePath():
	char_name = player.GetName()
	filename = "{}_settings.json".format(char_name)
	return os.path.join(path, filename)

def GetServerID():
	serverID = 0
	for k in serverInfo.REGION_DICT[0].keys():
		if serverInfo.REGION_DICT[0][k]["name"] == net.GetServerInfo().split(",")[0]:
			serverID = k
			break
	return serverID

## Search for def __ini__(self): and add after self.__LoadWindow()
		self.LoadChannels()

## Search for def __Initialize(self): and after self.currentChannel = 0
		self.previousChannel = -1
		self.nextChannel = -1

##Replace def Open(self): with this:
	def Open(self):
		if self.ingameChannel == 99:
			chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.MOVE_CHANNEL_NOT_MOVE)
			return
		if self.ingameChannel < 99:
			self.currentChannel = self.ingameChannel - 1
			if self.previousChannel == -1:
				self.previousChannel = self.currentChannel
			if self.nextChannel == -1:
				self.nextChannel = self.currentChannel
		self.__RefreshChannelButtons()
		self.SetCenterPosition()
		self.Show()

##Replace def __RefreshChannelButtons(self): with this:
	def __RefreshChannelButtons(self):
		for i in xrange(self.GetChannelCount()):
			base_text = serverInfo.REGION_DICT[0][GetServerID()]["channel"][i]["name"]
			if i == self.currentChannel:
				text = base_text + " |cFF00FF00(Actual)|r"
			elif i == self.previousChannel:
				text = base_text + " |cFFFF0000(Anterior)|r"
			elif i == self.nextChannel and self.nextChannel != self.currentChannel:
				text = base_text + " |cFFFFFF00(Urmator)|r"
			else:
				text = base_text

			self.channelButtonList[i].SetText(text)

			if i == self.nextChannel:
				self.channelButtonList[i].Down()
			else:
				self.channelButtonList[i].SetUp()

#Replace SelectChannel(self, channel): with this:
	def SelectChannel(self, channel):
		self.nextChannel = channel
		self.__RefreshChannelButtons()

##Replace 	def ChangeChannel(self): with this:
	def ChangeChannel(self):
		channelID = self.nextChannel + 1
		if channelID <= 0 or channelID > 4:
			chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.MOVE_CHANNEL_NOT_MOVE)
			return
		if self.ingameChannel != channelID:
			self.previousChannel = self.ingameChannel - 1
			self.ingameChannel = channelID
			self.currentChannel = self.ingameChannel - 1
			self.nextChannel = self.currentChannel

			self.SaveChannels()

		self.__RefreshChannelButtons()
		self.Close()
		net.SendChatPacket("/change_channel {}".format(channelID))

##Add at the end of files:
	def SaveChannels(self):
		try:
			data = {
				"previousChannel": self.previousChannel,
				"currentChannel": self.currentChannel,
				"nextChannel": self.nextChannel,
				"ingameChannel": self.ingameChannel,
			}
			if not os.path.exists(path):
				os.makedirs(path)
			with open(GetFilePath(), "w") as f:
				json.dump(data, f)
		except Exception as e:
			dbg.Trace("Failed to save channels: {}".format(e))

	def LoadChannels(self):
		try:
			file_path = GetFilePath()
			if os.path.exists(file_path):
				with open(file_path, "r") as f:
					data = json.load(f)
					self.previousChannel = data.get("previousChannel", -1)
					self.currentChannel = data.get("currentChannel", 0)
					self.nextChannel = data.get("nextChannel", 0)
					self.ingameChannel = data.get("ingameChannel", 1)
			else:
				self.previousChannel = -1
				self.currentChannel = 0
				self.nextChannel = 0
				self.ingameChannel = 1
		except Exception as e:
			dbg.Trace("Failed to load channels: {}".format(e))
			self.previousChannel = -1
			self.currentChannel = 0
			self.nextChannel = 0
			self.ingameChannel = 1

 

spacer.png

  • Eyes 1
  • Good 4
Link to comment
https://metin2.dev/topic/33773-remember-channel-select-move-channel/
Share on other sites

  • 1 year later...

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.