PDA

View Full Version : 2.2.0 Feature: Custom Pointers



Goblin-King
September 12th, 2008, 08:29
The 2.2.0 version of Fantasy Grounds allows the definition of custom pointer types in the ruleset. You can create any shape that can be defined using a series of spline curves defined using four control points.

488

To accomplish this, you need to include a <pointertypes> element in your imagecontrol definition:


<pointertypes>
<arrow>
<icon>pointer</icon>
<label>Draw Arrow</label>
</arrow>
<custom name="my_cone">
<icon>pointer_cone</icon>
<label>Draw Cone</label>
</custom>
</pointertypes>
Doing this resets the selection of pointer types. If you want to preserve the original selection of pointer types, use the subelements arrow, circle, rectangle or cone (the example adds the basic arrow). The custom element adds a new type.

When pointers of a custom type are created or modified, a new script event will be fired to build the list of control points.


function transformSpline(spline, angle, centerx, centery)
for segmentindex, segment in ipairs(spline) do
for controlpointindex, controlpoint in ipairs(segment) do
local x = controlpoint[1];
local y = controlpoint[2];

local nx = (x-centerx) * math.cos(angle) -
(y-centery) * math.sin(angle) + centerx;
local ny = (x-centerx) * math.sin(angle) +
(y-centery) * math.cos(angle) + centery;

segment[controlpointindex] = { nx, ny };
end
end
end

function onBuildCustomPointer(startx, starty, endx, endy, type)
local segments = {};
local distpos;
local drawarrow;

local u = 32;
if hasGrid() then
u = getGridSize();
end
local angle = math.atan2(endx - startx, - endy + starty);

if type == "my_cone" then
-- Build a cone facing in the negative y direction
local segment = { { startx, starty },
{ startx, starty },
{ startx - 1.5*u, starty - 6.5*u },
{ startx - 1.5*u, starty - 7.5*u } };
table.insert(segments, segment);
local segment = { { startx - 1.5*u, starty - 7.5*u },
{ startx - 1.5*u, starty - 8.25*u },
{ startx - 0.75*u, starty - 9*u },
{ startx, starty - 9*u } };
table.insert(segments, segment);
local segment = { { startx, starty },
{ startx, starty },
{ startx + 1.5*u, starty - 6.5*u },
{ startx + 1.5*u, starty - 7.5*u } };
table.insert(segments, segment);
local segment = { { startx + 1.5*u, starty - 7.5*u },
{ startx + 1.5*u, starty - 8.25*u },
{ startx + 0.75*u, starty - 9*u },
{ startx, starty - 9*u } };
table.insert(segments, segment);

-- Set the distance indicator position (in pixels)
distpos = { 30, 30 };
end

-- Transform it to match angle
transformSpline(segments, angle, startx, starty);

return segments, distpos, drawarrow;
end

The script snippet provides a useful utility function that allows you to make the definition for the shape in the negative y direction (i.e. up) and transform it to match the orientation of the pointer.

The onBuildCustomPointer event can return three values. The first is the list of spline segments, the second is a table of two values that specify where the length of the pointer should be drawn relative to its origin (given by onMeasurePointer), and the third a boolean value indicating whether to end the pointer with an arrowhead pointing in the direction of the last segment.

Please keep in mind that very complex shapes can cause performance issues on slower computers.

Custom pointers don't support grid shading at this time, we're looking into this possibility.

Grix
April 13th, 2009, 19:09
Unless I'm missing something, this is the ever elusive Savage Worlds Cone. If so, thank you very much (a bit late).

I consider myself relatively PC savvy but I'm no programmer or custom ruleset guy, and delving into enough about XML and LUA to do this would probably just make me very, very dangerous to myself and others.

I was hoping that someone might know if this was going to be appearing in the Savage Worlds ruleset any time soon?

If not, then is there something out there like "An Idiot's Guide to Adding the Savage Worlds Cone Template to FGII"?

If not, I might be willing to take a hack at it, but ideally someone in the know would... well, know :)

Thanks!
-Grix (the XML villiage idiot)

Thore_Ironrock
April 14th, 2009, 14:46
Unless I'm missing something, this is the ever elusive Savage Worlds Cone. If so, thank you very much (a bit late).

I consider myself relatively PC savvy but I'm no programmer or custom ruleset guy, and delving into enough about XML and LUA to do this would probably just make me very, very dangerous to myself and others.

I was hoping that someone might know if this was going to be appearing in the Savage Worlds ruleset any time soon?

If not, then is there something out there like "An Idiot's Guide to Adding the Savage Worlds Cone Template to FGII"?

If not, I might be willing to take a hack at it, but ideally someone in the know would... well, know :)

Thanks!
-Grix (the XML villiage idiot)

We are currently evaluating an update to the SW ruleset, and will take this request into consideration.

Grix
April 14th, 2009, 16:08
We are currently evaluating an update to the SW ruleset, and will take this request into consideration.

I couldn't ask for anything more. Thank you!