mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-16 14:08:59 +07:00
remove touchable.click_evt
This commit is contained in:
@@ -10,13 +10,11 @@
|
||||
|
||||
namespace e2d::touchable_events
|
||||
{
|
||||
class click_evt;
|
||||
class mouse_evt;
|
||||
class touch_evt;
|
||||
class hover_evt;
|
||||
|
||||
using event = std::variant<std::monostate,
|
||||
click_evt,
|
||||
mouse_evt,
|
||||
touch_evt,
|
||||
hover_evt>;
|
||||
@@ -152,18 +150,10 @@ namespace e2d::touchable_events
|
||||
};
|
||||
}
|
||||
|
||||
class click_evt final : public impl::base_evt<click_evt> {
|
||||
public:
|
||||
click_evt()
|
||||
: base_evt(true) {}
|
||||
|
||||
click_evt(gobject target)
|
||||
: base_evt(target, true) {}
|
||||
};
|
||||
|
||||
class mouse_evt final : public impl::base_evt<mouse_evt> {
|
||||
public:
|
||||
ENUM_HPP_CLASS_DECL(types, u8,
|
||||
(clicked)
|
||||
(pressed)
|
||||
(released))
|
||||
public:
|
||||
@@ -189,6 +179,7 @@ namespace e2d::touchable_events
|
||||
class touch_evt final : public impl::base_evt<touch_evt> {
|
||||
public:
|
||||
ENUM_HPP_CLASS_DECL(types, u8,
|
||||
(clicked)
|
||||
(pressed)
|
||||
(released))
|
||||
public:
|
||||
|
||||
@@ -137,8 +137,8 @@
|
||||
"behaviour" : {
|
||||
"script" : "../scripts/sample_08/panel.lua"
|
||||
},
|
||||
"sprite_renderer" : {
|
||||
"scale" : [1,1]
|
||||
"widget" : {
|
||||
"size" : [100,100]
|
||||
},
|
||||
"rect_collider" : {
|
||||
"size" : [100,100],
|
||||
@@ -174,8 +174,8 @@
|
||||
"behaviour" : {
|
||||
"script" : "../scripts/sample_08/panel.lua"
|
||||
},
|
||||
"sprite_renderer" : {
|
||||
"scale" : [1,1]
|
||||
"widget" : {
|
||||
"size" : [100,100]
|
||||
},
|
||||
"rect_collider" : {
|
||||
"size" : [100,100],
|
||||
|
||||
@@ -68,15 +68,6 @@ local touchable_base_evt = {
|
||||
}
|
||||
touchable.touchable_base_evt = touchable_base_evt
|
||||
|
||||
--
|
||||
-- touchable_click_evt
|
||||
--
|
||||
|
||||
---@class touchable_click_evt : touchable_base_evt
|
||||
local touchable_click_evt = {
|
||||
}
|
||||
touchable.touchable_click_evt = touchable_click_evt
|
||||
|
||||
--
|
||||
-- touchable_mouse_evt
|
||||
--
|
||||
@@ -116,7 +107,7 @@ local touchable_hover_evt = {
|
||||
}
|
||||
touchable.touchable_hover_evt = touchable_hover_evt
|
||||
|
||||
---@alias touchable_event touchable_click_evt | touchable_mouse_evt | touchable_touch_evt | touchable_hover_evt
|
||||
---@alias touchable_event touchable_mouse_evt | touchable_touch_evt | touchable_hover_evt
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
--
|
||||
|
||||
@@ -26,9 +26,9 @@ end
|
||||
|
||||
---@param go gobject
|
||||
---@param type string
|
||||
---@param event touchable_base_evt | touchable_click_evt
|
||||
---@param event touchable_mouse_evt
|
||||
function M:on_event(go, type, event)
|
||||
if type == "touchable.click_evt" then
|
||||
if type == "touchable.mouse_evt" and event.type == "clicked" then
|
||||
local offset = v2f.new(math.random(-15,15), math.random(-15,15))
|
||||
go.actor.node.translation = go.actor.node.translation + offset
|
||||
end
|
||||
|
||||
@@ -188,21 +188,6 @@ namespace e2d::bindings::high
|
||||
// events
|
||||
//
|
||||
|
||||
l["touchable"].get_or_create<sol::table>()
|
||||
.new_usertype<touchable_events::click_evt>("click_evt",
|
||||
sol::no_constructor,
|
||||
|
||||
"target", sol::property(
|
||||
[](const touchable_events::click_evt& c) -> gobject {
|
||||
return c.target();
|
||||
}),
|
||||
|
||||
"bubbling", sol::property(
|
||||
[](const touchable_events::click_evt& c) -> bool {
|
||||
return c.bubbling();
|
||||
})
|
||||
);
|
||||
|
||||
l["touchable"].get_or_create<sol::table>()
|
||||
.new_usertype<touchable_events::mouse_evt>("mouse_evt",
|
||||
sol::no_constructor,
|
||||
|
||||
@@ -87,10 +87,6 @@ namespace
|
||||
behaviours::call_result r = behaviours::call_result::success;
|
||||
std::visit(utils::overloaded {
|
||||
[](std::monostate){},
|
||||
[&b,&a,&r](const touchable_events::click_evt& e){
|
||||
r = behaviours::call_meta_method(
|
||||
b, "on_event", a.node()->owner(), "touchable.click_evt", e);
|
||||
},
|
||||
[&b,&a,&r](const touchable_events::mouse_evt& e){
|
||||
r = behaviours::call_meta_method(
|
||||
b, "on_event", a.node()->owner(), "touchable.mouse_evt", e);
|
||||
|
||||
@@ -47,13 +47,6 @@ namespace
|
||||
template < typename E >
|
||||
bool dispatch_event(gobject target, const E& event);
|
||||
|
||||
void apply_event(gobject target, const touchable_events::click_evt& event) {
|
||||
target.component<events<touchable_events::event>>().ensure()
|
||||
.add(event);
|
||||
|
||||
target.component<touchable::clicked>().ensure();
|
||||
}
|
||||
|
||||
void apply_event(gobject target, const touchable_events::mouse_evt& event) {
|
||||
target.component<events<touchable_events::event>>().ensure()
|
||||
.add(event);
|
||||
@@ -63,6 +56,9 @@ namespace
|
||||
}
|
||||
|
||||
switch ( event.type() ) {
|
||||
case touchable_events::mouse_evt::types::clicked:
|
||||
target.component<touchable::clicked>().ensure();
|
||||
break;
|
||||
case touchable_events::mouse_evt::types::pressed:
|
||||
target.component<touchable::pressed>().ensure();
|
||||
break;
|
||||
@@ -350,13 +346,20 @@ namespace e2d::touch_system_impl
|
||||
}
|
||||
|
||||
switch ( event.type() ) {
|
||||
case touchable_events::mouse_evt::types::clicked:
|
||||
break;
|
||||
case touchable_events::mouse_evt::types::pressed:
|
||||
target.component<touchable::pushing>().ensure();
|
||||
break;
|
||||
case touchable_events::mouse_evt::types::released:
|
||||
if ( target.component<touchable::pushing>() ) {
|
||||
target.component<touchable::pushing>().remove();
|
||||
dispatch_event(target, touchable_events::click_evt(target));
|
||||
dispatch_event(
|
||||
target,
|
||||
touchable_events::mouse_evt(
|
||||
target,
|
||||
touchable_events::mouse_evt::types::clicked,
|
||||
event.button()));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -372,13 +375,20 @@ namespace e2d::touch_system_impl
|
||||
}
|
||||
|
||||
switch ( event.type() ) {
|
||||
case touchable_events::touch_evt::types::clicked:
|
||||
break;
|
||||
case touchable_events::touch_evt::types::pressed:
|
||||
target.component<touchable::pushing>().ensure();
|
||||
break;
|
||||
case touchable_events::touch_evt::types::released:
|
||||
if ( target.component<touchable::pushing>() ) {
|
||||
target.component<touchable::pushing>().remove();
|
||||
dispatch_event(target, touchable_events::click_evt(target));
|
||||
dispatch_event(
|
||||
target,
|
||||
touchable_events::touch_evt(
|
||||
target,
|
||||
touchable_events::touch_evt::types::clicked,
|
||||
event.finger()));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user