Skip to content

Commit 55f95b2

Browse files
committed
edited drag drop example
1 parent 77cdd05 commit 55f95b2

File tree

1 file changed

+42
-20
lines changed

1 file changed

+42
-20
lines changed

Examples/Content/Scripts/helloJS.js

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,22 @@
109109
}
110110

111111
function tutorial_Draggable(root) {
112+
let sprite
113+
let mygeom
114+
class DragOp extends DragDropOperation {
115+
Dragged(event) {
116+
let pos = UPointerEvent.C(event).GetScreenSpacePosition()
117+
pos = Geometry.C(mygeom).AbsoluteToLocal(pos)
118+
sprite.Slot.SetPosition(pos)
119+
}
120+
Drop(event) {
121+
sprite.SetVisibility('Hidden')
122+
}
123+
DragCancelled(event) {
124+
sprite.SetVisibility('Hidden')
125+
}
126+
}
127+
let DragOp_C = uclass(DragOp)
112128
class MyDraggable extends JavascriptWidget {
113129
AddChild(x) {
114130
this.SetRootWidget(x)
@@ -117,19 +133,17 @@
117133
RemoveChild(x) {
118134
this.SetRootWidget(null)
119135
}
120-
OnDragOver(geom,event,op) {
121-
let abs = KismetInputLibrary.GetScreenSpacePosition(event)
122-
let local = SlateBlueprintLibrary.AbsoluteToLocal(geom,abs)
123-
return WidgetBlueprintLibrary.Handled()
124-
}
125136
OnDragDetected() {
137+
let op = WidgetBlueprintLibrary.CreateDragDropOperation(DragOp_C)
138+
sprite.SetVisibility('Visible')
126139
return {
127140
$: WidgetBlueprintLibrary.Handled(),
128-
Operation: WidgetBlueprintLibrary.CreateDragDropOperation(null)
141+
Operation: op
129142
}
130143
}
131144
OnMouseButtonDown(geom,event) {
132-
return WidgetBlueprintLibrary.DetectDragIfPressed(event,this,{KeyName:'LeftMouseButton'})
145+
mygeom = geom
146+
return event.DetectDragIfPressed(this,{KeyName:'LeftMouseButton'})
133147
}
134148
}
135149
class MyDropTarget extends JavascriptWidget {
@@ -142,19 +156,25 @@
142156
}
143157
OnDrop(x) {
144158
console.log('dropped',x)
159+
return WidgetBlueprintLibrary.Handled()
145160
}
146161
}
147162
let MyDraggable_C = uclass(MyDraggable)
148163
let MyDropTarget_C = uclass(MyDropTarget)
149164
let widget = root.add_child(
150-
UMG.div({},
151-
UMG(MyDraggable_C,{},
152-
UMG(Border,{BrushColor:{A:0.5}},"X")
165+
UMG(Overlay,{'Slot.Size.Rule':'Fill','VerticalAlignment':'VAlign_Fill'},
166+
UMG.div({'Slot.HorizontalAlignment':'HAlign_Fill'},
167+
UMG(MyDraggable_C,{},
168+
UMG(Border,{BrushColor:{A:0.5}},"X")
169+
),
170+
UMG(MyDropTarget_C,{},
171+
UMG(Border,{BrushColor:{R:1,A:0.5}},"Drop target")
172+
)
153173
),
154-
UMG(MyDropTarget_C,{},
155-
UMG(Border,{BrushColor:{R:1,A:0.5}},"Drop target")
174+
UMG(CanvasPanel,{'Slot.HorizontalAlignment':'HAlign_Fill','Slot.VerticalAlignment':'VAlign_Fill'},
175+
UMG(Border,{Visibility:'Hidden',$link:elem => sprite = elem})
156176
)
157-
)
177+
)
158178
)
159179
return _ => {
160180
root.remove_child(widget)
@@ -179,13 +199,15 @@
179199
cur = v(root)
180200
}},UMG.text({},k)
181201
)),
182-
UMG.div({$link:elem => root = elem}),
183-
UMG(Border,{
184-
'Slot.Size.Rule':'Fill',
185-
'Slot.VerticalAlignment':'VAlign_Bottom',
186-
'BrushColor':{A:0.5}
187-
},
188-
logger.window()
202+
UMG(Overlay,{'Slot.Size.Rule':'Fill'},
203+
UMG.div({'Slot.HorizontalAlignment':'HAlign_Fill','Slot.VerticalAlignment':'VAlign_Fill',$link:elem => root = elem}),
204+
UMG(Border,{
205+
'Slot.HorizontalAlignment':'HAlign_Fill',
206+
'Slot.VerticalAlignment':'VAlign_Bottom',
207+
'BrushColor':{A:0.5}
208+
},
209+
logger.window()
210+
)
189211
)
190212
)
191213
}

0 commit comments

Comments
 (0)