From 724713f9e480ba92f4884c62058b96f691c7bc8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ritzl?= Date: Fri, 1 Jun 2018 08:43:08 +0200 Subject: [PATCH] Include transition id in TRANSITION.DONE message Also send the TRANSITION.DONE message to the gui that was transitioned --- README.md | 5 +++++ monarch/transitions/gui.lua | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 63265e6..7acfcd7 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ When a transition is completed it is up to the developer to send a ```transition Monarch comes with a system for setting up transitions easily in a gui_script using the ```monarch.transitions.gui``` module. Example: local transitions = require "monarch.transitions.gui" + local monarch = require "monarch.monarch" function init(self) -- create transitions for the node 'root' @@ -137,6 +138,10 @@ Monarch comes with a system for setting up transitions easily in a gui_script us function on_message(self, message_id, message, sender) self.transition.handle(message_id, message, sender) + -- you can also check when a transition has completed: + if message_id == monarch.TRANSITION.DONE and message.transition == monarch.TRANSITION.SHOW_IN then + print("Show in done!") + end end ### Predefined transitions diff --git a/monarch/transitions/gui.lua b/monarch/transitions/gui.lua index 783d93a..5c7ab2b 100644 --- a/monarch/transitions/gui.lua +++ b/monarch/transitions/gui.lua @@ -113,16 +113,18 @@ function M.create(node) } end - local function start_transition(transition, url) + local function start_transition(transition, transition_id, url) table.insert(transition.urls, url) if not transition.in_progress then + table.insert(transition.urls, msg.url()) current_transition = transition transition.in_progress = true transition.fn(node, initial_data, transition.easing, transition.duration, transition.delay or 0, function() transition.in_progress = false + local message = { transition = transition_id } while #transition.urls > 0 do local url = table.remove(transition.urls) - msg.post(url, monarch.TRANSITION.DONE) + msg.post(url, monarch.TRANSITION.DONE, message) end end) end @@ -141,7 +143,7 @@ function M.create(node) else local transition = transitions[message_id] if transition then - start_transition(transition, sender) + start_transition(transition, message_id, sender) end end end