some chat functionality

This commit is contained in:
Eduardo Bart
2012-01-13 23:37:15 -02:00
parent aae784468b
commit 61aa710d1c
27 changed files with 345 additions and 146 deletions

View File

@@ -0,0 +1,40 @@
ChannelListLabel < Label
font: verdana-11px-monochrome
background-color: alpha
text-offset: 2 0
focusable: true
$focus:
background-color: #ffffff22
color: #ffffff
MainWindow
id: channelsWindow
text: Channels
size: 250 208
@onEscape: self:destroy()
TextList
id: channelList
anchors.fill: parent
anchors.bottom: next.top
margin-bottom: 10
padding: 1
focusable: false
Button
id: buttonOpen
text: Open
width: 64
anchors.right: next.left
anchors.bottom: parent.bottom
margin-right: 10
@onClick: self:getParent():onEnter()
Button
id: buttonCancel
text: Cancel
width: 64
anchors.right: parent.right
anchors.bottom: parent.bottom
@onClick: self:getParent():destroy()

View File

@@ -7,35 +7,51 @@ local SpeakTypes = {
yell = { color = '#FFFF00' },
monsterSay = { color = '#FE6500', hideInConsole = true},
monsterYell = { color = '#FE6500', hideInConsole = true},
npcToPlayer = { color = '#5FF7F7' },
npcToPlayer = { color = '#5FF7F7', private = true, npcChat = true },
channelYellow = { color = '#FFFF00' },
channelWhite = { color = '#FFFFFF' },
channelRed = { color = '#F55E5E' },
channelOrange = { color = '#FE6500' },
private = { color = '#5FF7F7' },
playerToNpc = { color = '#9F9DFD' },
broadcast = { color = '#F55E5E' },
privateRed = { color = '#F55E5E' }
private = { color = '#5FF7F7', private = true },
playerToNpc = { color = '#9F9DFD', private = true, npcChat = true },
broadcast = { color = '#F55E5E', private = true },
privateRed = { color = '#F55E5E', private = true }
}
local consolePanel
local consoleBuffer
local consoleTabBar
local defaultChannelTab
local serverLogTab
local currentTab
local consoleLineEdit
local channels
-- private functions
function applyMessagePrefixies(name, level, message)
if name then
if Options.showLevelsInConsole and level > 0 then
message = name .. ' [' .. level .. ']: ' .. message
else
message = name .. ': ' .. message
end
end
return message
end
-- public functions
function Console.create()
consolePanel = displayUI('console.otui', { parent = Game.gameBottomPanel } )
consoleLineEdit = consolePanel:getChildById('consoleLineEdit')
consoleBuffer = consolePanel:getChildById('consoleBuffer')
consoleTabBar = consolePanel:getChildById('consoleTabBar')
consoleTabBar:setContentWidget(consoleBuffer)
defaultChannelTab = consoleTabBar:addTab('Default')
serverLogTab = consoleTabBar:addTab('Server Log')
channels = {}
Console.addChannel('Default', 0)
Console.addTab('Server Log')
Hotkeys.bind('Tab', function() consoleTabBar:selectNextTab() end, consolePanel)
Hotkeys.bind('Shift+Tab', function() consoleTabBar:selectPrevTab() end, consolePanel)
Hotkeys.bind('Enter', Console.sendCurrentMessage, consolePanel)
Hotkeys.bind('Return', Console.sendCurrentMessage, consolePanel)
end
function Console.destroy()
@@ -43,24 +59,84 @@ function Console.destroy()
consolePanel = nil
end
function Console.addText(text, color, channelTab)
color = color or 'white'
function Console.addTab(name)
local tab = consoleTabBar:addTab(name)
consoleTabBar:selectTab(tab)
return tab
end
function Console.getTab(name)
return consoleTabBar:getTab(name)
end
function Console.getCurrentTab()
return consoleTabBar:getCurrentTab()
end
function Console.addChannel(name, id)
channels[id] = name
local tab = Console.addTab(name)
tab.channelId = id
return tab
end
function Console.addPrivateText(text, speaktype, name)
local privateTab = Console.getTab(name)
if privateTab == nil then
if Options.showPrivateMessagesInConsole then
privateTab = Console.getTab('Default')
else
privateTab = Console.addTab(name)
end
privateTab.npcChat = speaktype.npcChat
end
Console.addTabText(text, speaktype, privateTab)
end
function Console.addText(text, speaktype, tabName)
local tab = Console.getTab(tabName)
Console.addTabText(text, speaktype, tab)
end
function Console.addTabText(text, speaktype, tab)
if Options.showTimestampsInConsole then
text = os.date('%H:%M') .. ' ' .. text
end
local label = createWidget('ConsoleLabel', consoleTabBar:getTabPanel(channelTab))
local label = createWidget('ConsoleLabel', consoleTabBar:getTabPanel(tab))
label:setText(text)
label:setColor(color)
consoleTabBar:blinkTab(channelTab)
label:setColor(speaktype.color)
consoleTabBar:blinkTab(tab)
end
function Console.addChannelMessage(text, color, channel)
if channel == 'Server Log' then
Console.addText(text, color, serverLogTab)
elseif channel == 'Default' then
Console.addText(text, color, defaultChannelTab)
function Console.sendCurrentMessage()
local message = consoleLineEdit:getText()
if #message == 0 then return end
consoleLineEdit:clearText()
local tab = Console.getCurrentTab()
local name = tab:getText()
if name == 'Server Log' then name = 'Default' end
local speaktypedesc = 'say'
if tab.npcChat then
speaktypedesc = 'playerToNpc'
end
if tab.channelId then
if tab.channelId ~= 0 then
speaktypedesc = 'channelYellow'
end
Game.talkChannel(speaktypedesc, tab.channelId, message)
return
else
local speaktype = SpeakTypes[speaktypedesc]
local player = Game.getLocalPlayer()
message = applyMessagePrefixies(player:getName(), player:getLevel(), message)
Console.addPrivateText(message, speaktype, name)
Game.talkPrivate(speaktypedesc, name, message)
end
end
@@ -69,17 +145,44 @@ local function onCreatureSpeak(name, level, speaktypedesc, message, channelId, c
speaktype = SpeakTypes[speaktypedesc]
if speaktype.hideInConsole then return end
if name then
if Options.showLevelsInConsole and level > 0 then
message = name .. ' [' .. level .. ']: ' .. message
else
message = name .. ': ' .. message
message = applyMessagePrefixies(name, level, message)
if speaktype.private then
Console.addPrivateText(message, speaktype, name)
else
Console.addText(message, speaktype, channels[channelId])
end
end
local function onOpenChannel(channelId, channelName)
Console.addChannel(channelName, channelId)
end
local function onChannelList(channelList)
local channelsWindow = displayUI('channelswindow.otui')
local channelListPanel = channelsWindow:getChildById('channelList')
channelsWindow.onEnter = function(self)
local selectedChannelLabel = channelListPanel:getFocusedChild()
if not selectedChannelLabel then return end
--Game.joinChannel(selectedChannelLabel.channelId)
--Console.addChannel(selectedChannelLabel:getText(), selectedChannelLabel .channelId)
channelsWindow:destroy()
end
for k,v in pairs(channelList) do
local channelId = v[1]
local channelName = v[2]
if channelId ~= 0 and #channelName > 0 then
local label = createWidget('ChannelListLabel', channelListPanel)
print(channelId, channelName)
label.channelId = channelId
label:setText(channelName)
end
end
Console.addText(message, speaktype.color, defaultChannelTab)
end
connect(Game, { onLogin = Console.create,
onLogout = Console.destroy,
onCreatureSpeak = onCreatureSpeak})
onCreatureSpeak = onCreatureSpeak,
onChannelList = onChannelList,
onOpenChannel = onOpenChannel})

View File

@@ -34,12 +34,29 @@ Panel
ConsoleButton
id: nextChannelButton
icon: /core_styles/icons/rightarrow.png
anchors.right: parent.right
anchors.right: next.left
anchors.top: parent.top
margin-right: 5
margin-top: 6
enabled: false
ConsoleButton
id: closeChannelButton
icon: /core_styles/icons/closechannel.png
anchors.right: next.left
anchors.top: parent.top
margin-right: 5
margin-top: 6
ConsoleButton
id: channelsButton
icon: /core_styles/icons/channels.png
anchors.right: parent.right
anchors.top: parent.top
margin-right: 5
margin-top: 6
@onClick: Game.requestChannels()
Panel
id: consoleBuffer
anchors.top: prev.bottom