mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-27 15:23:12 +00:00
Change padding to be side-sensitive (4 sides). Make pages have less padding towards the center.
This commit is contained in:
1 parent
6a0429ec54
commit
23da60afd0
2 files changed
+96
-37
No files matched your search
@@ -29,6 +29,7 @@ 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 slimeknights.mantle.client.gui.book.element.SizedBookElement;
|
||||
|
||||
import static slimeknights.mantle.client.gui.book.Textures.TEX_BOOK;
|
||||
import static slimeknights.mantle.client.gui.book.Textures.TEX_BOOKFRONT;
|
||||
@@ -40,16 +41,24 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
|
||||
public static final int TEX_SIZE = 512;
|
||||
|
||||
public static final int PAGE_PADDING = 8;
|
||||
public static final int PAGE_MARGIN = 18;
|
||||
public static int PAGE_MARGIN = 8;
|
||||
|
||||
public static final float PAGE_SCALE = 0.5F;
|
||||
public static final int PAGE_WIDTH_UNSCALED = 206;
|
||||
public static final int PAGE_HEIGHT_UNSCALED = 200;
|
||||
public static int PAGE_PADDING_TOP = 4;
|
||||
public static int PAGE_PADDING_BOT = 4;
|
||||
public static int PAGE_PADDING_LEFT = 8;
|
||||
public static int PAGE_PADDING_RIGHT = 0;
|
||||
|
||||
public static float PAGE_SCALE = 1f;
|
||||
public static int PAGE_WIDTH_UNSCALED = 206;
|
||||
public static int PAGE_HEIGHT_UNSCALED = 200;
|
||||
|
||||
// For best results, make sure both PAGE_WIDTH_UNSCALED - (PAGE_PADDING + PAGE_MARGIN) * 2 and PAGE_HEIGHT_UNSCALED - (PAGE_PADDING + PAGE_MARGIN) * 2 divide evenly into PAGE_SCALE (without remainder)
|
||||
public static final int PAGE_WIDTH = (int) ((PAGE_WIDTH_UNSCALED - (PAGE_PADDING + PAGE_MARGIN) * 2) / PAGE_SCALE);
|
||||
public static final int PAGE_HEIGHT = (int) ((PAGE_HEIGHT_UNSCALED - (PAGE_PADDING + PAGE_MARGIN) * 2) / PAGE_SCALE);
|
||||
public static int PAGE_WIDTH;
|
||||
public static int PAGE_HEIGHT;
|
||||
|
||||
static{
|
||||
init(); // initializes page width and height
|
||||
}
|
||||
|
||||
private boolean loadingAchievements = true;
|
||||
private GuiArrow previousArrow, nextArrow, backArrow, indexArrow;
|
||||
@@ -64,27 +73,54 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
|
||||
public StatFileWriter statFile;
|
||||
|
||||
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, StatFileWriter statFile, @Nullable ItemStack item) {
|
||||
this.book = book;
|
||||
this.item = item;
|
||||
|
||||
this.statFile = statFile;
|
||||
init();
|
||||
}
|
||||
|
||||
public void drawerTransform(boolean rightSide) {
|
||||
if(rightSide) {
|
||||
GlStateManager
|
||||
.translate(width / 2 + PAGE_PADDING + PAGE_MARGIN, height / 2 - PAGE_HEIGHT_UNSCALED / 2 + PAGE_PADDING + PAGE_MARGIN, 0);
|
||||
GlStateManager.translate(width / 2 + PAGE_PADDING_RIGHT + PAGE_MARGIN, height / 2 - PAGE_HEIGHT_UNSCALED / 2 + PAGE_PADDING_TOP + PAGE_MARGIN, 0);
|
||||
} else {
|
||||
GlStateManager
|
||||
.translate(width / 2 - PAGE_WIDTH_UNSCALED + PAGE_PADDING + PAGE_MARGIN, height / 2 - PAGE_HEIGHT_UNSCALED / 2 + PAGE_PADDING + PAGE_MARGIN, 0);
|
||||
GlStateManager.translate(width / 2 - PAGE_WIDTH_UNSCALED + PAGE_PADDING_LEFT + PAGE_MARGIN, height / 2 - PAGE_HEIGHT_UNSCALED / 2 + PAGE_PADDING_TOP + PAGE_MARGIN, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// offset to the left edge of the left/right side
|
||||
protected float leftOffset(boolean rightSide) {
|
||||
if(rightSide) {
|
||||
// from center: go padding + margin to the right
|
||||
return width / 2 + PAGE_PADDING_RIGHT + PAGE_MARGIN;
|
||||
} else {
|
||||
// from center: go page width left, then right with padding and margin
|
||||
return width / 2 - PAGE_WIDTH_UNSCALED + PAGE_PADDING_LEFT + PAGE_MARGIN;
|
||||
}
|
||||
}
|
||||
|
||||
protected float topOffset() {
|
||||
return height / 2 - PAGE_HEIGHT_UNSCALED / 2 + PAGE_PADDING_TOP + PAGE_MARGIN;
|
||||
}
|
||||
|
||||
protected int getMouseX(boolean rightSide) {
|
||||
return (int) ((Mouse.getX() * this.width / this.mc.displayWidth - leftOffset(rightSide)) / PAGE_SCALE);
|
||||
}
|
||||
|
||||
protected int getMouseY() {
|
||||
return (int) ((this.height - Mouse.getY() * this.height / this.mc.displayHeight - 1 - topOffset()) / PAGE_SCALE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("ForLoopReplaceableByForEach")
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
init();
|
||||
FontRenderer fontRenderer = book.fontRenderer;
|
||||
if(fontRenderer == null) {
|
||||
fontRenderer = mc.fontRendererObj;
|
||||
@@ -110,13 +146,32 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
GlStateManager.enableBlend();
|
||||
|
||||
// The books are unreadable at Gui Scale set to small, so we'll double the scale
|
||||
/*
|
||||
if(mc.gameSettings.guiScale == 1) {
|
||||
GlStateManager.scale(2F, 2F, 2F);
|
||||
float f = 1.5f;
|
||||
GlStateManager.scale(f, f, 1);
|
||||
|
||||
mouseX /= 2;
|
||||
mouseY /= 2;
|
||||
float ox = this.width/6;
|
||||
float oy = this.height/6;
|
||||
|
||||
mouseX = (int)((float)mouseX / f);
|
||||
mouseY = (int)((float)mouseY / f);
|
||||
|
||||
GlStateManager.translate(ox, oy, 0);
|
||||
}
|
||||
else if(mc.gameSettings.guiScale == 2) {
|
||||
float f = 3f/2f;
|
||||
GlStateManager.scale(f, f, 1);
|
||||
|
||||
float ox = -this.width/6;
|
||||
float oy = -this.height/6;
|
||||
|
||||
mouseX = (int)(((float)mouseX - ox)/f);
|
||||
mouseY = (int)(((float)mouseY - oy)/f);
|
||||
|
||||
GlStateManager.translate(ox, oy, 0);
|
||||
}
|
||||
*/
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.color(1F, 1F, 1F);
|
||||
|
||||
@@ -171,14 +226,11 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
|
||||
if(book.appearance.drawPageNumbers) {
|
||||
String pNum = (page - 1) * 2 + 2 + "";
|
||||
fontRenderer.drawString(pNum, PAGE_WIDTH / 2 - fontRenderer
|
||||
.getStringWidth(pNum) / 2, PAGE_HEIGHT + 15, 0xFFAAAAAA, false);
|
||||
fontRenderer.drawString(pNum, PAGE_WIDTH / 2 - fontRenderer.getStringWidth(pNum) / 2, PAGE_HEIGHT - 10, 0xFFAAAAAA, false);
|
||||
}
|
||||
|
||||
int mX = (int) ((Mouse
|
||||
.getX() * this.width / this.mc.displayWidth - (width / 2 - PAGE_WIDTH_UNSCALED) - PAGE_PADDING - PAGE_MARGIN) / PAGE_SCALE);
|
||||
int mY = (int) ((this.height - Mouse
|
||||
.getY() * this.height / this.mc.displayHeight - 1 - (height / 2 - PAGE_HEIGHT_UNSCALED / 2) - PAGE_PADDING - PAGE_MARGIN) / PAGE_SCALE);
|
||||
int mX = getMouseX(false);
|
||||
int mY = getMouseY();
|
||||
|
||||
// Not foreach to prevent conmodification crashes
|
||||
for(int i = 0; i < leftElements.size(); i++) {
|
||||
@@ -215,14 +267,11 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
|
||||
if(book.appearance.drawPageNumbers) {
|
||||
String pNum = (page - 1) * 2 + 3 + "";
|
||||
fontRenderer.drawString(pNum, PAGE_WIDTH / 2 - fontRenderer
|
||||
.getStringWidth(pNum) / 2, PAGE_HEIGHT + 15, 0xFFAAAAAA, false);
|
||||
fontRenderer.drawString(pNum, PAGE_WIDTH / 2 - fontRenderer.getStringWidth(pNum) / 2, PAGE_HEIGHT - 10, 0xFFAAAAAA, false);
|
||||
}
|
||||
|
||||
int mX = (int) ((Mouse
|
||||
.getX() * this.width / this.mc.displayWidth - (width / 2) - PAGE_PADDING - PAGE_MARGIN) / PAGE_SCALE);
|
||||
int mY = (int) ((this.height - Mouse
|
||||
.getY() * this.height / this.mc.displayHeight - 1 - (height / 2 - PAGE_HEIGHT_UNSCALED / 2) - PAGE_PADDING - PAGE_MARGIN) / PAGE_SCALE);
|
||||
int mX = getMouseX(true);
|
||||
int mY = getMouseY();
|
||||
|
||||
// Not foreach to prevent conmodification crashes
|
||||
for(int i = 0; i < rightElements.size(); i++) {
|
||||
@@ -493,14 +542,11 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
|
||||
boolean right = false;
|
||||
|
||||
mouseX = (int) ((Mouse
|
||||
.getX() * this.width / this.mc.displayWidth - (width / 2 - PAGE_WIDTH_UNSCALED) - PAGE_PADDING - PAGE_MARGIN) / PAGE_SCALE);
|
||||
mouseY = (int) ((this.height - Mouse
|
||||
.getY() * this.height / this.mc.displayHeight - 1 - (height / 2 - PAGE_HEIGHT_UNSCALED / 2) - PAGE_PADDING - PAGE_MARGIN) / PAGE_SCALE);
|
||||
mouseX = getMouseX(false);
|
||||
mouseY = getMouseY();
|
||||
|
||||
if(mouseX > PAGE_WIDTH + (PAGE_MARGIN + PAGE_PADDING) / PAGE_SCALE) {
|
||||
mouseX = (int) ((Mouse
|
||||
.getX() * this.width / this.mc.displayWidth - (width / 2) - PAGE_PADDING - PAGE_MARGIN) / PAGE_SCALE);
|
||||
if(mouseX > PAGE_WIDTH + (PAGE_MARGIN + PAGE_PADDING_LEFT) / PAGE_SCALE) {
|
||||
mouseX = getMouseX(true);
|
||||
right = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,8 +45,10 @@ public class GuiBookEditor extends GuiScreen {
|
||||
mouseY /= 2;
|
||||
}
|
||||
|
||||
BoxRenderer
|
||||
.drawBox(width / 2 - (GuiBook.PAGE_WIDTH_UNSCALED + SIDEBAR_WIDTH) / 2, height / 2 - (GuiBook.PAGE_HEIGHT_UNSCALED - GuiBook.PAGE_PADDING) / 2, SIDEBAR_WIDTH + GuiBook.PAGE_PADDING + GuiBook.PAGE_MARGIN, GuiBook.PAGE_HEIGHT_UNSCALED - GuiBook.PAGE_PADDING, 0);
|
||||
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();
|
||||
@@ -61,8 +63,19 @@ public class GuiBookEditor extends GuiScreen {
|
||||
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, GuiBook.PAGE_HEIGHT_UNSCALED, GuiBook.TEX_SIZE, GuiBook.TEX_SIZE);
|
||||
drawModalRectWithCustomSizedTexture(width / 2 - GuiBook.PAGE_WIDTH_UNSCALED / 2 + GuiBook.PAGE_MARGIN + GuiBook.PAGE_PADDING, height / 2 - GuiBook.PAGE_HEIGHT_UNSCALED / 2, GuiBook.PAGE_WIDTH_UNSCALED + GuiBook.PAGE_MARGIN + GuiBook.PAGE_PADDING, GuiBook.PAGE_HEIGHT_UNSCALED, GuiBook.PAGE_WIDTH_UNSCALED - GuiBook.PAGE_MARGIN - GuiBook.PAGE_PADDING, GuiBook.PAGE_HEIGHT_UNSCALED, GuiBook.TEX_SIZE, GuiBook.TEX_SIZE);
|
||||
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);
|
||||
|
||||
Reference in new issue
Block a user