PDA

View Full Version : Radio Button?



Oberoten
January 1st, 2009, 23:45
I have a windowlist for my weaponry stats on the character-sheet. This works really well except for one thing... I want to be able to pull an initiative to the CT.

So I need to be able to create a radiobutton control that can only be active in one entry at a time.

What would be the easiest way to get this to work and just send the clicked value to a hidden value on the charactersheet that'd then be droppable to the CT?

- Obe

Foen
January 2nd, 2009, 06:46
I think I need to understand a bit more about your requirement Obe: the standard tracker has a 'turn' indicator which is only active for one entry at a time. Is it something like that you need? And how does that link baack to the character sheet?

Perhaps you could describe the sequence of event you want to occur when you are using this radio button?

Cheers

Stuart

Oberoten
January 2nd, 2009, 09:11
What makes this complex is that the initiative is calculated from the skill used so there are 3 different windowlists it could source from. I have figured out how to link a stat from charactersheet to CT, but I want some way of selecting which active skill/melee-weapon or ranged weapon it should show the initiative for.

I am thinking to just have a hidden field somewhere on the charactersheet that gets populated with the initative value when you click down on a skill's checkbox. Easy enough so far.

But I need to uncheck all the other skills and weapons checkboxes when the skill IS marked. This is what stumps me. I never really learned how to iterate over several windowlists.

- Obe

Foen
January 3rd, 2009, 08:37
OK, this may not help your particular case, but I've written a radiobutton template control.

First the easy bit:


Add to your common_templates.xml file:
<template name="radiobutton">
<genericcontrol>
<stateicons>
<on>indicator_checkon</on>
<off>indicator_checkoff</off>
</stateicons>
<script file="scripts/template_radiobutton.lua" />
</genericcontrol>
</template>


Now the script bit:


create in its own new file, in scripts/template_radiobutton.lua:
-- This file is provided under the Open Game License version 1.0a
-- For more information on OGL and related issues, see
-- https://www.wizards.com/d20

-- All producers of work derived from this definition are adviced to
-- familiarize themselves with the above license, and to take special
-- care in providing the definition of Product Identity (as specified
-- by the OGL) in their products.

-- Copyright 2008 SmiteWorks Ltd.

local buttonvalue = "";
local defaultvalue = false;
local sourcenode = nil;
local readonlyvalue = false;

function onInit()
setIcon(stateicons[1].off[1]);
if source and source[1] then
sourcenode = window.getDatabaseNode().createChild(source[1],"string");
end
if value and value[1] then
buttonvalue = value[1];
end
if default then
defaultvalue = true;
end
if sourcenode then
sourcenode.onUpdate = refresh;
readonlyvalue = sourcenode.isStatic();
end
if readonly then
readonlyvalue = true;
end
if defaultvalue and buttonvalue~="" and sourcenode and sourcenode.getValue()=="" then
activate();
end
refresh();
end

function onClickDown(button, x, y)
return (not readonlyvalue);
end

function onClickRelease()
activate();
end

function activate()
if not readonlyvalue and sourcenode and buttonvalue~="" and sourcenode.getValue()~=buttonvalue then
sourcenode.setValue(buttonvalue);
end
end

function refresh()
if sourcenode and buttonvalue~="" and sourcenode.getValue()==buttonvalue then
setIcon(stateicons[1].on[1]);
else
setIcon(stateicons[1].off[1]);
end
end

function getResult()
if sourcenode then
return sourcenode.getValue();
else
return "";
end
end

function getValue()
return buttonvalue;
end

function setValue(value)
buttonvalue = value;
refresh();
end

function isReadOnly()
return readonlyvalue;
end

function setReadOnly(state)
if sourcenode and sourcenode.isStatic() then
return;
end
if state then
readonlyvalue = true;
else
readonlyvalue = false;
end
end

function isDefault()
return defaultvalue;
end


Phew! To use it, you must designate a database node which is common to all the radio buttons in a group, each button must have a unique 'value' associated with it (so you can check which one has been selected) and one of them can have the 'default' tag declared. Here is a small example used in the Labyrinth Lord ruleset:



<radiobutton name="checkspells">
<bounds>56,-20,12,12</bounds>
<source>skills.displaytype</source>
<value>spells</value>
</radiobutton>
<stringcontrol>
<bounds>70,-20,70,12</bounds>
<static>Spell User</static>
<font>sheetlabelsmall</font>
<script>
function onClickDown(...)
return window.checkspells.onClickDown(...);
end
function onClickRelease()
window.checkspells.activate();
end
</script>
</stringcontrol>
<radiobutton name="checkthief">
<bounds>156,-20,12,12</bounds>
<source>skills.displaytype</source>
<value>thief</value>
</radiobutton>
<stringcontrol>
<bounds>170,-20,70,12</bounds>
<static>Thief</static>
<font>sheetlabelsmall</font>
<script>
function onClickDown(...)
return window.checkthief.onClickDown(...);
end
function onClickRelease()
window.checkthief.activate();
end
</script>
</stringcontrol>
<radiobutton name="checknormal">
<bounds>256,-20,12,12</bounds>
<source>skills.displaytype</source>
<value>normal</value>
<default/>
</radiobutton>
<stringcontrol>
<bounds>270,-20,70,12</bounds>
<static>Normal</static>
<font>sheetlabelsmall</font>
<script>
function onClickDown(...)
return window.checknormal.onClickDown(...);
end
function onClickRelease()
window.checknormal.activate();
end
</script>
</stringcontrol>


I have added string control labels next to each radio button (they don't have them by default) and the small bit of script in each of them allows a user to click on the labels and not just the button itself.

The code supports read-only radio buttons (in response to static database nodes or an explicit <readonly> tag), and some simple methods to get and set the readonly, default and value attributes. Note that you can either query the underlying database node to determine which radio button is selected, or you can call getResult() on any of the radio buttons themselves. Calling getValue() returns the value associated with that button, not the value of the overall result.

Hope that helps!

Stuart

Oberoten
January 3rd, 2009, 09:32
Would it be okay to post this on the Wiki?

- Obe

Foen
January 3rd, 2009, 10:09
No problem - it is offered freely (subject to OGL, as it is based on Smite Works' checkbox template).

Stuart

Oberoten
January 3rd, 2009, 11:06
Many thanks. :) This is the kind of thing the Wiki really needs.

- Obe