Make colored crafting monitor elements selectable.

This commit is contained in:
raoulvdberge
2018-06-06 22:19:28 +02:00
parent 17c36263ba
commit f67424d4b1
11 changed files with 64 additions and 130 deletions

View File

@@ -12,17 +12,13 @@ import javax.annotation.Nullable;
*/ */
public interface ICraftingMonitorElement { public interface ICraftingMonitorElement {
/** /**
* @param x position on the x axis to render * @param x position on the x axis to render
* @param y position on the y axis to render * @param y position on the y axis to render
* @param drawers the drawers that this element can use * @param drawers the drawers that this element can use
* @param selected whether the element is selected
*/ */
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
void draw(int x, int y, IElementDrawers drawers); void draw(int x, int y, IElementDrawers drawers, boolean selected);
/**
* @return whether the crafting monitor can draw a selection background behind the element when selected
*/
boolean canDrawSelection();
/** /**
* Returns the position of the corresponding task in the crafting task list. * Returns the position of the corresponding task in the crafting task list.

View File

@@ -30,7 +30,7 @@ public interface IElementDrawers {
} }
/** /**
* @return an overlay drawer, colour will be the element * @return an overlay drawer, color will be the element
*/ */
default IElementDrawer<Integer> getOverlayDrawer() { default IElementDrawer<Integer> getOverlayDrawer() {
return getNullDrawer(); return getNullDrawer();

View File

@@ -7,27 +7,37 @@ import net.minecraftforge.fml.common.network.ByteBufUtils;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class CraftingMonitorElementError implements ICraftingMonitorElement { public class CraftingMonitorElementColor implements ICraftingMonitorElement {
public static final String ID = "error"; public static final int COLOR_INFO = 0xFFD9EDF7;
public static final int COLOR_ERROR = 0xFFF2DEDE;
public static final int COLOR_SUCCESS = 0XFFADDBC6;
public static final String ID = "color";
private ICraftingMonitorElement base; private ICraftingMonitorElement base;
private String tooltip; private String tooltip;
private int color;
private int darkenedColor;
public CraftingMonitorElementError(ICraftingMonitorElement base, @Nullable String tooltip) { public CraftingMonitorElementColor(ICraftingMonitorElement base, @Nullable String tooltip, int color) {
this.base = base; this.base = base;
this.tooltip = tooltip; this.tooltip = tooltip;
this.color = color;
float ratio = 1.0F - 0.1F;
int a = (color >> 24) & 0xFF;
int r = (int) (((color >> 16) & 0xFF) * ratio);
int g = (int) (((color >> 8) & 0xFF) * ratio);
int b = (int) ((color & 0xFF) * ratio);
this.darkenedColor = (a << 24) | (r << 16) | (g << 8) | b;
} }
@Override @Override
public void draw(int x, int y, IElementDrawers drawers) { public void draw(int x, int y, IElementDrawers drawers, boolean selected) {
drawers.getOverlayDrawer().draw(x, y, 0xFFF2DEDE); drawers.getOverlayDrawer().draw(x, y, selected ? darkenedColor : color);
base.draw(x, y, drawers); base.draw(x, y, drawers, false);
}
@Override
public boolean canDrawSelection() {
return false;
} }
@Override @Override
@@ -48,6 +58,7 @@ public class CraftingMonitorElementError implements ICraftingMonitorElement {
@Override @Override
public void write(ByteBuf buf) { public void write(ByteBuf buf) {
buf.writeInt(color);
ByteBufUtils.writeUTF8String(buf, base.getId()); ByteBufUtils.writeUTF8String(buf, base.getId());
ByteBufUtils.writeUTF8String(buf, tooltip); ByteBufUtils.writeUTF8String(buf, tooltip);
@@ -56,11 +67,11 @@ public class CraftingMonitorElementError implements ICraftingMonitorElement {
@Override @Override
public boolean merge(ICraftingMonitorElement element) { public boolean merge(ICraftingMonitorElement element) {
return element.getId().equals(getId()) && elementHashCode() == element.elementHashCode() && base.merge(((CraftingMonitorElementError) element).base); return element.getId().equals(getId()) && elementHashCode() == element.elementHashCode() && base.merge(((CraftingMonitorElementColor) element).base);
} }
@Override @Override
public int elementHashCode() { public int elementHashCode() {
return base.elementHashCode() ^ tooltip.hashCode(); return base.elementHashCode() ^ tooltip.hashCode() ^ color;
} }
} }

View File

@@ -26,7 +26,11 @@ public class CraftingMonitorElementFluidRender implements ICraftingMonitorElemen
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void draw(int x, int y, IElementDrawers drawers) { public void draw(int x, int y, IElementDrawers drawers, boolean selected) {
if (selected) {
drawers.getOverlayDrawer().draw(x, y, 0xFFCCCCCC);
}
drawers.getFluidDrawer().draw(x + 2 + offset, y + 1, stack); drawers.getFluidDrawer().draw(x + 2 + offset, y + 1, stack);
float scale = drawers.getFontRenderer().getUnicodeFlag() ? 1F : 0.5F; float scale = drawers.getFontRenderer().getUnicodeFlag() ? 1F : 0.5F;
@@ -39,11 +43,6 @@ public class CraftingMonitorElementFluidRender implements ICraftingMonitorElemen
GlStateManager.popMatrix(); GlStateManager.popMatrix();
} }
@Override
public boolean canDrawSelection() {
return true;
}
@Override @Override
public int getTaskId() { public int getTaskId() {
return taskId; return taskId;

View File

@@ -1,66 +0,0 @@
package com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor;
import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
import com.raoulvdberge.refinedstorage.api.render.IElementDrawers;
import io.netty.buffer.ByteBuf;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import javax.annotation.Nullable;
public class CraftingMonitorElementInfo implements ICraftingMonitorElement {
public static final String ID = "info";
private ICraftingMonitorElement base;
private String tooltip;
public CraftingMonitorElementInfo(ICraftingMonitorElement base, @Nullable String tooltip) {
this.base = base;
this.tooltip = tooltip;
}
@Override
public void draw(int x, int y, IElementDrawers drawers) {
drawers.getOverlayDrawer().draw(x, y, 0xFFD9EDF7);
base.draw(x, y, drawers);
}
@Override
public boolean canDrawSelection() {
return false;
}
@Override
public int getTaskId() {
return base.getTaskId();
}
@Override
public String getId() {
return ID;
}
@Override
@Nullable
public String getTooltip() {
return tooltip;
}
@Override
public void write(ByteBuf buf) {
ByteBufUtils.writeUTF8String(buf, base.getId());
ByteBufUtils.writeUTF8String(buf, tooltip);
base.write(buf);
}
@Override
public boolean merge(ICraftingMonitorElement element) {
return element.getId().equals(getId()) && elementHashCode() == element.elementHashCode() && base.merge(((CraftingMonitorElementInfo) element).base);
}
@Override
public int elementHashCode() {
return base.elementHashCode() ^ tooltip.hashCode();
}
}

View File

@@ -28,7 +28,11 @@ public class CraftingMonitorElementItemRender implements ICraftingMonitorElement
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void draw(int x, int y, IElementDrawers drawers) { public void draw(int x, int y, IElementDrawers drawers, boolean selected) {
if (selected) {
drawers.getOverlayDrawer().draw(x, y, 0xFFCCCCCC);
}
drawers.getItemDrawer().draw(x + 2 + offset, y + 1, stack); drawers.getItemDrawer().draw(x + 2 + offset, y + 1, stack);
float scale = drawers.getFontRenderer().getUnicodeFlag() ? 1F : 0.5F; float scale = drawers.getFontRenderer().getUnicodeFlag() ? 1F : 0.5F;
@@ -41,11 +45,6 @@ public class CraftingMonitorElementItemRender implements ICraftingMonitorElement
GlStateManager.popMatrix(); GlStateManager.popMatrix();
} }
@Override
public boolean canDrawSelection() {
return true;
}
@Override @Override
public int getTaskId() { public int getTaskId() {
return taskId; return taskId;

View File

@@ -31,7 +31,11 @@ public class CraftingMonitorElementText implements ICraftingMonitorElement {
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void draw(int x, int y, IElementDrawers drawers) { public void draw(int x, int y, IElementDrawers drawers, boolean selected) {
if (selected) {
drawers.getOverlayDrawer().draw(x, y, 0xFFCCCCCC);
}
float scale = drawers.getFontRenderer().getUnicodeFlag() ? 1F : 0.5F; float scale = drawers.getFontRenderer().getUnicodeFlag() ? 1F : 0.5F;
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();
@@ -42,11 +46,6 @@ public class CraftingMonitorElementText implements ICraftingMonitorElement {
GlStateManager.popMatrix(); GlStateManager.popMatrix();
} }
@Override
public boolean canDrawSelection() {
return true;
}
@Override @Override
public int getTaskId() { public int getTaskId() {
return -1; return -1;

View File

@@ -9,8 +9,7 @@ import com.raoulvdberge.refinedstorage.api.network.INetwork;
import com.raoulvdberge.refinedstorage.api.util.IComparer; import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.api.util.IStackList; import com.raoulvdberge.refinedstorage.api.util.IStackList;
import com.raoulvdberge.refinedstorage.apiimpl.API; import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementError; import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementColor;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementInfo;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementItemRender; import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementItemRender;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementText; import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementText;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementItemStack; import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementItemStack;
@@ -240,12 +239,12 @@ public class CraftingTask implements ICraftingTask {
if (!missing.isEmpty()) { if (!missing.isEmpty()) {
elements.directAdd(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.items_missing", 16)); elements.directAdd(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.items_missing", 16));
missing.getStacks().stream().map(stack -> new CraftingMonitorElementError(new CraftingMonitorElementItemRender( missing.getStacks().stream().map(stack -> new CraftingMonitorElementColor(new CraftingMonitorElementItemRender(
-1, -1,
stack, stack,
stack.getCount(), stack.getCount(),
32 32
), "")).forEach(elements::add); ), "", CraftingMonitorElementColor.COLOR_ERROR)).forEach(elements::add);
elements.commit(); elements.commit();
} }
@@ -262,7 +261,7 @@ public class CraftingTask implements ICraftingTask {
); );
if (item.getStatus() == CraftingInserterItemStatus.FULL) { if (item.getStatus() == CraftingInserterItemStatus.FULL) {
element = new CraftingMonitorElementError(element, "gui.refinedstorage:crafting_monitor.network_full"); element = new CraftingMonitorElementColor(element, "gui.refinedstorage:crafting_monitor.network_full", CraftingMonitorElementColor.COLOR_ERROR);
} }
elements.add(element); elements.add(element);
@@ -290,7 +289,7 @@ public class CraftingTask implements ICraftingTask {
); );
if (status == CraftingExtractorItemStatus.MISSING) { if (status == CraftingExtractorItemStatus.MISSING) {
element = new CraftingMonitorElementInfo(element, "gui.refinedstorage:crafting_monitor.waiting_for_items"); element = new CraftingMonitorElementColor(element, "gui.refinedstorage:crafting_monitor.waiting_for_items", CraftingMonitorElementColor.COLOR_INFO);
} }
elements.add(element); elements.add(element);
@@ -320,11 +319,13 @@ public class CraftingTask implements ICraftingTask {
); );
if (status == CraftingExtractorItemStatus.MISSING) { if (status == CraftingExtractorItemStatus.MISSING) {
element = new CraftingMonitorElementInfo(element, "gui.refinedstorage:crafting_monitor.waiting_for_items"); element = new CraftingMonitorElementColor(element, "gui.refinedstorage:crafting_monitor.waiting_for_items", CraftingMonitorElementColor.COLOR_INFO);
} else if (status == CraftingExtractorItemStatus.MACHINE_DOES_NOT_ACCEPT) { } else if (status == CraftingExtractorItemStatus.MACHINE_DOES_NOT_ACCEPT) {
element = new CraftingMonitorElementError(element, "gui.refinedstorage:crafting_monitor.machine_does_not_accept"); element = new CraftingMonitorElementColor(element, "gui.refinedstorage:crafting_monitor.machine_does_not_accept", CraftingMonitorElementColor.COLOR_ERROR);
} else if (status == CraftingExtractorItemStatus.MACHINE_NONE) { } else if (status == CraftingExtractorItemStatus.MACHINE_NONE) {
element = new CraftingMonitorElementError(element, "gui.refinedstorage:crafting_monitor.machine_none"); element = new CraftingMonitorElementColor(element, "gui.refinedstorage:crafting_monitor.machine_none", CraftingMonitorElementColor.COLOR_ERROR);
} else if (status == CraftingExtractorItemStatus.EXTRACTED) {
element = new CraftingMonitorElementColor(element, "gui.refinedstorage:crafting_monitor.item_inserted_into_machine", CraftingMonitorElementColor.COLOR_SUCCESS);
} }
elements.add(element); elements.add(element);

View File

@@ -138,10 +138,6 @@ public class GuiCraftingMonitor extends GuiBase implements IResizableDisplay {
} }
drawTexture(x, yy, 0, getTopHeight() + (18 * 3), screenWidth, getBottomHeight()); drawTexture(x, yy, 0, getTopHeight() + (18 * 3), screenWidth, getBottomHeight());
if (itemSelectedX != -1 && itemSelectedY != -1 && itemSelected >= 0 && itemSelected < getElements().size() && getElements().get(itemSelected).canDrawSelection()) {
drawRect(x + itemSelectedX, y + itemSelectedY, x + itemSelectedX + ITEM_WIDTH, y + itemSelectedY + ITEM_HEIGHT - 1, 0xFFCCCCCC);
}
} }
@Override @Override
@@ -173,7 +169,7 @@ public class GuiCraftingMonitor extends GuiBase implements IResizableDisplay {
itemSelectedTooltip = element.getTooltip(); itemSelectedTooltip = element.getTooltip();
} }
element.draw(x, y, drawers); element.draw(x, y, drawers, item == itemSelected);
y += ITEM_HEIGHT; y += ITEM_HEIGHT;
} }

View File

@@ -6,7 +6,10 @@ import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.RSBlocks; import com.raoulvdberge.refinedstorage.RSBlocks;
import com.raoulvdberge.refinedstorage.RSItems; import com.raoulvdberge.refinedstorage.RSItems;
import com.raoulvdberge.refinedstorage.apiimpl.API; import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.*; import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementColor;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementFluidRender;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementItemRender;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementText;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementError; import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementError;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementFluidStack; import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementFluidStack;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementItemStack; import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementItemStack;
@@ -88,17 +91,12 @@ public class ProxyCommon {
API.instance().getCraftingMonitorElementRegistry().add(CraftingMonitorElementItemRender.ID, buf -> new CraftingMonitorElementItemRender(buf.readInt(), ByteBufUtils.readItemStack(buf), buf.readInt(), buf.readInt())); API.instance().getCraftingMonitorElementRegistry().add(CraftingMonitorElementItemRender.ID, buf -> new CraftingMonitorElementItemRender(buf.readInt(), ByteBufUtils.readItemStack(buf), buf.readInt(), buf.readInt()));
API.instance().getCraftingMonitorElementRegistry().add(CraftingMonitorElementFluidRender.ID, buf -> new CraftingMonitorElementFluidRender(buf.readInt(), StackUtils.readFluidStack(buf).getRight(), buf.readInt())); API.instance().getCraftingMonitorElementRegistry().add(CraftingMonitorElementFluidRender.ID, buf -> new CraftingMonitorElementFluidRender(buf.readInt(), StackUtils.readFluidStack(buf).getRight(), buf.readInt()));
API.instance().getCraftingMonitorElementRegistry().add(CraftingMonitorElementText.ID, buf -> new CraftingMonitorElementText(ByteBufUtils.readUTF8String(buf), buf.readInt())); API.instance().getCraftingMonitorElementRegistry().add(CraftingMonitorElementText.ID, buf -> new CraftingMonitorElementText(ByteBufUtils.readUTF8String(buf), buf.readInt()));
API.instance().getCraftingMonitorElementRegistry().add(CraftingMonitorElementError.ID, buf -> { API.instance().getCraftingMonitorElementRegistry().add(CraftingMonitorElementColor.ID, buf -> {
int color = buf.readInt();
String id = ByteBufUtils.readUTF8String(buf); String id = ByteBufUtils.readUTF8String(buf);
String tooltip = ByteBufUtils.readUTF8String(buf); String tooltip = ByteBufUtils.readUTF8String(buf);
return new CraftingMonitorElementError(API.instance().getCraftingMonitorElementRegistry().get(id).apply(buf), tooltip); return new CraftingMonitorElementColor(API.instance().getCraftingMonitorElementRegistry().get(id).apply(buf), tooltip, color);
});
API.instance().getCraftingMonitorElementRegistry().add(CraftingMonitorElementInfo.ID, buf -> {
String id = ByteBufUtils.readUTF8String(buf);
String tooltip = ByteBufUtils.readUTF8String(buf);
return new CraftingMonitorElementInfo(API.instance().getCraftingMonitorElementRegistry().get(id).apply(buf), tooltip);
}); });
API.instance().getCraftingPreviewElementRegistry().add(CraftingPreviewElementItemStack.ID, CraftingPreviewElementItemStack::fromByteBuf); API.instance().getCraftingPreviewElementRegistry().add(CraftingPreviewElementItemStack.ID, CraftingPreviewElementItemStack::fromByteBuf);

View File

@@ -34,6 +34,7 @@ gui.refinedstorage:crafting_monitor.machine_does_not_accept=Machine doesn't acce
gui.refinedstorage:crafting_monitor.machine_none=No machine found gui.refinedstorage:crafting_monitor.machine_none=No machine found
gui.refinedstorage:crafting_monitor.waiting_for_items=Waiting for items gui.refinedstorage:crafting_monitor.waiting_for_items=Waiting for items
gui.refinedstorage:crafting_monitor.network_full=Network is full gui.refinedstorage:crafting_monitor.network_full=Network is full
gui.refinedstorage:crafting_monitor.item_inserted_into_machine=Item is inserted into machine, waiting for result
gui.refinedstorage:wireless_transmitter=Wireless Transmitter gui.refinedstorage:wireless_transmitter=Wireless Transmitter
gui.refinedstorage:wireless_transmitter.distance=%d block(s) gui.refinedstorage:wireless_transmitter.distance=%d block(s)
gui.refinedstorage:crafter=Crafter gui.refinedstorage:crafter=Crafter