fix death issues, improve text messages

This commit is contained in:
Eduardo Bart
2012-01-25 12:56:17 -02:00
parent 29f99ee9b3
commit cfcc3fd428
13 changed files with 161 additions and 119 deletions

View File

@@ -5,21 +5,19 @@ importStyle 'textmessage.otui'
-- private variables
local MessageTypes = {
consoleRed = { color = '#F55E5E', consoleTab = 'Default' }, -- 18
consoleOrange = { color = '#FE6500', consoleTab = 'Default' }, -- 19/20
consoleBlue = { color = '#9F9DFD', consoleTab = 'Default' }, -- 27
warning = { color = '#F55E5E', consoleTab = 'Server Log', windowLocation = 'center' }, -- 21
infoDescription = { color = '#00EB00', consoleTab = 'Server Log', windowLocation = 'center', consoleOption = 'showInfoMessagesInConsole' }, -- 25
eventAdvance = { color = '#FFFFFF', consoleTab = 'Server Log', windowLocation = 'center', consoleOption = 'showEventMessagesInConsole' }, -- 22
eventDefault = { color = '#FFFFFF', consoleTab = 'Server Log', windowLocation = 'bottom', consoleOption = 'showEventMessagesInConsole' }, -- 23
statusDefault = { color = '#FFFFFF', consoleTab = 'Server Log', windowLocation = 'bottom', consoleOption = 'showStatusMessagesInConsole' }, -- 24
statusSmall = { color = '#FFFFFF', windowLocation = 'bottom' }, -- 26
consoleRed = { color = '#F55E5E', consoleTab = 'Default' },
consoleOrange = { color = '#FE6500', consoleTab = 'Default' },
consoleBlue = { color = '#9F9DFD', consoleTab = 'Default' },
warning = { color = '#F55E5E', consoleTab = 'Server Log', labelId = 'centerWarning', wrap = true },
infoDescription = { color = '#00EB00', consoleTab = 'Server Log', labelId = 'centerInfo', consoleOption = 'showInfoMessagesInConsole', wrap = true },
eventAdvance = { color = '#FFFFFF', consoleTab = 'Server Log', labelId = 'centerAdvance', consoleOption = 'showEventMessagesInConsole', wrap = true },
eventDefault = { color = '#FFFFFF', consoleTab = 'Server Log', labelId = 'bottomStatus', consoleOption = 'showEventMessagesInConsole' },
statusDefault = { color = '#FFFFFF', consoleTab = 'Server Log', labelId = 'bottomStatus', consoleOption = 'showStatusMessagesInConsole' },
statusSmall = { color = '#FFFFFF', windowLocation = 'bottomStatus' },
}
local bottomLabelWidget
local centerLabelWidget
local bottomLabelHideEvent
local centerLabelHideEvent
local centerTextMessagePanel
local centerLabel
-- private functions
local function displayMessage(msgtype, msg, time)
@@ -31,28 +29,22 @@ local function displayMessage(msgtype, msg, time)
end
end
if msgtype.windowLocation then
local label
local style
if msgtype.windowLocation == 'bottom' then
label = bottomLabelWidget
style = 'BottomLabel'
elseif msgtype.windowLocation == 'center' then
label = centerLabelWidget
style = 'CenterLabel'
end
if msgtype.labelId then
local label = Game.gameMapPanel:recursiveGetChildById(msgtype.labelId)
label:setVisible(true)
label:setText(msg)
label:setStyle(style)
label:setColor(msgtype.color)
label:resizeToText()
if msgtype.windowLocation == 'center' then
if msgtype.wrap then
label:setWidth(label:getParent():getWidth())
label:wrapText()
label:setHeight(label:getTextSize().height)
end
if not time then
time = math.max(#msg * 75, 3000)
time = math.max(#msg * 100, 5000)
else
time = time * 1000
end
@@ -61,10 +53,36 @@ local function displayMessage(msgtype, msg, time)
end
end
local function createTextMessageLabel(id, parent)
local label = createWidget('UILabel', parent)
label:setFont('verdana-11px-rounded')
label:setTextAlign(AlignCenter)
label:setId(id)
label:setMarginBottom(2)
label:setVisible(false)
return label
end
-- public functions
function TextMessage.create()
bottomLabelWidget = createWidget('UILabel', Game.gameMapPanel)
centerLabelWidget = createWidget('UILabel', Game.gameMapPanel)
centerTextMessagePanel = createWidget('Panel', Game.gameMapPanel)
centerTextMessagePanel:setId('centerTextMessagePanel')
local layout = UIVerticalLayout.create(centerTextMessagePanel)
layout:setFitChildren(true)
centerTextMessagePanel:setLayout(layout)
centerTextMessagePanel:setWidth(360)
centerTextMessagePanel:centerIn('parent')
createTextMessageLabel('centerWarning', centerTextMessagePanel)
createTextMessageLabel('centerAdvance', centerTextMessagePanel)
createTextMessageLabel('centerInfo', centerTextMessagePanel)
bottomStatusLabel = createTextMessageLabel('bottomStatus', Game.gameMapPanel)
bottomStatusLabel:setHeight(16)
bottomStatusLabel:addAnchor(AnchorBottom, 'parent', AnchorBottom)
bottomStatusLabel:addAnchor(AnchorLeft, 'parent', AnchorLeft)
bottomStatusLabel:addAnchor(AnchorRight, 'parent', AnchorRight)
end
function TextMessage.displayStatus(msg, time)
@@ -84,11 +102,13 @@ end
-- hooked events
local function onGameDeath()
TextMessage.displayEventAdvance('You are dead.', 60)
local advanceLabel = Game.gameMapPanel:recursiveGetChildById('centerAdvance')
if advanceLabel:isVisible() then return end
TextMessage.displayEventAdvance('You are dead.')
end
local function onGameTextMessage(msgtype, msg)
TextMessage.display(msgtype, msg)
local function onGameTextMessage(msgtypedesc, msg)
TextMessage.display(msgtypedesc, msg)
end
connect(Game, { onLogin = TextMessage.create,