-
April 20th, 2020, 07:41 #1
Image.selectToken() during a Token.onClickDown()
I am attempting to have have the default token selection be the one that has "active" initiative if there is a pile of tokens.
I've setup Token.onClickDown = onClickDownADND; and that code is something alone these lines.
Code:function onClickDownADND( target, button, image ) -- if host and not pressing control (targeting) if not Input.isControlPressed() then -- click left mouse on token if button == 1 then local ctwnd = nil; local windowPath = nil if User.isHost() then ctwnd = Interface.findWindow("combattracker_host", "combattracker"); if ctwnd then windowPath = ctwnd.combatants.subwindow.list; end; else ctwnd = Interface.findWindow("combattracker_client", "combattracker"); if ctwnd then windowPath = ctwnd.list; end; end if ctwnd then local nodeCT = CombatManager.getCTFromToken(target); if nodeCT then -- Debug.console("manager_token_adnd.lua","onClickDownADND","target",target); for _, oToken in pairs(image.getTokens()) do -- otoken is in a pile with selected token/target if oToken.getPosition() == target.getPosition() then Debug.console("manager_token_adnd.lua","onClickDownADND","oToken",oToken); local nodeCT = CombatManager.getCTFromToken(oToken); if nodeCT then Debug.console("manager_token_adnd.lua","onClickDownADND","nodeCT",nodeCT); local bActive = (DB.getValue(nodeCT, "active", 0) == 1); Debug.console("manager_token_adnd.lua","onClickDownADND","bActive",bActive); if bActive then Debug.console("manager_token_adnd.lua","onClickDownADND","image.getSelectedTokens()",image.getSelectedTokens()); image.clearSelectedTokens(); image.selectToken(oToken, true); Debug.console("manager_token_adnd.lua","onClickDownADND","image.getSelectedTokens()",image.getSelectedTokens()); return true; end end end end -- end -- nodeCT entry didn't exist for token on map end end end end
What is the proper process to unselected/select a "selected" token programmatically ?---
Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
Documentation for AD&D 2E ruleset.
Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.
-
April 20th, 2020, 08:12 #2
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,566
The mouse event calls on tokens do not work the same as controls (registered handlers can events); and multiple handlers can be assigned to each mouse action by different scripts.
This means that the default behavior is still called after the handlers are run. You won’t be able to override the default behavior with the current implementation.
Regards,
JPG
-
April 20th, 2020, 16:04 #3
- Join Date
- Jun 2018
- Posts
- 112
You will need to check if the token clicked on is the current “active” token
Then unselect all, run threw the list at the current position, and select the token wanted (but not the one clicked on), then lastly replace the token initially clicked on and lastly return true
Hope that helps and makes sense... that was the first version of token stack resolution I did... and it has become much more complicated now... but that is the source for making this all work
The real key is to “hold” the original token until you finish resolving the stackLast edited by Diablobob; April 20th, 2020 at 16:16.
-
April 21st, 2020, 17:59 #4
With some help from @Diablobob I was able to resolve my issue... it's a end run around to get it to work but it works. I'd much prefer just being able to selectToken(). Hopefully down the road in FGU we can have more flexibility to do that.
Here is a code snippet that works. This version is restricted to just the host. You'll want to make sure it's only run when you want it (when clicked down, not control-clicked/etc).
Code:--[[ Select a specific token in a pile of tokens. Used to push a token to the top of a pile and set as selected. ]]-- function selectTokenInPile(tokenToSelect) if User.isHost() then local imageControl = ImageManager.getImageControl(tokenToSelect, true); if imageControl then local positionTarget = tokenToSelect.getPosition(); imageControl.clearSelectedTokens(); for _, oToken in pairs(imageControl.getTokens()) do -- otoken is ontop of selected target if oToken.getPosition() == positionTarget then local nodeCT = CombatManager.getCTFromToken(oToken); if nodeCT then if tokenToSelect == oToken then imageControl.selectToken(oToken, true); else CombatManager.replaceCombatantToken(nodeCT,nil); end end end end return true; end end return false; end
---
Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
Documentation for AD&D 2E ruleset.
Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks