Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
5fa7cdb
add animation for opening manual
MCTBL Apr 28, 2026
c927af7
add auto scaled but have some issue
MCTBL Apr 28, 2026
f7c67cd
add auto scale for manual
MCTBL Apr 29, 2026
cf62d75
fix the wrong y position
MCTBL Apr 29, 2026
b41cbc9
Dump button, dumps the grid to linked inventory (#228)
ChromaPIE Apr 28, 2026
db69873
Merge branch 'master' into rework_manual
MCTBL Apr 29, 2026
712064f
let buttons will render while during animation
MCTBL Apr 29, 2026
e1017ec
prevent calc position every time after finish
MCTBL Apr 30, 2026
c2f720e
Merge branch 'master' into rework_manual
Dream-Master Apr 30, 2026
b45b097
add a button to quickly back to home page like higher version
MCTBL May 1, 2026
79fbc0c
Merge branch 'master' into rework_manual
MCTBL May 4, 2026
7eca5a8
make book front cover and page render separately
MCTBL May 5, 2026
edf28be
add navigation button class
MCTBL May 6, 2026
5c0a623
add tooltips for manual button
MCTBL May 7, 2026
717adf0
add new tic crafting page
MCTBL May 7, 2026
dd6d446
can use mouse scroll and arrow key to turn page
MCTBL May 9, 2026
96eefad
add TiC pic/furnace render
MCTBL May 9, 2026
f3212a7
fix wrong render order
MCTBL May 9, 2026
89cb77e
let item stack can hover
MCTBL May 9, 2026
2943e3e
add auto generate page / quick jump button
MCTBL May 9, 2026
14e23ba
fix wrong render code copy from Mantel
MCTBL May 10, 2026
f1859ed
add tool desc lang key
MCTBL May 10, 2026
5c8095d
replace some magic number and copy tools desc
MCTBL May 11, 2026
4eb3a94
add render for material buttons
MCTBL May 11, 2026
3fe2fd1
adjust capacity
MCTBL May 11, 2026
6b95a6c
add null check to prevent crashing (#280)
MCTBL May 6, 2026
31672c5
fix(InventoryCraftingStation): add missing markDirty (#284)
Worive May 7, 2026
c985d04
Correctly loot registration (#283)
slprime May 9, 2026
0ebca89
prevent `ToolPartChunk` and shard
MCTBL May 11, 2026
c5372e3
change itter way like NEI addons
MCTBL May 12, 2026
0244ba6
Merge branch 'master' into rework_manual
MCTBL May 12, 2026
3edae6c
add localization for reinforced universal implement
MCTBL May 13, 2026
013ab2d
add material page
MCTBL May 13, 2026
e3f430f
add color for ability
MCTBL May 13, 2026
848e9dd
add font color helper
MCTBL May 14, 2026
55b6369
add tooltip desc for string in manual
MCTBL May 14, 2026
d41ad1c
add material ability tooltips
MCTBL May 16, 2026
2afb878
format modifier define
MCTBL May 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/main/java/tconstruct/client/TProxyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import org.w3c.dom.Document;

import cpw.mods.fml.common.Loader;
import mantle.client.SmallFontRenderer;
import mantle.lib.client.MantleClientRegistry;
import tconstruct.TConstruct;
Expand Down Expand Up @@ -57,15 +56,16 @@ public void registerRenderer() {
public static Document volume2;
public static Document smelter;
public static Document weaponry;
public static Document materialsandyou;
public static ManualInfo manualData;

public void readManuals() {
initManualIcons();
initManualRecipes();
initManualPages();
if (!Loader.isModLoaded("dreamcraft")) {
readTinkersConstructManuals();
}
// if (!Loader.isModLoaded("dreamcraft")) {
readTinkersConstructManuals();
// }
}

private void readTinkersConstructManuals() {
Expand All @@ -77,13 +77,15 @@ private void readTinkersConstructManuals() {
Document volume2_cl = readManual("/assets/tinker/manuals/" + CurrentLanguage + "/materials.xml", dbFactory);
Document smelter_cl = readManual("/assets/tinker/manuals/" + CurrentLanguage + "/smeltery.xml", dbFactory);
Document weaponry_cl = readManual("/assets/tinker/manuals/" + CurrentLanguage + "/weaponry.xml", dbFactory);
Document materialsandyou_cl = readManual("/assets/tinker/manuals/materialsandyou.xml", dbFactory);

diary = diary_cl != null ? diary_cl : readManual("/assets/tinker/manuals/en_US/diary.xml", dbFactory);
volume1 = volume1_cl != null ? volume1_cl : readManual("/assets/tinker/manuals/en_US/firstday.xml", dbFactory);
volume2 = volume2_cl != null ? volume2_cl : readManual("/assets/tinker/manuals/en_US/materials.xml", dbFactory);
smelter = smelter_cl != null ? smelter_cl : readManual("/assets/tinker/manuals/en_US/smeltery.xml", dbFactory);
weaponry = weaponry_cl != null ? weaponry_cl
: readManual("/assets/tinker/manuals/en_US/weaponry.xml", dbFactory);
materialsandyou = materialsandyou_cl;

manualData = new ManualInfo();
}
Expand Down
157 changes: 157 additions & 0 deletions src/main/java/tconstruct/client/pages/NavigationPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package tconstruct.client.pages;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import mantle.books.BookData;
import tconstruct.TConstruct;
import tconstruct.library.client.TConstructClientRegistry;
import tconstruct.library.util.IToolPart;
import tconstruct.library.util.TiCBookData;
import tconstruct.library.util.TiCGuiManual;
import tconstruct.library.util.TiCNavigationButton;
import tconstruct.library.util.TiCNavigationButton.ButtonSize;
import tconstruct.util.FontColorHelper;
import tconstruct.util.McTextFormatter;

public class NavigationPage extends TiCBookPage {

private static final String namePrefix = "tconstruct.manual.materialsandyou.navigation.";

private ButtonSize BS;

private String title;
int eachRow;

@Override
public void readPageFromXML(Element element) {
this.pageButtonList = new ArrayList<>();

String size = element.getAttribute("size");
this.BS = ButtonSize.getSize(size);

String eachRowString = element.getAttribute("capacity");
this.eachRow = eachRowString.length() != 0 ? Integer.parseInt(eachRowString) : 5;

String name = element.getAttribute("name");
if (StatCollector.canTranslate(namePrefix + name)) {
this.title = StatCollector.translateToLocal(namePrefix + name);
} else {
this.title = name;
}

NodeList buttonList = element.getElementsByTagName("button");
int length = buttonList.getLength();
for (int idx = 0; idx < length; idx++) {
Element b = (Element) buttonList.item(idx);

String color = b.getAttribute("color");
String naviTo = b.getAttribute("to");
String tempText = b.getElementsByTagName("text").item(0).getTextContent();
if (StatCollector.canTranslate(tempText)) tempText = StatCollector.translateToLocal(tempText);

String iconStr = b.getElementsByTagName("icon").item(0).getTextContent();
if (iconStr.startsWith("material_")) {
ItemStack[] iconStacks = (ItemStack[]) TConstructClientRegistry.getManualIcon(iconStr);
iconStacks = Arrays.asList(iconStacks).stream().filter(i -> !(i.getItem() instanceof IToolPart))
.collect(Collectors.toList()).toArray(new ItemStack[0]);
this.pageButtonList
.add(
new TiCNavigationButton(
0,
this.BS,
iconStacks,
naviTo,
tempText,
this,
color.length() != 0 ? FontColorHelper
.adjustForegroundKeepHue(BACKGROUNDCOLOR, Integer.parseInt(color))
: 0x000000));
} else {
ItemStack iconStack = TConstructClientRegistry.getOrRegisterManualIcon(iconStr);
this.pageButtonList.add(new TiCNavigationButton(0, this.BS, iconStack, tempText, naviTo, this));
}
}
}

public static int ceilDiv(int x, int y) {
final int q = x / y;
// if the signs are the same and modulo not zero, round up
if ((x ^ y) >= 0 && (q * y != x)) {
return q + 1;
}
return q;
}

public void updateButtonPositionAndRender(int startX, int startY, float scale, int mouseX, int mouseY,
List<GuiButton> parentButtonList) {
if (title != null) this.drawStrCenterAt(
McTextFormatter.addUnderLine(title),
startX + PAGECONTENTWIDTH / 2,
startY + 4,
1.0f,
0x000000);

int middleX = startX + PAGECONTENTWIDTH / 2;
int middleY = startY + PAGECONTENTHEIGHT / 2;

int buttonWidth = (int) (TiCNavigationButton.defaultWidth * BS.multi);
int buttonHeight = (int) (TiCNavigationButton.defaultHeight * BS.multi);
// int buttonGap = buttonWidth / 8;
int buttonGap = 5;

int buttonRows = ceilDiv(this.pageButtonList.size(), this.eachRow);

int buttonsGroupHeight = buttonRows * buttonHeight + (buttonRows - 1) * buttonGap;
int buttonsGroupWidth = this.eachRow * buttonWidth + (this.eachRow - 1) * buttonGap;

int buttonsGroupStartX = middleX - buttonsGroupWidth / 2;
int buttonsGroupStartY = middleY - buttonsGroupHeight / 2;

for (int idx = 0; idx < this.pageButtonList.size(); idx++) {
TiCNavigationButton b = (TiCNavigationButton) this.pageButtonList.get(idx);
int row = idx / this.eachRow;
int column = idx % this.eachRow;

int buttonX = buttonsGroupStartX + column * (buttonWidth + buttonGap);
int buttonY = buttonsGroupStartY + row * (buttonHeight + buttonGap);

b.id = idx + parentButtonList.size();
b.xPosition = (int) (buttonX * scale);
b.yPosition = (int) (buttonY * scale);
b.drawButtonWithScale(manual.mc, mouseX, mouseY, scale, manual.fonts);
}

if (parentButtonList != null) {
parentButtonList.addAll(this.pageButtonList);
}
}

@Override
public void actionPerformed(GuiButton button, BookData d) {
TiCNavigationButton b = (TiCNavigationButton) button;
if (d instanceof TiCBookData tcbd) {
int pageIndex = tcbd.getIndexFromName(b.target);
Item item = b.renderStack[b.counter % b.renderStack.length].getItem();

TConstruct.logger.info(item + " is clicked");
if (pageIndex != -1) {
((TiCGuiManual) manual).setCurrentPage(pageIndex);
} else {
TConstruct.logger.error("There's no page name " + b.target);
}
}

}

}
120 changes: 120 additions & 0 deletions src/main/java/tconstruct/client/pages/TiCBookPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package tconstruct.client.pages;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.item.ItemStack;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

import mantle.books.BookData;
import mantle.client.pages.BookPage;
import tconstruct.library.util.ItemStackWithPosition;
import tconstruct.library.util.TiCGuiButton;
import tconstruct.library.util.WidgetsHasTooltips;

public abstract class TiCBookPage extends BookPage {

public static final int PAGECONTENTHEIGHT = 165;

// outer gap is 16 inner gap is 5, 185 + 16 + 5 = 206
public static final int PAGECONTENTWIDTH = 185;

public static final int BACKGROUNDCOLOR = 0xFFFAEE;

List<TiCGuiButton> pageButtonList;
public List<WidgetsHasTooltips> widgetsList = new ArrayList<>();

public void updateButtonPositionAndRender(int startX, int startY, float scale, int mouseX, int mouseY,
List<GuiButton> parentButtonList) {

// just for debug, draw a rect on page range to see where is the border
// Gui.drawRect(startX, startY, startX + PAGECONTENTWIDTH, startY + PAGECONTENTHEIGHT, 0xAAAAAAAA);

updateButtonPosition(startX, startY, scale, mouseX, mouseY, parentButtonList);
render(startX, startY, scale, mouseX, mouseY, parentButtonList);
}

public void updateButtonPosition(int startX, int startY, float scale, int mouseX, int mouseY,
List<GuiButton> parentButtonList) {}

public void render(int startX, int startY, float scale, int mouseX, int mouseY, List<GuiButton> parentButtonList) {}

@Override
public void renderContentLayer(int localwidth, int localheight, boolean isTranslatable) {
this.updateButtonPositionAndRender(localheight, localheight, 1.0f, 0, 0, null);
}

public void actionPerformed(GuiButton button, BookData b) {}

void drawStrAt(String str, int X, int Y, float scale) {
drawStrAt(str, X, Y, scale, 0x000000);
}

void drawStrAt(String str, int X, int Y, float scale, int color) {
manual.fonts.drawString(str, (int) (X / scale), (int) (Y / scale), color);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
}

void drawStrCenterAt(String str, int X, int Y, float scale, int color) {
manual.fonts.drawString(
str,
(int) (X / scale - manual.fonts.getStringWidth(str) / 2),
(int) ((Y - manual.fonts.FONT_HEIGHT / 2) / scale),
color);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
}

void renderItemStackIntoPage(ItemStack stack, int x, int y) {
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glPushMatrix();
manual.renderitem.renderItemAndEffectIntoGUI(manual.fonts, manual.getMC().renderEngine, stack, x, y);
if (stack.stackSize > 1) manual.renderitem.renderItemOverlayIntoGUI(
manual.fonts,
manual.getMC().renderEngine,
stack,
x,
y,
String.valueOf(stack.stackSize));
GL11.glPopMatrix();
GL11.glPopAttrib();
}

void beforeRenderItem() {
beforeRenderItem(2.0F);
}

void beforeRenderItem(float scale) {
beforeRenderItem(scale, 100);
}

void beforeRenderItem(float scale, int z) {
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glScalef(scale, scale, 2.0F);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
RenderHelper.enableGUIStandardItemLighting();
manual.renderitem.zLevel = z;
}

void afterRenderItem() {
afterRenderItem(2.0F);
}

void afterRenderItem(float scale) {
manual.renderitem.zLevel = 0;
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
GL11.glPopAttrib();
GL11.glPopMatrix();
}

void renderItemStackIntoPage(ItemStack stack, int x, int y, float scale) {
renderItemStackIntoPage(stack, x, y);
this.widgetsList.add(new ItemStackWithPosition(stack, x, y, scale));
}

}
54 changes: 54 additions & 0 deletions src/main/java/tconstruct/client/pages/TiCCoverPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package tconstruct.client.pages;

import net.minecraft.util.StatCollector;

import org.lwjgl.opengl.GL11;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import mantle.client.pages.BookPage;

public class TiCCoverPage extends BookPage {

String[] innerText;

@Override
public void readPageFromXML(Element element) {
NodeList nodes = element.getElementsByTagName("text");
String tempText = nodes.item(0).getTextContent();
if (StatCollector.canTranslate(tempText)) tempText = StatCollector.translateToLocal(tempText);
innerText = tempText.split("\\\\n");
}

private void drawStrCenterAt(String str, int X, int Y, float scale, int color) {
manual.fonts.drawString(
str,
(int) (X / scale - manual.fonts.getStringWidth(str) / 2),
(int) ((Y - manual.fonts.FONT_HEIGHT / 2) / scale),
color);
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}

@Override
public void renderContentLayer(int startX, int startY, boolean isTranslatable) {

int cousorX = TiCBookPage.PAGECONTENTWIDTH / 2;
int cousorY = TiCBookPage.PAGECONTENTHEIGHT * 3 / 7;

float scale = 2.5f;
GL11.glScalef(scale, scale, 1.0f);
this.drawStrCenterAt(innerText[0], startX + cousorX, startY + cousorY, scale, 0x000000);
cousorY += manual.fonts.FONT_HEIGHT * scale;
GL11.glScalef(1.0f / scale, 1.0f / scale, 1.0f);

scale = 1.0f;
GL11.glScalef(scale, scale, 1.0f);
this.drawStrCenterAt(innerText[1], startX + cousorX, startY + cousorY, scale, 0x000000);
cousorY += manual.fonts.FONT_HEIGHT * scale;
this.drawStrCenterAt(innerText[2], startX + cousorX, startY + cousorY, scale, 0x000000);
cousorY += manual.fonts.FONT_HEIGHT * scale;
GL11.glScalef(1.0f / scale, 1.0f / scale, 1.0f);

}

}
Loading
Loading