-add tibia chat commands like #w, #y and private command.
-fixed redundant onEnter/onReturn on chat panel
This commit is contained in:
parent
882b7ec026
commit
1615bf7a36
|
@ -58,7 +58,7 @@ end
|
||||||
|
|
||||||
function UITabBar:getTab(text)
|
function UITabBar:getTab(text)
|
||||||
for k,tab in pairs(self.tabs) do
|
for k,tab in pairs(self.tabs) do
|
||||||
if tab:getText() == text then
|
if tab:getText():lower() == text:lower() then
|
||||||
return tab
|
return tab
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,6 +36,12 @@ local SpeakTypes = {
|
||||||
[SpeakMonsterYell] = SpeakTypesSettings.monsterYell,
|
[SpeakMonsterYell] = SpeakTypesSettings.monsterYell,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local SayModes = {
|
||||||
|
[1] = { speakTypeDesc = 'whisper', icon = '/core_styles/icons/whisper.png' },
|
||||||
|
[2] = { speakTypeDesc = 'say', icon = '/core_styles/icons/say.png' },
|
||||||
|
[3] = { speakTypeDesc = 'yell', icon = '/core_styles/icons/yell.png' }
|
||||||
|
}
|
||||||
|
|
||||||
local consolePanel
|
local consolePanel
|
||||||
local consoleBuffer
|
local consoleBuffer
|
||||||
local consoleTabBar
|
local consoleTabBar
|
||||||
|
@ -126,14 +132,14 @@ function Console.addChannel(name, id)
|
||||||
return tab
|
return tab
|
||||||
end
|
end
|
||||||
|
|
||||||
function Console.addPrivateText(text, speaktype, name)
|
function Console.addPrivateText(text, speaktype, name, isPrivateCommand)
|
||||||
if speaktype.speakType == SpeakPrivateNpcToPlayer then
|
if speaktype.speakType == SpeakPrivateNpcToPlayer then
|
||||||
name = 'NPCs'
|
name = 'NPCs'
|
||||||
end
|
end
|
||||||
|
|
||||||
local privateTab = Console.getTab(name)
|
local privateTab = Console.getTab(name)
|
||||||
if privateTab == nil then
|
if privateTab == nil then
|
||||||
if Options.showPrivateMessagesInConsole then
|
if Options.showPrivateMessagesInConsole or (isPrivateCommand and not privateTab) then
|
||||||
privateTab = Console.getTab('Default')
|
privateTab = Console.getTab('Default')
|
||||||
else
|
else
|
||||||
privateTab = Console.addTab(name, false)
|
privateTab = Console.addTab(name, false)
|
||||||
|
@ -145,7 +151,11 @@ end
|
||||||
|
|
||||||
function Console.addText(text, speaktype, tabName)
|
function Console.addText(text, speaktype, tabName)
|
||||||
local tab = Console.getTab(tabName)
|
local tab = Console.getTab(tabName)
|
||||||
Console.addTabText(text, speaktype, tab)
|
if tab ~= nil then
|
||||||
|
Console.addTabText(text, speaktype, tab)
|
||||||
|
else
|
||||||
|
print("Error","Trying to addText on tabName: " .. tabName)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Console.addTabText(text, speaktype, tab)
|
function Console.addTabText(text, speaktype, tab)
|
||||||
|
@ -172,6 +182,33 @@ function Console.sendCurrentMessage()
|
||||||
-- get current channel
|
-- get current channel
|
||||||
local tab = Console.getCurrentTab()
|
local tab = Console.getCurrentTab()
|
||||||
|
|
||||||
|
-- handling chat commands
|
||||||
|
local chatCommandSayMode
|
||||||
|
local chatCommandPrivate
|
||||||
|
|
||||||
|
local chatCommandMessage = message:match("^%#y (.*)")
|
||||||
|
if chatCommandMessage ~= nil then chatCommandSayMode = 'yell' end -- player used yell command
|
||||||
|
message = chatCommandMessage or message
|
||||||
|
|
||||||
|
local chatCommandMessage = message:match("^%#w (.*)")
|
||||||
|
if chatCommandMessage ~= nil then chatCommandSayMode = 'whisper' end -- player used whisper
|
||||||
|
message = chatCommandMessage or message
|
||||||
|
|
||||||
|
local findIni, findEnd, chatCommandInitial, chatCommandPrivate, chatCommandEnd, chatCommandMessage = message:find("([%*%@])(.+)([%*%@])(.*)")
|
||||||
|
if findIni ~= nil and findIni == 1 then -- player used private chat command
|
||||||
|
if chatCommandInitial == chatCommandEnd then
|
||||||
|
chatCommandPrivateRepeat = false
|
||||||
|
if chatCommandInitial == "*" then
|
||||||
|
consoleLineEdit:setText('*'.. chatCommandPrivate .. '* ')
|
||||||
|
end
|
||||||
|
chatCommandPrivate = chatCommandPrivate
|
||||||
|
message = chatCommandMessage:trim()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
message = message:gsub("^(%s*)(.*)","%2") -- remove space characters from message init
|
||||||
|
if #message == 0 then return end
|
||||||
|
|
||||||
-- when talking on server log, the message goes to default channel
|
-- when talking on server log, the message goes to default channel
|
||||||
local name = tab:getText()
|
local name = tab:getText()
|
||||||
if name == 'Server Log' then
|
if name == 'Server Log' then
|
||||||
|
@ -180,9 +217,10 @@ function Console.sendCurrentMessage()
|
||||||
end
|
end
|
||||||
local speaktypedesc
|
local speaktypedesc
|
||||||
|
|
||||||
if tab.channelId then
|
if tab.channelId and not chatCommandPrivate then
|
||||||
if tab.channelId == 0 then
|
if tab.channelId == 0 then
|
||||||
speaktypedesc = 'say'
|
speaktypedesc = chatCommandSayMode or SayModes[consolePanel:getChildById('sayModeButton').sayMode].speakTypeDesc
|
||||||
|
if speaktypedesc ~= 'say' then Console.sayModeChange(2) end -- head back to say mode
|
||||||
else
|
else
|
||||||
speaktypedesc = 'channelYellow'
|
speaktypedesc = 'channelYellow'
|
||||||
end
|
end
|
||||||
|
@ -190,21 +228,39 @@ function Console.sendCurrentMessage()
|
||||||
Game.talkChannel(SpeakTypesSettings[speaktypedesc].speakType, tab.channelId, message)
|
Game.talkChannel(SpeakTypesSettings[speaktypedesc].speakType, tab.channelId, message)
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
if tab.npcChat then
|
local isPrivateCommand = false
|
||||||
|
if chatCommandPrivate then
|
||||||
|
speaktypedesc = 'privatePlayerToPlayer'
|
||||||
|
name = chatCommandPrivate
|
||||||
|
isPrivateCommand = true
|
||||||
|
elseif tab.npcChat then
|
||||||
speaktypedesc = 'privatePlayerToNpc'
|
speaktypedesc = 'privatePlayerToNpc'
|
||||||
else
|
else
|
||||||
speaktypedesc = 'privatePlayerToPlayer'
|
speaktypedesc = 'privatePlayerToPlayer'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local speaktype = SpeakTypesSettings[speaktypedesc]
|
local speaktype = SpeakTypesSettings[speaktypedesc]
|
||||||
local player = Game.getLocalPlayer()
|
local player = Game.getLocalPlayer()
|
||||||
Game.talkPrivate(speaktype.speakType, name, message)
|
Game.talkPrivate(speaktype.speakType, name, message)
|
||||||
|
|
||||||
message = applyMessagePrefixies(player:getName(), player:getLevel(), message)
|
message = applyMessagePrefixies(player:getName(), player:getLevel(), message)
|
||||||
Console.addPrivateText(message, speaktype, name)
|
Console.addPrivateText(message, speaktype, name, isPrivateCommand)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Console.sayModeChange(sayMode)
|
||||||
|
local buttom = consolePanel:getChildById('sayModeButton')
|
||||||
|
if sayMode == nil then
|
||||||
|
sayMode = buttom.sayMode + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if sayMode > #SayModes then sayMode = 1 end
|
||||||
|
|
||||||
|
buttom:setIcon(SayModes[sayMode].icon)
|
||||||
|
buttom.sayMode = sayMode
|
||||||
|
end
|
||||||
|
|
||||||
-- hooked events
|
-- hooked events
|
||||||
local function onCreatureSpeak(name, level, speaktype, message, channelId, creaturePos)
|
local function onCreatureSpeak(name, level, speaktype, message, channelId, creaturePos)
|
||||||
speaktype = SpeakTypes[speaktype]
|
speaktype = SpeakTypes[speaktype]
|
||||||
|
@ -213,7 +269,7 @@ local function onCreatureSpeak(name, level, speaktype, message, channelId, creat
|
||||||
message = applyMessagePrefixies(name, level, message)
|
message = applyMessagePrefixies(name, level, message)
|
||||||
|
|
||||||
if speaktype.private then
|
if speaktype.private then
|
||||||
Console.addPrivateText(message, speaktype, name)
|
Console.addPrivateText(message, speaktype, name, false)
|
||||||
else
|
else
|
||||||
Console.addText(message, speaktype, channels[channelId])
|
Console.addText(message, speaktype, channels[channelId])
|
||||||
end
|
end
|
||||||
|
@ -230,11 +286,9 @@ local function onOpenPrivateChannel(receiver)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onChannelList(channelList)
|
local function doChannelListSubmit(channelsWindow)
|
||||||
local channelsWindow = displayUI('channelswindow.otui')
|
|
||||||
local channelListPanel = channelsWindow:getChildById('channelList')
|
local channelListPanel = channelsWindow:getChildById('channelList')
|
||||||
channelsWindow.onEnter = function(self)
|
local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText()
|
||||||
local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText()
|
|
||||||
if openPrivateChannelWith ~= '' then
|
if openPrivateChannelWith ~= '' then
|
||||||
Game.openPrivateChannel(openPrivateChannelWith)
|
Game.openPrivateChannel(openPrivateChannelWith)
|
||||||
else
|
else
|
||||||
|
@ -242,8 +296,14 @@ local function onChannelList(channelList)
|
||||||
if not selectedChannelLabel then return end
|
if not selectedChannelLabel then return end
|
||||||
Game.joinChannel(selectedChannelLabel.channelId)
|
Game.joinChannel(selectedChannelLabel.channelId)
|
||||||
end
|
end
|
||||||
channelsWindow:destroy()
|
channelsWindow:destroy()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function onChannelList(channelList)
|
||||||
|
local channelsWindow = displayUI('channelswindow.otui')
|
||||||
|
local channelListPanel = channelsWindow:getChildById('channelList')
|
||||||
|
connect(channelsWindow, { onEnter = function () doChannelListSubmit(channelsWindow) end } )
|
||||||
|
|
||||||
for k,v in pairs(channelList) do
|
for k,v in pairs(channelList) do
|
||||||
local channelId = v[1]
|
local channelId = v[1]
|
||||||
local channelName = v[2]
|
local channelName = v[2]
|
||||||
|
@ -252,6 +312,9 @@ local function onChannelList(channelList)
|
||||||
local label = createWidget('ChannelListLabel', channelListPanel)
|
local label = createWidget('ChannelListLabel', channelListPanel)
|
||||||
label.channelId = channelId
|
label.channelId = channelId
|
||||||
label:setText(channelName)
|
label:setText(channelName)
|
||||||
|
|
||||||
|
label:setPhantom(false)
|
||||||
|
connect(label, { onMouseDoubleClick = function () doChannelListSubmit(channelsWindow) end } )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -74,11 +74,14 @@ Panel
|
||||||
ConsoleButton
|
ConsoleButton
|
||||||
id: sayModeButton
|
id: sayModeButton
|
||||||
icon: /core_styles/icons/say.png
|
icon: /core_styles/icons/say.png
|
||||||
|
tooltip: Adjust volume
|
||||||
|
&sayMode: 2
|
||||||
size: 20 20
|
size: 20 20
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
margin-left: 6
|
margin-left: 6
|
||||||
margin-bottom: 6
|
margin-bottom: 6
|
||||||
|
@onClick: Console.sayModeChange()
|
||||||
|
|
||||||
LineEdit
|
LineEdit
|
||||||
id: consoleLineEdit
|
id: consoleLineEdit
|
||||||
|
|
|
@ -60,10 +60,6 @@ bool UIGame::onKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilter)
|
||||||
return true;
|
return true;
|
||||||
} else if(wouldFilter) {
|
} else if(wouldFilter) {
|
||||||
return false;
|
return false;
|
||||||
} else if(keyCode == Fw::KeyReturn || keyCode == Fw::KeyEnter) {
|
|
||||||
g_game.talk(chatLineEdit->getText());
|
|
||||||
chatLineEdit->clearText();
|
|
||||||
return true;
|
|
||||||
} else if(keyCode == Fw::KeyDelete) {
|
} else if(keyCode == Fw::KeyDelete) {
|
||||||
chatLineEdit->removeCharacter(true);
|
chatLineEdit->removeCharacter(true);
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue