[C++&PY] Map Name on The Application Window

  • Konbuyu başlatan Konbuyu başlatan Admin
  • Başlangıç tarihi Başlangıç tarihi
  • Cevaplar Cevaplar 0
  • Görüntüleme Görüntüleme 83

Admin

Metin2Lobby
Yönetici
Founder
Katılım
6 Mayıs 2022
Mesajlar
52,647
Ticaret : 1 / 0 / 0
Merhaba TurkMMO ;

Bugün ufak ama hoş bir detay paylaşacağım, oyun içerisinde bulunduğunuz map ismi title bölümünde yazacak.Fikir ve paylaşım için Metin2Dev'den Owsap adlı üyeye teşekkürler, kendisinden alıntıdır.

Nasıl Gözükür ?

<a href=" " class="link link--external" target="_blank" rel="nofollow ugc noopener" data-proxy-href="/proxy.php?link=https%3A%2F%2Fi.gyazo.com%2Fe48ad3ce390849d32da0840c206e67da.mp4&amp;hash=d6176d363cbd53032c1d6ece8e00c87f"> </a>

Anlatım ;

CLIENT SRC

UserInterface/Locale_inc.h
açılır ve içine eklenir ;

Kod:
#define ENABLE_MAP_NAME_ON_APP_TITLE // Exenin title bölümünde bulunduğunuz harita ismi gözükür.

UserInterface/PythonApplicationModule.cpp açılır ve aşağıdaki kod bulunur ;

Kod:
PyObject* appLoop(PyObject* poSelf, PyObject* poArgs)

Üstüne eklenir ;

Kod:
#if defined(ENABLE_MAP_NAME_ON_APP_TITLE) PyObject* appSetText(PyObject* poSelf, PyObject* poArgs) {     char* szName;     if (!PyTuple_GetString(poArgs, 0, &amp;szName))         return Py_BuildException();     CPythonApplication&amp; rkApp = CPythonApplication::Instance();     rkApp.SetText(szName);     return Py_BuildNone(); } #endif

Aşağıdaki kod bulunur ;

Kod:
{ "Loop", appLoop, METH_VARARGS },

Üstüne eklenir ;

Kod:
#if defined(ENABLE_MAP_NAME_ON_APP_TITLE)         { "SetText", appSetText, METH_VARARGS }, #endif

Aşağıdaki kod bulunur ;

Kod:
PyModule_AddIntConstant(poModule, "CAMERA_STOP", CPythonApplication::CAMERA_STOP);

Altına eklenir ;

Kod:
#if defined(ENABLE_MAP_NAME_ON_APP_TITLE)     PyModule_AddIntConstant(poModule, "ENABLE_MAP_NAME_ON_APP_TITLE", 1); #else     PyModule_AddIntConstant(poModule, "ENABLE_MAP_NAME_ON_APP_TITLE", 0); #endif

UserInterface/PythonNetworkStream.cpp açılır ve aşağıdaki kod bloğu bulunur ;

Kod:
bool CPythonNetworkStream::RecvPhasePacket

Kod bloğunun içinde bulunur ;


Kod:
case PHASE_GAME: // °ÔÀÓ È¸é         SetGamePhase();

Altına eklenir ;

Kod:
#if defined(ENABLE_MAP_NAME_ON_APP_TITLE)         PyCallClassMemberFunc(m_apoPhaseWnd[PHASE_WINDOW_GAME], "SetApplicationText", Py_BuildValue("()")); #endif

Client/root/game.py Açılır ve aşağıdaki bölüm bulunur ; //TAB AYARLARINA DİKKAT !!!

Kod:
def StartGame(self):         self.RefreshInventory()         self.RefreshEquipment()         self.RefreshCharacter()         self.RefreshSkill()

Üstüne Eklenir ;

