PDA

View Full Version : Portrait Chat



Tenian
September 11th, 2008, 00:18
I like that chat with portaits shown by Joshua in this thread (https://www.fantasygrounds.com/forums/showthread.php?t=6549)

I also like Xorn's addition of a GM token. So I've worked them both into 4E_JPG. But there is one more thing I'd love to add....

Right now when the GM rolls dice from an NPC it uses the GM portrait, what I'd like to do is use the NPC's token if it's available (or default to the GM if not).

I know displaying it is a matter of setting the icon to be the image. Currently I am setting it in a block of code that looks like this:


if User.isHost() then
msg.icon = "portrait_gm_token"
else
msg.icon = "portrait_" .. User.getCurrentIdentity() .. "_chat";
end


When rolling off the NPC sheet, I can get the NPC's token but it has the form of "/tokens/General/w.png" (if we are using the generic W token). I'm unsure how (if it's even possible) to convert this into the format that icon is expecting.

Foen
September 11th, 2008, 07:45
I'm not sure either, sorry. I think the string is an icon resource name (from graphics.xml etc) not a path name, and I'm not sure how you can convert one to the other.

The 'wrong' way to do it would be to strip the path and extension from the file name, but that assumes that icon resources are always defined that way, and it is an unsafe assumption.

Stuart

Tenian
September 11th, 2008, 12:29
I played around with it some more. For clients it uses a string in the format:
portrait_id-00001_chat

I can use the getID() function to build a similar string (getID() gives me npc.id-00001 or combattracker.id-00001) plugging these in just returns no icon.

Any idea where to look in the reference library for instructions on how the graphics/tokens work?

The combat tracker and NPC sheets both display exactly what I am looking for, so there should be some way to replicate it..... If I knew what I was looking for I might be able to figure out how to steal it :)

Foen
September 11th, 2008, 19:35
If you have access to the source object (combat tracker entry or NPC entry) you should be able to use the getPrototype() function on the underlying token control.

For example, in a d20 combat tracker entry, the token control is called "token" so you can use the following code snippet (assuming win is a reference to the combat tracker entry you are copying from):



local ref = win.token.getPrototype();


Have a look at the documentation here (https://www.fantasygrounds.com/refdoc/tokencontrol.xcp).

Cheers

Foen

Tenian
September 11th, 2008, 22:28
Apparently the only thing you can set on a message is "icon" containing the icon resource name for the desired icon.

In graphics.xml you can define icons with the
<icon name="xxx" file="zzz" />
syntax

What I'd like to do is somehow change the file of the icon so it can be dynamically set. I can get the filename but I can't for the life of me figure out how to alter an existing icon or just create a new one on the fly.


So I began to explore the User object. This has a function:
setPortrait( identity, portraitfile )

So I should be able to set the portrait based on the token file (easy for me to get). But the when the User.isHost() then User.getCurrentIdentity() comes back as a null...

Once again I am stuck...

Foen
September 12th, 2008, 05:49
I have to say it looks a bit intractible. The chat messages can only take an icon and you can only dynamically manipulate a token. Character portraits are a special (read 'fudge') case, where the FG engine assigns an icon to each character identity based on a token path, but it looks like the host cannot own identities.

:(

Tenian
September 12th, 2008, 11:14
Yeah, I've pretty much written this dream off for now. Shame because I think it would have been a nice extension.

I did notice there's several options involving local identities. I pondered creating a local ID, assigning it a portrait and then blowing it away after the message was sent but that seemed really hacky.

joshuha
September 12th, 2008, 13:54
You could just write a script that will spit out an XML file that could declare all your tokens as icons.

Tenian
September 12th, 2008, 14:07
Wouldn't that mean that everyone who used the ruleset would have to populate their own icon file based off the tokens they have?

For me that would be pretty trivial, but I'd like it to remain easy for the end user. I suppose I could roll it into the MM Parse program since adding tokens has already been requested as a feature.

I haven't worked with the icons/graphics all that much so forgive me if this obvious, could the XML file declaring the icons be within the module itself or would it have to be within the ruleset?

Foen
September 12th, 2008, 14:41
You'd have to amend the ruleset (which is where the icons are declared) every time you added a new token, which seems excessive. However, you wouldn't have to worry about the client end, as they would download the patched ruleset when they next connected.

Foen

Tenian
September 12th, 2008, 14:59
Well by end user I actually meant people using the ruleset to run games other than myself.

I think that's a little much to ask users to do

joshuha
September 12th, 2008, 17:19
Well in theory you could make a program that renames the FG shortcut, runs your program to check for new tokens before FG loads, creates a new icon XML file, then boots up FG heh. A little excessive but would work in theory.

I would put in a request for the ability to create resources like icons and frame definitions on startup based off a LUA file that generates the XML programatically.

Tenian
September 12th, 2008, 18:13
That does seem a bit extreme :)

I'll add a request to create resources :)