-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)
|
||||
for k,tab in pairs(self.tabs) do
|
||||
if tab:getText() == text then
|
||||
if tab:getText():lower() == text:lower() then
|
||||
return tab
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,6 +36,12 @@ local SpeakTypes = {
|
|||
[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 consoleBuffer
|
||||
local consoleTabBar
|
||||
|
@ -65,7 +71,7 @@ function Console.create()
|
|||
|
||||
Console.addChannel('Default', 0)
|
||||
Console.addTab('Server Log', false)
|
||||
|
||||
|
||||
Hotkeys.bindKeyDown('Tab', function() consoleTabBar:selectNextTab() end, consolePanel)
|
||||
Hotkeys.bindKeyDown('Shift+Tab', function() consoleTabBar:selectPrevTab() end, consolePanel)
|
||||
Hotkeys.bindKeyDown('Enter', Console.sendCurrentMessage, consolePanel)
|
||||
|
@ -126,14 +132,14 @@ function Console.addChannel(name, id)
|
|||
return tab
|
||||
end
|
||||
|
||||
function Console.addPrivateText(text, speaktype, name)
|
||||
function Console.addPrivateText(text, speaktype, name, isPrivateCommand)
|
||||
if speaktype.speakType == SpeakPrivateNpcToPlayer then
|
||||
name = 'NPCs'
|
||||
end
|
||||
|
||||
local privateTab = Console.getTab(name)
|
||||
if privateTab == nil then
|
||||
if Options.showPrivateMessagesInConsole then
|
||||
if Options.showPrivateMessagesInConsole or (isPrivateCommand and not privateTab) then
|
||||
privateTab = Console.getTab('Default')
|
||||
else
|
||||
privateTab = Console.addTab(name, false)
|
||||
|
@ -145,7 +151,11 @@ end
|
|||
|
||||
function Console.addText(text, speaktype, 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
|
||||
|
||||
function Console.addTabText(text, speaktype, tab)
|
||||
|
@ -172,6 +182,33 @@ function Console.sendCurrentMessage()
|
|||
-- get current channel
|
||||
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
|
||||
local name = tab:getText()
|
||||
if name == 'Server Log' then
|
||||
|
@ -180,9 +217,10 @@ function Console.sendCurrentMessage()
|
|||
end
|
||||
local speaktypedesc
|
||||
|
||||
if tab.channelId then
|
||||
if tab.channelId and not chatCommandPrivate 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
|
||||
speaktypedesc = 'channelYellow'
|
||||
end
|
||||
|
@ -190,21 +228,39 @@ function Console.sendCurrentMessage()
|
|||
Game.talkChannel(SpeakTypesSettings[speaktypedesc].speakType, tab.channelId, message)
|
||||
return
|
||||
else
|
||||
if tab.npcChat then
|
||||
local isPrivateCommand = false
|
||||
if chatCommandPrivate then
|
||||
speaktypedesc = 'privatePlayerToPlayer'
|
||||
name = chatCommandPrivate
|
||||
isPrivateCommand = true
|
||||
elseif tab.npcChat then
|
||||
speaktypedesc = 'privatePlayerToNpc'
|
||||
else
|
||||
speaktypedesc = 'privatePlayerToPlayer'
|
||||
end
|
||||
|
||||
|
||||
local speaktype = SpeakTypesSettings[speaktypedesc]
|
||||
local player = Game.getLocalPlayer()
|
||||
Game.talkPrivate(speaktype.speakType, name, message)
|
||||
|
||||
message = applyMessagePrefixies(player:getName(), player:getLevel(), message)
|
||||
Console.addPrivateText(message, speaktype, name)
|
||||
Console.addPrivateText(message, speaktype, name, isPrivateCommand)
|
||||
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
|
||||
local function onCreatureSpeak(name, level, speaktype, message, channelId, creaturePos)
|
||||
speaktype = SpeakTypes[speaktype]
|
||||
|
@ -213,7 +269,7 @@ local function onCreatureSpeak(name, level, speaktype, message, channelId, creat
|
|||
message = applyMessagePrefixies(name, level, message)
|
||||
|
||||
if speaktype.private then
|
||||
Console.addPrivateText(message, speaktype, name)
|
||||
Console.addPrivateText(message, speaktype, name, false)
|
||||
else
|
||||
Console.addText(message, speaktype, channels[channelId])
|
||||
end
|
||||
|
@ -230,11 +286,9 @@ local function onOpenPrivateChannel(receiver)
|
|||
end
|
||||
end
|
||||
|
||||
local function onChannelList(channelList)
|
||||
local channelsWindow = displayUI('channelswindow.otui')
|
||||
local function doChannelListSubmit(channelsWindow)
|
||||
local channelListPanel = channelsWindow:getChildById('channelList')
|
||||
channelsWindow.onEnter = function(self)
|
||||
local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText()
|
||||
local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText()
|
||||
if openPrivateChannelWith ~= '' then
|
||||
Game.openPrivateChannel(openPrivateChannelWith)
|
||||
else
|
||||
|
@ -242,8 +296,14 @@ local function onChannelList(channelList)
|
|||
if not selectedChannelLabel then return end
|
||||
Game.joinChannel(selectedChannelLabel.channelId)
|
||||
end
|
||||
channelsWindow:destroy()
|
||||
end
|
||||
channelsWindow:destroy()
|
||||
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
|
||||
local channelId = v[1]
|
||||
local channelName = v[2]
|
||||
|
@ -252,6 +312,9 @@ local function onChannelList(channelList)
|
|||
local label = createWidget('ChannelListLabel', channelListPanel)
|
||||
label.channelId = channelId
|
||||
label:setText(channelName)
|
||||
|
||||
label:setPhantom(false)
|
||||
connect(label, { onMouseDoubleClick = function () doChannelListSubmit(channelsWindow) end } )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -74,11 +74,14 @@ Panel
|
|||
ConsoleButton
|
||||
id: sayModeButton
|
||||
icon: /core_styles/icons/say.png
|
||||
tooltip: Adjust volume
|
||||
&sayMode: 2
|
||||
size: 20 20
|
||||
anchors.left: parent.left
|
||||
anchors.bottom: parent.bottom
|
||||
margin-left: 6
|
||||
margin-bottom: 6
|
||||
@onClick: Console.sayModeChange()
|
||||
|
||||
LineEdit
|
||||
id: consoleLineEdit
|
||||
|
|
|
@ -60,10 +60,6 @@ bool UIGame::onKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilter)
|
|||
return true;
|
||||
} else if(wouldFilter) {
|
||||
return false;
|
||||
} else if(keyCode == Fw::KeyReturn || keyCode == Fw::KeyEnter) {
|
||||
g_game.talk(chatLineEdit->getText());
|
||||
chatLineEdit->clearText();
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyDelete) {
|
||||
chatLineEdit->removeCharacter(true);
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue