diff options
Diffstat (limited to 'features/friendsGUI')
-rw-r--r-- | features/friendsGUI/index.js | 90 |
1 files changed, 78 insertions, 12 deletions
diff --git a/features/friendsGUI/index.js b/features/friendsGUI/index.js index 0469efd..189f25d 100644 --- a/features/friendsGUI/index.js +++ b/features/friendsGUI/index.js @@ -8,6 +8,9 @@ import BoxWithLoading from "../../../guimanager/GuiElement/BoxWithLoading"; import Feature from "../../featureClass/class"; import GuiPage from "../soopyGui/GuiPage"; import SoopyMouseClickEvent from "../../../guimanager/EventListener/SoopyMouseClickEvent"; +import ButtonWithArrow from "../../../guimanager/GuiElement/ButtonWithArrow"; +import ProgressBar from "../../../guimanager/GuiElement/ProgressBar"; +import logger from "../../logger"; class FriendsGui extends Feature { constructor() { @@ -22,12 +25,7 @@ class FriendsGui extends Feature { 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.registerCommand("soopyunfriendthing", () => { - this.GuiPage.unfriendMode = !this.GuiPage.unfriendMode - ChatLib.chat("UNFRIEND MODE NOW " + this.GuiPage.unfriendMode) - }) this.registerStep(false, 1, () => { this.GuiPage.runComm.call(this.GuiPage) }) - } initVariables() { @@ -61,8 +59,24 @@ class SettingPage extends GuiPage { this.loadedFriends = {} + this.loadedPages = new Set() + this.pageCount = undefined + this.sidebar = new SoopyGuiElement() + + this.sidebarCustomPage = undefined + + this.sidebarMainPage = new SoopyGuiElement().setLocation(0, 0, 1, 1) + + this.sidebarMainPage.addChild( + new ButtonWithArrow().setText("§0Load all friends").setLocation(0.1, 0.1, 0.8, 0.2) + .addEvent(new SoopyMouseClickEvent().setHandler(() => { + this.loadAllFriends() + + this.updateSidebar() + }))) + this.heightPerFriend = 0.2 this.loadingElement = new BoxWithLoading().setLocation(0, 0, 1, 0.175) this.lastLoadedPage = 0 @@ -78,19 +92,59 @@ class SettingPage extends GuiPage { this.commandQueue = [] + this.updateSidebar() this.finaliseLoading() } + loadAllFriends() { + this.sidebarCustomPage = new SoopyGuiElement().setLocation(0, 0, 1, 1) + + this.sidebarCustomPage.addChild(new SoopyTextElement().setText("§0Loading all friends...").setLocation(0.2, 0.1, 0.6, 0.2).setMaxTextScale(10)) + + + let progressBar = new ProgressBar().setProgress(0).setLocation(0.2, 0.5, 0.6, 0.1) + + this.sidebarCustomPage.addChild(progressBar) + for (let i = this.maxLoadedPage + 1; i < this.pageCount + 1; i++) { + let i2 = i + + this.loadFriendPage(i, () => { + progressBar.setProgress(i2 / (this.pageCount + 1), 1000) + + if (i2 === this.pageCount + 1) { + this.sidebarCustomPage = undefined + + this.updateSidebar() + } + }) + } + } + + updateSidebar() { + this.sidebar.clearChildren() + if (this.sidebarCustomPage) { + this.sidebar.addChild(this.sidebarCustomPage) + return + } + this.sidebar.addChild(this.sidebarMainPage) + } + + runCommand(command, callback) { + this.commandQueue.push([command, callback]) + } + runComm() { - if (this.commandQueue.length > 0) { - let c = this.commandQueue.shift() + if (this.commandQueue.length > 0 && this.isOpen()) { + let [c, callback] = this.commandQueue.shift() ChatLib.say(c) + logger.logMessage("running command " + c, 3) + callback() } } friendListMessageEvent(pagenum, maxpages, friendslist, event) { - if (Date.now() - this.lastRender < 1000) { + if (Date.now() - this.lastLoadedPage < 3000) { cancel(event) // console.log("Canceling") } else { @@ -122,7 +176,7 @@ class SettingPage extends GuiPage { currentGame: location.replace("in ", "").replace("currently offline", "&cCurrently offline"), element: new ButtonWithArrowAndDescription().setLocation(0, this.heightPerFriend * Object.keys(this.loadedFriends).length + 1, 1, this.heightPerFriend * 0.875).setText(name).setDesc("&7" + location.replace("in ", "").replace("currently offline", "&cCurrently offline")).addEvent(new SoopyMouseClickEvent().setHandler(() => { if (this.unfriendMode) { - this.commandQueue.push("/friend remove " + ChatLib.removeFormatting(name)) + // this.commandQueue.push("/friend remove " + ChatLib.removeFormatting(name)) this.loadedFriends[ChatLib.removeFormatting(name)].exists = false @@ -165,9 +219,14 @@ class SettingPage extends GuiPage { } } - loadFriendPage(page) { - ChatLib.command("friends list " + page) - this.lastLoadedPage = Date.now() + loadFriendPage(page, callback) { + if (this.loadedPages.has(page)) return + + this.loadedPages.add(page) + this.runCommand("/friends list " + page, () => { + this.lastLoadedPage = Date.now() + if (callback) callback() + }) } onOpen() { @@ -176,9 +235,16 @@ class SettingPage extends GuiPage { this.lastLoadedPage = 0 this.maxLoadedPage = 0 + this.sidebarCustomPage = undefined + this.commandQueue = [] + + this.loadedPages.clear() + this.regenGuiElements() this.loadFriendPage(1) + this.openSidebarPage(this.sidebar) + this.updateSidebar() } } |