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
3 changed files with 10 additions and 2 deletions

View File

@ -31,6 +31,7 @@ class GameSettings {
var multiplayerTurnCheckerEnabled = true var multiplayerTurnCheckerEnabled = true
var multiplayerTurnCheckerPersistentNotificationEnabled = true var multiplayerTurnCheckerPersistentNotificationEnabled = true
var multiplayerTurnCheckerDelayInMinutes = 5 var multiplayerTurnCheckerDelayInMinutes = 5
var orderTradeOffersByAmount = true
init { init {
// 26 = Android Oreo. Versions below may display permanent icon in notification bar. // 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.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.unciv.Constants import com.unciv.Constants
import com.unciv.UncivGame
import com.unciv.logic.trade.TradeOffer import com.unciv.logic.trade.TradeOffer
import com.unciv.logic.trade.TradeOffersList import com.unciv.logic.trade.TradeOffersList
import com.unciv.logic.trade.TradeType import com.unciv.logic.trade.TradeType
@ -42,8 +43,8 @@ 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 } .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)) { if (expanderTabs.containsKey(offerType)) {
expanderTabs[offerType]!!.innerTable.clear() expanderTabs[offerType]!!.innerTable.clear()

View File

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