Removed deprecated Methods/Classes

This commit is contained in:
Frank 2022-08-01 01:13:55 +02:00
parent 907785f2f5
commit 22ae922439
81 changed files with 61 additions and 6277 deletions

View file

@ -1,36 +0,0 @@
package org.betterx.bclib.client.gui.gridlayout;
import org.betterx.bclib.interfaces.TriConsumer;
import com.mojang.blaze3d.vertex.PoseStack;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import java.util.List;
import java.util.function.Function;
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
class GridCell extends GridCellDefinition {
public final float height;
Function<GridTransform, Object> componentPlacer;
TriConsumer<PoseStack, GridTransform, Object> customRender;
GridCell(
double width,
double height,
GridLayout.GridValueType widthType,
Function<GridTransform, Object> componentPlacer,
TriConsumer<PoseStack, GridTransform, Object> customRender
) {
super(width, widthType);
this.height = (float) height;
this.componentPlacer = componentPlacer;
this.customRender = customRender;
}
protected GridElement buildElementAt(int left, int top, int width, final List<GridElement> collector) {
return new GridElement(left, top, width, (int) this.height, componentPlacer, customRender);
}
}

View file

@ -1,103 +0,0 @@
package org.betterx.bclib.client.gui.gridlayout;
import net.minecraft.client.gui.components.Checkbox;
import net.minecraft.network.chat.Component;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import java.util.function.Consumer;
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
class SignalingCheckBox extends Checkbox {
private final Consumer<Boolean> onChange;
public SignalingCheckBox(
int left,
int top,
int width,
int height,
Component component,
boolean checked,
Consumer<Boolean> onChange
) {
super(left, top, width, height, component, checked);
this.onChange = onChange;
if (onChange != null)
onChange.accept(checked);
}
@Override
public void onPress() {
super.onPress();
if (onChange != null)
onChange.accept(this.selected());
}
}
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
public class GridCheckboxCell extends GridCell implements GridWidgetWithEnabledState {
private boolean checked;
private Checkbox lastCheckbox;
private boolean enabled;
private final float alpha;
GridCheckboxCell(
Component text,
boolean checked,
float alpha,
double width,
GridLayout.GridValueType widthType,
double height
) {
this(text, checked, alpha, width, widthType, height, null);
}
GridCheckboxCell(
Component text,
boolean checked,
float alpha,
double width,
GridLayout.GridValueType widthType,
double height,
Consumer<Boolean> onChange
) {
super(width, height, widthType, null, null);
lastCheckbox = null;
enabled = true;
this.alpha = alpha;
this.componentPlacer = (transform) -> {
Checkbox cb = new SignalingCheckBox(transform.left, transform.top, transform.width, transform.height,
text,
checked,
(state) -> {
this.checked = state;
if (onChange != null) onChange.accept(state);
}
);
cb.setAlpha(alpha);
lastCheckbox = cb;
setEnabled(enabled);
return cb;
};
}
public boolean isChecked() {
return checked;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
if (lastCheckbox != null) {
lastCheckbox.active = enabled;
lastCheckbox.setAlpha(enabled ? alpha : (alpha * 0.5f));
}
this.enabled = enabled;
}
}

View file

@ -1,79 +0,0 @@
package org.betterx.bclib.client.gui.gridlayout;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import java.util.List;
/**
* @deprecated Please use {@link org.betterx.ui.layout.components.VerticalStack} instead
*/
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
public class GridColumn extends GridContainer {
GridColumn(double width) {
super(width);
}
GridColumn(double width, GridLayout.GridValueType widthType) {
super(width, widthType);
}
public GridRow addRow() {
return addRow(GridLayout.VerticalAlignment.TOP);
}
public GridRow addRow(GridLayout.VerticalAlignment align) {
GridRow row = new GridRow(
1.0,
widthType == GridLayout.GridValueType.INHERIT
? GridLayout.GridValueType.INHERIT
: GridLayout.GridValueType.PERCENTAGE,
align
);
this.cells.add(row);
return row;
}
public void addSpacerRow() {
this.addSpacerRow(4);
}
public void addSpacerRow(int height) {
GridCell cell = new GridCell(1.0, height, GridLayout.GridValueType.PERCENTAGE, null, null);
this.cells.add(cell);
}
@Override
public int calculateWidth(final int parentWidth) {
if (widthType == GridLayout.GridValueType.INHERIT) {
return cells.stream()
.filter(row -> row.widthType == GridLayout.GridValueType.INHERIT)
.map(row -> row.buildElement(0, 0, 1, 0, 0, null).width)
.reduce(0, (p, c) -> Math.max(p, c));
} else {
return super.calculateWidth(parentWidth);
}
}
@Override
protected GridElement buildElementAt(int left, int inTop, int width, final List<GridElement> collector) {
int height = 0;
int top = inTop;
if (widthType == GridLayout.GridValueType.INHERIT) {
width = calculateWidth(width);
}
for (GridCellDefinition row : cells) {
GridElement element = row.buildElement(width, 0, 1, left, top, collector);
top += element.height;
height += element.height;
}
return new GridElement(left, inTop, width, height);
}
}

