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

@@ -1,18 +0,0 @@
MapEffects = {}
function MapEffects.init()
--[[
local box = createWidget('ComboBox', 'leftButtonsPanel')
box:addAnchor(AnchorLeft, 'prev', AnchorRight)
box:addAnchor(AnchorTop, 'parent', AnchorTop)
box:setMargin(6, 6)
box:addOption('Normal')
box:addOption('Bloom')
box:addOption('TV')
displayUI(box)
]]--
end
function MapEffects.terminate()
end

View File

@@ -1,16 +0,0 @@
Module
name: mapeffects
description: Contains experimental shader effects for map
author: OTClient team
website: https://github.com/edubart/otclient
// console can be loaded after core
autoLoad: true
autoLoadPriority: 1000
onLoad: |
require 'mapeffects'
MapEffects.init()
onUnload: |
MapEffects.terminate()

View File

@@ -5,7 +5,7 @@ Module
website: https://github.com/edubart/otclient
autoLoad: true
autoLoadPriority: 1000
autoLoadAntecedence: 1000
onLoad: |
require 'pingbar'

View File

@@ -1,7 +1,7 @@
Module
name: playground
autoLoad: true
autoLoadPriority: 1000
autoLoadAntecedence: 1000
onLoad: |
require 'playground'

View File

@@ -5,7 +5,7 @@ Module
website: https://github.com/edubart/otclient
autoLoad: true
autoLoadPriority: 200
autoLoadAntecedence: 200
onLoad: |
require 'terminal'

View File

@@ -16,7 +16,7 @@ OptionCheckBox < CheckBox
MainWindow
id: optionsWindow
text: Options
size: 286 230
size: 286 250
@onEnter: Options.hide()
@onEscape: Options.hide()
@@ -58,9 +58,9 @@ MainWindow
id: showLevelsInConsole
text: Show levels in console
//OptionCheckBox
// id: showPrivateMessagesInConsole
// text: Show private messages in console
OptionCheckBox
id: showPrivateMessagesInConsole
text: Show private messages in console
Button
text: Ok

View File

@@ -6,7 +6,7 @@ Module
// core must be loaded before other modules
autoLoad: true
autoLoadPriority: 10
autoLoadAntecedence: 10
// NOTE: order does matter
dependencies:

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 300 B

View File

