-
Notifications
You must be signed in to change notification settings - Fork 382
Open
Labels
Description
Dear RmlUi,
I am trying to implement drag and drop from a Lua API. I registered the Lua API into my context already via Rml::Lua::Initialise()
I am implementing drag and drop from one list on the left to one on the right side to have friends for a match before it starts.
Code for Context in questions below
My rcss has:
...
table img {
drag: clone;
}
...This is my rml code (look at the img data-value part, this is the image I drag):
...
<div id="match_preparation_list_content" class="lists-container">
<div class="minititle-wrapper">
<h3 class="minititle">¡Arrastra el avatar de tres amigos a la lista de la derecha para empezar!</h3>
</div>
<div class="table-container left">
<table>
<thead>
<tr>
<td class="blueish-bold" colspan="2">Amigos disponibles</td>
</tr>
</thead>
<tbody>
<tr data-for="friend, idx : model.availableFriends" >
<td><img data-value="friend.userId" class="miniature" src="overlays/incognito.tga"/></td>
<td>{{friend.nickName}}</td>
</tr>
</tbody>
</table>
</div>
<div id="add-match-friend" class="table-container right"
data-class-blue-selection-border="model.hoveringOverAddFriendTarget">
<table>
<thead>
<tr>
<td class="greenish" colspan="2">Invitados a jugar (faltan 3)</td>
</tr>
</thead>
<tbody id="tbody">
<tr data-for="friend : model.nextMatchFriends " data-value="friend.userId">
<td><img class="miniature" src="overlays/incognito.tga"/></td>
<td>{{friend.nickName}}</td>
</tr>
</tbody>
</table>
</div>
</div>
...My Lua code adds an event listener:
...
rmlui.contexts["main"]:AddEventListener('dragdrop', function(event)
local drag_element = event.parameters.drag_element
LOG:debug('Event: ' .. type(event))
LOG:debug('drag_element type is ' .. type(drag_element))
LOG:debug("Target element id " .. event.target_element.id)
LOG:debug("Current element id " .. event.current_element.id)
LOG:debug("Drag element value " .. drag_element:GetAttribute('data-value'))
end)
startButton:AddEventListener('click', function()
CurrentAction = ExitActions.goToMatch
end)
...Output for drag and drop
When I drag and drop I obtain this output (from my log):
2025-05-30 12:26:29.314] [OnlineRoomsScreen] [debug] [thd 936483] over
[2025-05-30 12:26:29.861] [OnlineRoomsScreen] [debug] [thd 936483] Event: userdata
[2025-05-30 12:26:29.861] [OnlineRoomsScreen] [debug] [thd 936483] drag_element type is userdata
[2025-05-30 12:26:29.861] [OnlineRoomsScreen] [debug] [thd 936483] Target element type is userdata
[2025-05-30 12:26:29.861] [OnlineRoomsScreen] [debug] [thd 936483] Current element type is userdata
[2025-05-30 12:26:29.861] [OnlineRoomsScreen] [debug] [thd 936483] Target element id add-match-friend
[2025-05-30 12:26:29.861] [OnlineRoomsScreen] [debug] [thd 936483] Current element id main
[2025-05-30 12:26:29.861] [Rml] [warning] [thd 936483] [string "LOG = Logger.get("OnlineRoomsScreen")..."]:169: attempt to index a userdata value (local 'drag_element')
stack traceback:
Questions
My problems are basically:
- why current element id is "main", I would expect it to be an empty id, since my img is the dragged element and it does not have any id. However the current element id seems to be where the Event Listener was attached?
- I cannot use the Lua API, it fails and my elements are just opaque 'userdata' without any possibility to invoke the APIs for getting attributes, etc. I would like to get the 'data-value' field in some way for the dragged img, since this is what gives me information about what I dragged.
Thanks for your time!