mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-18 19:29:32 +00:00
Book section gating
- Added section unlock criteria - Added type adapter for Hex/Binary int String -> int
This commit is contained in:
1 parent
1ac2d95644
commit
b8e0dde333
9 files changed
+221
-105
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package slimeknights.mantle.client.book;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import java.util.HashMap;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.IReloadableResourceManager;
|
||||
@@ -27,6 +28,7 @@ import slimeknights.mantle.client.book.data.content.ContentTextImage;
|
||||
import slimeknights.mantle.client.book.data.content.ContentTextLeftImage;
|
||||
import slimeknights.mantle.client.book.data.content.ContentTextRightImage;
|
||||
import slimeknights.mantle.client.book.data.content.PageContent;
|
||||
import slimeknights.mantle.client.book.data.deserializer.HexStringDeserializer;
|
||||
import slimeknights.mantle.client.book.repository.BookRepository;
|
||||
import slimeknights.mantle.network.NetworkWrapper;
|
||||
import slimeknights.mantle.network.book.PacketUpdateSavedPage;
|
||||
@@ -35,7 +37,7 @@ import slimeknights.mantle.network.book.PacketUpdateSavedPage;
|
||||
public class BookLoader implements IResourceManagerReloadListener {
|
||||
|
||||
/** GSON object to be used for book loading purposes */
|
||||
public static final Gson GSON = new Gson();
|
||||
public static final Gson GSON = new GsonBuilder().registerTypeAdapter(int.class, new HexStringDeserializer()).create();
|
||||
|
||||
/** Maps page content presets to names */
|
||||
private static final HashMap<String, Class<? extends PageContent>> typeToContentMap = new HashMap<>();
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.stats.StatFileWriter;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@@ -90,18 +91,26 @@ public class BookData implements IDataItem {
|
||||
}
|
||||
|
||||
public SectionData findSection(String name) {
|
||||
return findSection(name, null);
|
||||
}
|
||||
|
||||
public SectionData findSection(String name, @Nullable StatFileWriter writer) {
|
||||
for (SectionData section : sections)
|
||||
if (section.name.equals(name.toLowerCase()))
|
||||
return section;
|
||||
return section.isUnlocked(writer) ? section : null;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getFirstPageNumber(SectionData section) {
|
||||
return getFirstPageNumber(section, null);
|
||||
}
|
||||
|
||||
public int getFirstPageNumber(SectionData section, @Nullable StatFileWriter writer) {
|
||||
int pages = 0;
|
||||
for (SectionData sect : sections) {
|
||||
if (section == sect)
|
||||
return pages + 1;
|
||||
return section.isUnlocked(writer) ? pages + 1 : -1;
|
||||
|
||||
pages += sect.getPageCount();
|
||||
}
|
||||
@@ -110,11 +119,18 @@ public class BookData implements IDataItem {
|
||||
}
|
||||
|
||||
public PageData findPage(int number) {
|
||||
return findPage(number, null);
|
||||
}
|
||||
|
||||
public PageData findPage(int number, @Nullable StatFileWriter writer) {
|
||||
if (number < 0)
|
||||
return null;
|
||||
|
||||
int pages = 0;
|
||||
for (SectionData section : sections) {
|
||||
if (!section.isUnlocked(writer))
|
||||
continue;
|
||||
|
||||
if (pages + section.getPageCount() > number)
|
||||
return section.pages.get(number - pages);
|
||||
else
|
||||
@@ -125,10 +141,18 @@ public class BookData implements IDataItem {
|
||||
}
|
||||
|
||||
public PageData findPage(String location) {
|
||||
return findPage(findPageNumber(location));
|
||||
return findPage(location, null);
|
||||
}
|
||||
|
||||
public PageData findPage(String location, @Nullable StatFileWriter writer) {
|
||||
return findPage(findPageNumber(location, writer));
|
||||
}
|
||||
|
||||
public int findPageNumber(String location) {
|
||||
return findPageNumber(location, null);
|
||||
}
|
||||
|
||||
public int findPageNumber(String location, @Nullable StatFileWriter writer) {
|
||||
location = location.toLowerCase();
|
||||
|
||||
int pages = 0;
|
||||
@@ -140,6 +164,9 @@ public class BookData implements IDataItem {
|
||||
String pageName = location.substring(location.indexOf('.') + 1);
|
||||
|
||||
for (SectionData section : sections) {
|
||||
if (!section.isUnlocked(writer))
|
||||
continue;
|
||||
|
||||
if (!sectionName.equals(section.name)) {
|
||||
pages += section.getPageCount();
|
||||
continue;
|
||||
@@ -159,15 +186,23 @@ public class BookData implements IDataItem {
|
||||
}
|
||||
|
||||
public int getPageCount() {
|
||||
return getPageCount(null);
|
||||
}
|
||||
|
||||
public int getPageCount(@Nullable StatFileWriter writer) {
|
||||
int pages = 0;
|
||||
for (SectionData section : sections) {
|
||||
pages += section.getPageCount();
|
||||
pages += section.isUnlocked(writer) ? section.getPageCount() : 0;
|
||||
}
|
||||
return pages;
|
||||
}
|
||||
|
||||
public int getFullPageCount() {
|
||||
return (int) Math.ceil((getPageCount() - 1) / 2F) + 1;
|
||||
return getFullPageCount(null);
|
||||
}
|
||||
|
||||
public int getFullPageCount(@Nullable StatFileWriter writer) {
|
||||
return (int) Math.ceil((getPageCount(writer) - 1) / 2F) + 1;
|
||||
}
|
||||
|
||||
public String getItemAction(ItemStackData item) {
|
||||
@@ -180,8 +215,8 @@ public class BookData implements IDataItem {
|
||||
}
|
||||
|
||||
public void openGui(@Nullable ItemStack item) {
|
||||
if (Minecraft.getMinecraft().currentScreen == null)
|
||||
Minecraft.getMinecraft().displayGuiScreen(new GuiBook(this, item));
|
||||
if (Minecraft.getMinecraft().thePlayer != null)
|
||||
Minecraft.getMinecraft().displayGuiScreen(new GuiBook(this, Minecraft.getMinecraft().thePlayer.getStatFileWriter(), item));
|
||||
}
|
||||
|
||||
public void addRepository(BookRepository repository) {
|
||||
|
||||
@@ -3,11 +3,13 @@ package slimeknights.mantle.client.book.data;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.stats.Achievement;
|
||||
import net.minecraft.stats.AchievementList;
|
||||
import net.minecraft.stats.StatFileWriter;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.client.book.BookLoader;
|
||||
import slimeknights.mantle.client.book.data.content.ContentError;
|
||||
import slimeknights.mantle.client.book.data.element.CriteriaData;
|
||||
import slimeknights.mantle.client.book.data.element.ImageData;
|
||||
import static slimeknights.mantle.client.book.ResourceHelper.getResource;
|
||||
import static slimeknights.mantle.client.book.ResourceHelper.getResourceLocation;
|
||||
@@ -19,7 +21,7 @@ public class SectionData implements IDataItem {
|
||||
public String name = null;
|
||||
public String title = "";
|
||||
public ImageData icon = new ImageData();
|
||||
public CriteriaData[] unlockCriteria = new CriteriaData[0];
|
||||
public String[] requirements = new String[0];
|
||||
public String data = "";
|
||||
|
||||
public transient int unnamedPageCounter = 0;
|
||||
@@ -70,4 +72,38 @@ public class SectionData implements IDataItem {
|
||||
public int getPageCount() {
|
||||
return pages.size();
|
||||
}
|
||||
|
||||
public boolean isUnlocked(StatFileWriter writer) {
|
||||
if (writer == null || requirements == null || requirements.length == 0)
|
||||
return true;
|
||||
|
||||
for (String achievement : requirements) {
|
||||
if (!requirementSatisfied(achievement, writer))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean requirementSatisfied(String requirement, StatFileWriter writer) {
|
||||
if (writer == null)
|
||||
return true;
|
||||
|
||||
Achievement achievement = findAchievement(requirement);
|
||||
|
||||
return achievement == null || writer.hasAchievementUnlocked(achievement);
|
||||
|
||||
}
|
||||
|
||||
public static Achievement findAchievement(String name) {
|
||||
if (name == null || name.isEmpty())
|
||||
return null;
|
||||
|
||||
for (Achievement achievement : AchievementList.achievementList) {
|
||||
if (achievement.statId.equals(name))
|
||||
return achievement;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package slimeknights.mantle.client.book.data.deserializer;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class HexStringDeserializer implements JsonDeserializer<Integer> {
|
||||
|
||||
@Override
|
||||
public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isNumber())
|
||||
return json.getAsInt();
|
||||
else if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isString()) {
|
||||
try {
|
||||
String s = json.getAsString();
|
||||
|
||||
if (s.toLowerCase().startsWith("0b"))
|
||||
return Integer.parseInt(s.substring(2), 2);
|
||||
else if (s.toLowerCase().startsWith("0x"))
|
||||
return Integer.parseInt(s.substring(2), 16);
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package slimeknights.mantle.client.book.data.element;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class CriteriaData {
|
||||
// TODO criteria parsing
|
||||
}
|
||||
@@ -3,12 +3,17 @@ package slimeknights.mantle.client.gui.book;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.IProgressMeter;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.play.client.C16PacketClientStatus;
|
||||
import net.minecraft.stats.StatFileWriter;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@@ -23,7 +28,7 @@ import slimeknights.mantle.client.book.data.element.ItemStackData;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiBook extends GuiScreen {
|
||||
public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
|
||||
private static final ResourceLocation TEX_BOOK = new ResourceLocation("mantle:textures/gui/book.png");
|
||||
private static final ResourceLocation TEX_BOOKFRONT = new ResourceLocation("mantle:textures/gui/bookfront.png");
|
||||
@@ -39,8 +44,7 @@ public class GuiBook extends GuiScreen {
|
||||
public static final int PAGE_WIDTH = (int) ((PAGE_WIDTH_UNSCALED - (PAGE_PADDING + PAGE_MARGIN) * 2) / PAGE_SCALE);
|
||||
public static final int PAGE_HEIGHT = (int) ((PAGE_HEIGHT_UNSCALED - (PAGE_PADDING + PAGE_MARGIN) * 2) / PAGE_SCALE);
|
||||
|
||||
public static boolean side = false;
|
||||
|
||||
private boolean loadingAchievements = true;
|
||||
private GuiArrow previousArrow, nextArrow, backArrow, indexArrow;
|
||||
|
||||
public final BookData book;
|
||||
@@ -51,15 +55,16 @@ public class GuiBook extends GuiScreen {
|
||||
private ArrayList<BookElement> leftElements = new ArrayList<>();
|
||||
private ArrayList<BookElement> rightElements = new ArrayList<>();
|
||||
|
||||
public GuiBook(BookData book, @Nullable ItemStack item) {
|
||||
public StatFileWriter statFile;
|
||||
|
||||
public GuiBook(BookData book, StatFileWriter statFile, @Nullable ItemStack item) {
|
||||
this.book = book;
|
||||
this.item = item;
|
||||
|
||||
openPage(book.findPageNumber(BookHelper.getSavedPage(item)));
|
||||
this.statFile = statFile;
|
||||
}
|
||||
|
||||
public void drawerTransform(boolean rightSide) {
|
||||
side = rightSide;
|
||||
if (rightSide)
|
||||
GlStateManager.translate(width / 2 + PAGE_PADDING + PAGE_MARGIN, height / 2 - PAGE_HEIGHT_UNSCALED / 2 + PAGE_PADDING + PAGE_MARGIN, 0);
|
||||
else
|
||||
@@ -70,6 +75,16 @@ public class GuiBook extends GuiScreen {
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
FontRenderer font = mc.fontRendererObj;
|
||||
|
||||
if (loadingAchievements) {
|
||||
this.drawDefaultBackground();
|
||||
|
||||
this.drawCenteredString(this.fontRendererObj, I18n.format("multiplayer.downloadingStats"), this.width / 2, this.height / 2, 16777215);
|
||||
this.drawCenteredString(this.fontRendererObj, lanSearchStates[(int) (Minecraft.getSystemTime() / 150L % (long) lanSearchStates.length)], this.width / 2, this.height / 2 + this.fontRendererObj.FONT_HEIGHT * 2, 16777215);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
GlStateManager.enableAlpha();
|
||||
GlStateManager.enableBlend();
|
||||
|
||||
@@ -160,7 +175,7 @@ public class GuiBook extends GuiScreen {
|
||||
// Set color back to white
|
||||
GlStateManager.color(1F, 1F, 1F, 1F);
|
||||
|
||||
if ((page < book.getFullPageCount() - 1 || book.getPageCount() % 2 != 0) && page < book.getFullPageCount()) {
|
||||
if ((page < book.getFullPageCount(statFile) - 1 || book.getPageCount(statFile) % 2 != 0) && page < book.getFullPageCount(statFile)) {
|
||||
drawModalRectWithCustomSizedTexture(width / 2, height / 2 - PAGE_HEIGHT_UNSCALED / 2, PAGE_WIDTH_UNSCALED, PAGE_HEIGHT_UNSCALED, PAGE_WIDTH_UNSCALED, PAGE_HEIGHT_UNSCALED, 512, 512);
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
@@ -203,6 +218,9 @@ public class GuiBook extends GuiScreen {
|
||||
}
|
||||
|
||||
public void openPage(int page, boolean returner) {
|
||||
if (loadingAchievements)
|
||||
return;
|
||||
|
||||
if (page < 0)
|
||||
return;
|
||||
|
||||
@@ -214,7 +232,7 @@ public class GuiBook extends GuiScreen {
|
||||
else
|
||||
bookPage = (page - 2) / 2 + 1;
|
||||
|
||||
if (bookPage >= -1 && bookPage < book.getFullPageCount()) {
|
||||
if (bookPage >= -1 && bookPage < book.getFullPageCount(statFile)) {
|
||||
if (returner)
|
||||
oldPage = this.page;
|
||||
|
||||
@@ -228,6 +246,9 @@ public class GuiBook extends GuiScreen {
|
||||
}
|
||||
|
||||
private void buildPages() {
|
||||
if (loadingAchievements)
|
||||
return;
|
||||
|
||||
leftElements.clear();
|
||||
rightElements.clear();
|
||||
|
||||
@@ -235,13 +256,13 @@ public class GuiBook extends GuiScreen {
|
||||
return;
|
||||
|
||||
if (page == 0) {
|
||||
PageData page = book.findPage(0);
|
||||
PageData page = book.findPage(0, statFile);
|
||||
|
||||
if (page != null)
|
||||
page.content.build(book, rightElements);
|
||||
} else {
|
||||
PageData leftPage = book.findPage((page - 1) * 2 + 1);
|
||||
PageData rightPage = book.findPage((page - 1) * 2 + 2);
|
||||
PageData leftPage = book.findPage((page - 1) * 2 + 1, statFile);
|
||||
PageData rightPage = book.findPage((page - 1) * 2 + 2, statFile);
|
||||
|
||||
if (leftPage != null)
|
||||
leftPage.content.build(book, leftElements);
|
||||
@@ -259,6 +280,11 @@ public class GuiBook extends GuiScreen {
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
if (loadingAchievements) {
|
||||
this.mc.getNetHandler().addToSendQueue(new C16PacketClientStatus(C16PacketClientStatus.EnumState.REQUEST_STATS));
|
||||
return;
|
||||
}
|
||||
|
||||
// The books are unreadable at Gui Scale set to small, so we'll double the scale, and of course half the size so that all our code still works as it should
|
||||
if (mc.gameSettings.guiScale == 1) {
|
||||
width /= 2F;
|
||||
@@ -282,8 +308,11 @@ public class GuiBook extends GuiScreen {
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
|
||||
if (loadingAchievements)
|
||||
return;
|
||||
|
||||
previousArrow.visible = page != -1;
|
||||
nextArrow.visible = page < book.getFullPageCount() - (book.getPageCount() % 2 != 0 ? 0 : 1);
|
||||
nextArrow.visible = page < book.getFullPageCount(statFile) - (book.getPageCount(statFile) % 2 != 0 ? 0 : 1);
|
||||
backArrow.visible = oldPage >= -1;
|
||||
|
||||
if (page == -1) {
|
||||
@@ -300,10 +329,21 @@ public class GuiBook extends GuiScreen {
|
||||
nextArrow.yPosition = height / 2 + 75;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doneLoading() {
|
||||
loadingAchievements = false;
|
||||
|
||||
initGui();
|
||||
openPage(book.findPageNumber(BookHelper.getSavedPage(item), statFile));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton button) {
|
||||
if (loadingAchievements)
|
||||
return;
|
||||
|
||||
if (button instanceof GuiBookmark) {
|
||||
openPage(book.findPageNumber(((GuiBookmark) button).data.page));
|
||||
openPage(book.findPageNumber(((GuiBookmark) button).data.page, statFile));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -314,8 +354,8 @@ public class GuiBook extends GuiScreen {
|
||||
page = -1;
|
||||
} else if (button == nextArrow) {
|
||||
page++;
|
||||
if (page > book.getFullPageCount() - (book.getPageCount() % 2 != 0 ? 0 : 1))
|
||||
page = book.getFullPageCount() - 1;
|
||||
if (page > book.getFullPageCount(statFile) - (book.getPageCount(statFile) % 2 != 0 ? 0 : 1))
|
||||
page = book.getFullPageCount(statFile) - 1;
|
||||
} else if (button == backArrow) {
|
||||
if (oldPage >= -1)
|
||||
page = oldPage;
|
||||
@@ -331,6 +371,9 @@ public class GuiBook extends GuiScreen {
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
|
||||
if (loadingAchievements)
|
||||
return;
|
||||
|
||||
if (keyCode == Keyboard.KEY_LEFT || keyCode == Keyboard.KEY_A)
|
||||
actionPerformed(previousArrow);
|
||||
else if (keyCode == Keyboard.KEY_RIGHT || keyCode == Keyboard.KEY_D)
|
||||
@@ -339,6 +382,9 @@ public class GuiBook extends GuiScreen {
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
if (loadingAchievements)
|
||||
return;
|
||||
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
|
||||
boolean right = false;
|
||||
@@ -361,10 +407,13 @@ public class GuiBook extends GuiScreen {
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
PageData page = this.page == 0 ? book.findPage(0) : book.findPage((this.page - 1) * 2 + 1);
|
||||
if (loadingAchievements)
|
||||
return;
|
||||
|
||||
PageData page = this.page == 0 ? book.findPage(0, statFile) : book.findPage((this.page - 1) * 2 + 1, statFile);
|
||||
|
||||
if (page == null)
|
||||
page = book.findPage((this.page - 1) * 2 + 2);
|
||||
page = book.findPage((this.page - 1) * 2 + 2, statFile);
|
||||
|
||||
if (this.page == -1)
|
||||
BookLoader.updateSavedPage(mc.thePlayer, item, "");
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package slimeknights.mantle.client.gui.book.element;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.stats.Achievement;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import slimeknights.mantle.client.book.data.SectionData;
|
||||
|
||||
public class ElementSection extends BookElement {
|
||||
@@ -21,12 +25,16 @@ public class ElementSection extends BookElement {
|
||||
|
||||
@Override
|
||||
public void draw(int mouseX, int mouseY, float partialTicks) {
|
||||
boolean unlocked = section.isUnlocked(parent.statFile);
|
||||
boolean hover = mouseX > x && mouseY > y && mouseX < x + WIDTH && mouseY < y + HEIGHT;
|
||||
|
||||
if (section.icon != null) {
|
||||
Minecraft.getMinecraft().renderEngine.bindTexture(section.icon.location);
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F, hover ? 1F : 0.5F);
|
||||
if (unlocked)
|
||||
GlStateManager.color(1F, 1F, 1F, hover ? 1F : 0.5F);
|
||||
else
|
||||
GlStateManager.color(0.5F, 0.5F, 0.5F, 1F);
|
||||
|
||||
drawScaledCustomSizeModalRect(x + WIDTH / 2 - IMG_SIZE / 2, y + HEIGHT / 2 - IMG_SIZE / 2, section.icon.u, section.icon.v, section.icon.uw, section.icon.vh, IMG_SIZE, IMG_SIZE, section.icon.texWidth, section.icon.texHeight);
|
||||
}
|
||||
@@ -34,8 +42,25 @@ public class ElementSection extends BookElement {
|
||||
Minecraft.getMinecraft().fontRendererObj.drawString(section.title, x + WIDTH / 2 - Minecraft.getMinecraft().fontRendererObj.getStringWidth(section.title) / 2, y + HEIGHT - Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT, hover ? 0xFF000000 : 0x7F000000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOverlay(int mouseX, int mouseY, float partialTicks) {
|
||||
if (section != null && !section.isUnlocked(parent.statFile) && mouseX > x && mouseY > y && mouseX < x + WIDTH && mouseY < y + HEIGHT) {
|
||||
List<String> l = new ArrayList<String>();
|
||||
l.add(EnumChatFormatting.RED + "Locked");
|
||||
l.add("Requirements:");
|
||||
|
||||
for (String requirement : section.requirements) {
|
||||
Achievement achievement = SectionData.findAchievement(requirement);
|
||||
if (achievement != null)
|
||||
l.add((SectionData.requirementSatisfied(requirement, parent.statFile) ? EnumChatFormatting.GREEN : EnumChatFormatting.RED) + EnumChatFormatting.getTextWithoutFormattingCodes(achievement.getStatName().getFormattedText()));
|
||||
}
|
||||
|
||||
drawHoveringText(l, mouseX, mouseY, Minecraft.getMinecraft().fontRendererObj);
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if (mouseButton == 0 && section != null && mouseX > x && mouseY > y && mouseX < x + WIDTH && mouseY < y + HEIGHT)
|
||||
if (mouseButton == 0 && section != null && section.isUnlocked(parent.statFile) && mouseX > x && mouseY > y && mouseX < x + WIDTH && mouseY < y + HEIGHT)
|
||||
parent.openPage(parent.book.getFirstPageNumber(section));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user