mirror of
https://github.com/refactorinqq/SLC-1.8.9.git
synced 2024-11-10 07:21:32 +01:00
Account Picker in Lite Menu
This commit is contained in:
parent
abcb6872bb
commit
443b4b29ab
@ -28,7 +28,7 @@ public class NewOutfitModal extends SilentScreen {
|
||||
public NewOutfitModal(GuiScreen parentScreen) {
|
||||
this.parentScreen = parentScreen;
|
||||
this.modalWidth = 200;
|
||||
this.modalHeight = 90;
|
||||
this.modalHeight = 70;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -98,7 +98,7 @@ public class NewOutfitModal extends SilentScreen {
|
||||
|
||||
// Header
|
||||
RenderUtils.drawRect(x, y, this.modalWidth, this.modalHeight, Theme.backgroundColor().getRGB());
|
||||
Client.getInstance().getSilentFontRenderer().drawString("New Config", x + 3, y + 3, 14, SilentFontRenderer.FontType.TITLE);
|
||||
Client.getInstance().getSilentFontRenderer().drawString("New Outfit", x + 3, y + 3, 14, SilentFontRenderer.FontType.TITLE);
|
||||
|
||||
// Content
|
||||
this.silentInputs.get(0).render(mouseX, mouseY, x + 3, y + 23, this.modalWidth - 6);
|
||||
|
@ -18,7 +18,7 @@ import java.awt.*;
|
||||
public class Button extends GuiButton
|
||||
{
|
||||
|
||||
protected int animatedOpcaity = 0;
|
||||
protected int animatedOpacity = 0;
|
||||
private boolean escMenu = false;
|
||||
private int fontSize;
|
||||
|
||||
@ -67,27 +67,27 @@ public class Button extends GuiButton
|
||||
this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
|
||||
ColorUtils.setColor(theme.getBackgroundColor().getRGB());
|
||||
RenderUtil.drawRoundedRect((float) xPosition, (float)yPosition, width, height, (float)3, theme.getBackgroundColor().getRGB());
|
||||
ColorUtils.setColor(theme.getHoveredBackgroundColor(this.enabled ? animatedOpcaity : 0).getRGB());
|
||||
RenderUtil.drawRoundedRect((float) xPosition, (float)yPosition, width, height, (float)3, theme.getHoveredBackgroundColor(this.enabled ? animatedOpcaity : 0).getRGB());
|
||||
ColorUtils.setColor(theme.getHoveredBackgroundColor(this.enabled ? animatedOpacity : 0).getRGB());
|
||||
RenderUtil.drawRoundedRect((float) xPosition, (float)yPosition, width, height, (float)3, theme.getHoveredBackgroundColor(this.enabled ? animatedOpacity : 0).getRGB());
|
||||
ColorUtils.setColor(this.enabled ? new Color(214, 213, 210, 255).getRGB() : new Color(255,255,255,50).getRGB());
|
||||
RenderUtil.drawRoundedOutline(xPosition, yPosition, width, height, 3, 1, theme.getBorderColor().getRGB());
|
||||
this.mouseDragged(mc, mouseX, mouseY);
|
||||
|
||||
if (this.hovered && this.enabled) {
|
||||
if (this.animatedOpcaity < 75 && animateTimer.delay(30)) {
|
||||
this.animatedOpcaity += 15;
|
||||
if (this.animatedOpacity < 75 && animateTimer.delay(30)) {
|
||||
this.animatedOpacity += 15;
|
||||
animateTimer.reset();
|
||||
}
|
||||
} else {
|
||||
if (this.animatedOpcaity != 0 && animateTimer.delay(30)) {
|
||||
this.animatedOpcaity -= 15;
|
||||
if (this.animatedOpacity != 0 && animateTimer.delay(30)) {
|
||||
this.animatedOpacity -= 15;
|
||||
animateTimer.reset();
|
||||
}
|
||||
}
|
||||
|
||||
this.drawButtonContent();
|
||||
} else {
|
||||
this.animatedOpcaity = 0;
|
||||
this.animatedOpacity = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,156 @@
|
||||
package net.silentclient.client.gui.lite;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.silentclient.client.Client;
|
||||
import net.silentclient.client.gui.font.SilentFontRenderer;
|
||||
import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils;
|
||||
import net.silentclient.client.gui.silentmainmenu.components.AccountPicker;
|
||||
import net.silentclient.client.gui.theme.button.DefaultButtonTheme;
|
||||
import net.silentclient.client.gui.theme.button.IButtonTheme;
|
||||
import net.silentclient.client.gui.util.RenderUtil;
|
||||
import net.silentclient.client.utils.AccountManager;
|
||||
import net.silentclient.client.utils.ColorUtils;
|
||||
import net.silentclient.client.utils.SCTextureManager;
|
||||
import net.silentclient.client.utils.TimerUtils;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
public class LiteAccountPicker extends AccountPicker {
|
||||
public static HashMap<String, MinecraftAvatar> avatars = new HashMap<>();
|
||||
public static boolean loading;
|
||||
protected int animatedOpacity = 0;
|
||||
protected TimerUtils animateTimer = new TimerUtils();
|
||||
|
||||
public LiteAccountPicker(int x, int y) {
|
||||
super(x, y);
|
||||
}
|
||||
|
||||
public void draw(Minecraft mc, int mouseX, int mouseY) {
|
||||
IButtonTheme theme = new DefaultButtonTheme();
|
||||
ColorUtils.setColor(theme.getBackgroundColor().getRGB());
|
||||
RenderUtil.drawRoundedRect(x, y, 100, 18, 3, theme.getBackgroundColor().getRGB());
|
||||
ColorUtils.setColor(theme.getHoveredBackgroundColor(animatedOpacity).getRGB());
|
||||
RenderUtil.drawRoundedRect(x, y, 100, 18, 3, theme.getHoveredBackgroundColor(animatedOpacity ).getRGB());
|
||||
ColorUtils.setColor(theme.getBorderColor().getRGB());
|
||||
RenderUtil.drawRoundedOutline(x, y, 100, 18, 3, 1, theme.getBorderColor().getRGB());
|
||||
|
||||
if(!avatars.containsKey(Client.getInstance().getAccount().original_username)) {
|
||||
avatars.put(Client.getInstance().getAccount().original_username, new MinecraftAvatar(Client.getInstance().getAccount().original_username));
|
||||
}
|
||||
|
||||
if(!avatars.get(Client.getInstance().getAccount().original_username).initSkin) {
|
||||
avatars.get(Client.getInstance().getAccount().original_username).loadSkin();
|
||||
}
|
||||
|
||||
RenderUtil.drawImage(avatars.get(Client.getInstance().getAccount().original_username).imageLocation, x + 2, y + 2, 14, 14, false);
|
||||
RenderUtil.drawImage(new ResourceLocation("silentclient/icons/dropdown-icon.png"), x + 100 - 16, y + 2, 14, 14, false);
|
||||
|
||||
Client.getInstance().getSilentFontRenderer().drawString(Client.getInstance().getAccount().original_username, x + 18, y + 9 - 6, 12, SilentFontRenderer.FontType.TITLE, 70);
|
||||
|
||||
if(MouseUtils.isInside(mouseX, mouseY, x, y, 100, 18)) {
|
||||
if (this.animatedOpacity < 75 && animateTimer.delay(30)) {
|
||||
this.animatedOpacity += 15;
|
||||
animateTimer.reset();
|
||||
}
|
||||
} else {
|
||||
if (this.animatedOpacity != 0 && animateTimer.delay(30)) {
|
||||
this.animatedOpacity -= 15;
|
||||
animateTimer.reset();
|
||||
}
|
||||
}
|
||||
|
||||
if(this.open) {
|
||||
int accountY = y + 20;
|
||||
RenderUtil.drawRoundedRect(x, y + 20, 100, (Client.getInstance().getAccountManager().getAccounts().size() - 1) * 18, 3, new Color(20, 20, 20).getRGB());
|
||||
for(AccountManager.AccountType account : Client.getInstance().getAccountManager().getAccounts()) {
|
||||
if(Client.getInstance().getAccount().getUsername().equalsIgnoreCase(account.username)) {
|
||||
continue;
|
||||
}
|
||||
if(!avatars.containsKey(account.username)) {
|
||||
avatars.put(account.username, new MinecraftAvatar(account.username));
|
||||
}
|
||||
|
||||
if(!avatars.get(account.username).initSkin) {
|
||||
avatars.get(account.username).loadSkin();
|
||||
}
|
||||
|
||||
if(MouseUtils.isInside(mouseX, mouseY, x, accountY, 100, 18)) {
|
||||
RenderUtil.drawRoundedRect(x, accountY, 100, 18, 3, theme.getHoveredBackgroundColor(75).getRGB());
|
||||
}
|
||||
|
||||
RenderUtil.drawImage(avatars.get(account.username).imageLocation, x + 2, accountY + 2, 14, 14, false);
|
||||
Client.getInstance().getSilentFontRenderer().drawString(account.username, x + 18, accountY + 9 - 6, 12, SilentFontRenderer.FontType.TITLE, 70);
|
||||
accountY += 18;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onClick(Minecraft mc, int mouseX, int mouseY) {
|
||||
if(MouseUtils.isInside(mouseX, mouseY, x, y, 100, 18)) {
|
||||
this.open = !this.open;
|
||||
(new Thread(() -> {
|
||||
Client.getInstance().getAccountManager().updateAccounts();
|
||||
})).start();
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.open) {
|
||||
int accountY = y + 20;
|
||||
int accountIndex = 0;
|
||||
for(AccountManager.AccountType account : Client.getInstance().getAccountManager().getAccounts()) {
|
||||
if(Client.getInstance().getAccount().getUsername().equalsIgnoreCase(account.username)) {
|
||||
accountIndex += 1;
|
||||
continue;
|
||||
}
|
||||
if(MouseUtils.isInside(mouseX, mouseY, x, accountY, 100, 18)) {
|
||||
Client.getInstance().getAccountManager().setSelected(account, accountIndex, false);
|
||||
break;
|
||||
}
|
||||
accountY += 18;
|
||||
}
|
||||
}
|
||||
|
||||
this.open = false;
|
||||
}
|
||||
|
||||
public class MinecraftAvatar {
|
||||
public ResourceLocation imageLocation = new ResourceLocation("silentclient/images/steve_head.png");
|
||||
public BufferedImage image = null;
|
||||
public boolean initSkin = false;
|
||||
private final String username;
|
||||
|
||||
public MinecraftAvatar(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public void loadSkin() {
|
||||
if(image == null && !LiteAccountPicker.loading && !initSkin) {
|
||||
LiteAccountPicker.loading = true;
|
||||
(new Thread("McAvatarThread") {
|
||||
public void run() {
|
||||
Client.logger.info(String.format("Downloading avatar %s...", username));
|
||||
BufferedImage avatar = SCTextureManager.getImage(String.format("https://mc-heads.net/avatar/%s/100.png", username));
|
||||
if(avatar != null) {
|
||||
Client.logger.info(String.format("Avatar %s successfully downloaded!", username));
|
||||
image = avatar;
|
||||
} else {
|
||||
Client.logger.info(String.format("Avatar %s downloading failed!", username));
|
||||
initSkin = true;
|
||||
}
|
||||
LiteAccountPicker.loading = false;
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
if(image != null && !initSkin) {
|
||||
Client.logger.info(String.format("Crating ResourceLocation of avatar %s...", username));
|
||||
imageLocation = Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation("player_avatar_" + new Random().nextLong(), new DynamicTexture(image));
|
||||
initSkin = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ import net.silentclient.client.gui.elements.IconButton;
|
||||
import net.silentclient.client.gui.font.SilentFontRenderer;
|
||||
import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils;
|
||||
import net.silentclient.client.gui.silentmainmenu.MainMenuConcept;
|
||||
import net.silentclient.client.gui.silentmainmenu.components.AccountPicker;
|
||||
import net.silentclient.client.gui.util.RenderUtil;
|
||||
import net.silentclient.client.utils.ColorUtils;
|
||||
|
||||
@ -21,19 +22,21 @@ import java.net.URI;
|
||||
public class LiteMainMenu extends GuiScreen
|
||||
{
|
||||
private SimpleAnimation bannerAnimation;
|
||||
private AccountPicker accountPicker;
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
this.accountPicker = new LiteAccountPicker(this.width - 100 - 4, 5);
|
||||
this.bannerAnimation = new SimpleAnimation(0);
|
||||
Client.backgroundPanorama.updateWidthHeight(this.width, this.height);
|
||||
|
||||
this.buttonList.clear();
|
||||
this.buttonList.add(new IconButton(1, 4, 5, new ResourceLocation("silentclient/icons/news.png")));
|
||||
this.buttonList.add(new IconButton(2, 26, 5, new ResourceLocation("silentclient/icons/settings/cosmetics.png")));
|
||||
this.buttonList.add(new IconButton(3, 48, 5, new ResourceLocation("silentclient/icons/store_icon.png")));
|
||||
this.buttonList.add(new IconButton(4, 70, 5, new ResourceLocation("silentclient/icons/language.png")));
|
||||
this.buttonList.add(new IconButton(5, 92, 5, new ResourceLocation("silentclient/icons/back.png")));
|
||||
this.buttonList.add(new IconButton(1, 4, 5, 18, 18, 10, 10, new ResourceLocation("silentclient/icons/news.png")));
|
||||
this.buttonList.add(new IconButton(2, 24, 5, 18, 18, 10, 10, new ResourceLocation("silentclient/icons/settings/cosmetics.png")));
|
||||
this.buttonList.add(new IconButton(3, 44, 5, 18, 18, 10, 10, new ResourceLocation("silentclient/icons/store_icon.png")));
|
||||
this.buttonList.add(new IconButton(4, 64, 5, 18, 18, 10, 10, new ResourceLocation("silentclient/icons/language.png")));
|
||||
this.buttonList.add(new IconButton(5, 84, 5, 18, 18, 10, 10, new ResourceLocation("silentclient/icons/back.png")));
|
||||
|
||||
int buttonY = this.height / 2 - 18;
|
||||
|
||||
@ -69,13 +72,15 @@ public class LiteMainMenu extends GuiScreen
|
||||
|
||||
if(GuiNews.imageLocation != null) {
|
||||
if(MouseUtils.isInside(mouseX, mouseY, this.width - 74, this.height - 42, 71, 40)) {
|
||||
this.bannerAnimation.setAnimation(4, 12);
|
||||
this.bannerAnimation.setAnimation(4, 20);
|
||||
} else {
|
||||
this.bannerAnimation.setAnimation(0, 12);
|
||||
this.bannerAnimation.setAnimation(0, 30);
|
||||
}
|
||||
RenderUtil.drawImage(GuiNews.imageLocation, this.width - 74 + (-this.bannerAnimation.getValue()), this.height - 42 + (-this.bannerAnimation.getValue()), 71, 40, false);
|
||||
}
|
||||
|
||||
accountPicker.draw(mc, mouseX, mouseY);
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@ -133,6 +138,8 @@ public class LiteMainMenu extends GuiScreen
|
||||
err.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
accountPicker.onClick(mc, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -163,11 +163,16 @@ public class MainMenuConcept extends SilentScreen {
|
||||
|
||||
// Functions
|
||||
private void loadSkin() {
|
||||
if(image == null && !loading) {
|
||||
if(image == null && !loading && !initSkin) {
|
||||
loading = true;
|
||||
(new Thread("SkinThread") {
|
||||
public void run() {
|
||||
MainMenuConcept.image = SCTextureManager.getImage(String.format("https://mc-heads.net/body/%s/left/1000.png", Client.getInstance().getAccount().getUsername()));
|
||||
BufferedImage skin = SCTextureManager.getImage(String.format("https://mc-heads.net/body/%s/left/1000.png", Client.getInstance().getAccount().getUsername()));
|
||||
if(skin != null) {
|
||||
MainMenuConcept.image = skin;
|
||||
} else {
|
||||
MainMenuConcept.initSkin = true;
|
||||
}
|
||||
MainMenuConcept.loading = false;
|
||||
}
|
||||
}).start();
|
||||
|
@ -10,9 +10,9 @@ import net.silentclient.client.utils.ColorUtils;
|
||||
import java.awt.*;
|
||||
|
||||
public class AccountPicker {
|
||||
private boolean open;
|
||||
private final int x;
|
||||
private final int y;
|
||||
protected boolean open;
|
||||
protected final int x;
|
||||
protected final int y;
|
||||
|
||||
public AccountPicker(int x, int y) {
|
||||
this.x = x;
|
||||
|
BIN
src/main/resources/assets/minecraft/silentclient/icons/dropdown-icon.png
Executable file → Normal file
BIN
src/main/resources/assets/minecraft/silentclient/icons/dropdown-icon.png
Executable file → Normal file
Binary file not shown.
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
Binary file not shown.
After Width: | Height: | Size: 972 B |
Loading…
Reference in New Issue
Block a user