diff options
-rw-r--r-- | features/statHistoryGui/index.js | 164 | ||||
-rw-r--r-- | features/statHistoryGui/metadata.json | 8 | ||||
-rw-r--r-- | features/streamsGUI/index.js | 6 |
3 files changed, 175 insertions, 3 deletions
diff --git a/features/statHistoryGui/index.js b/features/statHistoryGui/index.js new file mode 100644 index 0000000..173137f --- /dev/null +++ b/features/statHistoryGui/index.js @@ -0,0 +1,164 @@ +/// <reference types="../../../CTAutocomplete" /> +/// <reference lib="es2015" /> +import SoopyTextElement from "../../../guimanager/GuiElement/SoopyTextElement"; +import Feature from "../../featureClass/class"; +import GuiPage from "../soopyGui/GuiPage"; +import BoxWithLoading from "../../../guimanager/GuiElement/BoxWithLoading"; +import BoxWithTextAndDescription from "../../../guimanager/GuiElement/BoxWithTextAndDescription"; +import SoopyGuiElement from "../../../guimanager/GuiElement/SoopyGuiElement"; +import TextBox from "../../../guimanager/GuiElement/TextBox"; +import SoopyKeyPressEvent from "../../../guimanager/EventListener/SoopyKeyPressEvent"; +import { firstLetterWordCapital } from "../../utils/stringUtils"; +import SoopyMouseClickEvent from "../../../guimanager/EventListener/SoopyMouseClickEvent"; +import ButtonWithArrow from "../../../guimanager/GuiElement/ButtonWithArrow"; +import { fetch } from "../../utils/networkUtils"; +import SoopyImageElement from "../../../guimanager/GuiElement/SoopyImageElement"; +import renderLibs from "../../../guimanager/renderLibs"; + +class StatHistoryGUI extends Feature { + constructor() { + super() + } + + onEnable() { + this.initVariables() + + this.GuiPage = new StatGraphPage() + + } + + initVariables() { + this.GuiPage = undefined + } + + onDisable() { + this.initVariables() + } +} + + +class StatGraphPage extends GuiPage { + constructor() { + super(7) + + this.name = "Stat Graphs" + + this.pages = [this.newPage()] + + this.pages[0].addChild(new SoopyTextElement().setText("§0Stat Graphs").setMaxTextScale(3).setLocation(0.1, 0.05, 0.6, 0.1)) + let button = new ButtonWithArrow().setText("§0Open in browser").setLocation(0.7, 0.05, 0.2, 0.1) + this.pages[0].addChild(button) + + button.addEvent(new SoopyMouseClickEvent().setHandler(() => { + java.awt.Desktop.getDesktop().browse( + new java.net.URI("https://soopymc.my.to/stathistory") + ); + })) + + this.nameInput = new TextBox().setPlaceholder("Click to search").setLocation(0.1, 0.225, 0.8, 0.1) + this.pages[0].addChild(this.nameInput) + + this.nameInput.addEvent(new SoopyKeyPressEvent().setHandler((key, keyId) => { + if (this.nameInput.text.selected && keyId === 28) { + this.playerLoad = this.nameInput.text.text + this.nameInput.setText("") + this.updateData(this.playerLoad) + } + })) + + this.statArea = new SoopyGuiElement().setLocation(0.05, 0.325, 0.9, 0.675).setScrollable(true) + this.pages[0].addChild(this.statArea) + + this.loadingElm = new BoxWithLoading().setLocation(0.35, 0.4, 0.3, 0.2) + this.errorElm = new BoxWithTextAndDescription().setLocation(0.2, 0.3, 0.6, 0.4).setText("Error!").setDesc("An error occured while loading the data!") + this.statArea.addChild(this.loadingElm) + + this.playerLoad = undefined + + this.finaliseLoading() + } + + updateData(player) { + this.playerLoad = player + + this.statArea._scrollAmount = 0 + this.statArea.location.scroll.y.set(0, 100) + + this.statArea.clearChildren() + this.statArea.addChild(this.loadingElm) + + fetch("http://soopymc.my.to/api/v2/player/" + player).json(playerData => { + + if (player !== this.playerLoad) return + + if (!playerData.success) { + this.statArea.clearChildren() + this.statArea.addChild(this.errorElm) + this.errorElm.setText("§0" + playerData.error.name) + this.errorElm.setDesc("§0" + playerData.error.description) + return + } + + fetch("http://soopymc.my.to/api/v2/player_skyblock/" + playerData.data.uuid).json(skyblockData => { + + if (player !== this.playerLoad) return + + this.statArea.clearChildren() + + if (!skyblockData.success) { + this.statArea.addChild(this.errorElm) + this.errorElm.setText("§0" + skyblockData.error.name) + this.errorElm.setDesc("§0" + skyblockData.error.description) + return + } + + let nameElm = new SoopyTextElement().setText(playerData.data.stats.nameWithPrefix.replace(/§f/g, "§7")).setMaxTextScale(2).setLocation(0.1, 0.05, 0.8, 0.1) + this.statArea.addChild(nameElm) + + fetch("http://soopymc.my.to/statgraphgenerations/" + playerData.data.uuid + "/" + skyblockData.data.stats.bestProfileId).json(graphData => { + if (player !== this.playerLoad) return + + new Thread(() => { + let y = 0.2 + Object.keys(graphData).forEach(type => { + let typeElm = new SoopyTextElement().setText("§0" + firstLetterWordCapital(type.replace("total", ""))).setMaxTextScale(2).setLocation(0.1, y, 0.8, 0.1) + this.statArea.addChild(typeElm) + y += 0.15 + let x = 0.05 + Object.keys(graphData[type]).forEach((graph, i) => { + renderLibs.getImage(graphData[type][graph], true) //load image synchronously into cache so it knows the height + console.log(graphData[type][graph]) + let graphElm = new SoopyImageElement() + this.statArea.addChild(graphElm) + graphElm.setImage(graphData[type][graph]) + + if (i === 0) { + graphElm.setLocation(0.1, y, 0.8, 0.25) + graphElm.loadHeightFromImage() + y += graphElm.location.size.y.get() + 0.05 + } else { + graphElm.setLocation(x, y, 0.4, 0.25) + graphElm.loadHeightFromImage() + x += 0.5 + if (x > 0.7 || i === Object.keys(graphData[type]).length - 1) { + x = 0.05 + y += graphElm.location.size.y.get() + 0.05 + } + } + }) + }) + }).start() + }) + }) + }) + } + + onOpen() { + this.playerLoad = Player.getName() + this.updateData(Player.getName()) + } +} + +module.exports = { + class: new StatHistoryGUI() +}
\ No newline at end of file diff --git a/features/statHistoryGui/metadata.json b/features/statHistoryGui/metadata.json new file mode 100644 index 0000000..9345e0e --- /dev/null +++ b/features/statHistoryGui/metadata.json @@ -0,0 +1,8 @@ +{ + "name": "Stat History GUI", + "description": "Gui for Stat History", + "isHidden": true, + "isTogglable": false, + "defaultEnabled": true, + "sortA": 0 +}
\ No newline at end of file diff --git a/features/streamsGUI/index.js b/features/streamsGUI/index.js index 492728a..d7d75cd 100644 --- a/features/streamsGUI/index.js +++ b/features/streamsGUI/index.js @@ -10,7 +10,6 @@ import SoopyGuiElement from "../../../guimanager/GuiElement/SoopyGuiElement"; import SoopyMouseClickEvent from "../../../guimanager/EventListener/SoopyMouseClickEvent"; import ButtonWithArrow from "../../../guimanager/GuiElement/ButtonWithArrow"; import BoxWithText from "../../../guimanager/GuiElement/BoxWithText"; -import { drawBoxAtBlock } from "../../utils/renderUtils"; import { fetch } from "../../utils/networkUtils"; class StreamsGui extends Feature { @@ -94,9 +93,9 @@ class StreamPage extends GuiPage { let title = new SoopyMarkdownElement().setText(data.title).setLocation(0.1, 0.15, 0.8, 0.1) sidebar.addChild(title) - let image = new SoopyImageElement().setImage(data.image).setLocation(0.1, 0.15 + title.getHeight(), 0.8, 0.4) + let image = new SoopyImageElement().setLocation(0.1, 0.15 + title.getHeight(), 0.8, 0.4).setImage(data.image) sidebar.addChild(image) - image.loadHeightFromImage() + let button = new ButtonWithArrow().setText("§0Watch on Twitch").setLocation(0.1, 0.15 + image.location.size.y.get() + title.getHeight(), 0.8, 0.1) sidebar.addChild(button) @@ -118,6 +117,7 @@ class StreamPage extends GuiPage { button.location.location.y.set(0.15 + image.location.size.y.get() + title.getHeight()) if (language) language.location.location.y.set(0.25 + image.location.size.y.get() + title.getHeight()) }, this) + image.loadHeightFromImage() } onOpen() { |