diff options
author | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-04-18 00:25:15 +0800 |
---|---|---|
committer | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-04-18 00:25:15 +0800 |
commit | 082d9cf4af63495a3d8709b0ee87dc935ed986dc (patch) | |
tree | e1da1a02907573f68c8052ec5a2a77366385361c /features/hud/HudTextElement.js | |
parent | f718bd5743701a7fb5f96e74a4df75145cc28789 (diff) | |
download | SoopyV2-082d9cf4af63495a3d8709b0ee87dc935ed986dc.tar.gz SoopyV2-082d9cf4af63495a3d8709b0ee87dc935ed986dc.tar.bz2 SoopyV2-082d9cf4af63495a3d8709b0ee87dc935ed986dc.zip |
Many changes
Diffstat (limited to 'features/hud/HudTextElement.js')
-rw-r--r-- | features/hud/HudTextElement.js | 125 |
1 files changed, 72 insertions, 53 deletions
diff --git a/features/hud/HudTextElement.js b/features/hud/HudTextElement.js index be9e4ee..d2a2c91 100644 --- a/features/hud/HudTextElement.js +++ b/features/hud/HudTextElement.js @@ -1,5 +1,5 @@ -class HudTextElement{ - constructor(){ +class HudTextElement { + constructor() { this.text = "" this.toggleSetting = undefined @@ -14,104 +14,123 @@ class HudTextElement{ this.editBaseHeight = undefined this.tempDisableTime = 0 + + this.renderTextCache = [[""], [""]] + this.textChanged = false } - setBaseEditWidth(width){ + setBaseEditWidth(width) { this.editBaseWidth = width return this } - setBaseEditHeight(height){ + setBaseEditHeight(height) { this.editBaseHeight = height return this } - setText(text){ + setText(text = "") { this.text = text - - if(this.locationSetting && this.locationSetting.shadowType === 2){ + + if (this.locationSetting && this.locationSetting.shadowType === 2) { this.blackText = "&0" + ChatLib.removeFormatting(text) } + + this.renderTextCache = [this.text.split("\n"), this.blackText.split("\n")] return this } - setToggleSetting(setting){ + setToggleSetting(setting) { this.toggleSetting = setting return this } - setLocationSetting(setting){ + setLocationSetting(setting) { this.locationSetting = setting setting.setParent(this) - if(this.locationSetting.shadowType === 2){ + if (this.locationSetting.shadowType === 2) { this.blackText = "&0" + ChatLib.removeFormatting(text) } return this } - isEnabled(){ - if(!this.toggleSetting) return true + isEnabled() { + if (!this.toggleSetting) return true return this.locationSetting && this.toggleSetting.getValue() } - render(){ - if(this.toggleSetting && !this.toggleSetting.getValue() || !this.locationSetting) return - if(Date.now()-this.tempDisableTime < 100) return + render() { + if (this.toggleSetting && !this.toggleSetting.getValue() || !this.locationSetting) return + if (Date.now() - this.tempDisableTime < 100) return this.renderRaw() } - getWidth(locationBox=false){ - if(locationBox && this.editBaseWidth) return this.editBaseWidth - return Math.max(...(this.getText()[0].map(a=>Renderer.getStringWidth(ChatLib.removeFormatting(a))))) + getWidth(locationBox = false) { + if (locationBox && this.editBaseWidth) return this.editBaseWidth + return Math.max(...(this.getText()[0].map(a => Renderer.getStringWidth(ChatLib.removeFormatting(a))))) } - getHeight(locationBox=false){ - if(locationBox && this.editBaseHeight) return this.editBaseHeight - return 9*this.getText()[0].length + getHeight(locationBox = false) { + if (locationBox && this.editBaseHeight) return this.editBaseHeight + return 9 * this.getText()[0].length } - getText(){ - let text = this.text - let blackText = this.blackText - if(Date.now()-this.editTempTimeV < 100){ - if(this.editTempTextV){ + getText() { + if (Date.now() - this.editTempTimeV < 100) { + let text = this.text + if (this.editTempTextV) { text = this.editTempTextV - blackText = "&0" + ChatLib.removeFormatting(text) } - - if(ChatLib.removeFormatting(text) === ""){ + + if (ChatLib.removeFormatting(text) === "") { text = "&0Empty string" + } + + return text.split("\n") + } + return this.renderTextCache + } + + getBlackText() { + if (Date.now() - this.editTempTimeV < 100) { + let text = this.text + let blackText = this.blackText + if (this.editTempTextV) { + text = this.editTempTextV + blackText = "&0" + ChatLib.removeFormatting(text) + } + + if (ChatLib.removeFormatting(text) === "") { blackText = "&0Empty string" } + + return blackText.split("\n") } - return [text.split("\n"), blackText.split("\n")] + return this.renderBlackTextCache } - renderRaw(){ - try{ - let [text, blackText] = this.getText() - - text.forEach((line, i)=>{ - Renderer.scale(this.locationSetting.scale, this.locationSetting.scale) - switch(this.locationSetting.shadowType){ - case 0: - Renderer.drawString(line, this.locationSetting.x/this.locationSetting.scale, this.locationSetting.y/this.locationSetting.scale +9*i) + renderRaw() { + let text = this.getText() + + text.forEach((line, i) => { + Renderer.scale(this.locationSetting.scale, this.locationSetting.scale) + switch (this.locationSetting.shadowType) { + case 0: + Renderer.drawString(line, this.locationSetting.x / this.locationSetting.scale, this.locationSetting.y / this.locationSetting.scale + 9 * i) break; - case 1: - Renderer.drawStringWithShadow(line, this.locationSetting.x/this.locationSetting.scale, this.locationSetting.y/this.locationSetting.scale +9*i) + case 1: + Renderer.drawStringWithShadow(line, this.locationSetting.x / this.locationSetting.scale, this.locationSetting.y / this.locationSetting.scale + 9 * i) break; - case 2: - Renderer.drawString(blackText[i], (this.locationSetting.x+1)/this.locationSetting.scale, this.locationSetting.y/this.locationSetting.scale +9*i) - Renderer.drawString(blackText[i], (this.locationSetting.x-1)/this.locationSetting.scale, this.locationSetting.y/this.locationSetting.scale +9*i) - Renderer.drawString(blackText[i], this.locationSetting.x/this.locationSetting.scale, (this.locationSetting.y+1)/this.locationSetting.scale +9*i) - Renderer.drawString(blackText[i], this.locationSetting.x/this.locationSetting.scale, (this.locationSetting.y-1)/this.locationSetting.scale +9*i) - - Renderer.drawString(line, this.locationSetting.x/this.locationSetting.scale, this.locationSetting.y/this.locationSetting.scale +9*i) + case 2: + let blackText = this.getBlackText() + Renderer.drawString(blackText[i], (this.locationSetting.x + 1) / this.locationSetting.scale, this.locationSetting.y / this.locationSetting.scale + 9 * i) + Renderer.drawString(blackText[i], (this.locationSetting.x - 1) / this.locationSetting.scale, this.locationSetting.y / this.locationSetting.scale + 9 * i) + Renderer.drawString(blackText[i], this.locationSetting.x / this.locationSetting.scale, (this.locationSetting.y + 1) / this.locationSetting.scale + 9 * i) + Renderer.drawString(blackText[i], this.locationSetting.x / this.locationSetting.scale, (this.locationSetting.y - 1) / this.locationSetting.scale + 9 * i) + + Renderer.drawString(line, this.locationSetting.x / this.locationSetting.scale, this.locationSetting.y / this.locationSetting.scale + 9 * i) break; - } - }) - Renderer.scale(1, 1) - }catch(e){ //incase of wrong opengl context - } + } + }) } } |