Hundanger
Member
Hello there,
I would like to install in otclient the same functionality that exists in global tibia in which the player "clicks" on the highlighted word of the npcs, example:
When the play click on the word "records" the creature automaticaly says "records" in this channel, facilitating interaction.
I've been looking and in the console.lua class of the game_console module of otclient has this code:
Here it transforms all words that start with {and end with} into highlighted words in color #1f9ffe
further down it has this function:
The only possible logic I thought was:
calculate the position of the screen where each highlighted word starts and ends and do an if in onMousePress with parameter mousePos.
Do you know any easier way to do this? I looked like hell and didn't find it.
Thank you guys,
I would like to install in otclient the same functionality that exists in global tibia in which the player "clicks" on the highlighted word of the npcs, example:
When the play click on the word "records" the creature automaticaly says "records" in this channel, facilitating interaction.
I've been looking and in the console.lua class of the game_console module of otclient has this code:
Lua:
if speaktype.npcChat and (g_game.getCharacterName() ~= creatureName or g_game.getCharacterName() == 'Account Manager') then
local highlightData = getHighlightedText(text)
if #highlightData > 0 then
local labelHighlight = g_ui.createWidget('ConsolePhantomLabel', label)
labelHighlight:fill('parent')
labelHighlight:setId('consoleLabelHighlight' .. consoleBuffer:getChildCount())
labelHighlight:setColor("#1f9ffe")
-- Remove the curly braces
for i = 1, #highlightData / 3 do
local dataBlock = { _start = highlightData[(i-1)*3+1], _end = highlightData[(i-1)*3+2], words = highlightData[(i-1)*3+3] }
text = text:gsub("%{(.-)%}", dataBlock.words, 1)
-- Recalculate positions as braces are removed
highlightData[(i-1)*3+1] = dataBlock._start - ((i-1) * 2)
highlightData[(i-1)*3+2] = dataBlock._end - (1 + (i-1) * 2)
end
label:setText(text)
-- Calculate the positions of the highlighted text and fill with string.char(127) [Width: 1]
local drawText = label:getDrawText()
local tmpText = ""
for i = 1, #highlightData / 3 do
local dataBlock = { _start = highlightData[(i-1)*3+1], _end = highlightData[(i-1)*3+2], words = highlightData[(i-1)*3+3] }
local lastBlockEnd = (highlightData[(i-2)*3+2] or 1)
for letter = lastBlockEnd, dataBlock._start-1 do
local tmpChar = string.byte(drawText:sub(letter, letter))
local fillChar = (tmpChar == 10 or tmpChar == 32) and string.char(tmpChar) or string.char(127)
tmpText = tmpText .. string.rep(fillChar, letterWidth[tmpChar])
end
tmpText = tmpText .. dataBlock.words
end
-- Fill the highlight label to the same size as default label
local finalBlockEnd = (highlightData[(#highlightData/3-1)*3+2] or 1)
for letter = finalBlockEnd, drawText:len() do
local tmpChar = string.byte(drawText:sub(letter, letter))
local fillChar = (tmpChar == 10 or tmpChar == 32) and string.char(tmpChar) or string.char(127)
tmpText = tmpText .. string.rep(fillChar, letterWidth[tmpChar])
end
labelHighlight:setText(tmpText)
end
end
Here it transforms all words that start with {and end with} into highlighted words in color #1f9ffe
further down it has this function:
Lua:
label.onMousePress = function(self, mousePos, button)
if button == MouseLeftButton then clearSelection(consoleBuffer) end
end
The only possible logic I thought was:
calculate the position of the screen where each highlighted word starts and ends and do an if in onMousePress with parameter mousePos.
Do you know any easier way to do this? I looked like hell and didn't find it.
Thank you guys,
Attachments
-
1609987491197.png40 KB · Views: 12 · VirusTotal