use of com.simibubi.create.foundation.utility.Color in project Create by Creators-of-Create.
the class BoxElement method renderBox.
// total box width = 1 * 2 (outer border) + 1 * 2 (inner color border) + 2 * borderOffset + width
// defaults to 2 + 2 + 4 + 16 = 24px
// batch everything together to save a bunch of gl calls over GuiUtils
protected void renderBox(PoseStack ms) {
/*
* _____________
* _|_____________|_
* | | ___________ | |
* | | | | | | |
* | | | | | | |
* | | |--* | | | |
* | | | h | | |
* | | | --w-+ | | |
* | | | | | |
* | | |_________| | |
* |_|_____________|_|
* |_____________|
*
* */
RenderSystem.disableTexture();
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.setShader(GameRenderer::getPositionColorShader);
Matrix4f model = ms.last().pose();
int f = borderOffset;
Color c1 = background.copy().scaleAlpha(alpha);
Color c2 = borderTop.copy().scaleAlpha(alpha);
Color c3 = borderBot.copy().scaleAlpha(alpha);
Tesselator tessellator = Tesselator.getInstance();
BufferBuilder b = tessellator.getBuilder();
b.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
// outer top
b.vertex(model, x - f - 1, y - f - 2, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
b.vertex(model, x - f - 1, y - f - 1, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
b.vertex(model, x + f + 1 + width, y - f - 1, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
b.vertex(model, x + f + 1 + width, y - f - 2, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
// outer left
b.vertex(model, x - f - 2, y - f - 1, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
b.vertex(model, x - f - 2, y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
b.vertex(model, x - f - 1, y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
b.vertex(model, x - f - 1, y - f - 1, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
// outer bottom
b.vertex(model, x - f - 1, y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
b.vertex(model, x - f - 1, y + f + 2 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
b.vertex(model, x + f + 1 + width, y + f + 2 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
b.vertex(model, x + f + 1 + width, y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
// outer right
b.vertex(model, x + f + 1 + width, y - f - 1, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
b.vertex(model, x + f + 1 + width, y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
b.vertex(model, x + f + 2 + width, y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
b.vertex(model, x + f + 2 + width, y - f - 1, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
// inner background - also render behind the inner edges
b.vertex(model, x - f - 1, y - f - 1, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
b.vertex(model, x - f - 1, y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
b.vertex(model, x + f + 1 + width, y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
b.vertex(model, x + f + 1 + width, y - f - 1, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
tessellator.end();
b.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
// inner top - includes corners
b.vertex(model, x - f - 1, y - f - 1, z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
b.vertex(model, x - f - 1, y - f, z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
b.vertex(model, x + f + 1 + width, y - f, z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
b.vertex(model, x + f + 1 + width, y - f - 1, z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
// inner left - excludes corners
b.vertex(model, x - f - 1, y - f, z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
b.vertex(model, x - f - 1, y + f + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
b.vertex(model, x - f, y + f + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
b.vertex(model, x - f, y - f, z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
// inner bottom - includes corners
b.vertex(model, x - f - 1, y + f + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
b.vertex(model, x - f - 1, y + f + 1 + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
b.vertex(model, x + f + 1 + width, y + f + 1 + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
b.vertex(model, x + f + 1 + width, y + f + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
// inner right - excludes corners
b.vertex(model, x + f + width, y - f, z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
b.vertex(model, x + f + width, y + f + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
b.vertex(model, x + f + 1 + width, y + f + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
b.vertex(model, x + f + 1 + width, y - f, z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
tessellator.end();
RenderSystem.disableBlend();
RenderSystem.enableTexture();
}
use of com.simibubi.create.foundation.utility.Color in project Create by Creators-of-Create.
the class PonderButton method beforeRender.
@Override
protected void beforeRender(@Nonnull PoseStack ms, int mouseX, int mouseY, float partialTicks) {
super.beforeRender(ms, mouseX, mouseY, partialTicks);
float flashValue = flash.getValue(partialTicks);
if (flashValue > .1f) {
float sin = 0.5f + 0.5f * Mth.sin((AnimationTickHolder.getTicks(true) + partialTicks) / 5f);
sin *= flashValue;
Color nc1 = new Color(255, 255, 255, Mth.clamp(gradientColor1.getAlpha() + 150, 0, 255));
Color nc2 = new Color(155, 155, 155, Mth.clamp(gradientColor2.getAlpha() + 150, 0, 255));
gradientColor1 = gradientColor1.mixWith(nc1, sin);
gradientColor2 = gradientColor2.mixWith(nc2, sin);
}
}
use of com.simibubi.create.foundation.utility.Color in project Create by Creators-of-Create.
the class SubMenuConfigScreen method init.
@Override
protected void init() {
super.init();
listWidth = Math.min(width - 80, 300);
int yCenter = height / 2;
int listL = this.width / 2 - listWidth / 2;
int listR = this.width / 2 + listWidth / 2;
resetAll = new BoxWidget(listR + 10, yCenter - 25, 20, 20).withPadding(2, 2).withCallback((x, y) -> new ConfirmationScreen().centered().withText(FormattedText.of("Resetting all settings of the " + type.toString() + " config. Are you sure?")).withAction(success -> {
if (success)
resetConfig(spec.getValues());
}).open(this));
resetAll.showingElement(AllIcons.I_CONFIG_RESET.asStencil().withElementRenderer(BoxWidget.gradientFactory.apply(resetAll)));
resetAll.getToolTip().add(new TextComponent("Reset All"));
resetAll.getToolTip().addAll(TooltipHelper.cutStringTextComponent("Click here to reset all settings to their default value.", ChatFormatting.GRAY, ChatFormatting.GRAY));
saveChanges = new BoxWidget(listL - 30, yCenter - 25, 20, 20).withPadding(2, 2).withCallback((x, y) -> {
if (ConfigHelper.changes.isEmpty())
return;
ConfirmationScreen confirm = new ConfirmationScreen().centered().withText(FormattedText.of("Saving " + ConfigHelper.changes.size() + " changed value" + (ConfigHelper.changes.size() != 1 ? "s" : "") + "")).withAction(success -> {
if (success)
saveChanges();
});
addAnnotationsToConfirm(confirm).open(this);
});
saveChanges.showingElement(AllIcons.I_CONFIG_SAVE.asStencil().withElementRenderer(BoxWidget.gradientFactory.apply(saveChanges)));
saveChanges.getToolTip().add(new TextComponent("Save Changes"));
saveChanges.getToolTip().addAll(TooltipHelper.cutStringTextComponent("Click here to save your current changes.", ChatFormatting.GRAY, ChatFormatting.GRAY));
discardChanges = new BoxWidget(listL - 30, yCenter + 5, 20, 20).withPadding(2, 2).withCallback((x, y) -> {
if (ConfigHelper.changes.isEmpty())
return;
new ConfirmationScreen().centered().withText(FormattedText.of("Discarding " + ConfigHelper.changes.size() + " unsaved change" + (ConfigHelper.changes.size() != 1 ? "s" : "") + "")).withAction(success -> {
if (success)
clearChanges();
}).open(this);
});
discardChanges.showingElement(AllIcons.I_CONFIG_DISCARD.asStencil().withElementRenderer(BoxWidget.gradientFactory.apply(discardChanges)));
discardChanges.getToolTip().add(new TextComponent("Discard Changes"));
discardChanges.getToolTip().addAll(TooltipHelper.cutStringTextComponent("Click here to discard all the changes you made.", ChatFormatting.GRAY, ChatFormatting.GRAY));
goBack = new BoxWidget(listL - 30, yCenter + 65, 20, 20).withPadding(2, 2).withCallback(this::attemptBackstep);
goBack.showingElement(AllIcons.I_CONFIG_BACK.asStencil().withElementRenderer(BoxWidget.gradientFactory.apply(goBack)));
goBack.getToolTip().add(new TextComponent("Go Back"));
addRenderableWidget(resetAll);
addRenderableWidget(saveChanges);
addRenderableWidget(discardChanges);
addRenderableWidget(goBack);
list = new ConfigScreenList(minecraft, listWidth, height - 80, 35, height - 45, 40);
list.setLeftPos(this.width / 2 - list.getWidth() / 2);
addRenderableWidget(list);
search = new ConfigTextField(font, width / 2 - listWidth / 2, height - 35, listWidth, 20);
search.setResponder(this::updateFilter);
search.setHint("Search...");
search.moveCursorToStart();
addRenderableWidget(search);
configGroup.valueMap().forEach((key, obj) -> {
String humanKey = toHumanReadable(key);
if (obj instanceof AbstractConfig) {
SubMenuEntry entry = new SubMenuEntry(this, humanKey, spec, (UnmodifiableConfig) obj);
entry.path = key;
list.children().add(entry);
if (configGroup.valueMap().size() == 1)
ScreenOpener.open(new SubMenuConfigScreen(parent, humanKey, type, spec, (UnmodifiableConfig) obj));
} else if (obj instanceof ForgeConfigSpec.ConfigValue<?>) {
ForgeConfigSpec.ConfigValue<?> configValue = (ForgeConfigSpec.ConfigValue<?>) obj;
ForgeConfigSpec.ValueSpec valueSpec = spec.getRaw(configValue.getPath());
Object value = configValue.get();
ConfigScreenList.Entry entry = null;
if (value instanceof Boolean) {
entry = new BooleanEntry(humanKey, (ForgeConfigSpec.ConfigValue<Boolean>) configValue, valueSpec);
} else if (value instanceof Enum) {
entry = new EnumEntry(humanKey, (ForgeConfigSpec.ConfigValue<Enum<?>>) configValue, valueSpec);
} else if (value instanceof Number) {
entry = NumberEntry.create(value, humanKey, configValue, valueSpec);
}
if (entry == null)
entry = new LabeledEntry("Impl missing - " + configValue.get().getClass().getSimpleName() + " " + humanKey + " : " + value);
if (highlights.contains(key))
entry.annotations.put("highlight", ":)");
list.children().add(entry);
}
});
Collections.sort(list.children(), (e, e2) -> {
int group = (e2 instanceof SubMenuEntry ? 1 : 0) - (e instanceof SubMenuEntry ? 1 : 0);
if (group == 0 && e instanceof LabeledEntry && e2 instanceof LabeledEntry) {
LabeledEntry le = (LabeledEntry) e;
LabeledEntry le2 = (LabeledEntry) e2;
return le.label.getComponent().getString().compareTo(le2.label.getComponent().getString());
}
return group;
});
list.search(highlights.stream().findFirst().orElse(""));
// extras for server configs
if (type != ModConfig.Type.SERVER)
return;
if (minecraft.hasSingleplayerServer())
return;
boolean canEdit = minecraft != null && minecraft.player != null && minecraft.player.hasPermissions(2);
Couple<Color> red = Theme.p(Theme.Key.BUTTON_FAIL);
Couple<Color> green = Theme.p(Theme.Key.BUTTON_SUCCESS);
DelegatedStencilElement stencil = new DelegatedStencilElement();
serverLocked = new BoxWidget(listR + 10, yCenter + 5, 20, 20).withPadding(2, 2).showingElement(stencil);
if (!canEdit) {
list.children().forEach(e -> e.setEditable(false));
resetAll.active = false;
stencil.withStencilRenderer((ms, w, h, alpha) -> AllIcons.I_CONFIG_LOCKED.render(ms, 0, 0));
stencil.withElementRenderer((ms, w, h, alpha) -> UIRenderHelper.angledGradient(ms, 90, 8, 0, 16, 16, red));
serverLocked.withBorderColors(red);
serverLocked.getToolTip().add(new TextComponent("Locked").withStyle(ChatFormatting.BOLD));
serverLocked.getToolTip().addAll(TooltipHelper.cutStringTextComponent("You do not have enough permissions to edit the server config. You can still look at the current values here though.", ChatFormatting.GRAY, ChatFormatting.GRAY));
} else {
stencil.withStencilRenderer((ms, w, h, alpha) -> AllIcons.I_CONFIG_UNLOCKED.render(ms, 0, 0));
stencil.withElementRenderer((ms, w, h, alpha) -> UIRenderHelper.angledGradient(ms, 90, 8, 0, 16, 16, green));
serverLocked.withBorderColors(green);
serverLocked.getToolTip().add(new TextComponent("Unlocked").withStyle(ChatFormatting.BOLD));
serverLocked.getToolTip().addAll(TooltipHelper.cutStringTextComponent("You have enough permissions to edit the server config. Changes you make here will be synced with the server when you save them.", ChatFormatting.GRAY, ChatFormatting.GRAY));
}
addRenderableWidget(serverLocked);
}
use of com.simibubi.create.foundation.utility.Color in project Create by Creators-of-Create.
the class Outline method putVertex.
protected void putVertex(PoseStack.Pose pose, VertexConsumer builder, float x, float y, float z, float u, float v, Direction normal) {
Color rgb = params.rgb;
if (transformNormals == null)
transformNormals = pose.normal();
int xOffset = 0;
int yOffset = 0;
int zOffset = 0;
if (normal != null) {
xOffset = normal.getStepX();
yOffset = normal.getStepY();
zOffset = normal.getStepZ();
}
builder.vertex(pose.pose(), x, y, z).color(rgb.getRedAsFloat(), rgb.getGreenAsFloat(), rgb.getBlueAsFloat(), rgb.getAlphaAsFloat() * params.alpha).uv(u, v).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(params.lightMap).normal(pose.normal(), xOffset, yOffset, zOffset).endVertex();
transformNormals = null;
}
use of com.simibubi.create.foundation.utility.Color in project Create by Creators-of-Create.
the class GaugeBlock method animateTick.
@Override
public void animateTick(BlockState stateIn, Level worldIn, BlockPos pos, Random rand) {
BlockEntity te = worldIn.getBlockEntity(pos);
if (te == null || !(te instanceof GaugeTileEntity))
return;
GaugeTileEntity gaugeTE = (GaugeTileEntity) te;
if (gaugeTE.dialTarget == 0)
return;
int color = gaugeTE.color;
for (Direction face : Iterate.directions) {
if (!shouldRenderHeadOnFace(worldIn, pos, stateIn, face))
continue;
Vector3f rgb = new Color(color).asVectorF();
Vec3 faceVec = Vec3.atLowerCornerOf(face.getNormal());
Direction positiveFacing = Direction.get(AxisDirection.POSITIVE, face.getAxis());
Vec3 positiveFaceVec = Vec3.atLowerCornerOf(positiveFacing.getNormal());
int particleCount = gaugeTE.dialTarget > 1 ? 4 : 1;
if (particleCount == 1 && rand.nextFloat() > 1 / 4f)
continue;
for (int i = 0; i < particleCount; i++) {
Vec3 mul = VecHelper.offsetRandomly(Vec3.ZERO, rand, .25f).multiply(new Vec3(1, 1, 1).subtract(positiveFaceVec)).normalize().scale(.3f);
Vec3 offset = VecHelper.getCenterOf(pos).add(faceVec.scale(.55)).add(mul);
worldIn.addParticle(new DustParticleOptions(rgb, 1), offset.x, offset.y, offset.z, mul.x, mul.y, mul.z);
}
}
}
Aggregations