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

View File

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