Text pages!

This commit is contained in:
Ellpeck 2016-11-10 22:06:58 +01:00
parent 8c7bd9e696
commit 4a739b6ab4
10 changed files with 157 additions and 16 deletions

View file

@ -48,5 +48,10 @@ public interface IBookletPage{
void updateScreen(GuiBookletBase gui);
@SideOnly(Side.CLIENT)
void drawScreen(GuiBookletBase gui, int mouseX, int mouseY, float partialTicks);
void drawScreenPre(GuiBookletBase gui, int startX, int startY, int mouseX, int mouseY, float partialTicks);
@SideOnly(Side.CLIENT)
void drawScreenPost(GuiBookletBase gui, int startX, int startY, int mouseX, int mouseY, float partialTicks);
boolean shouldBeOnLeftSide();
}

View file

@ -22,4 +22,12 @@ public abstract class GuiBookletBase extends GuiScreen{
public abstract void renderSplitScaledAsciiString(String text, int x, int y, int color, boolean shadow, float scale, int length);
public abstract List<GuiButton> getButtonList();
public abstract int getGuiLeft();
public abstract int getGuiTop();
public abstract int getSizeX();
public abstract int getSizeY();
}

View file

@ -91,4 +91,24 @@ public class GuiBooklet extends GuiBookletBase{
public List<GuiButton> getButtonList(){
return this.buttonList;
}
@Override
public int getGuiLeft(){
return this.guiLeft;
}
@Override
public int getGuiTop(){
return this.guiTop;
}
@Override
public int getSizeX(){
return this.xSize;
}
@Override
public int getSizeY(){
return this.ySize;
}
}

View file

