Начинающий
- Статус
- Оффлайн
- Регистрация
- 23 Сен 2024
- Сообщения
- 332
- Реакции
- 0
- Выберите загрузчик игры
- Прочие моды
Всем привет! Всех хочу поздравить с новым 2026 годом! Я сделал на экспу 3.1 новый колор пикер (Color Component для Click Gui), присутствует копирование цвета, вставление цвета, также сбрасывания цвета к изначальному цвету, который указан в ColorSetting, ну вот короче вам код, но для начала SS
SS:
DW:
Кто сможет тот перенесёт, всем успехов в 2026 году, и здоровьечка :)
SS:
DW:
Color Component (сам colorpicker):
package vesence.clientRender.CsGui.components.settings;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Vector4f;
import vesence.clientRender.CsGui.CsGuiScreen;
import vesence.clientRender.CsGui.impl.Component;
import vesence.main.features.settings.impl.ColorSetting;
import vesence.util.fontSystems.excFonts.ExcFonts;
import vesence.util.math.Vector4i;
import vesence.util.render.animations.newanim.Animation;
import vesence.util.render.animations.newanim.util.Easings;
import vesence.util.render.render.color.ColorUtil;
import vesence.util.render.render.rect.RenderUtil;
import vesence.util.render.render.rect.Round;
import vesence.util.render.render.scissor.Scissor;
import vesence.util.render.render.scissor.ScissorUtil;
import java.awt.Color;
public class ColorComponent extends Component {
final ColorSetting colorSetting;
float colorRectX, colorRectY, colorRectWidth, colorRectHeight;
float pickerX, pickerY, pickerWidth, pickerHeight;
float sliderX, sliderY, sliderWidth, sliderHeight;
final float padding = 5;
float textX, textY;
private float[] hsb = new float[3];
boolean panelOpened;
boolean draggingHue, draggingPicker;
private final Animation heightAnimation = new Animation();
private final Animation alphaAnimation = new Animation();
private final Animation sliderIndicatorAnimation = new Animation();
private final Animation pickerCircleXAnimation = new Animation();
private final Animation pickerCircleYAnimation = new Animation();
private static final float CLOSED_HEIGHT = 18f;
private static final float OPENED_HEIGHT = 18f + 60f + 60;
private static int clipboardColor = -1;
public ColorComponent(ColorSetting colorSetting) {
this.colorSetting = colorSetting;
updateHSBFromRGB(colorSetting.getValue());
heightAnimation.set(CLOSED_HEIGHT);
alphaAnimation.set(0);
sliderIndicatorAnimation.set(0);
pickerCircleXAnimation.set(0);
pickerCircleYAnimation.set(0);
setHeight(CLOSED_HEIGHT);
}
private void updateHSBFromRGB(int rgb) {
int r = ColorUtil.IntColor.getRed(rgb);
int g = ColorUtil.IntColor.getGreen(rgb);
int b = ColorUtil.IntColor.getBlue(rgb);
Color.RGBtoHSB(r, g, b, hsb);
}
private void updateColorFromHSB() {
int newRgb = Color.getHSBColor(hsb[0], hsb[1], hsb[2]).getRGB();
colorSetting.set(newRgb);
}
@Override
public void render(MatrixStack stack, float mouseX, float mouseY) {
renderTextAndColorRect(stack);
heightAnimation.update();
alphaAnimation.update();
sliderIndicatorAnimation.update();
pickerCircleXAnimation.update();
pickerCircleYAnimation.update();
float currentHeight = heightAnimation.get();
setHeight(currentHeight);
float alpha = alphaAnimation.get();
float maxAlpha = (float) CsGuiScreen.getAlphaAnimation().getValue();
if (alpha > 0.01f) {
float normalizedAlpha = alpha * maxAlpha;
renderSlider(mouseX, mouseY, normalizedAlpha);
renderPickerPanel(mouseX, mouseY, normalizedAlpha);
renderCopyPasteButtons(stack, mouseX, mouseY, normalizedAlpha);
renderColorInfo(stack, normalizedAlpha);
}
super.render(stack, mouseX, mouseY);
}
private void renderColorInfo(MatrixStack stack, float alpha) {
int color = colorSetting.getValue();
int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = color & 0xFF;
String hexText = String.format("HEX: #%08X", color);
String rgbText = String.format("RGB: %d, %d, %d", r, g, b);
float startY = pickerY + pickerHeight * alphaAnimation.get() + 11 + 40;
float centerX = getX() + getWidth() / 2f + 2.5f;
int textColor = ColorUtil.getColor(200, 200, 200, (int) (255 * alpha));
ExcFonts.SF.drawCenter(stack, hexText, centerX, startY, textColor, 8);
ExcFonts.SF.drawCenter(stack, rgbText, centerX, startY + 10, textColor, 8);
}
private void renderTextAndColorRect(MatrixStack stack) {
String settingName = colorSetting.getName();
int colorValue = colorSetting.getValue();
this.textX = this.getX() + padding;
this.textY = this.getY() + 6.5f / 2f;
this.colorRectWidth = padding * 3;
this.colorRectHeight = padding * 2;
this.colorRectX = this.getX() + getWidth() - colorRectWidth - padding + 4;
this.colorRectY = this.getY() + padding - 4;
this.pickerX = this.getX() + padding + 7.5f;
this.pickerY = this.getY() + padding + 16 - 4 + 7.5f;
this.pickerWidth = getWidth() - padding * 4 - 15;
this.pickerHeight = 45;
this.sliderX = getX() + getWidth() - 8;
this.sliderY = getY() + 24;
this.sliderWidth = 3;
this.sliderHeight = 45;
float alpha = CsGuiScreen.getAlphaAnimation().get();
ExcFonts.SF.draw(stack, settingName, textX + 4, textY - 1f, ColorUtil.getColor(255, 255, 255, alpha), 6.5f);
RenderUtil.drawRoundedRect(colorRectX, colorRectY, colorRectWidth, colorRectHeight, 2f, ColorUtil.replAlpha(colorValue, alpha));
}
private void renderPickerPanel(float mouseX, float mouseY, float alpha) {
int white = ColorUtil.replAlpha(Color.WHITE.getRGB(), alpha);
int black = ColorUtil.replAlpha(Color.BLACK.getRGB(), alpha);
int fullHue = ColorUtil.replAlpha(Color.getHSBColor(hsb[0], 1f, 1f).getRGB(), alpha);
Vector4i vector4i = new Vector4i(white, black, fullHue, black);
float offset = 4;
float xRange = pickerWidth - 8;
float yRange = pickerHeight - 8;
if (draggingPicker) {
float saturation = MathHelper.clamp((mouseX - pickerX - offset), 0, xRange) / xRange;
float brightness = MathHelper.clamp((mouseY - pickerY - offset), 0, yRange) / yRange;
hsb[1] = saturation;
hsb[2] = 1f - brightness;
updateColorFromHSB();
}
RenderUtil.Rounded.smooth(new MatrixStack(), pickerX - 5, pickerY - 5.5f, pickerWidth + 10, pickerHeight * alphaAnimation.get() + 10, ColorUtil.getColor(255,255,255,(int) (7 * alpha)), Round.of(4));
RenderUtil.Rounded.roundedOutline(new MatrixStack(), pickerX - 5, pickerY - 5.5f, pickerWidth + 10, pickerHeight * alphaAnimation.get() + 10, 1, ColorUtil.getColor(255,255,255,(int) (15 * alpha)), Round.of(4));
RenderUtil.drawRoundedRect(pickerX, pickerY, pickerWidth, pickerHeight * alphaAnimation.get(), new Vector4f(5,5,5,5), vector4i);
float targetCircleX = pickerX + offset + hsb[1] * xRange;
float targetCircleY = pickerY + offset + (1f - hsb[2]) * yRange;
pickerCircleXAnimation.run(targetCircleX, 0.1, Easings.CUBIC_OUT);
pickerCircleYAnimation.run(targetCircleY, 0.1, Easings.CUBIC_OUT);
Scissor.push();
Scissor.setFromComponentCoordinates(pickerX, pickerY, pickerWidth, pickerHeight * alphaAnimation.get());
RenderUtil.drawCircle(pickerCircleXAnimation.get(), pickerCircleYAnimation.get(), 6.5f, ColorUtil.replAlpha(Color.BLACK.getRGB(), alpha));
RenderUtil.drawCircle(pickerCircleXAnimation.get(), pickerCircleYAnimation.get(), 6, ColorUtil.replAlpha(Color.WHITE.getRGB(), alpha));
Scissor.pop();
}
private void renderSlider(float mouseX, float mouseY, float alpha) {
for (int i = 0; i < sliderHeight; i++) {
float hue = i / sliderHeight;
int hueColor = ColorUtil.replAlpha(Color.HSBtoRGB(hue, 1f, 1f), alpha);
RenderUtil.drawCircle(sliderX + 1f, sliderY + i * alphaAnimation.get(), 3, hueColor);
}
RenderUtil.Rounded.smooth(new MatrixStack(), getX() + getWidth() - 13, getY() + 19, 12, 55 * alphaAnimation.get(), ColorUtil.getColor(255,255,255,(int) (7 * alpha)), Round.of(3.5f));
RenderUtil.Rounded.roundedOutline(new MatrixStack(), getX() + getWidth() - 13, getY() + 19, 12, 55 * alphaAnimation.get(), 1, ColorUtil.getColor(255,255,255,(int) (15 * alpha)), Round.of(3.5f));
float targetIndicatorY = sliderY + hsb[0] * sliderHeight - 2f - 0.5f;
sliderIndicatorAnimation.run(targetIndicatorY, 0.1, Easings.CUBIC_OUT);
RenderUtil.drawRoundedRect(sliderX + sliderWidth - 6.5f, sliderIndicatorAnimation.get() + alphaAnimation.get(), 9, 3 * alphaAnimation.get(), 2, ColorUtil.replAlpha(Color.BLACK.getRGB(), alpha));
RenderUtil.drawRoundedRect(sliderX + sliderWidth - 6f, sliderIndicatorAnimation.get() + 0.5f + alphaAnimation.get(), 8, 2 * alphaAnimation.get(), 2, ColorUtil.replAlpha(-1, alpha));
if (draggingHue) {
float hue = (mouseY - sliderY) / sliderHeight;
hsb[0] = MathHelper.clamp(hue, 0f, 1f);
updateColorFromHSB();
}
}
private void renderCopyPasteButtons(MatrixStack stack, float mouseX, float mouseY, float alpha) {
float buttonWidth = 64;
float buttonHeight = 16;
float startY = pickerY + pickerHeight * alphaAnimation.get() + 11;
float copyX = pickerX - 4.5f;
float pasteX = pickerX + buttonWidth;
RenderUtil.Rounded.smooth(new MatrixStack(), copyX, startY, buttonWidth, buttonHeight, ColorUtil.replAlpha(-1, (int)(7 * alpha)), Round.of(3.5f));
RenderUtil.Rounded.roundedOutline(new MatrixStack(), copyX, startY, buttonWidth, buttonHeight, 1, ColorUtil.replAlpha(-1, (int)(15 * alpha)), Round.of(3.5f));
RenderUtil.Rounded.smooth(new MatrixStack(), pasteX, startY, buttonWidth, buttonHeight, ColorUtil.replAlpha(-1, (int)(7 * alpha)), Round.of(3.5f));
RenderUtil.Rounded.roundedOutline(new MatrixStack(), pasteX, startY, buttonWidth, buttonHeight, 1, ColorUtil.replAlpha(-1, (int)(15 * alpha)), Round.of(3.5f));
RenderUtil.Rounded.smooth(new MatrixStack(), copyX, startY + 20, buttonWidth * 2 + 4, buttonHeight, ColorUtil.replAlpha(-1, (int)(7 * alpha)), Round.of(3.5f));
RenderUtil.Rounded.roundedOutline(new MatrixStack(), copyX, startY + 20, buttonWidth * 2 + 4, buttonHeight, 1, ColorUtil.replAlpha(-1, (int)(15 * alpha)), Round.of(3.5f));
ExcFonts.SF.drawCenter(stack, "Скопировать", copyX + buttonWidth / 2f + 0.5f, startY + 5, ColorUtil.getColor(255,255,255,(int)(255 * alpha)), 7);
ExcFonts.SF.drawCenter(stack, "Вставить", pasteX + buttonWidth / 2f + 0.5f, startY + 5, ColorUtil.getColor(255,255,255,(int)(255 * alpha)), 7);
ExcFonts.SF.drawCenter(stack, "Сбросить цвет", copyX + buttonWidth * 2 / 2f + 3, startY + 5 + 19.5f, ColorUtil.getColor(255,255,255,(int)(255 * alpha)), 7);
}
@Override
public boolean mouseClick(float mouseX, float mouseY, int button) {
if (RenderUtil.isInRegion(mouseX, mouseY, colorRectX, colorRectY, colorRectWidth, colorRectHeight) && (button == 0 || button == 1)) {
panelOpened = !panelOpened;
if (panelOpened) {
updateHSBFromRGB(colorSetting.getValue());
heightAnimation.run(OPENED_HEIGHT, 0.35, Easings.CUBIC_OUT);
alphaAnimation.run(CsGuiScreen.getAlphaAnimation().getValue(), 0.35, Easings.CUBIC_OUT);
} else {
heightAnimation.run(CLOSED_HEIGHT, 0.35, Easings.CUBIC_OUT);
alphaAnimation.run(0, 0.35, Easings.CUBIC_OUT);
}
return true;
}
if (panelOpened && alphaAnimation.get() > 0.5f) {
float sliderHitX = getX() + getWidth() - 13;
float sliderHitY = getY() + 19;
float sliderHitWidth = 12;
float sliderHitHeight = 55;
if (RenderUtil.isInRegion(mouseX, mouseY, sliderHitX, sliderHitY, sliderHitWidth, sliderHitHeight)) {
draggingHue = true;
return true;
}
else if (RenderUtil.isInRegion(mouseX, mouseY, pickerX, pickerY, pickerWidth, pickerHeight)) {
draggingPicker = true;
return true;
}
float buttonWidth = 64;
float buttonHeight = 16;
float startY = pickerY + pickerHeight * alphaAnimation.get() + 11;
float copyX = pickerX - 4.5f;
float pasteX = pickerX + buttonWidth;
if (RenderUtil.isInRegion(mouseX, mouseY, copyX, startY, buttonWidth, buttonHeight)) {
clipboardColor = colorSetting.getValue();
return true;
}
else if (RenderUtil.isInRegion(mouseX, mouseY, pasteX, startY, buttonWidth, buttonHeight) && clipboardColor != -1) {
colorSetting.set(clipboardColor);
updateHSBFromRGB(colorSetting.getValue());
return true;
}
else if (RenderUtil.isInRegion(mouseX, mouseY, copyX, startY + 20, buttonWidth * 2 + 4, buttonHeight)) {
colorSetting.resetToDefault();
updateHSBFromRGB(colorSetting.getValue());
return true;
}
}
return super.mouseClick(mouseX, mouseY, button);
}
@Override
public void mouseRelease(float mouseX, float mouseY, int button) {
draggingHue = false;
draggingPicker = false;
super.mouseRelease(mouseX, mouseY, button);
}
@Override
public boolean isVisible() {
return colorSetting.visible.get();
}
}
Color Setting (нужен для работы):
package vesence.main.features.settings.impl;
import vesence.main.features.settings.Setting;
import java.util.function.Supplier;
public class ColorSetting extends Setting<Integer> {
private final int defaultValue;
public ColorSetting(String name, Integer defaultVal) {
super(name, defaultVal);
this.defaultValue = defaultVal;
}
@Override
public ColorSetting setVisible(Supplier<Boolean> bool) {
return (ColorSetting) super.setVisible(bool);
}
public void resetToDefault() {
this.set(defaultValue);
}
public Integer getDefault() {
return defaultValue;
}
}
Кто сможет тот перенесёт, всем успехов в 2026 году, и здоровьечка :)
