PDA

View Full Version : Adding fields to record_item window



Ranzarok
July 19th, 2019, 03:49
Looking over this for days and out of ideas. How would one insert additional fields in the item window? I can actually add the fields but not where I would like them to go. Example below.

I would like to add the "Item Type" cycler either into the first Section or it's own Section following the first. Here is the code I've done.

record_item.xml

<windowclass name="item_main" merge="join">
<margins control="0,0,0,2" />
<script file="campaign/scripts/item_main.lua" />
<sheetdata>
<anchor_column name="columnanchor" />

<label_column name="nonid_name_label">
<static textres="item_label_unidentified" />
</label_column>
<string_columnh name="nonid_name" />

<label_column name="nonid_notes_label">
<static textres="item_label_unidentifiednotes" />
</label_column>
<string_columnh name="nonid_notes" />

<line_column name="divider" />

<label_column name="item_type_label">
<static textres="item_type_group" />
</label_column>
<item_cycler name="itemtype">
<anchored to="item_type_label" position="insidetopleft" offset="100,5" width="100" height="20" />
</item_cycler>

<line_column name="divider2" />

<label_column name="cost_label">
<static textres="item_label_cost" />
</label_column>
<string_columnh name="cost" />

<label_column name="weight_label">
<static textres="item_label_weight" />
</label_column>
<number_columnh name="weight" />

<line_column name="divider3" />

<ft_columnh name="notes" />

</sheetdata>
</windowclass>

my modified block of code in item_main.lua

function update()
local nodeRecord = getDatabaseNode();
local bReadOnly = WindowManager.getReadOnlyState(nodeRecord);
local bID = LibraryData.getIDState("item", nodeRecord);

local bSection1 = false;
if User.isHost() then
if updateControl("nonid_name", bReadOnly, true) then bSection1 = true; end;
else
updateControl("nonid_name", bReadOnly, false);
end
if (User.isHost() or not bID) then
if updateControl("nonid_notes", bReadOnly, true) then bSection1 = true; end;
else
updateControl("nonid_notes", bReadOnly, false);
end

local bSection2 = false;
if updateControl("itemtype", bReadOnly, bID) then bSection2 = true; end

local bSection3 = false;
if updateControl("cost", bReadOnly, bID) then bSection3 = true; end
if updateControl("weight", bReadOnly, bID) then bSection3 = true; end

local bSection4 = bID;
notes.setVisible(bID);
notes.setReadOnly(bReadOnly);

divider.setVisible(bSection1 and bSection2);
divider2.setVisible((bSection1 or bSection2) and bSection3);
divider3.setVisible((bSection1 or bSection2 or bSection3) and bSection4);
end

This is my result. As I said, I would like to get the cycler to show up in it's own section before "Cost"
https://i.imgur.com/Da6aPhX.png

damned
July 19th, 2019, 04:33
At first blush that looks correct...
Where are you adding this code? In the ruleset or an extension? Do you have any other extensions active?

Ranzarok
July 19th, 2019, 05:22
Thanks for the reply.

Adding in an extension, using the MoreCore ruleset, but there doesn't seem to be MC record_item, so I am extending the CoreRPG record_item.xml. No other extensions active.

damned
July 19th, 2019, 05:48
The record_item from corerpg is pretty basic - include the whole file and use merge="replace". See how that goes.

Ranzarok
July 19th, 2019, 07:34
Did this, used merge="replace", reloaded FG and the console shot back an error: windowclass: Defined with unrecognized merge attribute value(replace)

damned
July 19th, 2019, 08:02
Did this, used merge="replace", reloaded FG and the console shot back an error: windowclass: Defined with unrecognized merge attribute value(replace)

Merge = delete
Sorry on my phone
The reason the above isn't working is because the anchoring is relative and you have not defined all of the fields which means that the ones you didn't drive are displaying before your new ones

damned
July 19th, 2019, 08:03
It leave the merge attribute off altogether and it will replace.

Ranzarok
July 19th, 2019, 08:13
It leave the merge attribute off altogether and it will replace.

Thanks, that worked (leaving off the merge).

Just for my reference, could you explain this:

The reason the above isn't working is because the anchoring is relative and you have not defined all of the fields which means that the ones you didn't drive are displaying before your new ones

If the anchoring is relative, and I replaced the entire file, which fields would I have needed to define?

Thanks again for your help, I appreciate it.

damned
July 19th, 2019, 08:20
Replacing the entire file you need to just put your entries in the right order with the other elements.
Like you did in your example. It's just the merge doesn't really work that well with those relative anchors.

Ranzarok
July 19th, 2019, 08:38
Gotcha, thanks

Trenloe
July 19th, 2019, 14:20
It's just the merge doesn't really work that well with those relative anchors.
Yeah, when using merge="join" you'll need to use insertbefore="<control_name>" properties in each control in the new windowclass you're merging with the original if you want them to appear higher up in the relative anchor order and not get placed at the end.

I haven't tested this, but something like the following should work:


<windowclass name="item_main" merge="join">
<script file="campaign/scripts/item_main.lua" />
<sheetdata>
<label_column name="item_type_label" insertbefore="cost_label">
<static textres="item_type_group" />
</label_column>
<item_cycler name="itemtype" insertbefore="cost_label">
<anchored to="item_type_label" position="insidetopleft" offset="100,5" width="100" height="20" />
</item_cycler>
<line_column name="divider3" insertbefore="cost_label"/>
</sheetdata>
</windowclass>

Ranzarok
July 19th, 2019, 22:16
Thanks Trenloe, I will try this as well.