1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
/// <reference types="../../../CTAutocomplete" />
/// <reference lib="es2015" />
import Feature from "../../featureClass/class";
import SoopyGuiElement from "../../../guimanager/GuiElement/SoopyGuiElement";
import SoopyTextElement from "../../../guimanager/GuiElement/SoopyTextElement";
import SoopyBoxElement from "../../../guimanager/GuiElement/SoopyBoxElement";
import TextWithArrow from "../../../guimanager/GuiElement/TextWithArrow";
import ButtonWithArrow from "../../../guimanager/GuiElement/ButtonWithArrow";
import BoxWithToggleAndDescription from "../../../guimanager/GuiElement/BoxWithToggleAndDescription";
import ButtonWithArrowAndDescription from "../../../guimanager/GuiElement/ButtonWithArrowAndDescription";
import SoopyMouseClickEvent from "../../../guimanager/EventListener/SoopyMouseClickEvent";
import SoopyContentChangeEvent from "../../../guimanager/EventListener/SoopyContentChangeEvent";
import SoopyOpenGuiEvent from "../../../guimanager/EventListener/SoopyOpenGuiEvent";
import settingsCommunicator from "./settingsCommunicator";
import GuiPage from "../soopyGui/GuiPage"
import { SoopyRenderEvent } from "../../../guimanager";
class SettingsRenderer extends Feature {
constructor() {
super()
this.gui = undefined
this.pages = []
this.currentPage = 0
this.backButton = undefined
this.settingsCategoryArea = undefined
this.settingsTitle = undefined
this.settingsArea = undefined
this.modifyingFeature = false
this.featureLoadedTextBox = undefined
this.SettingPage = undefined
}
onEnable(){
this.SettingPage = new SettingPage()
this.SettingPage.FeatureManager = this.FeatureManager
return;
}
onDisable(){
this.SettingPage = undefined
return;
this.gui.delete()
this.pages = []
this.currentPage = 0
this.backButton = undefined
this.settingsArea = undefined
this.settingsTitle = undefined
this.settingsCategoryArea = undefined
this.modifyingFeature = false
this.featureLoadedTextBox = undefined
}
clickedOpenSettings(){
this.goToPage(1)
}
clickedBackButton(){
this.goToPage(this.currentPage-1)
}
goToPage(pageNum, animate=true){
pageNum = Math.max(0, Math.min(pageNum, this.pages.length-1))
if(pageNum == this.currentPage){
return
}
this.currentPage = pageNum
this.pages.forEach((p, i)=>{
p.forEach(e=>{
e.location.location.x.set(i-pageNum, animate?1000:0)
})
})
this.backButton.location.location.y.set(pageNum === 0?-0.2:0, animate?1000:0)
}
}
class SettingPage extends GuiPage {
constructor(){
super(10)
this.name = "Settings"
this.pages = [this.newPage(), this.newPage()]
this.settingsCategoryArea = undefined
this.settingsTitle = undefined
this.settingsArea = undefined
this.modifyingFeature = false
this.featureLoadedTextBox = undefined
this.SettingPage = undefined
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.8, 0.1)
this.pages[0].addChild(settingsCategoryTitle)
this.settingsCategoryArea = new SoopyGuiElement().setLocation(0.1, 0.2, 0.8, 0.8).setScrollable(true)
this.pages[0].addChild(this.settingsCategoryArea)
//###############################################################################################
// Settings Page
//###############################################################################################
this.settingsTitle = new SoopyTextElement().setMaxTextScale(3).setLocation(0.1, 0.05, 0.8, 0.1)
this.pages[1].addChild(this.settingsTitle)
this.settingsArea = new SoopyGuiElement().setLocation(0.1, 0.2, 0.8, 0.8).setScrollable(true)
this.pages[1].addChild(this.settingsArea)
this.finaliseLoading()
}
onOpen(){
this.updateSettingCategories()
this.settingsCategoryArea.location.scroll.x.set(0, 0)
this.settingsCategoryArea.location.scroll.y.set(0, 0)
}
updateSettingCategories(){
this.settingsCategoryArea.children = []
let i = 0
Object.keys(this.FeatureManager.featureMetas).sort((a, b)=>{return a.sortA-b.sortA}).forEach((f)=>{
let meta = this.FeatureManager.featureMetas[f]
let isHidden = meta.isHidden
if(typeof isHidden === "string"){
isHidden = require("../" + f + "/" + isHidden).hidden(this.FeatureManager)
}
if(isHidden) return
let category = new ButtonWithArrowAndDescription().setText("&0" + meta.name).setDesc("&0" +meta.description).setLocation(0, 0.225*i, 1, 0.2)
category.addEvent(new SoopyMouseClickEvent().setHandler(()=>{this.clickedOpenCategory(f)}))
this.settingsCategoryArea.addChild(category)
i++
})
// this.FeatureManager.features = {}; enabled features
}
updateSettings(category){
let meta = this.FeatureManager.featureMetas[category]
this.settingsArea.children = []
this.settingsTitle.setText("&0" + this.FeatureManager.featureMetas[category].name)
let height = 0
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)=>{
//dont allow editing if currenately loading/unloading it
if(this.modifyingFeature){
resetFun()
return
}
//toggle the feature
this.modifyingFeature = true
new Thread(()=>{
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)
}
Thread.sleep(100)
this.modifyingFeature = false
this.updateSettings(category)
}).start()
}))
height += toggle.location.size.y.get()+0.045
}
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))
this.settingsArea.addChild(textBox)
return;
}
settingsCommunicator.getModuleSettings(category).forEach(setting=>{
setting.location.location.y.set(height, 0)
this.settingsArea.addChild(setting)
height += 0.045+setting.location.size.y.get()
})
}
updateLocs(){
let totalHeight = 0
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())
})
}
clickedOpenCategory(category){
this.updateSettings(category)
this.goToPage(2)
this.settingsArea.location.scroll.x.set(0, 0)
this.settingsArea.location.scroll.y.set(0, 0)
}
}
module.exports = {
class: new SettingsRenderer()
}
|