mirror of
https://github.com/enduro2d/enduro2d.git
synced 2026-02-04 15:06:57 +07:00
dummy touchable flags (touched, under_mouse)
This commit is contained in:
@@ -15,6 +15,9 @@
|
||||
namespace e2d
|
||||
{
|
||||
class touchable final {
|
||||
public:
|
||||
class touched final {};
|
||||
class under_mouse final {};
|
||||
public:
|
||||
touchable() = default;
|
||||
};
|
||||
@@ -35,6 +38,34 @@ namespace e2d
|
||||
asset_dependencies& dependencies,
|
||||
const collect_context& ctx) const;
|
||||
};
|
||||
|
||||
template <>
|
||||
class factory_loader<touchable::touched> final : factory_loader<> {
|
||||
public:
|
||||
static const char* schema_source;
|
||||
|
||||
bool operator()(
|
||||
touchable::touched& component,
|
||||
const fill_context& ctx) const;
|
||||
|
||||
bool operator()(
|
||||
asset_dependencies& dependencies,
|
||||
const collect_context& ctx) const;
|
||||
};
|
||||
|
||||
template <>
|
||||
class factory_loader<touchable::under_mouse> final : factory_loader<> {
|
||||
public:
|
||||
static const char* schema_source;
|
||||
|
||||
bool operator()(
|
||||
touchable::under_mouse& component,
|
||||
const fill_context& ctx) const;
|
||||
|
||||
bool operator()(
|
||||
asset_dependencies& dependencies,
|
||||
const collect_context& ctx) const;
|
||||
};
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
|
||||
@@ -6,7 +6,31 @@
|
||||
}
|
||||
},
|
||||
"children" : [{
|
||||
"prototype" : "../prefabs/camera_prefab.json"
|
||||
"prototype" : "../prefabs/camera_prefab.json",
|
||||
"components" : {
|
||||
"actor" : {
|
||||
"rotation" : 0.5
|
||||
},
|
||||
"camera" : {
|
||||
"viewport" : [0.0, 0.0, 0.45, 1.0]
|
||||
},
|
||||
"named" : {
|
||||
"name" : "camera(1)"
|
||||
}
|
||||
}
|
||||
},{
|
||||
"prototype" : "../prefabs/camera_prefab.json",
|
||||
"components" : {
|
||||
"actor" : {
|
||||
"rotation" : -0.5
|
||||
},
|
||||
"camera" : {
|
||||
"viewport" : [0.55, 0.0, 0.45, 1.0]
|
||||
},
|
||||
"named" : {
|
||||
"name" : "camera(2)"
|
||||
}
|
||||
}
|
||||
},{
|
||||
"prototype" : "../prefabs/ship_prefab.json",
|
||||
"components" : {
|
||||
@@ -28,6 +52,7 @@
|
||||
"size" : [66,113]
|
||||
},
|
||||
"circle_collider" : {
|
||||
"offset" : [50,25],
|
||||
"radius" : 33
|
||||
}
|
||||
}
|
||||
@@ -38,8 +63,8 @@
|
||||
"name" : "ship(2)"
|
||||
},
|
||||
"actor" : {
|
||||
"translation" : [45,100],
|
||||
"rotation" : 0
|
||||
"translation" : [120,100],
|
||||
"rotation" : 0.2
|
||||
},
|
||||
"behaviour" : {
|
||||
"script" : "../scripts/sample_08/ship.lua"
|
||||
@@ -52,8 +77,10 @@
|
||||
"size" : [66,113]
|
||||
},
|
||||
"polygon_collider" : {
|
||||
"offset" : [25,50],
|
||||
"points" : [
|
||||
[-20,0],
|
||||
[0,-20],
|
||||
[20,0],
|
||||
[30,-50],
|
||||
[-30,-50]
|
||||
|
||||
@@ -4,7 +4,13 @@ local touchable = {
|
||||
enabled = true,
|
||||
|
||||
---@type boolean
|
||||
disabled = false
|
||||
disabled = false,
|
||||
|
||||
---@type boolean
|
||||
touched = false,
|
||||
|
||||
---@type boolean
|
||||
under_mouse = false
|
||||
}
|
||||
|
||||
---@overload fun(self: touchable)
|
||||
|
||||
@@ -48,6 +48,32 @@ namespace e2d::bindings::high
|
||||
c.owner().component<disabled<touchable>>().remove();
|
||||
}
|
||||
}
|
||||
),
|
||||
|
||||
"touched", sol::property(
|
||||
[](const gcomponent<touchable>& c) -> bool {
|
||||
return c.owner().component<touchable::touched>().exists();
|
||||
},
|
||||
[](gcomponent<touchable>& c, bool yesno){
|
||||
if ( yesno ) {
|
||||
c.owner().component<touchable::touched>().ensure();
|
||||
} else {
|
||||
c.owner().component<touchable::touched>().remove();
|
||||
}
|
||||
}
|
||||
),
|
||||
|
||||
"under_mouse", sol::property(
|
||||
[](const gcomponent<touchable>& c) -> bool {
|
||||
return c.owner().component<touchable::under_mouse>().exists();
|
||||
},
|
||||
[](gcomponent<touchable>& c, bool yesno){
|
||||
if ( yesno ) {
|
||||
c.owner().component<touchable::under_mouse>().ensure();
|
||||
} else {
|
||||
c.owner().component<touchable::under_mouse>().remove();
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -33,11 +33,81 @@ namespace e2d
|
||||
}
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
const char* factory_loader<touchable::touched>::schema_source = R"json({
|
||||
"type" : "object",
|
||||
"required" : [],
|
||||
"additionalProperties" : false,
|
||||
"properties" : {}
|
||||
})json";
|
||||
|
||||
bool factory_loader<touchable::touched>::operator()(
|
||||
touchable::touched& component,
|
||||
const fill_context& ctx) const
|
||||
{
|
||||
E2D_UNUSED(component, ctx);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool factory_loader<touchable::touched>::operator()(
|
||||
asset_dependencies& dependencies,
|
||||
const collect_context& ctx) const
|
||||
{
|
||||
E2D_UNUSED(dependencies, ctx);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
const char* factory_loader<touchable::under_mouse>::schema_source = R"json({
|
||||
"type" : "object",
|
||||
"required" : [],
|
||||
"additionalProperties" : false,
|
||||
"properties" : {}
|
||||
})json";
|
||||
|
||||
bool factory_loader<touchable::under_mouse>::operator()(
|
||||
touchable::under_mouse& component,
|
||||
const fill_context& ctx) const
|
||||
{
|
||||
E2D_UNUSED(component, ctx);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool factory_loader<touchable::under_mouse>::operator()(
|
||||
asset_dependencies& dependencies,
|
||||
const collect_context& ctx) const
|
||||
{
|
||||
E2D_UNUSED(dependencies, ctx);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
const char* component_inspector<touchable>::title = "touchable";
|
||||
|
||||
void component_inspector<touchable>::operator()(gcomponent<touchable>& c) const {
|
||||
E2D_UNUSED(c);
|
||||
if ( bool touched = c.owner().component<touchable::touched>().exists();
|
||||
ImGui::Checkbox("touched", &touched) )
|
||||
{
|
||||
if ( touched ) {
|
||||
c.owner().component<touchable::touched>().ensure();
|
||||
} else {
|
||||
c.owner().component<touchable::touched>().remove();
|
||||
}
|
||||
}
|
||||
|
||||
if ( bool under_mouse = c.owner().component<touchable::under_mouse>().exists();
|
||||
ImGui::Checkbox("under_mouse", &under_mouse) )
|
||||
{
|
||||
if ( under_mouse ) {
|
||||
c.owner().component<touchable::under_mouse>().ensure();
|
||||
} else {
|
||||
c.owner().component<touchable::under_mouse>().remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,7 +260,10 @@ namespace e2d
|
||||
.register_component<events<spine_player_events::event>>("spine_player.events")
|
||||
.register_component<commands<spine_player_commands::command>>("spine_player.commands")
|
||||
.register_component<sprite_renderer>("sprite_renderer")
|
||||
.register_component<touchable>("touchable");
|
||||
.register_component<touchable>("touchable")
|
||||
.register_component<touchable::touched>("touchable.touched")
|
||||
.register_component<touchable::under_mouse>("touchable.under_mouse")
|
||||
;
|
||||
|
||||
safe_module_initialize<inspector>()
|
||||
.register_component<actor>("actor")
|
||||
@@ -283,7 +286,10 @@ namespace e2d
|
||||
//.register_component<events<spine_player_events::event>>("spine_player.events")
|
||||
//.register_component<commands<spine_player_commands::command>>("spine_player.commands")
|
||||
.register_component<sprite_renderer>("sprite_renderer")
|
||||
.register_component<touchable>("touchable");
|
||||
.register_component<touchable>("touchable")
|
||||
//.register_component<touchable::touched>("touchable.touched")
|
||||
//.register_component<touchable::under_mouse>("touchable.under_mouse")
|
||||
;
|
||||
|
||||
safe_module_initialize<luasol>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user