Add "alternatives" button to item/fluid amount

This commit is contained in:
raoulvdberge
2019-11-11 16:43:41 +01:00
parent 0beb2491ee
commit dcefbf0a0a
16 changed files with 197 additions and 110 deletions

View File

@@ -2,8 +2,8 @@ package com.raoulvdberge.refinedstorage.container;
import net.minecraft.entity.player.PlayerEntity;
public class InputConfigurationContainer extends BaseContainer {
public InputConfigurationContainer(PlayerEntity player) {
public class AlternativesContainer extends BaseContainer {
public AlternativesContainer(PlayerEntity player) {
super(null, null, player, 0);
}
}

View File

@@ -171,12 +171,12 @@ public class GridContainer extends BaseContainer implements ICraftingGridListene
for (int i = 0; i < 9 * 2; ++i) {
int itemFilterSlotConfig = FilterSlot.FILTER_ALLOW_SIZE;
if (i < 9) {
itemFilterSlotConfig |= FilterSlot.FILTER_ALLOW_INPUT_CONFIGURATION;
itemFilterSlotConfig |= FilterSlot.FILTER_ALLOW_ALTERNATIVES;
}
int fluidFilterSlotConfig = FluidFilterSlot.FILTER_ALLOW_SIZE;
if (i < 9) {
fluidFilterSlotConfig |= FluidFilterSlot.FILTER_ALLOW_INPUT_CONFIGURATION;
fluidFilterSlotConfig |= FluidFilterSlot.FILTER_ALLOW_ALTERNATIVES;
}
addSlot(new FilterSlot(((GridNetworkNode) grid).getProcessingMatrix(), i, x, y, itemFilterSlotConfig).setEnableHandler(() -> ((GridNetworkNode) grid).isProcessingPattern() && ((GridNetworkNode) grid).getType() == IType.ITEMS));

View File

@@ -10,7 +10,7 @@ import javax.annotation.Nonnull;
public class FilterSlot extends BaseSlot {
public static final int FILTER_ALLOW_SIZE = 1;
public static final int FILTER_ALLOW_BLOCKS = 2;
public static final int FILTER_ALLOW_INPUT_CONFIGURATION = 4;
public static final int FILTER_ALLOW_ALTERNATIVES = 4;
private int flags;
@@ -54,7 +54,7 @@ public class FilterSlot extends BaseSlot {
return (flags & FILTER_ALLOW_BLOCKS) == FILTER_ALLOW_BLOCKS;
}
public boolean isInputConfigurationAllowed() {
return (flags & FILTER_ALLOW_INPUT_CONFIGURATION) == FILTER_ALLOW_INPUT_CONFIGURATION;
public boolean isAlternativesAllowed() {
return (flags & FILTER_ALLOW_ALTERNATIVES) == FILTER_ALLOW_ALTERNATIVES;
}
}

View File

@@ -10,7 +10,7 @@ import javax.annotation.Nonnull;
public class FluidFilterSlot extends BaseSlot {
public static final int FILTER_ALLOW_SIZE = 1;
public static final int FILTER_ALLOW_INPUT_CONFIGURATION = 2;
public static final int FILTER_ALLOW_ALTERNATIVES = 2;
private int flags;
private FluidInventory fluidInventory;
@@ -39,8 +39,8 @@ public class FluidFilterSlot extends BaseSlot {
return (flags & FILTER_ALLOW_SIZE) == FILTER_ALLOW_SIZE;
}
public boolean isInputConfigurationAllowed() {
return (flags & FILTER_ALLOW_INPUT_CONFIGURATION) == FILTER_ALLOW_INPUT_CONFIGURATION;
public boolean isAlternativesAllowed() {
return (flags & FILTER_ALLOW_ALTERNATIVES) == FILTER_ALLOW_ALTERNATIVES;
}
public FluidInventory getFluidInventory() {

View File

@@ -1,70 +0,0 @@
package com.raoulvdberge.refinedstorage.screen;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.container.AmountContainer;
import com.raoulvdberge.refinedstorage.network.SetFilterSlotMessage;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.items.ItemHandlerHelper;
public class AmountScreen extends AmountSpecifyingScreen<AmountContainer> {
private int containerSlot;
private ItemStack stack;
private int maxAmount;
public AmountScreen(BaseScreen parent, PlayerEntity player, int containerSlot, ItemStack stack, int maxAmount) {
super(parent, new AmountContainer(player, stack), 172, 99, player.inventory, new TranslationTextComponent("gui.refinedstorage.item_amount"));
this.containerSlot = containerSlot;
this.stack = stack;
this.maxAmount = maxAmount;
}
@Override
protected int getDefaultAmount() {
return stack.getCount();
}
@Override
protected boolean canAmountGoNegative() {
return false;
}
@Override
protected int getMaxAmount() {
return maxAmount;
}
@Override
protected String getOkButtonText() {
return I18n.format("misc.refinedstorage.set");
}
@Override
protected String getTexture() {
return "gui/crafting_settings.png";
}
@Override
protected int[] getIncrements() {
return new int[]{
1, 10, 64,
-1, -10, -64
};
}
@Override
protected void onOkButtonPressed(boolean shiftDown) {
try {
int amount = Integer.parseInt(amountField.getText());
RS.NETWORK_HANDLER.sendToServer(new SetFilterSlotMessage(containerSlot, ItemHandlerHelper.copyStackWithSize(stack, amount)));
close();
} catch (NumberFormatException e) {
// NO OP
}
}
}

View File

@@ -15,6 +15,7 @@ public abstract class AmountSpecifyingScreen<T extends Container> extends BaseSc
protected TextFieldWidget amountField;
protected Button okButton;
protected Button cancelButton;
public AmountSpecifyingScreen(BaseScreen parent, T container, int width, int height, PlayerInventory playerInventory, ITextComponent title) {
super(container, width, height, playerInventory, title);
@@ -42,12 +43,16 @@ public abstract class AmountSpecifyingScreen<T extends Container> extends BaseSc
return Pair.of(114, 33);
}
protected int getOkCancelButtonWidth() {
return 50;
}
@Override
public void onPostInit(int x, int y) {
Pair<Integer, Integer> pos = getOkCancelPos();
okButton = addButton(x + pos.getLeft(), y + pos.getRight(), 50, 20, getOkButtonText(), true, true, btn -> onOkButtonPressed(hasShiftDown()));
addButton(x + pos.getLeft(), y + pos.getRight() + 24, 50, 20, I18n.format("gui.cancel"), true, true, btn -> close());
okButton = addButton(x + pos.getLeft(), y + pos.getRight(), getOkCancelButtonWidth(), 20, getOkButtonText(), true, true, btn -> onOkButtonPressed(hasShiftDown()));
cancelButton = addButton(x + pos.getLeft(), y + pos.getRight() + 24, getOkCancelButtonWidth(), 20, I18n.format("gui.cancel"), true, true, btn -> close());
amountField = new TextFieldWidget(font, x + getAmountPos().getLeft(), y + getAmountPos().getRight(), 69 - 6, font.FONT_HEIGHT, "");
amountField.setEnableBackgroundDrawing(false);

View File

@@ -7,7 +7,7 @@ import com.raoulvdberge.refinedstorage.container.slot.filter.FilterSlot;
import com.raoulvdberge.refinedstorage.container.slot.filter.FluidFilterSlot;
import com.raoulvdberge.refinedstorage.integration.craftingtweaks.CraftingTweaksIntegration;
import com.raoulvdberge.refinedstorage.render.FluidRenderer;
import com.raoulvdberge.refinedstorage.screen.grid.InputConfigurationScreen;
import com.raoulvdberge.refinedstorage.screen.grid.AlternativesScreen;
import com.raoulvdberge.refinedstorage.screen.widget.CheckBoxWidget;
import com.raoulvdberge.refinedstorage.screen.widget.sidebutton.SideButton;
import com.raoulvdberge.refinedstorage.util.RenderUtils;
@@ -176,21 +176,28 @@ public abstract class BaseScreen<T extends Container> extends ContainerScreen<T>
if (valid && slot instanceof FilterSlot && slot.isEnabled() && ((FilterSlot) slot).isSizeAllowed()) {
if (!slot.getStack().isEmpty()) {
if (((FilterSlot) slot).isInputConfigurationAllowed() && hasControlDown()) {
minecraft.displayGuiScreen(new InputConfigurationScreen(
if (((FilterSlot) slot).isAlternativesAllowed() && hasControlDown()) {
minecraft.displayGuiScreen(new AlternativesScreen(
this,
minecraft.player,
new TranslationTextComponent("gui.refinedstorage.input_configuration"),
new TranslationTextComponent("gui.refinedstorage.alternatives"),
slot.getStack(),
slot.getSlotIndex()
));
} else {
minecraft.displayGuiScreen(new AmountScreen(
minecraft.displayGuiScreen(new ItemAmountScreen(
this,
minecraft.player,
slot.slotNumber,
slot.getStack(),
slot.getSlotStackLimit()
slot.getSlotStackLimit(),
parent -> new AlternativesScreen(
parent,
minecraft.player,
new TranslationTextComponent("gui.refinedstorage.alternatives"),
slot.getStack(),
slot.getSlotIndex()
)
));
}
}
@@ -198,11 +205,11 @@ public abstract class BaseScreen<T extends Container> extends ContainerScreen<T>
FluidStack stack = ((FluidFilterSlot) slot).getFluidInventory().getFluid(slot.getSlotIndex());
if (!stack.isEmpty()) {
if (((FluidFilterSlot) slot).isInputConfigurationAllowed() && hasControlDown()) {
minecraft.displayGuiScreen(new InputConfigurationScreen(
if (((FluidFilterSlot) slot).isAlternativesAllowed() && hasControlDown()) {
minecraft.displayGuiScreen(new AlternativesScreen(
this,
minecraft.player,
new TranslationTextComponent("gui.refinedstorage.input_configuration"),
new TranslationTextComponent("gui.refinedstorage.alternatives"),
stack,
slot.getSlotIndex()
));
@@ -212,7 +219,14 @@ public abstract class BaseScreen<T extends Container> extends ContainerScreen<T>
minecraft.player,
slot.slotNumber,
stack,
((FluidFilterSlot) slot).getFluidInventory().getMaxAmount()
((FluidFilterSlot) slot).getFluidInventory().getMaxAmount(),
parent -> new AlternativesScreen(
this,
minecraft.player,
new TranslationTextComponent("gui.refinedstorage.alternatives"),
stack,
slot.getSlotIndex()
)
));
}
} else {

View File

@@ -4,22 +4,56 @@ import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.container.FluidAmountContainer;
import com.raoulvdberge.refinedstorage.network.SetFluidFilterSlotMessage;
import com.raoulvdberge.refinedstorage.util.StackUtils;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.fluids.FluidStack;
import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nullable;
import java.util.function.Function;
// TODO here too
public class FluidAmountScreen extends AmountSpecifyingScreen<FluidAmountContainer> {
private int containerSlot;
private FluidStack stack;
private int maxAmount;
@Nullable
private Function<Screen, Screen> alternativesScreenFactory;
public FluidAmountScreen(BaseScreen parent, PlayerEntity player, int containerSlot, FluidStack stack, int maxAmount) {
super(parent, new FluidAmountContainer(player, stack), 172, 99, player.inventory, new TranslationTextComponent("gui.refinedstorage.fluid_amount"));
public FluidAmountScreen(BaseScreen parent, PlayerEntity player, int containerSlot, FluidStack stack, int maxAmount, @Nullable Function<Screen, Screen> alternativesScreenFactory) {
super(parent, new FluidAmountContainer(player, stack), alternativesScreenFactory != null ? 194 : 172, 99, player.inventory, new TranslationTextComponent("gui.refinedstorage.fluid_amount"));
this.containerSlot = containerSlot;
this.stack = stack;
this.maxAmount = maxAmount;
this.alternativesScreenFactory = alternativesScreenFactory;
}
@Override
protected int getOkCancelButtonWidth() {
return alternativesScreenFactory != null ? 75 : super.getOkCancelButtonWidth();
}
@Override
public void onPostInit(int x, int y) {
super.onPostInit(x, y);
if (alternativesScreenFactory != null) {
addButton(x + 114, cancelButton.y + 24, getOkCancelButtonWidth(), 20, I18n.format("gui.refinedstorage.alternatives"), true, true, btn -> {
minecraft.displayGuiScreen(alternativesScreenFactory.apply(this));
});
}
}
@Override
protected Pair<Integer, Integer> getOkCancelPos() {
if (alternativesScreenFactory == null) {
return super.getOkCancelPos();
}
return Pair.of(114, 22);
}
@Override
@@ -44,7 +78,7 @@ public class FluidAmountScreen extends AmountSpecifyingScreen<FluidAmountContain
@Override
protected String getTexture() {
return "gui/crafting_settings.png";
return alternativesScreenFactory != null ? "gui/amount_specifying_wide.png" : "gui/amount_specifying.png";
}
@Override

View File

@@ -0,0 +1,103 @@
package com.raoulvdberge.refinedstorage.screen;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.container.AmountContainer;
import com.raoulvdberge.refinedstorage.network.SetFilterSlotMessage;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.items.ItemHandlerHelper;
import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nullable;
import java.util.function.Function;
public class ItemAmountScreen extends AmountSpecifyingScreen<AmountContainer> {
private int containerSlot;
private ItemStack stack;
private int maxAmount;
@Nullable
private Function<Screen, Screen> alternativesScreenFactory;
public ItemAmountScreen(BaseScreen parent, PlayerEntity player, int containerSlot, ItemStack stack, int maxAmount, @Nullable Function<Screen, Screen> alternativesScreenFactory) {
super(parent, new AmountContainer(player, stack), alternativesScreenFactory != null ? 194 : 172, 99, player.inventory, new TranslationTextComponent("gui.refinedstorage.item_amount"));
this.containerSlot = containerSlot;
this.stack = stack;
this.maxAmount = maxAmount;
this.alternativesScreenFactory = alternativesScreenFactory;
}
@Override
protected int getOkCancelButtonWidth() {
return alternativesScreenFactory != null ? 75 : super.getOkCancelButtonWidth();
}
@Override
public void onPostInit(int x, int y) {
super.onPostInit(x, y);
if (alternativesScreenFactory != null) {
addButton(x + 114, cancelButton.y + 24, getOkCancelButtonWidth(), 20, I18n.format("gui.refinedstorage.alternatives"), true, true, btn -> {
minecraft.displayGuiScreen(alternativesScreenFactory.apply(this));
});
}
}
@Override
protected Pair<Integer, Integer> getOkCancelPos() {
if (alternativesScreenFactory == null) {
return super.getOkCancelPos();
}
return Pair.of(114, 22);
}
@Override
protected int getDefaultAmount() {
return stack.getCount();
}
@Override
protected boolean canAmountGoNegative() {
return false;
}
@Override
protected int getMaxAmount() {
return maxAmount;
}
@Override
protected String getOkButtonText() {
return I18n.format("misc.refinedstorage.set");
}
@Override
protected String getTexture() {
return alternativesScreenFactory != null ? "gui/amount_specifying_wide.png" : "gui/amount_specifying.png";
}
@Override
protected int[] getIncrements() {
return new int[]{
1, 10, 64,
-1, -10, -64
};
}
@Override
protected void onOkButtonPressed(boolean shiftDown) {
try {
int amount = Integer.parseInt(amountField.getText());
RS.NETWORK_HANDLER.sendToServer(new SetFilterSlotMessage(containerSlot, ItemHandlerHelper.copyStackWithSize(stack, amount)));
close();
} catch (NumberFormatException e) {
// NO OP
}
}
}

View File

@@ -1,7 +1,7 @@
package com.raoulvdberge.refinedstorage.screen.grid;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.container.InputConfigurationContainer;
import com.raoulvdberge.refinedstorage.container.AlternativesContainer;
import com.raoulvdberge.refinedstorage.render.FluidRenderer;
import com.raoulvdberge.refinedstorage.screen.BaseScreen;
import com.raoulvdberge.refinedstorage.screen.widget.CheckBoxWidget;
@@ -31,7 +31,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class InputConfigurationScreen extends BaseScreen {
public class AlternativesScreen extends BaseScreen {
private final Screen parent;
private final ScrollbarWidget scrollbar;
@@ -42,14 +42,14 @@ public class InputConfigurationScreen extends BaseScreen {
private ItemStack item;
private FluidStack fluid;
private InputConfigurationScreen(Screen parent, PlayerEntity player, ITextComponent title) {
super(new InputConfigurationContainer(player), 175, 143, null, title);
private AlternativesScreen(Screen parent, PlayerEntity player, ITextComponent title) {
super(new AlternativesContainer(player), 175, 143, null, title);
this.parent = parent;
this.scrollbar = new ScrollbarWidget(this, 155, 20, 12, 89);
}
public InputConfigurationScreen(Screen parent, PlayerEntity player, ITextComponent title, ItemStack item, int slot) {
public AlternativesScreen(Screen parent, PlayerEntity player, ITextComponent title, ItemStack item, int slot) {
this(parent, player, title);
this.type = IType.ITEMS;
@@ -58,7 +58,7 @@ public class InputConfigurationScreen extends BaseScreen {
this.fluid = null;
}
public InputConfigurationScreen(Screen parent, PlayerEntity player, ITextComponent title, FluidStack fluid, int slot) {
public AlternativesScreen(Screen parent, PlayerEntity player, ITextComponent title, FluidStack fluid, int slot) {
this(parent, player, title);
this.type = IType.FLUIDS;
@@ -69,9 +69,6 @@ public class InputConfigurationScreen extends BaseScreen {
@Override
public void onPostInit(int x, int y) {
Button apply = addButton(x + 7, y + 114, 50, 20, I18n.format("gui.refinedstorage.input_configuration.apply"), true, true, btn -> apply());
addButton(x + apply.getWidth() + 7 + 4, y + 114, 50, 20, I18n.format("gui.cancel"), true, true, btn -> close());
lines.clear();
if (item != null) {
@@ -135,6 +132,9 @@ public class InputConfigurationScreen extends BaseScreen {
yy += 18;
}
}
Button apply = addButton(x + 7, y + 114, 50, 20, I18n.format("gui.refinedstorage.alternatives.apply"), lines.size() > 1, true, btn -> apply());
addButton(x + apply.getWidth() + 7 + 4, y + 114, 50, 20, I18n.format("gui.cancel"), true, true, btn -> close());
}
@Override
@@ -153,7 +153,7 @@ public class InputConfigurationScreen extends BaseScreen {
@Override
public void renderBackground(int x, int y, int mouseX, int mouseY) {
bindTexture(RS.ID, "gui/input_configuration.png");
bindTexture(RS.ID, "gui/alternatives.png");
blit(x, y, 0, 0, xSize, ySize);
@@ -345,7 +345,7 @@ public class InputConfigurationScreen extends BaseScreen {
public void renderTooltip(int x, int y, int mx, int my) {
for (ItemStack item : items) {
if (RenderUtils.inBounds(x + 3, y, 16, 16, mx, my)) {
InputConfigurationScreen.this.renderTooltip(item, mx, my, RenderUtils.getTooltipFromItem(item));
AlternativesScreen.this.renderTooltip(item, mx, my, RenderUtils.getTooltipFromItem(item));
}
x += 17;
@@ -375,7 +375,7 @@ public class InputConfigurationScreen extends BaseScreen {
public void renderTooltip(int x, int y, int mx, int my) {
for (FluidStack fluid : fluids) {
if (RenderUtils.inBounds(x + 3, y, 16, 16, mx, my)) {
InputConfigurationScreen.this.renderTooltip(mx, my, fluid.getDisplayName().getFormattedText());
AlternativesScreen.this.renderTooltip(mx, my, fluid.getDisplayName().getFormattedText());
}
x += 17;

View File

@@ -28,7 +28,7 @@ public class CraftingSettingsScreen extends AmountSpecifyingScreen<CraftingSetti
@Override
protected String getTexture() {
return "gui/crafting_settings.png";
return "gui/amount_specifying.png";
}
@Override

View File

@@ -84,8 +84,8 @@
"gui.refinedstorage.security_manager.permission.5.tooltip": "Ability to change security options",
"gui.refinedstorage.storage_monitor": "Storage Monitor",
"gui.refinedstorage.crafter_manager": "Crafter Manager",
"gui.refinedstorage.input_configuration": "Input configuration",
"gui.refinedstorage.input_configuration.apply": "Apply",
"gui.refinedstorage.alternatives": "Alternatives",
"gui.refinedstorage.alternatives.apply": "Apply",
"misc.refinedstorage.energy_stored": "%d / %d FE",
"misc.refinedstorage.energy_usage": "Usage: %d FE/t",
"misc.refinedstorage.energy_usage_minimal": "%d FE/t",

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB