PDA

View Full Version : Problem getting checkbox icons to display



Lithl
June 7th, 2009, 03:05
I'm currently building an Exalted character sheet, starting from the nWoD ruleset as a base, as it's the nearest thing to what I want. As part of the sheet, I've got two kinds of "checkbox" widgets: one is circular, and is unmodified from the nWoD ruleset. The other is square, and is a modified version of a checkbox widget in the nWoD ruleset.

My problem is that at some point during my flailing around in XML is that these checkboxes stopped displaying until they're clicked on. So, when the character sheet loads none of them are visible. Once I click on them, though, they're visible and operate correctly, and I'm not sure why.


<!-- This is the circular checkbox; unmodified from nWoD -->
<template name="checkbox">
<genericcontrol>
<stateicons>
<on>indicator_checkon</on>
<off>indicator_checkoff</off>
</stateicons>
<script file="scripts/template_checkbox.lua" />
</genericcontrol>
</template>
...
<!-- This is the square nWoD checkbox mine is based on -->
<template name="willbox">
<genericcontrol>
<stateicons>
<empty>indicator_boxempty</empty>
<slash>indicator_boxslash</slash>
</stateicons>
<script file="scripts/template_willbox.lua" />
</genericcontrol>
</template>

<!-- This is my square checkbox -->
<template name="simplecheckbox">
<genericcontrol>
<stateicons>
<empty>indicator_boxempty</empty>
<slash>indicator_boxfilled</slash>
</stateicons>
<script file="scripts/template_willbox.lua" />
</genericcontrol>
</template>

The lua script governing the checkboxes are essentially the same:

local sourcelessvalue = false;

function setState(state)
local datavalue = 1;

if state == nil or state == false or state == 0 then
datavalue = 0;
end

if source then
source.setValue(datavalue);
else
if datavalue == 0 then
sourcelessvalue = false;
else
sourcelessvalue = true;
end

update();
end
end

function update()
if source then
if source.getValue() ~= 0 then
setIcon(stateicons[1].slash[1]);
else
setIcon(stateicons[1].empty[1]);
end
else
if sourcelessvalue then
setIcon(stateicons[1].slash[1]);
else
setIcon(stateicons[1].empty[1]);
end
end

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

function getState()
if source then
local datavalue = source.getValue();
return datavalue ~= 0;
else
return sourcelessvalue;
end
end

function onClickDown(button, x, y)
setState(not getState());
end

function onInit()
setIcon(stateicons[1].empty[1]);

if not sourceless and window.getDatabaseNode() then
-- Get value from source node
if sourcename then
source = window.getDatabaseNode().createChild(sourcename[1], "number");
else
source = window.getDatabaseNode().createChild(getName(), "number");
end
if source then
source.onUpdate = update;
update();
end
else
-- Use internal value, initialize to checked if <checked /> is specified
if checked then
sourcelessvalue = true;
update();
end
end
end

I'm using both several times very simply. Example:

<simplecheckbox name="caste1ability3favored">
<anchored>
<to>caste1ability2favored</to>
<position>below</position>
<offset>0,3</offset>
<size>
<height>15</height>
</size>
</anchored>
</simplecheckbox>

Any insights why they won't draw from the more experienced users?

Lithl
June 7th, 2009, 08:25
Ohh, I've discovered my problem!

I removed all of the widgets in the skillsframe control, and then removed the background icon from it so that it was transparent, so I could see the things I was adding. When I actually removed the skillframe, instead of just emptying it, the icons came back!

I'm not certain exactly why the extra frame was causing that, but I'm just glad I've got by icons back :)

Moon Wizard
June 7th, 2009, 10:26
You need to make sure that any frame elements are defined in the XML before the controls that are going to be inside the frame. The Z-order of controls is set by the order they are defined in the XML file.

Cheers,
JPG

Lithl
June 7th, 2009, 22:28
The checkboxes were defined after the frame, only some of the checkboxes were underneath the frame, and the frame itself was translucent. I'm glad my problem is fixed, but it was bizarre.