Skip to content

Commit

Permalink
added discord stats thing and more changes to the home screen
Browse files Browse the repository at this point in the history
  • Loading branch information
gatooooooo committed Dec 20, 2024
1 parent 47c9f1a commit 009362b
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 45 deletions.
13 changes: 10 additions & 3 deletions src/main/java/me/eldodebug/soar/Glide.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package me.eldodebug.soar;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;

import me.eldodebug.soar.gui.mainmenu.GuiGlideMainMenu;
import me.eldodebug.soar.gui.modmenu.GuiModMenu;
import me.eldodebug.soar.management.remote.discord.DiscordStats;
import me.eldodebug.soar.management.remote.discord.DiscordManager;
import me.eldodebug.soar.management.remote.update.Update;
import me.eldodebug.soar.management.remote.update.UpdateManager;
import org.apache.commons.lang3.ArrayUtils;
Expand Down Expand Up @@ -55,6 +56,7 @@ public class Glide {
private SecurityFeatureManager securityFeatureManager;
private QuickPlayManager quickPlayManager;
private ChangelogManager changelogManager;
private DiscordStats discordStats;
private WaypointManager waypointManager;
private GuiModMenu modMenu;
private GuiGlideMainMenu mainMenu;
Expand All @@ -65,7 +67,7 @@ public class Glide {
public Glide() {
name = "Glide";
version = "7.2";
verIdentifier = 7199;
verIdentifier = 7200;
}

public void start() {
Expand Down Expand Up @@ -96,6 +98,8 @@ public void start() {
securityFeatureManager = new SecurityFeatureManager();
quickPlayManager = new QuickPlayManager();
changelogManager = new ChangelogManager();
discordStats = new DiscordStats();
new DiscordManager();
waypointManager = new WaypointManager();

eventManager.register(new GlideHandler());
Expand Down Expand Up @@ -141,7 +145,6 @@ public FileManager getFileManager() {
return fileManager;
}


public ModManager getModManager() {
return modManager;
}
Expand Down Expand Up @@ -198,6 +201,10 @@ public ChangelogManager getChangelogManager() {
return changelogManager;
}

public DiscordStats getDiscordStats() {
return discordStats;
}

public WaypointManager getWaypointManager() {
return waypointManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import me.eldodebug.soar.Glide;
import me.eldodebug.soar.gui.modmenu.GuiModMenu;
import me.eldodebug.soar.gui.modmenu.category.Category;
import me.eldodebug.soar.management.language.Language;
import me.eldodebug.soar.management.remote.changelog.Changelog;
import me.eldodebug.soar.management.remote.changelog.ChangelogManager;
import me.eldodebug.soar.management.color.AccentColor;
Expand All @@ -17,14 +18,27 @@
import me.eldodebug.soar.management.nanovg.NanoVGManager;
import me.eldodebug.soar.management.nanovg.font.Fonts;
import me.eldodebug.soar.management.nanovg.font.Icon;
import me.eldodebug.soar.management.remote.discord.DiscordManager;
import me.eldodebug.soar.management.remote.discord.DiscordStats;
import me.eldodebug.soar.utils.mouse.MouseUtils;
import me.eldodebug.soar.utils.mouse.Scroll;

public class HomeCategory extends Category {

public HomeCategory(GuiModMenu parent) {
super(parent, TranslateText.HOME, Icon.HOME, false, false);
}

private Scroll changelogScroll = new Scroll();

@Override
public void initGui() {
changelogScroll.resetAll();
new ChangelogManager();
}

Color onlineColour = new Color(85, 155, 89, 255);
Color noColour = new Color(0, 0, 0, 0);

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {

Expand All @@ -34,40 +48,69 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
ColorPalette palette = colorManager.getPalette();
AccentColor currentColor = colorManager.getCurrentColor();
ChangelogManager changelogManager = instance.getChangelogManager();
DiscordStats discStat = instance.getDiscordStats();
int standardPadding = 8;
int outerPadding = 15;

// Changelog

int offsetY = 0;

nvg.drawRoundedRect(this.getX() + 230, this.getY() + 15, 174, 151, 8, palette.getBackgroundColor(ColorType.DARK));
nvg.drawRoundedRect(this.getX() + 230, this.getY() + outerPadding, 174, 151, 8, palette.getBackgroundColor(ColorType.DARK));
nvg.drawText(TranslateText.CHANGELOG.getText(), this.getX() + 230 + 8, this.getY() + 15 + 8, palette.getFontColor(ColorType.DARK), 11F, Fonts.DEMIBOLD);

nvg.save();
nvg.scissor(this.getX() + 230, this.getY() + outerPadding + 20, 174, 131);
nvg.translate(0, changelogScroll.getValue());

for(Changelog c : changelogManager.getChangelogs()) {
float tbSize = nvg.getTextBoxHeight(c.getText(), 8, Fonts.MEDIUM, 174 - 33);
nvg.drawRoundedRect(this.getX() + 230 + 8, this.getY() + 45 + offsetY + ((tbSize/2)-4), 13, 13, 7F, c.getType().getColor());
nvg.drawCenteredText(c.getType().getText(), this.getX() + 230 + 8 + (13 / 2), this.getY() + 47F + offsetY + ((tbSize/2)-4), Color.WHITE, 9, Fonts.ICON);
nvg.drawTextBox(c.getText(), this.getX() + 230 + 25, this.getY() + 48F + offsetY, 174 - 33, palette.getFontColor(ColorType.DARK), 8, Fonts.MEDIUM);
offsetY+= (int) (tbSize + 8);
nvg.drawRoundedRect(this.getX() + 230 + 8, this.getY() + 40 + offsetY + ((tbSize/2)-4), 13, 13, 7F, c.getType().getColor());
nvg.drawCenteredText(c.getType().getText(), this.getX() + 230 + 8 + (13 / 2), this.getY() + 42F + offsetY + ((tbSize/2)-4), Color.WHITE, 9, Fonts.ICON);
nvg.drawTextBox(c.getText(), this.getX() + 230 + 25, this.getY() + 43F + offsetY, 174 - 33, palette.getFontColor(ColorType.DARK), 8, Fonts.MEDIUM);
offsetY+= (int) (tbSize + 9);
}
nvg.restore();

if(MouseUtils.isInside(mouseX, mouseY,this.getX() + 230, this.getY() + outerPadding, 174, 151)) {changelogScroll.onScroll();}
changelogScroll.onAnimation();
changelogScroll.setMaxScroll(offsetY - 120);

nvg.drawVerticalGradientRect(this.getX() + 230 + 8, this.getY() + outerPadding + 20, 174 - 16, 8, palette.getBackgroundColor(ColorType.DARK), noColour);
nvg.drawVerticalGradientRect(this.getX() + 230 + 8, this.getY() + outerPadding + 151 - 8, 174 - 16, 8, noColour, palette.getBackgroundColor(ColorType.DARK));


// Discord
int discordStartX = this.getX() + 230;
int discordStartY = this.getY() + 179;
nvg.drawGradientRoundedRect(discordStartX, discordStartY, 174, 86, 8, currentColor.getColor1(), currentColor.getColor2());
nvg.drawText(TranslateText.JOIN_OUR_DISCORD_SERVER.getText(), discordStartX + 8, discordStartY + 8, Color.WHITE, 11F, Fonts.DEMIBOLD);
nvg.drawTextBox(TranslateText.DISCORD_DESCRIPTION.getText(), discordStartX + 8, discordStartY + 24, 174 - 16, Color.WHITE, 9, Fonts.REGULAR);

nvg.drawRoundedRect(discordStartX + 174 - 60, discordStartY + 58, 52, 18, 10, Color.WHITE);
nvg.drawCenteredText(TranslateText.JOIN.getText() + " >", discordStartX + 174 - 60 + (52 / 2), discordStartY + 63, currentColor.getInterpolateColor(), 7, Fonts.REGULAR);
int discordWidth = 174;
//bg
nvg.drawRoundedRect(discordStartX, discordStartY, discordWidth, 86, 8, palette.getBackgroundColor(ColorType.DARK));
// Discord branding
nvg.drawRoundedRectVarying(discordStartX + discordWidth - 22, discordStartY, 22, 22, 0, 8, 8, 0, new Color(114, 137, 214));
nvg.drawCenteredText(Icon.DISCORD, discordStartX + discordWidth - 11, discordStartY + 4, Color.WHITE, 14F, Fonts.ICON);
// txt
nvg.drawText(TranslateText.JOIN_OUR_DISCORD_SERVER.getText(), discordStartX + standardPadding, discordStartY + standardPadding, palette.getFontColor(ColorType.DARK), 11F, Fonts.DEMIBOLD);
nvg.drawTextBox(TranslateText.DISCORD_DESCRIPTION.getText(), discordStartX + standardPadding, discordStartY + 26, discordWidth - 16, palette.getFontColor(ColorType.DARK), 8, Fonts.REGULAR);
// stats
if(discStat.getMemberCount() != -1){
nvg.drawRoundedRect(discordStartX + 10, discordStartY + 66, 6, 6, 3, onlineColour);
nvg.drawRoundedGlow(discordStartX + 10, discordStartY + 66, 6, 6, 3, onlineColour, 7);
nvg.drawTextGlowing(discStat.getMemberCount() + " Members", discordStartX + 20, discordStartY + 62, onlineColour, 4, 8, Fonts.REGULAR);
nvg.drawTextGlowing(discStat.getMemberOnline() + " Online", discordStartX + 20, discordStartY + 70, onlineColour, 4, 8, Fonts.REGULAR);

}
// join button
nvg.drawRoundedRect(discordStartX + discordWidth - 60, discordStartY + 60, 52, 18, 9, new Color(114, 137, 214));
nvg.drawCenteredText(TranslateText.JOIN.getText() + " >", discordStartX + discordWidth - 60 + (52 / 2), discordStartY + 66, Color.WHITE, 7, Fonts.REGULAR);

}

@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
int discordStartX = this.getX() + 230;
int discordStartY = this.getY() + 179;
if(MouseUtils.isInside(mouseX, mouseY, discordStartX + 174 - 60, discordStartY + 58, 52, 18)) {
if(MouseUtils.isInside(mouseX, mouseY, discordStartX + 174 - 60, discordStartY + 60, 52, 18)) {
try {
Desktop.getDesktop().browse(new URL("https://glideclient.github.io/discord").toURI());
} catch (Exception e) {}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
nvg.save();

nvg.drawRoundedRect(this.getX() + 15, this.getY() + offsetY, this.getWidth() - 30, this.getHeight() - 30, 10, palette.getBackgroundColor(ColorType.DARK));
nvg.drawRect(this.getX() + 15, this.getY() + offsetY + 27, this.getWidth() - 30, 1, palette.getBackgroundColor(ColorType.NORMAL));
nvg.drawText(Icon.ARROW_LEFT, this.getX() + 25, this.getY() + offsetY + 8, palette.getFontColor(ColorType.DARK), 13, Fonts.ICON);
nvg.drawText(Icon.CHEVRON_LEFT, this.getX() + 25, this.getY() + offsetY + 8, palette.getFontColor(ColorType.DARK), 13, Fonts.ICON);
nvg.drawText(currentMod.getName(), this.getX() + 42, this.getY() + offsetY + 9, palette.getFontColor(ColorType.DARK), 13, Fonts.MEDIUM);
nvg.drawText(Icon.REFRESH, this.getX() + this.getWidth() - 39, this.getY() + offsetY + 7.5F, palette.getFontColor(ColorType.DARK), 13, Fonts.ICON);

Expand Down
18 changes: 3 additions & 15 deletions src/main/java/me/eldodebug/soar/management/file/FileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,18 @@

public class FileManager {

private File soarDir, profileDir, cacheDir, musicDir, externalDir,
screenshotDir;
private File soarDir, profileDir, cacheDir, screenshotDir;

public FileManager() {

soarDir = new File(Minecraft.getMinecraft().mcDataDir, "soar");
soarDir = new File(Minecraft.getMinecraft().mcDataDir, "glide");
profileDir = new File(soarDir, "profile");
cacheDir = new File(soarDir, "cache");
musicDir = new File(soarDir, "music");
externalDir = new File(soarDir, "external");
screenshotDir = new File(soarDir, "screenshots");

createDir(soarDir);
createDir(profileDir);
createDir(cacheDir);
createDir(musicDir);
createDir(externalDir);
createDir(screenshotDir);

createVersionFile();
Expand All @@ -36,7 +31,7 @@ private void createVersionFile() {
File versionDir = new File(cacheDir, "version");

createDir(versionDir);
createFile(new File(versionDir, Glide.getInstance().getVersion() + ".tmp"));
createFile(new File(versionDir, Glide.getInstance().getVersionIdentifier() + ".tmp"));
}

public void createDir(File file) {
Expand Down Expand Up @@ -67,11 +62,4 @@ public File getCacheDir() {
return cacheDir;
}

public File getMusicDir() {
return musicDir;
}

public File getExternalDir() {
return externalDir;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,40 @@ public void drawRoundedRectVarying(float x, float y, float width, float height,
NanoVG.nvgFillColor(nvg, nvgColor);
NanoVG.nvgFill(nvg);
}


public void drawVerticalGradientRect(float x, float y, float width, float height, Color color1, Color color2) {

NVGPaint bg = NVGPaint.create();

NanoVG.nvgBeginPath(nvg);
NanoVG.nvgRect(nvg, x, y, width, height);

NVGColor nvgColor1 = getColor(color1);
NVGColor nvgColor2 = getColor(color2);

NanoVG.nvgFillColor(nvg, nvgColor1);
NanoVG.nvgFillColor(nvg, nvgColor2);

NanoVG.nvgFillPaint(nvg, NanoVG.nvgLinearGradient(nvg, x, y, x, y+height, nvgColor1, nvgColor2, bg));
NanoVG.nvgFill(nvg);
}

public void drawGradientRect(float x, float y, float width, float height, Color color1, Color color2) {

NVGPaint bg = NVGPaint.create();

float tick = ((System.currentTimeMillis() % 3600) / 570F);
float max = Math.max(width, height);

NanoVG.nvgBeginPath(nvg);
NanoVG.nvgRect(nvg, x, y, width, height);

NVGColor nvgColor1 = getColor(color1);
NVGColor nvgColor2 = getColor(color2);

NanoVG.nvgFillColor(nvg, nvgColor1);
NanoVG.nvgFillColor(nvg, nvgColor2);

NanoVG.nvgFillPaint(nvg, NanoVG.nvgLinearGradient(nvg, x + width / 2 - (max / 2) * MathUtils.cos(tick), y + height / 2 - (max / 2) * MathUtils.sin(tick), x + width / 2 + (max / 2) * MathUtils.cos(tick), y + height / 2 + (max + 2f) * MathUtils.sin(tick), nvgColor1, nvgColor2, bg));
NanoVG.nvgFill(nvg);
}
Expand Down Expand Up @@ -259,6 +276,17 @@ public void drawGradientShadow(float x, float y, float width, float height, floa
alpha+=3;
}
}
public void drawRoundedGlow(float x, float y, float width, float height, float radius, Color color1, int strength) {

int alpha = 1;

for(float f = strength; f > 0; f--) {
drawGradientOutlineRoundedRect(x - (f / 2), y - (f / 2), width + f, height + f, radius + 2, f, ColorUtils.applyAlpha(color1, alpha), ColorUtils.applyAlpha(color1, alpha));

alpha+=2;
}
}


public void drawCircle(float x, float y, float radius, Color color) {

Expand Down Expand Up @@ -318,6 +346,29 @@ public void drawText(String text, float x, float y, Color color, float size, Fon
NanoVG.nvgText(nvg, x, y, text);
}

public void drawTextGlowing(String text, float x, float y, Color color, float blurRadius, float size, Font font) {
drawTextGlowingBg(text, x, y, color, size, blurRadius, font);
drawText(text, x,y, color, size, font);
}

private void drawTextGlowingBg(String text, float x, float y, Color color, float size, float blurRadius, Font font) {
y+=size / 2;

NanoVG.nvgBeginPath(nvg);
NanoVG.nvgFontSize(nvg, size);
NanoVG.nvgFontFace(nvg, font.getName());
NanoVG.nvgTextAlign(nvg, NanoVG.NVG_ALIGN_LEFT | NanoVG.NVG_ALIGN_MIDDLE);
NVGColor nvgColor = getColor(color);
NanoVG.nvgFillColor(nvg, nvgColor);
save();
fontBlur(blurRadius);
NanoVG.nvgText(nvg, x, y, text);
restore();
}




public void drawTextBox(String text, float x, float y, float maxWidth, Color color, float size, Font font) {

y += size / 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import me.eldodebug.soar.management.nanovg.font.Icon;

public enum ChangelogType {
ADDED(0, Icon.PLUS, new Color(68, 200, 129)),
FIXED(1, Icon.REFRESH, new Color(220, 220, 68)),
REMOVED(2, Icon.MINUS, new Color(220, 68, 68)),
ERROR(999, Icon.PROHIBITED, new Color(255, 0, 0));
ADDED(0, Icon.PLUS, new Color(0, 142, 65)),
FIXED(1, Icon.REFRESH, new Color(207, 112, 3)),
REMOVED(2, Icon.MINUS, new Color(209, 34, 34)),
ERROR(999, Icon.PROHIBITED, new Color(143, 0, 0));

private int id;
private String string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package me.eldodebug.soar.management.remote.discord;

import com.google.gson.JsonObject;
import me.eldodebug.soar.Glide;
import me.eldodebug.soar.utils.JsonUtils;
import me.eldodebug.soar.utils.Multithreading;
import me.eldodebug.soar.utils.network.HttpUtils;

public class DiscordManager {
public DiscordManager() {Multithreading.runAsync(this::checkDiscordValues);}

public void checkDiscordValues(){
DiscordStats discordStats = Glide.getInstance().getDiscordStats();
JsonObject jsonObject = HttpUtils.readJson("https://discord.com/api/v9/invites/42PXqKvwxq?with_counts=true", null);

if(jsonObject != null) {
discordStats.setMemberCount(JsonUtils.getIntProperty(jsonObject, "approximate_member_count", -1));
discordStats.setMemberOnline(JsonUtils.getIntProperty(jsonObject, "approximate_presence_count", -1));
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package me.eldodebug.soar.management.remote.discord;

public class DiscordStats {
int membersCount = -1;
int membersOnline = -1;

public void setMemberCount(int in){
this.membersCount = in;
}
public int getMemberCount(){return membersCount;}
public void setMemberOnline(int in){
this.membersOnline = in;
}
public int getMemberOnline(){return membersOnline;}

}
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ text.specialcape=特別なケープ
text.customcape=カスタムケープ
text.error=エラー
text.premiumonly=この機能はプレミアム専用です
text.joindiscordserver=Discordサーバーに参加する
text.joindiscordserver=Discord に参加する
text.join=参加する
text.discorddescription=サポートを受けたり、コミュニティ内の人々と交流する
text.customsound=カスタムサウンド
Expand Down

0 comments on commit 009362b

Please sign in to comment.