From cd9737df9fe9212fcb84a20593701cd098d56315 Mon Sep 17 00:00:00 2001 From: Jack Rainy Date: Sun, 19 Apr 2020 16:36:13 +0300 Subject: [PATCH] Display trades sorted by expiration (#2465) --- core/src/com/unciv/ui/EmpireOverviewScreen.kt | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/core/src/com/unciv/ui/EmpireOverviewScreen.kt b/core/src/com/unciv/ui/EmpireOverviewScreen.kt index 9a1dc235..49a837f9 100644 --- a/core/src/com/unciv/ui/EmpireOverviewScreen.kt +++ b/core/src/com/unciv/ui/EmpireOverviewScreen.kt @@ -113,12 +113,24 @@ class EmpireOverviewScreen(private val viewingPlayer:CivilizationInfo, private v stage.addActor(table) } - private fun getTradesTable(): Table { val tradesTable = Table().apply { defaults().pad(10f) } - for(diplomacy in viewingPlayer.diplomacy.values) - for(trade in diplomacy.trades) - tradesTable.add(createTradeTable(trade,diplomacy.otherCiv())).row() + val diplomacies = viewingPlayer.diplomacy.values.filter { it.trades.isNotEmpty() } + .sortedWith(Comparator { d0, d1 -> + val d0offers = d0.trades.first().ourOffers + val d1offers = d1.trades.first().ourOffers + val d0max = if (d0offers.isEmpty()) 0 else d0offers.maxBy { it.duration }!!.duration + val d1max = if (d1offers.isEmpty()) 0 else d1offers.maxBy { it.duration }!!.duration + when { + d0max > d1max -> 1 + d0max == d1max -> 0 + else -> -1 + } + }) + for(diplomacy in diplomacies) { + for (trade in diplomacy.trades) + tradesTable.add(createTradeTable(trade, diplomacy.otherCiv())).row() + } return tradesTable }