PDA

View Full Version : A Table of Checkbox Types?



PneumaPilot
November 15th, 2008, 20:56
Okay, so I'm trying to make my nWoD character sheet a little more dynamic. I have a row of colored beads like this that I hope to one day allow the character sheet to change to enable new fields/remove old fields to match a given 'module' in the World of Darkness.

https://i208.photobucket.com/albums/bb309/PneumaPilot/GameLine.jpg

Now, to begin with, I just want to get these beads working so that when I click on one, it lights up and any other lit up bead goes dark. This state information also needs to be saved since the character sheet will be built onInit to match the selected state.

For this task, I have chosen to (one again) modify the checkbox control. One part of that is easy - just create a copy of the control, rename it, and change which icons are associated with the state information. Now, I can do that the hard way: make a new template control for each different colored bead, but it seems like there ought to be an easier way.

I've noticed in the template script for checkbox that there is apparently some array of icons. It calls stateicons[1].on[1] and the like. It seems like there ought to be a way to simplify this whole thing for the gameline beads where all of them fit in one control template. Does anyone know anything about this?

Foen
November 15th, 2008, 22:19
My initial guess would be to have different icons for each bead, but to link all of them to the same underlying db node. The beads would then have a selected/not-selected icon each, and a unique selected-value (which would be saved in the underlying field if that bead is selected).

If each bead registers a handler for its link-update event, it should just check to see if the new value is (or isn't) the same as its selected-value.

Foen

PneumaPilot
November 15th, 2008, 22:37
Foen, I'm sorry, but I don't understand much of what you said.

I haven't linked any of my previous checkboxes to the db. They all just sort of work without doing that, so I haven't done it. I also have never used a link-update event on any of my previous checkboxes, except the ones in the combat tracker, but that was for a different reason.

After looking back over the code again from template_checkbox.lua and common_templates.xml, I think that I am going to have to create a separate checkbox template for each bead. For instance, I don't see anything in the way that the icon data is stored in common_templates.xml that would allow me to indicate a certain subclass of checkbox in the control definition.

What I was hoping for was something like "<checkbox[2] name="vampire">", but I don't think that's possible.

PneumaPilot
November 15th, 2008, 23:21
Okay, I got it working. I did create a separate template_checkbox clone for each type of bead and then changed the update method to look like this:


function update()
if source then
if source.getValue() ~= 0 then
setIcon(stateicons[1].on[1]);
window.ishunter.setState(false);
window.ismortal.setState(false);
window.ismage.setState(false);
window.iswerewolf.setState(false);
window.ischangeling.setState(false);
window.ispromethean.setState(false);
window.isspirit.setState(false);
else
setIcon(stateicons[1].off[1]);
end
else
if sourcelessvalue then
setIcon(stateicons[1].on[1]);
else
setIcon(stateicons[1].off[1]);
end
end

if self.onValueChanged then
self.onValueChanged();
end
end


That way, whenever you click on one of the beads, any other lit one goes off. There is only one potential problem with this code and that is that someone can turn one bead off without turning another one on. That should be easy to solve, though.

Now, I have to figure out how to make the character sheet build itself onInit based on these bead states and how to change onUpdate when a bead changes.