diff options
Diffstat (limited to 'features/settings')
-rw-r--r-- | features/settings/index.js | 163 |
1 files changed, 80 insertions, 83 deletions
diff --git a/features/settings/index.js b/features/settings/index.js index 6888f8a..30f653f 100644 --- a/features/settings/index.js +++ b/features/settings/index.js @@ -20,15 +20,15 @@ class SettingsRenderer extends Feature { super() } - onEnable(){ + onEnable() { this.SettingPage = new SettingPage() this.EditLocationsPage = new EditLocationsPage() this.SettingPage.FeatureManager = this.FeatureManager - this.registerStep(true, 1, ()=>{ - if(!this.EditLocationsPage) return - - if(this.EditLocationsPage.needsExitPage){ + this.registerStep(true, 1, () => { + if (!this.EditLocationsPage) return + + if (this.EditLocationsPage.needsExitPage) { this.EditLocationsPage.goToPage(0, 500) this.EditLocationsPage.needsExitPage = false } @@ -36,66 +36,66 @@ class SettingsRenderer extends Feature { } - onDisable(){ + onDisable() { this.EditLocationsPage = undefined this.SettingPage = undefined } } class EditLocationsPage extends GuiPage { - - constructor(){ + + constructor() { super(9) - + this.name = "Edit GUI Locations" this.needsExitPage = false this.soopyGui = new SoopyGui() - this.soopyGui._renderBackground = ()=>{} //remove background darkening + this.soopyGui._renderBackground = () => { } //remove background darkening + - - this.soopyGui.ctGui.registerDraw((mouseX, mouseY, partialTicks)=>{ + this.soopyGui.ctGui.registerDraw((mouseX, mouseY, partialTicks) => { this.renderGui(mouseX, mouseY) this.soopyGui._render(mouseX, mouseY, partialTicks) }) - this.soopyGui.ctGui.registerClicked((mouseX, mouseY, button)=>{ + this.soopyGui.ctGui.registerClicked((mouseX, mouseY, button) => { this.clicked(mouseX, mouseY) this.soopyGui._onClick(mouseX, mouseY, button) }) - this.soopyGui.ctGui.registerMouseReleased((mouseX, mouseY)=>{ + this.soopyGui.ctGui.registerMouseReleased((mouseX, mouseY) => { this.released(mouseX, mouseY) }) this.finaliseLoading() } - - renderGui(mouseX, mouseY){ - for(let setting of locationSettingHolder.getData()){ - if(setting.parent){ - if(setting.parent.isEnabled()){ + + renderGui(mouseX, mouseY) { + for (let setting of locationSettingHolder.getData()) { + if (setting.parent) { + if (setting.parent.isEnabled()) { setting.renderGui(mouseX, mouseY) } - }else{ + } else { setting.renderGui(mouseX, mouseY) } } } - clicked(mouseX, mouseY){ - for(let setting of locationSettingHolder.getData()){ - if(setting.clicked(mouseX, mouseY)) return //dont allow the user to drag 2 locations at once + clicked(mouseX, mouseY) { + for (let setting of locationSettingHolder.getData()) { + if (setting.clicked(mouseX, mouseY)) return //dont allow the user to drag 2 locations at once } } - released(mouseX, mouseY){ - for(let setting of locationSettingHolder.getData()){ + released(mouseX, mouseY) { + for (let setting of locationSettingHolder.getData()) { setting.released(mouseX, mouseY) } } - onOpen(){ + onOpen() { this.needsExitPage = true this.soopyGui.open() @@ -103,9 +103,9 @@ class EditLocationsPage extends GuiPage { } class SettingPage extends GuiPage { - constructor(){ + constructor() { super(10) - + this.name = "Settings" this.pages = [this.newPage(), this.newPage()] @@ -118,20 +118,20 @@ class SettingPage extends GuiPage { this.SettingPage = undefined - this.pages[0].addEvent(new SoopyRenderEvent().setHandler(()=>{this.updateLocs()})) + this.pages[0].addEvent(new SoopyRenderEvent().setHandler(() => { this.updateLocs() })) //############################################################################################### // Settings Category Page //############################################################################################### - + let settingsCategoryTitle = new SoopyTextElement().setText("ยง0Settings").setMaxTextScale(3).setLocation(0.1, 0.05, 0.5, 0.1) this.pages[0].addChild(settingsCategoryTitle) this.settingsCategorySearch = new TextBox().setPlaceholder("Search...").setLocation(0.6, 0.05, 0.3, 0.1) this.pages[0].addChild(this.settingsCategorySearch) - this.settingsCategorySearch.text.addEvent(new SoopyContentChangeEvent().setHandler(()=>{ + this.settingsCategorySearch.text.addEvent(new SoopyContentChangeEvent().setHandler(() => { this.updateSettingCategories() })) @@ -153,7 +153,7 @@ class SettingPage extends GuiPage { this.finaliseLoading() } - onOpen(){ + onOpen() { this.updateSettingCategories() this.settingsCategoryArea.location.scroll.x.set(0, 0) this.settingsCategoryArea.location.scroll.y.set(0, 0) @@ -163,13 +163,13 @@ class SettingPage extends GuiPage { this.updateSettingCategories() } - onOpenPage(p){ - if(p===1) this.updateSettingCategories() + onOpenPage(p) { + if (p === 1) this.updateSettingCategories() this.closeSidebarPage() } - updateSettingCategories(){ + updateSettingCategories() { let search = this.settingsCategorySearch.text.text @@ -177,50 +177,50 @@ class SettingPage extends GuiPage { let height = 0 - Object.keys(this.FeatureManager.featureMetas).sort((a, b)=>{return a.sortA-b.sortA}).forEach((f)=>{ + Object.keys(this.FeatureManager.featureMetas).sort((a, b) => { return a.sortA - b.sortA }).forEach((f) => { let meta = this.FeatureManager.featureMetas[f] let showing = search.length === 0 - if(!showing){ + if (!showing) { showing = meta.name.toLowerCase().includes(search.toLowerCase()) || meta.description.toLowerCase().includes(search.toLowerCase()) } - if(!showing){ - settingsCommunicator.getModuleSettings(f).forEach(setting=>{ + if (!showing) { + settingsCommunicator.getModuleSettings(f).forEach(setting => { - if(setting && (setting.name.toLowerCase().includes(search.toLowerCase()) || setting.description.toLowerCase().includes(search.toLowerCase()))){ + if (setting && (setting.name.toLowerCase().includes(search.toLowerCase()) || setting.description.toLowerCase().includes(search.toLowerCase()))) { showing = true } }) } - if(!showing) return + if (!showing) return let isHidden = meta.isHidden - if(typeof isHidden === "string"){ + if (typeof isHidden === "string") { isHidden = require("../" + f + "/" + isHidden).hidden(this.FeatureManager) } - if(isHidden) return + if (isHidden) return - let category = new ButtonWithArrowAndDescription().setText("&0" + meta.name).setDesc("&0" +meta.description).setLocation(0, height, 1, 0.2) - category.addEvent(new SoopyMouseClickEvent().setHandler(()=>{this.clickedOpenCategory(f)})) + let category = new ButtonWithArrowAndDescription().setText("&0" + meta.name).setDesc("&0" + meta.description).setLocation(0, height, 1, 0.2) + category.addEvent(new SoopyMouseClickEvent().setHandler(() => { this.clickedOpenCategory(f) })) this.settingsCategoryArea.addChild(category) - height+=0.225 + height += 0.225 - - if(search.length > 0){ - settingsCommunicator.getModuleSettings(f).forEach(setting=>{ - if(setting && (setting.name.toLowerCase().includes(search.toLowerCase()) || setting.description.toLowerCase().includes(search.toLowerCase()))){ + if (search.length > 0) { + settingsCommunicator.getModuleSettings(f).forEach(setting => { + + if (setting && (setting.name.toLowerCase().includes(search.toLowerCase()) || setting.description.toLowerCase().includes(search.toLowerCase()))) { setting.getGuiObject().location.location.y.set(height, 0) this.settingsCategoryArea.addChild(setting.getGuiObject()) - - height += 0.025+setting.getGuiObject().location.size.y.get() + + height += 0.025 + setting.getGuiObject().location.size.y.get() setting.update() } @@ -232,7 +232,7 @@ class SettingPage extends GuiPage { // this.FeatureManager.features = {}; enabled features } - updateSettings(category){ + updateSettings(category) { let meta = this.FeatureManager.featureMetas[category] this.settingsArea.children = [] @@ -241,82 +241,79 @@ class SettingPage extends GuiPage { let height = 0 - if(meta.isTogglable){ + if (meta.isTogglable) { let toggle = new BoxWithToggleAndDescription().setLocation(0, height, 1, 0.2).setText("&0Main toggle").setDesc("&0This is the main toggle for the whole category") this.settingsArea.addChild(toggle) toggle.toggle.setValue(this.FeatureManager.isFeatureLoaded(category), 0) - toggle.toggle.addEvent(new SoopyContentChangeEvent().setHandler((newVal, oldVal, resetFun)=>{ + toggle.toggle.addEvent(new SoopyContentChangeEvent().setHandler((newVal, oldVal, resetFun) => { //dont allow editing if currenately loading/unloading it - if(this.modifyingFeature){ + if (this.modifyingFeature) { resetFun() return } //toggle the feature this.modifyingFeature = true - new Thread(()=>{ - this.FeatureManager.featureSettingsData[category].enabled = newVal - this.FeatureManager.featureSettingsDataLastUpdated = true + this.FeatureManager.featureSettingsData[category].enabled = newVal + this.FeatureManager.featureSettingsDataLastUpdated = true - if(!newVal && this.FeatureManager.isFeatureLoaded(category)){ - this.FeatureManager.unloadFeature(category) - } - if(newVal && !this.FeatureManager.isFeatureLoaded(category)){ - this.FeatureManager.loadFeature(category) - } + if (!newVal && this.FeatureManager.isFeatureLoaded(category)) { + this.FeatureManager.unloadFeature(category) + } + if (newVal && !this.FeatureManager.isFeatureLoaded(category)) { + this.FeatureManager.loadFeature(category) + } - Thread.sleep(100) - this.modifyingFeature = false - - this.updateSettings(category) - }).start() + this.modifyingFeature = false + + this.updateSettings(category) })) - height += toggle.location.size.y.get()+0.045 + height += toggle.location.size.y.get() + 0.045 } - if(!this.FeatureManager.isFeatureLoaded(category)){ + if (!this.FeatureManager.isFeatureLoaded(category)) { //only show if feature issnt loaded let textBox = new SoopyBoxElement().setLocation(0, height, 1, 0.2) - .addChild(new SoopyTextElement().setText("&0Feature not loaded").setLocation(0, 0, 1, 0.5)) - .addChild(new SoopyTextElement().setText("&0Load feature to access settings").setLocation(0, 0.5, 1, 0.5)) + .addChild(new SoopyTextElement().setText("&0Feature not loaded").setLocation(0, 0, 1, 0.5)) + .addChild(new SoopyTextElement().setText("&0Load feature to access settings").setLocation(0, 0.5, 1, 0.5)) this.settingsArea.addChild(textBox) return; } - settingsCommunicator.getModuleSettings(category).forEach(setting=>{ + settingsCommunicator.getModuleSettings(category).forEach(setting => { setting.getGuiObject().location.location.y.set(height, 0) this.settingsArea.addChild(setting.getGuiObject()) - height += 0.045+setting.getGuiObject().location.size.y.get() - + height += 0.045 + setting.getGuiObject().location.size.y.get() + setting.update() }) } - updateLocs(){ + updateLocs() { let totalHeight = 0 - this.settingsArea.children.forEach(e=>{ + this.settingsArea.children.forEach(e => { e.location.location.y.set(totalHeight, 0) - totalHeight += e.location.size.y.get()+Math.min(0.045,e.location.size.y.get()) + totalHeight += e.location.size.y.get() + Math.min(0.045, e.location.size.y.get()) }) totalHeight = 0 - this.settingsCategoryArea.children.forEach(e=>{ + this.settingsCategoryArea.children.forEach(e => { e.location.location.y.set(totalHeight, 0) - totalHeight += e.location.size.y.get()+Math.min(0.025,e.location.size.y.get()) + totalHeight += e.location.size.y.get() + Math.min(0.025, e.location.size.y.get()) }) } - clickedOpenCategory(category){ + clickedOpenCategory(category) { this.updateSettings(category) this.goToPage(2) |