Kod:
if app.ENABLE_MAP_NAME_ON_APP_TITLE:         def SetApplicationText(self):             mapName = background.GetCurrentMapName()             if mapName in localeInfo.MINIMAP_ZONE_NAME_DICT:                 app.SetText(localeInfo.APP_TITLE + " - " + localeInfo.MINIMAP_ZONE_NAME_DICT[mapName])

Metin2 Uygulama Penceresinde Harita Adını Gösterme (C++ & Python)

Metin2 özel sunucularında geliştirme yaparken, oyuncuların o anda hangi haritada bulunduğunu görebilmeleri oldukça önemli bir özelliktir. Bu özellik, hem kullanıcı deneyimini artırır hem de geliştiricinin kontrolünü kolaylaştırır. Bu yazıda, C++ tarafında oyun çekirdeğinde ve Python tarafında arayüzde (GUI) nasıl bir harita adı bilgisinin uygulama penceresinde gösterileceğini detaylıca inceleyeceğiz.

Harita Adı Nedir ve Neden Kullanılır?

Harita adı (map name), oyuncunun bulunduğu alanın ismidir. Metin2'de bu genellikle 'MapName' veya 'MapIndex' olarak tanımlanır. Bu bilgi, hem oyun içindeki sistemlerde hem de istatistiksel analizlerde, hata ayıklamada ve sunucu yönetimi için kritik öneme sahiptir. Örneğin, bir PvP savaşında oyuncu hangi haritada ise, o harita özel kuralları devreye girebilir. Bu nedenle, harita adının doğru şekilde takip edilmesi ve kullanıcıya aktarılması önemlidir.

C++ Tarafında Harita Adı Bilgisi Alımı

Oyun sunucusunun çekirdeğinde, yani game core tarafında, bir oyuncunun hangi haritada olduğu bilgisi genellikle client tarafına gönderilir. Bu işlem, genellikle packet (paket) üzerinden yapılır. Oyuncu bir haritaya geçiş yaptığında, game server tarafından bir mesaj gönderilir ve bu mesajda harita adı da yer alır.

Örnek olarak, game/src/map dizini altında bulunan CMapManager.cpp dosyasında, harita geçişlerini yöneten fonksiyonlar yer alır. Bu fonksiyonlardan biri olan SetCharacterPos, oyuncuyu belirtilen haritaya yerleştirir ve harita adını gönderir. Ayrıca, packets.h dosyasında tanımlanan HEADER_CG_MAP_CHANGE gibi paket tipleri ile harita bilgisi istemciye iletilir.

Python Tarafında Arayüzde Harita Adı Gösterimi

Python tarafında, genellikle root klasöründe bulunan uiscript dosyaları ile arayüz tasarlanır. Bu arayüzler, py root ve py gui sistemleri ile çalışır. Harita adını pencere başlığında veya ekranda göstermek için, Python tarafında bir GUI elemanı tanımlanabilir.

Örneğin, bir wnd.py dosyasında bir TextLine nesnesi oluşturulabilir. Bu nesne, net.SendChatPacket veya benzeri bir yöntemle gelen harita adı bilgisini alır ve ekranda gösterir. Eğer harita adını doğrudan pencere başlığına koymak isterseniz, Python’un Tkinter veya benzeri bir arayüz kütüphanesi ile title() fonksiyonu kullanılabilir.

Örnek Kod: Python GUI Üzerinde Harita Adı Gösterimi

import app, net, ui, wndMgr
class MapNameWindow(ui.Window):
def __init__(self):
ui.Window.__init__(self)
self.map_name_text = None
self.Build()
def Build(self):
self.map_name_text = ui.TextLine()
self.map_name_text.SetParent(self)
self.map_name_text.SetText('Current Map: ')
self.map_name_text.SetPosition(10, 10)
self.map_name_text.Show()
def UpdateMapName(self, mapName):
self.map_name_text.SetText('Current Map: %s' % mapName)

