diff --git a/docs_md/changelog.md b/docs_md/changelog.md index 1dbd518..1581d0f 100644 --- a/docs_md/changelog.md +++ b/docs_md/changelog.md @@ -465,8 +465,6 @@ The API section now filled with overview and usage examples. I've started with t Also, I've added the **Unit Tests**. It's not cover all **Druid** code, but it's a good start! 🎉 -I have the feedback form for you, please fill it if you have a free minute. It will help me to improve **Druid** in future. %LINK HERE% - Have a good day! @@ -478,7 +476,7 @@ Have a good day! - **#39**: [System] Finally add **Unit Tests**. Yeah, it cover not all **Druid** code, but it's a good start! 🎉 - **#219**: [System] UTF-8 performance optimization. Now Druid will try to use *utf8* native extension over lua utf8 library if exists. If you wanna use native utf8, just [add the extension](https://github.com/d954mas/defold-utf8) in your `game.project` dependency. - **#156**: [Button] Now button can work in HTML5 with `html5.set_interaction_listener`. - - The API is `button:set_html5_user_interaction(true)`. In HTML5 mode button have several restrictions. Basically, only the single tap event will work. + - The API is `button:set_web_user_interaction(true)`. In HTML5 mode button have several restrictions. Basically, only the single tap event will work. - **#227**: Update current URL in HTML5 example - Now if you will open the example from direct URL, it will be updated to the current URL in your browser. So now it's much easier to share the example link with each other. - **#183**: Documentation about [GUI in World Space](https://forum.defold.com/t/how-to-gui-in-defold/73256#gui-in-world-coordinates-49) diff --git a/druid/base/button.lua b/druid/base/button.lua index 5bd2b51..d7113cd 100755 --- a/druid/base/button.lua +++ b/druid/base/button.lua @@ -168,6 +168,10 @@ end local function on_button_click(self) + if self._is_html5_mode then + self._is_html5_listener_set = false + html5.set_interaction_listener(nil) + end self.click_in_row = 1 self.on_click:trigger(self:get_context(), self.params, self) self.style.on_click(self, self.anim_node) @@ -302,6 +306,8 @@ function Button.init(self, node, callback, custom_args, anim_node) self._check_function = nil self._failure_callback = nil + self._is_html5_mode = false + self._is_html5_listener_set = false -- Events self.on_click = Event(callback) @@ -349,7 +355,9 @@ function Button.on_input(self, action_id, action) if action.released then self.on_click_outside:trigger(self:get_context(), self.params, self) end - if self._is_html5_mode then + + if self._is_html5_mode and self._is_html5_listener_set then + self._is_html5_listener_set = false html5.set_interaction_listener(nil) end return false @@ -367,9 +375,9 @@ function Button.on_input(self, action_id, action) self.on_pressed:trigger(self:get_context(), self.params, self) if self._is_html5_mode then + self._is_html5_listener_set = true html5.set_interaction_listener(function() on_button_click(self) - html5.set_interaction_listener(nil) end) end return true @@ -528,7 +536,7 @@ end -- @usage -- button:set_web_user_interaction(true) function Button.set_web_user_interaction(self, is_web_mode) - self._is_html5_mode = is_web_mode and html5 + self._is_html5_mode = not not (is_web_mode and html5) return self end diff --git a/druid/extended/input.lua b/druid/extended/input.lua index 320491a..f08ac6b 100755 --- a/druid/extended/input.lua +++ b/druid/extended/input.lua @@ -151,7 +151,7 @@ function Input.init(self, click_node, text_node, keyboard_type) self.button.on_long_click:subscribe(clear_and_select) if html5 then - self.button:set_html5_user_interaction(true) + self.button:set_web_user_interaction(true) end self.on_input_select = Event() diff --git a/example/examples/data_list/manage_data/manage_data.gui_script b/example/examples/data_list/manage_data/manage_data.gui_script index b1d4900..adfd601 100644 --- a/example/examples/data_list/manage_data/manage_data.gui_script +++ b/example/examples/data_list/manage_data/manage_data.gui_script @@ -53,7 +53,6 @@ function init(self) self.druid:new_button("button_add_first/button", on_add_first) local button = self.druid:new_button("button_add_last/button", on_add_last) - button:set_html5_user_interaction(true) end