diff options
author | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-05-22 16:19:11 +0800 |
---|---|---|
committer | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-05-22 16:19:11 +0800 |
commit | 030cbe72bdadea6226f2665cd5c2b2f04e272d9c (patch) | |
tree | adf4e5b8dc917fe069d342d98c8b4c728416b520 | |
parent | a7dcf231cc43c9ef73d6a969203c2dafd2ce8caf (diff) | |
download | SoopyV2-030cbe72bdadea6226f2665cd5c2b2f04e272d9c.tar.gz SoopyV2-030cbe72bdadea6226f2665cd5c2b2f04e272d9c.tar.bz2 SoopyV2-030cbe72bdadea6226f2665cd5c2b2f04e272d9c.zip |
asd
-rw-r--r-- | features/eventsGUI/index.js | 221 | ||||
-rw-r--r-- | features/soopyGui/GuiPage.js | 8 | ||||
-rw-r--r-- | features/soopyGui/index.js | 92 | ||||
-rw-r--r-- | socketConnection.js | 18 |
4 files changed, 286 insertions, 53 deletions
diff --git a/features/eventsGUI/index.js b/features/eventsGUI/index.js index c828f85..d13d792 100644 --- a/features/eventsGUI/index.js +++ b/features/eventsGUI/index.js @@ -1,7 +1,17 @@ /// <reference types="../../../CTAutocomplete" /> /// <reference lib="es2015" /> +import Enum from "../../../guimanager/Enum"; +import SoopyMouseClickEvent from "../../../guimanager/EventListener/SoopyMouseClickEvent"; import BoxWithLoading from "../../../guimanager/GuiElement/BoxWithLoading"; +import ButtonWithArrow from "../../../guimanager/GuiElement/ButtonWithArrow"; +import SoopyGuiElement from "../../../guimanager/GuiElement/SoopyGuiElement"; +import SoopyMarkdownElement from "../../../guimanager/GuiElement/SoopyMarkdownElement"; +import SoopyTextElement from "../../../guimanager/GuiElement/SoopyTextElement"; +import TextBox from "../../../guimanager/GuiElement/TextBox"; import Feature from "../../featureClass/class"; +import socketConnection from "../../socketConnection"; +import { timeSince } from "../../utils/numberUtils"; +import { firstLetterCapital } from "../../utils/stringUtils"; import GuiPage from "../soopyGui/GuiPage"; class EventsGui extends Feature { @@ -12,10 +22,23 @@ class EventsGui extends Feature { onEnable() { this.initVariables() - // this.GuiPage = new EventsPage() //TODO: SOON(tm) + this.GuiPage = new EventsPage() // this.registerChat("&9&m-----------------------------------------------------&r&9${*}&r&9 ${*} &6Friends (Page ${pagenum} of ${maxpages})${friendslist}&r&9&m-----------------------------------------------------&r", (...args) => { this.GuiPage.friendListMessageEvent.call(this.GuiPage, ...args) }) - // this.registerStep(true, 5, () => { this.GuiPage.regenGuiElements.call(this.GuiPage) }) + this.registerStep(true, 5, () => { this.GuiPage.regenGuiElements.call(this.GuiPage) }) + this.registerStep(false, 60, () => { this.GuiPage.pollData.call(this.GuiPage) }) + } + + eventsDataUpdated(data) { + this.GuiPage.eventsDataUpdated(data) + } + + joinEventResult(data) { + this.GuiPage.joinEventResult(data) + } + + pollEventData(admin) { + this.GuiPage.pollEventData(admin) } initVariables() { @@ -32,17 +55,207 @@ class EventsPage extends GuiPage { constructor() { super(8) - this.name = "Guild Events" + this.name = "Events" this.pages = [this.newPage()] - this.pages[0].addChild(new BoxWithLoading().setLocation(0.3, 0.3, 0.4, 0.4)) + this.leaderboardElm = undefined + this.memberData = undefined + + this.lastScroll = 1 + + this.leaderboardChildren = [] + + this.code = undefined this.finaliseLoading() } + updateNotInEvent() { + this.pages[0].clearChildren() + + this.pages[0].addChild(new SoopyTextElement().setText("§0You are not currently in any events").setMaxTextScale(3).setLocation(0.2, 0.1, 0.6, 0.2)) + this.pages[0].addChild(new SoopyTextElement().setText("§0If you have a join code enter it here").setMaxTextScale(1).setLocation(0.3, 0.4, 0.4, 0.1)) + let joinBox = new TextBox().setPlaceholder("Code here").setLocation(0.3, 0.5, 0.4, 0.1) + this.pages[0].addChild(joinBox) + + this.pages[0].addChild(new ButtonWithArrow().setLocation(0.35, 0.6, 0.3, 0.1).setText("§0Join Event").addEvent(new SoopyMouseClickEvent().setHandler(() => { + + let code = joinBox.getText() + + this.pages[0].clearChildren() + this.pages[0].addChild(new BoxWithLoading().setLocation(0.3, 0.3, 0.4, 0.4)) + + socketConnection.pollEventCode(code) + + this.code = code + }))) + } + + updateInEvent(data) { + //MAIN PAGE + + this.pages[0].clearChildren() + + this.pages[0].addChild(new SoopyTextElement().setText("§0You are curently in an event managed by §6" + data.admin).setMaxTextScale(3).setLocation(0.1, 0.05, 0.8, 0.2)) + + if (!data.members[Player.getUUID().toString().replace(/-/g, "")]) { + this.pages[0].addChild(new ButtonWithArrow().setText("Join").setLocation(0.05, 0.2, 0.1, 0.05).addEvent(new SoopyMouseClickEvent().setHandler(() => { + this.pages[0].clearChildren() + this.pages[0].addChild(new BoxWithLoading().setLocation(0.3, 0.3, 0.4, 0.4)) + + socketConnection.pollEventCode(data.code) + + this.code = data.code + }))) + } + + let leaderboard = new SoopyGuiElement().setLocation(0.1, 0.3, 0.8, 0.7).setScrollable(true) + + this.pages[0].addChild(leaderboard) + + let playerPosition = -1 + + if (this.leaderboardElm) { + let scroll = this.leaderboardElm._scrollAmount + + leaderboard._scrollAmount = scroll + leaderboard.location.scroll.y.set(scroll, 0) + } + + this.leaderboardElm = leaderboard + + Object.values(data.members).sort((a, b) => b.progress - a.progress).forEach((m, i) => { + let isPlayer = m.uuid === Player.getUUID().toString().replace(/-/g, "") + + if (isPlayer) playerPosition = i + 1 + + let nameLine = new SoopyTextElement().setText(`${isPlayer ? "§d" : "§0"}#${i + 1} ${m.username}`).setLocation(0, i * 0.05, 0.5, 0.05).setLore(["Last updated " + timeSince(m.timestamp) + " ago"]) + nameLine.timestamp = m.timestamp + leaderboard.addChild(nameLine) + leaderboard.addChild(new SoopyTextElement().setText(`§0+${Math.floor(m.progress)}`).setLocation(0.5, i * 0.05, 0.5, 0.05)) + }) + + this.leaderboardChildren = [...leaderboard.children] + + this.lastScroll = 1 + + if (playerPosition >= 0) { + this.pages[0].addChild(new SoopyTextElement().setText("§0You are #" + playerPosition + " with +" + Math.floor(data.members[Player.getUUID().toString().replace(/-/g, "")].progress)).setMaxTextScale(2).setLocation(0.2, 0.2, 0.6, 0.1)) + } + + // SIDEBAR + + let sideBarElm = new SoopyGuiElement().setLocation(0, 0, 1, 1).setScrollable(true) + + sideBarElm.addChild(new SoopyTextElement().setText("§0Event Settings").setMaxTextScale(3).setLocation(0.1, 0, 0.8, 0.2)) + + sideBarElm.addChild(new SoopyMarkdownElement().setLocation(0.05, 0.2, 0.9, 1).setText("# Tracking: \n" + data.settings.tracking.map(a => firstLetterCapital(a.replace(/\w+?_/, "").replace(/_/g, " "))).join("\n"))) + + this.openSidebarPage(sideBarElm) + } + + regenGuiElements() { + if (!this.isOpen()) return + + if (this.leaderboardElm) { + let scroll = this.leaderboardElm.location.scroll.y.get() + if (this.lastScroll !== scroll) { + this.lastScroll = scroll + + this.leaderboardElm.children = [] + + let min = this.leaderboardElm.location.getYExact() - 100 + let max = min + 200 + this.leaderboardElm.location.getHeightExact() + let lastChildNotAdded = undefined + this.leaderboardChildren.forEach(c => { + c.setParent(this.leaderboardElm) + c.triggerEvent(Enum.EVENT.RESET_FRAME_CACHES) + + let y = c.location.getYExact() + + if (y > min && y < max) { + this.leaderboardElm.children.push(c) + } else { + lastChildNotAdded = c + } + }) + + if (lastChildNotAdded) { + this.leaderboardElm.children.push(lastChildNotAdded) + } + } + + + this.leaderboardChildren.forEach(c => { + if (c.timestamp) { + c.setLore(["Last updated " + timeSince(c.timestamp) + " ago"]) + } + }) + } + } + + eventsDataUpdated(data) { + if (!data.inEvent) { + this.updateNotInEvent() + return + } + + this.updateInEvent(data) + } + + pollEventData(admin) { + if (!admin) { + this.updateNotInEvent() + this.pages[0].addChild(new SoopyTextElement().setText("§cInvalid code").setMaxTextScale(3).setLocation(0.2, 0.7, 0.6, 0.2)) + return + } + this.pages[0].clearChildren() + this.pages[0].addChild(new SoopyTextElement().setText("§0Join §6" + admin + "§0's event?").setMaxTextScale(3).setLocation(0.2, 0.2, 0.6, 0.2)) + this.pages[0].addChild(new ButtonWithArrow().setText("§0Join").setLocation(0.4, 0.4, 0.4, 0.3).addEvent(new SoopyMouseClickEvent().setHandler(() => { + socketConnection.joinEvent(this.code) + this.pages[0].clearChildren() + this.pages[0].addChild(new BoxWithLoading().setLocation(0.3, 0.3, 0.4, 0.4)) + }))) + this.pages[0].addChild(new ButtonWithArrow().setText("§0Cancel").setLocation(0.2, 0.4, 0.2, 0.3).setDirectionRight(false).addEvent(new SoopyMouseClickEvent().setHandler(() => { + this.updateNotInEvent() + }))) + } + + joinEventResult(data) { + this.pages[0].clearChildren() + if (data.success) { + this.pages[0].addChild(new SoopyTextElement().setText("§0Joined event!").setMaxTextScale(3).setLocation(0.2, 0.2, 0.6, 0.2)) + this.pages[0].addChild(new ButtonWithArrow().setText("§0Ok").setLocation(0.3, 0.4, 0.4, 0.4).addEvent(new SoopyMouseClickEvent().setHandler(() => { + this.pages[0].clearChildren() + this.pages[0].addChild(new BoxWithLoading().setLocation(0.3, 0.3, 0.4, 0.4)) + + socketConnection.pollEventData() + }))) + } else { + this.pages[0].addChild(new SoopyTextElement().setText("§0Unable to join event!").setMaxTextScale(3).setLocation(0.2, 0.2, 0.6, 0.1)) + this.pages[0].addChild(new SoopyTextElement().setText("§0" + data.reason).setMaxTextScale(3).setLocation(0.2, 0.3, 0.6, 0.1)) + this.pages[0].addChild(new ButtonWithArrow().setText("§0Ok").setLocation(0.3, 0.4, 0.4, 0.4).addEvent(new SoopyMouseClickEvent().setHandler(() => { + this.pages[0].clearChildren() + this.pages[0].addChild(new BoxWithLoading().setLocation(0.3, 0.3, 0.4, 0.4)) + + socketConnection.pollEventData() + }))) + } + } + + pollData() { + if (!this.isOpen()) return + + socketConnection.pollEventData() + } + onOpen() { + this.pages[0].clearChildren() + this.pages[0].addChild(new BoxWithLoading().setLocation(0.3, 0.3, 0.4, 0.4)) + this.leaderboardElm = undefined + socketConnection.pollEventData() } } diff --git a/features/soopyGui/GuiPage.js b/features/soopyGui/GuiPage.js index f5ac9a5..7a21d26 100644 --- a/features/soopyGui/GuiPage.js +++ b/features/soopyGui/GuiPage.js @@ -19,7 +19,13 @@ class GuiPage { } getSoopyGui() { - return global.soopyv2featuremanagerthing.features["soopyGui"].class + if (global.soopyv2featuremanagerthing.features["soopyGui"]) return global.soopyv2featuremanagerthing.features["soopyGui"].class; + } + + isOpen() { + if (!this.getSoopyGui()?.gui?.ctGui?.isOpen()) return false + + return this.getSoopyGui()?.currCategory === this } newPage() { diff --git a/features/soopyGui/index.js b/features/soopyGui/index.js index 4c8f571..32ac1a7 100644 --- a/features/soopyGui/index.js +++ b/features/soopyGui/index.js @@ -29,7 +29,7 @@ class SoopyGui extends Feature { this.activeCategory = undefined } - onEnable(){ + onEnable() { this.gui = new SoopyGui2() // this.gui.isDebugEnabled = true @@ -39,23 +39,23 @@ class SoopyGui extends Feature { this.mainWindowElement = new SoopyBoxElement().setLocation(0.25, 0.2, 0.5, 0.6) - this.mainWindowElement.addEvent(new SoopyOpenGuiEvent().setHandler(()=>{this.goToPageNum(0, false)})) + this.mainWindowElement.addEvent(new SoopyOpenGuiEvent().setHandler(() => { this.goToPageNum(0, false) })) //############################################################################################### // Category Page //############################################################################################### this.categoryPage = new SoopyGuiElement().setLocation(0, 0, 1, 1) - + let title = new SoopyTextElement().setText("§0SoopyV2!").setMaxTextScale(3).setLocation(0.1, 0.05, 0.5, 0.1) this.categoryPage.addChild(title) let discordButton = new ButtonWithArrow().setText("§0Discord").setLocation(0.7, 0.05, 0.25, 0.1) - discordButton.addEvent(new SoopyMouseClickEvent().setHandler(()=>{ + discordButton.addEvent(new SoopyMouseClickEvent().setHandler(() => { java.awt.Desktop.getDesktop().browse( new java.net.URI("https://discord.gg/dfSMq96RSN") - ); - })) + ); + })) this.categoryPage.addChild(discordButton) this.buttonListElm = new SoopyGuiElement().setLocation(0.1, 0.2, 0.8, 0.8).setScrollable(true) @@ -64,11 +64,11 @@ class SoopyGui extends Feature { //############################################################################################### // Back button for all second pages //############################################################################################### - + this.backButton = new TextWithArrow().setText("§0Back").setLocation(0.01, -0.2, 0.1, 0.1).setDirectionRight(false) - let backButtonEvent = new SoopyMouseClickEvent().setHandler(()=>{this.clickedBackButton()}) + let backButtonEvent = new SoopyMouseClickEvent().setHandler(() => { this.clickedBackButton() }) this.backButton.addEvent(backButtonEvent) - + this.mainWindowElement.addChild(this.categoryPage) this.sidebarPage = new SoopyBoxElement().setLocation(0.3, 0.2, 0.3, 0.6) @@ -76,43 +76,43 @@ class SoopyGui extends Feature { this.gui.element.addChild(this.sidebarPage) this.gui.element.addChild(this.mainWindowElement) - + this.mainWindowElement.addChild(this.backButton) this.updateButtons() } - openCommand(page){ + openCommand(page) { this.gui.open() - if(page){ - this.getPages().forEach(p=>{ - if(p.name.replace(/ /g, "_").toLowerCase() === page.toLowerCase()){ + if (page) { + this.getPages().forEach(p => { + if (p.name.replace(/ /g, "_").toLowerCase() === page.toLowerCase()) { this.clickedOpen(p, false) } }) } } - getPages(){ + getPages() { return categoryManager.arr } - updateButtons(){ - if(!this.buttonListElm) return; + updateButtons() { + if (!this.buttonListElm) return; this.buttonListElm.children = [] - this.getPages().forEach((p, i)=>{ - let settingsButton = new ButtonWithArrow().setText("§0" + p.name).setLocation(0, 0.225*i, 1, 0.2) - settingsButton.addEvent(new SoopyMouseClickEvent().setHandler(()=>{this.clickedOpen(p)})) + this.getPages().forEach((p, i) => { + let settingsButton = new ButtonWithArrow().setText("§0" + p.name).setLocation(0, 0.225 * i, 1, 0.2) + settingsButton.addEvent(new SoopyMouseClickEvent().setHandler(() => { this.clickedOpen(p) })) this.buttonListElm.addChild(settingsButton) }) } - clickedOpen(category, anim=true){ - if(!this.lastClickedOpen)this.lastClickedOpen = 0 - if(Date.now()-this.lastClickedOpen < 100) return //Stopping infinite loop where button getting reset causes click event to get fired again + clickedOpen(category, anim = true) { + if (!this.lastClickedOpen) this.lastClickedOpen = 0 + if (Date.now() - this.lastClickedOpen < 100) return //Stopping infinite loop where button getting reset causes click event to get fired again this.lastClickedOpen = Date.now() let theParent = this.mainWindowElement.innerObjectPaddingThing || this.mainWindowElement @@ -124,7 +124,7 @@ class SoopyGui extends Feature { this.activePages = category.pages this.currCategory = category - Object.values(this.activePages).forEach(p=>{ + Object.values(this.activePages).forEach(p => { this.mainWindowElement.addChild(p) }) @@ -133,7 +133,7 @@ class SoopyGui extends Feature { this.goToPageNum(1, anim) } - onDisable(){ + onDisable() { this.gui.delete() this.gui = undefined @@ -145,50 +145,50 @@ class SoopyGui extends Feature { this.lastClickedOpen = undefined } - clickedBackButton(){ - this.goToPageNum(this.currentPage-1) + clickedBackButton() { + this.goToPageNum(this.currentPage - 1) } - goToPage(page, animate=true){ + goToPage(page, animate = true) { let pageNum = page._soopyAddonsPageId - - if(pageNum == this.currentPage){ + + if (pageNum == this.currentPage) { return } this.currentPage = pageNum - this.getPages().forEach((p)=>{ - Object.values(p.pages).forEach((e, i)=>{ - e.location.location.x.set(i-pageNum+1, animate?500:0) + this.getPages().forEach((p) => { + Object.values(p.pages).forEach((e, i) => { + e.location.location.x.set(i - pageNum + 1, animate ? 500 : 0) }) }) - this.categoryPage.location.location.x.set(-pageNum, animate?500:0) + this.categoryPage.location.location.x.set(-pageNum, animate ? 500 : 0) - this.backButton.location.location.y.set((pageNum === 0 || !this.currCategory.showBackButton)?-0.2:0, animate?500:0) + this.backButton.location.location.y.set((pageNum === 0 || !this.currCategory.showBackButton) ? -0.2 : 0, animate ? 500 : 0) } - goToPageNum(pageNum, animate=true){ - if(pageNum<0) return; + goToPageNum(pageNum, animate = true) { + if (pageNum < 0) return; this.currentPage = pageNum - if(pageNum===0){ + if (pageNum === 0) { this.currCategory = undefined this.closeSidebarPage() this.updateButtons() } - this.getPages().forEach((p)=>{ - Object.values(p.pages).forEach((e, i)=>{ - e.location.location.x.set(i-pageNum+1, animate?500:0) + this.getPages().forEach((p) => { + Object.values(p.pages).forEach((e, i) => { + e.location.location.x.set(i - pageNum + 1, animate ? 500 : 0) }) }) - this.categoryPage.location.location.x.set(-pageNum, animate?500:0) + this.categoryPage.location.location.x.set(-pageNum, animate ? 500 : 0) - this.backButton.location.location.y.set((pageNum === 0 || !this.currCategory.showBackButton)?-0.2:0, animate?500:0) + this.backButton.location.location.y.set((pageNum === 0 || !this.currCategory.showBackButton) ? -0.2 : 0, animate ? 500 : 0) - if(this.currCategory) this.currCategory.onOpenPage(pageNum) + if (this.currCategory) this.currCategory.onOpenPage(pageNum) } - openSidebarPage(child){ + openSidebarPage(child) { this.sidebarPage.location.location.x.set(0.625, 500) this.mainWindowElement.location.location.x.set(0.075, 500) @@ -197,7 +197,7 @@ class SoopyGui extends Feature { this.sidebarPage.addChild(child) } - closeSidebarPage(){ + closeSidebarPage() { this.sidebarPage.location.location.x.set(0.3, 500) this.mainWindowElement.location.location.x.set(0.25, 500) diff --git a/socketConnection.js b/socketConnection.js index b032d39..7e6bb99 100644 --- a/socketConnection.js +++ b/socketConnection.js @@ -20,6 +20,8 @@ class SoopyV2Server extends WebsiteCommunicator { this.userCosmeticPermissions = undefined + this.eventData = undefined + this.cookieCount = 0 this.cookieData = undefined this.cookieDataUpdated = 0 @@ -74,11 +76,16 @@ class SoopyV2Server extends WebsiteCommunicator { this.cookieDataUpdated = Date.now() } if (data.type === "joinEventResult") { - console.log(JSON.stringify(data, undefined, 2)) + if (global.soopyv2featuremanagerthing && global.soopyv2featuremanagerthing.features.eventsGUI) global.soopyv2featuremanagerthing.features.eventsGUI.class.joinEventResult(data.response) } if (data.type === "eventData") { - console.log(JSON.stringify(data, undefined, 2)) + this.eventData = data + if (global.soopyv2featuremanagerthing && global.soopyv2featuremanagerthing.features.eventsGUI) global.soopyv2featuremanagerthing.features.eventsGUI.class.eventsDataUpdated(data) + } + if (data.type === "pollEvent") { + if (global.soopyv2featuremanagerthing && global.soopyv2featuremanagerthing.features.eventsGUI) global.soopyv2featuremanagerthing.features.eventsGUI.class.pollEventData(data.admin) } + } onConnect() { @@ -206,6 +213,13 @@ class SoopyV2Server extends WebsiteCommunicator { type: "eventData" }) } + + pollEventCode(code) { + this.sendData({ + type: "pollEvent", + code + }) + } } if (!global.soopyV2Server) { |