View file

@ -1,20 +0,0 @@
package org.betterx.bclib.client.gui.gridlayout;
import org.betterx.bclib.client.gui.gridlayout.GridLayout.GridValueType;
import com.mojang.blaze3d.vertex.PoseStack;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
public abstract class GridCustomRenderCell extends GridCell {
protected GridCustomRenderCell(double width, GridValueType widthType, double height) {
super(width, height, widthType, null, null);
this.customRender = this::onRender;
}
public abstract void onRender(PoseStack poseStack, GridTransform transform, Object context);
}

View file

@ -1,52 +0,0 @@
package org.betterx.bclib.client.gui.gridlayout;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.resources.ResourceLocation;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
public class GridImageCell extends GridCell {
GridImageCell(
ResourceLocation location,
double width,
GridLayout.GridValueType widthType,
double height,
float alpha,
int uvLeft,
int uvTop,
int uvWidth,
int uvHeight,
int resourceWidth,
int resourceHeight
) {
super(width, height, widthType, null, (poseStack, transform, context) -> {
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, location);
RenderSystem.enableBlend();
RenderSystem.blendFunc(
GlStateManager.SourceFactor.SRC_ALPHA,
GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA
);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, alpha);
GuiComponent.blit(
poseStack,
transform.left,
transform.top,
transform.width,
transform.height,
uvLeft,
uvTop,
uvWidth,
uvHeight,
resourceWidth,
resourceHeight
);
});
}
}

View file

@ -1,234 +0,0 @@
package org.betterx.bclib.client.gui.gridlayout;
import org.betterx.bclib.client.gui.gridlayout.GridLayout.GridValueType;
import org.betterx.bclib.interfaces.TriConsumer;
import org.betterx.bclib.util.Pair;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.components.AbstractWidget;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Function;
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
abstract class GridCellDefinition {
public final float width;
public final GridLayout.GridValueType widthType;
public GridCellDefinition(double width, GridLayout.GridValueType widthType) {
this.width = (float) width;
this.widthType = widthType;
}
public int calculateWidth(final int parentWidth) {
if (widthType == GridLayout.GridValueType.CONSTANT) {
return (int) this.width;
} else if (widthType == GridValueType.PERCENTAGE) {
return (int) (this.width * parentWidth);
} else {
return 0;
}
}
final GridElement buildElement(
final int parentWidth,
final int autoWidth,
final float autoWidthSum,
int left,
final int top,
final List<GridElement> collector
) {
final int width = widthType == GridValueType.FILL
? (int) ((this.width / autoWidthSum) * autoWidth)
: calculateWidth(parentWidth);
final GridElement el = buildElementAt(left, top, width, collector);
if (collector != null) {
collector.add(el);
}
return el;
}
abstract protected GridElement buildElementAt(int left, int top, int width, final List<GridElement> collector);
}
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
class GridElement extends GridTransform {
final Function<GridTransform, Object> componentPlacer;
final TriConsumer<PoseStack, GridTransform, Object> customRender;
Object renderContext;
GridElement(
int left,
int top,
int width,
int height,
Function<GridTransform, Object> componentPlacer,
TriConsumer<PoseStack, GridTransform, Object> customRender
) {
super(left, top, width, height);
this.componentPlacer = componentPlacer;
this.customRender = customRender;
}
GridElement(int left, int top, int width, int height) {
this(left, top, width, height, null, null);
}
GridTransform transformWithPadding(int leftPadding, int topPadding) {
return new GridTransform(left + leftPadding, top + topPadding, width, height);
}
}
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
abstract class GridContainer extends GridCellDefinition {
protected List<GridCellDefinition> cells;
public GridContainer(double width) {
this(width, GridLayout.GridValueType.CONSTANT);
}
GridContainer(double width, GridLayout.GridValueType widthType) {
super(width, widthType);
cells = new LinkedList<>();
}
}
/**
* @deprecated Please use {@link org.betterx.ui.layout.components.Panel} instead
*/
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
public class GridLayout extends GridColumn {
public static final int COLOR_WHITE = 0xFFFFFFFF;
public static final int COLOR_RED = 0xFFDB1F48;
public static final int COLOR_CYAN = 0xFF01949A;
public static final int COLOR_GREEN = 0xFF00FF00;
public static final int COLOR_DARK_GREEN = 0xFF007F00;
public static final int COLOR_YELLOW = 0xFFFAD02C;
public static final int COLOR_BLUE = 0xFF0000FF;
public static final int COLOR_GRAY = 0xFF7F7F7F;
public final GridScreen screen;
public final int screenHeight;
public final int sidePadding;
public final int initialTopPadding;
public final boolean centerVertically;
private int height;
private int topPadding;
private List<GridElement> elements;
public GridLayout(GridScreen screen) {
this(screen, 0, true);
}
public GridLayout(GridScreen screen, int topPadding, boolean centerVertically) {
this(screen, topPadding, 20, centerVertically);
}
public GridLayout(GridScreen screen, int topPadding, int sidePadding, boolean centerVertically) {
super(screen.width - 2 * sidePadding, GridValueType.CONSTANT);
this.screen = screen;
this.screenHeight = screen.height;
height = 0;
this.topPadding = topPadding;
this.sidePadding = sidePadding;
this.initialTopPadding = topPadding;
this.centerVertically = centerVertically;
}
public int getHeight() {
return height;
}
public int getTopPadding() {
return topPadding;
}
void buildLayout() {
elements = new LinkedList<>();
GridElement el = this.buildElement((int) this.width, 0, 1, 0, 0, elements);
this.height = el.height;
if (centerVertically && el.height + initialTopPadding < screenHeight) {
topPadding = (screenHeight - el.height) >> 1;
} else {
topPadding = initialTopPadding;
}
}
public List<Pair<AbstractWidget, Integer>> movableWidgets = new LinkedList<>();
public void finalizeLayout() {
buildLayout();
elements
.stream()
.filter(element -> element.componentPlacer != null)
.forEach(element -> {
final GridTransform transform = element.transformWithPadding(sidePadding, topPadding);
final Object context = element.componentPlacer.apply(transform);
if (element.customRender != null) {
element.renderContext = context;
} else if (context instanceof AbstractWidget) {
final AbstractWidget widget = (AbstractWidget) context;
movableWidgets.add(new Pair(widget, widget.y));
screen.addRenderableWidget(widget);
}
});
}
public void render(PoseStack poseStack) {
if (elements == null) return;
elements
.stream()
.filter(element -> element.customRender != null)
.forEach(element -> element.customRender.accept(
poseStack,
element.transformWithPadding(sidePadding, topPadding),
element.renderContext
));
}
public enum VerticalAlignment {
TOP, CENTER, BOTTOM
}
public enum Alignment {
LEFT, CENTER, RIGHT
}
/**
* Determines how a measurement value is interpreted
*/
public enum GridValueType {
/**
* The value is a constant pixel size
*/
CONSTANT,
/**
* The Value is relative to the parent size
*/
PERCENTAGE,
/**
* The value will be set to fill up the remaining space (i.e. when this is applied to a width of a row element,
* a {@link #FILL}-type may be used to right align (FILL - CONSTANT) or center (FILL - CONSTANT - FILL) elements.
*/
FILL,
/**
* Calculate size based on child-elements
*/
INHERIT
}
}

