From 38c36c283106df762b5cb938ec3d5a148f1e9097 Mon Sep 17 00:00:00 2001 From: Firenoo <49818773+firenoo@users.noreply.github.com> Date: Sat, 11 Feb 2023 14:29:25 -0800 Subject: [PATCH] GuiAdvancedMemoryCard.kt: Fix sorting For whatever reason chaining function calls breaks it the sorting... --- .../client/gui/GuiAdvancedMemoryCard.kt | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/projecturanus/betterp2p/client/gui/GuiAdvancedMemoryCard.kt b/src/main/java/com/projecturanus/betterp2p/client/gui/GuiAdvancedMemoryCard.kt index 21d9c8b..fc52421 100644 --- a/src/main/java/com/projecturanus/betterp2p/client/gui/GuiAdvancedMemoryCard.kt +++ b/src/main/java/com/projecturanus/betterp2p/client/gui/GuiAdvancedMemoryCard.kt @@ -58,9 +58,18 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound { private val modeButton by lazy { GuiButton(0, guiLeft + 8, guiTop + 190, 256, 20, modeString) } init { - sortInfo() + val tmp = mutableSetOf() + sortedInfo = sortedInfo.filter { tmp.add(it.toString()) } selectedIndex = mapSelected(msg.memoryInfo.selectedIndex) - sortInfo() + sortedInfo.sortedBy { if (it.index == selectedIndex) { + -2 // Put the selected p2p in the front + } else if (it.frequency != 0.toLong() && it.frequency == selectedInfo?.frequency && !it.output) { + -3 // Put input in the beginning + } else if (it.frequency != 0.toLong() && it.frequency == selectedInfo?.frequency) { + -1 // Put same frequency in the front + } else { + it.frequency + Short.MAX_VALUE + } } // infoOnScreen = sortedInfo.take(5) selectInfo(selectedIndex) @@ -104,7 +113,9 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound { it.frequency.toHexString().format4().contains(searchBar.text.uppercase()) || it.name.lowercase().contains(searchBar.text.lowercase()) } - sortedInfo = tmpInfo.sortedBy { + sortedInfo = tmpInfo.filter { + tmp.add(it.toString()) + }.sortedBy { if (it.index == selectedIndex) { -2 // Put the selected p2p in the front } else if (it.frequency != 0.toLong() && it.frequency == selectedInfo?.frequency && !it.output) { @@ -114,8 +125,6 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound { } else { it.frequency + Short.MAX_VALUE } - }.filter { - tmp.add(it.toString()) } } } @@ -124,7 +133,8 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound { val tmp = mutableSetOf() sortedInfo = infos.filter { tmp.add(it.toString()) - }.sortedBy { + } + sortedInfo = sortedInfo.sortedBy { if (it.index == selectedIndex) { -2 // Put the selected p2p in the front } else if (it.frequency != 0.toLong() && it.frequency == selectedInfo?.frequency && !it.output) {