Progress widget
This commit is contained in:
parent
1067aa0bd5
commit
d5a0c8acd2
@ -17,6 +17,7 @@ import ru.dbotthepony.mc.otm.menu.slot.MachineInputSlot;
|
||||
import ru.dbotthepony.mc.otm.menu.slot.MachineOutputSlot;
|
||||
import ru.dbotthepony.mc.otm.menu.widget.BatteryLevelWidget;
|
||||
import ru.dbotthepony.mc.otm.menu.widget.MatterLevelWidget;
|
||||
import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@ -26,35 +27,12 @@ public class MatterDecomposerMenu extends PoweredMatteryMenu {
|
||||
}
|
||||
|
||||
public MatterLevelWidget<PoweredMatteryMenu> matter_widget;
|
||||
|
||||
public ContainerData progress;
|
||||
public ProgressGaugeWidget<PoweredMatteryMenu> progress_widget;
|
||||
|
||||
public MatterDecomposerMenu(int containerID, Inventory inventory, @Nullable BlockEntityMatterDecomposer tile) {
|
||||
super(Registry.Menus.MATTER_DECOMPOSER, containerID, inventory, tile);
|
||||
Container container = tile != null ? tile.item_container : new SimpleContainer(2);
|
||||
|
||||
progress = new ContainerData() {
|
||||
int get_value;
|
||||
|
||||
@Override
|
||||
public int get(int i) {
|
||||
if (tile != null)
|
||||
return (int) (tile.getWorkProgress() * 100);
|
||||
|
||||
return get_value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int i, int i1) {
|
||||
get_value = i1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
// Вход
|
||||
addSlot(new MachineInputSlot(container, 0, 61, 36) {
|
||||
@Override
|
||||
@ -68,15 +46,14 @@ public class MatterDecomposerMenu extends PoweredMatteryMenu {
|
||||
|
||||
if (tile == null || tile.getCapability(MatteryCapability.MATTER).resolve().isEmpty()) {
|
||||
matter_widget = new MatterLevelWidget<>(this, 22, 14);
|
||||
progress_widget = new ProgressGaugeWidget<>(this, 61 + 18 + 3, 36);
|
||||
} else {
|
||||
matter_widget = new MatterLevelWidget<>(this, 22, 14, tile.getCapability(MatteryCapability.MATTER).resolve().get());
|
||||
progress_widget = new ProgressGaugeWidget<>(this, 61 + 18 + 3, 36, () -> (float) tile.getWorkProgress());
|
||||
}
|
||||
|
||||
addBatterySlot(14);
|
||||
|
||||
addInventorySlots();
|
||||
|
||||
this.addDataSlots(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,24 +2,17 @@ package ru.dbotthepony.mc.otm.menu.widget;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.FormattedText;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.inventory.ContainerData;
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
||||
import ru.dbotthepony.mc.otm.capability.IMatteryEnergyStorage;
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||
import ru.dbotthepony.mc.otm.menu.FormattingHelper;
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu;
|
||||
import ru.dbotthepony.mc.otm.menu.data.BigDecimalDataContainer;
|
||||
import ru.dbotthepony.mc.otm.screen.MatteryScreen;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class BatteryLevelWidget<T extends MatteryMenu> extends StorageVerticalGaugeWidget<T> {
|
||||
public class BatteryLevelWidget<T extends MatteryMenu> extends StorageGaugeWidget<T> {
|
||||
public BatteryLevelWidget(T menu, int x, int y, IMatteryEnergyStorage capability) {
|
||||
super(menu, x, y, capability::getBatteryLevel, capability::getMaxBatteryLevel);
|
||||
}
|
||||
|
@ -0,0 +1,69 @@
|
||||
package ru.dbotthepony.mc.otm.menu.widget;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu;
|
||||
import ru.dbotthepony.mc.otm.screen.MatteryScreen;
|
||||
|
||||
abstract public class GaugeWidget<T extends MatteryMenu> extends AbstractWidget<T> {
|
||||
public enum GaugeDirection {
|
||||
TOP_TO_BOTTOM,
|
||||
BOTTOM_TO_TOP,
|
||||
LEFT_TO_RIGHT,
|
||||
RIGHT_TO_LEFT
|
||||
}
|
||||
|
||||
public GaugeWidget(T menu, int x, int y) {
|
||||
super(menu, x, y);
|
||||
}
|
||||
|
||||
public GaugeDirection fill_order = GaugeDirection.BOTTOM_TO_TOP;
|
||||
|
||||
abstract public float getLevel();
|
||||
|
||||
@Override
|
||||
public void renderBackground(MatteryScreen<T> screen, PoseStack pose, int local_x, int local_y, int mouse_x, int mouse_y) {
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.setShaderTexture(0, TEXTURE);
|
||||
|
||||
screen.blit(pose, local_x + x, local_y + y, getImageX(), getImageY(), getImageWidth(), getImageHeight());
|
||||
float level = getLevel();
|
||||
|
||||
if (level > 0.01f) {
|
||||
|
||||
|
||||
if (fill_order == GaugeDirection.BOTTOM_TO_TOP) {
|
||||
int intHeight = (int) Math.floor(level * (float) getImageHeight() + 0.5f);
|
||||
|
||||
screen.blit(
|
||||
pose,
|
||||
local_x + x,
|
||||
local_y + y + getImageHeight() - intHeight,
|
||||
getImageX() + getImageWidth(),
|
||||
getImageY() + getImageHeight() - intHeight,
|
||||
getImageWidth(),
|
||||
intHeight);
|
||||
} else if (fill_order == GaugeDirection.TOP_TO_BOTTOM) {
|
||||
screen.blit(
|
||||
pose,
|
||||
local_x + x,
|
||||
local_y + y,
|
||||
getImageX() + getImageWidth(),
|
||||
getImageY(),
|
||||
getImageWidth(),
|
||||
(int) Math.floor(level * (float) getImageHeight() + 0.5f));
|
||||
} else if (fill_order == GaugeDirection.LEFT_TO_RIGHT) {
|
||||
screen.blit(
|
||||
pose,
|
||||
local_x + x,
|
||||
local_y + y,
|
||||
getImageX() + getImageWidth(),
|
||||
getImageY(),
|
||||
(int) Math.floor(level * (float) getImageWidth() + 0.5f),
|
||||
getImageHeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import ru.dbotthepony.mc.otm.capability.IMatterHandler;
|
||||
import ru.dbotthepony.mc.otm.capability.IMatteryEnergyStorage;
|
||||
import ru.dbotthepony.mc.otm.menu.FormattingHelper;
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu;
|
||||
import ru.dbotthepony.mc.otm.screen.MatteryScreen;
|
||||
@ -13,7 +12,7 @@ import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class MatterLevelWidget<T extends MatteryMenu> extends StorageVerticalGaugeWidget<T> {
|
||||
public class MatterLevelWidget<T extends MatteryMenu> extends StorageGaugeWidget<T> {
|
||||
public MatterLevelWidget(T menu, int x, int y, IMatterHandler capability) {
|
||||
super(menu, x, y, capability::getStoredMatter, capability::getMaxStoredMatter);
|
||||
}
|
||||
|
@ -0,0 +1,92 @@
|
||||
package ru.dbotthepony.mc.otm.menu.widget;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.inventory.ContainerData;
|
||||
import ru.dbotthepony.mc.otm.menu.FormattingHelper;
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu;
|
||||
import ru.dbotthepony.mc.otm.screen.MatteryScreen;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ProgressGaugeWidget<T extends MatteryMenu> extends GaugeWidget<T> {
|
||||
protected Supplier<Float> progress_supplier;
|
||||
|
||||
protected final ContainerData progress_container = new ContainerData() {
|
||||
private int value;
|
||||
|
||||
@Override
|
||||
public int get(int i) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int i, int i1) {
|
||||
value = i1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
public ProgressGaugeWidget(T menu, int x, int y) {
|
||||
super(menu, x, y);
|
||||
fill_order = GaugeDirection.LEFT_TO_RIGHT;
|
||||
addDataSlots(progress_container);
|
||||
}
|
||||
|
||||
public ProgressGaugeWidget(T menu, int x, int y, Supplier<Float> progress) {
|
||||
this(menu, x, y);
|
||||
progress_supplier = progress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getImageWidth() {
|
||||
return 22;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getImageHeight() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getImageX() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getImageY() {
|
||||
return 132;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateServer() {
|
||||
if (progress_supplier != null)
|
||||
progress_container.set(0, (int) (progress_supplier.get() * 10000f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderTooltip(MatteryScreen<T> screen, PoseStack pose, int local_x, int local_y, int mouse_x, int mouse_y) {
|
||||
if (is_hovered) {
|
||||
List<Component> text = List.of(
|
||||
new TranslatableComponent("otm.gui.progress_widget", String.format("%.2f", progress_container.get(0) / 100f))
|
||||
);
|
||||
|
||||
screen.renderComponentTooltip(pose, text, mouse_x, mouse_y);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLevel() {
|
||||
return progress_container.get(0) / 10000f;
|
||||
}
|
||||
}
|
@ -1,26 +1,24 @@
|
||||
package ru.dbotthepony.mc.otm.menu.widget;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu;
|
||||
import ru.dbotthepony.mc.otm.menu.data.BigDecimalDataContainer;
|
||||
import ru.dbotthepony.mc.otm.screen.MatteryScreen;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
abstract public class StorageVerticalGaugeWidget<T extends MatteryMenu> extends VerticalGaugeWidget<T> {
|
||||
abstract public class StorageGaugeWidget<T extends MatteryMenu> extends GaugeWidget<T> {
|
||||
protected Supplier<BigDecimal> value_supplier;
|
||||
protected Supplier<BigDecimal> max_value_supplier;
|
||||
|
||||
protected final BigDecimalDataContainer value_container = new BigDecimalDataContainer();
|
||||
protected final BigDecimalDataContainer max_value_container = new BigDecimalDataContainer();
|
||||
|
||||
public StorageVerticalGaugeWidget(T menu, int x, int y) {
|
||||
public StorageGaugeWidget(T menu, int x, int y) {
|
||||
this(menu, x, y, null, null);
|
||||
}
|
||||
|
||||
public StorageVerticalGaugeWidget(T menu, int x, int y, Supplier<BigDecimal> value_supplier, Supplier<BigDecimal> max_value_supplier) {
|
||||
public StorageGaugeWidget(T menu, int x, int y, Supplier<BigDecimal> value_supplier, Supplier<BigDecimal> max_value_supplier) {
|
||||
super(menu, x, y);
|
||||
this.value_supplier = value_supplier;
|
||||
this.max_value_supplier = max_value_supplier;
|
||||
@ -39,7 +37,7 @@ abstract public class StorageVerticalGaugeWidget<T extends MatteryMenu> extends
|
||||
}
|
||||
|
||||
@Override
|
||||
float getLevel() {
|
||||
public float getLevel() {
|
||||
return max_value_container.getDecimal().compareTo(BigDecimal.ZERO) == 0 ? 0f : value_container.getDecimal().divide(max_value_container.getDecimal(), MatteryCapability.ROUND_RULES).floatValue();
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package ru.dbotthepony.mc.otm.menu.widget;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu;
|
||||
import ru.dbotthepony.mc.otm.screen.MatteryScreen;
|
||||
|
||||
abstract public class VerticalGaugeWidget<T extends MatteryMenu> extends AbstractWidget<T> {
|
||||
public VerticalGaugeWidget(T menu, int x, int y) {
|
||||
super(menu, x, y);
|
||||
}
|
||||
|
||||
abstract float getLevel();
|
||||
|
||||
@Override
|
||||
public void renderBackground(MatteryScreen<T> screen, PoseStack pose, int local_x, int local_y, int mouse_x, int mouse_y) {
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.setShaderTexture(0, TEXTURE);
|
||||
|
||||
screen.blit(pose, local_x + x, local_y + y, getImageX(), getImageY(), getImageWidth(), getImageHeight());
|
||||
float level = getLevel();
|
||||
|
||||
if (level > 0.01f) {
|
||||
int intHeight = (int) Math.floor(level * (float) getImageHeight() + 0.5f);
|
||||
screen.blit(pose, local_x + x, local_y + y + getImageHeight() - intHeight, getImageX() + getImageWidth(), getImageY() + getImageHeight() - intHeight, getImageWidth(), intHeight);
|
||||
}
|
||||
}
|
||||
}
|
@ -57,75 +57,6 @@ public class MatteryScreen<T extends MatteryMenu> extends AbstractContainerScree
|
||||
}
|
||||
}
|
||||
|
||||
protected void renderVerticalGauge(PoseStack pose, int x, int y, float level, int image_x, int image_y, int width, int max_height) {
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.setShaderTexture(0, WIDGETS);
|
||||
|
||||
this.blit(pose, render_x + x, render_y + y, image_x, image_y, width, max_height);
|
||||
|
||||
if (level > 0.01f) {
|
||||
int intHeight = (int) Math.floor(level * (float) max_height + 0.5f);
|
||||
this.blit(pose, render_x + x, render_y + y + max_height - intHeight, image_x + width, image_y + max_height - intHeight, width, intHeight);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean renderVerticalGauge(PoseStack pose, int x, int y, int mouseX, int mouseY, float level, int image_x, int image_y, int width, int max_height) {
|
||||
renderVerticalGauge(pose, x, y, level, image_x, image_y, width, max_height);
|
||||
|
||||
x += leftPos;
|
||||
y += topPos;
|
||||
return x <= mouseX && x + 7 >= mouseX && y <= mouseY && y + 46 >= mouseY;
|
||||
}
|
||||
|
||||
protected void renderHorizontalGauge(PoseStack pose, int x, int y, float level, int image_x, int image_y, int max_width, int height) {
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.setShaderTexture(0, WIDGETS);
|
||||
|
||||
this.blit(pose, render_x + x, render_y + y, image_x, image_y, max_width, height);
|
||||
|
||||
if (level > 0.01f) {
|
||||
int intWidth = (int) Math.floor(level * (float) max_width + 0.5f);
|
||||
this.blit(pose, render_x + x, render_y + y, image_x + max_width, image_y, intWidth, height);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean renderHorizontalGauge(PoseStack pose, int x, int y, int mouseX, int mouseY, float level, int image_x, int image_y, int width, int max_height) {
|
||||
renderHorizontalGauge(pose, x, y, level, image_x, image_y, width, max_height);
|
||||
|
||||
x += leftPos;
|
||||
y += topPos;
|
||||
return x <= mouseX && x + 7 >= mouseX && y <= mouseY && y + 46 >= mouseY;
|
||||
}
|
||||
|
||||
public static float level(BigDecimal a, BigDecimal b, boolean exact) {
|
||||
float level;
|
||||
|
||||
if (b.compareTo(BigDecimal.ZERO) == 0) {
|
||||
level = 0f;
|
||||
} else {
|
||||
level = a.divide(b, MatteryCapability.ROUND_RULES).floatValue();
|
||||
|
||||
if (!exact && level >= 0.98)
|
||||
level = 1f;
|
||||
}
|
||||
|
||||
return level;
|
||||
}
|
||||
|
||||
public static float level(BigDecimal a, BigDecimal b) {
|
||||
return level(a, b, true);
|
||||
}
|
||||
|
||||
protected void renderProgressGauge(PoseStack pose, int x, int y, float level) {
|
||||
renderHorizontalGauge(pose, x, y, level, 0, 132, 22, 16);
|
||||
}
|
||||
|
||||
protected void renderProgressGaugeLeft(PoseStack pose, int x, int y, float level) {
|
||||
renderHorizontalGauge(pose, x - 22, y, level, 0, 132, 22, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PoseStack p_98418_, int mouseX, int mouseY, float p_98421_) {
|
||||
render_x = (width - imageWidth) / 2;
|
||||
|
@ -6,6 +6,8 @@
|
||||
"otm.gui.level": "%s / %s",
|
||||
"otm.gui.power.name": "MtE",
|
||||
|
||||
"otm.gui.progress_widget": "Progress: %s%%",
|
||||
|
||||
"otm.gui.matter.percentage_level": "Matter level: %s%%",
|
||||
"otm.gui.matter.format": "Matter: %s",
|
||||
"otm.gui.matter.name": "MtU",
|
||||
|
Loading…
Reference in New Issue
Block a user