@@ -1,14 +1,14 @@
UITabBar = extends(UIWidget)
-- private functions
local function onTabClick(tabButton)
tabButton.tabBar:selectTab(tabButton)
local function onTabClick(tab)
tab.tabBar:selectTab(tab)
end
local function tabBlink(tabButton)
if not tabButton.blinking then return end
tabButton:setOn(not tabButton:isOn())
scheduleEvent(function() tabBlink(tabButton) end, 500)
local function tabBlink(tab)
if not tab.blinking then return end
tab:setOn(not tab:isOn())
scheduleEvent(function() tabBlink(tab) end, 500)
end
-- public functions
@@ -31,44 +31,52 @@ function UITabBar:addTab(text, panel)
panel = createWidget(self:getStyleName() .. 'Panel')
end
local tabButton = createWidget(self:getStyleName() .. 'Button', self)
tabButton.tabPanel = panel
tabButton.tabBar = self
tabButton:setText(text)
tabButton:setWidth(tabButton:getTextSize().width + tabButton:getPaddingLeft() + tabButton:getPaddingRight())
connect(tabButton, { onClick = onTabClick })
local tab = createWidget(self:getStyleName() .. 'Button', self)
tab.tabPanel = panel
tab.tabBar = self
tab:setText(text)
tab:setWidth(tab:getTextSize().width + tab:getPaddingLeft() + tab:getPaddingRight())
connect(tab, { onClick = onTabClick })
table.insert(self.tabs, tabButton)
table.insert(self.tabs, tab)
if #self.tabs == 1 then
self:selectTab(tabButton)
self:selectTab(tab)
end
return tabButton
return tab
end
function UITabBar:selectTab(tabButton)
if self.currentTabButton == tabButton then return end
function UITabBar:getTab(text)
for k,tab in pairs(self.tabs) do
if tab:getText() == text then
return tab
end
end
end
function UITabBar:selectTab(tab)
if self.currentTab == tab then return end
if self.contentWidget then
local selectedWidget = self.contentWidget:getFirstChild()
if selectedWidget then
self.contentWidget:removeChild(selectedWidget)
end
self.contentWidget:addChild(tabButton.tabPanel)
tabButton.tabPanel:fill('parent')
self.contentWidget:addChild(tab.tabPanel)
tab.tabPanel:fill('parent')
end
if self.currentTabButton then
self.currentTabButton:setChecked(false)
if self.currentTab then
self.currentTab:setChecked(false)
end
self.currentTabButton = tabButton
tabButton:setChecked(true)
tabButton:setOn(false)
tabButton.blinking = false
self.currentTab = tab
tab:setChecked(true)
tab:setOn(false)
tab.blinking = false
end
function UITabBar:selectNextTab()
if self.currentTabButton == nil then return end
local index = table.find(self.tabs, self.currentTabButton)
if self.currentTab == nil then return end
local index = table.find(self.tabs, self.currentTab)
if index == nil then return end
local nextTab = self.tabs[index + 1] or self.tabs[1]
if not nextTab then return end
@@ -76,26 +84,30 @@ function UITabBar:selectNextTab()
end
function UITabBar:selectPrevTab()
if self.currentTabButton == nil then return end
local index = table.find(self.tabs, self.currentTabButton)
if self.currentTab == nil then return end
local index = table.find(self.tabs, self.currentTab)
if index == nil then return end
local prevTab = self.tabs[index - 1] or self.tabs[#self.tabs]
if not prevTab then return end
self:selectTab(prevTab)
end
function UITabBar:blinkTab(tabButton)
if tabButton:isChecked() or tabButton.blinking then return end
tabButton.blinking = true
tabBlink(tabButton)
function UITabBar:blinkTab(tab)
if tab:isChecked() or tab.blinking then return end
tab.blinking = true
tabBlink(tab)
end
function UITabBar:getTabPanel(tabButton)
return tabButton.tabPanel
function UITabBar:getTabPanel(tab)
return tab.tabPanel
end
function UITabBar:getCurrentTabPanel()
if self.currentTabButton then
return self.currentTabButton.tabPanel
if self.currentTab then
return self.currentTab.tabPanel
end
end
function UITabBar:getCurrentTab()
return self.currentTab
end

View File

@@ -133,7 +133,7 @@ function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
menu:addSeparator()
if creatureThing:asLocalPlayer() then
menu:addOption('Set Outfit', function() Game.openOutfitWindow() end)
menu:addOption('Set Outfit', function() Game.requestOutfit() end)
if creatureThing:asPlayer():isPartyMember() --[[and not fighting]] then
if creatureThing:asPlayer():isPartyLeader() then

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

View File

@@ -5,16 +5,16 @@ importStyle 'textmessage.otui'
-- private variables
local MessageTypes = {
consoleRed = { color = '#F55E5E', consoleChannel = 'Server Log' },
eventOrange = { color = '#FE6500', consoleChannel = 'Default' , windowLocation = 'center', consoleOption = 'showEventMessagesInConsole' },
consoleOrange = { color = '#FE6500', consoleChannel = 'Default' },
warning = { color = '#F55E5E', consoleChannel = 'Server Log', windowLocation = 'center' },
eventAdvance = { color = '#FFFFFF', consoleChannel = 'Server Log', windowLocation = 'center', consoleOption = 'showEventMessagesInConsole' },
eventDefault = { color = '#FFFFFF', consoleChannel = 'Server Log', windowLocation = 'bottom', consoleOption = 'showEventMessagesInConsole' },
statusDefault = { color = '#FFFFFF', consoleChannel = 'Server Log', windowLocation = 'bottom', consoleOption = 'showStatusMessagesInConsole' },
infoDescription = { color = '#00EB00', consoleChannel = 'Server Log', windowLocation = 'center', consoleOption = 'showInfoMessagesInConsole' },
consoleRed = { color = '#F55E5E', consoleTab = 'Server Log' },
eventOrange = { color = '#FE6500', consoleTab = 'Default' , windowLocation = 'center', consoleOption = 'showEventMessagesInConsole' },
consoleOrange = { color = '#FE6500', consoleTab = 'Default' },
warning = { color = '#F55E5E', consoleTab = 'Server Log', windowLocation = 'center' },
eventAdvance = { color = '#FFFFFF', consoleTab = 'Server Log', windowLocation = 'center', consoleOption = 'showEventMessagesInConsole' },
eventDefault = { color = '#FFFFFF', consoleTab = 'Server Log', windowLocation = 'bottom', consoleOption = 'showEventMessagesInConsole' },
statusDefault = { color = '#FFFFFF', consoleTab = 'Server Log', windowLocation = 'bottom', consoleOption = 'showStatusMessagesInConsole' },
infoDescription = { color = '#00EB00', consoleTab = 'Server Log', windowLocation = 'center', consoleOption = 'showInfoMessagesInConsole' },
statusSmall = { color = '#FFFFFF', windowLocation = 'bottom' },
consoleBlue = { color = '#9F9DFD', consoleChannel = 'Default' },
consoleBlue = { color = '#9F9DFD', consoleTab = 'Default' },
}
local bottomLabelWidget
@@ -26,9 +26,9 @@ local centerLabelHideEvent
local function displayMessage(msgtype, msg, time)
if not Game.isOnline() then return end
if msgtype.consoleChannel ~= nil then
if msgtype.consoleTab ~= nil then
if msgtype.consoleOption == nil or Options[msgtype.consoleOption] then
Console.addChannelMessage(msg, msgtype.color, msgtype.consoleChannel)
Console.addText(msg, msgtype, msgtype.consoleTab)
end
end