mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-28 23:59:25 +00:00
Have LexiconEntry extend Comparable and allow for priority over others.
This commit is contained in:
1 parent
f56f78487b
commit
e7c071efab
2 files changed
+22
-13
No files matched your search
@@ -15,21 +15,28 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import vazkii.botania.api.page.LexiconPage;
|
||||
|
||||
public class LexiconEntry {
|
||||
public class LexiconEntry implements Comparable<LexiconEntry>{
|
||||
|
||||
public final String unlocalizedName;
|
||||
public List<LexiconPage> pages = new ArrayList<LexiconPage>();
|
||||
|
||||
private boolean priority = false;
|
||||
|
||||
/**
|
||||
* @param unlocalizedName The unlocalized name of this entry. This will be localized by the client display.
|
||||
*/
|
||||
public LexiconEntry(String unlocalizedName) {
|
||||
this.unlocalizedName = unlocalizedName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this page as prioritized, as in, will appear before others in the lexicon.
|
||||
*/
|
||||
public void setPriority() {
|
||||
priority = true;
|
||||
}
|
||||
|
||||
public String getUnlocalizedName() {
|
||||
return unlocalizedName;
|
||||
@@ -48,4 +55,13 @@ public class LexiconEntry {
|
||||
public void addPage(LexiconPage page) {
|
||||
pages.add(page);
|
||||
}
|
||||
}
|
||||
|
||||
public final String getNameForSorting() {
|
||||
return (priority ? 0 : 1) + StatCollector.translateToLocal(getUnlocalizedName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(LexiconEntry o) {
|
||||
return getNameForSorting().compareTo(o.getNameForSorting());
|
||||
}
|
||||
}
|
||||
@@ -58,14 +58,7 @@ public class GuiLexiconIndex extends GuiLexicon {
|
||||
|
||||
entriesToDisplay.clear();
|
||||
entriesToDisplay.addAll(category.entries);
|
||||
Collections.sort(entriesToDisplay, new Comparator<LexiconEntry>() {
|
||||
|
||||
@Override
|
||||
public int compare(LexiconEntry arg0, LexiconEntry arg1) {
|
||||
return StatCollector.translateToLocal(arg0.getUnlocalizedName()).compareTo(StatCollector.translateToLocal(arg1.getUnlocalizedName()));
|
||||
}
|
||||
|
||||
});
|
||||
Collections.sort(entriesToDisplay);
|
||||
|
||||
updatePageButtons();
|
||||
populateIndex();
|
||||
|
||||
Reference in new issue
Block a user