diff options
Diffstat (limited to 'indra')
-rw-r--r-- | indra/llui/llluafloater.cpp | 68 | ||||
-rw-r--r-- | indra/llui/llluafloater.h | 4 | ||||
-rw-r--r-- | indra/newview/scripts/lua/test_luafloater_demo.lua | 19 | ||||
-rw-r--r-- | indra/newview/scripts/lua/test_luafloater_gesture_list.lua | 14 |
4 files changed, 44 insertions, 61 deletions
diff --git a/indra/llui/llluafloater.cpp b/indra/llui/llluafloater.cpp index 668c0edc53..4ae0e28963 100644 --- a/indra/llui/llluafloater.cpp +++ b/indra/llui/llluafloater.cpp @@ -49,53 +49,40 @@ std::map<std::string, std::string> EVENT_LIST = {"CLOSE_EVENT", "floater_close"} }; + + LLLuaFloater::LLLuaFloater(const LLSD &key) : - LLFloater(key), + LLFloater(key), + mDispatchListener(LLUUID::generateNewID().asString(), "action"), mReplyPumpName(key["reply"].asString()), - mDispatcher("LLLuaFloater", "action"), mReqID(key) { - mListenerPumpName = LLUUID::generateNewID().asString(); - - mBoundListener = LLEventPumps::instance().obtain(mListenerPumpName).listen(LISTENER_NAME, [this](const LLSD &event) - { - if (event.has("action")) - { - mDispatcher.try_call(event); - } - else + auto ctrl_lookup = [this](const LLSD &event, std::function<LLSD(LLUICtrl*,const LLSD&)> cb) + { + LLUICtrl *ctrl = getChild<LLUICtrl>(event["ctrl_name"].asString()); + if (!ctrl) { - LL_WARNS("LuaFloater") << "Unknown message: " << event << LL_ENDL; + LL_WARNS("LuaFloater") << "Control not found: " << event["ctrl_name"] << LL_ENDL; + return LLSD(); } - return false; - }); + return cb(ctrl, event); + }; LLSD requiredParams = llsd::map("ctrl_name", LLSD(), "value", LLSD()); - mDispatcher.add("set_enabled", "", [this](const LLSD &event) + mDispatchListener.add("set_enabled", "", [this, ctrl_lookup](const LLSD &event) { - LLUICtrl *ctrl = getChild<LLUICtrl>(event["ctrl_name"].asString()); - if(ctrl) - { - ctrl->setEnabled(event["value"].asBoolean()); - } + return ctrl_lookup(event, [](LLUICtrl *ctrl, const LLSD &event) { ctrl->setEnabled(event["value"].asBoolean()); return LLSD(); }); }, requiredParams); - mDispatcher.add("set_visible", "", [this](const LLSD &event) + mDispatchListener.add("set_visible", "", [this, ctrl_lookup](const LLSD &event) { - LLUICtrl *ctrl = getChild<LLUICtrl>(event["ctrl_name"].asString()); - if(ctrl) - { - ctrl->setVisible(event["value"].asBoolean()); - } + return ctrl_lookup(event, [](LLUICtrl *ctrl, const LLSD &event) { ctrl->setVisible(event["value"].asBoolean()); return LLSD(); }); }, requiredParams); - mDispatcher.add("set_value", "", [this](const LLSD &event) + mDispatchListener.add("set_value", "", [this, ctrl_lookup](const LLSD &event) { - LLUICtrl *ctrl = getChild<LLUICtrl>(event["ctrl_name"].asString()); - if(ctrl) - { - ctrl->setValue(event["value"]); - } + return ctrl_lookup(event, [](LLUICtrl *ctrl, const LLSD &event) { ctrl->setValue(event["value"]); return LLSD(); }); }, requiredParams); - mDispatcher.add("add_list_element", "", [this](const LLSD &event) + + mDispatchListener.add("add_list_element", "", [this](const LLSD &event) { LLScrollListCtrl *ctrl = getChild<LLScrollListCtrl>(event["ctrl_name"].asString()); if(ctrl) @@ -104,21 +91,14 @@ LLLuaFloater::LLLuaFloater(const LLSD &key) : } }, requiredParams); - mDispatcher.add("set_title", "", [this](const LLSD &event) + mDispatchListener.add("set_title", "", [this](const LLSD &event) { setTitle(event["value"].asString()); }, llsd::map("value", LLSD())); - mDispatcher.add("get_value", "", [this](const LLSD &event) + mDispatchListener.add("get_value", "", [this, ctrl_lookup](const LLSD &event) { - LLUICtrl *ctrl = getChild<LLUICtrl>(event["ctrl_name"].asString()); - if(ctrl) - { - LLSD response; - response["value"] = ctrl->getValue(); - response["reqid"] = event["reqid"]; - post(response); - } + return ctrl_lookup(event, [](LLUICtrl *ctrl, const LLSD &event) { return llsd::map("value", ctrl->getValue()); }); }, llsd::map("ctrl_name", LLSD(), "reqid", LLSD())); } @@ -162,7 +142,7 @@ BOOL LLLuaFloater::postBuild() } //send pump name to the script after the floater is built - post(llsd::map("command_name", mListenerPumpName, "event", EVENT_LIST["POST_BUILD_EVENT"])); + post(llsd::map("command_name", mDispatchListener.getPumpName(), "event", EVENT_LIST["POST_BUILD_EVENT"])); return true; } diff --git a/indra/llui/llluafloater.h b/indra/llui/llluafloater.h index b9f96f0ad3..d4c16745ee 100644 --- a/indra/llui/llluafloater.h +++ b/indra/llui/llluafloater.h @@ -46,10 +46,8 @@ public: private: LLReqID mReqID; - LLEventDispatcher mDispatcher; - LLTempBoundListener mBoundListener; + LLDispatchListener mDispatchListener; - std::string mListenerPumpName; std::string mReplyPumpName; }; #endif diff --git a/indra/newview/scripts/lua/test_luafloater_demo.lua b/indra/newview/scripts/lua/test_luafloater_demo.lua index 2cbafcec14..308cebcb88 100644 --- a/indra/newview/scripts/lua/test_luafloater_demo.lua +++ b/indra/newview/scripts/lua/test_luafloater_demo.lua @@ -39,12 +39,19 @@ function handleEvents(event_data) elseif event_data.event == e.CLOSE_EVENT then print_warning("Floater was closed") leap.done() - --script received event pump name, after floater was built - elseif event_data.event == e.POST_BUILD_EVENT then - COMMAND_PUMP_NAME = event_data.command_name end end +local key = {xml_path = XML_FILE_PATH, op = "showLuaFloater"} +--sign for additional events for defined control {<control_name>= {action1, action2, ...}} +key.extra_events={show_time_lbl = {e.RIGHT_MOUSE_DOWN_EVENT, e.DOUBLE_CLICK_EVENT}} +coro.launch(function () + --script received event pump name, after floater was built + COMMAND_PUMP_NAME = leap.request("LLFloaterReg", key)["command_name"] + leap.done() +end) +leap.process() + catch_events = leap.WaitFor:new(-1, "all_events") function catch_events:filter(pump, data) return data @@ -58,12 +65,6 @@ function process_events(waitfor) end end -local key = {xml_path = XML_FILE_PATH, op = "showLuaFloater"} - ---sign for additional events for defined control {<control_name>= {action1, action2, ...}} -key.extra_events={show_time_lbl = {e.RIGHT_MOUSE_DOWN_EVENT, e.DOUBLE_CLICK_EVENT}} -leap.send("LLFloaterReg", key, "floater1") - coro.launch(process_events, catch_events) leap.process() print_warning("End of the script") diff --git a/indra/newview/scripts/lua/test_luafloater_gesture_list.lua b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua index 5ea2b1e30d..57f737ce9b 100644 --- a/indra/newview/scripts/lua/test_luafloater_gesture_list.lua +++ b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua @@ -40,6 +40,15 @@ function handleEvents(event_data) end end +local key = {xml_path = XML_FILE_PATH, op = "showLuaFloater"} +--receive additional events for defined control {<control_name>= {action1, action2, ...}} +key.extra_events={gesture_list = {e.DOUBLE_CLICK_EVENT}} +coro.launch(function () + handleEvents(leap.request("LLFloaterReg", key)) + leap.done() +end) +leap.process() + catch_events = leap.WaitFor:new(-1, "all_events") function catch_events:filter(pump, data) return data @@ -53,10 +62,5 @@ function process_events(waitfor) end end -local key = {xml_path = XML_FILE_PATH, op = "showLuaFloater"} ---receive additional events for defined control {<control_name>= {action1, action2, ...}} -key.extra_events={gesture_list = {e.DOUBLE_CLICK_EVENT}} -leap.send("LLFloaterReg", key, "floater1") - coro.launch(process_events, catch_events) leap.process() |