PDA

View Full Version : Making a padlock on a form 'readonly' (ie show in red) - using code not XML.



MadBeardMan
March 31st, 2018, 00:04
Greetings All,

Been busy working on the Traveller ruleset, now doing all the 'loose' ends kind of things.

One thing I'd like to be able to do is to 'lock' rulebook skills from being edited, ie turn that padlock red.

Can't seem to figure it out.

I've posted an example image on my Twitter feed (https://twitter.com/MadBeardMan/status/979855210918174720), very basically this is the code that sets up the 'skill' form.


<!-- Skill description sheet -->
<windowclass name="reference_skill">
<frame>recordsheet</frame>
<placement>
<size width="400" height="350" />
</placement>
<sizelimits>
<minimum width="300" height="300" />
<dynamic />
</sizelimits>
<minimize>minimized_reference</minimize>
<tooltip field="name" />
<nodelete />
<script>
function onLockChanged()
if content.subwindow then
content.subwindow.update();
end
end
</script>
<sheetdata>
<anchor_record_header_right name="rightanchor" />
<sub_record_header name="header">
<class>ref_skill_header</class>
</sub_record_header>

<frame_ref_content />
<sub_ref_content name="content">
<class>ref_skill_stats</class>
</sub_ref_content>

<scrollbar_ref_content />

<icon_record_locked>
<anchored>
<right offset="-28" />
<top offset="25" />
</anchored>
</icon_record_locked>
<button_record_locked>
<anchored>
<right offset="-28" />
<top offset="25" />
</anchored>
</button_record_locked>

<resize_recordsheet />
<close_recordsheet />
</sheetdata>
</windowclass>

I have a flag on the XML that tells me it's a 'rulebook skill', but I want to use code to change the padlock to readonly status.

Can anyone help?

Cheers
MBM

Trenloe
March 31st, 2018, 00:07
Impatient! ;)

MadBeardMan
March 31st, 2018, 00:08
Impatient! ;)

Lol no, it's called 'Trenloe could be busy doing something really important!'.

MadBeardMan
March 31st, 2018, 00:26
Had a better idea, is it possible just to hide the darn padlock?

MadBeardMan
March 31st, 2018, 00:30
Yep, that worked nicely - thread closed!

I have in my XML, a 'noedit' with a value of 1 meaning you can't.


<script>
function onInit()
local node = getDatabaseNode();
local isSkillReadOnly = DB.getValue(node, "noedit", -1);

if (isSkillReadOnly == 1) then
padlock.setVisible(false);
end
end

function onLockChanged()
if content.subwindow then
content.subwindow.update();
end
end
</script>

Trenloe
March 31st, 2018, 00:30
Had a better idea, is it possible just to hide the darn padlock?
Of course - it's a normal control. Either remove it from the XML or set it invisible via code.

Moon Wizard
April 4th, 2018, 22:45
If the module data is set to static (for example, under the "reference" tag with the static attribute used in most of our modules), then the padlock will automatically be set to red and permanently locked.

Regards,
JPG