Informations
Jump to content

Lorem Ipsum...

Click to Dismiss this Notification
Ładowanie danych...

Recommended Posts

Today, I'm excited to share a feature that enhances the player experience by improving quest interactions through tooltips. This particular functionality, known as OnInsertImageShowItemToolTip, was integrated into the official release around 2014-2015, likely coinciding with the introduction of new armors. While the tooltip can appear somewhat unconventional, I'm sharing the code as it was implemented officially.

Tooltip Example

Important Note:

Please be aware that this implementation is not reversed; it utilizes only the official, root components.

Step 1: Update the Python Event Manager Header

Start by navigating to PythonEventManager.h and incorporate the following line at the bottom of the enum EEventType:

 
EVENT_TYPE_INSERT_IMAGE_SHOW_ITEM_TOOLTIP,
    

Step 2: Modify the Event Manager Implementation

Next, proceed to PythonEventManager.cpp. Within the constructor, specifically CPythonEventManager::CPythonEventManager(), add this line towards the end:

 
EventTypeMap["INSERT_IMAGE_SHOW_ITEM_TOOLTIP"] = EVENT_TYPE_INSERT_IMAGE_SHOW_ITEM_TOOLTIP;

Now, in the same file, locate the function CPythonEventManager::ProcessEventSet(TEventSet* pEventSet) and add the following case right before the closing bracket:

 
case EVENT_TYPE_INSERT_IMAGE_SHOW_ITEM_TOOLTIP:
{
    int vnum = atoi(GetArgument("vnum", ScriptCommand.argList));
    int index = atoi(GetArgument("index", ScriptCommand.argList));
    int total = atoi(GetArgument("total", ScriptCommand.argList));

    PyCallClassMemberFunc(pEventSet->poEventHandler, "OnInsertImageShowItemToolTip", Py_BuildValue("(iii)", vnum, index, total));
    pEventSet->iAdjustLine += 2;
    break;
}

With those changes made, you can now compile the client.

Step 3: Enhance the Client-Side UI

Now, let’s modify the client by editing uiQuest.py. Add the following class beneath the line:

 
entire_questpage_number = 1

ItemToolTipImageBox Class Definition

 
##[ENABLE_QUEST_SHOWITEMTOOLOIP
class ItemToolTipImageBox(ui.ImageBox):
    def __init__(self):
        ui.ImageBox.__init__(self)
        self.itemvnum = 0
        self.DestroyToolTip()

    def __del__(self):
        ui.ImageBox.__del__(self)

    def CreateToolTip(self, parent, x, y, vnum):
        import uiToolTip
        self.toolTip = uiToolTip.ItemToolTip()
        self.toolTip.SetWindowHorizontalAlignCenter()
        self.toolTip.SetFollow(False)
        self.toolTip.SetPosition(x, y)
        self.itemvnum = vnum
        self.toolTip.SetItemToolTip(self.itemvnum)
        self.toolTip.ResizeToolTip()
        self.toolTip.Hide()

    def DestroyToolTip(self):
        self.toolTip = None

    def OnMouseOverIn(self):
        if self.toolTip:
            self.toolTip.SetTop()
            print(self.itemvnum)
            self.toolTip.SetItemToolTip(self.itemvnum)
            self.toolTip.Show()

    def OnMouseOverOut(self):
        if self.toolTip:
            self.toolTip.Hide()

Step 4: Integrate Tooltip Functionality

Proceed to find the function:

 
def OnSize(self, width, height):
    self.board.SetSize(width, height)

Insert the following method right above it:

 
##[ENABLE_QUEST_SHOWITEMTOOLOIP
def OnInsertImageShowItemToolTip(self, vnum, index=0, total=1):
    import item
    item.SelectItem(vnum)
    filename = item.GetIconImageFileName()
    
    if index == 0:
        event.AddEventSetLocalYPosition(self.descIndex, 24)

    y = event.GetEventSetLocalYPosition(self.descIndex)
    xBoard, yBoard = self.board.GetGlobalPosition()

    try:
        img = ItemToolTipImageBox()
        img.SetParent(self.board)
        img.LoadImage(filename)
        pos_x = (self.board.GetWidth() * (index + 1) / (total + 1)) - (img.GetWidth() / 2)
        img.SetPosition(pos_x, y)
        img.DestroyToolTip()
        img.CreateToolTip(self.board, 0, yBoard + y + img.GetHeight(), vnum)            
        img.Show()
        self.images.append(img)
    except RuntimeError:
        pass
        
    event.AddEventSetLocalYPosition(self.descIndex, img.GetHeight() - 20)
    
    itemname = item.GetItemName()
    
    if itemname:
        if localeInfo.IsARABIC():
            idx = total - 1 - index
            event.AddEventSetLocalYPosition(self.descIndex, 3)
            event.InsertTextInline(self.descIndex, itemname, (self.board.GetWidth() * (idx + 1) / (total + 1)))
            if index != total - 1:
                event.AddEventSetLocalYPosition(self.descIndex, -(3 + 16))
        else:
            event.AddEventSetLocalYPosition(self.descIndex, 3)
            event.InsertTextInline(self.descIndex, itemname, (self.board.GetWidth() * (index + 1) / (total + 1)))
            if index != total - 1:
                event.AddEventSetLocalYPosition(self.descIndex, -(3 + 16))
    else:
        if index == total - 1:
            event.AddEventSetLocalYPosition(self.descIndex, 4)
    
    if index != total - 1:
        event.AddEventSetLocalYPosition(self.descIndex, -(img.GetHeight() - 20))

Step 5: Implement the Script Functionality

Move on to questlib.lua and below the existing function:

 
function say_item_vnum(vnum)
    say_item(item_name(vnum), vnum, "")
end

Add this new function:

 
function say_item_vnum_tooltip(vnum, index, total)
    if index >= total then
        return
    end
    if total > 3 then
        return
    end
    raw_script("[INSERT_IMAGE_SHOW_ITEM_TOOLTIP vnum;" .. vnum .. "|index;" .. index .. "|total;" .. total .. "]")
end

Finally, don’t forget to declare say_item_vnum_tooltip within quest_functions.

Usage Instructions

You can now use the following commands to display items on either side of the interface. Here, "0" and "2" represent the indexes, while "1" is treated as the middle position:

 
say_item_vnum_tooltip(19, 0, 3)
say_item_vnum_tooltip(29, 2, 3)

Conclusion

With these enhancements, players will enjoy a much more engaging experience when interacting with items in quests. If you have any questions or need further assistance, feel free to reach out!

Link to comment
Share on other sites


  • 100% changed the title to OnInsertImageShowItemToolTip For Enhanced Item Interaction

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.

spacer.png

Disable AdBlock
The popup will be closed in 5 seconds...