Improve drawer system.
This commit is contained in:
@@ -1,14 +1,10 @@
|
||||
package com.refinedmods.refinedstorage.api.render;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.refinedmods.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
||||
import com.refinedmods.refinedstorage.api.autocrafting.preview.ICraftingPreviewElement;
|
||||
|
||||
/**
|
||||
* This {@link FunctionalInterface} is used to define a draw/render function.
|
||||
* This function use x and y coords and the element to draw.
|
||||
* Usually packaged in a {@link IElementDrawers}.
|
||||
* Used in {@link ICraftingPreviewElement#draw(int, int, IElementDrawers)} and {@link ICraftingMonitorElement#draw(int, int, IElementDrawers)}.
|
||||
*
|
||||
* @param <T> the element to draw, usually {@link String}, {@link net.minecraft.item.ItemStack} or {@link net.minecraftforge.fluids.FluidStack}
|
||||
*/
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package com.refinedmods.refinedstorage.api.render;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
@@ -30,21 +29,16 @@ public interface IElementDrawers {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an overlay drawer, color will be the element
|
||||
* @return an overlay drawer
|
||||
*/
|
||||
default IElementDrawer<Integer> getOverlayDrawer() {
|
||||
return getNullDrawer();
|
||||
}
|
||||
|
||||
default IElementDrawer<?> getErrorDrawer() {
|
||||
default IElementDrawer<Void> getErrorDrawer() {
|
||||
return getNullDrawer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the font renderer
|
||||
*/
|
||||
FontRenderer getFontRenderer();
|
||||
|
||||
/**
|
||||
* DO NOT OVERRIDE!
|
||||
*
|
||||
|
@@ -6,32 +6,28 @@ import com.refinedmods.refinedstorage.api.render.IElementDrawer;
|
||||
import com.refinedmods.refinedstorage.container.CraftingMonitorContainer;
|
||||
import com.refinedmods.refinedstorage.screen.BaseScreen;
|
||||
import net.minecraft.client.gui.AbstractGui;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
|
||||
public class CraftingMonitorElementDrawers extends ElementDrawers {
|
||||
private int itemWidth;
|
||||
private int itemHeight;
|
||||
public class CraftingMonitorElementDrawers extends ElementDrawers<CraftingMonitorContainer> {
|
||||
private final IElementDrawer<Integer> overlayDrawer;
|
||||
private final IElementDrawer<Void> errorDrawer;
|
||||
|
||||
private final IElementDrawer<Integer> overlayDrawer = (matrixStack, x, y, color) -> {
|
||||
RenderSystem.color4f(1, 1, 1, 1);
|
||||
RenderSystem.disableLighting();
|
||||
public CraftingMonitorElementDrawers(BaseScreen<CraftingMonitorContainer> screen, int itemWidth, int itemHeight) {
|
||||
super(screen);
|
||||
|
||||
AbstractGui.fill(matrixStack, x, y, x + itemWidth, y + itemHeight, color);
|
||||
};
|
||||
this.overlayDrawer = (matrixStack, x, y, color) -> {
|
||||
RenderSystem.color4f(1, 1, 1, 1);
|
||||
RenderSystem.disableLighting();
|
||||
|
||||
private final IElementDrawer<?> errorDrawer = (matrixStack, x, y, nothing) -> {
|
||||
RenderSystem.color4f(1, 1, 1, 1);
|
||||
RenderSystem.disableLighting();
|
||||
AbstractGui.fill(matrixStack, x, y, x + itemWidth, y + itemHeight, color);
|
||||
};
|
||||
|
||||
screen.bindTexture(RS.ID, "gui/crafting_preview.png");
|
||||
screen.blit(matrixStack, x + itemWidth - 12 - 2, y + itemHeight - 12 - 2, 0, 244, 12, 12);
|
||||
};
|
||||
this.errorDrawer = (matrixStack, x, y, nothing) -> {
|
||||
RenderSystem.color4f(1, 1, 1, 1);
|
||||
RenderSystem.disableLighting();
|
||||
|
||||
public CraftingMonitorElementDrawers(BaseScreen<CraftingMonitorContainer> gui, FontRenderer fontRenderer, int itemWidth, int itemHeight) {
|
||||
super(gui, fontRenderer);
|
||||
|
||||
this.itemWidth = itemWidth;
|
||||
this.itemHeight = itemHeight;
|
||||
screen.bindTexture(RS.ID, "gui/crafting_preview.png");
|
||||
screen.blit(matrixStack, x + itemWidth - 12 - 2, y + itemHeight - 12 - 2, 0, 244, 12, 12);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,7 +36,7 @@ public class CraftingMonitorElementDrawers extends ElementDrawers {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IElementDrawer<?> getErrorDrawer() {
|
||||
public IElementDrawer<Void> getErrorDrawer() {
|
||||
return errorDrawer;
|
||||
}
|
||||
}
|
||||
|
@@ -4,9 +4,9 @@ import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.refinedmods.refinedstorage.api.render.IElementDrawer;
|
||||
import com.refinedmods.refinedstorage.screen.grid.CraftingPreviewScreen;
|
||||
import net.minecraft.client.gui.AbstractGui;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
|
||||
public class CraftingPreviewElementDrawers extends ElementDrawers {
|
||||
public class CraftingPreviewElementDrawers extends ElementDrawers<Container> {
|
||||
private final IElementDrawer<Integer> overlayDrawer = (matrixStack, x, y, color) -> {
|
||||
RenderSystem.color4f(1, 1, 1, 1);
|
||||
RenderSystem.disableLighting();
|
||||
@@ -14,8 +14,8 @@ public class CraftingPreviewElementDrawers extends ElementDrawers {
|
||||
AbstractGui.fill(matrixStack, x, y, x + 73, y + 29, color);
|
||||
};
|
||||
|
||||
public CraftingPreviewElementDrawers(CraftingPreviewScreen screen, FontRenderer fontRenderer) {
|
||||
super(screen, fontRenderer);
|
||||
public CraftingPreviewElementDrawers(CraftingPreviewScreen screen) {
|
||||
super(screen);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -4,17 +4,15 @@ import com.refinedmods.refinedstorage.api.render.IElementDrawer;
|
||||
import com.refinedmods.refinedstorage.api.render.IElementDrawers;
|
||||
import com.refinedmods.refinedstorage.render.FluidRenderer;
|
||||
import com.refinedmods.refinedstorage.screen.BaseScreen;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public class ElementDrawers implements IElementDrawers {
|
||||
protected final BaseScreen screen;
|
||||
private final FontRenderer fontRenderer;
|
||||
public class ElementDrawers<T extends Container> implements IElementDrawers {
|
||||
protected final BaseScreen<T> screen;
|
||||
|
||||
public ElementDrawers(BaseScreen screen, FontRenderer fontRenderer) {
|
||||
public ElementDrawers(BaseScreen<T> screen) {
|
||||
this.screen = screen;
|
||||
this.fontRenderer = fontRenderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -31,9 +29,4 @@ public class ElementDrawers implements IElementDrawers {
|
||||
public IElementDrawer<String> getStringDrawer() {
|
||||
return screen::renderString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FontRenderer getFontRenderer() {
|
||||
return fontRenderer;
|
||||
}
|
||||
}
|
||||
|
@@ -104,14 +104,14 @@ public class CraftingMonitorScreen extends BaseScreen<CraftingMonitorContainer>
|
||||
private List<IGridTab> tasks = Collections.emptyList();
|
||||
private final TabListWidget tabs;
|
||||
|
||||
private final IElementDrawers drawers = new CraftingMonitorElementDrawers(this, font, ITEM_WIDTH, ITEM_HEIGHT);
|
||||
private final IElementDrawers drawers = new CraftingMonitorElementDrawers(this, ITEM_WIDTH, ITEM_HEIGHT);
|
||||
|
||||
public CraftingMonitorScreen(CraftingMonitorContainer container, PlayerInventory inventory, ITextComponent title) {
|
||||
super(container, 254, 201, inventory, title);
|
||||
|
||||
this.craftingMonitor = container.getCraftingMonitor();
|
||||
|
||||
this.tabs = new TabListWidget(this, new ElementDrawers(this, font), () -> tasks, () -> (int) Math.floor((float) Math.max(0, tasks.size() - 1) / (float) ICraftingMonitor.TABS_PER_PAGE), craftingMonitor::getTabPage, () -> {
|
||||
this.tabs = new TabListWidget(this, new ElementDrawers<>(this), () -> tasks, () -> (int) Math.floor((float) Math.max(0, tasks.size() - 1) / (float) ICraftingMonitor.TABS_PER_PAGE), craftingMonitor::getTabPage, () -> {
|
||||
IGridTab tab = getCurrentTab();
|
||||
|
||||
if (tab == null) {
|
||||
|
@@ -50,7 +50,7 @@ public class CraftingPreviewScreen extends BaseScreen<Container> {
|
||||
private ItemStack hoveringStack;
|
||||
private FluidStack hoveringFluid;
|
||||
|
||||
private final IElementDrawers drawers = new CraftingPreviewElementDrawers(this, font);
|
||||
private final IElementDrawers drawers = new CraftingPreviewElementDrawers(this);
|
||||
|
||||
public CraftingPreviewScreen(Screen parent, List<ICraftingPreviewElement> elements, UUID id, int quantity, boolean fluids, ITextComponent title) {
|
||||
super(new Container(null, 0) {
|
||||
|
@@ -72,7 +72,7 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
|
||||
this.grid = grid;
|
||||
this.view = grid.getGridType() == GridType.FLUID ? new FluidGridView(this, getDefaultSorter(), getSorters()) : new ItemGridView(this, getDefaultSorter(), getSorters());
|
||||
this.wasConnected = this.grid.isGridActive();
|
||||
this.tabs = new TabListWidget(this, new ElementDrawers(this, font), grid::getTabs, grid::getTotalTabPages, grid::getTabPage, grid::getTabSelected, IGrid.TABS_PER_PAGE);
|
||||
this.tabs = new TabListWidget(this, new ElementDrawers<>(this), grid::getTabs, grid::getTotalTabPages, grid::getTabPage, grid::getTabSelected, IGrid.TABS_PER_PAGE);
|
||||
this.tabs.addListener(new TabListWidget.ITabListListener() {
|
||||
@Override
|
||||
public void onSelectionChanged(int tab) {
|
||||
|
Reference in New Issue
Block a user