|
5 | 5 | const _ = require('lodash')
|
6 | 6 | const uclass = require('uclass')().bind(this,global)
|
7 | 7 |
|
| 8 | + let game_mode, ui_mode |
| 9 | + |
8 | 10 | function tutorial_WebSocket() {
|
9 | 11 | // borrowed from https://developers.google.com/web/updates/2012/06/How-to-convert-ArrayBuffer-to-and-from-String
|
10 | 12 | function ab2str(buf) {
|
|
56 | 58 | }
|
57 | 59 |
|
58 | 60 | function tutorial_StaticMeshActor() {
|
| 61 | + game_mode() |
59 | 62 | console.log('creating a static mesh actor')
|
60 | 63 | class MySMA extends StaticMeshActor {
|
61 | 64 | ctor() {
|
|
68 | 71 | }
|
69 | 72 | let actor = new (uclass(MySMA))(GWorld,{Z:100})
|
70 | 73 | return _ => {
|
| 74 | + ui_mode() |
71 | 75 | actor.DestroyActor()
|
72 | 76 | }
|
73 | 77 | }
|
74 | 78 |
|
75 | 79 | let tutorials = {
|
76 | 80 | 'Static mesh actor' : tutorial_StaticMeshActor,
|
77 |
| - 'Web socket' : tutorial_WebSocket |
| 81 | + 'Web socket' : tutorial_WebSocket, |
| 82 | + 'Draggable' : tutorial_Draggable |
78 | 83 | }
|
79 | 84 |
|
80 | 85 | function Logger() {
|
|
102 | 107 | window : LogWindow
|
103 | 108 | }
|
104 | 109 | }
|
| 110 | + |
| 111 | + function tutorial_Draggable(root) { |
| 112 | + class MyDraggable extends JavascriptWidget { |
| 113 | + AddChild(x) { |
| 114 | + this.SetRootWidget(x) |
| 115 | + return {} |
| 116 | + } |
| 117 | + RemoveChild(x) { |
| 118 | + this.SetRootWidget(null) |
| 119 | + } |
| 120 | + OnDragOver(geom,event,op) { |
| 121 | + let abs = KismetInputLibrary.GetScreenSpacePosition(event) |
| 122 | + let local = SlateBlueprintLibrary.AbsoluteToLocal(geom,abs) |
| 123 | + return WidgetBlueprintLibrary.Handled() |
| 124 | + } |
| 125 | + OnDragDetected() { |
| 126 | + return { |
| 127 | + $: WidgetBlueprintLibrary.Handled(), |
| 128 | + Operation: WidgetBlueprintLibrary.CreateDragDropOperation(null) |
| 129 | + } |
| 130 | + } |
| 131 | + OnMouseButtonDown(geom,event) { |
| 132 | + return WidgetBlueprintLibrary.DetectDragIfPressed(event,this,{KeyName:'LeftMouseButton'}) |
| 133 | + } |
| 134 | + } |
| 135 | + class MyDropTarget extends JavascriptWidget { |
| 136 | + AddChild(x) { |
| 137 | + this.SetRootWidget(x) |
| 138 | + return {} |
| 139 | + } |
| 140 | + RemoveChild(x) { |
| 141 | + this.SetRootWidget(null) |
| 142 | + } |
| 143 | + OnDrop(x) { |
| 144 | + console.log('dropped',x) |
| 145 | + } |
| 146 | + } |
| 147 | + let MyDraggable_C = uclass(MyDraggable) |
| 148 | + let MyDropTarget_C = uclass(MyDropTarget) |
| 149 | + let widget = root.add_child( |
| 150 | + UMG.div({}, |
| 151 | + UMG(MyDraggable_C,{}, |
| 152 | + UMG(Border,{BrushColor:{A:0.5}},"X") |
| 153 | + ), |
| 154 | + UMG(MyDropTarget_C,{}, |
| 155 | + UMG(Border,{BrushColor:{R:1,A:0.5}},"Drop target") |
| 156 | + ) |
| 157 | + ) |
| 158 | + ) |
| 159 | + return _ => { |
| 160 | + root.remove_child(widget) |
| 161 | + } |
| 162 | + } |
105 | 163 |
|
106 | 164 | function app() {
|
107 | 165 | let logger = Logger()
|
108 | 166 |
|
109 |
| - let cur |
| 167 | + let cur, root |
110 | 168 | return UMG.div({$link:elem => {
|
111 | 169 | elem.bye = _ => {
|
112 | 170 | console.log('done')
|
113 | 171 | cur && cur()
|
114 | 172 | logger.destroy()
|
115 | 173 | }
|
| 174 | + cur = tutorial_Draggable(root) |
116 | 175 | }},
|
117 | 176 | _.map(tutorials,(v,k) =>
|
118 | 177 | UMG(Button,{OnClicked:_ => {
|
119 | 178 | cur && cur()
|
120 |
| - cur = v() |
| 179 | + cur = v(root) |
121 | 180 | }},UMG.text({},k)
|
122 | 181 | )),
|
| 182 | + UMG.div({$link:elem => root = elem}), |
123 | 183 | UMG(Border,{
|
124 | 184 | 'Slot.Size.Rule':'Fill',
|
125 | 185 | 'Slot.VerticalAlignment':'VAlign_Bottom',
|
126 | 186 | 'BrushColor':{A:0.5}
|
127 |
| - }, |
| 187 | + }, |
128 | 188 | logger.window()
|
129 | 189 | )
|
130 | 190 | )
|
|
145 | 205 |
|
146 | 206 | widget.SetRootWidget(page)
|
147 | 207 | widget.AddToViewport()
|
148 |
| - |
| 208 | + |
| 209 | + ui_mode = _ => { |
| 210 | + PlayerController.C(PC).bShowMouseCursor = true |
| 211 | + PlayerController.C(PC).SetInputMode_UIOnly(widget,false) |
| 212 | + } |
| 213 | + |
| 214 | + game_mode = _ => { |
| 215 | + PlayerController.C(PC).bShowMouseCursor = true |
| 216 | + PlayerController.C(PC).SetInputMode_GameAndUI(widget,false,false) |
| 217 | + } |
| 218 | + |
| 219 | + ui_mode() |
| 220 | + |
149 | 221 | return function () {
|
150 | 222 | page.bye()
|
151 | 223 | widget.RemoveFromViewport()
|
|
0 commit comments