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

View File

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

View File

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

View File

@ -160,8 +160,8 @@ MarketFilters = {
SearchAll = 4
}
MarketFilters.First = MarketFilters.vocation
MarketFilters.Last = MarketFilters.depot
MarketFilters.First = MarketFilters.Vocation
MarketFilters.Last = MarketFilters.Depot
function getMarketSlotFilterId(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