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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
|
import { SoopyGui, SoopyRenderEvent } from "../../../guimanager"
import SoopyKeyPressEvent from "../../../guimanager/EventListener/SoopyKeyPressEvent"
import SoopyMouseClickEvent from "../../../guimanager/EventListener/SoopyMouseClickEvent"
import ButtonWithArrow from "../../../guimanager/GuiElement/ButtonWithArrow"
import ProgressBar from "../../../guimanager/GuiElement/ProgressBar"
import SoopyBoxElement from "../../../guimanager/GuiElement/SoopyBoxElement"
import SoopyGuiElement from "../../../guimanager/GuiElement/SoopyGuiElement"
import SoopyTextElement from "../../../guimanager/GuiElement/SoopyTextElement"
import renderLibs from "../../../guimanager/renderLibs"
import * as utils from "../../utils/utils"
class MuseumGui {
constructor(){
this.checkMenu = false
this.isInMuseum = false
this.guiOpenTickThing = false
this.dontOpen = 0
this.lastClosed = 0
this.itemsInPages = {}
this.soopyGui = new SoopyGui()
this.soopyGui.element.addEvent(new SoopyKeyPressEvent().setHandler((...args)=>{
this.keyPress(...args)
}))
this.mainPage = new SoopyGuiElement().setLocation(0,0,1,1)
this.soopyGui.element.addChild(this.mainPage)
let widthPer = 0.2
let leftOffset = (1-widthPer*3-widthPer*4/5)/2
this.weaponsIndicator = new SoopyBoxElement().setLocation(leftOffset, 0.05, widthPer*4/5, 0.15)
this.weaponsIndicator.addEvent(new SoopyRenderEvent().setHandler(()=>{
if(this.weaponsIndicator.hovered && ChatLib.removeFormatting(Player.getOpenedInventory().getStackInSlot(4).getName()) !== "Weapons"){
this.weaponText.location.location.x.set(0.05, 500)
this.weaponText.location.size.x.set(0.9, 500)
this.weaponText.location.location.y.set(0.025, 500)
this.weaponText.location.size.y.set(0.35, 500)
this.weaponsIndicator.setColorOffset(-20, -20, -20, 100)
Renderer.translate(0,0,100)
Renderer.drawRect(Renderer.color(0,0,0,100), this.weaponsIndicator.location.getXExact(), this.weaponsIndicator.location.getYExact(), this.weaponsIndicator.location.getWidthExact(), this.weaponsIndicator.location.getHeightExact())
let clicks = ChatLib.removeFormatting(Player.getOpenedInventory().getStackInSlot(4).getName())==="Museum"?"1":"2"
Renderer.translate(0,0,100)
renderLibs.drawStringCenteredFull(clicks, this.weaponsIndicator.location.getXExact()+this.weaponsIndicator.location.getWidthExact()/2, this.weaponsIndicator.location.getYExact()+this.weaponsIndicator.location.getHeightExact()/2, Math.min(this.weaponsIndicator.location.getWidthExact()/Renderer.getStringWidth(clicks)/4, this.weaponsIndicator.location.getHeightExact()/4/2))
}else{
this.weaponText.location.location.x.set(0.1, 500)
this.weaponText.location.size.x.set(0.8, 500)
this.weaponText.location.location.y.set(0.05, 500)
this.weaponText.location.size.y.set(0.3, 500)
this.weaponsIndicator.setColorOffset(0, 0, 0, 100)
}
})).addEvent(new SoopyMouseClickEvent().setHandler(()=>{
this.clickedTopButton("Weapons")
}))
this.weaponText = new SoopyTextElement().setText("§5Weapons").setMaxTextScale(10).setLocation(0.1,0.05,0.8,0.3)
this.weaponsIndicator.addChild(this.weaponText)
this.weaponsPercentageText = new SoopyTextElement().setLocation(0.1,0.4,0.8,0.2).setText("§0Items Donated: §7Loading...").setMaxTextScale(10)
this.weaponsIndicator.addChild(this.weaponsPercentageText)
this.weaponsProgressBar = new ProgressBar().setLocation(0.1,0.6,0.8,0.35).showPercentage(true)
this.weaponsIndicator.addChild(this.weaponsProgressBar)
this.mainPage.addChild(this.weaponsIndicator)
this.armourIndicator = new SoopyBoxElement().setLocation(leftOffset+widthPer, 0.05, widthPer*4/5, 0.15)
this.armourIndicator.addEvent(new SoopyRenderEvent().setHandler(()=>{
if(this.armourIndicator.hovered && ChatLib.removeFormatting(Player.getOpenedInventory().getStackInSlot(4).getName()) !== "Armor Sets"){
this.armourText.location.location.x.set(0.05, 500)
this.armourText.location.size.x.set(0.9, 500)
this.armourText.location.location.y.set(0.025, 500)
this.armourText.location.size.y.set(0.35, 500)
this.armourIndicator.setColorOffset(-20, -20, -20, 100)
Renderer.translate(0,0,100)
Renderer.drawRect(Renderer.color(0,0,0,100), this.armourIndicator.location.getXExact(), this.armourIndicator.location.getYExact(), this.armourIndicator.location.getWidthExact(), this.armourIndicator.location.getHeightExact())
let clicks = ChatLib.removeFormatting(Player.getOpenedInventory().getStackInSlot(4).getName())==="Museum"?"1":"2"
Renderer.translate(0,0,100)
renderLibs.drawStringCenteredFull(clicks, this.armourIndicator.location.getXExact()+this.armourIndicator.location.getWidthExact()/2, this.armourIndicator.location.getYExact()+this.armourIndicator.location.getHeightExact()/2, Math.min(this.armourIndicator.location.getWidthExact()/Renderer.getStringWidth(clicks)/4, this.armourIndicator.location.getHeightExact()/4/2))
}else{
this.armourText.location.location.x.set(0.1, 500)
this.armourText.location.size.x.set(0.8, 500)
this.armourText.location.location.y.set(0.05, 500)
this.armourText.location.size.y.set(0.3, 500)
this.armourIndicator.setColorOffset(0, 0, 0, 100)}
})).addEvent(new SoopyMouseClickEvent().setHandler(()=>{
this.clickedTopButton("Armor Sets")
}))
this.armourText = new SoopyTextElement().setText("§5Armor Sets").setMaxTextScale(10).setLocation(0.1,0.05,0.8,0.3)
this.armourIndicator.addChild(this.armourText)
this.armourPercentageText = new SoopyTextElement().setLocation(0.1,0.4,0.8,0.2).setText("§0Items Donated: §7Loading...").setMaxTextScale(10)
this.armourIndicator.addChild(this.armourPercentageText)
this.armourProgressBar = new ProgressBar().setLocation(0.1,0.6,0.8,0.35).showPercentage(true)
this.armourIndicator.addChild(this.armourProgressBar)
this.mainPage.addChild(this.armourIndicator)
this.raritiesIndicator = new SoopyBoxElement().setLocation(leftOffset+widthPer*2, 0.05, widthPer*4/5, 0.15)
this.raritiesIndicator.addEvent(new SoopyRenderEvent().setHandler(()=>{
if(this.raritiesIndicator.hovered && ChatLib.removeFormatting(Player.getOpenedInventory().getStackInSlot(4).getName()) !== "Rarities"){
this.raritiesText.location.location.x.set(0.05, 500)
this.raritiesText.location.size.x.set(0.9, 500)
this.raritiesText.location.location.y.set(0.025, 500)
this.raritiesText.location.size.y.set(0.35, 500)
this.raritiesIndicator.setColorOffset(-20, -20, -20, 100)
Renderer.translate(0,0,100)
Renderer.drawRect(Renderer.color(0,0,0,100), this.raritiesIndicator.location.getXExact(), this.raritiesIndicator.location.getYExact(), this.raritiesIndicator.location.getWidthExact(), this.raritiesIndicator.location.getHeightExact())
let clicks = ChatLib.removeFormatting(Player.getOpenedInventory().getStackInSlot(4).getName())==="Museum"?"1":"2"
Renderer.translate(0,0,100)
renderLibs.drawStringCenteredFull(clicks, this.raritiesIndicator.location.getXExact()+this.raritiesIndicator.location.getWidthExact()/2, this.raritiesIndicator.location.getYExact()+this.raritiesIndicator.location.getHeightExact()/2, Math.min(this.raritiesIndicator.location.getWidthExact()/Renderer.getStringWidth(clicks)/4, this.raritiesIndicator.location.getHeightExact()/4/2))
}else{
this.raritiesText.location.location.x.set(0.1, 500)
this.raritiesText.location.size.x.set(0.8, 500)
this.raritiesText.location.location.y.set(0.05, 500)
this.raritiesText.location.size.y.set(0.3, 500)
this.raritiesIndicator.setColorOffset(0, 0, 0, 100)
}
})).addEvent(new SoopyMouseClickEvent().setHandler(()=>{
this.clickedTopButton("Rarities")
}))
this.raritiesText = new SoopyTextElement().setText("§5Rarities").setMaxTextScale(10).setLocation(0.1,0.05,0.8,0.3)
this.raritiesIndicator.addChild(this.raritiesText)
this.raritiesPercentageText = new SoopyTextElement().setLocation(0.1,0.4,0.8,0.2).setText("§0Items Donated: §7Loading...").setMaxTextScale(10)
this.raritiesIndicator.addChild(this.raritiesPercentageText)
this.raritiesProgressBar = new ProgressBar().setLocation(0.1,0.6,0.8,0.35).showPercentage(true)
this.raritiesIndicator.addChild(this.raritiesProgressBar)
this.mainPage.addChild(this.raritiesIndicator)
this.specialIndicator = new SoopyBoxElement().setLocation(leftOffset+widthPer*3, 0.05, widthPer*4/5, 0.15)
this.specialIndicator.addEvent(new SoopyRenderEvent().setHandler(()=>{
if(this.specialIndicator.hovered && ChatLib.removeFormatting(Player.getOpenedInventory().getStackInSlot(4).getName()) !== "Special Items"){
this.specialText.location.location.x.set(0.05, 500)
this.specialText.location.size.x.set(0.9, 500)
this.specialText.location.location.y.set(0.025, 500)
this.specialText.location.size.y.set(0.35, 500)
this.specialIndicator.setColorOffset(-20, -20, -20, 100)
Renderer.translate(0,0,100)
Renderer.drawRect(Renderer.color(0,0,0,100), this.specialIndicator.location.getXExact(), this.specialIndicator.location.getYExact(), this.specialIndicator.location.getWidthExact(), this.specialIndicator.location.getHeightExact())
let clicks = ChatLib.removeFormatting(Player.getOpenedInventory().getStackInSlot(4).getName())==="Museum"?"1":"2"
Renderer.translate(0,0,100)
renderLibs.drawStringCenteredFull(clicks, this.specialIndicator.location.getXExact()+this.specialIndicator.location.getWidthExact()/2, this.specialIndicator.location.getYExact()+this.specialIndicator.location.getHeightExact()/2, Math.min(this.specialIndicator.location.getWidthExact()/Renderer.getStringWidth(clicks)/4, this.specialIndicator.location.getHeightExact()/4/2))
}else{
this.specialText.location.location.x.set(0.1, 500)
this.specialText.location.size.x.set(0.8, 500)
this.specialText.location.location.y.set(0.05, 500)
this.specialText.location.size.y.set(0.3, 500)
this.specialIndicator.setColorOffset(0, 0, 0, 100)
}
})).addEvent(new SoopyMouseClickEvent().setHandler(()=>{
this.clickedTopButton("Special Items")
}))
this.specialText = new SoopyTextElement().setText("§5Special Items").setMaxTextScale(10).setLocation(0.1,0.05,0.8,0.3)
this.specialIndicator.addChild(this.specialText)
this.specialPercentageText = new SoopyTextElement().setLocation(0.1,0.4,0.8,0.6).setText("§0Items Donated: §7Loading...").setMaxTextScale(10)
this.specialIndicator.addChild(this.specialPercentageText)
this.mainPage.addChild(this.specialIndicator)
let box = new SoopyBoxElement().setLocation(0.5-widthPer/2, 0.25, widthPer, 0.075)
this.pageTitle = new SoopyTextElement().setText("§5Museum").setMaxTextScale(10).setLocation(0,0,1,1)
box.addChild(this.pageTitle)
this.mainPage.addChild(box)
this.itemsBox = new SoopyBoxElement().setLocation(0.5-widthPer*3/2, 0.35, widthPer*3, 0.6).setScrollable(true)
this.mainPage.addChild(this.itemsBox)
}
clickedTopButton(type){
if(ChatLib.removeFormatting(Player.getOpenedInventory().getStackInSlot(4).getName())===type) return
if(ChatLib.removeFormatting(Player.getOpenedInventory().getStackInSlot(4).getName())==="Museum"){
//if on main page can just directly click on it
switch(type){
case "Weapons":
Player.getOpenedInventory().click(19, false, "MIDDLE")
break
case "Armor Sets":
Player.getOpenedInventory().click(21, false, "MIDDLE")
break
case "Rarities":
Player.getOpenedInventory().click(23, false, "MIDDLE")
break
case "Special Items":
Player.getOpenedInventory().click(25, false, "MIDDLE")
break
}
}else{
Player.getOpenedInventory().click(48, false, "MIDDLE")
}
}
tickMenu(){
this.pageTitle.setText("§5"+ChatLib.removeFormatting(Player.getOpenedInventory().getStackInSlot(4).getName()))
if(ChatLib.removeFormatting(Player.getOpenedInventory().getStackInSlot(4).getName())==="Museum"){
if(!Player.getOpenedInventory().getStackInSlot(19)) return
let lore = Player.getOpenedInventory().getStackInSlot(19).getLore()
lore.forEach((line, i)=>{
if(i===0) return
if(line.split(" ")?.[1]?.includes("/")){
let data = ChatLib.removeFormatting(line).split(" ")[1].split("/")
this.weaponsProgressBar.setProgress(parseInt(data[0])/parseInt(data[1]))
this.weaponsPercentageText.setText("§0Items Donated: §7"+data[0]+"/"+data[1])
}
})
this.weaponsIndicator.setLore(lore)
lore = Player.getOpenedInventory().getStackInSlot(21).getLore()
lore.forEach((line, i)=>{
if(i===0) return
if(line.split(" ")?.[1]?.includes("/")){
let data = ChatLib.removeFormatting(line).split(" ")[1].split("/")
this.armourProgressBar.setProgress(parseInt(data[0])/parseInt(data[1]))
this.armourPercentageText.setText("§0Items Donated: §7"+data[0]+"/"+data[1])
}
})
this.armourIndicator.setLore(lore)
lore = Player.getOpenedInventory().getStackInSlot(23).getLore()
lore.forEach((line, i)=>{
if(i===0) return
if(line.split(" ")?.[1]?.includes("/")){
let data = ChatLib.removeFormatting(line).split(" ")[1].split("/")
this.raritiesProgressBar.setProgress(parseInt(data[0])/parseInt(data[1]))
this.raritiesPercentageText.setText("§0Items Donated: §7"+data[0]+"/"+data[1])
}
})
this.raritiesIndicator.setLore(lore)
lore = Player.getOpenedInventory().getStackInSlot(25).getLore()
lore.forEach((line, i)=>{
if(i===0) return
if(ChatLib.removeFormatting(line).startsWith("Items Donated: ")){
this.specialPercentageText.setText("§0Items Donated: §7"+ChatLib.removeFormatting(line).split(": ")[1])
}
})
this.specialIndicator.setLore(lore)
}
let itempages = ["Weapons", "Armor Sets", "Rarities", "Special Items"]
if(itempages.includes(ChatLib.removeFormatting(Player.getOpenedInventory().getStackInSlot(4).getName()))){
let page = ChatLib.removeFormatting(Player.getOpenedInventory().getStackInSlot(4).getName())
let pageNum = 0
Player.getOpenedInventory().getStackInSlot(45).getLore().forEach(line=>{
if(ChatLib.removeFormatting(line).startsWith("Page ")) pageNum = parseInt(ChatLib.removeFormatting(line).split(" ")[1])+1
})
Player.getOpenedInventory().getStackInSlot(53).getLore().forEach(line=>{
if(ChatLib.removeFormatting(line).startsWith("Page ")) pageNum = parseInt(ChatLib.removeFormatting(line).split(" ")[1])-1
})
if(!this.itemsInPages[page]) this.itemsInPages[page] = []
//10-16 43
let changed = false
for(let i = 0;i<3;i++){
for(let j = 10;j<16;j++){
let slot = i*9+j
let item = Player.getOpenedInventory().getStackInSlot(slot)
let sb_id = utils.getSBID(item)
if(sb_id){
if(!this.itemsInPages[page][pageNum]) this.itemsInPages[page][pageNum] = []
if(!this.itemsInPages[page][pageNum][i]) this.itemsInPages[page][pageNum][i] = []
let itemData = {
sb_id: sb_id,
name: item.getName(),
lore: item.getLore()
}
if(JSON.stringify(this.itemsInPages[page][pageNum][i][j]) !== JSON.stringify(itemData)){
this.itemsInPages[page][pageNum][i][j] = itemData
changed = true
}
}
}
}
if(changed) this.regenItems()
}
}
regenItems(){
this.itemsBox.clearChildren()
let page = ChatLib.removeFormatting(Player.getOpenedInventory().getStackInSlot(4).getName())
let y = 0.1
let itemNum = 0
let width = 2
let widthPer = 0.9/(width+1)
let offset = 0.0125
this.itemsInPages[page].forEach(page=>{
if(page === null) return
page.forEach(row=>{
if(row === null) return
row.forEach(slot=>{
if(slot === null) return
let child = new ButtonWithArrow().setText(slot.name.startsWith("§f")?"&7"+slot.name.substr(2):slot.name).setLore(slot.lore).setLocation(0.05+offset+widthPer*itemNum,y,widthPer*9/10,0.15)
this.itemsBox.addChild(child)
itemNum++
if(itemNum>width){
itemNum = 0
y+=0.175
}
})
})
})
}
guiOpened(event){
if(this.dontOpen > 0){
this.dontOpen--
return
}
if(this.soopyGui.ctGui.isOpen()){
cancel(event)
// this.soopyGui.ctGui.open()
return
}
if(this.isInMuseum){
this.soopyGui.ctGui.open()
}else{
this.checkMenu = true
}
}
keyPress(key, keyId){
if(keyId === 1){ //escape key
this.isInMuseum = false
this.dontOpen = 3
}
}
tick(){
if(this.isInMuseum){
if(this.soopyGui.ctGui.isOpen() || this.guiOpenTickThing){
this.tickMenu()
this.guiOpenTickThing = false
}else{
// Client.currentGui.close()
this.isInMuseum = false
this.lastClosed = Date.now()
}
}
if(!(this.soopyGui.ctGui.isOpen() || this.guiOpenTickThing) && Date.now()-this.lastClosed > 1000){
this.weaponsProgressBar.setProgress(0)
this.armourProgressBar.setProgress(0)
this.raritiesProgressBar.setProgress(0)
}
if(this.checkMenu){
if(Player.getOpenedInventory().getName() === "Your Museum" && !this.isInMuseum){
this.isInMuseum = true
this.soopyGui.open()
this.guiOpenTickThing = true
}
this.checkMenu = false
}
if(this.dontOpen > 0){
Client.currentGui.close()
}
}
}
export default MuseumGui;
|