PDA

View Full Version : Changing FriendFoe icons by Onclick Event?



Jingo
July 20th, 2008, 01:28
I would like to do what I think would be a simple mod to the combat tracker. I want to be able to cycle through the FriendFoe icon by clicking on it. Dragging the little red, green, or yellow face icon from below and dropping it takes a long time, especially so if you're wanting to modify a large group.

I think something in the code section below needs to be changed. But I'm only a wannabe scripter and am not familiar with LUA.

Suggestions on what to do?



<genericcontrol name="friendfoe">
<anchored>
<right>
<parent>activatedefensive</parent>
<anchor>left</anchor>
<offset>-8</offset>
</right>
<top>
<parent>link</parent>
<anchor>top</anchor>
<offset>1</offset>
</top>
<size>
<width>20</width>
<height>20</height>
</size>
</anchored>
<icon>indicator_ctffempty</icon>
<stateicons>
<friend>indicator_ctfffriend</friend>
<neutral>indicator_ctffneutral</neutral>
<foe>indicator_ctfffoe</foe>
</stateicons>
<script>
function onDrop(x, y, draginfo)
if draginfo.isType("combattrackerff") then
state = draginfo.getStringData();
window.setFoF(state);
setIcon(stateicons[1][state][1]);
end
end

function setState(s)
state = s;
window.setFoF(state);
if stateicons[1][state] then
setIcon(stateicons[1][state][1]);
else
setIcon(icon[1]);
end
end
</script>
</genericcontrol>

Foen
July 20th, 2008, 07:03
In the script block you need to add an onClickDown event handler to cycle the state. This is a bit more complex than first blush because the current state value isn't stored locally, but at the containing window level. Furthermore, the state value is a string ('friend','neutral','foe') not a number, so you can't just add 1 to it.

It is a bit clunky, but you could try adding the following:



function onClickDown(button, x, y)
local state = window.getFoF();
if state=='friend' then
state = 'neutral';
elseif state=='neutral' then
state = 'foe';
else
state = 'friend';
end
setState(state);
end


I've not tested it, but you could give it a go.

Cheers

Stuart

Jingo
July 23rd, 2008, 05:42
Tried it but it gave a bunch of errors, something about setting a (nil) value and something about required end at <eof>. Your function's structure looked fine to me, but like I said I don't know LUA at all.

Foen
July 23rd, 2008, 06:15
Sorry, my sloppy programming: "else if" should be "elseif" (one word).

I've tested it now and it seems to do the trick.

Stuart

Jingo
July 23rd, 2008, 17:05
Awesome!!! It does work. Ahhh, that's so much easier then endless drag and drop iterations. Thank you! You are amazing.

Foen
July 23rd, 2008, 18:31
My pleasure!

Welcome to the world of ruleset modification *grin*

Stuart

cbradshaw007
July 28th, 2008, 17:17
What file are you modifing with this code?

Foen
July 28th, 2008, 20:02
It is in utility_combattracker.xml, the combattracker_entry window class.

Stuart

Spyke
August 2nd, 2008, 19:45
That's a neat little feature. I've added it my ruleset. Much obliged :-)

Bidmaron
August 25th, 2008, 03:47
I'm not up to this myself yet, but I get irritated having to drag open books in the module (the double-click on the book works, but why can't you just click the danged thing?). Also, having to drag up the x, checkmark, or whatever to allow the players is irritating. This seems like it should be fixed to do the same kind of thing to cycle through the options (with an extra option of blank maybe).
--Dale--

Griogre
August 25th, 2008, 06:28
Remember this stuff is a one time thing so if you have a main campaign you only need to do it once and the settings are remembered for that campaign. Regardless, because this is part of the Main FG GUI it can't be scripted.

I agree with that whole brown book drag. It has confused more people, double clicking on it like the book icon would have seemed to be a better choice.