Sort resources by name and amount (#2152)

This commit is contained in:
Jack Rainy 2020-03-14 20:13:46 +02:00 committed by GitHub
parent 1978d7e707
commit a18d52c82a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,7 +19,7 @@ class OffersListScroll(val onOfferClicked: (TradeOffer) -> Unit) : ScrollPane(nu
val table = Table(CameraStageBaseScreen.skin).apply { defaults().pad(5f) }
val expanderTabs = HashMap<TradeType, ExpanderTab>()
private val expanderTabs = HashMap<TradeType, ExpanderTab>()
fun update(offersToDisplay:TradeOffersList) {
table.clear()
@ -41,12 +41,13 @@ class OffersListScroll(val onOfferClicked: (TradeOffer) -> Unit) : ScrollPane(nu
}
}
for (offertype in values()) {
val offersOfType = offersToDisplay.filter { it.type == offertype }
for (offerType in values()) {
val offersOfType = offersToDisplay.filter { it.type == offerType }.
sortedBy { it.name }.sortedByDescending { it.amount }
if (expanderTabs.containsKey(offertype)) {
expanderTabs[offertype]!!.innerTable.clear()
table.add(expanderTabs[offertype]!!).row()
if (expanderTabs.containsKey(offerType)) {
expanderTabs[offerType]!!.innerTable.clear()
table.add(expanderTabs[offerType]!!).row()
}
for (offer in offersOfType) {
@ -62,12 +63,12 @@ class OffersListScroll(val onOfferClicked: (TradeOffer) -> Unit) : ScrollPane(nu
else tradeButton.disable() // for instance we have negative gold
if (expanderTabs.containsKey(offertype))
expanderTabs[offertype]!!.innerTable.add(tradeButton).row()
if (expanderTabs.containsKey(offerType))
expanderTabs[offerType]!!.innerTable.add(tradeButton).row()
else table.add(tradeButton).row()
}
}
widget = table
actor = table
}
}