mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-10 20:11:35 +01:00
Human friendly schematic selection
This commit is contained in:
parent
8b5d5abc06
commit
ddb5aa9a3d
2 changed files with 63 additions and 0 deletions
|
@ -9,6 +9,7 @@ import java.nio.file.Paths;
|
|||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -142,6 +143,56 @@ public class ClientSchematicLoader {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Collections.sort(availableSchematics, (a, b) -> {
|
||||
if (a.endsWith(".nbt"))
|
||||
a = a.substring(0, a.length() - 4);
|
||||
if (b.endsWith(".nbt"))
|
||||
b = b.substring(0, b.length() - 4);
|
||||
int aLength = a.length();
|
||||
int bLength = b.length();
|
||||
int minSize = Math.min(aLength, bLength);
|
||||
char aChar, bChar;
|
||||
boolean aNumber, bNumber;
|
||||
boolean asNumeric = false;
|
||||
int lastNumericCompare = 0;
|
||||
for (int i = 0; i < minSize; i++) {
|
||||
aChar = a.charAt(i);
|
||||
bChar = b.charAt(i);
|
||||
aNumber = aChar >= '0' && aChar <= '9';
|
||||
bNumber = bChar >= '0' && bChar <= '9';
|
||||
if (asNumeric)
|
||||
if (aNumber && bNumber) {
|
||||
if (lastNumericCompare == 0)
|
||||
lastNumericCompare = aChar - bChar;
|
||||
} else if (aNumber)
|
||||
return 1;
|
||||
else if (bNumber)
|
||||
return -1;
|
||||
else if (lastNumericCompare == 0) {
|
||||
if (aChar != bChar)
|
||||
return aChar - bChar;
|
||||
asNumeric = false;
|
||||
} else
|
||||
return lastNumericCompare;
|
||||
else if (aNumber && bNumber) {
|
||||
asNumeric = true;
|
||||
if (lastNumericCompare == 0)
|
||||
lastNumericCompare = aChar - bChar;
|
||||
} else if (aChar != bChar)
|
||||
return aChar - bChar;
|
||||
}
|
||||
if (asNumeric)
|
||||
if (aLength > bLength && a.charAt(bLength) >= '0' && a.charAt(bLength) <= '9') // as number
|
||||
return 1; // a has bigger size, thus b is smaller
|
||||
else if (bLength > aLength && b.charAt(aLength) >= '0' && b.charAt(aLength) <= '9') // as number
|
||||
return -1; // b has bigger size, thus a is smaller
|
||||
else if (lastNumericCompare == 0)
|
||||
return aLength - bLength;
|
||||
else
|
||||
return lastNumericCompare;
|
||||
else
|
||||
return aLength - bLength;
|
||||
});
|
||||
}
|
||||
|
||||
public List<String> getAvailableSchematics() {
|
||||
|
|
|
@ -38,6 +38,16 @@ public class SelectionScrollInput extends ScrollInput {
|
|||
protected void updateTooltip() {
|
||||
toolTip.clear();
|
||||
toolTip.add(TextFormatting.BLUE + title);
|
||||
int min = Math.min(this.max - 16, state - 7);
|
||||
int max = Math.max(this.min + 16, state + 8);
|
||||
min = Math.max(min, this.min);
|
||||
max = Math.min(max, this.max);
|
||||
if (this.min + 1 == min)
|
||||
min--;
|
||||
if (min > this.min)
|
||||
toolTip.add(TextFormatting.GRAY + "> ...");
|
||||
if (this.max - 1 == max)
|
||||
max++;
|
||||
for (int i = min; i < max; i++) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
if (i == state)
|
||||
|
@ -46,6 +56,8 @@ public class SelectionScrollInput extends ScrollInput {
|
|||
result.append(TextFormatting.GRAY).append("> ").append(options.get(i));
|
||||
toolTip.add(result.toString());
|
||||
}
|
||||
if (max < this.max)
|
||||
toolTip.add(TextFormatting.GRAY + "> ...");
|
||||
toolTip.add(TextFormatting.DARK_GRAY + "" + TextFormatting.ITALIC + scrollToSelect);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue