use of mekanism.client.gui.element.GuiElement in project Mekanism by mekanism.
the class GuiMinerFilterHelper method addMinerDefaults.
default void addMinerDefaults(IGuiWrapper gui, MinerFilter<?> filter, int slotOffset, UnaryOperator<GuiElement> childAdder) {
childAdder.apply(new GuiSlot(SlotType.NORMAL, gui, getRelativeX() + 148, getRelativeY() + slotOffset).setRenderHover(true).stored(() -> new ItemStack(filter.replaceTarget)).setGhostHandler((IGhostBlockItemConsumer) ingredient -> {
filter.replaceTarget = ((ItemStack) ingredient).getItem();
Minecraft.getInstance().getSoundManager().play(SimpleSound.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F));
}));
childAdder.apply(new MekanismImageButton(gui, getRelativeX() + 148, getRelativeY() + 45, 14, 16, MekanismUtils.getResource(ResourceType.GUI_BUTTON, "exclamation.png"), () -> filter.requiresReplacement = !filter.requiresReplacement, (onHover, matrix, xAxis, yAxis) -> gui.displayTooltip(matrix, MekanismLang.MINER_REQUIRE_REPLACE.translate(YesNo.of(filter.requiresReplacement)), xAxis, yAxis)));
}
use of mekanism.client.gui.element.GuiElement in project Mekanism by mekanism.
the class GuiMekanism method incrementFocus.
@Override
public void incrementFocus(GuiElement current) {
int index = focusListeners.indexOf(current);
if (index != -1) {
GuiElement next = focusListeners.get((index + 1) % focusListeners.size());
next.setFocused(true);
focusChange(next);
}
}
use of mekanism.client.gui.element.GuiElement in project Mekanism by mekanism.
the class GuiMekanism method renderLabels.
@Override
protected void renderLabels(@Nonnull MatrixStack matrix, int mouseX, int mouseY) {
matrix.translate(0, 0, 300);
RenderSystem.translatef(-leftPos, -topPos, 0);
children().stream().filter(c -> c instanceof GuiElement).forEach(c -> ((GuiElement) c).onDrawBackground(matrix, mouseX, mouseY, MekanismRenderer.getPartialTick()));
RenderSystem.translatef(leftPos, topPos, 0);
drawForegroundText(matrix, mouseX, mouseY);
int xAxis = mouseX - leftPos;
int yAxis = mouseY - topPos;
// first render general foregrounds
maxZOffset = 200;
int zOffset = 200;
for (Widget widget : this.buttons) {
if (widget instanceof GuiElement) {
matrix.pushPose();
((GuiElement) widget).onRenderForeground(matrix, mouseX, mouseY, zOffset, zOffset);
matrix.popPose();
}
}
// now render overlays in reverse-order (i.e. back to front)
zOffset = maxZOffset;
for (LRU<GuiWindow>.LRUIterator iter = getWindowsDescendingIterator(); iter.hasNext(); ) {
GuiWindow overlay = iter.next();
zOffset += 150;
matrix.pushPose();
overlay.onRenderForeground(matrix, mouseX, mouseY, zOffset, zOffset);
if (iter.hasNext()) {
// if this isn't the focused window, render a 'blur' effect over it
overlay.renderBlur(matrix);
}
matrix.popPose();
}
// then render tooltips, translating above max z offset to prevent clashing
GuiElement tooltipElement = getWindowHovering(mouseX, mouseY);
if (tooltipElement == null) {
for (int i = buttons.size() - 1; i >= 0; i--) {
Widget widget = buttons.get(i);
if (widget instanceof GuiElement && widget.isMouseOver(mouseX, mouseY)) {
tooltipElement = (GuiElement) widget;
break;
}
}
}
// translate forwards using RenderSystem. this should never have to happen as we do all the necessary translations with MatrixStacks,
// but Minecraft has decided to not fully adopt MatrixStacks for many crucial ContainerScreen render operations. should be re-evaluated
// when mc updates related logic on their end (IMPORTANT)
RenderSystem.translatef(0, 0, maxZOffset);
if (tooltipElement != null) {
tooltipElement.renderToolTip(matrix, xAxis, yAxis);
}
// render item tooltips
RenderSystem.translatef(-leftPos, -topPos, 0);
renderTooltip(matrix, mouseX, mouseY);
RenderSystem.translatef(leftPos, topPos, 0);
// IMPORTANT: additional hacky translation so held items render okay. re-evaluate as discussed above
RenderSystem.translatef(0, 0, 200);
}
use of mekanism.client.gui.element.GuiElement in project Mekanism by mekanism.
the class GuiMekanism method init.
@Override
public void init(@Nonnull Minecraft minecraft, int width, int height) {
// Mark that we are not switching to JEI if we start being initialized again
switchingToJEI = false;
// Note: We are forced to do the logic that normally would be inside the "resize" method
// here in init, as when mods like JEI take over the screen to show recipes, and then
// return the screen to the "state" it was beforehand it does not actually properly
// transfer the state from the previous instance to the new instance. If we run the
// code we normally would run for when things get resized, we then are able to
// properly reinstate/transfer the states of the various elements
List<Pair<Integer, GuiElement>> prevElements = new ArrayList<>();
for (int i = 0; i < buttons.size(); i++) {
Widget widget = buttons.get(i);
if (widget instanceof GuiElement && ((GuiElement) widget).hasPersistentData()) {
prevElements.add(Pair.of(i, (GuiElement) widget));
}
}
// flush the focus listeners list unless it's an overlay
focusListeners.removeIf(element -> !element.isOverlay);
int prevLeft = leftPos, prevTop = topPos;
super.init(minecraft, width, height);
windows.forEach(window -> window.resize(prevLeft, prevTop, leftPos, topPos));
prevElements.forEach(e -> {
if (e.getLeft() < buttons.size()) {
Widget widget = buttons.get(e.getLeft());
// ensured by the class comparison, and the restrictions of what can go in prevElements
if (widget.getClass() == e.getRight().getClass()) {
((GuiElement) widget).syncFrom(e.getRight());
}
}
});
}
use of mekanism.client.gui.element.GuiElement in project Mekanism by mekanism.
the class GhostIngredientHandler method getTargets.
private <INGREDIENT> List<TargetInfo<INGREDIENT>> getTargets(List<? extends IGuiEventListener> children, INGREDIENT ingredient) {
List<TargetInfo<INGREDIENT>> ghostTargets = new ArrayList<>();
for (IGuiEventListener child : children) {
if (child instanceof Widget) {
Widget widget = (Widget) child;
if (widget.visible) {
if (widget instanceof GuiElement) {
// Start by adding any grandchild ghost targets we have as they are the "top" layer, and we want them
// to get checked/interacted with first
ghostTargets.addAll(getTargets(((GuiElement) widget).children(), ingredient));
}
// Then go ahead and check if our element is a ghost target and if it is, and it supports the ingredient add it
if (widget instanceof IJEIGhostTarget) {
IJEIGhostTarget ghostTarget = (IJEIGhostTarget) widget;
IGhostIngredientConsumer ghostHandler = ghostTarget.getGhostHandler();
if (ghostHandler != null && ghostHandler.supportsIngredient(ingredient)) {
ghostTargets.add(new TargetInfo<>(ghostTarget, ghostHandler, widget.x, widget.y, widget.getWidth(), widget.getHeight()));
}
}
}
}
}
return ghostTargets;
}
Aggregations