PDA

View Full Version : Using the <token> data as an icon



The Crusader of Metal
August 22nd, 2011, 02:51
So, following my idea from here (https://www.fantasygrounds.com/forums/showthread.php?p=113408), I started developing such an extension. I got pretty far but hit a roadblock. I can get the <token> value from the npc which is speaking. This value is from type token which I found no documentation, but its value is something on the likes of: tokens/host/Portraits/port001.JPG

If I try to pass this value to the field icon of the message object, nothing appears on the chat, not even the GM logo. I believe it is because this is just a prototype for a token and not an actual one which can be used as an icon, right? Is there a way I can create such an icon to be used?

I just changed the chat_entry.lua file, which follows:

--
-- Please see the license.html file included with this distribution for
-- attribution and copyright information.
--

function onInit()
ChatManager.registerEntryControl(self);
end

function onDeliverMessage(msg, mode)
if mode == "chat" then
local bOptPCHT = OptionsManager.isOption("PCHT", "on");
if User.isHost() then
gmid, isgm = GmIdentityManager.getCurrent();
msg.sender = gmid;
if isgm then
msg.font = "chatgmfont";
if bOptPCHT then
msg.icon = "portrait_gm_token";
end
else
msg.font = "chatnpcfont";
if bOptPCHT then
local token = findNPCPortrait(msg.sender);
if token then
msg.icon = token;
else
msg.icon = "portrait_gm_token";
end
end
end
else
if bOptPCHT then
local sCurrentId = User.getCurrentIdentity();
if sCurrentId then
msg.icon = "portrait_" .. sCurrentId .. "_chat";
end
end
end
elseif mode == "emote" then
if User.isHost() then
local gmid, isgm = GmIdentityManager.getCurrent();
if not isgm then
msg.sender = "";
msg.text = gmid .. " " .. msg.text;
end
end
end
return msg;
end

function findNPCPortrait(npcName)
local rootNode = DB.findNode("npc");
if rootNode then
local npcs = rootNode.getChildren();
if not npcs then
return nil;
end
for npcKey, npc in pairs(npcs) do
local name = npc.getChild("name");
if name then
if name.getText() == npcName then
local token = npc.getChild("token").getValue();
if token then
return token;
end
end
end
end
end
return nil;
end

function onTab()
ChatManager.doAutocomplete();
end

Zeus
August 22nd, 2011, 08:05
So, following my idea from here (https://www.fantasygrounds.com/forums/showthread.php?p=113408), I started developing such an extension. I got pretty far but hit a roadblock. I can get the <token> value from the npc which is speaking. This value is from type token which I found no documentation, but its value is something on the likes of: tokens/host/Portraits/port001.JPG

The name of the control is 'token' but it's type is a tokenfield (tokencontrol). See here (https://www.fantasygrounds.com/refdoc/tokencontrol.xcp) more library information on the control and its methods. To get the string name of the token path and file name, use the method getPrototype().


If I try to pass this value to the field icon of the message object, nothing appears on the chat, not even the GM logo. I believe it is because this is just a prototype for a token and not an actual one which can be used as an icon, right? Is there a way I can create such an icon to be used?

Essentially correct. Messages accept the string name of an icon which in turn are registered in the ruleset using the notation:


<icon name="exampleicon" file="graphics/icons/some_icon.png" />

Icons are usually registered in one of the various graphics.xml files in the ruleset folder. I am not aware of a method of creating icons during runtime so I believe these would have to be defined in the ruleset files before the campaign is instantiated and loaded.

Tokencontrols on the other hand use strings to define the path and filename of the image file containing the token graphic, whilst Portraits can be referenced in place of icons using something like the following:


msg.icon = "portrait_" .. nodeofpccharsheet.getName() .. "_chat";

However Portraits are not supported for NPCs, only PCs, I think to change this would require a change to FGII itself (not 100% sure though).

The Crusader of Metal
August 23rd, 2011, 03:32
Thanks for the answer DrZeuss, I found your explanations really really useful!

What I did after posting to get it working was that I used an user just to create characters with the same name of the npcs, so I could get the portrait using the exact same idea you showed there. But unfortunately that is a little bit confusing so I don't feel like releasing an extension like this one.


The name of the control is 'token' but it's type is a tokenfield (tokencontrol). See here (https://../refdoc/tokencontrol.xcp) more library information on the control and its methods. To get the string name of the token path and file name, use the method getPrototype().I am not sure about it because I used the getType() method in the node and it returned 'token'. Also while looking into the page you linked I found this method populateFromImageNode, that I thought would instantiate and create a new image which could be used. Unfortunately it returns an error message saying that this function is nil, so I really think it is of the 'token' type and not of the 'tokencontrol'.

The <icon> idea is pretty nice, I liked it! The only problem would be needing to add all of the portraits to the extension before hand.

I am thinking about following the pseudo-pc idea though, would feel like a workaround but at least I wouldn't need to redistribute the extension everytime I added new entries.

Or if some dev could explain if it is possible to generate portraits for NPCs ... :D