PDA

View Full Version : One windowlist, two windowclasses



Lithl
June 21st, 2009, 06:17
I've got two windowclasses: element_armor, and element_shield. element_armor has fields for soak, mobility penalty, fatigue rating, and notes. element_shield has fields for mobility penalty, fatigue rating, melee defense value, ranged defense value, and notes. They're basically the same, just with gaps in the layout where they don't have fields that the other class does.

I want to put both of these windowclasses in the same windowlist:

<windowlist name="armorlist">
<anchored>
<to>armorframe</to>
<position>insidetopleft</position>
<offset>13,30</offset>
<size>
<width>475</width>
<height>80</height>
</size>
</anchored>
<datasource>.armor_shields</datasource>
<class>element_armor</class>
<allowdelete />
<script>
function onInit()
self.registerMenuItem("Create Armor", "insert", 5);
self.registerMenuItem("Create Shield", "insert", 4);
end

function onMenuSelection(...)
local index = ...;
if index == 5 then
self.createWindow();
elseif index == 4 then
self.createWindowWithClass("element_shield");
end
end
</script>
</windowlist>

The problem is that, while the radial menu correctly has the two create buttons, and adding an armor works perfectly fine... adding a shield doesn't quite work correctly.

While a shield is correctly added to the windowlist, and I can edit the shield's fields perfectly fine, it doesn't get saved to the database. If you can't store multiple windowclass types in a windowlist, then why is there a createWindowWithClass function, and if you can save multiple windowclass types, then what am I doing wrong? :(

Foen
June 21st, 2009, 06:40
I use createWindowWithClass to work on unbound window lists (the contents are created each time in onInit) or to add subtitles to lists (such as the categories in the Library left hand window), which aren't saved.

Although your approach can be made to work (I think the entries are saved, but would re-display as armour entries, not shield entries), I suggest you instead think about modifying the window class to toggle between displaying shields or armour.

Using one window class, but having it show only the correct fields depnding on the object type, would be easier (IMHO).

Foen

Lithl
June 21st, 2009, 06:50
I use createWindowWithClass to work on unbound window lists (the contents are created each time in onInit) or to add subtitles to lists (such as the categories in the Library left hand window), which aren't saved.
Darn, that's disappointing =/

Oh well, I can live with it.