|
109 | 109 | }
|
110 | 110 |
|
111 | 111 | 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) |
112 | 128 | class MyDraggable extends JavascriptWidget {
|
113 | 129 | AddChild(x) {
|
114 | 130 | this.SetRootWidget(x)
|
|
117 | 133 | RemoveChild(x) {
|
118 | 134 | this.SetRootWidget(null)
|
119 | 135 | }
|
120 |
| - OnDragOver(geom,event,op) { |
121 |
| - let abs = KismetInputLibrary.GetScreenSpacePosition(event) |
122 |
| - let local = SlateBlueprintLibrary.AbsoluteToLocal(geom,abs) |
123 |
| - return WidgetBlueprintLibrary.Handled() |
124 |
| - } |
125 | 136 | OnDragDetected() {
|
| 137 | + let op = WidgetBlueprintLibrary.CreateDragDropOperation(DragOp_C) |
| 138 | + sprite.SetVisibility('Visible') |
126 | 139 | return {
|
127 | 140 | $: WidgetBlueprintLibrary.Handled(),
|
128 |
| - Operation: WidgetBlueprintLibrary.CreateDragDropOperation(null) |
| 141 | + Operation: op |
129 | 142 | }
|
130 | 143 | }
|
131 | 144 | OnMouseButtonDown(geom,event) {
|
132 |
| - return WidgetBlueprintLibrary.DetectDragIfPressed(event,this,{KeyName:'LeftMouseButton'}) |
| 145 | + mygeom = geom |
| 146 | + return event.DetectDragIfPressed(this,{KeyName:'LeftMouseButton'}) |
133 | 147 | }
|
134 | 148 | }
|
135 | 149 | class MyDropTarget extends JavascriptWidget {
|
|
142 | 156 | }
|
143 | 157 | OnDrop(x) {
|
144 | 158 | console.log('dropped',x)
|
| 159 | + return WidgetBlueprintLibrary.Handled() |
145 | 160 | }
|
146 | 161 | }
|
147 | 162 | let MyDraggable_C = uclass(MyDraggable)
|
148 | 163 | let MyDropTarget_C = uclass(MyDropTarget)
|
149 | 164 | 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 | + ) |
153 | 173 | ),
|
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}) |
156 | 176 | )
|
157 |
| - ) |
| 177 | + ) |
158 | 178 | )
|
159 | 179 | return _ => {
|
160 | 180 | root.remove_child(widget)
|
|
179 | 199 | cur = v(root)
|
180 | 200 | }},UMG.text({},k)
|
181 | 201 | )),
|
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 | + ) |
189 | 211 | )
|
190 | 212 | )
|
191 | 213 | }
|
|
0 commit comments