ProgressScreen
This commit is contained in:
parent
898668ae96
commit
469e97b790
10 changed files with 273 additions and 36 deletions
|
@ -12,7 +12,7 @@ import java.util.function.Function;
|
|||
class GridCell extends GridCellDefinition {
|
||||
public final float height;
|
||||
Function<GridTransform, Object> componentPlacer;
|
||||
final TriConsumer<PoseStack, GridTransform, Object> customRender;
|
||||
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);
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package ru.bclib.gui.gridlayout;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import ru.bclib.gui.gridlayout.GridLayout.GridValueType;
|
||||
|
||||
|
||||
@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);
|
||||
}
|
|
@ -86,6 +86,7 @@ public class GridLayout extends GridColumn {
|
|||
public static final int COLOR_RED = 0x00FF0000;
|
||||
public static final int COLOR_GREEN = 0x0000FF00;
|
||||
public static final int COLOR_BLUE = 0x000000FF;
|
||||
public static final int COLOR_GRAY = 0x007F7F7F;
|
||||
|
||||
public final GridScreen screen;
|
||||
public final int screenHeight;
|
||||
|
|
|
@ -11,41 +11,51 @@ import ru.bclib.gui.gridlayout.GridLayout.GridValueType;
|
|||
import java.util.List;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
class GridMessageCell extends GridCell {
|
||||
public class GridMessageCell extends GridCell {
|
||||
private final Font font;
|
||||
private final Component text;
|
||||
private MultiLineLabel label;
|
||||
private Component text;
|
||||
private MultiLineLabel lastLabel;
|
||||
private GridTransform lastTransform;
|
||||
|
||||
GridMessageCell(double width, GridValueType widthType, Alignment contentAlignment, Font font, Component text) {
|
||||
this(width, widthType, contentAlignment, font, text, GridLayout.COLOR_WHITE);
|
||||
}
|
||||
GridMessageCell(double width, GridValueType widthType, Alignment contentAlignment, Font font, Component text, int color) {
|
||||
super(width, -1, widthType, null, (poseStack, transform, context) -> {
|
||||
MultiLineLabel label = (MultiLineLabel) context;
|
||||
if (contentAlignment == Alignment.CENTER) {
|
||||
label.renderCentered(poseStack, transform.width / 2 + transform.left, transform.top, font.lineHeight, color);
|
||||
}
|
||||
else if (contentAlignment == Alignment.LEFT) {
|
||||
label.renderLeftAligned(poseStack, transform.left, transform.top, font.lineHeight, color);
|
||||
}
|
||||
});
|
||||
|
||||
super(width, -1, widthType, null, null);
|
||||
this.font = font;
|
||||
this.text = text;
|
||||
|
||||
customRender = (poseStack, transform, context) -> {
|
||||
//MultiLineLabel label = (MultiLineLabel) context;
|
||||
if (contentAlignment == Alignment.CENTER) {
|
||||
lastLabel.renderCentered(poseStack, transform.width / 2 + transform.left, transform.top, font.lineHeight, color);
|
||||
}
|
||||
else if (contentAlignment == 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 label;
|
||||
return lastLabel;
|
||||
}
|
||||
|
||||
protected void create(GridTransform transform) {
|
||||
this.label = MultiLineLabel.create(font, text, transform.width);
|
||||
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.label.getLineCount() + 1;
|
||||
int promptLines = this.lastLabel.getLineCount() + 1;
|
||||
int height = promptLines * 9;
|
||||
|
||||
return new GridElement(left, top, width, height, this::getLabel, customRender);
|
||||
|
|
|
@ -122,6 +122,10 @@ public class GridRow extends GridContainer {
|
|||
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);
|
||||
|
@ -170,48 +174,48 @@ public class GridRow extends GridContainer {
|
|||
}
|
||||
|
||||
|
||||
public GridCell addMessage(Component text, Font font, Alignment contentAlignment) {
|
||||
public GridMessageCell addMessage(Component text, Font font, Alignment contentAlignment) {
|
||||
return addMessage(text, font, GridLayout.COLOR_WHITE, contentAlignment);
|
||||
}
|
||||
|
||||
public GridCell addMessage(Component text, Font font, int color, Alignment contentAlignment) {
|
||||
public GridMessageCell addMessage(Component text, Font font, int color, Alignment contentAlignment) {
|
||||
return addMessage(text, 1.0, GridLayout.GridValueType.PERCENTAGE, font, color, contentAlignment);
|
||||
}
|
||||
|
||||
public GridCell addMessage(Component text, double width, GridValueType widthType, Font font, Alignment contentAlignment) {
|
||||
public GridMessageCell addMessage(Component text, double width, GridValueType widthType, Font font, Alignment contentAlignment) {
|
||||
return addMessage(text, width, widthType, font, GridLayout.COLOR_WHITE, contentAlignment);
|
||||
}
|
||||
|
||||
public GridCell addMessage(Component text, double width, GridValueType widthType, Font font, int color, Alignment contentAlignment) {
|
||||
GridCell cell = new GridMessageCell(width, widthType, Alignment.LEFT, font, text, color);
|
||||
public GridMessageCell addMessage(Component text, double width, GridValueType widthType, Font font, int color, Alignment contentAlignment) {
|
||||
GridMessageCell cell = new GridMessageCell(width, widthType, contentAlignment, font, text, color);
|
||||
this.cells.add(cell);
|
||||
return cell;
|
||||
}
|
||||
|
||||
public GridCell addString(Component text, GridScreen parent) {
|
||||
public GridStringCell addString(Component text, GridScreen parent) {
|
||||
return this.addString(text, GridLayout.COLOR_WHITE, parent);
|
||||
}
|
||||
|
||||
public GridCell addString(Component text, int color, GridScreen parent) {
|
||||
final int width = parent.getFont()
|
||||
.width(text.getVisualOrderText());
|
||||
|
||||
public GridStringCell addString(Component text, int color, GridScreen parent) {
|
||||
final int width = parent.getWidth(text);
|
||||
return this.addString(text, width, GridValueType.CONSTANT, GridLayout.COLOR_WHITE, Alignment.CENTER, parent);
|
||||
}
|
||||
|
||||
public GridCell addString(Component text, Alignment contentAlignment, GridScreen parent) {
|
||||
public GridStringCell addString(Component text, Alignment contentAlignment, GridScreen parent) {
|
||||
return this.addString(text, GridLayout.COLOR_WHITE, contentAlignment, parent);
|
||||
}
|
||||
|
||||
public GridCell addString(Component text, int color, Alignment contentAlignment, GridScreen parent) {
|
||||
public GridStringCell addString(Component text, int color, Alignment contentAlignment, GridScreen parent) {
|
||||
return this.addString(text, 1.0, GridLayout.GridValueType.PERCENTAGE, color, contentAlignment, parent);
|
||||
}
|
||||
|
||||
public GridCell addString(Component text, double width, GridValueType widthType, Alignment contentAlignment, GridScreen parent) {
|
||||
public GridStringCell addString(Component text, double width, GridValueType widthType, Alignment contentAlignment, GridScreen parent) {
|
||||
return addString(text, width, widthType, GridLayout.COLOR_WHITE, contentAlignment, parent);
|
||||
}
|
||||
|
||||
public GridCell addString(Component text, double width, GridValueType widthType, int color, Alignment contentAlignment, GridScreen parent) {
|
||||
GridCell cell = new GridStringCell(width, widthType, parent.getFont().lineHeight, contentAlignment, parent, text, color);
|
||||
public GridStringCell addString(Component text, double width, GridValueType widthType, int color, Alignment contentAlignment, GridScreen parent) {
|
||||
GridStringCell cell = new GridStringCell(width, widthType, parent.getFont().lineHeight, contentAlignment, parent, text, color);
|
||||
this.cells.add(cell);
|
||||
return cell;
|
||||
}
|
||||
|
|
|
@ -96,4 +96,12 @@ public abstract class GridScreen extends Screen {
|
|||
|
||||
super.render(poseStack, i, j, f);
|
||||
}
|
||||
|
||||
public static int getWidth(Component text, Font font) {
|
||||
return font.width(text.getVisualOrderText());
|
||||
}
|
||||
|
||||
public int getWidth(Component text) {
|
||||
return getWidth(text, getFont());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,19 +7,26 @@ import ru.bclib.gui.gridlayout.GridLayout.Alignment;
|
|||
import ru.bclib.gui.gridlayout.GridLayout.GridValueType;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
class GridStringCell extends GridCell {
|
||||
public class GridStringCell extends GridCell {
|
||||
private Component text;
|
||||
GridStringCell(double width, GridValueType widthType, int height, Alignment contentAlignment, GridScreen parent, Component text) {
|
||||
this(width, widthType, height, contentAlignment, parent, text, GridLayout.COLOR_WHITE);
|
||||
|
||||
}
|
||||
GridStringCell(double width, GridValueType widthType, int height, Alignment contentAlignment, GridScreen parent, Component text, int color) {
|
||||
super(width, height, widthType, null, (poseStack, transform, context) -> {
|
||||
super(width, height, widthType, null, null);
|
||||
this.text = text;
|
||||
this.customRender = (poseStack, transform, context) -> {
|
||||
if (contentAlignment == Alignment.CENTER) {
|
||||
parent.drawCenteredString(poseStack, parent.getFont(), text, transform.width / 2 + transform.left, transform.top, color);
|
||||
parent.drawCenteredString(poseStack, parent.getFont(), this.text, transform.width / 2 + transform.left, transform.top, color);
|
||||
}
|
||||
else if (contentAlignment == Alignment.LEFT) {
|
||||
parent.drawString(poseStack, parent.getFont(), text, transform.left, transform.top, color);
|
||||
parent.drawString(poseStack, parent.getFont(), this.text, transform.left, transform.top, color);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
public void setText(Component newText){
|
||||
this.text = newText;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue