mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-13 16:54:06 +00:00
Add sorting to LexiconCategory.
This commit is contained in:
1 parent
dd4c8d43f0
commit
fb648c5afa
4 files changed
+54
-13
No files matched your search
@@ -16,22 +16,50 @@ import java.util.List;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class LexiconCategory {
|
||||
public class LexiconCategory implements Comparable<LexiconCategory> {
|
||||
|
||||
private static int count = 0;
|
||||
|
||||
public final String unlocalizedName;
|
||||
public final List<LexiconEntry> entries = new ArrayList<LexiconEntry>();
|
||||
private final int sortingId;
|
||||
private ResourceLocation icon;
|
||||
private int priority = 5;
|
||||
|
||||
/**
|
||||
* @param unlocalizedName The unlocalized name of this category. This will be localized by the client display.
|
||||
*/
|
||||
public LexiconCategory(String unlocalizedName) {
|
||||
this.unlocalizedName = unlocalizedName;
|
||||
sortingId = count;
|
||||
count++;
|
||||
}
|
||||
|
||||
public String getUnlocalizedName() {
|
||||
return unlocalizedName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the priority for this category for sorting. Higher numbers
|
||||
* means they'll appear first in the book. The basics category
|
||||
* is 9, the miscellaneous category is 0, other vanilla botania categories
|
||||
* are 5. Using 9 and 0 is <b>not</b> recommended, since having your
|
||||
* categories before basics or after miscellaneous is a bad idea.
|
||||
* If two categories have the same priority they'll be sorted
|
||||
* by insertion order.
|
||||
*/
|
||||
public LexiconCategory setPriority(int priority) {
|
||||
this.priority = priority;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getSortingPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
public final int getSortingId() {
|
||||
return sortingId;
|
||||
}
|
||||
|
||||
public LexiconCategory setIcon(ResourceLocation icon) {
|
||||
this.icon = icon;
|
||||
@@ -41,4 +69,9 @@ public class LexiconCategory {
|
||||
public ResourceLocation getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(LexiconCategory category) {
|
||||
return priority == category.priority ? sortingId - category.sortingId : category.priority - priority;
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ package vazkii.botania.client.gui.lexicon;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -51,6 +52,8 @@ public class GuiLexicon extends GuiScreen {
|
||||
public float lastTime = 0F;
|
||||
public float partialTicks = 0F;
|
||||
public float timeDelta = 0F;
|
||||
|
||||
List<LexiconCategory> allCategories;
|
||||
|
||||
String title;
|
||||
int guiWidth = 146;
|
||||
@@ -60,6 +63,10 @@ public class GuiLexicon extends GuiScreen {
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
allCategories = new ArrayList(BotaniaAPI.getAllCategories());
|
||||
Collections.sort(allCategories);
|
||||
|
||||
lastTime = ClientTickHandler.ticksInGame;
|
||||
|
||||
title = Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem().getDisplayName();
|
||||
@@ -77,10 +84,10 @@ public class GuiLexicon extends GuiScreen {
|
||||
}
|
||||
populateIndex();
|
||||
} else if(isCategoryIndex()) {
|
||||
int categories = BotaniaAPI.getAllCategories().size();
|
||||
int categories = allCategories.size();
|
||||
for(int i = 0; i < categories + 1; i++) {
|
||||
LexiconCategory category = null;
|
||||
category = i >= categories ? null : BotaniaAPI.getAllCategories().get(i);
|
||||
category = i >= categories ? null : allCategories.get(i);
|
||||
int x = i % 4;
|
||||
int y = i / 4;
|
||||
|
||||
|
||||
@@ -18,9 +18,10 @@ import vazkii.botania.common.lib.LibLexicon;
|
||||
|
||||
public class BLexiconCategory extends LexiconCategory {
|
||||
|
||||
public BLexiconCategory(String unlocalizedName) {
|
||||
public BLexiconCategory(String unlocalizedName, int priority) {
|
||||
super(LibLexicon.CATEGORY_PREFIX + unlocalizedName);
|
||||
setIcon(new ResourceLocation(LibResources.PREFIX_CATEGORIES + unlocalizedName + ".png"));
|
||||
setPriority(priority);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -196,15 +196,15 @@ public final class LexiconData {
|
||||
public static LexiconEntry bcIntegration;
|
||||
|
||||
public static void init() {
|
||||
BotaniaAPI.addCategory(categoryBasics = new BLexiconCategory(LibLexicon.CATEGORY_BASICS));
|
||||
BotaniaAPI.addCategory(categoryMana = new BLexiconCategory(LibLexicon.CATEGORY_MANA));
|
||||
BotaniaAPI.addCategory(categoryGenerationFlowers = new BLexiconCategory(LibLexicon.CATEGORY_GENERATION_FLOWERS));
|
||||
BotaniaAPI.addCategory(categoryFunctionalFlowers = new BLexiconCategory(LibLexicon.CATEGORY_FUNCTIONAL_FLOWERS));
|
||||
BotaniaAPI.addCategory(categoryDevices = new BLexiconCategory(LibLexicon.CATEGORY_DEVICES));
|
||||
BotaniaAPI.addCategory(categoryTools = new BLexiconCategory(LibLexicon.CATEGORY_TOOLS));
|
||||
BotaniaAPI.addCategory(categoryBaubles = new BLexiconCategory(LibLexicon.CATEGORY_BAUBLES));
|
||||
BotaniaAPI.addCategory(categoryAlfhomancy = new BLexiconCategory(LibLexicon.CATEGORY_ALFHOMANCY));
|
||||
BotaniaAPI.addCategory(categoryMisc = new BLexiconCategory(LibLexicon.CATEGORY_MISC));
|
||||
BotaniaAPI.addCategory(categoryBasics = new BLexiconCategory(LibLexicon.CATEGORY_BASICS, 9));
|
||||
BotaniaAPI.addCategory(categoryMana = new BLexiconCategory(LibLexicon.CATEGORY_MANA, 5));
|
||||
BotaniaAPI.addCategory(categoryGenerationFlowers = new BLexiconCategory(LibLexicon.CATEGORY_GENERATION_FLOWERS, 5));
|
||||
BotaniaAPI.addCategory(categoryFunctionalFlowers = new BLexiconCategory(LibLexicon.CATEGORY_FUNCTIONAL_FLOWERS, 5));
|
||||
BotaniaAPI.addCategory(categoryDevices = new BLexiconCategory(LibLexicon.CATEGORY_DEVICES, 5));
|
||||
BotaniaAPI.addCategory(categoryTools = new BLexiconCategory(LibLexicon.CATEGORY_TOOLS, 0));
|
||||
BotaniaAPI.addCategory(categoryBaubles = new BLexiconCategory(LibLexicon.CATEGORY_BAUBLES, 5));
|
||||
BotaniaAPI.addCategory(categoryAlfhomancy = new BLexiconCategory(LibLexicon.CATEGORY_ALFHOMANCY, 5));
|
||||
BotaniaAPI.addCategory(categoryMisc = new BLexiconCategory(LibLexicon.CATEGORY_MISC, 0));
|
||||
|
||||
// BASICS ENTRIES
|
||||
introVideo = new BLexiconEntry(LibLexicon.BASICS_INTRO_VIDEO, categoryBasics);
|
||||
|
||||
Reference in new issue
Block a user