PDA

View Full Version : Hide control when sheet locked.



mr900rr
July 12th, 2025, 23:37
Working on an personal extension to add function to magic items bonuses apply when equipped, right now I am having trouble with the formatting on the Item sheet. When locked, the cycler controls stay visible and editable, I would like it to work like on the 3.5 character sheet (the ruleset im using) ,skills tab, "stat" column. When unlocked its has the dark field and editable and when locked on field and not editable. I tried using the same control "cycler_charskillability" but still same result. Will try to attach images and code if I can figure how to do that lol.

record_item.xml


<line_content_top name="divider4" />

<!-- added -->
<label_content_column name="statname_label">
<static textres="item_label_stat" />
</label_content_column>
<button_stringcycler_content_column name="statname">
<anchored to="contentanchor" height="20" width="80">
<top relation="current" offset="3" postoffset="3" />
<left offset="110" />
<right merge="delete" />
</anchored>
<parameters>
<labels>Str|Dex|Con|Int|Wis|Cha</labels>
<values>strength|dexterity|constitution|intelligence|wisdo m|charisma</values>
</parameters>
</button_stringcycler_content_column>
<label_content_column name="statbonus_label">
<static textres="item_label_bonus" />
<anchored to="contentanchor">
<top relation="current" offset="3" />
<left merge="replace" parent="statname" offset="135" />
</anchored>
</label_content_column>
<number_content_columnh name="statbonus">
<anchored width="40">
<top relation="relative" offset="3" postoffset="3" />
<left offset="295" />
</anchored>
<delaykeyupdate />
<displaysign />
</number_content_columnh>

<label_content_column name="savename_label">
<static textres="item_label_save" />
</label_content_column>
<button_stringcycler_content_column name="savename">
<anchored to="contentanchor" height="20" width="80">
<top relation="current" offset="3" postoffset="3" />
<left offset="110" />
<right merge="delete" />
</anchored>
<parameters>
<labels>Fort|Ref|Will|All</labels>
<values>fortitude|reflex|will|all</values>
</parameters>
</button_stringcycler_content_column>
<label_content_column name="savebonus_label">
<static textres="item_label_bonus" />
<anchored to="contentanchor">
<top relation="current" offset="3" />
<left merge="replace" parent="savename" offset="135" />
</anchored>
</label_content_column>
<number_content_columnh name="savebonus">
<anchored width="40">
<top relation="relative" offset="3" postoffset="3" />
<left offset="295" />
</anchored>
<delaykeyupdate />
<displaysign />
</number_content_columnh>

<label_content_column name="actype_label">
<static textres="item_label_actype" />
</label_content_column>
<button_stringcycler_content_column name="actype">
<anchored to="contentanchor" height="20" width="80">
<top relation="current" offset="3" postoffset="3" />
<left offset="110" />
<right merge="delete" />
</anchored>
<parameters>
<labels>Armor|Shield|Natural|Dex|Dodge|Deflection|Size|Mag ic|Alchemical|Enhancement|Insight|Luck</labels>
<values>armor|shield|natural|dex|dodge|deflection|size|mag ic|alchemical|enhancement|insight|luck</values>
</parameters>
</button_stringcycler_content_column>
<label_content_column name="acbonus_label">
<static textres="item_label_bonus" />
<anchored to="contentanchor">
<top relation="current" offset="3" />
<left merge="replace" parent="actype" offset="135" />
</anchored>
</label_content_column>
<number_content_columnh name="acbonus">
<anchored width="40">
<top relation="relative" offset="3" postoffset="3" />
<left offset="295" />
</anchored>
<delaykeyupdate />
<displaysign />
</number_content_columnh>

<label_content_column name="resisttype_label">
<static textres="item_label_resist" />
</label_content_column>
<button_stringcycler_content_column name="resisttype">
<anchored to="contentanchor" height="20" width="80">
<top relation="current" offset="3" postoffset="3" />
<left offset="110" />
<right merge="delete" />
</anchored>
<parameters>
<labels>Fire|Cold|Electricity|Acid|Sonic|Spell|All</labels>
<values>fire|cold|electricity|acid|sonic|spell|all</values>
</parameters>
</button_stringcycler_content_column>
<label_content_column name="resistbonus_label">
<static textres="item_label_bonus" />
<anchored to="contentanchor">
<top relation="current" offset="3" />
<left merge="replace" parent="resisttype" offset="135" />
</anchored>
</label_content_column>
<number_content_columnh name="resistbonus">
<anchored width="40">
<top relation="relative" offset="3" postoffset="3" />
<left offset="295" />
</anchored>
<delaykeyupdate />
<displaysign />
</number_content_columnh>

<!-- <spacer_content_top name="spacer1">
<anchored height="15"/>
</spacer_content_top>-->
<!-- end added -->

<label_content_column name="aura_label">
<static textres="item_label_aura" />
</label_content_column>
<string_content_columnh name="aura" />


and modified this line in item_main.lua


local tMagicFields = { "statbonus", "savebonus", "acbonus", "resistbonus", "resisttype", "aura", "cl", "prerequisites", };


also tried this in item_main.lua


local tMagicFields = { "statname", "statbonus", "savename", "savebonus", "actype", "acbonus", "resisttype", "resistbonus", "aura", "cl", "prerequisites", };


Edited code above to reflect change suggested and implemented by Trenloe in first reply.

Thanks for any help have been trying everything I can think of but I am no programmer I just reverse engineer to figure stuff out.

