diff options
author | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2021-10-31 09:49:42 +0800 |
---|---|---|
committer | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2021-10-31 09:49:42 +0800 |
commit | 48653ec89538f1650106a5e77463412cad4684c2 (patch) | |
tree | 09687cd579462e04d539fd4615369fa6dae13902 /features/hud/HudTextElement.js | |
download | SoopyV2-48653ec89538f1650106a5e77463412cad4684c2.tar.gz SoopyV2-48653ec89538f1650106a5e77463412cad4684c2.tar.bz2 SoopyV2-48653ec89538f1650106a5e77463412cad4684c2.zip |
first commit
Diffstat (limited to 'features/hud/HudTextElement.js')
-rw-r--r-- | features/hud/HudTextElement.js | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/features/hud/HudTextElement.js b/features/hud/HudTextElement.js new file mode 100644 index 0000000..582b778 --- /dev/null +++ b/features/hud/HudTextElement.js @@ -0,0 +1,77 @@ +class HudTextElement{ + constructor(){ + this.text = "" + + this.toggleSetting = undefined + this.locationSetting = undefined + + this.blackText = "&0" + ChatLib.removeFormatting(this.text) + + this.editTempTimeV = 0 + this.editTempTextV = undefined + + this.tempDisableTime = 0 + } + + setText(text){ + this.text = text + + if(this.locationSetting.shadowType === 2){ + this.blackText = "&0" + ChatLib.removeFormatting(text) + } + return this + } + setToggleSetting(setting){ + this.toggleSetting = setting + return this + } + setLocationSetting(setting){ + this.locationSetting = setting + setting.setParent(this) + return this + } + + render(){ + if(this.toggleSetting && !this.toggleSetting.getValue() || !this.locationSetting) return + if(Date.now()-this.tempDisableTime < 100) return + + this.renderRaw() + } + + getText(){ + let text = this.text + let blackText = this.blackText + if(this.editTempTextV && Date.now()-this.editTempTimeV < 100){ + text = this.editTempTextV + blackText = "&0" + ChatLib.removeFormatting(text) + } + return [text.split("\n"), blackText.split("\n")] + } + + renderRaw(){ + 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) + break; + 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) + break; + } + }) + Renderer.scale(1, 1) + } +} + +export default HudTextElement
\ No newline at end of file |