View file

@ -1,82 +0,0 @@
package org.betterx.bclib.client.gui.gridlayout;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.components.MultiLineLabel;
import net.minecraft.network.chat.Component;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import java.util.List;
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
public class GridMessageCell extends GridCell {
private final Font font;
private Component text;
private MultiLineLabel lastLabel;
private GridTransform lastTransform;
GridMessageCell(
double width,
GridLayout.GridValueType widthType,
GridLayout.Alignment contentAlignment,
Font font,
Component text
) {
this(width, widthType, contentAlignment, font, text, GridLayout.COLOR_WHITE);
}
GridMessageCell(
double width,
GridLayout.GridValueType widthType,
GridLayout.Alignment contentAlignment,
Font font,
Component text,
int color
) {
super(width, -1, widthType, null, null);
this.font = font;
this.text = text;
customRender = (poseStack, transform, context) -> {
//MultiLineLabel label = (MultiLineLabel) context;
if (contentAlignment == GridLayout.Alignment.CENTER) {
lastLabel.renderCentered(
poseStack,
transform.width / 2 + transform.left,
transform.top,
font.lineHeight,
color
);
} else if (contentAlignment == GridLayout.Alignment.LEFT) {
lastLabel.renderLeftAligned(poseStack, transform.left, transform.top, font.lineHeight, color);
}
};
}
public void setText(Component text) {
this.text = text;
if (lastTransform != null) {
create(lastTransform);
}
}
private MultiLineLabel getLabel(GridTransform transform) {
return lastLabel;
}
protected void create(GridTransform transform) {
this.lastTransform = transform;
this.lastLabel = MultiLineLabel.create(font, text, transform.width);
}
@Override
protected GridElement buildElementAt(int left, int top, int width, List<GridElement> collector) {
create(new GridTransform(left, top, width, 0));
int promptLines = this.lastLabel.getLineCount() + 1;
int height = promptLines * 9;
return new GridElement(left, top, width, height, this::getLabel, customRender);
}
}

