mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-20 20:22:17 +00:00
Create Recipe Widget; Recipe GUI: Infinity Scroll; Recipe GUI: Max Height Settings (#701)
Co-authored-by: Martin Robertz <[email protected]>
This commit is contained in:
1 parent
2ea9ae1eb9
commit
fe0c5d4e50
50 files changed
+4150
-2107
No files matched your search
@@ -1,168 +1,154 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
import static codechicken.lib.gui.GuiDraw.getMousePosition;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.nei.Button;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
|
||||
public class GuiRecipeTabs {
|
||||
|
||||
private final GuiRecipe<?> guiRecipe;
|
||||
private final List<GuiRecipeTab> tabs = new ArrayList<>();
|
||||
private final List<Button> buttons = new ArrayList<>();
|
||||
|
||||
private final Rectangle area = new Rectangle();
|
||||
private List<? extends IRecipeHandler> currenthandlers;
|
||||
|
||||
private int pageCount = 1;
|
||||
private int pageNumber = 0;
|
||||
private int categoriesPerPage = 1;
|
||||
private int numHandlers = 1;
|
||||
private int tabWidth;
|
||||
private int tabHeight;
|
||||
private int recipetype;
|
||||
|
||||
public GuiRecipeTabs(GuiRecipe<?> guiRecipe) {
|
||||
this.guiRecipe = guiRecipe;
|
||||
}
|
||||
private final Button prevTab = new Button("<") {
|
||||
|
||||
public void initLayout() {
|
||||
if (NEIClientConfig.useCreativeTabStyle()) {
|
||||
tabWidth = GuiRecipeTabCreative.TAB_WIDTH;
|
||||
tabHeight = GuiRecipeTabCreative.TAB_HEIGHT;
|
||||
} else {
|
||||
tabWidth = GuiRecipeTabJEI.TAB_WIDTH;
|
||||
tabHeight = GuiRecipeTabJEI.TAB_HEIGHT;
|
||||
@Override
|
||||
public boolean onButtonPress(boolean rightClick) {
|
||||
if (!rightClick) {
|
||||
NEIClientUtils.playClickSound();
|
||||
return previousPage();
|
||||
} else return false;
|
||||
}
|
||||
|
||||
int totalWidth = 0;
|
||||
categoriesPerPage = 0;
|
||||
numHandlers = guiRecipe.currenthandlers.size();
|
||||
};
|
||||
|
||||
for (int i = 0; i < numHandlers; i++) {
|
||||
if (totalWidth + tabWidth < (guiRecipe.xSize - 4)) {
|
||||
totalWidth += tabWidth;
|
||||
categoriesPerPage++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
private final Button nextTab = new Button(">") {
|
||||
|
||||
@Override
|
||||
public boolean onButtonPress(boolean rightclick) {
|
||||
if (!rightclick) {
|
||||
NEIClientUtils.playClickSound();
|
||||
return nextPage();
|
||||
} else return false;
|
||||
}
|
||||
|
||||
area.width = totalWidth;
|
||||
area.height = tabHeight;
|
||||
area.x = guiRecipe.guiLeft + 4;
|
||||
area.y = guiRecipe.guiTop - tabHeight + 3;
|
||||
};
|
||||
|
||||
pageCount = (int) Math.ceil((float) numHandlers / categoriesPerPage);
|
||||
calcPageNumber();
|
||||
Rectangle navigationArea = new Rectangle(area);
|
||||
navigationArea.height = 20;
|
||||
navigationArea.translate(0, -(2 + navigationArea.height));
|
||||
public static int getTabWidth() {
|
||||
return NEIClientConfig.useCreativeTabStyle() ? GuiRecipeTabCreative.TAB_WIDTH : GuiRecipeTabJEI.TAB_WIDTH;
|
||||
}
|
||||
|
||||
public void calcPageNumber() {
|
||||
pageNumber = guiRecipe.recipetype / Math.max(categoriesPerPage, 1);
|
||||
public static int getTabHeight() {
|
||||
return NEIClientConfig.useCreativeTabStyle() ? GuiRecipeTabCreative.TAB_HEIGHT : GuiRecipeTabJEI.TAB_HEIGHT;
|
||||
}
|
||||
|
||||
public void update(GuiRecipe<?> guiRecipe) {
|
||||
final int tabWidth = getTabWidth();
|
||||
final int tabHeight = getTabHeight();
|
||||
|
||||
this.recipetype = guiRecipe.recipetype;
|
||||
this.currenthandlers = guiRecipe.currenthandlers;
|
||||
this.numHandlers = this.currenthandlers.size();
|
||||
this.categoriesPerPage = (guiRecipe.xSize - 4) / tabWidth;
|
||||
this.pageNumber = this.recipetype / Math.max(this.categoriesPerPage, 1);
|
||||
this.pageCount = (int) Math.ceil((float) this.numHandlers / this.categoriesPerPage);
|
||||
|
||||
this.area.width = this.categoriesPerPage * tabWidth;
|
||||
this.area.height = tabHeight;
|
||||
this.area.x = guiRecipe.guiLeft + 4;
|
||||
this.area.y = guiRecipe.guiTop - tabHeight + 3;
|
||||
|
||||
refreshPage();
|
||||
updateArrows(tabHeight);
|
||||
}
|
||||
|
||||
public void refreshPage() {
|
||||
tabs.clear();
|
||||
buttons.clear();
|
||||
final int startIndex = this.pageNumber * this.categoriesPerPage;
|
||||
final int tabWidth = getTabWidth();
|
||||
|
||||
final int startIndex = pageNumber * categoriesPerPage;
|
||||
for (int i = 0; i < categoriesPerPage; i++) {
|
||||
this.tabs.clear();
|
||||
|
||||
for (int i = 0; i < this.categoriesPerPage && i + startIndex < numHandlers; i++) {
|
||||
final int index = i + startIndex;
|
||||
if (index >= numHandlers) break;
|
||||
IRecipeHandler handler = guiRecipe.currenthandlers.get(index);
|
||||
int tabX = area.x + (i * tabWidth);
|
||||
final IRecipeHandler handler = this.currenthandlers.get(index);
|
||||
final int tabX = this.area.x + (i * tabWidth);
|
||||
|
||||
if (NEIClientConfig.useCreativeTabStyle()) {
|
||||
tabs.add(new GuiRecipeTabCreative(guiRecipe, handler, tabX, area.y));
|
||||
tabs.add(new GuiRecipeTabCreative(handler, tabX, this.area.y) {
|
||||
|
||||
@Override
|
||||
public boolean onButtonPress(boolean rightclick) {
|
||||
setRecipePage(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
});
|
||||
} else {
|
||||
tabs.add(new GuiRecipeTabJEI(guiRecipe, handler, tabX, area.y));
|
||||
tabs.add(new GuiRecipeTabJEI(handler, tabX, this.area.y) {
|
||||
|
||||
@Override
|
||||
public boolean onButtonPress(boolean rightclick) {
|
||||
setRecipePage(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Maybe add buttons
|
||||
if (numHandlers > categoriesPerPage) {
|
||||
Button prevTab = new Button("prevTab") {
|
||||
private void updateArrows(int tabHeight) {
|
||||
this.buttons.clear();
|
||||
|
||||
@Override
|
||||
public boolean onButtonPress(boolean rightClick) {
|
||||
if (!rightClick) {
|
||||
NEIClientUtils.playClickSound();
|
||||
return previousPage();
|
||||
} else return false;
|
||||
}
|
||||
if (this.numHandlers > this.categoriesPerPage) {
|
||||
this.prevTab.w = this.nextTab.w = 8;
|
||||
this.prevTab.h = this.nextTab.h = tabHeight - 4;
|
||||
this.prevTab.y = this.nextTab.y = this.area.y + 2;
|
||||
|
||||
@Override
|
||||
public String getRenderLabel() {
|
||||
return "<";
|
||||
}
|
||||
};
|
||||
prevTab.w = 8;
|
||||
prevTab.h = tabHeight - 4;
|
||||
prevTab.x = area.x - prevTab.w + 1;
|
||||
prevTab.y = area.y + 2;
|
||||
buttons.add(prevTab);
|
||||
this.prevTab.x = this.area.x - this.prevTab.w + 1;
|
||||
this.nextTab.x = this.area.x + this.area.width - 1;
|
||||
|
||||
Button nextTab = new Button("nextTab") {
|
||||
|
||||
@Override
|
||||
public boolean onButtonPress(boolean rightclick) {
|
||||
if (!rightclick) {
|
||||
NEIClientUtils.playClickSound();
|
||||
return nextPage();
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRenderLabel() {
|
||||
return ">";
|
||||
}
|
||||
};
|
||||
nextTab.w = prevTab.w;
|
||||
nextTab.h = prevTab.h;
|
||||
nextTab.x = area.x + area.width - 1;
|
||||
nextTab.y = prevTab.y;
|
||||
buttons.add(nextTab);
|
||||
this.buttons.add(this.prevTab);
|
||||
this.buttons.add(this.nextTab);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean nextPage() {
|
||||
if (hasNext()) pageNumber++;
|
||||
else pageNumber = 0;
|
||||
protected void setRecipePage(int recipetype) {}
|
||||
|
||||
public boolean nextPage() {
|
||||
this.pageNumber = (this.pageNumber + 1) % this.pageCount;
|
||||
refreshPage();
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return pageNumber + 1 < pageCount;
|
||||
}
|
||||
|
||||
public boolean previousPage() {
|
||||
if (hasPrevious()) pageNumber--;
|
||||
else pageNumber = pageCount - 1;
|
||||
|
||||
this.pageNumber = (this.pageCount + this.pageNumber - 1) % this.pageCount;
|
||||
refreshPage();
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return pageNumber > 0;
|
||||
}
|
||||
|
||||
public void draw(int mouseX, int mouseY) {
|
||||
IRecipeHandler current = guiRecipe.currenthandlers.get(guiRecipe.recipetype);
|
||||
for (GuiRecipeTab tab : tabs) {
|
||||
tab.setSelected(current);
|
||||
final int indexShift = this.pageNumber * this.categoriesPerPage;
|
||||
|
||||
for (int index = 0; index < this.tabs.size(); index++) {
|
||||
final GuiRecipeTab tab = this.tabs.get(index);
|
||||
tab.setSelected(indexShift + index == this.recipetype);
|
||||
tab.draw(mouseX, mouseY);
|
||||
}
|
||||
for (Button button : buttons) {
|
||||
|
||||
for (Button button : this.buttons) {
|
||||
button.draw(mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
@@ -170,12 +156,12 @@ public class GuiRecipeTabs {
|
||||
public void handleTooltip(int mousex, int mousey, List<String> tooltips) {
|
||||
if (!NEIClientConfig.areJEIStyleTabsVisible()) return;
|
||||
|
||||
for (GuiRecipeTab tab : tabs) {
|
||||
for (GuiRecipeTab tab : this.tabs) {
|
||||
if (tab.contains(mousex, mousey)) {
|
||||
tab.addTooltips(tooltips);
|
||||
}
|
||||
}
|
||||
for (Button button : buttons) {
|
||||
for (Button button : this.buttons) {
|
||||
if (button.contains(mousex, mousey)) {
|
||||
button.addTooltips(tooltips);
|
||||
}
|
||||
@@ -185,27 +171,26 @@ public class GuiRecipeTabs {
|
||||
protected boolean mouseClicked(int x, int y, int mouseButton) {
|
||||
if (!NEIClientConfig.areJEIStyleTabsVisible()) return false;
|
||||
|
||||
for (Button button : buttons) {
|
||||
for (Button button : this.buttons) {
|
||||
if (button.contains(x, y)) {
|
||||
return button.onButtonPress(mouseButton == 1);
|
||||
}
|
||||
}
|
||||
for (GuiRecipeTab tab : tabs) {
|
||||
|
||||
for (GuiRecipeTab tab : this.tabs) {
|
||||
if (tab.contains(x, y)) {
|
||||
return tab.onButtonPress(mouseButton == 1);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean mouseScrolled(int i) {
|
||||
Point mousePosition = getMousePosition();
|
||||
protected boolean mouseScrolled(int scroll) {
|
||||
|
||||
// Switch between recipe handlers if the cursor is over the tabbar.
|
||||
if (NEIClientConfig.areJEIStyleTabsVisible() && area.contains(mousePosition)) {
|
||||
if (i < 0) guiRecipe.nextType();
|
||||
else guiRecipe.prevType();
|
||||
|
||||
if (NEIClientConfig.areJEIStyleTabsVisible() && this.area.contains(GuiDraw.getMousePosition())) {
|
||||
setRecipePage(this.recipetype - scroll);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user