Trenloe
July 13th, 2025, 00:00
The control appears to be called "Istatname". You don't have this in the tMagicFields LUA table.

You'll probably need to change the name to "statname" (so it matches with "statname_label") and add "statname" to the tMagicFields LUA table. You'll also need to change the anchoring of "statbonus_label" from "Istatname" to "statname".

mr900rr
July 13th, 2025, 00:11
Thanks Trenloe for your quick reply, I tried what you suggested and sadly it didnt seem to have an effect, I suspect its getting broken in what ever function determines and or sets the read only state maybe in manager_window.lua.

Trenloe
July 13th, 2025, 00:23
Please provide all your extension code so that we can help fix it.

EDIT: See next post.

Trenloe
July 13th, 2025, 00:46
Rename "Istatname" to "statname" (as previously mentioned) and then use this in item_main.lua:


local tMagicFields = { "statbonus", "savebonus", "acbonus", "resistbonus", "aura", "cl", "prerequisites", };
WindowManager.callSafeControlsUpdate(self, tMagicFields, bReadOnly, not bID);
WindowManager.callSafeControlsSetLockMode(self, { "statname", "savename", "actype", "resisttype"}, bReadOnly);

mr900rr
July 13th, 2025, 00:53
Ok, it would just be what I added above to the two files so far, record_item.xml and item_main.lua, I tried to paste code for whole files but it said it was too long, is there a way to attach files?

Trenloe
July 13th, 2025, 01:00
Ok, it would just be what I added above to the two files so far, record_item.xml and item_main.lua, I tried to paste code for whole files but it said it was too long, is there a way to attach files?
See my subsequent post.

As a side note - if you're writing an extension you shouldn't be copying the whole item_main.lua file, just code for your own changes, for example (I haven't tested this):

function onStateChanged()
if super and super.onStateChanged then
super.onStateChanged();
end

local tMagicFields = { "statbonus", "savebonus", "acbonus", "resistbonus", "aura", "cl", "prerequisites", };
WindowManager.callSafeControlsUpdate(self, tMagicFields, bReadOnly, not bID);
WindowManager.callSafeControlsSetLockMode(self, { "statname", "savename", "actype", "resisttype"}, bReadOnly);
divider5.setVisible(WindowManager.getAnyControlVis ible(self, tMagicFields));
end

mr900rr
July 13th, 2025, 01:05
I tried your suggestion above and it did solve the issue with the fields being editable while locked but still getting the issue where empty item still overlapping, see attached image. Would I maybe want to add a similar call to callSafeControlsSetVisible?

64820

mr900rr
July 13th, 2025, 01:10
See my subsequent post.

As a side note - if you're writing an extension you shouldn't be copying the whole item_main.lua file, just code for your own changes, for example (I haven't tested this):

function onStateChanged()
if super and super.onStateChanged then
super.onStateChanged();
end

local tMagicFields = { "statbonus", "savebonus", "acbonus", "resistbonus", "aura", "cl", "prerequisites", };
WindowManager.callSafeControlsUpdate(self, tMagicFields, bReadOnly, not bID);
WindowManager.callSafeControlsSetLockMode(self, { "statname", "savename", "actype", "resisttype"}, bReadOnly);
divider5.setVisible(WindowManager.getAnyControlVis ible(self, tMagicFields));
end

Where would I place this Function, sorry again not a pro at this, still learning hehe.

Trenloe
July 13th, 2025, 02:40
Give the attached a try - other than extension.xml, this should be the only file you need for this functionality to work in an extension.

There's a gotcha - the stacking of the labels will overlap if there's no bonus value (i.e. it's 0) as the "relative" anchoring relies on the bonus field being visible, and the bonus field is hidden if the value is 0.

I haven't done any testing from the player side - you'll probably need more code to hide fields on the player side if the item isn't identified.

Hopefully this will get you moving, I'm afraid I don't have any more free time to assist further.

mr900rr
July 13th, 2025, 05:18
Thank you Trenloe, appreciate the help, should get me moving in the right direction. So I got it all working properly now even with no number entered into the bonus field. I renamed the controls for for the bonus field to match the name of the cycler but with the word "bonus" at the end ie "statbonus" to "statnamebonus" etc and their corresponding labels to match "statnamebonus_label". Then I modified your script so that if the bonus field is empty the cycler is not visible if it has a value or not.



local tMagicFields = { "statname", "statnamebonus", "savename", "savenamebonus", "actype", "actypebonus", "resisttype", "resisttypebonus", "aura", "cl", "prerequisites", };
WindowManager.callSafeControlsSetLockMode(self, { "statname", "savename", "actype", "resisttype"}, bReadOnly);
WindowManager.callSafeControlsUpdate(self, tMagicFields, bReadOnly, not bID);
local tCyclerControls = { "statname", "savename", "actype", "resisttype" };
for _,sControlName in pairs(tCyclerControls) do
local c = self[sControlName];
local cBonus = self[sControlName .. "bonus"];
if c then
if cBonus.getValue() == 0 and bReadOnly then
WindowManager.setControlVisibleWithLabel(self, sControlName, false);
elseif c.getValue() == "" and bReadOnly then
WindowManager.setControlVisibleWithLabel(self, sControlName, false);
WindowManager.setControlVisibleWithLabel(self, sControlName .. "bonus", false);
else
WindowManager.setControlVisibleWithLabel(self, sControlName, true);
end
end
end

Trenloe
July 14th, 2025, 16:02
Nice one!