View file

@ -1,455 +0,0 @@
package org.betterx.bclib.client.gui.gridlayout;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.Button.OnPress;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
/**
* @deprecated Please use {@link org.betterx.ui.layout.components.HorizontalStack} instead
*/
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
public class GridRow extends GridContainer {
public final GridLayout.VerticalAlignment alignment;
GridRow(double width) {
this(width, GridLayout.VerticalAlignment.TOP);
}
GridRow(double width, GridLayout.GridValueType widthType) {
this(width, widthType, GridLayout.VerticalAlignment.CENTER);
}
GridRow(double width, GridLayout.VerticalAlignment alignment) {
super(width);
this.alignment = alignment;
}
GridRow(double width, GridLayout.GridValueType widthType, GridLayout.VerticalAlignment alignment) {
super(width, widthType);
this.alignment = alignment;
}
public GridColumn addColumn(double width, GridLayout.GridValueType widthType) {
GridColumn cell = new GridColumn(width, widthType);
this.cells.add(cell);
return cell;
}
public GridCell addComponent(double height, Function<GridTransform, Object> componentPlacer) {
return addComponent(1.0, GridLayout.GridValueType.PERCENTAGE, height, componentPlacer);
}
public GridCell addComponent(
double width,
GridLayout.GridValueType widthType,
double height,
Function<GridTransform, Object> componentPlacer
) {
GridCell cell = new GridCell(width, height, widthType, componentPlacer, null);
this.cells.add(cell);
return cell;
}
public GridCell addButton(Component text, double height, OnPress onPress) {
return addButton(text, 1.0, GridLayout.GridValueType.PERCENTAGE, height, onPress);
}
public GridCell addButton(Component text, float alpha, double height, OnPress onPress) {
return addButton(text, alpha, 1.0, GridLayout.GridValueType.PERCENTAGE, height, onPress);
}
public GridCell addButton(Component text, double height, Font font, OnPress onPress) {
return addButton(text, 1.0f, height, font, onPress);
}
public GridCell addButton(Component text, float alpha, double height, Font font, OnPress onPress) {
final int width = font.width(text.getVisualOrderText()) + 24;
return addButton(text, alpha, width, GridLayout.GridValueType.CONSTANT, height, onPress);
}
public GridCell addButton(
Component text,
double width,
GridLayout.GridValueType widthType,
double height,
OnPress onPress
) {
return addButton(text, 1.0f, width, widthType, height, onPress);
}
public GridCell addButton(
Component text,
float alpha,
double width,
GridLayout.GridValueType widthType,
double height,
OnPress onPress
) {
GridCell cell = new GridCell(width, height, widthType, (transform) -> {
Button customButton = new Button(
transform.left,
transform.top,
transform.width,
transform.height,
text,
onPress
);
customButton.setAlpha(alpha);
return customButton;
}, null);
this.cells.add(cell);
return cell;
}
public GridCheckboxCell addCheckbox(Component text, boolean checked, Font font, Consumer<Boolean> onChange) {
final int width = font.width(text.getVisualOrderText()) + 24 + 2 * 12;
return addCheckbox(text, checked, width, widthType, onChange);
}
public GridCheckboxCell addCheckbox(
Component text, boolean checked, double width,
GridLayout.GridValueType widthType, Consumer<Boolean> onChange
) {
GridCheckboxCell cell = new GridCheckboxCell(text, checked, 1.0f, width, widthType, 20, onChange);
this.cells.add(cell);
return cell;
}
public GridCheckboxCell addCheckbox(Component text, boolean checked, int height) {
return addCheckbox(text, checked, 1.0f, height);
}
public GridCheckboxCell addCheckbox(Component text, boolean checked, float alpha, int height) {
return addCheckbox(text, checked, alpha, 1.0, GridLayout.GridValueType.PERCENTAGE, height);
}
public GridCheckboxCell addCheckbox(Component text, boolean checked, int height, Font font) {
return addCheckbox(text, checked, 1.0f, height, font);
}
public GridCheckboxCell addCheckbox(Component text, boolean checked, float alpha, int height, Font font) {
final int width = font.width(text.getVisualOrderText()) + 24 + 2 * 12;
return addCheckbox(text, checked, alpha, width, GridLayout.GridValueType.CONSTANT, height);
}
public GridCheckboxCell addCheckbox(
Component text,
boolean checked,
double width,
GridLayout.GridValueType widthType,
int height
) {
return addCheckbox(text, checked, 1.0f, width, widthType, height);
}
public GridCheckboxCell addCheckbox(
Component text,
boolean checked,
float alpha,
double width,
GridLayout.GridValueType widthType,
int height
) {
GridCheckboxCell cell = new GridCheckboxCell(text, checked, alpha, width, widthType, height);
this.cells.add(cell);
return cell;
}
public GridCustomRenderCell addCustomRender(GridCustomRenderCell cell) {
this.cells.add(cell);
return cell;
}
public GridCell addImage(ResourceLocation location, int width, int height) {
return addImage(location, 1.0f, width, height);
}
public GridCell addImage(ResourceLocation location, float alpha, int width, int height) {
return addImage(
location,
alpha,
width,
GridLayout.GridValueType.CONSTANT,
height,
0,
0,
width,
height,
width,
height
);
}
public GridCell addImage(
ResourceLocation location,
double width,
GridLayout.GridValueType widthType,
int height,
int resourceWidth,
int resourceHeight
) {
return addImage(location, 1.0f, width, widthType, height, resourceWidth, resourceHeight);
}
public GridCell addImage(
ResourceLocation location,
float alpha,
double width,
GridLayout.GridValueType widthType,
int height,
int resourceWidth,
int resourceHeight
) {
return addImage(
location,
alpha,
width,
widthType,
height,
0,
0,
resourceWidth,
resourceWidth,
resourceWidth,
resourceHeight
);
}
public GridCell addImage(
ResourceLocation location,
double width,
GridLayout.GridValueType widthType,
int height,
int uvLeft,
int uvTop,
int uvWidth,
int uvHeight,
int resourceWidth,
int resourceHeight
) {
return addImage(
location,
1.0f,
width,
widthType,
height,
uvLeft,
uvTop,
uvWidth,
uvHeight,
resourceWidth,
resourceHeight
);
}
public GridCell addImage(
ResourceLocation location,
float alpha,
double width,
GridLayout.GridValueType widthType,
int height,
int uvLeft,
int uvTop,
int uvWidth,
int uvHeight,
int resourceWidth,
int resourceHeight
) {
GridCell cell = new GridImageCell(
location,
width,
widthType,
height,
alpha,
uvLeft,
uvTop,
uvWidth,
uvHeight,
resourceWidth,
resourceHeight
);
this.cells.add(cell);
return cell;
}
public GridColumn addFiller() {
return addFiller(1);
}
public GridColumn addFiller(float portion) {
GridColumn cell = new GridColumn(portion, GridLayout.GridValueType.FILL);
this.cells.add(cell);
return cell;
}
public void addSpacer() {
addSpacer(12);
}
public void addSpacer(int width) {
GridCell cell = new GridCell(width, 0, GridLayout.GridValueType.CONSTANT, null, null);
this.cells.add(cell);
}
public GridMessageCell addMessage(Component text, Font font, GridLayout.Alignment contentAlignment) {
return addMessage(text, font, GridLayout.COLOR_WHITE, contentAlignment);
}
public GridMessageCell addMessage(Component text, Font font, int color, GridLayout.Alignment contentAlignment) {
return addMessage(text, 1.0, GridLayout.GridValueType.PERCENTAGE, font, color, contentAlignment);
}
public GridMessageCell addMessage(
Component text,
double width,
GridLayout.GridValueType widthType,
Font font,
GridLayout.Alignment contentAlignment
) {
return addMessage(text, width, widthType, font, GridLayout.COLOR_WHITE, contentAlignment);
}
public GridMessageCell addMessage(
Component text,
double width,
GridLayout.GridValueType widthType,
Font font,
int color,
GridLayout.Alignment contentAlignment
) {
GridMessageCell cell = new GridMessageCell(width, widthType, contentAlignment, font, text, color);
this.cells.add(cell);
return cell;
}
public GridStringCell addString(Component text, GridScreen parent) {
return this.addString(text, GridLayout.COLOR_WHITE, parent);
}
public GridStringCell addString(Component text, int color, GridScreen parent) {
final int width = parent.getWidth(text);
return this.addString(
text,
width,
GridLayout.GridValueType.CONSTANT,
color,
GridLayout.Alignment.CENTER,
parent
);
}
public GridStringCell addString(Component text, GridLayout.Alignment contentAlignment, GridScreen parent) {
return this.addString(text, GridLayout.COLOR_WHITE, contentAlignment, parent);
}
public GridStringCell addString(
Component text,
int color,
GridLayout.Alignment contentAlignment,
GridScreen parent
) {
return this.addString(text, 1.0, GridLayout.GridValueType.PERCENTAGE, color, contentAlignment, parent);
}
public GridStringCell addString(
Component text,
double width,
GridLayout.GridValueType widthType,
GridLayout.Alignment contentAlignment,
GridScreen parent
) {
return addString(text, width, widthType, GridLayout.COLOR_WHITE, contentAlignment, parent);
}
public GridStringCell addString(
Component text,
double width,
GridLayout.GridValueType widthType,
int color,
GridLayout.Alignment contentAlignment,
GridScreen parent
) {
GridStringCell cell = new GridStringCell(
width,
widthType,
parent.getFont().lineHeight,
contentAlignment,
parent,
text,
color
);
this.cells.add(cell);
return cell;
}
@Override
protected GridElement buildElementAt(int inLeft, int top, int width, final List<GridElement> collector) {
int height = 0;
int left = inLeft;
if (widthType == GridLayout.GridValueType.INHERIT) {
final int originalWidth = width;
width = cells.stream()
.filter(row -> row.widthType == GridLayout.GridValueType.CONSTANT || row.widthType == GridLayout.GridValueType.INHERIT)
.map(row -> row.buildElement(0, 0, 1, 0, 0, null).width)
.reduce(0, (p, c) -> p + c);
}
final int inheritedWidth = width;
final int fixedWidth = cells.stream()
.filter(col -> col.widthType != GridLayout.GridValueType.FILL)
.map(col -> col.calculateWidth(inheritedWidth))
.reduce(0, (p, c) -> p + c);
final float autoWidthSum = cells.stream()
.filter(col -> col.widthType == GridLayout.GridValueType.FILL)
.map(col -> col.width)
.reduce(0.0f, (p, c) -> p + c);
final int autoWidth = width - fixedWidth;
if (alignment == GridLayout.VerticalAlignment.TOP) {
for (GridCellDefinition col : cells) {
GridElement element = col.buildElement(width, autoWidth, autoWidthSum, left, top, collector);
left += element.width;
height = Math.max(height, element.height);
}
} else {
//first iteration will collect heights, second one will transform top position for alignment
Map<GridCellDefinition, GridElement> cache = new HashMap<>();
for (GridCellDefinition col : cells) {
GridElement element = col.buildElement(width, autoWidth, autoWidthSum, left, top, null);
left += element.width;
height = Math.max(height, element.height);
cache.put(col, element);
}
left = inLeft;
for (GridCellDefinition col : cells) {
GridElement element = cache.get(col);
final int topOffset = (alignment == GridLayout.VerticalAlignment.BOTTOM)
? (height - element.height)
: (height - element.height) >> 1;
element = col.buildElement(width, autoWidth, autoWidthSum, left, top + topOffset, collector);
left += element.width;
}
}
return new GridElement(inLeft, top, width, height);
}
}

