(feature) recent colors

This commit is contained in:
kirillsaint 2024-05-02 00:45:28 +06:00
parent 563e479b7b
commit 3444529aa7
6 changed files with 241 additions and 8 deletions

View File

@ -51,6 +51,16 @@ public class HSBPicker extends Gui {
this.alphaSliderHeight = pickerHeight; this.alphaSliderHeight = pickerHeight;
} }
public void setPickerX(int pickerX) {
this.pickerX = pickerX;
this.hueSliderX = pickerX;
}
public void setPickerY(int pickerY) {
this.pickerY = pickerY;
this.hueSliderY = pickerY + pickerHeight + 6;
}
public void render(int mouseX, int mouseY) { public void render(int mouseX, int mouseY) {
if (this.rainbowState) { if (this.rainbowState) {
double rainbowState = Math.ceil((System.currentTimeMillis() + 200) / 20.0); double rainbowState = Math.ceil((System.currentTimeMillis() + 200) / 20.0);

View File

@ -15,17 +15,21 @@ import net.silentclient.client.gui.elements.Slider;
import net.silentclient.client.gui.font.SilentFontRenderer; import net.silentclient.client.gui.font.SilentFontRenderer;
import net.silentclient.client.gui.hud.HUDConfigScreen; import net.silentclient.client.gui.hud.HUDConfigScreen;
import net.silentclient.client.gui.lite.clickgui.utils.GlUtils; import net.silentclient.client.gui.lite.clickgui.utils.GlUtils;
import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils;
import net.silentclient.client.gui.theme.Theme; import net.silentclient.client.gui.theme.Theme;
import net.silentclient.client.gui.util.ColorPickerAction; import net.silentclient.client.gui.util.ColorPickerAction;
import net.silentclient.client.gui.util.RenderUtil; import net.silentclient.client.gui.util.RenderUtil;
import net.silentclient.client.utils.ColorUtils;
import net.silentclient.client.utils.MenuBlurUtils; import net.silentclient.client.utils.MenuBlurUtils;
import net.silentclient.client.utils.MouseCursorHandler; import net.silentclient.client.utils.MouseCursorHandler;
import net.silentclient.client.utils.Sounds; import net.silentclient.client.utils.Sounds;
import net.silentclient.client.utils.types.GlobalSettings;
import org.lwjgl.input.Keyboard; import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import java.awt.*; import java.awt.*;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
public class GuiColorPicker extends SilentScreen { public class GuiColorPicker extends SilentScreen {
private final GuiScreen parentScreen; private final GuiScreen parentScreen;
@ -36,6 +40,8 @@ public class GuiColorPicker extends SilentScreen {
private final boolean allowChangeOpacity; private final boolean allowChangeOpacity;
private int opacity; private int opacity;
private ColorPickerAction action; private ColorPickerAction action;
private ArrayList<GlobalSettings.CustomColor> colors;
private boolean customClose = false;
public GuiColorPicker(Color defaultColor, boolean chroma, boolean allowChangeOpacity, int opacity, ColorPickerAction action, GuiScreen parentScreen) { public GuiColorPicker(Color defaultColor, boolean chroma, boolean allowChangeOpacity, int opacity, ColorPickerAction action, GuiScreen parentScreen) {
this.parentScreen = parentScreen; this.parentScreen = parentScreen;
@ -62,11 +68,18 @@ public class GuiColorPicker extends SilentScreen {
float[] vals = Color.RGBtoHSB(defaultColor.getRed(), defaultColor.getGreen(), defaultColor.getBlue(), null); float[] vals = Color.RGBtoHSB(defaultColor.getRed(), defaultColor.getGreen(), defaultColor.getBlue(), null);
hsb.color = new float[] {vals[0],vals[1],vals[2], defaultColor.getAlpha() / 255.0f}; hsb.color = new float[] {vals[0],vals[1],vals[2], defaultColor.getAlpha() / 255.0f};
hsb.init(); hsb.init();
colors = Client.getInstance().getGlobalSettings().getLatestColors();
} }
@Override @Override
public void onGuiClosed() { public void onGuiClosed() {
action.onClose(hsb.getSelectedColorFinal(), chroma, opacity); if(!customClose) {
action.onClose(hsb.getSelectedColorFinal(), chroma, opacity);
if(!chroma) {
Client.getInstance().getGlobalSettings().addToLatestColors(new Color(hsb.getSelectedColorFinal().getRed(), hsb.getSelectedColorFinal().getGreen(), hsb.getSelectedColorFinal().getBlue(), opacity));
Client.getInstance().getGlobalSettings().save();
}
}
MenuBlurUtils.unloadBlur(); MenuBlurUtils.unloadBlur();
super.onGuiClosed(); super.onGuiClosed();
} }
@ -114,6 +127,25 @@ public class GuiColorPicker extends SilentScreen {
double newVal = 0 + mouse * diff; double newVal = 0 + mouse * diff;
opacity = (int) newVal; opacity = (int) newVal;
} }
settingY += 15;
}
int colorX = x + 100;
int colorIndex = 0;
for(GlobalSettings.CustomColor color : colors) {
ColorUtils.resetColor();
RenderUtil.drawRoundedRect(colorX, settingY, 20, 20, 3, color.getRGB(!allowChangeOpacity));
RenderUtil.drawRoundedOutline(colorX, settingY, 20, 20, 3, 2, new Color(0, 0, 0).getRGB());
if(MouseUtils.isInside(mouseX, mouseY, colorX, settingY, 20, 20)) {
cursorType = MouseCursorHandler.CursorType.POINTER;
}
colorX += 25;
colorIndex += 1;
if(colorIndex == 7) {
colorIndex = 0;
colorX = x + 100;
settingY += 25;
}
} }
GL11.glPopMatrix(); GL11.glPopMatrix();
@ -167,6 +199,31 @@ public class GuiColorPicker extends SilentScreen {
Sounds.playButtonSound(); Sounds.playButtonSound();
chroma = !chroma; chroma = !chroma;
} }
settingY += 15 + 90;
if(allowChangeOpacity) {
settingY += 15;
}
int colorX = x + 100;
int colorIndex = 0;
for(GlobalSettings.CustomColor customColor : colors) {
if(MouseUtils.isInside(mouseX, mouseY, colorX, settingY, 20, 20)) {
Color color = customColor.getColor(!allowChangeOpacity);
action.onChange(color, false, color.getAlpha());
customClose = true;
action.onClose(color, false, color.getAlpha());
mc.displayGuiScreen(parentScreen);
break;
}
colorX += 25;
colorIndex += 1;
if(colorIndex == 7) {
colorIndex = 0;
colorX = x + 100;
settingY += 25;
}
}
} }
@Override @Override

View File

@ -9,12 +9,18 @@ import net.silentclient.client.gui.SilentScreen;
import net.silentclient.client.gui.elements.Button; import net.silentclient.client.gui.elements.Button;
import net.silentclient.client.gui.elements.Checkbox; import net.silentclient.client.gui.elements.Checkbox;
import net.silentclient.client.gui.elements.HSBPicker; import net.silentclient.client.gui.elements.HSBPicker;
import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils;
import net.silentclient.client.gui.util.ColorPickerAction; import net.silentclient.client.gui.util.ColorPickerAction;
import net.silentclient.client.gui.util.RenderUtil;
import net.silentclient.client.utils.ColorUtils;
import net.silentclient.client.utils.MenuBlurUtils; import net.silentclient.client.utils.MenuBlurUtils;
import net.silentclient.client.utils.MouseCursorHandler; import net.silentclient.client.utils.MouseCursorHandler;
import net.silentclient.client.utils.ScrollHelper;
import net.silentclient.client.utils.types.GlobalSettings;
import java.awt.*; import java.awt.*;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
public class ColorPicker extends SilentScreen { public class ColorPicker extends SilentScreen {
private final GuiScreen parentScreen; private final GuiScreen parentScreen;
@ -25,6 +31,9 @@ public class ColorPicker extends SilentScreen {
private final boolean allowChangeOpacity; private final boolean allowChangeOpacity;
private int opacity; private int opacity;
private ColorPickerAction action; private ColorPickerAction action;
private ArrayList<GlobalSettings.CustomColor> colors;
private ScrollHelper scrollHelper = new ScrollHelper();
private boolean customClose = false;
public ColorPicker(Color defaultColor, boolean chroma, boolean allowChangeOpacity, int opacity, ColorPickerAction action, GuiScreen parentScreen) { public ColorPicker(Color defaultColor, boolean chroma, boolean allowChangeOpacity, int opacity, ColorPickerAction action, GuiScreen parentScreen) {
this.parentScreen = parentScreen; this.parentScreen = parentScreen;
@ -51,6 +60,7 @@ public class ColorPicker extends SilentScreen {
ModMenu.initBaseButtons(this.buttonList); ModMenu.initBaseButtons(this.buttonList);
this.buttonList.add(new Button(1, 3, 26, 144, 15, "Back")); this.buttonList.add(new Button(1, 3, 26, 144, 15, "Back"));
colors = Client.getInstance().getGlobalSettings().getLatestColors();
} }
@Override @Override
@ -62,9 +72,15 @@ public class ColorPicker extends SilentScreen {
super.drawScreen(mouseX, mouseY, partialTicks); super.drawScreen(mouseX, mouseY, partialTicks);
ModMenu.trimContentStart(width, height); ModMenu.trimContentStart(width, height, true);
scrollHelper.setStep(5);
scrollHelper.setElementsHeight(100 + (allowChangeOpacity ? 30 : 0) + (float) Math.ceil((colors.size() + 5) / 5) * 30);
scrollHelper.setMaxScroll(height - 20);
scrollHelper.setSpeed(200);
scrollHelper.setFlag(true);
float scrollY = scrollHelper.getScroll();
float colorY = 66; float colorY = 66 + scrollY;
Checkbox.render(mouseX, mouseY, 3, colorY, "Chroma", chroma); Checkbox.render(mouseX, mouseY, 3, colorY, "Chroma", chroma);
if(Checkbox.isHovered(mouseX, mouseY, 3, colorY)) { if(Checkbox.isHovered(mouseX, mouseY, 3, colorY)) {
cursorType = MouseCursorHandler.CursorType.POINTER; cursorType = MouseCursorHandler.CursorType.POINTER;
@ -76,6 +92,8 @@ public class ColorPicker extends SilentScreen {
colorY += 100; colorY += 100;
hsb.setPickerY((int) (80 + scrollY));
if(allowChangeOpacity) { if(allowChangeOpacity) {
GlStateManager.color(1, 1, 1, 1); GlStateManager.color(1, 1, 1, 1);
RegularSlider.render(3, colorY, 144, "Opacity", 255, opacity); RegularSlider.render(3, colorY, 144, "Opacity", 255, opacity);
@ -85,6 +103,25 @@ public class ColorPicker extends SilentScreen {
double newVal = 0 + mouse * diff; double newVal = 0 + mouse * diff;
opacity = (int) newVal; opacity = (int) newVal;
} }
colorY += 30;
}
int colorX = 3;
int colorIndex = 0;
for(GlobalSettings.CustomColor color : colors) {
ColorUtils.resetColor();
RenderUtil.drawRoundedRect(colorX, colorY, 20, 20, 3, color.getRGB(!allowChangeOpacity));
RenderUtil.drawRoundedOutline(colorX, colorY, 20, 20, 3, 2, new Color(0, 0, 0).getRGB());
if(MouseUtils.isInside(mouseX, mouseY, colorX, colorY, 20, 20)) {
cursorType = MouseCursorHandler.CursorType.POINTER;
}
colorX += 25;
colorIndex += 1;
if(colorIndex == 5) {
colorIndex = 0;
colorX = 3;
colorY += 25;
}
} }
Client.getInstance().getMouseCursorHandler().enableCursor(cursorType); Client.getInstance().getMouseCursorHandler().enableCursor(cursorType);
@ -110,6 +147,30 @@ public class ColorPicker extends SilentScreen {
chroma = !chroma; chroma = !chroma;
} }
colorY += 100;
if(allowChangeOpacity) {
colorY += 30;
}
int colorX = 3;
int colorIndex = 0;
for(GlobalSettings.CustomColor customColor : colors) {
if(MouseUtils.isInside(mouseX, mouseY, colorX, colorY, 20, 20)) {
Color color = customColor.getColor(!allowChangeOpacity);
action.onChange(color, false, color.getAlpha());
customClose = true;
action.onClose(color, false, color.getAlpha());
mc.displayGuiScreen(parentScreen);
break;
}
colorX += 25;
colorIndex += 1;
if(colorIndex == 5) {
colorIndex = 0;
colorX = 3;
colorY += 25;
}
}
hsb.mouseClicked(mouseX, mouseY, mouseButton); hsb.mouseClicked(mouseX, mouseY, mouseButton);
} }
@ -122,7 +183,13 @@ public class ColorPicker extends SilentScreen {
@Override @Override
public void onGuiClosed() { public void onGuiClosed() {
super.onGuiClosed(); super.onGuiClosed();
action.onClose(hsb.getSelectedColorFinal(), chroma, opacity); if(!customClose) {
action.onClose(hsb.getSelectedColorFinal(), chroma, opacity);
if(!chroma) {
Client.getInstance().getGlobalSettings().addToLatestColors(new Color(hsb.getSelectedColorFinal().getRed(), hsb.getSelectedColorFinal().getGreen(), hsb.getSelectedColorFinal().getBlue(), opacity));
Client.getInstance().getGlobalSettings().save();
}
}
MenuBlurUtils.unloadBlur(); MenuBlurUtils.unloadBlur();
Client.getInstance().configManager.save(); Client.getInstance().configManager.save();
} }

View File

@ -263,11 +263,15 @@ public class ModMenu extends SilentScreen {
} }
public static void trimContentStart(int width, int height) { public static void trimContentStart(int width, int height) {
trimContentStart(width, height, false);
}
public static void trimContentStart(int width, int height, boolean withoutFooter) {
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glEnable(GL11.GL_SCISSOR_TEST); GL11.glEnable(GL11.GL_SCISSOR_TEST);
ScaledResolution r = new ScaledResolution(Minecraft.getMinecraft()); ScaledResolution r = new ScaledResolution(Minecraft.getMinecraft());
int s = r.getScaleFactor(); int s = r.getScaleFactor();
int listHeight = height - 66 - 21; int listHeight = height - 66 - (withoutFooter ? 0 : 21);
int translatedY = r.getScaledHeight() - 66 - listHeight; int translatedY = r.getScaledHeight() - 66 - listHeight;
GL11.glScissor(0 * s, translatedY * s, width * s, listHeight * s); GL11.glScissor(0 * s, translatedY * s, width * s, listHeight * s);
} }

View File

@ -1,9 +1,13 @@
package net.silentclient.client.utils; package net.silentclient.client.utils;
import java.awt.Color;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
import net.silentclient.client.Client;
import net.silentclient.client.gui.animation.SimpleAnimation; import net.silentclient.client.gui.animation.SimpleAnimation;
import net.silentclient.client.mods.Mod;
import net.silentclient.client.mods.Setting;
import java.awt.*;
import java.util.ArrayList;
public class ColorUtils { public class ColorUtils {
@ -36,4 +40,23 @@ public class ColorUtils {
public static void resetColor() { public static void resetColor() {
setColor(-1); setColor(-1);
} }
public static ArrayList<Color> getLatestColors(boolean ignoreOpacity) {
ArrayList<Color> colors = new ArrayList<>();
for(Mod mod : Client.getInstance().getModInstances().getMods()) {
for(Setting setting : Client.getInstance().getSettingsManager().getSettingByMod(mod)) {
if(setting.isColor() && !setting.isChroma()) {
Color color = !ignoreOpacity ? setting.getValColor() : new Color(setting.getValColor().getRed(), setting.getValColor().getBlue(), setting.getValColor().getGreen());
if(!colors.contains(color)) {
colors.add(color);
}
}
}
}
return colors;
}
} }

View File

@ -3,6 +3,7 @@ package net.silentclient.client.utils.types;
import net.silentclient.client.Client; import net.silentclient.client.Client;
import net.silentclient.client.utils.FeaturedServers; import net.silentclient.client.utils.FeaturedServers;
import java.awt.*;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.util.ArrayList; import java.util.ArrayList;
@ -13,6 +14,8 @@ public class GlobalSettings {
public boolean configsMigrated; public boolean configsMigrated;
public boolean packsPanoramaEnabled; public boolean packsPanoramaEnabled;
public ArrayList<FeaturedServers.FeaturedServerInfo> savedFeaturedServers; public ArrayList<FeaturedServers.FeaturedServerInfo> savedFeaturedServers;
public ArrayList<GlobalSettings.CustomColor> latestColors;
public GlobalSettings() { public GlobalSettings() {
this.config = "Default.txt"; this.config = "Default.txt";
@ -20,6 +23,7 @@ public class GlobalSettings {
this.displayedTutorial = false; this.displayedTutorial = false;
this.packsPanoramaEnabled = true; this.packsPanoramaEnabled = true;
this.savedFeaturedServers = new ArrayList<>(); this.savedFeaturedServers = new ArrayList<>();
this.latestColors = new ArrayList<>();
} }
public String getConfig() { public String getConfig() {
@ -73,6 +77,36 @@ public class GlobalSettings {
this.savedFeaturedServers = savedFeaturedServers; this.savedFeaturedServers = savedFeaturedServers;
} }
public ArrayList<CustomColor> getLatestColors() {
if(latestColors == null) {
this.latestColors = new ArrayList<>();
latestColors.add(new CustomColor(new Color(255, 255, 255)));
latestColors.add(new CustomColor(new Color(156, 157, 151)));
latestColors.add(new CustomColor(new Color(71,79,82)));
latestColors.add(new CustomColor(new Color(0, 0, 0)));
latestColors.add(new CustomColor(new Color(255,216,61)));
latestColors.add(new CustomColor(new Color(249,128,29)));
latestColors.add(new CustomColor(new Color(176,46,38)));
latestColors.add(new CustomColor(new Color(130,84,50)));
latestColors.add(new CustomColor(new Color(128,199,31)));
latestColors.add(new CustomColor(new Color(58,179,218)));
latestColors.add(new CustomColor(new Color(22,156,157)));
latestColors.add(new CustomColor(new Color(60,68,169)));
latestColors.add(new CustomColor(new Color(243,140,170)));
latestColors.add(new CustomColor(new Color(198,79,189)));
latestColors.add(new CustomColor(new Color(137,50,183)));
}
return latestColors;
}
public void addToLatestColors(Color color) {
latestColors.removeIf(customColor -> customColor.color == new Color(color.getRed(), color.getGreen(), color.getBlue()).getRGB() && customColor.opacity == color.getAlpha());
if(latestColors.size() == 21) {
latestColors.remove(20);
}
latestColors.add(0, new CustomColor(color));
}
public void save() { public void save() {
try { try {
FileOutputStream outputStream = new FileOutputStream(Client.getInstance().getGlobalSettingsFile()); FileOutputStream outputStream = new FileOutputStream(Client.getInstance().getGlobalSettingsFile());
@ -84,4 +118,42 @@ public class GlobalSettings {
Client.logger.catching(err); Client.logger.catching(err);
} }
} }
public class CustomColor {
public int color;
public int opacity;
public CustomColor(Color color) {
this(new Color(color.getRed(), color.getGreen(), color.getBlue()), color.getAlpha());
}
public CustomColor(Color color, int opacity) {
this.color = new Color(color.getRed(), color.getGreen(), color.getBlue()).getRGB();
this.opacity = opacity;
}
public Color getColor() {
return getColor(false);
}
public Color getColor(boolean ignoreOpacity) {
if(!ignoreOpacity) {
Color color = new Color(this.color);
return new Color(color.getRed(), color.getGreen(), color.getBlue(), opacity);
}
return new Color(this.color);
}
public int getRGB() {
return getRGB(false);
}
public int getRGB(boolean ignoreOpacity) {
if(!ignoreOpacity) {
Color color = new Color(this.color);
return new Color(color.getRed(), color.getGreen(), color.getBlue(), opacity).getRGB();
}
return this.color;
}
}
} }