CheckBox sınıfına çok benzer, bu yüzden onu kullanmak için tek yapmanız gereken kullanıcı arayüzünü değiştirmek. ui.CheckBox() -> ui.ToggleSwitch()
ve "ON_UNCKECK" ile ilgili herhangi bir sorununuz varsa
<blockquote data-attributes="" data-quote="" data-source="" class="bbCodeBlock bbCodeBlock--expandable bbCodeBlock--quote js-expandWatch">
Kod:
import math MAIN_PATH = "d:/ymir work/ui/game/toggle_switch/special/" class ToggleSwitch(Window): def __init__(self): Window.__init__(self) self._Initialize() self.CreateElements() def __del__(self): Window.__del__(self) self._Initialize() def _Initialize(self): self.backgroundImage = None self.checkImage = None self.eventFunc = { "ON_CHECK" : None, "ON_UNCHECK" : None, } self.eventArgs = { "ON_CHECK" : None, "ON_UNCHECK" : None, } self.isChecked = False self.animationProgress = 0 self.animationDuration = 10 self.isAnimating = False self.uncheckedXPosition = 0 self.checkedXPosition = 13 self.animationDistance = self.checkedXPosition - self.uncheckedXPosition def CreateElements(self): self.backgroundImage = ImageBox() self.backgroundImage.SetParent(self) self.backgroundImage.AddFlag("not_pick") self.backgroundImage.SetPosition(0, 0) self.backgroundImage.LoadImage(MAIN_PATH + "bg.png") self.backgroundImage.Show() self.checkImage = ImageBox() self.checkImage.SetParent(self.backgroundImage) self.checkImage.AddFlag("not_pick") self.checkImage.SetPosition(self.uncheckedXPosition, 0) self.checkImage.LoadImage(MAIN_PATH + "Unchecked.png") self.checkImage.Show() self.textInfo = TextLine() self.textInfo.SetParent(self) self.textInfo.SetPosition(0, 0) self.textInfo.SetWindowHorizontalAlignRight() self.textInfo.Show() self.SetSize(self.backgroundImage.GetWidth(), self.backgroundImage.GetHeight()) self.backgroundImage.SetWindowHorizontalAlignCenter() def SetTextInfo(self, info, x = 50, y = 0): if self.textInfo: self.textInfo.SetText(info) self.textInfo.SetPosition(x, y) def SetCheckStatus(self, flag): if flag != self.isChecked: self.isChecked = flag self.StartAnimation() def GetCheckStatus(self): if self.checkImage: return self.isChecked return False def SetEvent(self, func, *args) : result = self.eventFunc.has_key(args[0]) if result : self.eventFunc[args[0]] = func self.eventArgs[args[0]] = args else : print "[ERROR] ui.py SetEvent, Can`t Find has_key : %s" % args[0] def OnMouseLeftButtonUp(self): if not self.isAnimating: self.isChecked = not self.isChecked self.StartAnimation() if self.isChecked and self.eventFunc["ON_CHECK"]: apply(self.eventFunc["ON_CHECK"], self.eventArgs["ON_CHECK"]) elif not self.isChecked and self.eventFunc["ON_UNCHECK"]: apply(self.eventFunc["ON_UNCHECK"], self.eventArgs["ON_UNCHECK"]) def StartAnimation(self): self.isAnimating = True self.animationProgress = 0 self.checkImage.Show() def OnRender(self): if self.isAnimating: self.animationProgress += 1 progress = float(self.animationProgress) / self.animationDuration if progress <= 1: x_offset = int(math.sin(progress * math.pi / 2) * self.animationDistance) if self.isChecked: self.checkImage.SetPosition(self.uncheckedXPosition + x_offset, 0) self.checkImage.LoadImage(MAIN_PATH + "Checked.png") else: self.checkImage.SetPosition(self.checkedXPosition - x_offset, 0) self.checkImage.LoadImage(MAIN_PATH + "Unchecked.png") else: self.isAnimating = False self.animationProgress = 0 if self.isChecked: self.checkImage.SetPosition(self.checkedXPosition, 0) self.checkImage.LoadImage(MAIN_PATH + "Checked.png") else: self.checkImage.SetPosition(self.uncheckedXPosition, 0) self.checkImage.LoadImage(MAIN_PATH + "Unchecked.png")
Animasyonlu Geçiş Anahtarı - Python
Python Kullanarak Animasyonlu Geçiş Sistemleri
Metin2 özel sunucularında kullanıcı arayüzü geliştirmek isteyen geliştiriciler için animasyonlar önemli bir yere sahiptir. Özellikle geçiş anahtarları gibi görsel etkileşim unsurları, oyuncu deneyimini ciddi anlamda artırabilir. Bu yazıda, Python dilini kullanarak nasıl animasyonlu geçiş anahtarı oluşturulacağını ve bu sistemin Metin2 özel sunucularında nasıl uygulanabileceğini detaylı olarak ele alacağız.
Geçiş Anahtarı Nedir?
Geçiş anahtarı, genellikle menü geçişlerinde veya farklı ekranlar arasında geçiş yaparken kullanılan görsel bir bileşendir. Örneğin, bir menüden diğerine geçerken soluk bir animasyonla ekranda belirip kaybolan bir buton ya da arka plan efekti gibi düşünebilirsiniz. Bu tür efektler, kullanıcı arayüzünü modern ve profesyonel göstermek için idealdir.
Python ile Animasyonlu Geçiş Uygulaması
Python, özellikle PyQt veya Tkinter gibi GUI kütüphaneleri sayesinde animasyonlu arayüz bileşenleri oluşturmak için oldukça elverişlidir. Bu sistemler, Metin2 özel sunucularında py gui veya uiscript dosyalarıyla entegre edilebilir. Öncelikle basit bir geçiş animasyonu oluşturalım:
Örnek Kod Yapısı:
from PyQt5.QtWidgets import QWidget, QPushButton, QApplication, QLabel
from PyQt5.QtCore import QPropertyAnimation, QEasingCurve
class TransitionButton(QWidget):
def __init__(self):
super().__init__()
self.button = QPushButton('Geçiş Butonu', self)
self.button.setGeometry(100, 100, 150, 50)
self.animation = QPropertyAnimation(self.button, b'geometry')
self.setup_animation()
def setup_animation(self):
self.animation.setDuration(1000)
self.animation.setStartValue(self.button.geometry())
self.animation.setEndValue(self.button.geometry().adjusted(0, 0, 100, 0))
self.animation.setEasingCurve(QEasingCurve.InOutQuad)
def start_animation(self):
self.animation.start()
Metin2 Özel Sunucularda Entegrasyon
Python ile oluşturulan bu tür animasyonlar, py root dizininde yer alan arayüz dosyalarıyla birleştirilebilir. Özellikle uiscript dosyalarında belirli menüler için özel geçiş efektleri tanımlamak mümkündür. Bu sayede oyuncular daha akıcı ve estetik bir arayüz deneyimi yaşarlar.
Avantajlar
- Oyuncu dikkatini çeker
- Arayüzü daha modern hale getirir
- Tıklama sonrası geri bildirim sağlar
- Sunucu marka imajını güçlendirir
Sonuç
Python tabanlı animasyonlu geçiş anahtarı sistemleri, Metin2 özel sunucularında kullanıcı deneyimini artırmak için güçlü bir araçtır. Geliştiriciler, bu tür küçük ama etkili detaylarla sunucularını rakiplerinden ayırabilirler. Bu sistemleri doğru şekilde uygulamak, hem teknik hem de görsel açıdan fark yaratmak için harika bir yöntemdir.
Animated Transition Switch - Python
Creating Animated Transitions with Python
For developers looking to enhance the user interface in Metin2 private servers, animations play a significant role. Visual interaction elements like transition switches can significantly improve the player experience. In this article, we will detail how to create an animated transition switch using the Python language and how this system can be implemented in Metin2 private servers.
What is a Transition Switch?
A transition switch is typically a visual component used during menu transitions or switching between different screens. For example, think of a button that appears and disappears with a smooth animation when transitioning from one menu to another. Such effects are ideal for making the user interface look more modern and professional.
Implementing Animated Transitions with Python
Python is quite suitable for creating animated UI components thanks to GUI libraries such as PyQt or Tkinter. These systems can be integrated into Metin2 private servers via py gui or uiscript files. Let’s start by creating a simple transition animation:
Sample Code Structure:
from PyQt5.QtWidgets import QWidget, QPushButton, QApplication, QLabel
from PyQt5.QtCore import QPropertyAnimation, QEasingCurve
class TransitionButton(QWidget):
def __init__(self):
super().__init__()
self.button = QPushButton('Transition Button', self)
self.button.setGeometry(100, 100, 150, 50)
self.animation = QPropertyAnimation(self.button, b'geometry')
self.setup_animation()
def setup_animation(self):
self.animation.setDuration(1000)
self.animation.setStartValue(self.button.geometry())
self.animation.setEndValue(self.button.geometry().adjusted(0, 0, 100, 0))
self.animation.setEasingCurve(QEasingCurve.InOutQuad)
def start_animation(self):
self.animation.start()
Integration in Metin2 Private Servers
Animations created with Python can be merged with UI files located in the py root directory. Specifically, custom transition effects can be defined in uiscript files for certain menus. This allows players to enjoy a smoother and more aesthetic interface experience.
Advantages
- Captures player attention
- Makes the interface more modern
- Provides feedback after clicking
- Strengthens server branding
Conclusion
Python-based animated transition switch systems are powerful tools for enhancing user experience in Metin2 private servers. Developers can differentiate their servers from competitors by implementing these small yet impactful details. Correctly applying these systems is an excellent way to make a difference both technically and visually.