View file

@ -1,269 +0,0 @@
package org.betterx.bclib.client.gui.gridlayout;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.components.Widget;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.narration.NarratableEntry;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.network.chat.Component;
import net.minecraft.util.Mth;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.jetbrains.annotations.Nullable;
/**
* @deprecated Use {@link org.betterx.ui.vanilla.LayoutScreen} or {@link org.betterx.ui.vanilla.LayoutScreenWithIcon} instead
*/
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
public abstract class GridScreen extends Screen {
protected GridLayout grid = null;
public final int topPadding;
public final int sidePadding;
public final boolean centerVertically;
@Nullable
public final Screen parent;
protected int scrollPos = 0;
public GridScreen(Component title) {
this(null, title);
}
public GridScreen(@Nullable Screen parent, Component title) {
this(parent, title, 0, true);
}
public GridScreen(Component title, int topPadding, boolean centerVertically) {
this(null, title, topPadding, 20, centerVertically);
}
public GridScreen(@Nullable Screen parent, Component title, int topPadding, boolean centerVertically) {
this(parent, title, topPadding, 20, centerVertically);
}
public GridScreen(Component title, int topPadding, int sidePadding, boolean centerVertically) {
this(null, title, topPadding, sidePadding, centerVertically);
}
public GridScreen(
@Nullable Screen parent,
Component title,
int topPadding,
int sidePadding,
boolean centerVertically
) {
super(title);
this.parent = parent;
this.topPadding = topPadding;
this.sidePadding = sidePadding;
this.centerVertically = centerVertically;
}
@Override
public void onClose() {
this.minecraft.setScreen(parent);
}
public Font getFont() {
return this.font;
}
@Override
public boolean isPauseScreen() {
return true;
}
@Override
public <T extends GuiEventListener & Widget & NarratableEntry> T addRenderableWidget(T guiEventListener) {
return super.addRenderableWidget(guiEventListener);
}
protected void addTitle() {
grid.addRow().addString(this.title, GridLayout.Alignment.CENTER, this);
grid.addSpacerRow(15);
}
final protected void init() {
super.init();
this.grid = new GridLayout(this, this.topPadding, this.sidePadding, this.centerVertically);
addTitle();
initLayout();
grid.finalizeLayout();
}
protected abstract void initLayout();
protected void renderScreen(PoseStack poseStack, int i, int j, float f) {
super.render(poseStack, i, j, f);
}
public void render(PoseStack poseStack, int i, int j, float f) {
this.renderDirtBackground(i);
renderGrid(poseStack);
super.render(poseStack, i, j, f);
}
protected void renderGrid(PoseStack poseStack) {
if (grid != null) {
if (isScrollable()) {
for (var item : grid.movableWidgets) {
item.first.y = item.second + scrollPos;
}
renderScroll(poseStack);
poseStack.pushPose();
poseStack.translate(0, scrollPos, 0);
grid.render(poseStack);
poseStack.popPose();
} else {
grid.render(poseStack);
}
}
}
public static int getWidth(Component text, Font font) {
return font.width(text.getVisualOrderText());
}
public int getWidth(Component text) {
return getWidth(text, getFont());
}
public void setScrollPos(int sp) {
scrollPos = Math.max(getMaxScrollPos(), Math.min(0, sp));
}
public int getScrollPos() {
return scrollPos;
}
public int getScrollHeight() {
if (grid != null) return grid.getHeight() + topPadding;
return height;
}
public int getMaxScrollPos() {
return height - (getScrollHeight() + topPadding);
}
public boolean isScrollable() {
return height < getScrollHeight();
}
public boolean isMouseOverScroller(double x, double y) {
return y >= 0 && y <= height && x >= width - SCROLLER_WIDTH && x <= width;
}
private boolean scrolling = false;
protected void updateScrollingState(double x, double y, int i) {
this.scrolling = i == 0 && x >= width - SCROLLER_WIDTH && x < width;
}
private static final int SCROLLER_WIDTH = 6;
private void renderScroll(PoseStack poseStack) {
final int y1 = height;
final int y0 = 0;
final int yd = y1 - y0;
final int maxPosition = getScrollHeight() + topPadding;
final int x0 = width - SCROLLER_WIDTH;
final int x1 = width;
Tesselator tesselator = Tesselator.getInstance();
BufferBuilder bufferBuilder = tesselator.getBuilder();
RenderSystem.disableTexture();
RenderSystem.setShader(GameRenderer::getPositionColorShader);
int widgetHeight = (int) ((float) (yd * yd) / (float) maxPosition);
widgetHeight = Mth.clamp(widgetHeight, 32, yd - 8);
float relPos = (float) this.getScrollPos() / this.getMaxScrollPos();
int top = (int) (relPos * (yd - widgetHeight)) + y0;
if (top < y0) {
top = y0;
}
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
//scroller background
bufferBuilder.vertex(x0, y1, 0.0D).color(0, 0, 0, 255).endVertex();
bufferBuilder.vertex(x1, y1, 0.0D).color(0, 0, 0, 255).endVertex();
bufferBuilder.vertex(x1, y0, 0.0D).color(0, 0, 0, 255).endVertex();
bufferBuilder.vertex(x0, y0, 0.0D).color(0, 0, 0, 255).endVertex();
//scroll widget shadow
bufferBuilder.vertex(x0, top + widgetHeight, 0.0D).color(128, 128, 128, 255).endVertex();
bufferBuilder.vertex(x1, top + widgetHeight, 0.0D).color(128, 128, 128, 255).endVertex();
bufferBuilder.vertex(x1, top, 0.0D).color(128, 128, 128, 255).endVertex();
bufferBuilder.vertex(x0, top, 0.0D).color(128, 128, 128, 255).endVertex();
//scroll widget
bufferBuilder.vertex(x0, top + widgetHeight - 1, 0.0D)
.color(192, 192, 192, 255)
.endVertex();
bufferBuilder.vertex(x1 - 1, top + widgetHeight - 1, 0.0D)
.color(192, 192, 192, 255)
.endVertex();
bufferBuilder.vertex(x1 - 1, top, 0.0D).color(192, 192, 192, 255).endVertex();
bufferBuilder.vertex(x0, top, 0.0D).color(192, 192, 192, 255).endVertex();
tesselator.end();
}
public boolean mouseClicked(double x, double y, int i) {
this.updateScrollingState(x, y, i);
if (this.scrolling) {
return true;
} else {
return super.mouseClicked(x, y, i);
}
}
public boolean mouseDragged(double xAbs, double yAbs, int i, double dX, double dY) {
if (super.mouseDragged(xAbs, yAbs, i, dX, dY)) {
return true;
} else if (i == 0 && this.scrolling) {
if (yAbs < 0) {
this.setScrollPos(0);
} else if (yAbs > height) {
this.setScrollPos(this.getMaxScrollPos());
} else {
this.setScrollPos((int) (this.getScrollPos() - dY * 2));
}
return true;
} else {
return false;
}
}
public boolean mouseScrolled(double d, double e, double f) {
if (isScrollable()) {
setScrollPos((int) (scrollPos + f * 10));
}
return true;
}
public boolean keyPressed(int keyCode, int j, int k) {
if (super.keyPressed(keyCode, j, k)) {
return true;
} else if (keyCode == 264) {
this.mouseScrolled(0, -1.0f, 0);
return true;
} else if (keyCode == 265) {
this.mouseScrolled(0, 1.0, 0);
return true;
} else {
return false;
}
}
}

