aboutsummaryrefslogtreecommitdiff
path: root/features/settings/settingThings/toggle.js
diff options
context:
space:
mode:
authorSoopyboo32 <49228220+Soopyboo32@users.noreply.github.com>2021-10-31 09:49:42 +0800
committerSoopyboo32 <49228220+Soopyboo32@users.noreply.github.com>2021-10-31 09:49:42 +0800
commit48653ec89538f1650106a5e77463412cad4684c2 (patch)
tree09687cd579462e04d539fd4615369fa6dae13902 /features/settings/settingThings/toggle.js
downloadSoopyV2-48653ec89538f1650106a5e77463412cad4684c2.tar.gz
SoopyV2-48653ec89538f1650106a5e77463412cad4684c2.tar.bz2
SoopyV2-48653ec89538f1650106a5e77463412cad4684c2.zip
first commit
Diffstat (limited to 'features/settings/settingThings/toggle.js')
-rw-r--r--features/settings/settingThings/toggle.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/features/settings/settingThings/toggle.js b/features/settings/settingThings/toggle.js
new file mode 100644
index 0000000..d839b8f
--- /dev/null
+++ b/features/settings/settingThings/toggle.js
@@ -0,0 +1,58 @@
+import Enum from "../../../../guimanager/Enum";
+import SoopyContentChangeEvent from "../../../../guimanager/EventListener/SoopyContentChangeEvent";
+import Toggle from "../../../../guimanager/GuiElement/Toggle";
+import SettingBase from "./settingBase";
+
+class ToggleSetting extends SettingBase {
+ constructor(name, description, defaultVal, settingId, module){
+ super(name, description, defaultVal, settingId, module)
+
+ this.toggleObject = new Toggle().setLocation(0, 0.3, 0.8, 0.4).setValue(this.getValue())
+ this.settingObject.addChild(this.toggleObject)
+
+ this.toggleObject.addEvent(new SoopyContentChangeEvent().setHandler((newVal, oldVal, resetFun)=>{
+ this.setValue(newVal)
+ }))
+
+ }
+
+ setValue(newVal){
+ super.setValue(newVal)
+
+ this.toggleObject.setValue(newVal)
+
+ return this
+ }
+
+ requires(toggleSetting){
+ this.requiresO = toggleSetting
+
+ toggleSetting.toggleObject.addEvent(new SoopyContentChangeEvent().setHandler((newVal, oldVal, resetFun)=>{
+ if(newVal){
+ this.setValue(this.temp_val)
+
+ this.toggleObject.triggerEvent(Enum.EVENT.CONTENT_CHANGE, [this.temp_val, false, ()=>{}])
+
+ this.guiObject.location.size.y.set(0.2, 500)
+ }else{
+ this.temp_val = this.getValue()
+ this.setValue(false)
+
+ this.toggleObject.triggerEvent(Enum.EVENT.CONTENT_CHANGE, [false, this.temp_val, ()=>{}])
+
+ this.guiObject.location.size.y.set(0, 500)
+ }
+ }))
+ let newVal = this.requiresO.getValue()
+ if(!newVal){
+ let temp_val = this.temp_val
+ this.setValue(false)
+ this.temp_val = temp_val
+ this.guiObject.location.size.y.set(0, 0)
+ }
+
+ return this
+ }
+}
+
+export default ToggleSetting \ No newline at end of file