Jump to content

Recommended Posts

  • Active+ Member

While analyzing the official MESSENGER_RENEWAL system in order to recreate it, I noticed that it uses the following parameters:

"outline_tooltip_text"  : uiScriptLocale.COMMUNITY_MAIN_TAB_GUILD,
"outline_tooltip_width": 65,

These are used to display a more modern-looking tooltip description for buttons.
So I decided to implement the same thing on my side, trying to follow the same logic used on the official.
Additionally, buttons that are in a "disabled" state can now also display tooltips.

INSTALLATION

 

UserInterface/Locale_inc.h

Add:

#define ENABLE_BUTTON_TOOLTIP_RENEWAL


UserInterface/PythonApplicationModule.cpp

Search:

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

Add below:

#ifdef ENABLE_BUTTON_TOOLTIP_RENEWAL
    PyModule_AddIntConstant(poModule, "ENABLE_BUTTON_TOOLTIP_RENEWAL",    1);
#else
    PyModule_AddIntConstant(poModule, "ENABLE_BUTTON_TOOLTIP_RENEWAL",    0);
#endif


EterPythonLib/PythonWindow.cpp

Search:

    void CButton::OnMouseOverIn()
    {
        if (!IsEnable())
            return;

        Over();
        PyCallClassMemberFunc(m_poHandler, "ShowToolTip", BuildEmptyTuple());
    }
    void CButton::OnMouseOverOut()
    {
        if (!IsEnable())
            return;

        SetUp();
        PyCallClassMemberFunc(m_poHandler, "HideToolTip", BuildEmptyTuple());
    }

Replace with:

#ifdef ENABLE_BUTTON_TOOLTIP_RENEWAL
    void CButton::OnMouseOverIn()
    {
        if (IsEnable())
        {
            Over();
        }

        PyCallClassMemberFunc(m_poHandler, "ShowToolTip", BuildEmptyTuple());
    }
    void CButton::OnMouseOverOut()
    {
        if (IsEnable())
        {
            SetUp();
        }

        PyCallClassMemberFunc(m_poHandler, "HideToolTip", BuildEmptyTuple());
    }
#else
    void CButton::OnMouseOverIn()
    {
        if (!IsEnable())
            return;

        Over();
        PyCallClassMemberFunc(m_poHandler, "ShowToolTip", BuildEmptyTuple());
    }
    void CButton::OnMouseOverOut()
    {
        if (!IsEnable())
            return;

        SetUp();
        PyCallClassMemberFunc(m_poHandler, "HideToolTip", BuildEmptyTuple());
    }
#endif


EterPythonLib/PythonWindow.h

Add:

#include "../UserInterface/Locale_inc.h" // ENABLE_BUTTON_TOOLTIP_RENEWAL


ui.py

Search in class Button(Window):

    def SetUp(self):
        wndMgr.SetUp(self.hWnd)


Add below:

    if app.ENABLE_BUTTON_TOOLTIP_RENEWAL:
        def Over(self):
            wndMgr.Over(self.hWnd)


Search in class Button(Window):

        def ShowToolTip(self):
            if self.ToolTipText:
                self.ToolTipText.Show()

        def HideToolTip(self):
            if self.ToolTipText:
                self.ToolTipText.Hide()


Replace with:

    if app.ENABLE_BUTTON_TOOLTIP_RENEWAL:
        def SetToolTipTextRenew(self, text, min_width=0):
            if not text:
                return

            self.SetRenewToolTip(text, min_width)

        def SetRenewToolTip(self, text, min_width):
            import uiToolTip 

            if not self.ToolTipText or not isinstance(self.ToolTipText, uiToolTip.ToolTip):
                self.ToolTipText = uiToolTip.ToolTip()

            self.ToolTipText.ClearToolTip()

            if isinstance(text, str):
                lines = text.split("\n")
                for line in lines:
                    self.ToolTipText.AutoAppendTextLine(line)

            elif isinstance(text, list) or isinstance(text, tuple):
                for line in text:
                    self.ToolTipText.AutoAppendTextLine(str(line))

            self.ToolTipText.AutoResize(min_width)

        def ShowToolTip(self):
            if self.ToolTipText:
                if hasattr(self.ToolTipText, "ShowToolTip"):
                    self.ToolTipText.ShowToolTip()
                else:
                    self.ToolTipText.Show()

        def HideToolTip(self):
            if self.ToolTipText:
                if hasattr(self.ToolTipText, "HideToolTip"):
                    self.ToolTipText.HideToolTip()
                else:
                    self.ToolTipText.Hide()
    else:
        def SetToolTipTextRenew(self, text, min_width=0):
            self.SetToolTipText(text)

        def ShowToolTip(self):
            if self.ToolTipText:
                self.ToolTipText.Show()

        def HideToolTip(self):
            if self.ToolTipText:
                self.ToolTipText.Hide()


Search in def LoadElementButton :

        if TRUE == value.has_key("tooltip_text"):
            if TRUE == value.has_key("tooltip_x") and TRUE == value.has_key("tooltip_y"):
                window.SetToolTipText(value["tooltip_text"], int(value["tooltip_x"]), int(value["tooltip_y"]))
            else:
                window.SetToolTipText(value["tooltip_text"])

Add below:

        if app.ENABLE_BUTTON_TOOLTIP_RENEWAL:
            if TRUE == value.has_key("outline_tooltip_text"):
                if TRUE == value.has_key("outline_tooltip_width"):
                    window.SetToolTipTextRenew(value["outline_tooltip_text"], int(value["outline_tooltip_width"]))
                else:
                    window.SetToolTipTextRenew(value["outline_tooltip_text"])
        else:
            if TRUE == value.has_key("outline_tooltip_text"):
                window.SetToolTipText(value["outline_tooltip_text"])

uitooltip.py

Search in class ToolTip(ui.ThinBoard):

    def HideToolTip(self):
        self.Hide()

Add below:

    if app.ENABLE_BUTTON_TOOLTIP_RENEWAL:
        def AutoResize(self, min_width):
            maxWidth = 0

            for child in self.childrenList:

                if isinstance(child, ui.TextLine):
                    (w, h) = child.GetTextSize()
                    if w > maxWidth:
                        maxWidth = w

                elif hasattr(child, "GetWidth"):
                    w = child.GetWidth()
                    if w > maxWidth and w != 150:
                        maxWidth = w

            self.toolTipWidth = (maxWidth + 40)

            if self.toolTipWidth < 40:
                self.toolTipWidth = 40

            if self.toolTipWidth < min_width:
                self.toolTipWidth = min_width

            self.AlignHorizonalCenter()
            self.ResizeToolTip()

 

PREVIEW

 spacer.png
 

USAGE

You can use it directly in UIScript like this:

{
    "name"                  : "community_guild_tab_button",
    "type"                  : "button",

    "x"                     : 105,
    "y"                     : 400,

    "width"                 : 95,
    "height"                : 90,

    "outline_tooltip_text"  : uiScriptLocale.COMMUNITY_MAIN_TAB_GUILD,  # tooltip text
    "outline_tooltip_width" : 65,  # minimum width accepted (useful if you want a larger tooltip even with short text)
},

Or directly from Python:

self.buttonName.SetToolTipTextRenew(text, minimum_width)


 

  • Metin2 Dev 2
  • Love 4
Link to comment
https://metin2.dev/topic/34222-button-tooltip-renewal/
Share on other sites

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.