View file

@ -1,56 +0,0 @@
package org.betterx.bclib.client.gui.gridlayout;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.network.chat.Component;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
public class GridStringCell extends GridCell {
private Component text;
GridStringCell(
double width,
GridLayout.GridValueType widthType,
int height,
GridLayout.Alignment contentAlignment,
GridScreen parent,
Component text
) {
this(width, widthType, height, contentAlignment, parent, text, GridLayout.COLOR_WHITE);
}
GridStringCell(
double width,
GridLayout.GridValueType widthType,
int height,
GridLayout.Alignment contentAlignment,
GridScreen parent,
Component text,
int color
) {
super(width, height, widthType, null, null);
this.text = text;
this.customRender = (poseStack, transform, context) -> {
if (contentAlignment == GridLayout.Alignment.CENTER) {
GuiComponent.drawCenteredString(
poseStack,
parent.getFont(),
this.text,
transform.width / 2 + transform.left,
transform.top,
color
);
} else if (contentAlignment == GridLayout.Alignment.LEFT) {
GuiComponent.drawString(poseStack, parent.getFont(), this.text, transform.left, transform.top, color);
}
};
}
public void setText(Component newText) {
this.text = newText;
}
}

View file

@ -1,26 +0,0 @@
package org.betterx.bclib.client.gui.gridlayout;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
public class GridTransform {
public final int left;
public final int top;
public final int width;
public final int height;
GridTransform(int left, int top, int width, int height) {
this.left = left;
this.top = top;
this.width = width;
this.height = height;
}
@Override
public String toString() {
return "{" + "left=" + left + ", top=" + top + ", width=" + width + ", height=" + height + '}';
}
}

