mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Create condition to know when a draggable object was just dropped (#4441)
This commit is contained in:
@@ -28,13 +28,11 @@ class GD_EXTENSION_API DraggableBehavior : public gd::Behavior {
|
||||
return new DraggableBehavior(*this);
|
||||
}
|
||||
|
||||
#if defined(GD_IDE_ONLY)
|
||||
virtual std::map<gd::String, gd::PropertyDescriptor> GetProperties(
|
||||
const gd::SerializerElement& behaviorContent) const override;
|
||||
virtual bool UpdateProperty(gd::SerializerElement& behaviorContent,
|
||||
const gd::String& name,
|
||||
const gd::String& value) override;
|
||||
#endif
|
||||
|
||||
virtual void InitializeContent(
|
||||
gd::SerializerElement& behaviorContent) override;
|
||||
|
@@ -34,10 +34,9 @@ void DeclareDraggableBehaviorExtension(gd::PlatformExtension& extension) {
|
||||
std::make_shared<DraggableBehavior>(),
|
||||
std::shared_ptr<gd::BehaviorsSharedData>());
|
||||
|
||||
#if defined(GD_IDE_ONLY)
|
||||
aut.AddCondition("Dragged",
|
||||
_("Being dragged"),
|
||||
_("Check if the object is being dragged"),
|
||||
_("Check if the object is being dragged."),
|
||||
_("_PARAM0_ is being dragged"),
|
||||
"",
|
||||
"CppPlatform/Extensions/draggableicon24.png",
|
||||
@@ -46,5 +45,16 @@ void DeclareDraggableBehaviorExtension(gd::PlatformExtension& extension) {
|
||||
.AddParameter("object", _("Object"))
|
||||
.AddParameter("behavior", _("Behavior"), "Draggable")
|
||||
.SetFunctionName("IsDragged");
|
||||
#endif
|
||||
|
||||
aut.AddCondition("Dropped",
|
||||
_("Was just dropped"),
|
||||
_("Check if the object was just dropped after being dragged."),
|
||||
_("_PARAM0_ was just dropped"),
|
||||
"",
|
||||
"CppPlatform/Extensions/draggableicon24.png",
|
||||
"CppPlatform/Extensions/draggableicon16.png")
|
||||
|
||||
.AddParameter("object", _("Object"))
|
||||
.AddParameter("behavior", _("Behavior"), "Draggable")
|
||||
.SetFunctionName("WasJustDropped");
|
||||
}
|
||||
|
@@ -4,7 +4,6 @@ GDevelop - Draggable Behavior Extension
|
||||
Copyright (c) 2014-2016 Florian Rival (Florian.Rival@gmail.com)
|
||||
This project is released under the MIT License.
|
||||
*/
|
||||
#if defined(GD_IDE_ONLY)
|
||||
#include "GDCore/Extensions/PlatformExtension.h"
|
||||
#include "GDCore/Tools/Localization.h"
|
||||
|
||||
@@ -32,6 +31,11 @@ class DraggableBehaviorJsExtension : public gd::PlatformExtension {
|
||||
.SetFunctionName("isDragged")
|
||||
.SetIncludeFile(
|
||||
"Extensions/DraggableBehavior/draggableruntimebehavior.js");
|
||||
GetAllConditionsForBehavior(
|
||||
"DraggableBehavior::Draggable")["DraggableBehavior::Dropped"]
|
||||
.SetFunctionName("wasJustDropped")
|
||||
.SetIncludeFile(
|
||||
"Extensions/DraggableBehavior/draggableruntimebehavior.js");
|
||||
GD_COMPLETE_EXTENSION_COMPILATION_INFORMATION();
|
||||
};
|
||||
};
|
||||
@@ -49,4 +53,3 @@ extern "C" gd::PlatformExtension* GD_EXTENSION_API CreateGDJSExtension() {
|
||||
return new DraggableBehaviorJsExtension;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
@@ -15,6 +15,7 @@ namespace gdjs {
|
||||
*/
|
||||
_draggedByDraggableManager: DraggableManager | null = null;
|
||||
_checkCollisionMask: boolean;
|
||||
_justDropped = false;
|
||||
|
||||
constructor(
|
||||
instanceContainer: gdjs.RuntimeInstanceContainer,
|
||||
@@ -41,6 +42,7 @@ namespace gdjs {
|
||||
_endDrag() {
|
||||
if (this._draggedByDraggableManager) {
|
||||
this._draggedByDraggableManager.endDrag();
|
||||
this._justDropped = true;
|
||||
}
|
||||
this._draggedByDraggableManager = null;
|
||||
}
|
||||
@@ -126,11 +128,17 @@ namespace gdjs {
|
||||
.getGame()
|
||||
.getInputManager()
|
||||
.isMouseButtonPressed(0);
|
||||
|
||||
this._justDropped = false;
|
||||
}
|
||||
|
||||
isDragged(instanceContainer: gdjs.RuntimeInstanceContainer): boolean {
|
||||
isDragged(): boolean {
|
||||
return !!this._draggedByDraggableManager;
|
||||
}
|
||||
|
||||
wasJustDropped(): boolean {
|
||||
return this._justDropped;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user