rework on chat functionalities
This commit is contained in:
parent
7bb828faee
commit
84bcdb5f95
|
@ -46,6 +46,16 @@ function UITabBar:addTab(text, panel)
|
||||||
return tab
|
return tab
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function UITabBar:removeTab(tab)
|
||||||
|
local index = table.find(self.tabs, tab)
|
||||||
|
if index == nil then return end
|
||||||
|
if self.currentTab == tab then
|
||||||
|
self:selectPrevTab()
|
||||||
|
end
|
||||||
|
table.remove(self.tabs, index)
|
||||||
|
tab:destroy()
|
||||||
|
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() == text then
|
||||||
|
@ -68,6 +78,7 @@ function UITabBar:selectTab(tab)
|
||||||
if self.currentTab then
|
if self.currentTab then
|
||||||
self.currentTab:setChecked(false)
|
self.currentTab:setChecked(false)
|
||||||
end
|
end
|
||||||
|
signalcall(self.onTabChange, self, tab)
|
||||||
self.currentTab = tab
|
self.currentTab = tab
|
||||||
tab:setChecked(true)
|
tab:setChecked(true)
|
||||||
tab:setOn(false)
|
tab:setOn(false)
|
||||||
|
|
|
@ -11,7 +11,7 @@ ChannelListLabel < Label
|
||||||
MainWindow
|
MainWindow
|
||||||
id: channelsWindow
|
id: channelsWindow
|
||||||
text: Channels
|
text: Channels
|
||||||
size: 250 208
|
size: 250 238
|
||||||
@onEscape: self:destroy()
|
@onEscape: self:destroy()
|
||||||
|
|
||||||
TextList
|
TextList
|
||||||
|
@ -22,6 +22,22 @@ MainWindow
|
||||||
padding: 1
|
padding: 1
|
||||||
focusable: false
|
focusable: false
|
||||||
|
|
||||||
|
LargerLabel
|
||||||
|
id: openPrivateChannelWithLabel
|
||||||
|
text: Open a private message channel:
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.bottom: next.top
|
||||||
|
text-align: center
|
||||||
|
margin-bottom: 2
|
||||||
|
|
||||||
|
LineEdit
|
||||||
|
id: openPrivateChannelWith
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.bottom: next.top
|
||||||
|
margin-bottom: 10
|
||||||
|
|
||||||
Button
|
Button
|
||||||
id: buttonOpen
|
id: buttonOpen
|
||||||
text: Open
|
text: Open
|
||||||
|
|
|
@ -1,21 +1,39 @@
|
||||||
Console = {}
|
Console = {}
|
||||||
|
|
||||||
-- private variables
|
-- private variables
|
||||||
|
local SpeakTypesSettings = {
|
||||||
|
say = { speakType = SpeakSay, color = '#FFFF00' },
|
||||||
|
whisper = { speakType = SpeakWhisper, color = '#FFFF00' },
|
||||||
|
yell = { speakType = SpeakYell, color = '#FFFF00' },
|
||||||
|
broadcast = { speakType = SpeakBroadcast, color = '#F55E5E' },
|
||||||
|
private = { speakType = SpeakPrivate, color = '#5FF7F7', private = true },
|
||||||
|
privateRed = { speakType = SpeakPrivateRed, color = '#F55E5E', private = true },
|
||||||
|
privatePlayerToPlayer = { speakType = SpeakPrivate, color = '#9F9DFD', private = true },
|
||||||
|
privatePlayerToNpc = { speakType = SpeakPrivatePlayerToNpc, color = '#9F9DFD', private = true, npcChat = true },
|
||||||
|
privateNpcToPlayer = { speakType = SpeakPrivateNpcToPlayer, color = '#5FF7F7', private = true, npcChat = true },
|
||||||
|
channelYellow = { speakType = SpeakChannelYellow, color = '#FFFF00' },
|
||||||
|
channelWhite = { speakType = SpeakChannelWhite, color = '#FFFFFF' },
|
||||||
|
channelRed = { speakType = SpeakChannelRed, color = '#F55E5E' },
|
||||||
|
channelOrange = { speakType = SpeakChannelOrange, color = '#FE6500' },
|
||||||
|
monsterSay = { speakType = SpeakMonsterSay, color = '#FE6500', hideInConsole = true},
|
||||||
|
monsterYell = { speakType = SpeakMonsterYell, color = '#FE6500', hideInConsole = true},
|
||||||
|
}
|
||||||
|
|
||||||
local SpeakTypes = {
|
local SpeakTypes = {
|
||||||
say = { color = '#FFFF00' },
|
[SpeakSay] = SpeakTypesSettings.say,
|
||||||
whisper = { color = '#FFFF00' },
|
[SpeakWhisper] = SpeakTypesSettings.whisper,
|
||||||
yell = { color = '#FFFF00' },
|
[SpeakYell] = SpeakTypesSettings.yell,
|
||||||
monsterSay = { color = '#FE6500', hideInConsole = true},
|
[SpeakBroadcast] = SpeakTypesSettings.broadcast,
|
||||||
monsterYell = { color = '#FE6500', hideInConsole = true},
|
[SpeakPrivate] = SpeakTypesSettings.private,
|
||||||
npcToPlayer = { color = '#5FF7F7', private = true, npcChat = true },
|
[SpeakPrivateRed] = SpeakTypesSettings.privateRed,
|
||||||
channelYellow = { color = '#FFFF00' },
|
[SpeakPrivatePlayerToNpc] = SpeakTypesSettings.privatePlayerToNpc,
|
||||||
channelWhite = { color = '#FFFFFF' },
|
[SpeakPrivateNpcToPlayer] = SpeakTypesSettings.privateNpcToPlayer,
|
||||||
channelRed = { color = '#F55E5E' },
|
[SpeakChannelYellow] = SpeakTypesSettings.channelYellow,
|
||||||
channelOrange = { color = '#FE6500' },
|
[SpeakChannelWhite] = SpeakTypesSettings.channelWhite,
|
||||||
private = { color = '#5FF7F7', private = true },
|
[SpeakChannelRed] = SpeakTypesSettings.channelRed,
|
||||||
playerToNpc = { color = '#9F9DFD', private = true, npcChat = true },
|
[SpeakChannelOrange] = SpeakTypesSettings.channelOrange,
|
||||||
broadcast = { color = '#F55E5E' },
|
[SpeakMonsterSay] = SpeakTypesSettings.monsterSay,
|
||||||
privateRed = { color = '#F55E5E', private = true }
|
[SpeakMonsterYell] = SpeakTypesSettings.monsterYell,
|
||||||
}
|
}
|
||||||
|
|
||||||
local consolePanel
|
local consolePanel
|
||||||
|
@ -46,12 +64,22 @@ function Console.create()
|
||||||
channels = {}
|
channels = {}
|
||||||
|
|
||||||
Console.addChannel('Default', 0)
|
Console.addChannel('Default', 0)
|
||||||
Console.addTab('Server Log')
|
Console.addTab('Server Log', false)
|
||||||
|
|
||||||
Hotkeys.bindKeyDown('Tab', function() consoleTabBar:selectNextTab() end, consolePanel)
|
Hotkeys.bindKeyDown('Tab', function() consoleTabBar:selectNextTab() end, consolePanel)
|
||||||
Hotkeys.bindKeyDown('Shift+Tab', function() consoleTabBar:selectPrevTab() end, consolePanel)
|
Hotkeys.bindKeyDown('Shift+Tab', function() consoleTabBar:selectPrevTab() end, consolePanel)
|
||||||
Hotkeys.bindKeyDown('Enter', Console.sendCurrentMessage, consolePanel)
|
Hotkeys.bindKeyDown('Enter', Console.sendCurrentMessage, consolePanel)
|
||||||
Hotkeys.bindKeyDown('Return', Console.sendCurrentMessage, consolePanel)
|
Hotkeys.bindKeyDown('Return', Console.sendCurrentMessage, consolePanel)
|
||||||
|
|
||||||
|
--Apply buttom functions after loaded
|
||||||
|
consolePanel:getChildById('nextChannelButton').onClick = function() consoleTabBar:selectNextTab() end
|
||||||
|
consolePanel:getChildById('prevChannelButton').onClick = function() consoleTabBar:selectPrevTab() end
|
||||||
|
|
||||||
|
--Tibia Like Hotkeys
|
||||||
|
Hotkeys.bindKeyDown('Ctrl+O', Game.requestChannels)
|
||||||
|
Hotkeys.bindKeyDown('Ctrl+E', Console.removeCurrentTab)
|
||||||
|
|
||||||
|
connect(consoleTabBar, { onTabChange = Console.onTabChange })
|
||||||
end
|
end
|
||||||
|
|
||||||
function Console.destroy()
|
function Console.destroy()
|
||||||
|
@ -59,12 +87,31 @@ function Console.destroy()
|
||||||
consolePanel = nil
|
consolePanel = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function Console.addTab(name)
|
function Console.addTab(name, focus)
|
||||||
local tab = consoleTabBar:addTab(name)
|
local tab = consoleTabBar:addTab(name)
|
||||||
consoleTabBar:selectTab(tab)
|
if focus then
|
||||||
|
consoleTabBar:selectTab(tab)
|
||||||
|
else
|
||||||
|
consoleTabBar:blinkTab(tab)
|
||||||
|
end
|
||||||
return tab
|
return tab
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Console.onTabChange(tabBar, tab)
|
||||||
|
if tab:getText() == "Default" or tab:getText() == "Server Log" then
|
||||||
|
consolePanel:getChildById('closeChannelButton'):disable()
|
||||||
|
else
|
||||||
|
consolePanel:getChildById('closeChannelButton'):enable()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Console.removeCurrentTab()
|
||||||
|
local tab = consoleTabBar:getCurrentTab()
|
||||||
|
if tab:getText() == "Default" or tab:getText() == "Server Log" then return end
|
||||||
|
|
||||||
|
consoleTabBar:removeTab(tab)
|
||||||
|
end
|
||||||
|
|
||||||
function Console.getTab(name)
|
function Console.getTab(name)
|
||||||
return consoleTabBar:getTab(name)
|
return consoleTabBar:getTab(name)
|
||||||
end
|
end
|
||||||
|
@ -75,7 +122,7 @@ end
|
||||||
|
|
||||||
function Console.addChannel(name, id)
|
function Console.addChannel(name, id)
|
||||||
channels[id] = name
|
channels[id] = name
|
||||||
local tab = Console.addTab(name)
|
local tab = Console.addTab(name, true)
|
||||||
tab.channelId = id
|
tab.channelId = id
|
||||||
return tab
|
return tab
|
||||||
end
|
end
|
||||||
|
@ -86,7 +133,7 @@ function Console.addPrivateText(text, speaktype, name)
|
||||||
if Options.showPrivateMessagesInConsole then
|
if Options.showPrivateMessagesInConsole then
|
||||||
privateTab = Console.getTab('Default')
|
privateTab = Console.getTab('Default')
|
||||||
else
|
else
|
||||||
privateTab = Console.addTab(name)
|
privateTab = Console.addTab(name, false)
|
||||||
end
|
end
|
||||||
privateTab.npcChat = speaktype.npcChat
|
privateTab.npcChat = speaktype.npcChat
|
||||||
end
|
end
|
||||||
|
@ -137,18 +184,18 @@ function Console.sendCurrentMessage()
|
||||||
speaktypedesc = 'channelYellow'
|
speaktypedesc = 'channelYellow'
|
||||||
end
|
end
|
||||||
|
|
||||||
Game.talkChannel(speaktypedesc, tab.channelId, message)
|
Game.talkChannel(SpeakTypesSettings[speaktypedesc].speakType, tab.channelId, message)
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
if tab.npcChat then
|
if tab.npcChat then
|
||||||
speaktypedesc = 'playerToNpc'
|
speaktypedesc = 'privatePlayerToNpc'
|
||||||
else
|
else
|
||||||
speaktypedesc = 'private'
|
speaktypedesc = 'privatePlayerToPlayer'
|
||||||
end
|
end
|
||||||
|
|
||||||
local speaktype = SpeakTypes[speaktypedesc]
|
local speaktype = SpeakTypesSettings[speaktypedesc]
|
||||||
local player = Game.getLocalPlayer()
|
local player = Game.getLocalPlayer()
|
||||||
Game.talkPrivate(speaktypedesc, 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)
|
||||||
|
@ -156,8 +203,8 @@ function Console.sendCurrentMessage()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- hooked events
|
-- hooked events
|
||||||
local function onCreatureSpeak(name, level, speaktypedesc, message, channelId, creaturePos)
|
local function onCreatureSpeak(name, level, speaktype, message, channelId, creaturePos)
|
||||||
speaktype = SpeakTypes[speaktypedesc]
|
speaktype = SpeakTypes[speaktype]
|
||||||
if speaktype.hideInConsole then return end
|
if speaktype.hideInConsole then return end
|
||||||
|
|
||||||
message = applyMessagePrefixies(name, level, message)
|
message = applyMessagePrefixies(name, level, message)
|
||||||
|
@ -173,13 +220,25 @@ local function onOpenChannel(channelId, channelName)
|
||||||
Console.addChannel(channelName, channelId)
|
Console.addChannel(channelName, channelId)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function onOpenPrivateChannel(receiver)
|
||||||
|
local privateTab = Console.getTab(receiver)
|
||||||
|
if privateTab == nil then
|
||||||
|
Console.addTab(receiver, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function onChannelList(channelList)
|
local function onChannelList(channelList)
|
||||||
local channelsWindow = displayUI('channelswindow.otui')
|
local channelsWindow = displayUI('channelswindow.otui')
|
||||||
local channelListPanel = channelsWindow:getChildById('channelList')
|
local channelListPanel = channelsWindow:getChildById('channelList')
|
||||||
channelsWindow.onEnter = function(self)
|
channelsWindow.onEnter = function(self)
|
||||||
local selectedChannelLabel = channelListPanel:getFocusedChild()
|
local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText()
|
||||||
if not selectedChannelLabel then return end
|
if openPrivateChannelWith ~= '' then
|
||||||
Game.joinChannel(selectedChannelLabel.channelId)
|
Game.openPrivateChannel(openPrivateChannelWith)
|
||||||
|
else
|
||||||
|
local selectedChannelLabel = channelListPanel:getFocusedChild()
|
||||||
|
if not selectedChannelLabel then return end
|
||||||
|
Game.joinChannel(selectedChannelLabel.channelId)
|
||||||
|
end
|
||||||
channelsWindow:destroy()
|
channelsWindow:destroy()
|
||||||
end
|
end
|
||||||
for k,v in pairs(channelList) do
|
for k,v in pairs(channelList) do
|
||||||
|
@ -198,4 +257,5 @@ connect(Game, { onLogin = Console.create,
|
||||||
onLogout = Console.destroy,
|
onLogout = Console.destroy,
|
||||||
onCreatureSpeak = onCreatureSpeak,
|
onCreatureSpeak = onCreatureSpeak,
|
||||||
onChannelList = onChannelList,
|
onChannelList = onChannelList,
|
||||||
onOpenChannel = onOpenChannel})
|
onOpenChannel = onOpenChannel,
|
||||||
|
onOpenPrivateChannel = onOpenPrivateChannel})
|
|
@ -21,7 +21,6 @@ Panel
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
margin-left: 6
|
margin-left: 6
|
||||||
margin-top: 6
|
margin-top: 6
|
||||||
enabled: false
|
|
||||||
|
|
||||||
ConsoleTabBar
|
ConsoleTabBar
|
||||||
id: consoleTabBar
|
id: consoleTabBar
|
||||||
|
@ -38,18 +37,21 @@ Panel
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
margin-right: 5
|
margin-right: 5
|
||||||
margin-top: 6
|
margin-top: 6
|
||||||
enabled: false
|
|
||||||
|
|
||||||
ConsoleButton
|
ConsoleButton
|
||||||
id: closeChannelButton
|
id: closeChannelButton
|
||||||
|
tooltip: Close this channel (Ctrl+E)
|
||||||
icon: /core_styles/icons/closechannel.png
|
icon: /core_styles/icons/closechannel.png
|
||||||
anchors.right: next.left
|
anchors.right: next.left
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
|
enabled: false
|
||||||
margin-right: 5
|
margin-right: 5
|
||||||
margin-top: 6
|
margin-top: 6
|
||||||
|
@onClick: Console.removeCurrentTab()
|
||||||
|
|
||||||
ConsoleButton
|
ConsoleButton
|
||||||
id: channelsButton
|
id: channelsButton
|
||||||
|
tooltip: Open new channel (Ctrl+O)
|
||||||
icon: /core_styles/icons/channels.png
|
icon: /core_styles/icons/channels.png
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
|
|
Loading…
Reference in New Issue