View file

@ -1,7 +0,0 @@
package org.betterx.bclib.client.gui.gridlayout;
@Deprecated(forRemoval = true)
public interface GridWidgetWithEnabledState {
boolean isEnabled();
void setEnabled(boolean enabled);
}

View file

@ -1,8 +1,8 @@
package org.betterx.bclib.client.gui.screens;
import org.betterx.bclib.api.v2.dataexchange.handler.autosync.HelloClient;
import org.betterx.bclib.client.gui.gridlayout.GridLayout;
import org.betterx.bclib.util.Triple;
import org.betterx.ui.ColorUtil;
import org.betterx.ui.layout.components.HorizontalStack;
import org.betterx.ui.layout.components.LayoutComponent;
import org.betterx.ui.layout.components.Text;
@ -196,29 +196,29 @@ public class ModListScreen extends BCLibLayoutScreen {
final int state = t.second;
final String stateString = t.third;
int color = GridLayout.COLOR_RED;
int color = ColorUtil.RED;
final String typeText;
if (state == STATE_VERSION || state == STATE_VERSION_NOT_OFFERED || state == STATE_VERSION_CLIENT_ONLY) {
typeText = "[VERSION]";
if (state == STATE_VERSION_NOT_OFFERED) {
color = GridLayout.COLOR_YELLOW;
color = ColorUtil.YELLOW;
} else if (state == STATE_VERSION_CLIENT_ONLY) {
color = GridLayout.COLOR_DARK_GREEN;
color = ColorUtil.DARK_GREEN;
}
} else if (state == STATE_MISSING || state == STATE_MISSING_NOT_OFFERED) {
typeText = "[MISSING]";
if (state == STATE_MISSING_NOT_OFFERED) {
color = GridLayout.COLOR_YELLOW;
color = ColorUtil.YELLOW;
}
} else if (state == STATE_SERVER_MISSING || state == STATE_SERVER_MISSING_CLIENT_MOD) {
if (state == STATE_SERVER_MISSING_CLIENT_MOD) {
color = GridLayout.COLOR_CYAN;
color = ColorUtil.AQUA;
typeText = "[OK]";
} else {
typeText = "[NOT ON SERVER]";
}
} else {
color = GridLayout.COLOR_DARK_GREEN;
color = ColorUtil.DARK_GREEN;
typeText = "[OK]";
}
Component dash = Component.literal("-");
@ -237,7 +237,7 @@ public class ModListScreen extends BCLibLayoutScreen {
row = grid.addRow();
row.addSpacer(4 + dashText.getContentWidth());
row.addText(fit(), fit(), Component.literal(stateString))
.setColor(GridLayout.COLOR_GRAY);
.setColor(ColorUtil.GRAY);
}
grid.addSpacer(4);