Skip to content

ordered trade route city list #168

Description

@jottyfan

Creating trade routes becomes a mess when you have multiple colonies. Then, the order is done as it comes from the game (I suggest creation date). Try to find your colony when you have so many ones.

I've found a solution for this by the patch provided. This is obviously not the way how freecol is developed, but it works without a performance issue.

Not sure, but I think there might be plans to allow multiple ordering ways. Best was to have a filterable search input field instead such as select2 (https://select2.org/getting-started/basic-usage/). Then, the order of colonies would not matter any more.

The quick fix for ordering alphabetically by colony name is in TradeRouteInputPanel.

diff --git a/src/net/sf/freecol/client/gui/panel/TradeRouteInputPanel.java b/src/net/sf/freecol/client/gui/panel/TradeRouteInputPanel.java
index 5bb5180..e55fd30 100644
--- a/src/net/sf/freecol/client/gui/panel/TradeRouteInputPanel.java
+++ b/src/net/sf/freecol/client/gui/panel/TradeRouteInputPanel.java
@@ -518,7 +519,9 @@
         if (player.getEurope() != null) {
             this.destinationSelector.addItem(player.getEurope().getId());
         }
-        for (Colony colony : player.getColonyList()) {
+        List<Colony> sortedColonies = new ArrayList<>(player.getColonyList());
+        sortedColonies.sort((a, b) -> a == null || b == null || a.getName() == null ? 0 : a.getName().compareTo(b.getName()));
+        for (Colony colony : sortedColonies) {
             this.destinationSelector.addItem(colony.getId());
         }

Not sure if this can be added to the source code until another solution is implemented. But for me, it works very well.

Image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions