mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-20 12:09:44 +00:00
Book item lists
- Added block interaction page type - Added smithing (anvil) page type - Integrated the title - Renamed textdata onClick to action - Implemented item list JSON files instead of nesting item data - Replaced the hardcoded ImageData transformer with a modular hotswap system
This commit is contained in:
1 parent
3861ce5f01
commit
4e98678f46
26 files changed
+448
-47
No files matched your search
@@ -19,11 +19,13 @@ 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.ContentBlank;
|
||||
import slimeknights.mantle.client.book.data.content.ContentBlockInteraction;
|
||||
import slimeknights.mantle.client.book.data.content.ContentCrafting;
|
||||
import slimeknights.mantle.client.book.data.content.ContentError;
|
||||
import slimeknights.mantle.client.book.data.content.ContentImage;
|
||||
import slimeknights.mantle.client.book.data.content.ContentImageText;
|
||||
import slimeknights.mantle.client.book.data.content.ContentSmelting;
|
||||
import slimeknights.mantle.client.book.data.content.ContentSmithing;
|
||||
import slimeknights.mantle.client.book.data.content.ContentText;
|
||||
import slimeknights.mantle.client.book.data.content.ContentTextImage;
|
||||
import slimeknights.mantle.client.book.data.content.ContentTextLeftImage;
|
||||
@@ -63,6 +65,8 @@ public class BookLoader implements IResourceManagerReloadListener {
|
||||
registerPageType("text with right image etch", ContentTextRightImage.class);
|
||||
registerPageType("crafting", ContentCrafting.class);
|
||||
registerPageType("smelting", ContentSmelting.class);
|
||||
registerPageType("smithing", ContentSmithing.class);
|
||||
registerPageType("block interaction", ContentBlockInteraction.class);
|
||||
|
||||
// Register action protocols
|
||||
StringActionProcessor.registerProtocol(new ProtocolGoToPage());
|
||||
|
||||
@@ -2,6 +2,7 @@ package slimeknights.mantle.client.book.data;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@@ -9,6 +10,7 @@ import slimeknights.mantle.client.book.BookLoader;
|
||||
import slimeknights.mantle.client.book.data.content.ContentError;
|
||||
import slimeknights.mantle.client.book.data.content.PageContent;
|
||||
import slimeknights.mantle.client.book.data.element.ImageData;
|
||||
import slimeknights.mantle.client.book.data.element.ItemStackData;
|
||||
import static slimeknights.mantle.client.book.ResourceHelper.getResource;
|
||||
import static slimeknights.mantle.client.book.ResourceHelper.getResourceLocation;
|
||||
import static slimeknights.mantle.client.book.ResourceHelper.resourceToString;
|
||||
@@ -16,6 +18,8 @@ import static slimeknights.mantle.client.book.ResourceHelper.resourceToString;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class PageData implements IDataItem {
|
||||
|
||||
private static final transient ArrayList<ValueHotswap> hotswaps = new ArrayList<>();
|
||||
|
||||
public String name = null;
|
||||
public String type = "";
|
||||
public String data = "";
|
||||
@@ -61,14 +65,62 @@ public class PageData implements IDataItem {
|
||||
}
|
||||
|
||||
for (Field f : content.getClass().getFields()) {
|
||||
if (f.getType().isAssignableFrom(ImageData.class) && !Modifier.isTransient(f.getModifiers()))
|
||||
for (ValueHotswap swap : hotswaps) {
|
||||
if (f.getType().isAssignableFrom(swap.t) && !Modifier.isTransient(f.getModifiers()) && !Modifier.isStatic(f.getModifiers()) && !Modifier.isFinal(f.getModifiers())) {
|
||||
try {
|
||||
f.setAccessible(true);
|
||||
Object o = f.get(content);
|
||||
|
||||
swap.swap(o);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
/*if (f.getType().isAssignableFrom(ImageData.class) && !Modifier.isTransient(f.getModifiers()))
|
||||
try {
|
||||
f.setAccessible(true);
|
||||
ImageData d = (ImageData) f.get(content);
|
||||
d.location = getResourceLocation(d.file, true);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
public static void addSwap(Class<?> t, Class<? extends ValueHotswap> swap) {
|
||||
try {
|
||||
ValueHotswap hotswap = swap.newInstance();
|
||||
hotswap.t = t;
|
||||
|
||||
hotswaps.add(hotswap);
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
addSwap(ImageData.class, new ValueHotswap<ImageData>() {
|
||||
@Override
|
||||
public void swap(ImageData object) {
|
||||
object.location = getResourceLocation(object.file, true);
|
||||
}
|
||||
}.getClass());
|
||||
addSwap(ItemStackData.class, new ValueHotswap<ItemStackData>() {
|
||||
@Override
|
||||
public void swap(ItemStackData object) {
|
||||
object.itemListLocation = getResourceLocation(object.itemList);
|
||||
|
||||
if (object.itemListLocation != null)
|
||||
object.id = "->itemList";
|
||||
}
|
||||
}.getClass());
|
||||
}
|
||||
|
||||
public static abstract class ValueHotswap<T> {
|
||||
|
||||
protected Class<?> t;
|
||||
|
||||
public abstract void swap(T object);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,5 @@ public class ContentBlank extends PageContent {
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.ImageData;
|
||||
import slimeknights.mantle.client.book.data.element.ItemStackData;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementImage;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementItem;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
import static slimeknights.mantle.client.gui.book.Textures.TEX_MISC;
|
||||
|
||||
public class ContentBlockInteraction extends PageContent {
|
||||
|
||||
public static final transient int TEX_SIZE = 512;
|
||||
public static final transient ImageData IMG_SMITHING = new ImageData(TEX_MISC, 0, 0, 88, 55, TEX_SIZE, TEX_SIZE);
|
||||
|
||||
public static final transient int INPUT_X = 6;
|
||||
public static final transient int INPUT_Y = 18;
|
||||
public static final transient int BLOCK_X = 40;
|
||||
public static final transient int BLOCK_Y = 26;
|
||||
|
||||
public static final transient float ITEM_SCALE = 2.0F;
|
||||
public static final transient float BLOCK_SCALE = 5.0F;
|
||||
|
||||
public String title = "Block Interaction";
|
||||
public ItemStackData input;
|
||||
public ItemStackData block;
|
||||
public TextData[] description;
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int x = GuiBook.PAGE_WIDTH / 2 - IMG_SMITHING.width / 2 - 10;
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
y = 0;
|
||||
else
|
||||
addTitle(list, title);
|
||||
|
||||
list.add(new ElementImage(x, y, IMG_SMITHING.width, IMG_SMITHING.height, IMG_SMITHING, book.appearance.coverColor));
|
||||
|
||||
if (input != null && !input.id.equals("")) {
|
||||
list.add(new ElementItem(x + INPUT_X, y + INPUT_Y, ITEM_SCALE, input.getItems(), input.action));
|
||||
}
|
||||
|
||||
if (block != null && !block.id.equals("")) {
|
||||
list.add(new ElementItem(x + BLOCK_X, y + BLOCK_Y, BLOCK_SCALE, block.getItems(), block.action));
|
||||
}
|
||||
|
||||
if (description != null && description.length > 0) {
|
||||
list.add(new ElementText(0, IMG_SMITHING.height + y + 50, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - IMG_SMITHING.height - y - 50, description));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.ImageData;
|
||||
import slimeknights.mantle.client.book.data.element.ItemStackData;
|
||||
@@ -11,10 +10,10 @@ import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementImage;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementItem;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
import static slimeknights.mantle.client.gui.book.Textures.TEX_CRAFTING;
|
||||
|
||||
public class ContentCrafting extends PageContent {
|
||||
|
||||
public static final transient ResourceLocation TEX_CRAFTING = new ResourceLocation("mantle:textures/gui/book/crafting.png");
|
||||
public static final transient int TEX_SIZE = 256;
|
||||
public static final transient ImageData IMG_CRAFTING_LARGE = new ImageData(TEX_CRAFTING, 0, 0, 183, 114, TEX_SIZE, TEX_SIZE);
|
||||
public static final transient ImageData IMG_CRAFTING_SMALL = new ImageData(TEX_CRAFTING, 0, 114, 155, 78, TEX_SIZE, TEX_SIZE);
|
||||
@@ -65,12 +64,12 @@ public class ContentCrafting extends PageContent {
|
||||
for (int j = 0; j < grid[i].length; j++) {
|
||||
if (grid[i][j].id.equals(""))
|
||||
continue;
|
||||
list.add(new ElementItem(x + SLOT_MARGIN + (SLOT_PADDING + Math.round(ElementItem.ITEM_SIZE_HARDCODED * ITEM_SCALE)) * j, y + SLOT_MARGIN + (SLOT_PADDING + Math.round(ElementItem.ITEM_SIZE_HARDCODED * ITEM_SCALE)) * i, ITEM_SCALE, grid[i][j].getItemStack()));
|
||||
list.add(new ElementItem(x + SLOT_MARGIN + (SLOT_PADDING + Math.round(ElementItem.ITEM_SIZE_HARDCODED * ITEM_SCALE)) * j, y + SLOT_MARGIN + (SLOT_PADDING + Math.round(ElementItem.ITEM_SIZE_HARDCODED * ITEM_SCALE)) * i, ITEM_SCALE, grid[i][j].getItems(), grid[i][j].action));
|
||||
}
|
||||
}
|
||||
|
||||
if (result != null) {
|
||||
list.add(new ElementItem(resultX, resultY, ITEM_SCALE, result.getItemStack()));
|
||||
list.add(new ElementItem(resultX, resultY, ITEM_SCALE, result.getItems(), result.action));
|
||||
}
|
||||
|
||||
if (description != null && description.length > 0) {
|
||||
|
||||
@@ -26,6 +26,8 @@ public class ContentError extends PageContent {
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
addTitle(list, "Error");
|
||||
|
||||
TextData[] text = new TextData[1 + (exception != null ? 2 : 0)];
|
||||
text[0] = new TextData(errorStage);
|
||||
text[0].color = "dark_red";
|
||||
@@ -41,6 +43,6 @@ public class ContentError extends PageContent {
|
||||
text[2].paragraph = true;
|
||||
}
|
||||
|
||||
list.add(new ElementText(0, 0, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT, text));
|
||||
list.add(new ElementText(0, TITLE_HEIGHT, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - TITLE_HEIGHT, text));
|
||||
}
|
||||
}
|
||||
@@ -12,13 +12,21 @@ import slimeknights.mantle.client.gui.book.element.ElementImage;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ContentImage extends PageContent {
|
||||
|
||||
public String title = null;
|
||||
public ImageData image;
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
if (image != null && image.location != null)
|
||||
list.add(new ElementImage(0, 0, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT, image));
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
y = 0;
|
||||
else
|
||||
list.add(new ElementImage(image));
|
||||
addTitle(list, title);
|
||||
|
||||
if (image != null && image.location != null)
|
||||
list.add(new ElementImage(0, y, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - y, image));
|
||||
else
|
||||
list.add(new ElementImage(ImageData.MISSING));
|
||||
}
|
||||
}
|
||||
@@ -14,17 +14,25 @@ import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ContentImageText extends PageContent {
|
||||
|
||||
public String title = null;
|
||||
public ImageData image;
|
||||
public TextData[] text;
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
if (image != null && image.location != null)
|
||||
list.add(new ElementImage(0, 0, GuiBook.PAGE_WIDTH, 100, image));
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
y = 0;
|
||||
else
|
||||
list.add(new ElementImage(0, 0, 32, 32, ImageData.MISSING));
|
||||
addTitle(list, title);
|
||||
|
||||
if (image != null && image.location != null)
|
||||
list.add(new ElementImage(0, y, GuiBook.PAGE_WIDTH, 100, image));
|
||||
else
|
||||
list.add(new ElementImage(0, y, 32, 32, ImageData.MISSING));
|
||||
|
||||
if (text != null && text.length > 0)
|
||||
list.add(new ElementText(0, 105, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 105, text));
|
||||
list.add(new ElementText(0, y + 105, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 105 - y, text));
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import java.util.ArrayList;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.ImageData;
|
||||
import slimeknights.mantle.client.book.data.element.ItemStackData;
|
||||
@@ -14,10 +13,10 @@ import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementImage;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementItem;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
import static slimeknights.mantle.client.gui.book.Textures.TEX_SMELTING;
|
||||
|
||||
public class ContentSmelting extends PageContent {
|
||||
|
||||
public static final transient ResourceLocation TEX_SMELTING = new ResourceLocation("mantle:textures/gui/book/smelting.png");
|
||||
public static final transient int TEX_SIZE = 128;
|
||||
public static final transient ImageData IMG_SMELTING = new ImageData(TEX_SMELTING, 0, 0, 110, 114, TEX_SIZE, TEX_SIZE);
|
||||
|
||||
@@ -38,19 +37,19 @@ public class ContentSmelting extends PageContent {
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int x = GuiBook.PAGE_WIDTH / 2 - IMG_SMELTING.width / 2;
|
||||
int y = 16;
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
TextData tdTitle = new TextData(title);
|
||||
tdTitle.underlined = true;
|
||||
list.add(new ElementText(0, 0, GuiBook.PAGE_WIDTH, 9, new TextData[]{tdTitle}));
|
||||
list.add(new ElementImage(x, y, IMG_SMELTING.width, IMG_SMELTING.height, IMG_SMELTING, book.appearance.coverColor));
|
||||
|
||||
if (input != null) {
|
||||
list.add(new ElementItem(x + INPUT_X, y + INPUT_Y, ITEM_SCALE, input.getItemStack()));
|
||||
if (input != null && !input.id.equals("")) {
|
||||
list.add(new ElementItem(x + INPUT_X, y + INPUT_Y, ITEM_SCALE, input.getItems(), input.action));
|
||||
}
|
||||
|
||||
if (result != null) {
|
||||
list.add(new ElementItem(x + RESULT_X, y + RESULT_Y, ITEM_SCALE, result.getItemStack()));
|
||||
if (result != null && !result.id.equals("")) {
|
||||
list.add(new ElementItem(x + RESULT_X, y + RESULT_Y, ITEM_SCALE, result.getItems(), result.action));
|
||||
}
|
||||
|
||||
list.add(new ElementItem(x + FUEL_X, y + FUEL_Y, ITEM_SCALE, getFuelsList()));
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.ImageData;
|
||||
import slimeknights.mantle.client.book.data.element.ItemStackData;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementImage;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementItem;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
import static slimeknights.mantle.client.gui.book.Textures.TEX_MISC;
|
||||
|
||||
public class ContentSmithing extends PageContent {
|
||||
|
||||
public static final transient int TEX_SIZE = 512;
|
||||
public static final transient ImageData IMG_SMITHING = new ImageData(TEX_MISC, 88, 0, 210, 42, TEX_SIZE, TEX_SIZE);
|
||||
|
||||
public static final transient int INPUT_X = 5;
|
||||
public static final transient int INPUT_Y = 5;
|
||||
public static final transient int MODIFIER_X = 89;
|
||||
public static final transient int MODIFIER_Y = 5;
|
||||
public static final transient int RESULT_X = 173;
|
||||
public static final transient int RESULT_Y = 5;
|
||||
|
||||
public static final transient float ITEM_SCALE = 2.0F;
|
||||
|
||||
public String title = "Smithing";
|
||||
public ItemStackData input;
|
||||
public ItemStackData modifier;
|
||||
public ItemStackData result;
|
||||
public TextData[] description;
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int x = GuiBook.PAGE_WIDTH / 2 - IMG_SMITHING.width / 2;
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
y = 0;
|
||||
else
|
||||
addTitle(list, title);
|
||||
|
||||
list.add(new ElementImage(x, y, IMG_SMITHING.width, IMG_SMITHING.height, IMG_SMITHING, book.appearance.coverColor));
|
||||
|
||||
if (input != null && !input.id.equals("")) {
|
||||
list.add(new ElementItem(x + INPUT_X, y + INPUT_Y, ITEM_SCALE, input.getItems(), input.action));
|
||||
}
|
||||
|
||||
if (modifier != null && !modifier.id.equals("")) {
|
||||
list.add(new ElementItem(x + MODIFIER_X, y + MODIFIER_Y, ITEM_SCALE, modifier.getItems(), modifier.action));
|
||||
}
|
||||
|
||||
if (result != null && !result.id.equals("")) {
|
||||
list.add(new ElementItem(x + RESULT_X, y + RESULT_Y, ITEM_SCALE, result.getItems(), result.action));
|
||||
}
|
||||
|
||||
if (description != null && description.length > 0) {
|
||||
list.add(new ElementText(0, IMG_SMITHING.height + y + 5, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - IMG_SMITHING.height - y - 5, description));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,11 +12,19 @@ import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ContentText extends PageContent {
|
||||
|
||||
public String title = null;
|
||||
public TextData[] text;
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
y = 0;
|
||||
else
|
||||
addTitle(list, title);
|
||||
|
||||
if (text != null && text.length > 0)
|
||||
list.add(new ElementText(0, 0, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT, text));
|
||||
list.add(new ElementText(0, y, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - y, text));
|
||||
}
|
||||
}
|
||||
@@ -14,17 +14,30 @@ import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ContentTextImage extends PageContent {
|
||||
|
||||
public String title = null;
|
||||
public TextData[] text;
|
||||
public ImageData image;
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
y = 0;
|
||||
else
|
||||
addTitle(list, title);
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
y = 0;
|
||||
else
|
||||
addTitle(list, title);
|
||||
|
||||
if (text != null && text.length > 0)
|
||||
list.add(new ElementText(0, 0, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 105, text));
|
||||
list.add(new ElementText(0, y, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 105, text));
|
||||
|
||||
if (image != null && image.location != null)
|
||||
list.add(new ElementImage(0, GuiBook.PAGE_HEIGHT - 100, GuiBook.PAGE_WIDTH, 100, image));
|
||||
list.add(new ElementImage(0, y + GuiBook.PAGE_HEIGHT - 100, GuiBook.PAGE_WIDTH, 100 - y, image));
|
||||
else
|
||||
list.add(new ElementImage(0, GuiBook.PAGE_HEIGHT - 100, GuiBook.PAGE_WIDTH, 100, ImageData.MISSING));
|
||||
list.add(new ElementImage(0, y + GuiBook.PAGE_HEIGHT - 100, GuiBook.PAGE_WIDTH, 100 - y, ImageData.MISSING));
|
||||
}
|
||||
}
|
||||
+13
-5
@@ -14,21 +14,29 @@ import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ContentTextLeftImage extends PageContent {
|
||||
|
||||
public String title = null;
|
||||
public ImageData image;
|
||||
public TextData[] text1;
|
||||
public TextData[] text2;
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
if (image != null && image.location != null)
|
||||
list.add(new ElementImage(0, 0, 50, 50, image));
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
y = 0;
|
||||
else
|
||||
list.add(new ElementImage(0, 0, 50, 50, ImageData.MISSING));
|
||||
addTitle(list, title);
|
||||
|
||||
if (image != null && image.location != null)
|
||||
list.add(new ElementImage(0, y, 50, 50, image));
|
||||
else
|
||||
list.add(new ElementImage(0, y, 50, 50, ImageData.MISSING));
|
||||
|
||||
if (text1 != null && text1.length > 0)
|
||||
list.add(new ElementText(55, 0, GuiBook.PAGE_WIDTH - 55, 50, text1));
|
||||
list.add(new ElementText(55, y, GuiBook.PAGE_WIDTH - 55, 50, text1));
|
||||
|
||||
if (text2 != null && text2.length > 0)
|
||||
list.add(new ElementText(0, 55, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 55, text2));
|
||||
list.add(new ElementText(0, y + 55, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 55 - y, text2));
|
||||
}
|
||||
}
|
||||
+12
-4
@@ -14,21 +14,29 @@ import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ContentTextRightImage extends PageContent {
|
||||
|
||||
public String title;
|
||||
public TextData[] text1;
|
||||
public TextData[] text2;
|
||||
public ImageData image;
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
y = 0;
|
||||
else
|
||||
addTitle(list, title);
|
||||
|
||||
if (text1 != null && text1.length > 0)
|
||||
list.add(new ElementText(0, 0, GuiBook.PAGE_WIDTH - 55, 50, text1));
|
||||
list.add(new ElementText(0, y, GuiBook.PAGE_WIDTH - 55, 50, text1));
|
||||
|
||||
if (image != null && image.location != null)
|
||||
list.add(new ElementImage(GuiBook.PAGE_WIDTH - 50, 0, 50, 50, image));
|
||||
list.add(new ElementImage(GuiBook.PAGE_WIDTH - 50, y, 50, 50, image));
|
||||
else
|
||||
list.add(new ElementImage(GuiBook.PAGE_WIDTH - 50, 0, 50, 50, ImageData.MISSING));
|
||||
list.add(new ElementImage(GuiBook.PAGE_WIDTH - 50, y, 50, 50, ImageData.MISSING));
|
||||
|
||||
if (text2 != null && text2.length > 0)
|
||||
list.add(new ElementText(0, 55, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 55, text2));
|
||||
list.add(new ElementText(0, y + 55, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 55 - y, text2));
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,25 @@ import java.util.ArrayList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract class PageContent {
|
||||
|
||||
public static final transient int TITLE_HEIGHT = 16;
|
||||
|
||||
public abstract void build(BookData book, ArrayList<BookElement> list);
|
||||
|
||||
public void addTitle(ArrayList<BookElement> list, String title) {
|
||||
TextData tdTitle = new TextData(title);
|
||||
tdTitle.underlined = true;
|
||||
addTitle(list, new TextData[]{tdTitle});
|
||||
}
|
||||
|
||||
public void addTitle(ArrayList<BookElement> list, TextData[] title) {
|
||||
list.add(new ElementText(0, 0, GuiBook.PAGE_WIDTH, 9, title));
|
||||
}
|
||||
}
|
||||
@@ -11,16 +11,44 @@ import net.minecraft.nbt.NBTException;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import slimeknights.mantle.client.book.BookLoader;
|
||||
import static slimeknights.mantle.client.book.ResourceHelper.getResource;
|
||||
import static slimeknights.mantle.client.book.ResourceHelper.resourceExists;
|
||||
import static slimeknights.mantle.client.book.ResourceHelper.resourceToString;
|
||||
|
||||
public class ItemStackData {
|
||||
|
||||
public String itemList = null;
|
||||
public transient ResourceLocation itemListLocation = null;
|
||||
public transient String action;
|
||||
|
||||
public String id = "";
|
||||
public byte amount = 1;
|
||||
public short damage = 0;
|
||||
public JsonObject nbt;
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
public ItemStack[] getItems() {
|
||||
if (itemListLocation != null && resourceExists(itemListLocation)) {
|
||||
try {
|
||||
ItemsList itemsList = BookLoader.GSON.fromJson(resourceToString(getResource(itemListLocation)), ItemsList.class);
|
||||
ItemStack[] items = new ItemStack[itemsList.items.length];
|
||||
|
||||
for (int i = 0; i < itemsList.items.length; i++) {
|
||||
items[i] = itemsList.items[i].getItem();
|
||||
}
|
||||
|
||||
this.action = itemsList.action;
|
||||
|
||||
return items;
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
return new ItemStack[]{getItem()};
|
||||
}
|
||||
|
||||
private ItemStack getItem() {
|
||||
Item item;
|
||||
boolean isMissingItem = false;
|
||||
try {
|
||||
@@ -39,7 +67,7 @@ public class ItemStackData {
|
||||
|
||||
if (nbt != null) {
|
||||
try {
|
||||
itemStack.setTagCompound(JsonToNBT.getTagFromJson(nbt.toString()));
|
||||
itemStack.setTagCompound(JsonToNBT.getTagFromJson(filterJsonQuotes(nbt.toString())));
|
||||
} catch (NBTException ignored) {
|
||||
}
|
||||
}
|
||||
@@ -72,6 +100,16 @@ public class ItemStackData {
|
||||
return data;
|
||||
}
|
||||
|
||||
public static String filterJsonQuotes(String s) {
|
||||
return s.replaceAll("\"(\\w+)\"\\s*:", "$1: ");
|
||||
}
|
||||
|
||||
private static class ItemsList {
|
||||
|
||||
public ItemStackData[] items = new ItemStackData[0];
|
||||
public String action;
|
||||
}
|
||||
|
||||
public static class ItemLink {
|
||||
|
||||
public ItemStackData item = new ItemStackData();
|
||||
|
||||
@@ -16,7 +16,7 @@ public class TextData {
|
||||
public boolean obfuscated = false;
|
||||
public boolean paragraph = false;
|
||||
public float scale = 1.F;
|
||||
public String onClick = "";
|
||||
public String action = "";
|
||||
public String[] tooltip = null;
|
||||
|
||||
public TextData() {
|
||||
|
||||
@@ -14,7 +14,6 @@ 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;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
@@ -26,13 +25,12 @@ import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.PageData;
|
||||
import slimeknights.mantle.client.book.data.element.ItemStackData;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
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 {
|
||||
|
||||
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");
|
||||
|
||||
public static final int PAGE_PADDING = 8;
|
||||
public static final int PAGE_MARGIN = 18;
|
||||
|
||||
|
||||
@@ -110,9 +110,9 @@ public class TextDataRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
if (item.onClick != null && !item.onClick.isEmpty())
|
||||
if (item.action != null && !item.action.isEmpty())
|
||||
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)) {
|
||||
action = item.onClick;
|
||||
action = item.action;
|
||||
}
|
||||
|
||||
if (atY >= boxHeight) {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package slimeknights.mantle.client.gui.book;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class Textures {
|
||||
|
||||
public static final ResourceLocation TEX_BOOK = new ResourceLocation("mantle:textures/gui/book.png");
|
||||
public static final ResourceLocation TEX_BOOKFRONT = new ResourceLocation("mantle:textures/gui/bookfront.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");
|
||||
public static final ResourceLocation TEX_MISC = new ResourceLocation("mantle:textures/gui/book/misc.png");
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.client.book.action.StringActionProcessor;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ElementItem extends BookElement {
|
||||
@@ -17,6 +18,7 @@ public class ElementItem extends BookElement {
|
||||
|
||||
public ItemStack[] itemCycle;
|
||||
public float scale;
|
||||
public String action;
|
||||
|
||||
public int renderTick = 0;
|
||||
public int currentItem = 0;
|
||||
@@ -34,10 +36,15 @@ public class ElementItem extends BookElement {
|
||||
}
|
||||
|
||||
public ElementItem(int x, int y, float scale, ItemStack[] itemCycle) {
|
||||
this(x, y, scale, itemCycle, null);
|
||||
}
|
||||
|
||||
public ElementItem(int x, int y, float scale, ItemStack[] itemCycle, String action) {
|
||||
super(x, y);
|
||||
|
||||
this.itemCycle = itemCycle;
|
||||
this.scale = scale;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,7 +80,10 @@ public class ElementItem extends BookElement {
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if (mouseButton == 0 && mouseX >= x && mouseY >= y && mouseX <= x + ITEM_SIZE_HARDCODED * scale && mouseY <= y + ITEM_SIZE_HARDCODED * scale && currentItem < itemCycle.length) {
|
||||
parent.itemClicked(itemCycle[currentItem]);
|
||||
if (action != null)
|
||||
StringActionProcessor.process(action, parent);
|
||||
else
|
||||
parent.itemClicked(itemCycle[currentItem]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user