Everything Doesn't Works (move stuff to panels)
This commit is contained in:
parent
c35c99b73c
commit
1b4226f0d5
@ -25,9 +25,9 @@ public class AndroidStationMenu extends PoweredMatteryMenu {
|
||||
LazyOptional<IAndroidCapability> capability = ply.getCapability(MatteryCapability.ANDROID);
|
||||
android = capability.isPresent() ? capability.resolve().get() : null;
|
||||
|
||||
if (android != null) {
|
||||
setItem(0, android.getBatteryItemStack());
|
||||
}
|
||||
capability.ifPresent(cap -> {
|
||||
setItem(0, cap.getBatteryItemStack());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ public class AndroidStationMenu extends PoweredMatteryMenu {
|
||||
inventory,
|
||||
tile);
|
||||
|
||||
battery_slot_index = addSlot(new AndroidBatterySlot(new AndroidStationContainer(inventory.player), 0, 39, 15)).index;
|
||||
battery_slot_index = addMainSlot(new AndroidBatterySlot(new AndroidStationContainer(inventory.player), 0, 39, 15)).index;
|
||||
addBatterySlot();
|
||||
|
||||
addInventorySlots();
|
||||
|
@ -19,7 +19,7 @@ import javax.annotation.Nullable;
|
||||
public class BatteryBankMenu extends MatteryMenu {
|
||||
protected BlockEntityBatteryBank tile;
|
||||
|
||||
public BatteryLevelWidget<PoweredMatteryMenu> battery_widget;
|
||||
public BatteryLevelWidget battery_widget;
|
||||
|
||||
public BatteryBankMenu(int p_38852_, Inventory inventory) {
|
||||
this(p_38852_, inventory, null, new SimpleContainer(5 * 3));
|
||||
@ -37,7 +37,7 @@ public class BatteryBankMenu extends MatteryMenu {
|
||||
|
||||
for (int row = 0; row < 2; row++)
|
||||
for (int column = 0; column < 6; column++)
|
||||
this.addSlot(new BatterySlot(batteries, row * 5 + column, 44 + column * 18, 24 + row * 18));
|
||||
addMainSlot(new BatterySlot(batteries, row * 5 + column, 44 + column * 18, 24 + row * 18));
|
||||
|
||||
addInventorySlots();
|
||||
}
|
||||
|
@ -14,22 +14,22 @@ public class MatterCapacitorBankMenu extends MatteryMenu {
|
||||
this(p_38852_, inventory, null);
|
||||
}
|
||||
|
||||
public MatterLevelWidget<MatterCapacitorBankMenu> matter;
|
||||
public MatterLevelWidget matter;
|
||||
|
||||
public MatterCapacitorBankMenu(int p_38852_, Inventory inventory, BlockEntityMatterCapacitorBank tile) {
|
||||
super(Registry.Menus.MATTER_CAPACITOR_BANK, p_38852_, inventory, tile);
|
||||
|
||||
if (tile == null) {
|
||||
matter = new MatterLevelWidget<>(this, 14, 20);
|
||||
matter = new MatterLevelWidget(this, 14, 20);
|
||||
} else {
|
||||
matter = new MatterLevelWidget<>(this, 14, 20, tile.matter);
|
||||
matter = new MatterLevelWidget(this, 14, 20, tile.matter);
|
||||
}
|
||||
|
||||
Container container = tile != null ? tile.matter_container : new SimpleContainer(5 * 3);
|
||||
|
||||
for (int row = 0; row < 2; row++)
|
||||
for (int column = 0; column < 6; column++)
|
||||
this.addSlot(new MatterContainerInputSlot(container, row * 5 + column, 44 + column * 18, 20 + row * 18, true, IMatterHandler.MatterDirection.BIDIRECTIONAL));
|
||||
addMainSlot(new MatterContainerInputSlot(container, row * 5 + column, 44 + column * 18, 20 + row * 18, true, IMatterHandler.MatterDirection.BIDIRECTIONAL));
|
||||
|
||||
addInventorySlots();
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class MatterDecomposerMenu extends PoweredMatteryMenu {
|
||||
Container container = tile != null ? tile.item_container : new SimpleContainer(2);
|
||||
|
||||
// Вход
|
||||
addSlot(new MatterySlot(container, 0, 61, 36) {
|
||||
addMainSlot(new MatterySlot(container, 0, 61, 36) {
|
||||
@Override
|
||||
public boolean mayPlace(ItemStack p_40231_) {
|
||||
return MatterRegistry.hasMatterValue(p_40231_);
|
||||
@ -33,14 +33,14 @@ public class MatterDecomposerMenu extends PoweredMatteryMenu {
|
||||
});
|
||||
|
||||
// Выход
|
||||
addSlot(new MachineOutputSlot(container, 1, 61 + 18 + 10 + 3 + 22, 36, true, true));
|
||||
addMainSlot(new MachineOutputSlot(container, 1, 61 + 18 + 10 + 3 + 22, 36, true, true));
|
||||
|
||||
if (tile == null || tile.getCapability(MatteryCapability.MATTER).resolve().isEmpty()) {
|
||||
new MatterLevelWidget<>(this, 22, 14);
|
||||
new ProgressGaugeWidget<>(this, 61 + 18 + 3, 36);
|
||||
new MatterLevelWidget(this, 22, 14);
|
||||
new ProgressGaugeWidget(this, 61 + 18 + 3, 36);
|
||||
} else {
|
||||
new MatterLevelWidget<>(this, 22, 14, tile.getCapability(MatteryCapability.MATTER).resolve().get());
|
||||
new ProgressGaugeWidget<>(this, 61 + 18 + 3, 36, () -> (float) tile.getWorkProgress(), tile::cantProcessJob);
|
||||
new MatterLevelWidget(this, 22, 14, tile.getCapability(MatteryCapability.MATTER).resolve().get());
|
||||
new ProgressGaugeWidget(this, 61 + 18 + 3, 36, () -> (float) tile.getWorkProgress(), tile::cantProcessJob);
|
||||
}
|
||||
|
||||
addBatterySlot(14);
|
||||
|
@ -20,14 +20,14 @@ public class MatterReplicatorMenu extends PoweredMatteryMenu {
|
||||
Container container = tile != null ? tile.regular_slots : new SimpleContainer(3);
|
||||
|
||||
for (int i = 0; i < container.getContainerSize(); i++)
|
||||
addSlot(new MachineOutputSlot(container, i, 64 + 18 * i, 38, true, false));
|
||||
addMainSlot(new MachineOutputSlot(container, i, 64 + 18 * i, 38, true, false));
|
||||
|
||||
if (tile != null) {
|
||||
new MatterLevelWidget<>(this, 22, 14, tile.matter);
|
||||
new ProgressGaugeWidget<>(this, 38, 38, () -> (float) tile.getWorkProgress(), tile::cantProcessJob);
|
||||
new MatterLevelWidget(this, 22, 14, tile.matter);
|
||||
new ProgressGaugeWidget(this, 38, 38, () -> (float) tile.getWorkProgress(), tile::cantProcessJob);
|
||||
} else {
|
||||
new MatterLevelWidget<>(this, 22, 14);
|
||||
new ProgressGaugeWidget<>(this, 38, 38);
|
||||
new MatterLevelWidget(this, 22, 14);
|
||||
new ProgressGaugeWidget(this, 38, 38);
|
||||
}
|
||||
|
||||
addBatterySlot(14);
|
||||
|
@ -20,7 +20,7 @@ public class MatterScannerMenu extends PoweredMatteryMenu {
|
||||
|
||||
Container container = tile != null ? tile.input_slot : new SimpleContainer(1);
|
||||
|
||||
addSlot(new MatterySlot(container, 0, 64, 38) {
|
||||
addMainSlot(new MatterySlot(container, 0, 64, 38) {
|
||||
@Override
|
||||
public boolean mayPlace(ItemStack p_40231_) {
|
||||
return MatterRegistry.hasMatterValue(p_40231_);
|
||||
@ -28,9 +28,9 @@ public class MatterScannerMenu extends PoweredMatteryMenu {
|
||||
});
|
||||
|
||||
if (tile != null) {
|
||||
new ProgressGaugeWidget<>(this, 88, 38, () -> (float) tile.getWorkProgress(), tile::cantProcessJob);
|
||||
new ProgressGaugeWidget(this, 88, 38, () -> (float) tile.getWorkProgress(), tile::cantProcessJob);
|
||||
} else {
|
||||
new ProgressGaugeWidget<>(this, 88, 38);
|
||||
new ProgressGaugeWidget(this, 88, 38);
|
||||
}
|
||||
|
||||
addBatterySlot();
|
||||
|
@ -22,8 +22,9 @@ public abstract class MatteryMenu extends AbstractContainerMenu {
|
||||
protected Inventory inventory;
|
||||
protected Player ply;
|
||||
|
||||
public final ArrayList<AbstractWidget<?>> mattery_widgets = new ArrayList<>();
|
||||
public final ArrayList<AbstractWidget> mattery_widgets = new ArrayList<>();
|
||||
public final ArrayList<MatterySlot> inventory_slots = new ArrayList<>();
|
||||
public final ArrayList<MatterySlot> main_slots = new ArrayList<>();
|
||||
|
||||
protected MatteryMenu(@Nullable MenuType<?> p_38851_, int p_38852_, Inventory inventory) {
|
||||
super(p_38851_, p_38852_);
|
||||
@ -36,7 +37,7 @@ public abstract class MatteryMenu extends AbstractContainerMenu {
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
public void addWidget(AbstractWidget<?> widget, Consumer<Consumer<ContainerData>> consumer) {
|
||||
public void addWidget(AbstractWidget widget, Consumer<Consumer<ContainerData>> consumer) {
|
||||
if (mattery_widgets.contains(widget))
|
||||
return;
|
||||
|
||||
@ -44,6 +45,12 @@ public abstract class MatteryMenu extends AbstractContainerMenu {
|
||||
consumer.accept(this::addDataSlots);
|
||||
}
|
||||
|
||||
public MatterySlot addMainSlot(MatterySlot slot) {
|
||||
addSlot(slot);
|
||||
main_slots.add(slot);
|
||||
return slot;
|
||||
}
|
||||
|
||||
protected void addInventorySlots() {
|
||||
addInventorySlots(97);
|
||||
}
|
||||
@ -80,7 +87,7 @@ public abstract class MatteryMenu extends AbstractContainerMenu {
|
||||
|
||||
@Override
|
||||
public void broadcastChanges() {
|
||||
for (AbstractWidget<?> widget : this.mattery_widgets) {
|
||||
for (AbstractWidget widget : this.mattery_widgets) {
|
||||
widget.updateServer();
|
||||
}
|
||||
|
||||
@ -89,7 +96,7 @@ public abstract class MatteryMenu extends AbstractContainerMenu {
|
||||
|
||||
@Override
|
||||
public void broadcastFullState() {
|
||||
for (AbstractWidget<?> widget : this.mattery_widgets) {
|
||||
for (AbstractWidget widget : this.mattery_widgets) {
|
||||
widget.updateServer();
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ public class PatternStorageMenu extends MatteryMenu {
|
||||
|
||||
for (int row = 0; row < 2; row++)
|
||||
for (int column = 0; column < 4; column++)
|
||||
addSlot(new PatternSlot(patterns, row * 4 + column, 48 + column * 20, 27 + row * 24));
|
||||
addMainSlot(new PatternSlot(patterns, row * 4 + column, 48 + column * 20, 27 + row * 24));
|
||||
|
||||
addInventorySlots();
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import javax.annotation.Nullable;
|
||||
abstract public class PoweredMatteryMenu extends MatteryMenu {
|
||||
protected BlockEntityMatteryPowered tile;
|
||||
|
||||
public BatteryLevelWidget<PoweredMatteryMenu> battery_widget;
|
||||
public BatteryLevelWidget battery_widget;
|
||||
|
||||
protected PoweredMatteryMenu(
|
||||
@Nullable MenuType<?> menuType,
|
||||
@ -26,9 +26,9 @@ abstract public class PoweredMatteryMenu extends MatteryMenu {
|
||||
this.tile = tile;
|
||||
|
||||
if (tile == null || tile.getCapability(MatteryCapability.ENERGY).resolve().isEmpty()) {
|
||||
battery_widget = new BatteryLevelWidget<>(this, 13, 14);
|
||||
battery_widget = new BatteryLevelWidget(this, 13, 14);
|
||||
} else {
|
||||
battery_widget = new BatteryLevelWidget<>(this, 13, 14, tile.getCapability(MatteryCapability.ENERGY).resolve().get());
|
||||
battery_widget = new BatteryLevelWidget(this, 13, 14, tile.getCapability(MatteryCapability.ENERGY).resolve().get());
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,6 +42,6 @@ abstract public class PoweredMatteryMenu extends MatteryMenu {
|
||||
|
||||
protected void addBatterySlot(int x, int y) {
|
||||
Container battery_container = tile != null ? tile.battery_container : new SimpleContainer(1);
|
||||
this.addSlot(new BatterySlot(battery_container, 0, x, y, true));
|
||||
addMainSlot(new BatterySlot(battery_container, 0, x, y, true));
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ru.dbotthepony.mc.otm.menu.widget;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.inventory.ContainerData;
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
||||
@ -8,6 +9,8 @@ import ru.dbotthepony.mc.otm.menu.MatteryMenu;
|
||||
import ru.dbotthepony.mc.otm.screen.MatteryScreen;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@ -17,25 +20,22 @@ import java.util.function.Consumer;
|
||||
* and these widgets are supposed to move data between server to client
|
||||
*
|
||||
* this is why this is different from Minecraft's clientside only widgets
|
||||
* @param <T> menu type
|
||||
*/
|
||||
public abstract class AbstractWidget<T extends MatteryMenu> {
|
||||
public abstract class AbstractWidget {
|
||||
public static final ResourceLocation TEXTURE = new ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/widgets.png");
|
||||
|
||||
public final T menu;
|
||||
public final MatteryMenu menu;
|
||||
public int x;
|
||||
public int y;
|
||||
protected Consumer<ContainerData> register_data;
|
||||
|
||||
protected boolean is_hovered = false;
|
||||
|
||||
public abstract int getImageWidth();
|
||||
public abstract int getImageHeight();
|
||||
|
||||
public abstract int getImageX();
|
||||
public abstract int getImageY();
|
||||
|
||||
public AbstractWidget(@Nonnull T menu, int x, int y) {
|
||||
public AbstractWidget(@Nonnull MatteryMenu menu, int x, int y) {
|
||||
this.menu = menu;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
@ -46,23 +46,12 @@ public abstract class AbstractWidget<T extends MatteryMenu> {
|
||||
register_data.accept(slots);
|
||||
}
|
||||
|
||||
public void updateIsHovered(int local_x, int local_y, int mouse_x, int mouse_y) {
|
||||
is_hovered = mouse_x >= x + local_x && mouse_y >= y + local_y && x + local_x + getImageWidth() >= mouse_x && y + local_y + getImageHeight() >= mouse_y;
|
||||
}
|
||||
|
||||
public void setIsHovered(boolean value) {
|
||||
is_hovered = value;
|
||||
}
|
||||
|
||||
public boolean isHovered() {
|
||||
return is_hovered;
|
||||
}
|
||||
|
||||
abstract public void updateServer();
|
||||
|
||||
abstract public void renderBackground(MatteryScreen<T> screen, PoseStack pose, int local_x, int local_y);
|
||||
abstract public void renderBackground(PoseStack pose, float local_x, float local_y);
|
||||
|
||||
// true - rendered a tooltip, break the loop
|
||||
// false - pass
|
||||
abstract public boolean renderTooltip(MatteryScreen<T> screen, PoseStack pose, int mouse_x, int mouse_y);
|
||||
@Nullable
|
||||
abstract public List<Component> getTooltip();
|
||||
}
|
||||
|
@ -8,20 +8,21 @@ import ru.dbotthepony.mc.otm.menu.FormattingHelper;
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu;
|
||||
import ru.dbotthepony.mc.otm.screen.MatteryScreen;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class BatteryLevelWidget<T extends MatteryMenu> extends StorageGaugeWidget<T> {
|
||||
public BatteryLevelWidget(T menu, int x, int y, IMatteryEnergyStorage capability) {
|
||||
public class BatteryLevelWidget extends StorageGaugeWidget {
|
||||
public BatteryLevelWidget(MatteryMenu menu, int x, int y, IMatteryEnergyStorage capability) {
|
||||
super(menu, x, y, capability::getBatteryLevel, capability::getMaxBatteryLevel);
|
||||
}
|
||||
|
||||
public BatteryLevelWidget(T menu, int x, int y) {
|
||||
public BatteryLevelWidget(MatteryMenu menu, int x, int y) {
|
||||
super(menu, x, y);
|
||||
}
|
||||
|
||||
public BatteryLevelWidget(T menu, int x, int y, Supplier<BigDecimal> value_supplier, Supplier<BigDecimal> max_value_supplier) {
|
||||
public BatteryLevelWidget(MatteryMenu menu, int x, int y, Supplier<BigDecimal> value_supplier, Supplier<BigDecimal> max_value_supplier) {
|
||||
super(menu, x, y, value_supplier, max_value_supplier);
|
||||
}
|
||||
|
||||
@ -45,19 +46,12 @@ public class BatteryLevelWidget<T extends MatteryMenu> extends StorageGaugeWidge
|
||||
return 48;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public boolean renderTooltip(MatteryScreen<T> screen, PoseStack pose, int mouse_x, int mouse_y) {
|
||||
if (is_hovered) {
|
||||
List<Component> text = List.of(
|
||||
new TranslatableComponent("otm.gui.power.percentage_level", String.format("%.2f", getLevel() * 100d)),
|
||||
FormattingHelper.formatPowerLevel(value_container.getDecimal(), max_value_container.getDecimal())
|
||||
);
|
||||
|
||||
screen.renderComponentTooltip(pose, text, mouse_x, mouse_y);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
public List<Component> getTooltip() {
|
||||
return List.of(
|
||||
new TranslatableComponent("otm.gui.power.percentage_level", String.format("%.2f", getLevel() * 100d)),
|
||||
FormattingHelper.formatPowerLevel(value_container.getDecimal(), max_value_container.getDecimal())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,9 @@ 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;
|
||||
import ru.dbotthepony.mc.otm.screen.RenderHelper;
|
||||
|
||||
abstract public class GaugeWidget<T extends MatteryMenu> extends AbstractWidget<T> {
|
||||
abstract public class GaugeWidget extends AbstractWidget {
|
||||
public enum GaugeDirection {
|
||||
TOP_TO_BOTTOM,
|
||||
BOTTOM_TO_TOP,
|
||||
@ -14,7 +15,7 @@ abstract public class GaugeWidget<T extends MatteryMenu> extends AbstractWidget<
|
||||
RIGHT_TO_LEFT
|
||||
}
|
||||
|
||||
public GaugeWidget(T menu, int x, int y) {
|
||||
public GaugeWidget(MatteryMenu menu, int x, int y) {
|
||||
super(menu, x, y);
|
||||
}
|
||||
|
||||
@ -29,44 +30,42 @@ abstract public class GaugeWidget<T extends MatteryMenu> extends AbstractWidget<
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderBackground(MatteryScreen<T> screen, PoseStack pose, int local_x, int local_y) {
|
||||
public void renderBackground(PoseStack pose, float local_x, float local_y) {
|
||||
setupGaugeDrawing();
|
||||
|
||||
screen.blit(pose, local_x + x, local_y + y, getImageX(), getImageY(), getImageWidth(), getImageHeight());
|
||||
RenderHelper.drawTexturedRectAuto(pose, local_x + x, local_y + y, getImageWidth(), getImageHeight(), getImageX(), getImageY());
|
||||
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(
|
||||
RenderHelper.drawTexturedRectAuto(
|
||||
pose,
|
||||
local_x + x,
|
||||
local_y + y + getImageHeight() - intHeight,
|
||||
getImageX() + getImageWidth(),
|
||||
getImageY() + getImageHeight() - intHeight,
|
||||
getImageWidth(),
|
||||
intHeight);
|
||||
intHeight,
|
||||
getImageX() + getImageWidth(),
|
||||
getImageY() + getImageHeight() - intHeight);
|
||||
} else if (fill_order == GaugeDirection.TOP_TO_BOTTOM) {
|
||||
screen.blit(
|
||||
RenderHelper.drawTexturedRectAuto(
|
||||
pose,
|
||||
local_x + x,
|
||||
local_y + y,
|
||||
getImageX() + getImageWidth(),
|
||||
getImageY(),
|
||||
getImageWidth(),
|
||||
(int) Math.floor(level * (float) getImageHeight() + 0.5f));
|
||||
(float) Math.floor(level * (float) getImageHeight() + 0.5f),
|
||||
getImageX() + getImageWidth(),
|
||||
getImageY());
|
||||
} else if (fill_order == GaugeDirection.LEFT_TO_RIGHT) {
|
||||
screen.blit(
|
||||
RenderHelper.drawTexturedRectAuto(
|
||||
pose,
|
||||
local_x + x,
|
||||
local_y + y,
|
||||
(float) Math.floor(level * (float) getImageWidth() + 0.5f),
|
||||
getImageHeight(),
|
||||
getImageX() + getImageWidth(),
|
||||
getImageY(),
|
||||
(int) Math.floor(level * (float) getImageWidth() + 0.5f),
|
||||
getImageHeight());
|
||||
getImageY());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,20 +8,21 @@ import ru.dbotthepony.mc.otm.menu.FormattingHelper;
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu;
|
||||
import ru.dbotthepony.mc.otm.screen.MatteryScreen;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class MatterLevelWidget<T extends MatteryMenu> extends StorageGaugeWidget<T> {
|
||||
public MatterLevelWidget(T menu, int x, int y, IMatterHandler capability) {
|
||||
public class MatterLevelWidget extends StorageGaugeWidget {
|
||||
public MatterLevelWidget(MatteryMenu menu, int x, int y, IMatterHandler capability) {
|
||||
super(menu, x, y, capability::getStoredMatter, capability::getMaxStoredMatter);
|
||||
}
|
||||
|
||||
public MatterLevelWidget(T menu, int x, int y) {
|
||||
public MatterLevelWidget(MatteryMenu menu, int x, int y) {
|
||||
super(menu, x, y);
|
||||
}
|
||||
|
||||
public MatterLevelWidget(T menu, int x, int y, Supplier<BigDecimal> value_supplier, Supplier<BigDecimal> max_value_supplier) {
|
||||
public MatterLevelWidget(MatteryMenu menu, int x, int y, Supplier<BigDecimal> value_supplier, Supplier<BigDecimal> max_value_supplier) {
|
||||
super(menu, x, y, value_supplier, max_value_supplier);
|
||||
}
|
||||
|
||||
@ -45,19 +46,12 @@ public class MatterLevelWidget<T extends MatteryMenu> extends StorageGaugeWidget
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public boolean renderTooltip(MatteryScreen<T> screen, PoseStack pose, int mouse_x, int mouse_y) {
|
||||
if (is_hovered) {
|
||||
List<Component> text = List.of(
|
||||
new TranslatableComponent("otm.gui.matter.percentage_level", String.format("%.2f", getLevel() * 100d)),
|
||||
FormattingHelper.formatMatterLevel(value_container.getDecimal(), max_value_container.getDecimal())
|
||||
);
|
||||
|
||||
screen.renderComponentTooltip(pose, text, mouse_x, mouse_y);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
public List<Component> getTooltip() {
|
||||
return List.of(
|
||||
new TranslatableComponent("otm.gui.matter.percentage_level", String.format("%.2f", getLevel() * 100d)),
|
||||
FormattingHelper.formatMatterLevel(value_container.getDecimal(), max_value_container.getDecimal())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -10,10 +10,11 @@ import net.minecraft.world.inventory.ContainerData;
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu;
|
||||
import ru.dbotthepony.mc.otm.screen.MatteryScreen;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ProgressGaugeWidget<T extends MatteryMenu> extends GaugeWidget<T> {
|
||||
public class ProgressGaugeWidget extends GaugeWidget {
|
||||
protected final Supplier<Float> progress_supplier;
|
||||
protected final Supplier<Boolean> is_stuck_supplier;
|
||||
|
||||
@ -41,7 +42,7 @@ public class ProgressGaugeWidget<T extends MatteryMenu> extends GaugeWidget<T> {
|
||||
}
|
||||
};
|
||||
|
||||
public ProgressGaugeWidget(T menu, int x, int y, Supplier<Float> progress, Supplier<Boolean> is_stuck_supplier) {
|
||||
public ProgressGaugeWidget(MatteryMenu menu, int x, int y, Supplier<Float> progress, Supplier<Boolean> is_stuck_supplier) {
|
||||
super(menu, x, y);
|
||||
fill_order = GaugeDirection.LEFT_TO_RIGHT;
|
||||
addDataSlots(progress_container);
|
||||
@ -49,11 +50,11 @@ public class ProgressGaugeWidget<T extends MatteryMenu> extends GaugeWidget<T> {
|
||||
this.is_stuck_supplier = is_stuck_supplier;
|
||||
}
|
||||
|
||||
public ProgressGaugeWidget(T menu, int x, int y) {
|
||||
public ProgressGaugeWidget(MatteryMenu menu, int x, int y) {
|
||||
this(menu, x, y, null, null);
|
||||
}
|
||||
|
||||
public ProgressGaugeWidget(T menu, int x, int y, Supplier<Float> progress) {
|
||||
public ProgressGaugeWidget(MatteryMenu menu, int x, int y, Supplier<Float> progress) {
|
||||
this(menu, x, y, progress, null);
|
||||
}
|
||||
|
||||
@ -95,28 +96,23 @@ public class ProgressGaugeWidget<T extends MatteryMenu> extends GaugeWidget<T> {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public boolean renderTooltip(MatteryScreen<T> screen, PoseStack pose, int mouse_x, int mouse_y) {
|
||||
if (is_hovered) {
|
||||
List<Component> text;
|
||||
public List<Component> getTooltip() {
|
||||
List<Component> text;
|
||||
|
||||
if (progress_container.get(1) != 0) {
|
||||
text = List.of(
|
||||
new TranslatableComponent("otm.gui.progress_widget", String.format("%.2f", progress_container.get(0) / 100f)),
|
||||
new TranslatableComponent("otm.gui.progress_widget_stuck").withStyle(ChatFormatting.DARK_RED)
|
||||
);
|
||||
} else {
|
||||
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;
|
||||
if (progress_container.get(1) != 0) {
|
||||
text = List.of(
|
||||
new TranslatableComponent("otm.gui.progress_widget", String.format("%.2f", progress_container.get(0) / 100f)),
|
||||
new TranslatableComponent("otm.gui.progress_widget_stuck").withStyle(ChatFormatting.DARK_RED)
|
||||
);
|
||||
} else {
|
||||
text = List.of(
|
||||
new TranslatableComponent("otm.gui.progress_widget", String.format("%.2f", progress_container.get(0) / 100f))
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -7,18 +7,18 @@ import ru.dbotthepony.mc.otm.menu.data.BigDecimalDataContainer;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
abstract public class StorageGaugeWidget<T extends MatteryMenu> extends GaugeWidget<T> {
|
||||
abstract public class StorageGaugeWidget extends GaugeWidget {
|
||||
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 StorageGaugeWidget(T menu, int x, int y) {
|
||||
public StorageGaugeWidget(MatteryMenu menu, int x, int y) {
|
||||
this(menu, x, y, null, null);
|
||||
}
|
||||
|
||||
public StorageGaugeWidget(T menu, int x, int y, Supplier<BigDecimal> value_supplier, Supplier<BigDecimal> max_value_supplier) {
|
||||
public StorageGaugeWidget(MatteryMenu 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;
|
||||
|
@ -1,18 +1,25 @@
|
||||
package ru.dbotthepony.mc.otm.screen;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
||||
import ru.dbotthepony.mc.otm.Registry;
|
||||
import ru.dbotthepony.mc.otm.capability.android.AndroidFeatureResearchNode;
|
||||
import ru.dbotthepony.mc.otm.menu.AndroidStationMenu;
|
||||
import ru.dbotthepony.mc.otm.screen.panels.Dock;
|
||||
import ru.dbotthepony.mc.otm.screen.panels.EditBoxPanel;
|
||||
import ru.dbotthepony.mc.otm.screen.panels.EditablePanel;
|
||||
import ru.dbotthepony.mc.otm.screen.panels.FramePanel;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class AndroidStationScreen extends PoweredMachineScreen<AndroidStationMenu> {
|
||||
public class AndroidStationScreen extends MatteryScreen<AndroidStationMenu> {
|
||||
private static final ResourceLocation CONTAINER_BACKGROUND = new ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/android_station.png");
|
||||
|
||||
@Override
|
||||
@ -22,6 +29,8 @@ public class AndroidStationScreen extends PoweredMachineScreen<AndroidStationMen
|
||||
|
||||
private final Set<AndroidFeatureResearchNode> nodes = new HashSet<>();
|
||||
|
||||
private FramePanel frame = new FramePanel(this, null, 0, 0, 80, 120, new TextComponent("test"));
|
||||
|
||||
public AndroidStationScreen(AndroidStationMenu p_97741_, Inventory p_97742_, Component p_97743_) {
|
||||
super(p_97741_, p_97742_, p_97743_);
|
||||
|
||||
@ -62,9 +71,4 @@ public class AndroidStationScreen extends PoweredMachineScreen<AndroidStationMen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderBg(PoseStack pose, float p_97788_, int mouseX, int mouseY) {
|
||||
super.renderBg(pose, p_97788_, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
@ -134,6 +134,10 @@ public abstract class MatteryScreen<T extends MatteryMenu> extends AbstractConta
|
||||
for (var widget : menu.mattery_widgets) {
|
||||
new MatteryWidgetPanel(this, main_frame, widget);
|
||||
}
|
||||
|
||||
for (var slot : menu.main_slots) {
|
||||
new SlotPanel<>(this, main_frame, slot);
|
||||
}
|
||||
}
|
||||
|
||||
movePanels();
|
||||
@ -335,10 +339,11 @@ public abstract class MatteryScreen<T extends MatteryMenu> extends AbstractConta
|
||||
}
|
||||
}
|
||||
|
||||
float depth = 0;
|
||||
float depth = -900f;
|
||||
|
||||
for (var panel : panels) {
|
||||
panel.set3DDepth(depth);
|
||||
RenderSystem.setShaderColor(1F, 1F, 1F, 1F);
|
||||
depth = Math.max(depth, panel.render(pose, mouse_x, mouse_y, flag));
|
||||
}
|
||||
|
||||
@ -374,6 +379,14 @@ public abstract class MatteryScreen<T extends MatteryMenu> extends AbstractConta
|
||||
this.renderFloatingItem(itemstack, mouse_x - render_x - 8, mouse_y - render_y - i2, override_count);
|
||||
}
|
||||
|
||||
RenderSystem.disableDepthTest();
|
||||
|
||||
// forge's hard limit on tooltip Z position
|
||||
if (depth > 500) {
|
||||
pose.pushPose();
|
||||
pose.translate(0, 0, depth - 500);
|
||||
}
|
||||
|
||||
if (this.menu.getCarried().isEmpty()) {
|
||||
if (this.hoveredSlot != null && this.hoveredSlot.hasItem()) {
|
||||
this.renderTooltip(pose, this.hoveredSlot.getItem(), mouse_x, mouse_y);
|
||||
@ -384,6 +397,10 @@ public abstract class MatteryScreen<T extends MatteryMenu> extends AbstractConta
|
||||
}
|
||||
}
|
||||
|
||||
if (depth > 500) {
|
||||
pose.popPose();
|
||||
}
|
||||
|
||||
RenderSystem.enableDepthTest();
|
||||
}
|
||||
|
||||
|
@ -146,6 +146,18 @@ public class RenderHelper {
|
||||
drawTexturedRectUV(stack.last().pose(), x, y, width, height, image_x / mapped_width, image_y / mapped_height, (image_x + width) / mapped_width, (image_y + height) / mapped_height);
|
||||
}
|
||||
|
||||
public static void drawTexturedRectAuto(
|
||||
PoseStack stack,
|
||||
float x,
|
||||
float y,
|
||||
float width,
|
||||
float height,
|
||||
float image_x,
|
||||
float image_y
|
||||
) {
|
||||
drawTexturedRectAuto(stack, x, y, width, height, image_x, image_y, 256, 256);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a textured rectangle on screen
|
||||
* with matrix from pose
|
||||
|
@ -1,5 +1,6 @@
|
||||
package ru.dbotthepony.mc.otm.screen.panels;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
import ru.dbotthepony.mc.otm.screen.MatteryScreen;
|
||||
@ -143,6 +144,7 @@ public class EditablePanel implements GuiEventListener {
|
||||
child.parent_x = parent_x + child.x;
|
||||
child.parent_y = parent_y + child.y;
|
||||
|
||||
RenderSystem.setShaderColor(1F, 1F, 1F, 1F);
|
||||
most_depth = Math.max(most_depth, child.render(stack, mouse_x, mouse_y, flag));
|
||||
}
|
||||
}
|
||||
|
@ -8,10 +8,10 @@ import ru.dbotthepony.mc.otm.screen.MatteryScreen;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class MatteryWidgetPanel<T extends MatteryMenu> extends EditablePanel {
|
||||
public final AbstractWidget<T> widget;
|
||||
public class MatteryWidgetPanel extends EditablePanel {
|
||||
public final AbstractWidget widget;
|
||||
|
||||
public MatteryWidgetPanel(@Nonnull MatteryScreen<T> screen, @Nullable EditablePanel parent, AbstractWidget<T> widget) {
|
||||
public MatteryWidgetPanel(@Nonnull MatteryScreen screen, @Nullable EditablePanel parent, AbstractWidget widget) {
|
||||
super(screen, parent, widget.x, widget.y, widget.getImageWidth(), widget.getImageHeight());
|
||||
widget.x = 0;
|
||||
widget.y = 0;
|
||||
@ -20,12 +20,16 @@ public class MatteryWidgetPanel<T extends MatteryMenu> extends EditablePanel {
|
||||
|
||||
@Override
|
||||
protected void innerRender(PoseStack stack, float mouse_x, float mouse_y, float flag) {
|
||||
widget.setIsHovered(is_hovered);
|
||||
widget.renderBackground((MatteryScreen<T>) screen, stack, 0, 0);
|
||||
widget.renderBackground(stack, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void innerRenderTooltips(PoseStack stack, float mouse_x, float mouse_y, float flag) {
|
||||
widget.renderTooltip((MatteryScreen<T>) screen, stack, (int) mouse_x, (int) mouse_y);
|
||||
if (is_hovered) {
|
||||
var tooltips = widget.getTooltip();
|
||||
|
||||
if (tooltips != null)
|
||||
screen.renderComponentTooltip(stack, tooltips, (int) mouse_x, (int) mouse_y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,12 +26,15 @@ public class SlotPanel<T extends MatterySlot> extends EditablePanel {
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
public SlotPanel(@Nonnull MatteryScreen<?> screen, @Nullable EditablePanel parent, T slot) {
|
||||
this(screen, parent, slot.x, slot.y, 18, 18, slot);
|
||||
}
|
||||
|
||||
public final RGBAColor SLOT_HIGHLIGHT = new RGBAColor(255, 255, 255, 100);
|
||||
public final RGBAColor SLOT_HIGHLIGHT_DRAG = new RGBAColor(200, 200, 200, 150);
|
||||
|
||||
@Override
|
||||
protected boolean mouseClickedInner(double mouse_x, double mouse_y, int button) {
|
||||
OverdriveThatMatters.LOGGER.info("click");
|
||||
screen.onSlotClicked(slot, button);
|
||||
return true;
|
||||
}
|
||||
@ -102,11 +105,12 @@ public class SlotPanel<T extends MatterySlot> extends EditablePanel {
|
||||
// Thanks Mojang
|
||||
// Very cool
|
||||
// (for int x, int y, which are then cast into doubles anyway)
|
||||
screen.getItemRenderer().blitOffset = accumulated_depth;
|
||||
screen.getItemRenderer().blitOffset = accumulated_depth - 100; // force item to draw only 50 units "above" background
|
||||
screen.getItemRenderer().renderAndDecorateItem(Minecraft.getInstance().player, itemstack, 0, 0, (int) (parent_x + parent_y * 1000) /* some kind of indexing ? */);
|
||||
screen.getItemRenderer().renderGuiItemDecorations(screen.getFont(), itemstack, 0, 0, count_override);
|
||||
|
||||
accumulate3DHeight(300);
|
||||
// too big accumulations can lead to Z near clipping issues
|
||||
accumulate3DHeight(100);
|
||||
|
||||
system_stack.popPose();
|
||||
RenderSystem.applyModelViewMatrix();
|
||||
@ -116,7 +120,7 @@ public class SlotPanel<T extends MatterySlot> extends EditablePanel {
|
||||
screen.hoveredSlot = slot;
|
||||
|
||||
stack.pushPose();
|
||||
stack.translate(0, 0, 300);
|
||||
stack.translate(0, 0, 101);
|
||||
RenderHelper.setDrawColor(SLOT_HIGHLIGHT);
|
||||
RenderHelper.drawRect(stack, 1, 1, getWidth() - 1, getHeight() - 1);
|
||||
stack.popPose();
|
||||
|
Loading…
Reference in New Issue
Block a user