mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-20 12:09:44 +00:00
Merge branch 'master' into 1.12
This commit is contained in:
commit
05afdba6df
39 files changed
+202
-914
No files matched your search
@@ -1,17 +1,16 @@
|
||||
package slimeknights.mantle.client.book;
|
||||
|
||||
import net.minecraft.stats.StatisticsManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.PageData;
|
||||
import slimeknights.mantle.client.book.data.SectionData;
|
||||
import slimeknights.mantle.client.book.data.content.ContentSectionList;
|
||||
import slimeknights.mantle.client.book.data.content.ContentTableOfContents;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BookTransformer {
|
||||
|
||||
@@ -34,10 +33,10 @@ public abstract class BookTransformer {
|
||||
public void transform(BookData book) {
|
||||
SectionData index = new SectionData(true) {
|
||||
@Override
|
||||
public void update(StatisticsManager statisticsManager) {
|
||||
public void update(GuiBook.AdvancementCache advancementCache) {
|
||||
pages.clear();
|
||||
|
||||
List<SectionData> visibleSections = parent.getVisibleSections(statisticsManager);
|
||||
List<SectionData> visibleSections = parent.getVisibleSections(advancementCache);
|
||||
|
||||
if(visibleSections.isEmpty()) {
|
||||
return;
|
||||
|
||||
@@ -3,20 +3,9 @@ package slimeknights.mantle.client.book.data;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.stats.StatisticsManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import slimeknights.mantle.Mantle;
|
||||
import slimeknights.mantle.client.book.BookLoader;
|
||||
import slimeknights.mantle.client.book.BookTransformer;
|
||||
@@ -25,6 +14,14 @@ import slimeknights.mantle.client.book.data.element.ItemStackData;
|
||||
import slimeknights.mantle.client.book.repository.BookRepository;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class BookData implements IDataItem {
|
||||
|
||||
@@ -169,12 +166,12 @@ public class BookData implements IDataItem {
|
||||
return findSection(name, null);
|
||||
}
|
||||
|
||||
public SectionData findSection(String name, @Nullable StatisticsManager statisticsManager) {
|
||||
public SectionData findSection(String name, GuiBook.AdvancementCache advancementCache) {
|
||||
for(SectionData section : sections) {
|
||||
section.update(statisticsManager);
|
||||
section.update(advancementCache);
|
||||
|
||||
if(section.name.equals(name.toLowerCase())) {
|
||||
return section.isUnlocked(statisticsManager) ? section : null;
|
||||
return section.isUnlocked(advancementCache) ? section : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,16 +182,16 @@ public class BookData implements IDataItem {
|
||||
return getFirstPageNumber(section, null);
|
||||
}
|
||||
|
||||
public int getFirstPageNumber(SectionData section, @Nullable StatisticsManager statisticsManager) {
|
||||
public int getFirstPageNumber(SectionData section, @Nullable GuiBook.AdvancementCache advancementCache) {
|
||||
int pages = 0;
|
||||
for(SectionData sect : sections) {
|
||||
sect.update(statisticsManager);
|
||||
sect.update(advancementCache);
|
||||
|
||||
if(section == sect) {
|
||||
return section.isUnlocked(statisticsManager) ? pages + 1 : -1;
|
||||
return section.isUnlocked(advancementCache) ? pages + 1 : -1;
|
||||
}
|
||||
|
||||
if(!sect.isUnlocked(statisticsManager)) {
|
||||
if(!sect.isUnlocked(advancementCache)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -208,16 +205,16 @@ public class BookData implements IDataItem {
|
||||
return findPage(number, null);
|
||||
}
|
||||
|
||||
public PageData findPage(int number, @Nullable StatisticsManager statisticsManager) {
|
||||
public PageData findPage(int number, @Nullable GuiBook.AdvancementCache advancementCache) {
|
||||
if(number < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int pages = 0;
|
||||
for(SectionData section : sections) {
|
||||
section.update(statisticsManager);
|
||||
section.update(advancementCache);
|
||||
|
||||
if(!section.isUnlocked(statisticsManager)) {
|
||||
if(!section.isUnlocked(advancementCache)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -236,15 +233,15 @@ public class BookData implements IDataItem {
|
||||
return findPage(location, null);
|
||||
}
|
||||
|
||||
public PageData findPage(String location, @Nullable StatisticsManager statisticsManager) {
|
||||
return findPage(findPageNumber(location, statisticsManager));
|
||||
public PageData findPage(String location, @Nullable GuiBook.AdvancementCache advancementCache) {
|
||||
return findPage(findPageNumber(location, advancementCache));
|
||||
}
|
||||
|
||||
public int findPageNumber(String location) {
|
||||
return findPageNumber(location, null);
|
||||
}
|
||||
|
||||
public int findPageNumber(String location, @Nullable StatisticsManager statisticsManager) {
|
||||
public int findPageNumber(String location, @Nullable GuiBook.AdvancementCache advancementCache) {
|
||||
location = location.toLowerCase();
|
||||
|
||||
int pages = 0;
|
||||
@@ -257,9 +254,9 @@ public class BookData implements IDataItem {
|
||||
String pageName = location.substring(location.indexOf('.') + 1);
|
||||
|
||||
for(SectionData section : sections) {
|
||||
section.update(statisticsManager);
|
||||
section.update(advancementCache);
|
||||
|
||||
if(!section.isUnlocked(statisticsManager)) {
|
||||
if(!section.isUnlocked(advancementCache)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -285,12 +282,12 @@ public class BookData implements IDataItem {
|
||||
return getPageCount(null);
|
||||
}
|
||||
|
||||
public int getPageCount(@Nullable StatisticsManager statisticsManager) {
|
||||
public int getPageCount(@Nullable GuiBook.AdvancementCache advancementCache) {
|
||||
int pages = 0;
|
||||
for(SectionData section : sections) {
|
||||
section.update(statisticsManager);
|
||||
section.update(advancementCache);
|
||||
|
||||
pages += section.isUnlocked(statisticsManager) ? section.getPageCount() : 0;
|
||||
pages += section.isUnlocked(advancementCache) ? section.getPageCount() : 0;
|
||||
}
|
||||
return pages;
|
||||
}
|
||||
@@ -299,8 +296,8 @@ public class BookData implements IDataItem {
|
||||
return getFullPageCount(null);
|
||||
}
|
||||
|
||||
public int getFullPageCount(@Nullable StatisticsManager statisticsManager) {
|
||||
return (int) Math.ceil((getPageCount(statisticsManager) - 1) / 2F) + 1;
|
||||
public int getFullPageCount(@Nullable GuiBook.AdvancementCache advancementCache) {
|
||||
return (int) Math.ceil((getPageCount(advancementCache) - 1) / 2F) + 1;
|
||||
}
|
||||
|
||||
public String getItemAction(ItemStackData item) {
|
||||
@@ -313,11 +310,11 @@ public class BookData implements IDataItem {
|
||||
return "";
|
||||
}
|
||||
|
||||
public List<SectionData> getVisibleSections(StatisticsManager statisticsManager) {
|
||||
public List<SectionData> getVisibleSections(GuiBook.AdvancementCache advancementCache) {
|
||||
List<SectionData> visible = new ArrayList<>();
|
||||
|
||||
for(SectionData section : sections) {
|
||||
if(section.isUnlocked(statisticsManager) || !section.hideWhenLocked) {
|
||||
if(section.isUnlocked(advancementCache) || !section.hideWhenLocked) {
|
||||
visible.add(section);
|
||||
}
|
||||
}
|
||||
@@ -336,8 +333,7 @@ public class BookData implements IDataItem {
|
||||
load();
|
||||
}
|
||||
if(Minecraft.getMinecraft().player != null) {
|
||||
Minecraft.getMinecraft()
|
||||
.displayGuiScreen(new GuiBook(this, Minecraft.getMinecraft().player.getStatFileWriter(), item));
|
||||
Minecraft.getMinecraft().displayGuiScreen(new GuiBook(this, item));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +1,18 @@
|
||||
package slimeknights.mantle.client.book.data;
|
||||
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.advancements.AdvancementManager;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.advancements.AdvancementProgress;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.stats.StatisticsManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import slimeknights.mantle.client.book.BookLoader;
|
||||
import slimeknights.mantle.client.book.data.content.ContentError;
|
||||
import slimeknights.mantle.client.book.data.element.ImageData;
|
||||
import slimeknights.mantle.client.book.repository.BookRepository;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class SectionData implements IDataItem {
|
||||
@@ -82,7 +77,7 @@ public class SectionData implements IDataItem {
|
||||
icon.location = source.getResourceLocation(icon.file, true);
|
||||
}
|
||||
|
||||
public void update(@Nullable StatisticsManager statisticsManager) {
|
||||
public void update(@Nullable GuiBook.AdvancementCache advancementCache) {
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
@@ -94,13 +89,13 @@ public class SectionData implements IDataItem {
|
||||
return pages.size();
|
||||
}
|
||||
|
||||
public boolean isUnlocked(StatisticsManager statisticsManager) {
|
||||
if(statisticsManager == null || requirements == null || requirements.length == 0) {
|
||||
public boolean isUnlocked(GuiBook.AdvancementCache advancementCache) {
|
||||
if(advancementCache == null || requirements == null || requirements.length == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for(String achievement : requirements) {
|
||||
if(!requirementSatisfied(achievement, statisticsManager)) {
|
||||
if(!requirementSatisfied(achievement, advancementCache)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -108,28 +103,14 @@ public class SectionData implements IDataItem {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean requirementSatisfied(String requirement, StatisticsManager writer) {
|
||||
if(writer == null) {
|
||||
public static boolean requirementSatisfied(String requirement, GuiBook.AdvancementCache advancementCache) {
|
||||
if(advancementCache == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Advancement advancement = findAdvancement(requirement);
|
||||
AdvancementProgress progress = advancementCache.getProgress(requirement);
|
||||
|
||||
return advancement == null;//TODO: Readd || writer.hasAchievementUnlocked(advancement);
|
||||
return progress != null && progress.isDone();
|
||||
|
||||
}
|
||||
|
||||
public static Advancement findAdvancement(String name) {
|
||||
if(name == null || name.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for(Advancement advancement : Minecraft.getMinecraft().player.connection.getAdvancementManager().getAdvancementList().getAdvancements()) {
|
||||
if(advancement.getId().equals(new ResourceLocation(name))) {
|
||||
return advancement;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
package slimeknights.mantle.client.gui.book;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
import static slimeknights.mantle.client.gui.book.Textures.TEX_BOX;
|
||||
|
||||
public class BoxRenderer {
|
||||
|
||||
public static final int TEX_SIZE = 128;
|
||||
|
||||
public static void drawBox(int x, int y, int width, int height, int index) {
|
||||
drawBox(x, y, width, height, index, 16, 16, 4, 4, 2, 2);
|
||||
}
|
||||
|
||||
public static void drawBox(int x, int y, int width, int height, int index, int sprW, int sprH, int segW, int segH, int segGW, int segGH) {
|
||||
Minecraft.getMinecraft().renderEngine.bindTexture(TEX_BOX);
|
||||
|
||||
int sx = x, sy = y;
|
||||
|
||||
for(int i = 0; i < 3; i++) {
|
||||
int sgW = width - segW * 2;
|
||||
|
||||
if(i % 2 == 0) {
|
||||
sgW = segW;
|
||||
}
|
||||
|
||||
for(int j = 0; j < 3; j++) {
|
||||
int sgH = height - segH * 2;
|
||||
|
||||
if(j % 2 == 0) {
|
||||
sgH = segH;
|
||||
}
|
||||
|
||||
int[] matrix = getTextureMatrixCoords(index, sprW, sprH, segW, segH, segGW, segGH, i + j * 3);
|
||||
Gui.drawScaledCustomSizeModalRect(sx, sy, matrix[0], matrix[1], segW, segH, sgW, sgH, TEX_SIZE, TEX_SIZE);
|
||||
|
||||
sy += sgH;
|
||||
}
|
||||
|
||||
sx += sgW;
|
||||
sy = y;
|
||||
}
|
||||
}
|
||||
|
||||
public static int[] getTextureMatrixCoords(int index, int sprW, int sprH, int segW, int segH, int segGW, int segGH, int segId) {
|
||||
int totalWidth = segW * 3 + segGW * 2;
|
||||
int totalHeight = segH * 3 + segGH * 2;
|
||||
|
||||
return getTextureMatrixCoords((index % (256 / sprW) * sprW) + (sprW / 2 - totalWidth / 2), (MathHelper
|
||||
.floor(index / (256F / sprH)) * sprH) + (sprH / 2 - totalHeight / 2), segW, segH, segGW, segGH, segId);
|
||||
}
|
||||
|
||||
public static int[] getTextureMatrixCoords(int u, int v, int segW, int segH, int segGW, int segGH, int segId) {
|
||||
int[] coords = new int[4];
|
||||
|
||||
int col = segId % 3;
|
||||
int row = MathHelper.floor(segId / 3F);
|
||||
|
||||
coords[0] = u + col * segW + col * segGW;
|
||||
coords[1] = v + row * segH + row * segGH;
|
||||
coords[2] = coords[0] + segW;
|
||||
coords[3] = coords[1] + segH;
|
||||
|
||||
return coords;
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,15 @@ package slimeknights.mantle.client.gui.book;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.advancements.AdvancementList;
|
||||
import net.minecraft.advancements.AdvancementProgress;
|
||||
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.multiplayer.ClientAdvancementManager;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
@@ -14,6 +18,7 @@ import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.play.client.CPacketClientStatus;
|
||||
import net.minecraft.stats.StatisticsManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -22,6 +27,7 @@ import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -38,7 +44,7 @@ import static slimeknights.mantle.client.gui.book.Textures.TEX_BOOK;
|
||||
import static slimeknights.mantle.client.gui.book.Textures.TEX_BOOKFRONT;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
public class GuiBook extends GuiScreen {
|
||||
|
||||
public static boolean debug = false;
|
||||
|
||||
@@ -63,7 +69,6 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
init(); // initializes page width and height
|
||||
}
|
||||
|
||||
private boolean loadingAchievements = true;
|
||||
private GuiArrow previousArrow, nextArrow, backArrow, indexArrow;
|
||||
|
||||
public final BookData book;
|
||||
@@ -74,21 +79,25 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
private ArrayList<BookElement> leftElements = new ArrayList<>();
|
||||
private ArrayList<BookElement> rightElements = new ArrayList<>();
|
||||
|
||||
public StatisticsManager statisticsManager;
|
||||
public AdvancementCache advancementCache;
|
||||
|
||||
public static void init() {
|
||||
PAGE_WIDTH = (int) ((PAGE_WIDTH_UNSCALED - (PAGE_PADDING_LEFT + PAGE_PADDING_RIGHT + PAGE_MARGIN + PAGE_MARGIN)) / PAGE_SCALE);
|
||||
PAGE_HEIGHT = (int) ((PAGE_HEIGHT_UNSCALED - (PAGE_PADDING_TOP + PAGE_PADDING_BOT + PAGE_MARGIN + PAGE_MARGIN)) / PAGE_SCALE);
|
||||
}
|
||||
|
||||
public GuiBook(BookData book, StatisticsManager statisticsManager, @Nullable ItemStack item) {
|
||||
public GuiBook(BookData book, @Nullable ItemStack item) {
|
||||
this.book = book;
|
||||
this.item = item;
|
||||
|
||||
this.statisticsManager = statisticsManager;
|
||||
this.mc = Minecraft.getMinecraft();
|
||||
this.fontRenderer = mc.fontRenderer;
|
||||
init();
|
||||
|
||||
advancementCache = new AdvancementCache();
|
||||
this.mc.player.connection.getAdvancementManager().setListener(advancementCache);
|
||||
|
||||
openPage(book.findPageNumber(BookHelper.getSavedPage(item), advancementCache));
|
||||
}
|
||||
|
||||
public void drawerTransform(boolean rightSide) {
|
||||
@@ -131,17 +140,6 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
fontRenderer = mc.fontRenderer;
|
||||
}
|
||||
|
||||
if(loadingAchievements) {
|
||||
this.drawDefaultBackground();
|
||||
|
||||
this.drawCenteredString(this.fontRenderer, I18n
|
||||
.format("multiplayer.downloadingStats"), this.width / 2, this.height / 2, 16777215);
|
||||
this.drawCenteredString(this.fontRenderer, LOADING_STRINGS[(int) (Minecraft
|
||||
.getSystemTime() / 150L % (long) LOADING_STRINGS.length)], this.width / 2, this.height / 2 + this.fontRenderer.FONT_HEIGHT * 2, 16777215);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(debug) {
|
||||
drawRect(0, 0, fontRenderer.getStringWidth("DEBUG") + 4, fontRenderer.FONT_HEIGHT + 4, 0x55000000);
|
||||
fontRenderer.drawString("DEBUG", 2, 2, 0xFFFFFFFF);
|
||||
@@ -255,6 +253,14 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
element.drawOverlay(mX, mY, partialTicks, fontRenderer);
|
||||
}
|
||||
|
||||
// Not foreach to prevent conmodification crashes
|
||||
for(int i = 0; i < leftElements.size(); i++) {
|
||||
BookElement element = leftElements.get(i);
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F, 1F);
|
||||
element.drawTooltips(mX, mY, partialTicks, fontRenderer);
|
||||
}
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
@@ -264,8 +270,8 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
GlStateManager.color(1F, 1F, 1F, 1F);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
|
||||
if((page < book.getFullPageCount(statisticsManager) - 1 || book.getPageCount(statisticsManager) % 2 != 0) && page < book
|
||||
.getFullPageCount(statisticsManager)) {
|
||||
int fullPageCount = book.getFullPageCount(advancementCache);
|
||||
if((page < fullPageCount - 1 || fullPageCount % 2 != 0) && page < fullPageCount) {
|
||||
drawModalRectWithCustomSizedTexture(width / 2, height / 2 - PAGE_HEIGHT_UNSCALED / 2, PAGE_WIDTH_UNSCALED, PAGE_HEIGHT_UNSCALED, PAGE_WIDTH_UNSCALED, PAGE_HEIGHT_UNSCALED, TEX_SIZE, TEX_SIZE);
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
@@ -297,6 +303,14 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
element.drawOverlay(mX, mY, partialTicks, fontRenderer);
|
||||
}
|
||||
|
||||
// Not foreach to prevent conmodification crashes
|
||||
for(int i = 0; i < rightElements.size(); i++) {
|
||||
BookElement element = rightElements.get(i);
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F, 1F);
|
||||
element.drawTooltips(mX, mY, partialTicks, fontRenderer);
|
||||
}
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
}
|
||||
@@ -311,10 +325,6 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
}
|
||||
|
||||
public int openPage(int page, boolean returner) {
|
||||
if(loadingAchievements) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(page < 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -328,7 +338,7 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
bookPage = (page - 2) / 2 + 1;
|
||||
}
|
||||
|
||||
if(bookPage >= -1 && bookPage < book.getFullPageCount(statisticsManager)) {
|
||||
if(bookPage >= -1 && bookPage < book.getFullPageCount(advancementCache)) {
|
||||
if(returner) {
|
||||
oldPage = this.page;
|
||||
}
|
||||
@@ -367,10 +377,6 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
}
|
||||
|
||||
public void openCover() {
|
||||
if(loadingAchievements) {
|
||||
return;
|
||||
}
|
||||
|
||||
_setPage(-1);
|
||||
|
||||
this.leftElements.clear();
|
||||
@@ -383,10 +389,6 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
}
|
||||
|
||||
private void buildPages() {
|
||||
if(loadingAchievements) {
|
||||
return;
|
||||
}
|
||||
|
||||
leftElements.clear();
|
||||
rightElements.clear();
|
||||
|
||||
@@ -395,14 +397,14 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
}
|
||||
|
||||
if(page == 0) {
|
||||
PageData page = book.findPage(0, statisticsManager);
|
||||
PageData page = book.findPage(0, advancementCache);
|
||||
|
||||
if(page != null) {
|
||||
page.content.build(book, rightElements, false);
|
||||
}
|
||||
} else {
|
||||
PageData leftPage = book.findPage((page - 1) * 2 + 1, statisticsManager);
|
||||
PageData rightPage = book.findPage((page - 1) * 2 + 2, statisticsManager);
|
||||
PageData leftPage = book.findPage((page - 1) * 2 + 1, advancementCache);
|
||||
PageData rightPage = book.findPage((page - 1) * 2 + 2, advancementCache);
|
||||
|
||||
if(leftPage != null) {
|
||||
leftPage.content.build(book, leftElements, false);
|
||||
@@ -424,11 +426,6 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
if(loadingAchievements) {
|
||||
this.mc.getConnection().sendPacket(new CPacketClientStatus((CPacketClientStatus.State.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) {
|
||||
@@ -454,12 +451,8 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
|
||||
if(loadingAchievements) {
|
||||
return;
|
||||
}
|
||||
|
||||
previousArrow.visible = page != -1;
|
||||
nextArrow.visible = page < book.getFullPageCount(statisticsManager) - (book.getPageCount(statisticsManager) % 2 != 0 ? 0 : 1);
|
||||
nextArrow.visible = page < book.getFullPageCount(advancementCache) - (book.getPageCount(advancementCache) % 2 != 0 ? 0 : 1);
|
||||
backArrow.visible = oldPage >= -1;
|
||||
|
||||
if(page == -1) {
|
||||
@@ -477,22 +470,10 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
nextArrow.y = height / 2 + 75;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatsUpdated() {
|
||||
loadingAchievements = false;
|
||||
|
||||
initGui();
|
||||
openPage(book.findPageNumber(BookHelper.getSavedPage(item), statisticsManager));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton button) {
|
||||
if(loadingAchievements) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(button instanceof GuiBookmark) {
|
||||
openPage(book.findPageNumber(((GuiBookmark) button).data.page, statisticsManager));
|
||||
openPage(book.findPageNumber(((GuiBookmark) button).data.page, advancementCache));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -504,8 +485,9 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
}
|
||||
} else if(button == nextArrow) {
|
||||
page++;
|
||||
if(page > book.getFullPageCount(statisticsManager) - (book.getPageCount(statisticsManager) % 2 != 0 ? 0 : 1)) {
|
||||
page = book.getFullPageCount(statisticsManager) - 1;
|
||||
int fullPageCount = book.getFullPageCount(advancementCache);
|
||||
if(page > fullPageCount - (fullPageCount % 2 != 0 ? 0 : 1)) {
|
||||
page = fullPageCount - 1;
|
||||
}
|
||||
} else if(button == backArrow) {
|
||||
if(oldPage >= -1) {
|
||||
@@ -523,10 +505,6 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
|
||||
if(loadingAchievements) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch(keyCode) {
|
||||
case Keyboard.KEY_LEFT:
|
||||
case Keyboard.KEY_A:
|
||||
@@ -544,10 +522,6 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
if(loadingAchievements) {
|
||||
return;
|
||||
}
|
||||
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
|
||||
boolean right = false;
|
||||
@@ -576,10 +550,6 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
protected void mouseReleased(int mouseX, int mouseY, int state) {
|
||||
super.mouseReleased(mouseX, mouseY, state);
|
||||
|
||||
if(loadingAchievements) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean right = false;
|
||||
mouseX = getMouseX(false);
|
||||
mouseY = getMouseY();
|
||||
@@ -598,10 +568,6 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
|
||||
@Override
|
||||
protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
|
||||
if(loadingAchievements) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean right = false;
|
||||
mouseX = getMouseX(false);
|
||||
mouseY = getMouseY();
|
||||
@@ -620,17 +586,14 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
if(loadingAchievements) {
|
||||
return;
|
||||
}
|
||||
if(mc.player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PageData page = this.page == 0 ? book.findPage(0, statisticsManager) : book.findPage((this.page - 1) * 2 + 1, statisticsManager);
|
||||
PageData page = this.page == 0 ? book.findPage(0, advancementCache) : book.findPage((this.page - 1) * 2 + 1, advancementCache);
|
||||
|
||||
if(page == null) {
|
||||
page = book.findPage((this.page - 1) * 2 + 2, statisticsManager);
|
||||
page = book.findPage((this.page - 1) * 2 + 2, advancementCache);
|
||||
}
|
||||
|
||||
if(this.page == -1) {
|
||||
@@ -644,4 +607,59 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
public boolean doesGuiPauseGame() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public class AdvancementCache implements ClientAdvancementManager.IListener {
|
||||
private HashMap<Advancement, AdvancementProgress> progress = new HashMap<>();
|
||||
private HashMap<ResourceLocation, Advancement> nameCache = new HashMap<>();
|
||||
|
||||
public AdvancementProgress getProgress(String id){
|
||||
return getProgress(getAdvancement(id));
|
||||
}
|
||||
|
||||
public AdvancementProgress getProgress(Advancement advancement){
|
||||
return progress.get(advancement);
|
||||
}
|
||||
|
||||
public Advancement getAdvancement(String id){
|
||||
return nameCache.get(new ResourceLocation(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateAdvancementProgress(Advancement advancement, AdvancementProgress advancementProgress) {
|
||||
progress.put(advancement, advancementProgress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectedTab(@Nullable Advancement advancement) {
|
||||
// noop
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rootAdvancementAdded(Advancement advancement) {
|
||||
nameCache.put(advancement.getId(), advancement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rootAdvancementRemoved(Advancement advancement) {
|
||||
progress.remove(advancement);
|
||||
nameCache.remove(advancement.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nonRootAdvancementAdded(Advancement advancement) {
|
||||
nameCache.put(advancement.getId(), advancement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nonRootAdvancementRemoved(Advancement advancement) {
|
||||
progress.remove(advancement);
|
||||
nameCache.remove(advancement.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void advancementsCleared() {
|
||||
progress.clear();
|
||||
nameCache.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,13 @@
|
||||
package slimeknights.mantle.client.gui.book;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import net.minecraftforge.fml.client.config.GuiUtils;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@@ -17,13 +15,29 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.Mantle;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class TextDataRenderer {
|
||||
|
||||
/**
|
||||
* @deprecated Call drawText with tooltip param and then call drawTooltip separately on the tooltip layer to prevent overlap
|
||||
*/
|
||||
public static String drawText(int x, int y, int boxWidth, int boxHeight, TextData[] data, int mouseX, int mouseY, FontRenderer fr) {
|
||||
String action = "";
|
||||
List<String> tooltip = new ArrayList<String>();
|
||||
String action = drawText(x, y, boxWidth, boxHeight, data, mouseX, mouseY, fr, tooltip);
|
||||
|
||||
String[] drawLabel = null;
|
||||
if(tooltip.size() > 0) {
|
||||
drawTooltip(tooltip, mouseX, mouseY, fr);
|
||||
}
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
public static String drawText(int x, int y, int boxWidth, int boxHeight, TextData[] data, int mouseX, int mouseY, FontRenderer fr, @Nonnull List<String> tooltip) {
|
||||
String action = "";
|
||||
|
||||
int atX = x;
|
||||
int atY = y;
|
||||
@@ -124,7 +138,7 @@ public class TextDataRenderer {
|
||||
drawGradientRect(mouseX, mouseY, mouseX + 5, mouseY + 5, 0xFFFF00FF, 0xFFFFFF00);*/
|
||||
|
||||
if((mouseX >= box1X && mouseX <= box1W && mouseY >= box1Y && mouseY <= box1H && box1X != box1W && box1Y != box1H) || (mouseX >= box2X && mouseX <= box2W && mouseY >= box2Y && mouseY <= box2H && box2X != box2W && box2Y != box2H) || (mouseX >= box3X && mouseX <= box3W && mouseY >= box3Y && mouseY <= box3H && box3X != box3W && box1Y != box3H)) {
|
||||
drawLabel = item.tooltip;
|
||||
tooltip.addAll(Arrays.asList(item.tooltip));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,21 +156,8 @@ public class TextDataRenderer {
|
||||
}
|
||||
|
||||
if(GuiBook.debug && action != null && !action.isEmpty()) {
|
||||
String[] label = drawLabel;
|
||||
drawLabel = new String[label != null ? label.length + 2 : 1];
|
||||
|
||||
if(label != null) {
|
||||
for(int i = 0; i < label.length; i++) {
|
||||
drawLabel[i] = label[i];
|
||||
}
|
||||
}
|
||||
|
||||
drawLabel[drawLabel.length > 1 ? drawLabel.length - 2 : 0] = "";
|
||||
drawLabel[drawLabel.length - 1] = TextFormatting.GRAY + "Action: " + action;
|
||||
}
|
||||
|
||||
if(drawLabel != null) {
|
||||
drawHoveringText(drawLabel, mouseX, mouseY, fr);
|
||||
tooltip.add("");
|
||||
tooltip.add(TextFormatting.GRAY + "Action: " + action);
|
||||
}
|
||||
|
||||
return action;
|
||||
@@ -167,7 +168,7 @@ public class TextDataRenderer {
|
||||
|
||||
while(s.contains("$(") && s.contains(")$") && s.indexOf("$(") < s.indexOf(")$")) {
|
||||
String loc = s.substring(s.indexOf("$(") + 2, s.indexOf(")$"));
|
||||
s = s.replace("$(" + loc + ")$", I18n.translateToLocal(loc));
|
||||
s = s.replace("$(" + loc + ")$", I18n.format(loc));
|
||||
}
|
||||
|
||||
if(s.indexOf("$(") > s.indexOf(")$") || s.contains(")$")) {
|
||||
@@ -214,8 +215,8 @@ public class TextDataRenderer {
|
||||
}
|
||||
|
||||
//BEGIN METHODS FROM GUI
|
||||
private static void drawHoveringText(String[] textLines, int x, int y, FontRenderer font) {
|
||||
GuiUtils.drawHoveringText(ImmutableList.copyOf(textLines), x, y, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT, GuiBook.PAGE_WIDTH, font);
|
||||
public static void drawTooltip(List<String> textLines, int mouseX, int mouseY, FontRenderer font) {
|
||||
GuiUtils.drawHoveringText(textLines, mouseX, mouseY, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT, GuiBook.PAGE_WIDTH, font);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ public class Textures {
|
||||
|
||||
public static final ResourceLocation TEX_BOOK = new ResourceLocation("mantle:textures/gui/book/book.png");
|
||||
public static final ResourceLocation TEX_BOOKFRONT = new ResourceLocation("mantle:textures/gui/book/bookfront.png");
|
||||
public static final ResourceLocation TEX_BOX = new ResourceLocation("mantle:textures/gui/box.png");
|
||||
|
||||
public static final ResourceLocation TEX_CRAFTING = new ResourceLocation("mantle:textures/gui/book/crafting.png");
|
||||
public static final ResourceLocation TEX_SMELTING = new ResourceLocation("mantle:textures/gui/book/smelting.png");
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
package slimeknights.mantle.client.gui.book.editor;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.gui.book.BoxRenderer;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
import slimeknights.mantle.client.gui.book.Textures;
|
||||
|
||||
public class GuiBookEditor extends GuiScreen {
|
||||
|
||||
private static final int SIDEBAR_WIDTH = 120;
|
||||
|
||||
private GuiBook innerUi;
|
||||
private int side;
|
||||
|
||||
public GuiBookEditor(@Nullable BookData book) {
|
||||
if(book == null) {
|
||||
book = new BookData();
|
||||
}
|
||||
|
||||
innerUi = new GuiBook(book, null, null);
|
||||
innerUi.mc = Minecraft.getMinecraft();
|
||||
innerUi.onStatsUpdated();
|
||||
|
||||
innerUi._setPage(-1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
GlStateManager.pushMatrix();
|
||||
|
||||
TextureManager render = this.mc.renderEngine;
|
||||
|
||||
if(mc.gameSettings.guiScale == 1) {
|
||||
GlStateManager.scale(2F, 2F, 2F);
|
||||
|
||||
mouseX /= 2;
|
||||
mouseY /= 2;
|
||||
}
|
||||
|
||||
BoxRenderer.drawBox(width / 2 - (GuiBook.PAGE_WIDTH_UNSCALED + SIDEBAR_WIDTH) / 2,
|
||||
height / 2 - (GuiBook.PAGE_HEIGHT_UNSCALED - GuiBook.PAGE_PADDING_TOP) / 2,
|
||||
SIDEBAR_WIDTH + GuiBook.PAGE_PADDING_RIGHT + GuiBook.PAGE_MARGIN,
|
||||
GuiBook.PAGE_HEIGHT_UNSCALED - GuiBook.PAGE_PADDING_BOT, 0);
|
||||
|
||||
if(innerUi.getPage_() == -1) {
|
||||
GlStateManager.pushMatrix();
|
||||
if(mc.gameSettings.guiScale == 1) {
|
||||
GlStateManager.scale(0.5F, 0.5F, 0.5F);
|
||||
}
|
||||
innerUi.openCover();
|
||||
innerUi
|
||||
.drawScreen(mouseX * (mc.gameSettings.guiScale == 1 ? 2 : 1), mouseY * (mc.gameSettings.guiScale == 1 ? 2 : 1), partialTicks);
|
||||
GlStateManager.popMatrix();
|
||||
} else {
|
||||
render.bindTexture(Textures.TEX_BOOK);
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F);
|
||||
drawModalRectWithCustomSizedTexture(width / 2 - GuiBook.PAGE_WIDTH_UNSCALED / 2,
|
||||
height / 2 - GuiBook.PAGE_HEIGHT_UNSCALED / 2,
|
||||
0, GuiBook.PAGE_HEIGHT_UNSCALED,
|
||||
GuiBook.PAGE_WIDTH_UNSCALED - GuiBook.PAGE_MARGIN - GuiBook.PAGE_PADDING_LEFT,
|
||||
GuiBook.PAGE_HEIGHT_UNSCALED,
|
||||
GuiBook.TEX_SIZE, GuiBook.TEX_SIZE);
|
||||
drawModalRectWithCustomSizedTexture(width / 2 - GuiBook.PAGE_WIDTH_UNSCALED / 2 + GuiBook.PAGE_MARGIN + GuiBook.PAGE_PADDING_LEFT,
|
||||
height / 2 - GuiBook.PAGE_HEIGHT_UNSCALED / 2,
|
||||
GuiBook.PAGE_WIDTH_UNSCALED + GuiBook.PAGE_MARGIN + GuiBook.PAGE_PADDING_LEFT,
|
||||
GuiBook.PAGE_HEIGHT_UNSCALED,
|
||||
GuiBook.PAGE_WIDTH_UNSCALED - GuiBook.PAGE_MARGIN - GuiBook.PAGE_PADDING_RIGHT,
|
||||
GuiBook.PAGE_HEIGHT_UNSCALED,
|
||||
GuiBook.TEX_SIZE, GuiBook.TEX_SIZE);
|
||||
}
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
buttonList.clear();
|
||||
|
||||
innerUi.width = width + SIDEBAR_WIDTH * (mc.gameSettings.guiScale == 1 ? 2 : 1);
|
||||
innerUi.height = height;
|
||||
|
||||
if(mc.gameSettings.guiScale == 1) {
|
||||
width /= 2F;
|
||||
height /= 2F;
|
||||
}
|
||||
|
||||
innerUi.initGui();
|
||||
innerUi.updateScreen();
|
||||
innerUi.buttonList.clear();
|
||||
|
||||
buttonList.add(new GuiButton(0, 0, height - 20, 50, 20, "Import"));
|
||||
buttonList.add(new GuiButton(1, 55, height - 20, 50, 20, "Export"));
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,9 @@ public abstract class BookElement extends Gui {
|
||||
public void drawOverlay(int mouseX, int mouseY, float partialTicks, FontRenderer fontRenderer) {
|
||||
}
|
||||
|
||||
public void drawTooltips(int mouseX, int mouseY, float partialTicks, FontRenderer fontRenderer) {
|
||||
}
|
||||
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ public class ElementItem extends SizedBookElement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOverlay(int mouseX, int mouseY, float partialTicks, FontRenderer fontRenderer) {
|
||||
public void drawTooltips(int mouseX, int mouseY, float partialTicks, FontRenderer fontRenderer) {
|
||||
if(isHovered(mouseX, mouseY) && currentItem < itemCycle.size()) {
|
||||
if(tooltip != null) {
|
||||
drawHoveringText(tooltip, mouseX, mouseY, fontRenderer);
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package slimeknights.mantle.client.gui.book.element;
|
||||
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import slimeknights.mantle.client.book.data.SectionData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import slimeknights.mantle.client.book.data.SectionData;
|
||||
|
||||
public class ElementSection extends SizedBookElement {
|
||||
|
||||
public static final int IMG_SIZE = 32;
|
||||
@@ -28,7 +27,7 @@ public class ElementSection extends SizedBookElement {
|
||||
|
||||
@Override
|
||||
public void draw(int mouseX, int mouseY, float partialTicks, FontRenderer fontRenderer) {
|
||||
boolean unlocked = section.isUnlocked(parent.statisticsManager);
|
||||
boolean unlocked = section.isUnlocked(parent.advancementCache);
|
||||
boolean hover = isHovered(mouseX, mouseY);
|
||||
|
||||
if(section.icon != null) {
|
||||
@@ -75,22 +74,15 @@ public class ElementSection extends SizedBookElement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOverlay(int mouseX, int mouseY, float partialTicks, FontRenderer fontRenderer) {
|
||||
public void drawTooltips(int mouseX, int mouseY, float partialTicks, FontRenderer fontRenderer) {
|
||||
if(section != null && isHovered(mouseX, mouseY)) {
|
||||
List<String> text = new ArrayList<>();
|
||||
text.add(section.getTitle());
|
||||
if(!section.isUnlocked(parent.statisticsManager)) {
|
||||
if(!section.isUnlocked(parent.advancementCache)) {
|
||||
text.add(TextFormatting.RED + "Locked");
|
||||
text.add("Requirements:");
|
||||
|
||||
for(String requirement : section.requirements) {
|
||||
Advancement advancement = SectionData.findAdvancement(requirement);
|
||||
if(advancement != null) {
|
||||
text.add((SectionData
|
||||
.requirementSatisfied(requirement, parent.statisticsManager) ? TextFormatting.GREEN : TextFormatting.RED) + TextFormatting
|
||||
.getTextWithoutFormattingCodes(advancement.getDisplay().getTitle().getFormattedText()));
|
||||
}
|
||||
}
|
||||
text.addAll(Arrays.asList(section.requirements));
|
||||
}
|
||||
drawHoveringText(text, mouseX, mouseY, fontRenderer);
|
||||
}
|
||||
@@ -98,8 +90,8 @@ public class ElementSection extends SizedBookElement {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if(mouseButton == 0 && section != null && section.isUnlocked(parent.statisticsManager) && isHovered(mouseX, mouseY)) {
|
||||
parent.openPage(parent.book.getFirstPageNumber(section, parent.statisticsManager));
|
||||
if(mouseButton == 0 && section != null && section.isUnlocked(parent.advancementCache) && isHovered(mouseX, mouseY)) {
|
||||
parent.openPage(parent.book.getFirstPageNumber(section, parent.advancementCache));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,9 @@ import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import slimeknights.mantle.client.book.action.StringActionProcessor;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
@@ -12,8 +14,8 @@ import slimeknights.mantle.client.gui.book.TextDataRenderer;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ElementText extends SizedBookElement {
|
||||
|
||||
public TextData[] text;
|
||||
private List<String> tooltip = new ArrayList<String>();
|
||||
|
||||
private boolean doAction = false;
|
||||
|
||||
@@ -33,7 +35,7 @@ public class ElementText extends SizedBookElement {
|
||||
|
||||
@Override
|
||||
public void draw(int mouseX, int mouseY, float partialTicks, FontRenderer fontRenderer) {
|
||||
String action = TextDataRenderer.drawText(x, y, width, height, text, mouseX, mouseY, fontRenderer);
|
||||
String action = TextDataRenderer.drawText(x, y, width, height, text, mouseX, mouseY, fontRenderer, tooltip);
|
||||
|
||||
if(doAction) {
|
||||
doAction = false;
|
||||
@@ -41,6 +43,14 @@ public class ElementText extends SizedBookElement {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawTooltips(int mouseX, int mouseY, float partialTicks, FontRenderer fontRenderer) {
|
||||
if(tooltip.size() > 0){
|
||||
TextDataRenderer.drawTooltip(tooltip, mouseX, mouseY, fontRenderer);
|
||||
tooltip.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if(mouseButton == 0) {
|
||||
|
||||
Reference in new issue
Block a user