Added market message, reworked text messages a little

This commit is contained in:
TheSumm 2015-01-22 20:38:28 +01:00
parent 1d022905ab
commit 92e2e8224f
5 changed files with 57 additions and 8 deletions

View File

@ -575,6 +575,10 @@ local function onAmountChange()
end end
end end
local function onMarketMessage(messageMode, message)
Market.displayMessage(message)
end
local function initMarketItems(category) local function initMarketItems(category)
for c = MarketCategory.First, MarketCategory.Last do for c = MarketCategory.First, MarketCategory.Last do
marketItems[c] = {} marketItems[c] = {}
@ -748,6 +752,8 @@ function init()
offerExhaust[MarketAction.Sell] = 10 offerExhaust[MarketAction.Sell] = 10
offerExhaust[MarketAction.Buy] = 20 offerExhaust[MarketAction.Buy] = 20
registerMessageMode(MessageModes.Market, onMarketMessage)
protocol.initProtocol() protocol.initProtocol()
connect(g_game, { onGameEnd = Market.reset }) connect(g_game, { onGameEnd = Market.reset })
connect(g_game, { onGameEnd = Market.close }) connect(g_game, { onGameEnd = Market.close })
@ -760,6 +766,8 @@ end
function terminate() function terminate()
Market.close() Market.close()
unregisterMessageMode(MessageModes.Market, onMarketMessage)
protocol.terminateProtocol() protocol.terminateProtocol()
disconnect(g_game, { onGameEnd = Market.reset }) disconnect(g_game, { onGameEnd = Market.reset })
disconnect(g_game, { onGameEnd = Market.close }) disconnect(g_game, { onGameEnd = Market.close })
@ -780,6 +788,13 @@ function Market.reset()
end end
end end
function Market.displayMessage(message)
if marketWindow:isHidden() then return end
local infoBox = displayInfoBox(tr('Market Error'), message)
infoBox:lock()
end
function Market.clearSelectedItem() function Market.clearSelectedItem()
if Market.isItemSelected() then if Market.isItemSelected() then
Market.resetCreateOffer() Market.resetCreateOffer()
@ -1059,7 +1074,7 @@ function Market.createNewOffer()
end end
if errorMsg ~= '' then if errorMsg ~= '' then
displayInfoBox('Error', errorMsg) Market.displayMessage(errorMsg)
return return
end end

View File

@ -44,7 +44,6 @@ MessageTypes = {
[MessageModes.Party] = MessageSettings.centerGreen, [MessageModes.Party] = MessageSettings.centerGreen,
[MessageModes.PartyManagement] = MessageSettings.centerWhite, [MessageModes.PartyManagement] = MessageSettings.centerWhite,
[MessageModes.TutorialHint] = MessageSettings.centerWhite, [MessageModes.TutorialHint] = MessageSettings.centerWhite,
[MessageModes.Market] = MessageSettings.centerWhite,
[MessageModes.BeyondLast] = MessageSettings.centerWhite, [MessageModes.BeyondLast] = MessageSettings.centerWhite,
[MessageModes.Report] = MessageSettings.consoleRed, [MessageModes.Report] = MessageSettings.consoleRed,
[MessageModes.HotkeyUse] = MessageSettings.centerGreen, [MessageModes.HotkeyUse] = MessageSettings.centerGreen,
@ -55,13 +54,19 @@ MessageTypes = {
messagesPanel = nil messagesPanel = nil
function init() function init()
connect(g_game, 'onTextMessage', displayMessage) for messageMode, _ in pairs(MessageTypes) do
registerMessageMode(messageMode, displayMessage)
end
connect(g_game, 'onGameEnd', clearMessages) connect(g_game, 'onGameEnd', clearMessages)
messagesPanel = g_ui.loadUI('textmessage', modules.game_interface.getRootPanel()) messagesPanel = g_ui.loadUI('textmessage', modules.game_interface.getRootPanel())
end end
function terminate() function terminate()
disconnect(g_game, 'onTextMessage', displayMessage) for messageMode, _ in pairs(MessageTypes) do
unregisterMessageMode(messageMode, displayMessage)
end
disconnect(g_game, 'onGameEnd', clearMessages) disconnect(g_game, 'onGameEnd', clearMessages)
clearMessages() clearMessages()
messagesPanel:destroy() messagesPanel:destroy()
@ -75,9 +80,7 @@ function displayMessage(mode, text)
if not g_game.isOnline() then return end if not g_game.isOnline() then return end
local msgtype = MessageTypes[mode] local msgtype = MessageTypes[mode]
if not msgtype then if not msgtype then
perror('unhandled onTextMessage message mode ' .. mode .. ': ' .. text)
return return
end end

View File

@ -19,6 +19,7 @@ Module
dofile 'creature' dofile 'creature'
dofile 'player' dofile 'player'
dofile 'market' dofile 'market'
dofile 'textmessages'
dofile 'thing' dofile 'thing'
dofile 'spells' dofile 'spells'

View File

@ -160,8 +160,8 @@ MarketFilters = {
SearchAll = 4 SearchAll = 4
} }
MarketFilters.First = MarketFilters.vocation MarketFilters.First = MarketFilters.Vocation
MarketFilters.Last = MarketFilters.depot MarketFilters.Last = MarketFilters.Depot
function getMarketSlotFilterId(name) function getMarketSlotFilterId(name)
local id = table.find(MarketSlotFilters, name) local id = table.find(MarketSlotFilters, name)

View File

@ -0,0 +1,30 @@
local messageModeCallbacks = {}
function g_game.onTextMessage(messageMode, message)
local callbacks = messageModeCallbacks[messageMode]
if not callbacks or #callbacks == 0 then
perror(string.format('Unhandled onTextMessage message mode %i: %s', messageMode, message))
return
end
for _, callback in pairs(callbacks) do
callback(messageMode, message)
end
end
function registerMessageMode(messageMode, callback)
if not messageModeCallbacks[messageMode] then
messageModeCallbacks[messageMode] = {}
end
table.insert(messageModeCallbacks[messageMode], callback)
return true
end
function unregisterMessageMode(messageMode, callback)
if not messageModeCallbacks[messageMode] then
return false
end
return table.removevalue(messageModeCallbacks[messageMode], callback)
end