aboutsummaryrefslogtreecommitdiff
path: root/features/friendsGUI/index.js
diff options
context:
space:
mode:
authorSoopyboo32 <49228220+Soopyboo32@users.noreply.github.com>2022-08-06 14:27:41 +0800
committerSoopyboo32 <49228220+Soopyboo32@users.noreply.github.com>2022-08-06 14:27:41 +0800
commit913dd7e3ada823233abc104212d97b5d447a4b96 (patch)
tree2543e024e7d27442090e461b729521117dd792a1 /features/friendsGUI/index.js
parente4a1af5c855c380cd4dd6ee4f84b3580112d91da (diff)
downloadSoopyV2-913dd7e3ada823233abc104212d97b5d447a4b96.tar.gz
SoopyV2-913dd7e3ada823233abc104212d97b5d447a4b96.tar.bz2
SoopyV2-913dd7e3ada823233abc104212d97b5d447a4b96.zip
custom friends menu overhaul + meta
Diffstat (limited to 'features/friendsGUI/index.js')
-rw-r--r--features/friendsGUI/index.js158
1 files changed, 134 insertions, 24 deletions
diff --git a/features/friendsGUI/index.js b/features/friendsGUI/index.js
index 189f25d..718f514 100644
--- a/features/friendsGUI/index.js
+++ b/features/friendsGUI/index.js
@@ -11,6 +11,7 @@ import SoopyMouseClickEvent from "../../../guimanager/EventListener/SoopyMouseCl
import ButtonWithArrow from "../../../guimanager/GuiElement/ButtonWithArrow";
import ProgressBar from "../../../guimanager/GuiElement/ProgressBar";
import logger from "../../logger";
+import SoopyMarkdownElement from "../../../guimanager/GuiElement/SoopyMarkdownElement";
class FriendsGui extends Feature {
constructor() {
@@ -61,6 +62,10 @@ class SettingPage extends GuiPage {
this.loadedPages = new Set()
+ this.selectedFriends = new Set()
+
+ this.allFriendsLoaded = false
+
this.pageCount = undefined
this.sidebar = new SoopyGuiElement()
@@ -69,14 +74,6 @@ class SettingPage extends GuiPage {
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
@@ -98,27 +95,65 @@ class SettingPage extends GuiPage {
}
loadAllFriends() {
+ let commands = []
+ for (let i = this.maxLoadedPage + 1; i < this.pageCount + 1; i++) {
+ commands.push("/friend list " + i)
+ }
+
+ this.runCommandsArray(commands)
+ }
+
+ runCommandsArray(commands, callback) {
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))
+ this.sidebarCustomPage.addChild(
+ new ButtonWithArrow().setText("§0CANCEL!").setLocation(0.1, 0.20, 0.8, 0.1)
+ .addEvent(new SoopyMouseClickEvent().setHandler(() => {
+ this.commandQueue = []
+ this.sidebarCustomPage = undefined
- let progressBar = new ProgressBar().setProgress(0).setLocation(0.2, 0.5, 0.6, 0.1)
+ this.updateSidebar()
+
+ if (callback) callback()
+ })))
+
+ this.sidebarCustomPage.addChild(new SoopyTextElement().setText("§0Running commands...").setLocation(0.2, 0.1, 0.6, 0.1).setMaxTextScale(10))
+
+
+ let progressBar = new ProgressBar().setProgress(0).setLocation(0.2, 0.3, 0.6, 0.1)
+
+ let elements = []
this.sidebarCustomPage.addChild(progressBar)
- for (let i = this.maxLoadedPage + 1; i < this.pageCount + 1; i++) {
+ for (let i = 0; i < commands.length; i++) {
let i2 = i
- this.loadFriendPage(i, () => {
- progressBar.setProgress(i2 / (this.pageCount + 1), 1000)
+ elements.push(new SoopyTextElement().setText("§0" + commands[i]).setLocation(0.2, 0.4 + i * 0.05, 0.6, 0.05))
+
+ this.runCommand(commands[i], () => {
+ progressBar.setProgress(i2 / (commands.length - 1), 1000)
+
+ let e = elements.shift()
+ this.sidebarCustomPage.removeChild(e)
- if (i2 === this.pageCount + 1) {
+ elements.forEach((e, i) => {
+ e.location.location.y.set(0.4 + i * 0.05, 500)
+ })
+
+ if (i2 === commands.length - 1) {
this.sidebarCustomPage = undefined
this.updateSidebar()
+
+ if (callback) callback()
}
})
}
+
+ for (let e of elements) {
+ this.sidebarCustomPage.addChild(e)
+ }
}
updateSidebar() {
@@ -127,6 +162,62 @@ class SettingPage extends GuiPage {
this.sidebar.addChild(this.sidebarCustomPage)
return
}
+
+ this.sidebarMainPage.clearChildren()
+ if (this.selectedFriends.size > 0) {
+ this.sidebarMainPage.addChild(
+ new SoopyTextElement().setText("§0" + this.selectedFriends.size + " friends selected").setMaxTextScale(2).setLocation(0.1, 0.05, 0.8, 0.1))
+
+ this.sidebarMainPage.addChild(
+ new ButtonWithArrow().setText("§0Deselect all").setLocation(0.1, 0.15, 0.8, 0.1)
+ .addEvent(new SoopyMouseClickEvent().setHandler(() => {
+ this.selectedFriends.clear()
+
+ this.regenGuiElements()
+ this.updateSidebar()
+ })))
+ this.sidebarMainPage.addChild(
+ new ButtonWithArrow().setText("§0Unfriend all").setLocation(0.1, 0.25, 0.8, 0.1)
+ .addEvent(new SoopyMouseClickEvent().setHandler(() => {
+ let commands = []
+
+ for (let f of this.selectedFriends) {
+ this.loadedFriends[f].exists = false
+ commands.push("/friend remove " + f)
+ }
+ this.selectedFriends.clear()
+
+ this.runCommandsArray(commands)
+ this.updateSidebar()
+ })))
+
+
+ } else {
+ if (!this.allFriendsLoaded) {
+ 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()
+ })))
+ } else {
+ this.sidebarMainPage.addChild(
+ new ButtonWithArrow().setText("§0Select all").setLocation(0.1, 0.1, 0.8, 0.2)
+ .addEvent(new SoopyMouseClickEvent().setHandler(() => {
+
+ Object.keys(this.loadedFriends).forEach((ign, i) => {
+ if (this.loadedFriends[ign].exists) {
+ this.selectedFriends.add(ign)
+ }
+ })
+
+ this.regenGuiElements()
+ this.updateSidebar()
+ })))
+ }
+ }
+
this.sidebar.addChild(this.sidebarMainPage)
}
@@ -144,7 +235,7 @@ class SettingPage extends GuiPage {
}
friendListMessageEvent(pagenum, maxpages, friendslist, event) {
- if (Date.now() - this.lastLoadedPage < 3000) {
+ if (Date.now() - this.lastLoadedPage < 3000 || this.isOpen()) {
cancel(event)
// console.log("Canceling")
} else {
@@ -155,6 +246,8 @@ class SettingPage extends GuiPage {
this.pageCount = parseInt(maxpages)
+ this.allFriendsLoaded = this.maxLoadedPage === this.pageCount
+
friendslist = friendslist.replace(/\-\>newLine\<\-/g, "\n").split("\n")
friendslist.shift()
@@ -175,13 +268,7 @@ class SettingPage extends GuiPage {
exists: true,
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.loadedFriends[ChatLib.removeFormatting(name)].exists = false
-
- this.regenGuiElements()
- }
+ this.clickedOn(ChatLib.removeFormatting(name))
}))
}
this.loadedFriends[ChatLib.removeFormatting(name)].element.location.location.y.set(this.heightPerFriend * Object.keys(this.loadedFriends).length - this.heightPerFriend, 500 + 100 * i)
@@ -192,6 +279,20 @@ class SettingPage extends GuiPage {
this.regenGuiElements()
}
+ clickedOn(name) {
+ if (this.selectedFriends.has(name)) {
+ this.selectedFriends.delete(name)
+ } else {
+ this.selectedFriends.add(name)
+ }
+ // this.commandQueue.push("/friend remove " + ChatLib.removeFormatting(name))
+
+ // this.loadedFriends[ChatLib.removeFormatting(name)].exists = false
+
+ this.regenGuiElements()
+ this.updateSidebar()
+ }
+
regenGuiElements() {
if (Date.now() - this.lastRender < 1000) {
this.friendsArea.children = []
@@ -203,8 +304,17 @@ class SettingPage extends GuiPage {
let maxY = -scroll + 1.5
Object.keys(this.loadedFriends).forEach((ign, i) => {
- if (this.loadedFriends[ign].exists && this.loadedFriends[ign].element.location.location.y.get() > minY && this.loadedFriends[ign].element.location.location.y.get() < maxY) {
- this.friendsArea.addChild(this.loadedFriends[ign].element)
+ /**@type {ButtonWithArrowAndDescription} */
+ let e = this.loadedFriends[ign].element
+
+ if (this.loadedFriends[ign].exists && e.location.location.y.get() > minY && e.location.location.y.get() < maxY) {
+ this.friendsArea.addChild(e)
+
+ if (this.selectedFriends.has(ign)) {
+ e.setColor(100, 255, 100)
+ } else {
+ e.setColor(253, 255, 227)
+ }
}
})