Added a second page to the book

This commit is contained in:
Sollace 2019-02-15 19:19:05 +02:00
parent 4dffafda01
commit ee53f83816
7 changed files with 50 additions and 16 deletions

BIN
book.xcf Normal file

Binary file not shown.

View file

@ -12,6 +12,9 @@ class PageInstance implements IPage {
int index; int index;
@Nullable
ResourceLocation parent;
@Nonnull @Nonnull
ResourceLocation name; ResourceLocation name;
@ -27,6 +30,10 @@ class PageInstance implements IPage {
PageInstance(ResourceLocation id, JsonObject json) { PageInstance(ResourceLocation id, JsonObject json) {
this.name = id; this.name = id;
if (json.has("parent")) {
parent = new ResourceLocation(json.get("parent").getAsString());
}
if (json.has("state")) { if (json.has("state")) {
state = PageState.of(json.get("state").getAsString()); state = PageState.of(json.get("state").getAsString());
} }

View file

@ -23,8 +23,8 @@ public class Pages {
return instance; return instance;
} }
private final Map<ResourceLocation, IPage> pages = Maps.newHashMap(); private final Map<ResourceLocation, PageInstance> pages = Maps.newHashMap();
private final List<IPage> pagesByIndex = Lists.newArrayList(); private final List<PageInstance> pagesByIndex = Lists.newArrayList();
private final Map<String, IConditionFactory> conditionFactories = Maps.newHashMap(); private final Map<String, IConditionFactory> conditionFactories = Maps.newHashMap();
@ -41,10 +41,25 @@ public class Pages {
pagesByIndex.clear(); pagesByIndex.clear();
assets.walk(); assets.walk();
int index = 0; List<ResourceLocation> names = Lists.newArrayList();
for (IPage ipage : pages.values()) {
((PageInstance)ipage).index = index++; for (PageInstance page : pages.values()) {
pagesByIndex.add(ipage); if (page.parent != null) {
int i = names.indexOf(page.parent);
if (i != -1) {
names.add(i, page.name);
pagesByIndex.add(i, page);
continue;
}
}
names.add(page.name);
pagesByIndex.add(page);
}
for (int i = 0; i < pagesByIndex.size(); i++) {
pagesByIndex.get(i).index = i;
} }
} }
@ -70,7 +85,7 @@ public class Pages {
} }
public Stream<IPage> getUnlockablePages(Predicate<IPage> predicate) { public Stream<IPage> getUnlockablePages(Predicate<IPage> predicate) {
return pages.values().stream().filter(predicate); return pages.values().stream().map(IPage.class::cast).filter(predicate);
} }
public void triggerUnlockEvent(IPageOwner owner, IUnlockEvent event, @Nullable IPageUnlockListener unlockListener) { public void triggerUnlockEvent(IPageOwner owner, IUnlockEvent event, @Nullable IPageUnlockListener unlockListener) {

View file

@ -60,12 +60,12 @@ public class ContainerSpellBook extends Container {
} }
public void initCraftingSlots() { public void initCraftingSlots() {
addSlotToContainer(new SlotEnchanting(craftMatrix, 0, 180, 50)); addSlotToContainer(new SlotEnchanting(craftMatrix, 0, 175, 50));
addSlotToContainer(new SlotEnchanting(craftMatrix, 1, 154, 94)); addSlotToContainer(new SlotEnchanting(craftMatrix, 1, 149, 94));
addSlotToContainer(new SlotEnchanting(craftMatrix, 2, 180, 134)); addSlotToContainer(new SlotEnchanting(craftMatrix, 2, 175, 134));
addSlotToContainer(new SlotEnchanting(craftMatrix, 3, 231, 120)); addSlotToContainer(new SlotEnchanting(craftMatrix, 3, 226, 120));
addSlotToContainer(new SlotEnchanting(craftMatrix, 4, 232, 65)); addSlotToContainer(new SlotEnchanting(craftMatrix, 4, 227, 65));
addSlotToContainer(resultSlot = new SlotEnchantingResult(listener, PlayerSpeciesList.instance().getPlayer(player), craftMatrix, craftResult, 0, 196, 92)); addSlotToContainer(resultSlot = new SlotEnchantingResult(listener, PlayerSpeciesList.instance().getPlayer(player), craftMatrix, craftResult, 0, 191, 92));
} }
@Override @Override

View file

@ -112,10 +112,13 @@ public class GuiSpellBook extends GuiContainer implements IPageUnlockListener {
if (slot instanceof SlotEnchanting) { if (slot instanceof SlotEnchanting) {
GlStateManager.enableBlend(); GlStateManager.enableBlend();
GL11.glDisable(GL11.GL_ALPHA_TEST); GL11.glDisable(GL11.GL_ALPHA_TEST);
mc.getTextureManager().bindTexture(spellBookGuiTextures); mc.getTextureManager().bindTexture(spellBookGuiTextures);
drawModalRectWithCustomSizedTexture(slot.xPos - 1, slot.yPos - 1, 51, 223, 18, 18, 512, 256); drawModalRectWithCustomSizedTexture(slot.xPos - 1, slot.yPos - 1, 51, 223, 18, 18, 512, 256);
GL11.glEnable(GL11.GL_ALPHA_TEST); GL11.glEnable(GL11.GL_ALPHA_TEST);
GlStateManager.disableBlend(); GlStateManager.disableBlend();
return true; return true;
} }
return false; return false;
@ -148,6 +151,9 @@ public class GuiSpellBook extends GuiContainer implements IPageUnlockListener {
GlStateManager.enableBlend(); GlStateManager.enableBlend();
GL11.glDisable(GL11.GL_ALPHA_TEST); GL11.glDisable(GL11.GL_ALPHA_TEST);
mc.getTextureManager().bindTexture(spellBookGuiTextures);
drawModalRectWithCustomSizedTexture(left + 147, top + 49, 407, 2, 100, 101, 512, 256);
if (playerExtension.getPageState(currentIPage) != PageState.LOCKED) { if (playerExtension.getPageState(currentIPage) != PageState.LOCKED) {
ResourceLocation texture = currentIPage.getTexture(); ResourceLocation texture = currentIPage.getTexture();
@ -163,9 +169,6 @@ public class GuiSpellBook extends GuiContainer implements IPageUnlockListener {
} }
} }
mc.getTextureManager().bindTexture(spellBookGuiTextures);
drawModalRectWithCustomSizedTexture(left + 152, top + 49, 407, 2, 100, 101, 512, 256);
GL11.glEnable(GL11.GL_ALPHA_TEST); GL11.glEnable(GL11.GL_ALPHA_TEST);
GlStateManager.disableBlend(); GlStateManager.disableBlend();
} }

View file

@ -0,0 +1,9 @@
{
"parent": "unicopia:preface",
"texture": "unicopia:chapter_1_gems",
"state": "unread",
"conditions": {
"type": "unicopia:compound_condition",
"conditions": []
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB