Recent

Author Topic: Updates for Virtual ListView  (Read 2853 times)

Khumarahn

  • New Member
  • *
  • Posts: 10
Updates for Virtual ListView
« on: August 14, 2015, 11:01:20 am »
Hi.

I am working on a port of the video game progressquest ( http://progressquest.com/ ) to lazarus. I never seriously used pascal, delphi or lazarus before, and my questions may be noobish.

There is an issue with the game (skip this if you are not interested in the game): after playing for around 10 years the size of main hero's backpack gets huge, and he may be carrying tens or hundreds of thousands of items. Backpack is a list of item-quantity. When the hero gets a next trophy, it is added to the backpack, and the hero looks through the whole backpack to see of he already has this type of item, then he increases quantity, else he adds new item in the end of the list. And when the hero goes to market, he repeatedly sells the second element in the list, removing it, until there is only the first item left, which cannot be sold because it is his wallet with gold.

So to make the game efficient I implemented the backpack as a custom data structure, and it displays through TListView with OwnerData:=True, and OnData refers to my data structure.

My current problem is: when a new item is won, and it is added in the end of the list, I update the display by running ListView.Items.Count := 1+ListView.Items.Count. Then for some weird reason the listview resets its position (scrolls to top), and if an item was selected, the selection is lost too.

Is there a way to make updates smoother, preserve the scrolling position, and/or selection?
« Last Edit: August 14, 2015, 11:14:53 am by Khumarahn »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12318
  • FPC developer.
Re: Updates for Virtual ListView
« Reply #1 on: August 14, 2015, 11:10:04 am »
Look for Virtual String Tree (aka VST) in the lazarus-ccr repository.

It is an ported version of a Delphi component that is fine for grids, trees and lists.

It takes some getting used to, studying the "advanced" demo might help.

Khumarahn

  • New Member
  • *
  • Posts: 10
Re: Updates for Virtual ListView
« Reply #2 on: August 14, 2015, 11:13:33 am »
I don't have a problem with speed now... Only with scrolling. Is scrolling in VST done right, when just one row is added in the end?

 

TinyPortal © 2005-2018