@ -15,9 +15,12 @@ import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry;
import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase;
import de.ellpeck.actuallyadditions.mod.booklet.button.EntryButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List;
@SideOnly(Side.CLIENT)
public class GuiEntry extends GuiBooklet{
//The page in the entry. Say you have 2 more chapters than fit on one double page, then those 2 would be displayed on entryPage 1 instead.

View file

@ -15,9 +15,12 @@ import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry;
import de.ellpeck.actuallyadditions.mod.booklet.button.EntryButton;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.io.IOException;
@SideOnly(Side.CLIENT)
public class GuiMainPage extends GuiBooklet{
public GuiMainPage(GuiScreen previousScreen){

View file

@ -14,50 +14,105 @@ import de.ellpeck.actuallyadditions.api.booklet.IBookletPage;
import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.io.IOException;
@SideOnly(Side.CLIENT)
public class GuiPage extends GuiBooklet{
private final IBookletPage page;
private final IBookletPage[] pages = new IBookletPage[2];
public GuiPage(GuiScreen previousScreen, GuiBookletBase parentPage, IBookletPage page){
public GuiPage(GuiScreen previousScreen, GuiBookletBase parentPage, IBookletPage page1, IBookletPage page2){
super(previousScreen, parentPage);
this.page = page;
this.pages[0] = page1;
this.pages[1] = page2;
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException{
this.page.mouseClicked(this, mouseX, mouseY, mouseButton);
super.mouseClicked(mouseX, mouseY, mouseButton);
for(IBookletPage page : this.pages){
if(page != null){
page.mouseClicked(this, mouseX, mouseY, mouseButton);
}
}
}
@Override
public void mouseReleased(int mouseX, int mouseY, int state){
this.page.mouseReleased(this, mouseX, mouseY, state);
super.mouseReleased(mouseX, mouseY, state);
for(IBookletPage page : this.pages){
if(page != null){
page.mouseReleased(this, mouseX, mouseY, state);
}
}
}
@Override
public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick){
this.page.mouseClickMove(this, mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
for(IBookletPage page : this.pages){
if(page != null){
page.mouseClickMove(this, mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
}
}
}
@Override
public void actionPerformed(GuiButton button) throws IOException{
this.page.actionPerformed(this, button);
super.actionPerformed(button);
for(IBookletPage page : this.pages){
if(page != null){
page.actionPerformed(this, button);
}
}
}
@Override
public void initGui(){
this.page.initGui(this);
super.initGui();
for(IBookletPage page : this.pages){
if(page != null){
page.initGui(this);
}
}
}
@Override
public void updateScreen(){
this.page.updateScreen(this);
super.updateScreen();
for(IBookletPage page : this.pages){
if(page != null){
page.updateScreen(this);
}
}
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks){
this.page.drawScreen(this, mouseX, mouseY, partialTicks);
for(int i = 0; i < this.pages.length; i++){
IBookletPage page = this.pages[i];
if(page != null){
page.drawScreenPre(this, this.guiLeft+6+i*142, this.guiTop+7, mouseX, mouseY, partialTicks);
}
}
super.drawScreen(mouseX, mouseY, partialTicks);
for(int i = 0; i < this.pages.length; i++){
IBookletPage page = this.pages[i];
if(page != null){
page.drawScreenPost(this, this.guiLeft+6+i*142, this.guiTop+7, mouseX, mouseY, partialTicks);
}
}
}
}

View file

@ -12,7 +12,6 @@ package de.ellpeck.actuallyadditions.mod.booklet.misc;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter;
import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry;
import de.ellpeck.actuallyadditions.api.booklet.IBookletPage;
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiBooklet;
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiEntry;
@ -44,6 +43,20 @@ public final class BookletUtils{
IBookletChapter chapter = page.getChapter();
GuiEntry entry = new GuiEntry(previousScreen, mainPage, chapter.getEntry(), chapter);
return new GuiPage(previousScreen, entry, page);
IBookletPage[] allPages = chapter.getAllPages();
int pageIndex = chapter.getPageNum(page)-1;
IBookletPage page1;
IBookletPage page2;
if(page.shouldBeOnLeftSide()){
page1 = page;
page2 = pageIndex >= allPages.length-1 ? null : allPages[pageIndex+1];
}
else{
page1 = pageIndex <= 0 ? null : allPages[pageIndex-1];
page2 = page;
}
return new GuiPage(previousScreen, entry, page1, page2);
}
}

View file

@ -20,6 +20,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.ArrayList;
import java.util.HashMap;
@ -82,40 +84,58 @@ public class BookletPage implements IBookletPage{
}
@Override
@SideOnly(Side.CLIENT)
public void mouseClicked(GuiBookletBase gui, int mouseX, int mouseY, int mouseButton){
}
@Override
@SideOnly(Side.CLIENT)
public void mouseReleased(GuiBookletBase gui, int mouseX, int mouseY, int state){
}
@Override
@SideOnly(Side.CLIENT)
public void mouseClickMove(GuiBookletBase gui, int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick){
}
@Override
@SideOnly(Side.CLIENT)
public void actionPerformed(GuiBookletBase gui, GuiButton button){
}
@Override
@SideOnly(Side.CLIENT)
public void initGui(GuiBookletBase gui){
}
@Override
@SideOnly(Side.CLIENT)
public void updateScreen(GuiBookletBase gui){
}
@Override
public void drawScreen(GuiBookletBase gui, int mouseX, int mouseY, float partialTicks){
@SideOnly(Side.CLIENT)
public void drawScreenPre(GuiBookletBase gui, int startX, int startY, int mouseX, int mouseY, float partialTicks){
}
@Override
@SideOnly(Side.CLIENT)
public void drawScreenPost(GuiBookletBase gui, int startX, int startY, int mouseX, int mouseY, float partialTicks){
}
@Override
public boolean shouldBeOnLeftSide(){
return this.chapter.getPageNum(this)%2 != 0;
}
public BookletPage setNoText(){
this.hasNoText = true;
return this;

View file

@ -10,10 +10,24 @@
package de.ellpeck.actuallyadditions.mod.booklet.page;
//TODO
import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class PageTextOnly extends BookletPage{
public PageTextOnly(int localizationKey){
super(localizationKey);
}
@Override
@SideOnly(Side.CLIENT)
public void drawScreenPost(GuiBookletBase gui, int startX, int startY, int mouseX, int mouseY, float partialTicks){
super.drawScreenPost(gui, startX, startY, mouseX, mouseY, partialTicks);
String text = this.getInfoText();
if(text != null && !text.isEmpty()){
gui.renderSplitScaledAsciiString(text, startX+6, startY+5, 0, false, 0.75F, 120);
}
}
}

View file

@ -69,7 +69,7 @@ public final class StringUtil{
@SideOnly(Side.CLIENT)
public static void renderSplitScaledAsciiString(FontRenderer font, String text, int x, int y, int color, boolean shadow, float scale, int length){
List<String> lines = font.listFormattedStringToWidth(text, (int)(length*scale));
List<String> lines = font.listFormattedStringToWidth(text, (int)(length/scale));
for(int i = 0; i < lines.size(); i++){
renderScaledAsciiString(font, lines.get(i), x, y+(i*font.FONT_HEIGHT), color, shadow, scale);
}