Trade offers better sorting with user choice (#2180)

#2152 is nice but sorts by internal key, thus translations are not
    taken into account and cities are sorted by their guid
   Also moving larger amounts to the top may not be everyone's taste
   so this offers the user a choice
This commit is contained in:
rh-github-2015 2020-03-18 09:21:50 +01:00 committed by GitHub
parent 076821a181
commit 701ddcb76b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View file

@ -31,6 +31,7 @@ class GameSettings {
var multiplayerTurnCheckerEnabled = true
var multiplayerTurnCheckerPersistentNotificationEnabled = true
var multiplayerTurnCheckerDelayInMinutes = 5
var orderTradeOffersByAmount = true
init {
// 26 = Android Oreo. Versions below may display permanent icon in notification bar.

View file

@ -4,6 +4,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.unciv.Constants
import com.unciv.UncivGame
import com.unciv.logic.trade.TradeOffer
import com.unciv.logic.trade.TradeOffersList
import com.unciv.logic.trade.TradeType
@ -42,8 +43,8 @@ class OffersListScroll(val onOfferClicked: (TradeOffer) -> Unit) : ScrollPane(nu
}
for (offerType in values()) {
val offersOfType = offersToDisplay.filter { it.type == offerType }.
sortedBy { it.name }.sortedByDescending { it.amount }
val offersOfType = offersToDisplay.filter { it.type == offerType }
.sortedWith(compareBy({if (UncivGame.Current.settings.orderTradeOffersByAmount) -it.amount else 0},{if (it.type==City) it.getOfferText() else it.name.tr()}))
if (expanderTabs.containsKey(offerType)) {
expanderTabs[offerType]!!.innerTable.clear()

View file

@ -76,6 +76,12 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen){
update()
}
innerTable.add("Order trade offers by amount".toLabel())
addButton(innerTable, if (settings.orderTradeOffersByAmount) "Yes" else "No") {
settings.orderTradeOffersByAmount = !settings.orderTradeOffersByAmount
update()
}
addLanguageSelectBox(innerTable)
addResolutionSelectBox(innerTable)