Bu yapı sayesinde, C++ tarafında gönderilen harita adı bilgisi Python tarafında alınarak GUI üzerinde gösterilebilir.

Harita Değişimini Takip Etme

Harita değişikliklerini anlık olarak takip etmek için, net.Update() fonksiyonu veya net.OnRecvPacket() metodları kullanılabilir. Bu metodlar sayesinde, sunucudan gelen harita adı bilgisi yakalanır ve GUI’ye aktarılır. Bu sayede kullanıcı, harita değişimlerini anlık olarak takip edebilir.

Sonuç

Metin2 özel sunucu geliştirme sürecinde, harita adı bilgisini doğru şekilde göstermek, kullanıcı dostu bir sistem oluşturmanın temel taşlarından biridir. Hem C++ hem de Python tarafında doğru entegrasyon ile bu bilgi, hem hata ayıklama hem de kullanıcı bilgilendirme açısından büyük fayda sağlar. Bu yapıyı uygulamak, server src ve client src üzerinde yapılan diğer geliştirmeler için de iyi bir temel oluşturur.


Displaying Map Name in the Application Window (C++ & Python) for Metin2

When developing private servers for Metin2, showing the current map name to players is an important feature. This feature enhances user experience and simplifies control for developers. In this article, we will examine how to display the map name information within the application window using both C++ for the game core and Python for the GUI interface.

What is Map Name and Why Use It?

The map name refers to the name of the area where the player currently resides. In Metin2, this is typically defined as 'MapName' or 'MapIndex'. This information is critical for internal game systems, statistical analysis, debugging, and server management. For instance, if a player is in a PvP battle, special rules for that map might apply. Therefore, accurately tracking and displaying the map name is crucial.

Retrieving Map Name in C++

Within the game server's core, i.e., the game core, the map location of a player is usually sent to the client side. This is generally done via packets. When a player transitions to a different map, the game server sends a message that includes the map name.

As an example, in the CMapManager.cpp file located under game/src/map, functions that manage map transitions are found. One such function, SetCharacterPos, places the player into the specified map and transmits the map name. Additionally, packet types like HEADER_CG_MAP_CHANGE defined in packets.h deliver map information to the client.

Displaying Map Name in Python GUI

On the Python side, the UI is generally designed using uiscript files located in the root folder. These interfaces operate with py root and py gui systems. To show the map name either in the window title or on-screen, a GUI element can be defined in Python.

For example, in a wnd.py file, a TextLine object can be created. This object receives the map name from net.SendChatPacket or similar methods and displays it on screen. If you want to place the map name directly in the window title, you can use title() from a Python GUI library such as Tkinter.

Sample Code: Displaying Map Name in Python GUI

import app, net, ui, wndMgr
class MapNameWindow(ui.Window):
def __init__(self):
ui.Window.__init__(self)
self.map_name_text = None
self.Build()
def Build(self):
self.map_name_text = ui.TextLine()
self.map_name_text.SetParent(self)
self.map_name_text.SetText('Current Map: ')
self.map_name_text.SetPosition(10, 10)
self.map_name_text.Show()
def UpdateMapName(self, mapName):
self.map_name_text.SetText('Current Map: %s' % mapName)

With this structure, the map name sent from the C++ side can be received and displayed in the GUI using Python.

Tracking Map Changes

To track map changes in real-time, net.Update() or net.OnRecvPacket() methods can be used. These allow capturing the map name sent by the server and passing it to the GUI. This way, users can follow map changes instantly.

Conclusion

In the process of developing Metin2 private servers, correctly displaying the map name is one of the fundamental elements of creating a user-friendly system. Correct integration on both C++ and Python sides provides significant benefits for both debugging and user notification. Implementing this structure also lays a good foundation for other enhancements made on server src and client src.
 

Şuan Bu Konuyu Görüntüleyen Kullanıcılar (Toplam : 0, Üye : 0, Misafir : 0)

Geri
Üst Alt