https://wiki.cheatengine.org/index.php?title=Lua:Class:Listview&feed=atom&action=historyLua:Class:Listview - Revision history2024-03-29T01:51:44ZRevision history for this page on the wikiMediaWiki 1.32.0https://wiki.cheatengine.org/index.php?title=Lua:Class:Listview&diff=6078&oldid=prevJgoemat: Created page with 'I recently had occasion to use this creating an Upgrade editor for Shadow Warrior 2 for the great table by Zanzer... I have a function that opens a form in LUA, clears the list …'2018-05-30T08:38:38Z<p>Created page with 'I recently had occasion to use this creating an Upgrade editor for Shadow Warrior 2 for the great table by Zanzer... I have a function that opens a form in LUA, clears the list …'</p>
<p><b>New page</b></p><div>I recently had occasion to use this creating an Upgrade editor for Shadow Warrior 2<br />
for the great table by Zanzer...<br />
<br />
I have a function that opens a form in LUA, clears the list view items, and<br />
listens for the user to click on an item:<br />
<br />
local lv = FormEditUpgrade.listViewProperties<br />
lv.items.clear()<br />
lv.setOnClick(FormEditUpgrade_listViewProperties_OnClick)<br />
<br />
So the form defines the list view with 3 columns. I changed the following properties<br />
when designing the form:<br />
<br />
* ColumnClick = False - ??<br />
* ReadOnly = True - don't allow edits directly in the table<br />
* RowSelect = True - select a whole row when clicking<br />
* ViewStyle = vsReport - shows multiple columns with headings<br />
<br />
When the last upgrade changes, I analyze the memory and create an array in LUA <br />
of the attributes of that upgrade. I then clear the items array on the list<br />
view and recreate them.<br />
<br />
You can see here that ''item.Caption'' controls what is displayed<br />
in the first column. I set the other columns using ''SubItems.text''<br />
by setting it to the values to put in those columns separated by CRLF.<br />
SubItems is a 'Strings' object and there may be a better way to do that,<br />
but this was easy enough for me.<br />
<br />
local function LoadUpgrade(address)<br />
CURRENT_UPGRADE = Upgrade(address)<br />
local lv = FormEditUpgrade.listViewProperties<br />
local items = lv.items<br />
items.clear()<br />
for i,attr in ipairs(CURRENT_UPGRADE.attributes) do<br />
local item = items:add()<br />
item.Caption = attr.name<br />
item.SubItems.text = table.concat({ attr.value or 'nil', attr.type }, '\r\n')<br />
end<br />
end<br />
<br />
When the user clicks on a row, I use ''ItemIndex'' and match it to<br />
the attribute in my LUA array. The SelectAttribute function handles<br />
using 'inputQuery' to pop up a window for changing the value, changing<br />
the value, and reloading the updated Upgrade.<br />
<br />
local function FormEditUpgrade_listViewProperties_OnClick()<br />
if CURRENT_UPGRADE == nil or CURRENT_UPGRADE.attributes == nil or #CURRENT_UPGRADE.attributes == 0 then return end<br />
local lv = FormEditUpgrade.listViewProperties<br />
local selectedIndex = lv.ItemIndex<br />
if selectedIndex < 0 or selectedIndex >= #CURRENT_UPGRADE.attributes then return end<br />
SelectAttribute(CURRENT_UPGRADE.attributes[selectedIndex+1]) -- +1 for 1 based LUA<br />
end</div>Jgoemat