diff options
author | syeyoung <cyoung06@naver.com> | 2023-02-24 15:45:34 +0900 |
---|---|---|
committer | syeyoung <cyoung06@naver.com> | 2023-02-24 15:45:34 +0900 |
commit | 6dbdbf581f2999d137c7bae8fa8363a33b8dfc57 (patch) | |
tree | 24b9cbb761828adf124f1a72e92fe9f648921dc8 /mod/src/main/java/kr/syeyoung | |
parent | bb318751e66f123b46a6c5f06a48f9f566f7eca3 (diff) | |
download | Skyblock-Dungeons-Guide-6dbdbf581f2999d137c7bae8fa8363a33b8dfc57.tar.gz Skyblock-Dungeons-Guide-6dbdbf581f2999d137c7bae8fa8363a33b8dfc57.tar.bz2 Skyblock-Dungeons-Guide-6dbdbf581f2999d137c7bae8fa8363a33b8dfc57.zip |
- chroma and gui formatting
Signed-off-by: syeyoung <cyoung06@naver.com>
Diffstat (limited to 'mod/src/main/java/kr/syeyoung')
8 files changed, 221 insertions, 42 deletions
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/MessageWithLink.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/MessageWithLink.java new file mode 100644 index 00000000..98181c0a --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/MessageWithLink.java @@ -0,0 +1,61 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2023 cyoung06 (syeyoung) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod; + +import javax.swing.*; +import javax.swing.event.HyperlinkEvent; +import javax.swing.event.HyperlinkListener; +import java.awt.*; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; + +public class MessageWithLink extends JEditorPane { + public MessageWithLink(String htmlBody) { + super("text/html", "<html><body style=\"" + getStyle() + "\">" + htmlBody + "</body></html>"); + addHyperlinkListener(new HyperlinkListener() { + @Override + public void hyperlinkUpdate(HyperlinkEvent e) { + if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) { + try { + Desktop.getDesktop().browse(e.getURL().toURI()); + } catch (IOException | URISyntaxException e2) { + e2.printStackTrace(); + } + } + } + }); + setEditable(false); + setBorder(null); + } + + static StringBuffer getStyle() { + // for copying style + JLabel label = new JLabel(); + Font font = label.getFont(); + Color color = label.getBackground(); + + // create some css from the label's font + StringBuffer style = new StringBuffer("font-family:" + font.getFamily() + ";"); + style.append("font-weight:" + (font.isBold() ? "bold" : "normal") + ";"); + style.append("font-size:" + font.getSize() + "pt;"); + style.append("background-color: rgb("+color.getRed()+","+color.getGreen()+","+color.getBlue()+");"); + return style; + } +}
\ No newline at end of file diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/VersionInfo.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/VersionInfo.java index 478a74e9..6f535038 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/VersionInfo.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/VersionInfo.java @@ -22,14 +22,43 @@ import kr.syeyoung.dungeonsguide.launcher.Main; import kr.syeyoung.dungeonsguide.launcher.branch.Update; import kr.syeyoung.dungeonsguide.launcher.branch.UpdateBranch; import kr.syeyoung.dungeonsguide.launcher.branch.UpdateRetrieverUtil; +import kr.syeyoung.dungeonsguide.launcher.gui.screen.GuiDisplayer; import kr.syeyoung.dungeonsguide.launcher.loader.*; +import kr.syeyoung.dungeonsguide.mod.guiv2.GuiScreenAdapter; +import kr.syeyoung.dungeonsguide.mod.guiv2.elements.GlobalHUDScale; +import kr.syeyoung.dungeonsguide.mod.guiv2.elements.Scaler; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraftforge.client.ForgeHooksClient; +import net.minecraftforge.fml.common.FMLCommonHandler; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import javax.swing.*; +import java.io.IOException; import java.util.Optional; +import java.util.Properties; public class VersionInfo { - public static final String VERSION = "4.0.0-beta4.4"; + public static final String VERSION; + public static final int MANDATORY_VERSION; + + static { + int MANDATORY_VERSION1; + String VERSION1; + try { + Properties properties = new Properties(); + properties.load(VersionInfo.class.getResourceAsStream("/versionMeta.properties")); + VERSION1 = properties.getProperty("VERSION"); + MANDATORY_VERSION1 = Integer.parseInt(properties.getProperty("MANDATORY_VERSION", "0")); + } catch (Exception e) { + VERSION1 = "unknown"; + MANDATORY_VERSION1 = 0; + e.printStackTrace(); + } + MANDATORY_VERSION = MANDATORY_VERSION1; + VERSION = VERSION1; + } public static IDGLoader getCurrentLoader() { return Main.getMain().getCurrentLoader(); @@ -43,23 +72,26 @@ public class VersionInfo { private static final Logger logger = LogManager.getLogger("OutdatedVersionWarning"); public static void checkAndOpen() { try { - if (VersionInfo.getCurrentLoader() instanceof DevEnvLoader) return; - - if (VersionInfo.getCurrentLoader() instanceof RemoteLoader) { - RemoteLoader loader = (RemoteLoader) VersionInfo.getCurrentLoader(); - Update latestUpdate = UpdateRetrieverUtil.getLatestUpdates(loader.getBranchId(), 0).get(0); - if (latestUpdate.getId() == loader.getUpdateId()) return; - - // update alarm gui - // show newVersion name - // show update logs - // a button to try updating - - logger.info("Update Required!!"); - // TODO: after new gui framework. - } else if (VersionInfo.getCurrentLoader() instanceof JarLoader || VersionInfo.getCurrentLoader() instanceof LocalLoader) { +// if (VersionInfo.getCurrentLoader() instanceof DevEnvLoader) return; +// +// if (VersionInfo.getCurrentLoader() instanceof RemoteLoader) { +// RemoteLoader loader = (RemoteLoader) VersionInfo.getCurrentLoader(); +// Update latestUpdate = UpdateRetrieverUtil.getLatestUpdates(loader.getBranchId(), 0).get(0); +// if (latestUpdate.getId() == loader.getUpdateId()) return; +// +// Scaler scaler = new Scaler(); +// scaler.scale.setValue((double) new ScaledResolution(Minecraft.getMinecraft()).getScaleFactor()); +// scaler.child.setValue(new WidgetUpdateLog( +// latestUpdate.getName(), latestUpdate.getUpdateLog() +// )); +// GuiDisplayer.INSTANCE.displayGui(new GuiScreenAdapter(scaler)); +// +// logger.info("Update Required!!"); +// } else if (VersionInfo.getCurrentLoader() instanceof JarLoader || VersionInfo.getCurrentLoader() instanceof LocalLoader) { UpdateBranch requiredUpdateBranch = UpdateRetrieverUtil.getUpdateBranches().stream().filter(a -> Optional.ofNullable(a.getMetadata()) + .filter(b -> b.has("additionalMeta")) + .map(b -> b.getJSONObject("additionalMeta")) .filter(b -> b.has("type")) .map(b -> b.getString("type")) .filter(b -> b.equals("update-alarm-github")) @@ -70,16 +102,27 @@ public class VersionInfo { } Update latestUpdate = UpdateRetrieverUtil.getLatestUpdates(requiredUpdateBranch.getId(), 0).get(0); + if (latestUpdate.getMetadata().optInt("mandatory_version",0 ) > (VersionInfo.MANDATORY_VERSION)) { + JOptionPane.showMessageDialog(null, + new MessageWithLink("Your version of Dungeons Guide requires a mandatory update!<br/><br/>" + + "Join our discord at <a href=\"https://discord.gg/dg\">https://discord.gg/dg</a><br/>" + + "Github at <a href=\"https://github.com/Dungeons-Guide/Skyblock-Dungeons-Guide\">https://github.com/Dungeons-Guide/Skyblock-Dungeons-Guide</a>") + , "Dungeons Guide Mandatory Update!", JOptionPane.WARNING_MESSAGE); + FMLCommonHandler.instance().exitJava(9999, false); + } + if (latestUpdate.getName().equals(VersionInfo.VERSION)) return; logger.info("Update Required!!"); - // update alarm gui - // show newVersion name - // link to github url - // show update logs - // TODO: after new gui framework. - } else { - logger.error("Failed to check version: Unknown Loader: " + VersionInfo.getLoaderInfo() + " / " + VersionInfo.getCurrentLoader().getClass().getName()); - } + + Scaler scaler = new Scaler(); + scaler.scale.setValue((double) new ScaledResolution(Minecraft.getMinecraft()).getScaleFactor()); + scaler.child.setValue(new WidgetUpdateLog( + latestUpdate.getName(), latestUpdate.getUpdateLog() + )); + GuiDisplayer.INSTANCE.displayGui(new GuiScreenAdapter(scaler)); +// } else { +// logger.error("Failed to check version: Unknown Loader: " + VersionInfo.getLoaderInfo() + " / " + VersionInfo.getCurrentLoader().getClass().getName()); +// } } catch (Exception e) { logger.error("Error while checking for updates: ",e); } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/WidgetUpdateLog.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/WidgetUpdateLog.java new file mode 100644 index 00000000..cb7903e3 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/WidgetUpdateLog.java @@ -0,0 +1,50 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2023 cyoung06 (syeyoung) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod; + +import kr.syeyoung.dungeonsguide.launcher.Main; +import kr.syeyoung.dungeonsguide.mod.guiv2.BindableAttribute; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.AnnotatedImportOnlyWidget; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.Bind; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.On; +import net.minecraft.client.Minecraft; +import net.minecraft.util.ResourceLocation; + +public class WidgetUpdateLog extends AnnotatedImportOnlyWidget { + @Bind(variableName = "updatelog") + public final BindableAttribute<String> updateLog = new BindableAttribute<>(String.class); + @Bind(variableName = "version") + public final BindableAttribute<String> version = new BindableAttribute<>(String.class); + + public WidgetUpdateLog(String version, String updateLog) { + super(new ResourceLocation("dungeonsguide:gui/update.gui")); + this.version.setValue(version); + this.updateLog.setValue(updateLog); + } + + @On(functionName = "continue") + public void continueB() { + Minecraft.getMinecraft().displayGuiScreen(null); + } + + @On(functionName = "unload") + public void unload() { + Main.getMain().unloadWithoutStacktraceReference(); + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/MainConfigWidget.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/MainConfigWidget.java index f22b0c07..28ad0008 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/MainConfigWidget.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/MainConfigWidget.java @@ -18,6 +18,7 @@ package kr.syeyoung.dungeonsguide.mod.config.guiconfig.configv3; +import kr.syeyoung.dungeonsguide.mod.VersionInfo; import kr.syeyoung.dungeonsguide.mod.config.guiconfig.location2.HUDLocationConfig; import kr.syeyoung.dungeonsguide.mod.features.AbstractFeature; import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry; @@ -43,6 +44,9 @@ public class MainConfigWidget extends AnnotatedImportOnlyWidget { @Bind(variableName = "relocate") public final BindableAttribute<Widget> relocate = new BindableAttribute<>(Widget.class); + @Bind(variableName = "version") + public final BindableAttribute<String> version = new BindableAttribute<>(String.class, VersionInfo.VERSION); + @Bind(variableName = "mainpage") public final BindableAttribute<Widget> mainPage = new BindableAttribute<>(Widget.class, new MainPageWidget()); public MainConfigWidget() { diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/types/AColor.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/types/AColor.java index a031a8f3..0130a11f 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/types/AColor.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/types/AColor.java @@ -56,7 +56,7 @@ public class AColor extends Color { } public Shader getShader() { - if (chroma) return new ChromaShader(chromaSpeed, getRGB()); + if (chroma) return new ChromaShader(this); else return new SingleColorShader(getRGB()); } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/text/TextStyle.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/text/TextStyle.java index 8a89ae25..c2155f21 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/text/TextStyle.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/text/TextStyle.java @@ -47,7 +47,7 @@ public class TextStyle { if (!color.isChroma()) linked.textShader = new SingleColorShader(color.getRGB()); else - linked.textShader = new ChromaShader(color.getChromaSpeed(), color.getRGB()); + linked.textShader = new ChromaShader(color); } public void setBackground(AColor background) { @@ -55,7 +55,7 @@ public class TextStyle { if (!background.isChroma()) linked.backgroundShader = new SingleColorShader(background.getRGB()); else - linked.backgroundShader = new ChromaShader(background.getChromaSpeed(), background.getRGB()); + linked.backgroundShader = new ChromaShader(color); } private ParentDelegatingTextStyle linked = new ParentDelegatingTextStyle(); diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Text.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Text.java index 3a161c55..1f981b92 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Text.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Text.java @@ -18,12 +18,15 @@ package kr.syeyoung.dungeonsguide.mod.guiv2.elements; +import kr.syeyoung.dungeonsguide.mod.config.types.AColor; import kr.syeyoung.dungeonsguide.mod.guiv2.BindableAttribute; import kr.syeyoung.dungeonsguide.mod.guiv2.DomElement; import kr.syeyoung.dungeonsguide.mod.guiv2.Widget; import kr.syeyoung.dungeonsguide.mod.guiv2.elements.richtext.BreakWord; import kr.syeyoung.dungeonsguide.mod.guiv2.elements.richtext.RichText; import kr.syeyoung.dungeonsguide.mod.guiv2.elements.richtext.TextSpan; +import kr.syeyoung.dungeonsguide.mod.guiv2.elements.richtext.shaders.ChromaShader; +import kr.syeyoung.dungeonsguide.mod.guiv2.elements.richtext.shaders.Shader; import kr.syeyoung.dungeonsguide.mod.guiv2.elements.richtext.shaders.SingleColorShader; import kr.syeyoung.dungeonsguide.mod.guiv2.elements.richtext.styles.ParentDelegatingTextStyle; import kr.syeyoung.dungeonsguide.mod.guiv2.xml.AnnotatedExportOnlyWidget; @@ -139,13 +142,18 @@ public class Text extends AnnotatedExportOnlyWidget { char c0 = text.charAt(i); if (c0 == 167 && i + 1 < text.length()) { if (!stringBuilder.toString().isEmpty()) { + AColor chroma =new AColor(255,0,0,255); + chroma.setChromaSpeed(0.3f); + chroma.setChroma(true); + Shader textShader = textColor == null ? null : + textColor== 0x33333333 ? new ChromaShader(chroma) : new SingleColorShader(textColor | 0xFF000000); spans.add(new TextSpan( new ParentDelegatingTextStyle() - .setTextShader(textColor == null ? null : new SingleColorShader(textColor | 0xFF000000)) + .setTextShader(textShader) .setBold(boldStyle) - .setStrikeThroughShader(textColor == null ? null : new SingleColorShader(textColor | 0xFF000000)) + .setStrikeThroughShader(textShader) .setStrikeThrough(strikethroughStyle) - .setUnderlineShader(textColor == null ? null : new SingleColorShader(textColor | 0xFF000000)) + .setUnderlineShader(textShader) .setUnderline(underlineStyle) .setItalics(italicStyle), stringBuilder.toString() @@ -154,8 +162,8 @@ public class Text extends AnnotatedExportOnlyWidget { } - int i1 = "0123456789abcdefklmnor".indexOf(text.toLowerCase(Locale.ENGLISH).charAt(i + 1)); - if (i1 < 16) { + int i1 = "0123456789abcdefklmnorz".indexOf(text.toLowerCase(Locale.ENGLISH).charAt(i + 1)); + if (i1 < 16 || i1 == 22) { boldStyle = false; strikethroughStyle = false; underlineStyle = false; @@ -163,7 +171,10 @@ public class Text extends AnnotatedExportOnlyWidget { if (i1 < 0) { i1 = 15; } - textColor = colorCode[i1]; + if (i1 == 22) + textColor = 0x33333333; + else + textColor = colorCode[i1]; } else if (i1 == 16) { } else if (i1 == 17) { boldStyle = true; @@ -188,13 +199,19 @@ public class Text extends AnnotatedExportOnlyWidget { } if (!stringBuilder.toString().isEmpty()) { + AColor chroma =new AColor(255,0,0,255); + chroma.setChromaSpeed(0.3f); + chroma.setChroma(true); + Shader textShader = textColor == null ? null : + textColor== 0x33333333 ? new ChromaShader(chroma) : new SingleColorShader(textColor | 0xFF000000); + spans.add(new TextSpan( new ParentDelegatingTextStyle() - .setTextShader(textColor == null ? null : new SingleColorShader(textColor | 0xFF000000)) + .setTextShader(textShader) .setBold(boldStyle) - .setStrikeThroughShader(textColor == null ? null : new SingleColorShader(textColor | 0xFF000000)) + .setStrikeThroughShader(textShader) .setStrikeThrough(strikethroughStyle) - .setUnderlineShader(textColor == null ? null : new SingleColorShader(textColor | 0xFF000000)) + .setUnderlineShader(textShader) .setUnderline(underlineStyle) .setItalics(italicStyle), stringBuilder.toString() diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/richtext/shaders/ChromaShader.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/richtext/shaders/ChromaShader.java index 5e1e8bb1..8ee3c5d5 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/richtext/shaders/ChromaShader.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/richtext/shaders/ChromaShader.java @@ -18,21 +18,25 @@ package kr.syeyoung.dungeonsguide.mod.guiv2.elements.richtext.shaders; +import kr.syeyoung.dungeonsguide.mod.config.types.AColor; +import kr.syeyoung.dungeonsguide.mod.utils.RenderUtils; import net.minecraft.client.renderer.GlStateManager; public class ChromaShader implements Shader { - private float r, g, b, a; - public ChromaShader(float chromaSpeed, int color) { - r = ((color >> 16) & 0xFF) / 255.0f; - g = ((color >> 8) & 0xFF) / 255.0f; - b = ((color) & 0xFF) / 255.0f; - a = ((color >> 24) & 0xFF) / 255.0f; + private AColor aColor; + public ChromaShader(AColor aColor) { + this.aColor = aColor; } // argb= @Override public void useShader() { + int color = RenderUtils.getColorAt(0,0,aColor); + float r = ((color >> 16) & 0xFF) / 255.0f; + float g = ((color >> 8) & 0xFF) / 255.0f; + float b = ((color) & 0xFF) / 255.0f; + float a = ((color >> 24) & 0xFF) / 255.0f; GlStateManager.color(r,g,b,a); } |