implement remove event lua function
This commit is contained in:
parent
4e0ca24cb7
commit
5b1b170165
|
@ -1,28 +1,40 @@
|
||||||
local eventId = 1
|
local eventId = 0
|
||||||
local events = { }
|
local eventsTable = { }
|
||||||
local orig = { scheduleEvent = scheduleEvent,
|
local orig = { scheduleEvent = scheduleEvent,
|
||||||
addEvent = addEvent }
|
addEvent = addEvent }
|
||||||
|
|
||||||
-- fix original scheduleEvent
|
-- fix original scheduleEvent
|
||||||
function scheduleEvent(func, delay)
|
function scheduleEvent(func, delay)
|
||||||
eventId = eventId + 1
|
eventId = eventId + 1
|
||||||
local id = eventId + 1
|
local id = eventId
|
||||||
local function proxyFunc()
|
local function proxyFunc()
|
||||||
|
if eventsTable[id] then
|
||||||
func()
|
func()
|
||||||
table[id] = nil
|
eventsTable[id] = nil
|
||||||
end
|
end
|
||||||
table[id] = proxyFunc
|
end
|
||||||
|
eventsTable[id] = proxyFunc
|
||||||
orig.scheduleEvent(proxyFunc, delay)
|
orig.scheduleEvent(proxyFunc, delay)
|
||||||
|
return id
|
||||||
|
end
|
||||||
|
|
||||||
|
function removeEvent(id)
|
||||||
|
if id and eventsTable[id] then
|
||||||
|
eventsTable[id] = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- fix original addEvent
|
-- fix original addEvent
|
||||||
function addEvent(func)
|
function addEvent(func)
|
||||||
eventId = eventId + 1
|
eventId = eventId + 1
|
||||||
local id = eventId + 1
|
local id = eventId
|
||||||
local function proxyFunc()
|
local function proxyFunc()
|
||||||
|
if eventsTable[id] then
|
||||||
func()
|
func()
|
||||||
table[id] = nil
|
eventsTable[id] = nil
|
||||||
end
|
end
|
||||||
table[id] = proxyFunc
|
end
|
||||||
|
eventsTable[id] = proxyFunc
|
||||||
orig.addEvent(proxyFunc)
|
orig.addEvent(proxyFunc)
|
||||||
|
return id
|
||||||
end
|
end
|
|
@ -18,6 +18,7 @@ local messageTypes = {
|
||||||
{ type = 'MessageBlue', color = '#3264C8', showOnConsole = true, showOnWindow = false },
|
{ type = 'MessageBlue', color = '#3264C8', showOnConsole = true, showOnWindow = false },
|
||||||
{ type = 'MessageRed', color = '#C83200', showOnConsole = true, showOnWindow = false }
|
{ type = 'MessageRed', color = '#C83200', showOnConsole = true, showOnWindow = false }
|
||||||
}
|
}
|
||||||
|
local hideEvent
|
||||||
|
|
||||||
-- public functions
|
-- public functions
|
||||||
function TextMessage.create()
|
function TextMessage.create()
|
||||||
|
@ -47,11 +48,11 @@ function Game.onTextMessage(type, message)
|
||||||
label:setVisible(true)
|
label:setVisible(true)
|
||||||
label:setForegroundColor(messageType.color)
|
label:setForegroundColor(messageType.color)
|
||||||
label:setText(message)
|
label:setText(message)
|
||||||
|
|
||||||
label:setStyle(messageType.windowLocation)
|
label:setStyle(messageType.windowLocation)
|
||||||
|
|
||||||
time = #message * 75
|
time = #message * 75
|
||||||
scheduleEvent(function()
|
removeEvent(hideEvent)
|
||||||
|
hideEvent = scheduleEvent(function()
|
||||||
label:setVisible(false)
|
label:setVisible(false)
|
||||||
end, time)
|
end, time)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue