PDA

View Full Version : Character Portrait problem



earthworm3
April 7th, 2013, 13:19
Hello, i have a problem when i add a portrait to a character sheet when i am a GM, it doesn't work :

--- INTO THE CHARSHEET ---

...
<genericcontrol name="FullPortraitFrame">
<bounds>431,50,63,63</bounds>
<icon>charlist_base</icon>
<tooltip>
<text>Drag and Drop Portrait</text>
</tooltip>
<script file="scripts/charsheet_portrait.lua" />
</genericcontrol>
...

--- INTO A SCRIPT ---



...

function onDrop(x, y, draginfo)
if draginfo.isType("portraitselection") then
setPortrait(window.getDatabaseNode(), draginfo.getStringData());
return true;
end
end


function setPortrait(nodeChar, sPortraitFile)
if not nodeChar or not sPortraitFile then
return;
end

if (User.isHost() == false) then
User.setPortrait(nodeChar, sPortraitFile);
else
local name = nodeChar.getName();
local child = "FullPortraitFrame";
print(node);
DB.findNode("charsheet").getChild(name).getChild(child).setIcon(sPortrait File);
end
end

earthworm3
April 7th, 2013, 14:31
Found an answer, but when the GM creates a character, the Icon is drag and drop but the window isn't updated unless the sheet is closed then opened :



function setPortrait(nodeChar, sPortraitFile)
if not nodeChar or not sPortraitFile then
return;
end
User.setPortrait(nodeChar, sPortraitFile);
wnd = Interface.findWindow("identityselection", "");

if wnd then
for k, v in pairs(wnd.list.getWindows()) do
if v.localdatabasenode then
if v.localdatabasenode == nodeChar then
v.localportrait.setFile(sPortraitFile);
end
end
end
end
end

earthworm3
April 7th, 2013, 17:28
This code does not work :



wnd = Interface.findWindow("identityselection", "");
if wnd then
for k, v in pairs(wnd.list.getWindows()) do
if v.localdatabasenode then
if v.localdatabasenode == nodeChar then
v.localportrait.setFile(sPortraitFile);
end
end
end
end


Any help ???

Trenloe
April 7th, 2013, 17:50
Try

window.update();
at the end of your onDrop code.

earthworm3
April 7th, 2013, 17:58
attempt to call field 'update' (a nil value)

Trenloe
April 7th, 2013, 18:00
attempt to call field 'update' (a nil value)
Show your code please.

earthworm3
April 7th, 2013, 18:03
charsheet_portrait.lua :


local portraitwidget = nil;

function onInit()
if super and super.onInit then
super.onInit();
end
if window.getDatabaseNode() and window.getDatabaseNode().getName() then
if getName() == "FullPortraitFrame" then
-- full-sized portrait
portraitwidget = addBitmapWidget("portrait_" .. window.getDatabaseNode().getName().. "_charlist");
end
end
if portraitwidget and portraitwidget.getBitmap() and window.logo then
window.logo.setVisible(false);
end
end

function onDragStart(button, x, y, dragdata)
local base = nil;
local identityname = window.getDatabaseNode().getName();

dragdata.setType("playercharacter");
dragdata.setTokenData("portrait_" .. identityname .. "_token");
dragdata.setDatabaseNode("charsheet." .. identityname);
dragdata.setStringData(window.name.getValue());

base = dragdata.createBaseData();
base.setType("token");
base.setTokenData("portrait_" .. identityname .. "_token");

return true;
end

function onClickDown(button, x, y)
return true;
end


function onClickRelease(button, x, y)
local nodeChar = window.getDatabaseNode();
if nodeChar then
local wnd = Interface.openWindow("portraitselection", "");
end
end

function onDrop(x, y, draginfo)
if (draginfo.isType("portraitselection"))then
CharManager.setPortrait(window.getDatabaseNode(), draginfo.getStringData());
window.update();
return true;
end
end


manager_char.lua :


function setPortrait(nodeChar, sPortraitFile)

if not nodeChar or not sPortraitFile then
return;
end

User.setPortrait(nodeChar, sPortraitFile);


wnd = Interface.findWindow("identityselection", "");

if wnd then
for k, v in pairs(wnd.list.getWindows()) do
if v.localdatabasenode then
if v.localdatabasenode == nodeChar then
v.localportrait.setFile(sPortraitFile);
end
end
end
end
end

Trenloe
April 7th, 2013, 18:12
Sorry, there's no update code for that window - hence the error.

Once a portrait has been assigned, any changes to that portrait work.

I suggest you have a look at the same code in the 3.5e ruleset (charsheet\scripts\manager_char.lua) to see how it is done there.

earthworm3
April 7th, 2013, 18:13
where is this ruleset ? into library on fg2 website ?

earthworm3
April 7th, 2013, 20:01
thanks i have found it, what is the function "SetLocalNode" ?

Trenloe
April 7th, 2013, 20:57
what is the function "SetLocalNode" ?
It is setting the data source for the window - see the discussion of window data sources here: https://www.fantasygrounds.com/refdoc/windowinstance.xcp

earthworm3
April 7th, 2013, 21:06
i have an error on it : attempt to call field 'SetLocalNode' (a nil value)

Trenloe
April 7th, 2013, 21:14
i have an error on it : attempt to call field 'SetLocalNode' (a nil value)
Everytime you say you get an error, please provide the code you are using. I won't ask again... ;)

earthworm3
April 7th, 2013, 21:17
ok sorry :)

charsheet_portrait.lua


function onInit()
if (User.isLocal() == false) then
local nodeChar = window.getDatabaseNode();
if nodeChar then
local nodeCharName = nodeChar.getName();
if nodeCharName then
window.portrait.setIcon("portrait_" .. nodeCharName .. "_charlist", true);
end
end
else
window.portrait.setVisible(false);
window.localportrait.setVisible(true);
local sPortrait = User.getLocalIdentityPortrait(window.getDatabaseNo de());
if sPortrait then
window.localportrait.setFile(sPortrait);
end
end
end


function onDrop(x, y, draginfo)
if draginfo.isType("portraitselection") then
CharManager.setPortrait(window.getDatabaseNode(), draginfo.getStringData());
return true;
end
end

function onClickDown(button, x, y)
return true;
end

function onClickRelease(button, x, y)
local nodeChar = window.getDatabaseNode();
if nodeChar then
local wnd = Interface.openWindow("portraitselection", "");
if wnd then
wnd.SetLocalNode(nodeChar);
end
end
end


manager_char.lua


function setPortrait(nodeChar, sPortraitFile)
if not nodeChar or not sPortraitFile then
return;
end

User.setPortrait(nodeChar, sPortraitFile);


local wnd = Interface.findWindow("charsheet", nodeChar)
if wnd then
if User.isLocal() then
wnd.localportrait.setFile(sPortraitFile);
else
wnd.portrait.setIcon("portrait_" .. nodeChar.getName() .. "_charlist", true);
end
end

wnd = Interface.findWindow("identityselection", "");
if wnd then
for k, v in pairs(wnd.list.getWindows()) do
if v.localdatabasenode then
if v.localdatabasenode == nodeChar then
v.localportrait.setFile(sPortraitFile);
end
end
end
end
end

earthworm3
April 7th, 2013, 21:42
i'm into charsheet_main not charsheet_toplevel ...

earthworm3
April 7th, 2013, 22:04
With this code the portrait change directly into the sheet but not into character selection :

All in the same page (charsheet_portrait.lua) :


function onDragStart(button, x, y, dragdata)
local base = nil;
local identityname = window.getDatabaseNode().getName();

dragdata.setType("playercharacter");
dragdata.setTokenData("portrait_" .. identityname .. "_token");
dragdata.setDatabaseNode("charsheet." .. identityname);
dragdata.setStringData(window.name.getValue());

base = dragdata.createBaseData();
base.setType("token");
base.setTokenData("portrait_" .. identityname .. "_token");

return true;
end

function onClickDown(button, x, y)
return true;
end

function onInit()
if (User.isLocal() == false) then
local nodeChar = window.getDatabaseNode();
if nodeChar then
local nodeCharName = nodeChar.getName();
if nodeCharName then
window.portrait.setIcon("portrait_" .. nodeCharName .. "_charlist", true);
end
end
else
window.portrait.setVisible(false);
window.localportrait.setVisible(true);
local sPortrait = User.getLocalIdentityPortrait(window.getDatabaseNo de());
if sPortrait then
window.localportrait.setFile(sPortrait);
end
end
end


function onDrop(x, y, draginfo)
if draginfo.isType("portraitselection") then
setPortrait(window.getDatabaseNode(), draginfo.getStringData());
return true;
end
end

function onClickDown(button, x, y)
return true;
end

function onClickRelease(button, x, y)
local nodeChar = window.getDatabaseNode();
if nodeChar then
local wnd = Interface.openWindow("portraitselection", "");
end
end

function setPortrait(nodeChar, sPortraitFile)
if not nodeChar or not sPortraitFile then
return;
end

User.setPortrait(nodeChar, sPortraitFile);


local wnd = Interface.findWindow("charsheet", nodeChar)
if wnd then
if User.isLocal() then
window.localportrait.setFile(sPortraitFile);
else
window.portrait.setIcon("portrait_" .. nodeChar.getName() .. "_charlist", true);
end
end

wnd = Interface.findWindow("identityselection", "");
if wnd then
for k, v in pairs(wnd.list.getWindows()) do
if v.localdatabasenode then
if v.localdatabasenode == nodeChar then
v.localportrait.setFile(sPortraitFile);
end
end
end
end
end


I have deleted SetLocalNode

earthworm3
April 7th, 2013, 22:10
Fixed ! So amazing, thanks Trenloe. :)