feat: modules moved and engine moved to submodule
This commit is contained in:
parent
dfb5e645cd
commit
c33d2130cc
5136 changed files with 225275 additions and 64485 deletions
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef ANIMATABLE_BODY_2D_H
|
||||
#define ANIMATABLE_BODY_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/physics/static_body_2d.h"
|
||||
|
||||
|
|
@ -57,5 +56,3 @@ private:
|
|||
void set_sync_to_physics(bool p_enable);
|
||||
bool is_sync_to_physics_enabled() const;
|
||||
};
|
||||
|
||||
#endif // ANIMATABLE_BODY_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef AREA_2D_H
|
||||
#define AREA_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "core/templates/vset.h"
|
||||
#include "scene/2d/physics/collision_object_2d.h"
|
||||
|
|
@ -198,5 +197,3 @@ public:
|
|||
};
|
||||
|
||||
VARIANT_ENUM_CAST(Area2D::SpaceOverride);
|
||||
|
||||
#endif // AREA_2D_H
|
||||
|
|
|
|||
|
|
@ -409,7 +409,7 @@ void CharacterBody2D::_set_collision_direction(const PhysicsServer2D::MotionResu
|
|||
on_wall = true;
|
||||
wall_normal = p_result.collision_normal;
|
||||
// Don't apply wall velocity when the collider is a CharacterBody2D.
|
||||
if (Object::cast_to<CharacterBody2D>(ObjectDB::get_instance(p_result.collider_id)) == nullptr) {
|
||||
if (ObjectDB::get_instance<CharacterBody2D>(p_result.collider_id) == nullptr) {
|
||||
_set_platform_data(p_result);
|
||||
}
|
||||
}
|
||||
|
|
@ -509,7 +509,7 @@ Ref<KinematicCollision2D> CharacterBody2D::_get_slide_collision(int p_bounce) {
|
|||
}
|
||||
|
||||
Ref<KinematicCollision2D> CharacterBody2D::_get_last_slide_collision() {
|
||||
if (motion_results.size() == 0) {
|
||||
if (motion_results.is_empty()) {
|
||||
return Ref<KinematicCollision2D>();
|
||||
}
|
||||
return _get_slide_collision(motion_results.size() - 1);
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef CHARACTER_BODY_2D_H
|
||||
#define CHARACTER_BODY_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/physics/kinematic_collision_2d.h"
|
||||
#include "scene/2d/physics/physics_body_2d.h"
|
||||
|
|
@ -168,5 +167,3 @@ protected:
|
|||
|
||||
VARIANT_ENUM_CAST(CharacterBody2D::MotionMode);
|
||||
VARIANT_ENUM_CAST(CharacterBody2D::PlatformOnLeave);
|
||||
|
||||
#endif // CHARACTER_BODY_2D_H
|
||||
|
|
|
|||
|
|
@ -295,7 +295,7 @@ uint32_t CollisionObject2D::create_shape_owner(Object *p_owner) {
|
|||
ShapeData sd;
|
||||
uint32_t id;
|
||||
|
||||
if (shapes.size() == 0) {
|
||||
if (shapes.is_empty()) {
|
||||
id = 0;
|
||||
} else {
|
||||
id = shapes.back()->key() + 1;
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef COLLISION_OBJECT_2D_H
|
||||
#define COLLISION_OBJECT_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
#include "scene/main/viewport.h"
|
||||
|
|
@ -175,5 +174,3 @@ public:
|
|||
};
|
||||
|
||||
VARIANT_ENUM_CAST(CollisionObject2D::DisableMode);
|
||||
|
||||
#endif // COLLISION_OBJECT_2D_H
|
||||
|
|
|
|||
|
|
@ -157,8 +157,8 @@ void CollisionPolygon2D::_notification(int p_what) {
|
|||
|
||||
Vector<Vector2> pts = {
|
||||
line_to + Vector2(0, tsize),
|
||||
line_to + Vector2(Math_SQRT12 * tsize, 0),
|
||||
line_to + Vector2(-Math_SQRT12 * tsize, 0)
|
||||
line_to + Vector2(Math::SQRT12 * tsize, 0),
|
||||
line_to + Vector2(-Math::SQRT12 * tsize, 0)
|
||||
};
|
||||
|
||||
Vector<Color> cols{ dcol, dcol, dcol };
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef COLLISION_POLYGON_2D_H
|
||||
#define COLLISION_POLYGON_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -92,5 +91,3 @@ public:
|
|||
};
|
||||
|
||||
VARIANT_ENUM_CAST(CollisionPolygon2D::BuildMode);
|
||||
|
||||
#endif // COLLISION_POLYGON_2D_H
|
||||
|
|
|
|||
|
|
@ -120,8 +120,8 @@ void CollisionShape2D::_notification(int p_what) {
|
|||
|
||||
Vector<Vector2> pts{
|
||||
line_to + Vector2(0, tsize),
|
||||
line_to + Vector2(Math_SQRT12 * tsize, 0),
|
||||
line_to + Vector2(-Math_SQRT12 * tsize, 0)
|
||||
line_to + Vector2(Math::SQRT12 * tsize, 0),
|
||||
line_to + Vector2(-Math::SQRT12 * tsize, 0)
|
||||
};
|
||||
|
||||
Vector<Color> cols{ draw_col, draw_col, draw_col };
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef COLLISION_SHAPE_2D_H
|
||||
#define COLLISION_SHAPE_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
#include "scene/resources/2d/shape_2d.h"
|
||||
|
|
@ -91,5 +90,3 @@ public:
|
|||
|
||||
CollisionShape2D();
|
||||
};
|
||||
|
||||
#endif // COLLISION_SHAPE_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef DAMPED_SPRING_JOINT_2D_H
|
||||
#define DAMPED_SPRING_JOINT_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/physics/joints/joint_2d.h"
|
||||
|
||||
|
|
@ -63,5 +62,3 @@ public:
|
|||
|
||||
DampedSpringJoint2D();
|
||||
};
|
||||
|
||||
#endif // DAMPED_SPRING_JOINT_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef GROOVE_JOINT_2D_H
|
||||
#define GROOVE_JOINT_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/physics/joints/joint_2d.h"
|
||||
|
||||
|
|
@ -55,5 +54,3 @@ public:
|
|||
|
||||
GrooveJoint2D();
|
||||
};
|
||||
|
||||
#endif // GROOVE_JOINT_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef JOINT_2D_H
|
||||
#define JOINT_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -80,5 +79,3 @@ public:
|
|||
Joint2D();
|
||||
~Joint2D();
|
||||
};
|
||||
|
||||
#endif // JOINT_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef PIN_JOINT_2D_H
|
||||
#define PIN_JOINT_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/physics/joints/joint_2d.h"
|
||||
|
||||
|
|
@ -67,5 +66,3 @@ public:
|
|||
|
||||
PinJoint2D();
|
||||
};
|
||||
|
||||
#endif // PIN_JOINT_2D_H
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ real_t KinematicCollision2D::get_depth() const {
|
|||
}
|
||||
|
||||
Object *KinematicCollision2D::get_local_shape() const {
|
||||
PhysicsBody2D *owner = Object::cast_to<PhysicsBody2D>(ObjectDB::get_instance(owner_id));
|
||||
PhysicsBody2D *owner = ObjectDB::get_instance<PhysicsBody2D>(owner_id);
|
||||
if (!owner) {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef KINEMATIC_COLLISION_2D_H
|
||||
#define KINEMATIC_COLLISION_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "core/object/ref_counted.h"
|
||||
#include "servers/physics_server_2d.h"
|
||||
|
|
@ -63,5 +62,3 @@ public:
|
|||
int get_collider_shape_index() const;
|
||||
Vector2 get_collider_velocity() const;
|
||||
};
|
||||
|
||||
#endif // KINEMATIC_COLLISION_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef PHYSICAL_BONE_2D_H
|
||||
#define PHYSICAL_BONE_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/physics/rigid_body_2d.h"
|
||||
#include "scene/2d/skeleton_2d.h"
|
||||
|
|
@ -84,5 +83,3 @@ public:
|
|||
PhysicalBone2D();
|
||||
~PhysicalBone2D();
|
||||
};
|
||||
|
||||
#endif // PHYSICAL_BONE_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef PHYSICS_BODY_2D_H
|
||||
#define PHYSICS_BODY_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/physics/collision_object_2d.h"
|
||||
#include "scene/2d/physics/kinematic_collision_2d.h"
|
||||
|
|
@ -56,5 +55,3 @@ public:
|
|||
void add_collision_exception_with(Node *p_node); //must be physicsbody
|
||||
void remove_collision_exception_with(Node *p_node);
|
||||
};
|
||||
|
||||
#endif // PHYSICS_BODY_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef RAY_CAST_2D_H
|
||||
#define RAY_CAST_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
|
|
@ -105,5 +104,3 @@ public:
|
|||
|
||||
RayCast2D();
|
||||
};
|
||||
|
||||
#endif // RAY_CAST_2D_H
|
||||
|
|
|
|||
|
|
@ -498,6 +498,7 @@ bool RigidBody2D::is_sleeping() const {
|
|||
}
|
||||
|
||||
void RigidBody2D::set_max_contacts_reported(int p_amount) {
|
||||
ERR_FAIL_INDEX_MSG(p_amount, MAX_CONTACTS_REPORTED_2D_MAX, "Max contacts reported allocates memory (about 100 bytes each), and therefore must not be set too high.");
|
||||
max_contacts_reported = p_amount;
|
||||
PhysicsServer2D::get_singleton()->body_set_max_contacts_reported(get_rid(), p_amount);
|
||||
}
|
||||
|
|
@ -643,7 +644,7 @@ PackedStringArray RigidBody2D::get_configuration_warnings() const {
|
|||
|
||||
PackedStringArray warnings = PhysicsBody2D::get_configuration_warnings();
|
||||
|
||||
if (ABS(t.columns[0].length() - 1.0) > 0.05 || ABS(t.columns[1].length() - 1.0) > 0.05) {
|
||||
if (Math::abs(t.columns[0].length() - 1.0) > 0.05 || Math::abs(t.columns[1].length() - 1.0) > 0.05) {
|
||||
warnings.push_back(RTR("Size changes to RigidBody2D will be overridden by the physics engine when running.\nChange the size in children collision shapes instead."));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef RIGID_BODY_2D_H
|
||||
#define RIGID_BODY_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "core/templates/vset.h"
|
||||
#include "scene/2d/physics/physics_body_2d.h"
|
||||
|
|
@ -246,5 +245,3 @@ VARIANT_ENUM_CAST(RigidBody2D::FreezeMode);
|
|||
VARIANT_ENUM_CAST(RigidBody2D::CenterOfMassMode);
|
||||
VARIANT_ENUM_CAST(RigidBody2D::DampMode);
|
||||
VARIANT_ENUM_CAST(RigidBody2D::CCDMode);
|
||||
|
||||
#endif // RIGID_BODY_2D_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef SHAPE_CAST_2D_H
|
||||
#define SHAPE_CAST_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
#include "scene/resources/2d/shape_2d.h"
|
||||
|
|
@ -122,5 +121,3 @@ public:
|
|||
|
||||
ShapeCast2D();
|
||||
};
|
||||
|
||||
#endif // SHAPE_CAST_2D_H
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include "static_body_2d.h"
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
#include "scene/resources/2d/capsule_shape_2d.h"
|
||||
#include "scene/resources/2d/circle_shape_2d.h"
|
||||
#include "scene/resources/2d/concave_polygon_shape_2d.h"
|
||||
|
|
@ -38,6 +39,7 @@
|
|||
#include "scene/resources/2d/navigation_polygon.h"
|
||||
#include "scene/resources/2d/rectangle_shape_2d.h"
|
||||
#include "servers/navigation_server_2d.h"
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
Callable StaticBody2D::_navmesh_source_geometry_parsing_callback;
|
||||
RID StaticBody2D::_navmesh_source_geometry_parser;
|
||||
|
|
@ -89,6 +91,7 @@ void StaticBody2D::_reload_physics_characteristics() {
|
|||
}
|
||||
}
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
void StaticBody2D::navmesh_parse_init() {
|
||||
ERR_FAIL_NULL(NavigationServer2D::get_singleton());
|
||||
if (!_navmesh_source_geometry_parser.is_valid()) {
|
||||
|
|
@ -156,7 +159,7 @@ void StaticBody2D::navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p
|
|||
const real_t capsule_radius = capsule_shape->get_radius();
|
||||
|
||||
Vector<Vector2> shape_outline;
|
||||
const real_t turn_step = Math_TAU / 12.0;
|
||||
const real_t turn_step = Math::TAU / 12.0;
|
||||
shape_outline.resize(14);
|
||||
int shape_outline_inx = 0;
|
||||
for (int i = 0; i < 12; i++) {
|
||||
|
|
@ -181,7 +184,7 @@ void StaticBody2D::navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p
|
|||
int circle_edge_count = 12;
|
||||
shape_outline.resize(circle_edge_count);
|
||||
|
||||
const real_t turn_step = Math_TAU / real_t(circle_edge_count);
|
||||
const real_t turn_step = Math::TAU / real_t(circle_edge_count);
|
||||
for (int i = 0; i < circle_edge_count; i++) {
|
||||
shape_outline.write[i] = static_body_xform.xform(Vector2(Math::cos(i * turn_step), Math::sin(i * turn_step)) * circle_radius);
|
||||
}
|
||||
|
|
@ -213,6 +216,7 @@ void StaticBody2D::navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
void StaticBody2D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_constant_linear_velocity", "vel"), &StaticBody2D::set_constant_linear_velocity);
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef STATIC_BODY_2D_H
|
||||
#define STATIC_BODY_2D_H
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/physics/physics_body_2d.h"
|
||||
|
||||
|
|
@ -64,12 +63,12 @@ private:
|
|||
static Callable _navmesh_source_geometry_parsing_callback;
|
||||
static RID _navmesh_source_geometry_parser;
|
||||
|
||||
#ifndef NAVIGATION_2D_DISABLED
|
||||
public:
|
||||
static void navmesh_parse_init();
|
||||
static void navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, Node *p_node);
|
||||
#endif // NAVIGATION_2D_DISABLED
|
||||
|
||||
private:
|
||||
void _reload_physics_characteristics();
|
||||
};
|
||||
|
||||
#endif // STATIC_BODY_2D_H
|
||||
|
|
|
|||
454
engine/scene/2d/physics/touch_screen_button.cpp
Normal file
454
engine/scene/2d/physics/touch_screen_button.cpp
Normal file
|
|
@ -0,0 +1,454 @@
|
|||
/**************************************************************************/
|
||||
/* touch_screen_button.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "touch_screen_button.h"
|
||||
|
||||
#include "scene/main/viewport.h"
|
||||
|
||||
void TouchScreenButton::set_texture_normal(const Ref<Texture2D> &p_texture) {
|
||||
if (texture_normal == p_texture) {
|
||||
return;
|
||||
}
|
||||
if (texture_normal.is_valid()) {
|
||||
texture_normal->disconnect(CoreStringName(changed), callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw));
|
||||
}
|
||||
texture_normal = p_texture;
|
||||
if (texture_normal.is_valid()) {
|
||||
texture_normal->connect(CoreStringName(changed), callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw), CONNECT_REFERENCE_COUNTED);
|
||||
}
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
Ref<Texture2D> TouchScreenButton::get_texture_normal() const {
|
||||
return texture_normal;
|
||||
}
|
||||
|
||||
void TouchScreenButton::set_texture_pressed(const Ref<Texture2D> &p_texture_pressed) {
|
||||
if (texture_pressed == p_texture_pressed) {
|
||||
return;
|
||||
}
|
||||
if (texture_pressed.is_valid()) {
|
||||
texture_pressed->disconnect(CoreStringName(changed), callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw));
|
||||
}
|
||||
texture_pressed = p_texture_pressed;
|
||||
if (texture_pressed.is_valid()) {
|
||||
texture_pressed->connect(CoreStringName(changed), callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw), CONNECT_REFERENCE_COUNTED);
|
||||
}
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
Ref<Texture2D> TouchScreenButton::get_texture_pressed() const {
|
||||
return texture_pressed;
|
||||
}
|
||||
|
||||
void TouchScreenButton::set_bitmask(const Ref<BitMap> &p_bitmask) {
|
||||
bitmask = p_bitmask;
|
||||
}
|
||||
|
||||
Ref<BitMap> TouchScreenButton::get_bitmask() const {
|
||||
return bitmask;
|
||||
}
|
||||
|
||||
void TouchScreenButton::set_shape(const Ref<Shape2D> &p_shape) {
|
||||
if (shape == p_shape) {
|
||||
return;
|
||||
}
|
||||
if (shape.is_valid()) {
|
||||
shape->disconnect_changed(callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw));
|
||||
}
|
||||
shape = p_shape;
|
||||
if (shape.is_valid()) {
|
||||
shape->connect_changed(callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw));
|
||||
}
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
Ref<Shape2D> TouchScreenButton::get_shape() const {
|
||||
return shape;
|
||||
}
|
||||
|
||||
void TouchScreenButton::set_shape_centered(bool p_shape_centered) {
|
||||
shape_centered = p_shape_centered;
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
bool TouchScreenButton::is_shape_visible() const {
|
||||
return shape_visible;
|
||||
}
|
||||
|
||||
void TouchScreenButton::set_shape_visible(bool p_shape_visible) {
|
||||
shape_visible = p_shape_visible;
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
bool TouchScreenButton::is_shape_centered() const {
|
||||
return shape_centered;
|
||||
}
|
||||
|
||||
void TouchScreenButton::_accessibility_action_click(const Variant &p_data) {
|
||||
_press(0);
|
||||
_release();
|
||||
}
|
||||
|
||||
void TouchScreenButton::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_ACCESSIBILITY_UPDATE: {
|
||||
RID ae = get_accessibility_element();
|
||||
ERR_FAIL_COND(ae.is_null());
|
||||
|
||||
Rect2 dst_rect(Point2(), texture_normal.is_valid() ? texture_normal->get_size() : Size2());
|
||||
|
||||
DisplayServer::get_singleton()->accessibility_update_set_role(ae, DisplayServer::AccessibilityRole::ROLE_BUTTON);
|
||||
|
||||
DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_CLICK, callable_mp(this, &TouchScreenButton::_accessibility_action_click));
|
||||
|
||||
DisplayServer::get_singleton()->accessibility_update_set_transform(ae, get_transform());
|
||||
DisplayServer::get_singleton()->accessibility_update_set_bounds(ae, dst_rect);
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_DRAW: {
|
||||
if (!is_inside_tree()) {
|
||||
return;
|
||||
}
|
||||
if (!Engine::get_singleton()->is_editor_hint() && !DisplayServer::get_singleton()->is_touchscreen_available() && visibility == VISIBILITY_TOUCHSCREEN_ONLY) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (finger_pressed != -1) {
|
||||
if (texture_pressed.is_valid()) {
|
||||
draw_texture(texture_pressed, Point2());
|
||||
} else if (texture_normal.is_valid()) {
|
||||
draw_texture(texture_normal, Point2());
|
||||
}
|
||||
|
||||
} else {
|
||||
if (texture_normal.is_valid()) {
|
||||
draw_texture(texture_normal, Point2());
|
||||
}
|
||||
}
|
||||
|
||||
if (!shape_visible) {
|
||||
return;
|
||||
}
|
||||
if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) {
|
||||
return;
|
||||
}
|
||||
if (shape.is_valid()) {
|
||||
Color draw_col = get_tree()->get_debug_collisions_color();
|
||||
|
||||
Vector2 pos;
|
||||
if (shape_centered && texture_normal.is_valid()) {
|
||||
pos = texture_normal->get_size() * 0.5;
|
||||
}
|
||||
|
||||
draw_set_transform_matrix(get_canvas_transform().translated_local(pos));
|
||||
shape->draw(get_canvas_item(), draw_col);
|
||||
}
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
if (!Engine::get_singleton()->is_editor_hint() && !DisplayServer::get_singleton()->is_touchscreen_available() && visibility == VISIBILITY_TOUCHSCREEN_ONLY) {
|
||||
return;
|
||||
}
|
||||
queue_redraw();
|
||||
|
||||
if (!Engine::get_singleton()->is_editor_hint()) {
|
||||
set_process_input(is_visible_in_tree());
|
||||
}
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
if (is_pressed()) {
|
||||
_release(true);
|
||||
}
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_VISIBILITY_CHANGED: {
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
break;
|
||||
}
|
||||
if (is_visible_in_tree()) {
|
||||
set_process_input(true);
|
||||
} else {
|
||||
set_process_input(false);
|
||||
if (is_pressed()) {
|
||||
_release();
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_SUSPENDED:
|
||||
case NOTIFICATION_PAUSED: {
|
||||
if (is_pressed()) {
|
||||
_release();
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
bool TouchScreenButton::is_pressed() const {
|
||||
return finger_pressed != -1;
|
||||
}
|
||||
|
||||
void TouchScreenButton::set_action(const String &p_action) {
|
||||
action = p_action;
|
||||
}
|
||||
|
||||
String TouchScreenButton::get_action() const {
|
||||
return action;
|
||||
}
|
||||
|
||||
void TouchScreenButton::input(const Ref<InputEvent> &p_event) {
|
||||
ERR_FAIL_COND(p_event.is_null());
|
||||
|
||||
if (!is_visible_in_tree()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const InputEventScreenTouch *st = Object::cast_to<InputEventScreenTouch>(*p_event);
|
||||
|
||||
if (passby_press) {
|
||||
const InputEventScreenDrag *sd = Object::cast_to<InputEventScreenDrag>(*p_event);
|
||||
|
||||
if (st && !st->is_pressed() && finger_pressed == st->get_index()) {
|
||||
_release();
|
||||
}
|
||||
|
||||
if ((st && st->is_pressed()) || sd) {
|
||||
int index = st ? st->get_index() : sd->get_index();
|
||||
Point2 coord = st ? st->get_position() : sd->get_position();
|
||||
|
||||
if (finger_pressed == -1 || index == finger_pressed) {
|
||||
if (_is_point_inside(coord)) {
|
||||
if (finger_pressed == -1) {
|
||||
_press(index);
|
||||
}
|
||||
} else {
|
||||
if (finger_pressed != -1) {
|
||||
_release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (st) {
|
||||
if (st->is_pressed()) {
|
||||
const bool can_press = finger_pressed == -1;
|
||||
if (!can_press) {
|
||||
return; //already fingering
|
||||
}
|
||||
|
||||
if (_is_point_inside(st->get_position())) {
|
||||
_press(st->get_index());
|
||||
}
|
||||
} else {
|
||||
if (st->get_index() == finger_pressed) {
|
||||
_release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool TouchScreenButton::_is_point_inside(const Point2 &p_point) {
|
||||
Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(p_point);
|
||||
|
||||
bool touched = false;
|
||||
bool check_rect = true;
|
||||
|
||||
if (shape.is_valid()) {
|
||||
check_rect = false;
|
||||
|
||||
Vector2 pos;
|
||||
if (shape_centered && texture_normal.is_valid()) {
|
||||
pos = texture_normal->get_size() * 0.5;
|
||||
}
|
||||
|
||||
touched = shape->collide(Transform2D().translated_local(pos), unit_rect, Transform2D(0, coord + Vector2(0.5, 0.5)));
|
||||
}
|
||||
|
||||
if (bitmask.is_valid()) {
|
||||
check_rect = false;
|
||||
if (!touched && Rect2(Point2(), bitmask->get_size()).has_point(coord)) {
|
||||
if (bitmask->get_bitv(coord)) {
|
||||
touched = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!touched && check_rect) {
|
||||
if (texture_normal.is_valid()) {
|
||||
touched = Rect2(Size2(), texture_normal->get_size()).has_point(coord);
|
||||
}
|
||||
}
|
||||
|
||||
return touched;
|
||||
}
|
||||
|
||||
void TouchScreenButton::_press(int p_finger_pressed) {
|
||||
finger_pressed = p_finger_pressed;
|
||||
|
||||
if (action != StringName()) {
|
||||
Input::get_singleton()->action_press(action);
|
||||
Ref<InputEventAction> iea;
|
||||
iea.instantiate();
|
||||
iea->set_action(action);
|
||||
iea->set_pressed(true);
|
||||
get_viewport()->push_input(iea, true);
|
||||
}
|
||||
|
||||
emit_signal(SceneStringName(pressed));
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
void TouchScreenButton::_release(bool p_exiting_tree) {
|
||||
finger_pressed = -1;
|
||||
|
||||
if (action != StringName()) {
|
||||
Input::get_singleton()->action_release(action);
|
||||
if (!p_exiting_tree) {
|
||||
Ref<InputEventAction> iea;
|
||||
iea.instantiate();
|
||||
iea->set_action(action);
|
||||
iea->set_pressed(false);
|
||||
get_viewport()->push_input(iea, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (!p_exiting_tree) {
|
||||
emit_signal(SNAME("released"));
|
||||
queue_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
Rect2 TouchScreenButton::_edit_get_rect() const {
|
||||
if (texture_normal.is_null()) {
|
||||
return CanvasItem::_edit_get_rect();
|
||||
}
|
||||
|
||||
return Rect2(Size2(), texture_normal->get_size());
|
||||
}
|
||||
|
||||
bool TouchScreenButton::_edit_use_rect() const {
|
||||
return texture_normal.is_valid();
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
Rect2 TouchScreenButton::get_anchorable_rect() const {
|
||||
if (texture_normal.is_null()) {
|
||||
return CanvasItem::get_anchorable_rect();
|
||||
}
|
||||
|
||||
return Rect2(Size2(), texture_normal->get_size());
|
||||
}
|
||||
|
||||
void TouchScreenButton::set_visibility_mode(VisibilityMode p_mode) {
|
||||
visibility = p_mode;
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
TouchScreenButton::VisibilityMode TouchScreenButton::get_visibility_mode() const {
|
||||
return visibility;
|
||||
}
|
||||
|
||||
void TouchScreenButton::set_passby_press(bool p_enable) {
|
||||
passby_press = p_enable;
|
||||
}
|
||||
|
||||
bool TouchScreenButton::is_passby_press_enabled() const {
|
||||
return passby_press;
|
||||
}
|
||||
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
bool TouchScreenButton::_set(const StringName &p_name, const Variant &p_value) {
|
||||
if (p_name == CoreStringName(normal)) { // Compatibility with Godot 3.x.
|
||||
set_texture_normal(p_value);
|
||||
return true;
|
||||
} else if (p_name == SceneStringName(pressed)) { // Compatibility with Godot 3.x.
|
||||
set_texture_pressed(p_value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif // DISABLE_DEPRECATED
|
||||
|
||||
void TouchScreenButton::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_texture_normal", "texture"), &TouchScreenButton::set_texture_normal);
|
||||
ClassDB::bind_method(D_METHOD("get_texture_normal"), &TouchScreenButton::get_texture_normal);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_texture_pressed", "texture"), &TouchScreenButton::set_texture_pressed);
|
||||
ClassDB::bind_method(D_METHOD("get_texture_pressed"), &TouchScreenButton::get_texture_pressed);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_bitmask", "bitmask"), &TouchScreenButton::set_bitmask);
|
||||
ClassDB::bind_method(D_METHOD("get_bitmask"), &TouchScreenButton::get_bitmask);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_shape", "shape"), &TouchScreenButton::set_shape);
|
||||
ClassDB::bind_method(D_METHOD("get_shape"), &TouchScreenButton::get_shape);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_shape_centered", "bool"), &TouchScreenButton::set_shape_centered);
|
||||
ClassDB::bind_method(D_METHOD("is_shape_centered"), &TouchScreenButton::is_shape_centered);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_shape_visible", "bool"), &TouchScreenButton::set_shape_visible);
|
||||
ClassDB::bind_method(D_METHOD("is_shape_visible"), &TouchScreenButton::is_shape_visible);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_action", "action"), &TouchScreenButton::set_action);
|
||||
ClassDB::bind_method(D_METHOD("get_action"), &TouchScreenButton::get_action);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_visibility_mode", "mode"), &TouchScreenButton::set_visibility_mode);
|
||||
ClassDB::bind_method(D_METHOD("get_visibility_mode"), &TouchScreenButton::get_visibility_mode);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_passby_press", "enabled"), &TouchScreenButton::set_passby_press);
|
||||
ClassDB::bind_method(D_METHOD("is_passby_press_enabled"), &TouchScreenButton::is_passby_press_enabled);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("is_pressed"), &TouchScreenButton::is_pressed);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_normal", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture_normal", "get_texture_normal");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_pressed", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture_pressed", "get_texture_pressed");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "bitmask", PROPERTY_HINT_RESOURCE_TYPE, "BitMap"), "set_bitmask", "get_bitmask");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape2D"), "set_shape", "get_shape");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shape_centered"), "set_shape_centered", "is_shape_centered");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shape_visible"), "set_shape_visible", "is_shape_visible");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "passby_press"), "set_passby_press", "is_passby_press_enabled");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "action"), "set_action", "get_action");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "visibility_mode", PROPERTY_HINT_ENUM, "Always,TouchScreen Only"), "set_visibility_mode", "get_visibility_mode");
|
||||
|
||||
ADD_SIGNAL(MethodInfo("pressed"));
|
||||
ADD_SIGNAL(MethodInfo("released"));
|
||||
|
||||
BIND_ENUM_CONSTANT(VISIBILITY_ALWAYS);
|
||||
BIND_ENUM_CONSTANT(VISIBILITY_TOUCHSCREEN_ONLY);
|
||||
}
|
||||
|
||||
TouchScreenButton::TouchScreenButton() {
|
||||
unit_rect.instantiate();
|
||||
unit_rect->set_size(Vector2(1, 1));
|
||||
}
|
||||
119
engine/scene/2d/physics/touch_screen_button.h
Normal file
119
engine/scene/2d/physics/touch_screen_button.h
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
/**************************************************************************/
|
||||
/* touch_screen_button.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
#include "scene/resources/2d/rectangle_shape_2d.h"
|
||||
#include "scene/resources/bit_map.h"
|
||||
#include "scene/resources/texture.h"
|
||||
|
||||
class TouchScreenButton : public Node2D {
|
||||
GDCLASS(TouchScreenButton, Node2D);
|
||||
|
||||
public:
|
||||
enum VisibilityMode {
|
||||
VISIBILITY_ALWAYS,
|
||||
VISIBILITY_TOUCHSCREEN_ONLY
|
||||
};
|
||||
|
||||
private:
|
||||
Ref<Texture2D> texture_normal;
|
||||
Ref<Texture2D> texture_pressed;
|
||||
Ref<BitMap> bitmask;
|
||||
Ref<Shape2D> shape;
|
||||
bool shape_centered = true;
|
||||
bool shape_visible = true;
|
||||
|
||||
Ref<RectangleShape2D> unit_rect;
|
||||
|
||||
StringName action;
|
||||
bool passby_press = false;
|
||||
int finger_pressed = -1;
|
||||
|
||||
VisibilityMode visibility = VISIBILITY_ALWAYS;
|
||||
|
||||
virtual void input(const Ref<InputEvent> &p_event) override;
|
||||
|
||||
bool _is_point_inside(const Point2 &p_point);
|
||||
|
||||
void _press(int p_finger_pressed);
|
||||
void _release(bool p_exiting_tree = false);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
bool _set(const StringName &p_name, const Variant &p_value);
|
||||
#endif // DISABLE_DEPRECATED
|
||||
|
||||
void _accessibility_action_click(const Variant &p_data);
|
||||
|
||||
public:
|
||||
#ifdef DEBUG_ENABLED
|
||||
virtual Rect2 _edit_get_rect() const override;
|
||||
virtual bool _edit_use_rect() const override;
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
void set_texture_normal(const Ref<Texture2D> &p_texture);
|
||||
Ref<Texture2D> get_texture_normal() const;
|
||||
|
||||
void set_texture_pressed(const Ref<Texture2D> &p_texture_pressed);
|
||||
Ref<Texture2D> get_texture_pressed() const;
|
||||
|
||||
void set_bitmask(const Ref<BitMap> &p_bitmask);
|
||||
Ref<BitMap> get_bitmask() const;
|
||||
|
||||
void set_shape(const Ref<Shape2D> &p_shape);
|
||||
Ref<Shape2D> get_shape() const;
|
||||
|
||||
void set_shape_centered(bool p_shape_centered);
|
||||
bool is_shape_centered() const;
|
||||
|
||||
void set_shape_visible(bool p_shape_visible);
|
||||
bool is_shape_visible() const;
|
||||
|
||||
void set_action(const String &p_action);
|
||||
String get_action() const;
|
||||
|
||||
void set_passby_press(bool p_enable);
|
||||
bool is_passby_press_enabled() const;
|
||||
|
||||
void set_visibility_mode(VisibilityMode p_mode);
|
||||
VisibilityMode get_visibility_mode() const;
|
||||
|
||||
bool is_pressed() const;
|
||||
|
||||
virtual Rect2 get_anchorable_rect() const override;
|
||||
|
||||
TouchScreenButton();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(TouchScreenButton::VisibilityMode);
|
||||
Loading…
Add table
Add a link
Reference in a new issue