mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-29 18:28:34 +01:00
Text pages!
This commit is contained in:
parent
8c7bd9e696
commit
4a739b6ab4
10 changed files with 157 additions and 16 deletions
|
@ -48,5 +48,10 @@ public interface IBookletPage{
|
||||||
void updateScreen(GuiBookletBase gui);
|
void updateScreen(GuiBookletBase gui);
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 void renderSplitScaledAsciiString(String text, int x, int y, int color, boolean shadow, float scale, int length);
|
||||||
|
|
||||||
public abstract List<GuiButton> getButtonList();
|
public abstract List<GuiButton> getButtonList();
|
||||||
|
|
||||||
|
public abstract int getGuiLeft();
|
||||||
|
|
||||||
|
public abstract int getGuiTop();
|
||||||
|
|
||||||
|
public abstract int getSizeX();
|
||||||
|
|
||||||
|
public abstract int getSizeY();
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,4 +91,24 @@ public class GuiBooklet extends GuiBookletBase{
|
||||||
public List<GuiButton> getButtonList(){
|
public List<GuiButton> getButtonList(){
|
||||||
return this.buttonList;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,9 +15,12 @@ import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry;
|
||||||
import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase;
|
import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase;
|
||||||
import de.ellpeck.actuallyadditions.mod.booklet.button.EntryButton;
|
import de.ellpeck.actuallyadditions.mod.booklet.button.EntryButton;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public class GuiEntry extends GuiBooklet{
|
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.
|
//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.
|
||||||
|
|
|
@ -15,9 +15,12 @@ import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry;
|
||||||
import de.ellpeck.actuallyadditions.mod.booklet.button.EntryButton;
|
import de.ellpeck.actuallyadditions.mod.booklet.button.EntryButton;
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public class GuiMainPage extends GuiBooklet{
|
public class GuiMainPage extends GuiBooklet{
|
||||||
|
|
||||||
public GuiMainPage(GuiScreen previousScreen){
|
public GuiMainPage(GuiScreen previousScreen){
|
||||||
|
|
|
@ -14,50 +14,105 @@ import de.ellpeck.actuallyadditions.api.booklet.IBookletPage;
|
||||||
import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase;
|
import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase;
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public class GuiPage extends GuiBooklet{
|
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);
|
super(previousScreen, parentPage);
|
||||||
this.page = page;
|
|
||||||
|
this.pages[0] = page1;
|
||||||
|
this.pages[1] = page2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException{
|
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
|
@Override
|
||||||
public void mouseReleased(int mouseX, int mouseY, int state){
|
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
|
@Override
|
||||||
public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick){
|
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
|
@Override
|
||||||
public void actionPerformed(GuiButton button) throws IOException{
|
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
|
@Override
|
||||||
public void initGui(){
|
public void initGui(){
|
||||||
this.page.initGui(this);
|
super.initGui();
|
||||||
|
|
||||||
|
for(IBookletPage page : this.pages){
|
||||||
|
if(page != null){
|
||||||
|
page.initGui(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateScreen(){
|
public void updateScreen(){
|
||||||
this.page.updateScreen(this);
|
super.updateScreen();
|
||||||
|
|
||||||
|
for(IBookletPage page : this.pages){
|
||||||
|
if(page != null){
|
||||||
|
page.updateScreen(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawScreen(int mouseX, int mouseY, float partialTicks){
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ package de.ellpeck.actuallyadditions.mod.booklet.misc;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
||||||
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter;
|
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.api.booklet.IBookletPage;
|
||||||
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiBooklet;
|
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiBooklet;
|
||||||
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiEntry;
|
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiEntry;
|
||||||
|
@ -44,6 +43,20 @@ public final class BookletUtils{
|
||||||
IBookletChapter chapter = page.getChapter();
|
IBookletChapter chapter = page.getChapter();
|
||||||
GuiEntry entry = new GuiEntry(previousScreen, mainPage, chapter.getEntry(), chapter);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.text.TextFormatting;
|
import net.minecraft.util.text.TextFormatting;
|
||||||
import net.minecraftforge.fluids.Fluid;
|
import net.minecraftforge.fluids.Fluid;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -82,40 +84,58 @@ public class BookletPage implements IBookletPage{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public void mouseClicked(GuiBookletBase gui, int mouseX, int mouseY, int mouseButton){
|
public void mouseClicked(GuiBookletBase gui, int mouseX, int mouseY, int mouseButton){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public void mouseReleased(GuiBookletBase gui, int mouseX, int mouseY, int state){
|
public void mouseReleased(GuiBookletBase gui, int mouseX, int mouseY, int state){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public void mouseClickMove(GuiBookletBase gui, int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick){
|
public void mouseClickMove(GuiBookletBase gui, int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public void actionPerformed(GuiBookletBase gui, GuiButton button){
|
public void actionPerformed(GuiBookletBase gui, GuiButton button){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public void initGui(GuiBookletBase gui){
|
public void initGui(GuiBookletBase gui){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public void updateScreen(GuiBookletBase gui){
|
public void updateScreen(GuiBookletBase gui){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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(){
|
public BookletPage setNoText(){
|
||||||
this.hasNoText = true;
|
this.hasNoText = true;
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -10,10 +10,24 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.booklet.page;
|
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 class PageTextOnly extends BookletPage{
|
||||||
|
|
||||||
public PageTextOnly(int localizationKey){
|
public PageTextOnly(int localizationKey){
|
||||||
super(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ public final class StringUtil{
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public static void renderSplitScaledAsciiString(FontRenderer font, String text, int x, int y, int color, boolean shadow, float scale, int length){
|
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++){
|
for(int i = 0; i < lines.size(); i++){
|
||||||
renderScaledAsciiString(font, lines.get(i), x, y+(i*font.FONT_HEIGHT), color, shadow, scale);
|
renderScaledAsciiString(font, lines.get(i), x, y+(i*font.FONT_HEIGHT), color, shadow, scale);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue