Interface GridView
- All Known Implementing Classes:
GridViewImpl
@API(status=STABLE,
since="2.0.0-milestone.1.0")
public interface GridView
Represents a grid view.
The grid view internally has a backing list and a view list.
The backing list is the logical view of the grid without any filtering or sorting applied. It's the source of truth.
The view list has filtering and sorting rules applied and is in sync with the backing list (depending on the view
being in "prevent sorting" mode).
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the backing list, view list and tracked resources index.long
getAmount
(ResourceKey resource) getTrackedResource
(ResourceKey resource) boolean
isAutocraftable
(ResourceKey resource) void
onChange
(ResourceKey resource, long amount, TrackedResource trackedResource) Applies a change to a resource.setFilterAndSort
(BiPredicate<GridView, GridResource> predicate) void
setListener
(Runnable listener) Sets a listener that is called when the grid view changes.boolean
setPreventSorting
(boolean changedPreventSorting) Preventing sorting means that the changes will still arrive at the backing list and view list, but, the view list won't be resorted and if a resource is zeroed, will stay in view until sorting is enabled again.void
setSortingDirection
(GridSortingDirection sortingDirection) Changing the sorting direction still requires a call tosort()
.void
setSortingType
(GridSortingType sortingType) Changing the sorting type still requires a call tosort()
.void
sort()
Sorts the view list.
-
Method Details
-
setListener
Sets a listener that is called when the grid view changes.- Parameters:
listener
- the listener, can be null
-
setSortingType
Changing the sorting type still requires a call tosort()
.- Parameters:
sortingType
- the sorting type
-
setFilterAndSort
- Parameters:
predicate
- the filter- Returns:
- the previous filtering predicate
-
setPreventSorting
boolean setPreventSorting(boolean changedPreventSorting) Preventing sorting means that the changes will still arrive at the backing list and view list, but, the view list won't be resorted and if a resource is zeroed, will stay in view until sorting is enabled again. This still requires a call tosort()
when preventing sorting is disabled again.- Parameters:
changedPreventSorting
- whether the view should prevent sorting on changes- Returns:
- whether prevent sorting has changed
-
setSortingDirection
Changing the sorting direction still requires a call tosort()
.- Parameters:
sortingDirection
- the sorting direction
-
getTrackedResource
- Parameters:
resource
- the resource- Returns:
- the tracked resource, if present
-
getAmount
- Parameters:
resource
- the resource- Returns:
- the amount in the view, or zero if not present
-
isAutocraftable
- Parameters:
resource
- the resource- Returns:
- whether its autocraftable
-
sort
void sort()Sorts the view list. Applies sorting and filtering rules. -
onChange
Applies a change to a resource. Will update the backing list, and will also update the view list (depending on if the view is preventing sorting).- Parameters:
resource
- the resourceamount
- the amount, can be negative or positivetrackedResource
- the tracked resource, can be null
-
getViewList
List<GridResource> getViewList()- Returns:
- the view list
-
copyBackingList
MutableResourceList copyBackingList()- Returns:
- a copy of the backing list
-
clear
void clear()Clears the backing list, view list and tracked resources index.
-