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
|
/// <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 SoopyMouseClickEvent from "../../../guimanager/EventListener/SoopyMouseClickEvent";
import SoopyOpenGuiEvent from "../../../guimanager/EventListener/SoopyOpenGuiEvent";
import SoopyGui2 from "../../../guimanager/SoopyGui";
import categoryManager from "./categoryManager";
class SoopyGui extends Feature {
constructor() {
super()
this.gui = undefined
this.currentPage = 0
this.backButton = undefined
this.categoryPage = undefined
this.currCategory = undefined
this.activePages = []
this.lastClickedOpen = undefined
this.activeCategory = undefined
}
onEnable(){
this.gui = new SoopyGui2()
// this.gui.isDebugEnabled = true
this.registerCommand("soopyv2", this.openCommand)
this.registerCommand("soopy", this.openCommand)
this.mainWindowElement = new SoopyBoxElement().setLocation(0.25, 0.2, 0.5, 0.6)
this.mainWindowElement.addEvent(new SoopyOpenGuiEvent().setHandler(()=>{this.goToPageNum(0, false)}))
//###############################################################################################
// Category Page
//###############################################################################################
this.categoryPage = new SoopyGuiElement().setLocation(0, 0, 1, 1)
let title = new SoopyTextElement().setText("§0Soopy Addons!").setMaxTextScale(3).setLocation(0.1, 0.05, 0.8, 0.1)
this.categoryPage.addChild(title)
this.buttonListElm = new SoopyGuiElement().setLocation(0.1, 0.2, 0.8, 0.8).setScrollable(true)
this.categoryPage.addChild(this.buttonListElm)
//###############################################################################################
// Back button for all second pages
//###############################################################################################
this.backButton = new TextWithArrow().setText("§0Back").setLocation(0.01, -0.2, 0.1, 0.1).setDirectionRight(false)
let backButtonEvent = new SoopyMouseClickEvent().setHandler(()=>{this.clickedBackButton()})
this.backButton.addEvent(backButtonEvent)
this.mainWindowElement.addChild(this.categoryPage)
this.sidebarPage = new SoopyBoxElement().setLocation(0.3, 0.2, 0.3, 0.6)
// this.sidebarPage.visable = false
this.gui.element.addChild(this.sidebarPage)
this.gui.element.addChild(this.mainWindowElement)
this.mainWindowElement.addChild(this.backButton)
this.updateButtons()
}
openCommand(page){
this.gui.open()
if(page){
this.getPages().forEach(p=>{
if(p.name.replace(/ /g, "_").toLowerCase() === page.toLowerCase()){
this.clickedOpen(p, false)
}
})
}
}
getPages(){
return categoryManager.arr
}
updateButtons(){
if(!this.buttonListElm) return;
this.buttonListElm.children = []
this.getPages().forEach((p, i)=>{
let settingsButton = new ButtonWithArrow().setText("§0" + p.name).setLocation(0, 0.225*i, 1, 0.2)
settingsButton.addEvent(new SoopyMouseClickEvent().setHandler(()=>{this.clickedOpen(p)}))
this.buttonListElm.addChild(settingsButton)
})
}
clickedOpen(category, anim=true){
if(!this.lastClickedOpen)this.lastClickedOpen = 0
if(Date.now()-this.lastClickedOpen < 100) return //Stopping infinite loop where button getting reset causes click event to get fired again
this.lastClickedOpen = Date.now()
let theParent = this.mainWindowElement.innerObjectPaddingThing || this.mainWindowElement
theParent.children = []
this.mainWindowElement.addChild(this.categoryPage)
this.mainWindowElement.addChild(this.backButton)
this.activePages = category.pages
this.currCategory = category
Object.values(this.activePages).forEach(p=>{
this.mainWindowElement.addChild(p)
})
this.goToPageNum(1, anim)
category.onOpen()
}
onDisable(){
this.gui.delete()
this.gui = undefined
this.currentPage = 0
this.backButton = undefined
this.activePages = []
this.currCategory = undefined
this.lastClickedOpen = undefined
}
clickedBackButton(){
this.goToPageNum(this.currentPage-1)
}
goToPage(page, animate=true){
let pageNum = page._soopyAddonsPageId
if(pageNum == this.currentPage){
return
}
this.currentPage = pageNum
this.getPages().forEach((p)=>{
Object.values(p.pages).forEach((e, i)=>{
e.location.location.x.set(i-pageNum+1, animate?500:0)
})
})
this.categoryPage.location.location.x.set(-pageNum, animate?500:0)
this.backButton.location.location.y.set((pageNum === 0 || !this.currCategory.showBackButton)?-0.2:0, animate?500:0)
}
goToPageNum(pageNum, animate=true){
if(pageNum<0) return;
this.currentPage = pageNum
if(pageNum===0){
this.currCategory = undefined
this.closeSidebarPage()
this.updateButtons()
}
this.getPages().forEach((p)=>{
Object.values(p.pages).forEach((e, i)=>{
e.location.location.x.set(i-pageNum+1, animate?500:0)
})
})
this.categoryPage.location.location.x.set(-pageNum, animate?500:0)
this.backButton.location.location.y.set((pageNum === 0 || !this.currCategory.showBackButton)?-0.2:0, animate?500:0)
}
openSidebarPage(child){
this.sidebarPage.location.location.x.set(0.625, 500)
this.mainWindowElement.location.location.x.set(0.075, 500)
// this.sidebarPage.visable = true
this.sidebarPage.clearChildren()
this.sidebarPage.addChild(child)
}
closeSidebarPage(){
this.sidebarPage.location.location.x.set(0.3, 500)
this.mainWindowElement.location.location.x.set(0.25, 500)
this.sidebarPage.clearChildren()
// this.sidebarPage.visable = false
}
}
module.exports = {
class: new SoopyGui()
}
|