aboutsummaryrefslogtreecommitdiff
path: root/features/settings/settingThings/location.js
diff options
context:
space:
mode:
authorSoopyboo32 <49228220+Soopyboo32@users.noreply.github.com>2022-05-07 17:24:45 +0800
committerSoopyboo32 <49228220+Soopyboo32@users.noreply.github.com>2022-05-07 17:24:45 +0800
commit5cd8bd6a4c0a61d3258816ae4a9666daade4d2da (patch)
treee48eedccaa1ed83e559d288d8afc76146f2bf736 /features/settings/settingThings/location.js
parent8392c362f9e9e5c387204b3a4ea78d15b9c69262 (diff)
downloadSoopyV2-5cd8bd6a4c0a61d3258816ae4a9666daade4d2da.tar.gz
SoopyV2-5cd8bd6a4c0a61d3258816ae4a9666daade4d2da.tar.bz2
SoopyV2-5cd8bd6a4c0a61d3258816ae4a9666daade4d2da.zip
fixes
Diffstat (limited to 'features/settings/settingThings/location.js')
-rw-r--r--features/settings/settingThings/location.js212
1 files changed, 106 insertions, 106 deletions
diff --git a/features/settings/settingThings/location.js b/features/settings/settingThings/location.js
index b5a6f1c..70e1527 100644
--- a/features/settings/settingThings/location.js
+++ b/features/settings/settingThings/location.js
@@ -10,12 +10,12 @@ import SoopyContentChangeEvent from "../../../../guimanager/EventListener/SoopyC
import locationSettingHolder from "../locationSettingHolder"
class LocationSetting extends ButtonSetting {
- constructor(name, description, settingId, module, defaultLocation){
+ constructor(name, description, settingId, module, defaultLocation) {
super(name, description, settingId, module, "Edit Position", this.editPosition, defaultLocation)
- this.x = this.getValue()[0]
- this.y = this.getValue()[1]
- this.scale = this.getValue()[2]
+ this.x = this.getValue()[0] ?? 10
+ this.y = this.getValue()[1] ?? 10
+ this.scale = this.getValue()[2] || 1
this.shadowType = this.getValue()[3] //0-none, 1-vanilla, 2-border
this.editTempTextV = undefined
@@ -24,12 +24,12 @@ class LocationSetting extends ButtonSetting {
this.dragOffset = [0, 0]
this.resisizing = false
this.resizePoint = 0
- this.resizeInitialPos=[0, 0, 0, 0, 0, 0]
+ this.resizeInitialPos = [0, 0, 0, 0, 0, 0]
this.parent = undefined
this.soopyGui = new SoopyGui()
- this.soopyGui._renderBackground = ()=>{} //remove background darkening
+ this.soopyGui._renderBackground = () => { } //remove background darkening
this.elmSettings = new SoopyBoxElement().setLocation(0, 0, 0.25, 0.25)
@@ -38,37 +38,37 @@ class LocationSetting extends ButtonSetting {
scaleText.centeredX = false
this.elmSettings.addChild(scaleText)
- this.scaleInput = new NumberTextBox().setText(this.scale.toFixed(2)).setLocation(Renderer.getStringWidth("Scale: ")+3, 0.025, -(Renderer.getStringWidth("Scale: ")+6), 0.15)
+ this.scaleInput = new NumberTextBox().setText(this.scale?.toFixed(2) || "?.??").setLocation(Renderer.getStringWidth("Scale: ") + 3, 0.025, -(Renderer.getStringWidth("Scale: ") + 6), 0.15)
this.scaleInput.location.location.setRelative(false, true)
this.scaleInput.location.size.setRelative(false, true)
this.elmSettings.addChild(this.scaleInput)
- this.scaleInput.text.addEvent(new SoopyContentChangeEvent().setHandler((newVal, oldVal, resetFun)=>{
- try{
+ this.scaleInput.text.addEvent(new SoopyContentChangeEvent().setHandler((newVal, oldVal, resetFun) => {
+ try {
newVal = parseFloat(newVal)
- if(!isNaN(newVal)){
+ if (!isNaN(newVal)) {
this.scale = newVal
this._updateValue()
}
- }catch(e){}
+ } catch (e) { }
}))
- this.lastScaleRender = this.scale.toFixed(2)
+ this.lastScaleRender = this.scale?.toFixed(2) || "?.??"
let xText = new SoopyTextElement().setText("&0X: ").setLocation(3, 0.225, 1, 0.15)
xText.location.location.setRelative(false, true)
xText.centeredX = false
this.elmSettings.addChild(xText)
- this.xInput = new NumberTextBox().setText(this.x.toFixed(0)).setLocation(Renderer.getStringWidth("X: ")+3, 0.225, -(Renderer.getStringWidth("X: ")+6), 0.15)
+ this.xInput = new NumberTextBox().setText(this.x.toFixed(0)).setLocation(Renderer.getStringWidth("X: ") + 3, 0.225, -(Renderer.getStringWidth("X: ") + 6), 0.15)
this.xInput.location.location.setRelative(false, true)
this.xInput.location.size.setRelative(false, true)
this.elmSettings.addChild(this.xInput)
- this.xInput.text.addEvent(new SoopyContentChangeEvent().setHandler((newVal, oldVal, resetFun)=>{
- try{
+ this.xInput.text.addEvent(new SoopyContentChangeEvent().setHandler((newVal, oldVal, resetFun) => {
+ try {
newVal = parseFloat(newVal)
- if(!isNaN(newVal)){
+ if (!isNaN(newVal)) {
this.x = newVal
this._updateValue()
}
- }catch(e){}
+ } catch (e) { }
}))
this.lastXRender = this.x.toFixed(0)
@@ -76,25 +76,25 @@ class LocationSetting extends ButtonSetting {
yText.location.location.setRelative(false, true)
yText.centeredX = false
this.elmSettings.addChild(yText)
- this.yInput = new NumberTextBox().setText(this.y.toFixed(0)).setLocation(Renderer.getStringWidth("Y: ")+3, 0.425, -(Renderer.getStringWidth("Y: ")+6), 0.15)
+ this.yInput = new NumberTextBox().setText(this.y.toFixed(0)).setLocation(Renderer.getStringWidth("Y: ") + 3, 0.425, -(Renderer.getStringWidth("Y: ") + 6), 0.15)
this.yInput.location.location.setRelative(false, true)
this.yInput.location.size.setRelative(false, true)
this.elmSettings.addChild(this.yInput)
- this.yInput.text.addEvent(new SoopyContentChangeEvent().setHandler((newVal, oldVal, resetFun)=>{
- try{
+ this.yInput.text.addEvent(new SoopyContentChangeEvent().setHandler((newVal, oldVal, resetFun) => {
+ try {
newVal = parseFloat(newVal)
- if(!isNaN(newVal)){
+ if (!isNaN(newVal)) {
this.y = newVal
this._updateValue()
}
- }catch(e){}
+ } catch (e) { }
}))
this.lastYRender = this.y.toFixed(0)
this.soopyGui.element.addChild(this.elmSettings)
let button = new ButtonWithArrow().setText("&0Reset").setLocation(0.125, 0.625, 0.75, 0.15)
- button.addEvent(new SoopyMouseClickEvent().setHandler(()=>{
+ button.addEvent(new SoopyMouseClickEvent().setHandler(() => {
this.x = defaultLocation[0]
this.y = defaultLocation[1]
this.scale = defaultLocation[2]
@@ -103,7 +103,7 @@ class LocationSetting extends ButtonSetting {
this.elmSettings.addChild(button)
let button2 = new ButtonWithArrow().setText("&0Back").setLocation(0.125, 0.825, 0.75, 0.15)
- button2.addEvent(new SoopyMouseClickEvent().setHandler(()=>{
+ button2.addEvent(new SoopyMouseClickEvent().setHandler(() => {
this.soopyGui.close()
this.guiObject.main.ctGui.open()
}))
@@ -111,83 +111,83 @@ class LocationSetting extends ButtonSetting {
this.editGui = this.soopyGui.ctGui
- this.editGui.registerDraw((mouseX, mouseY, partialTicks)=>{
+ this.editGui.registerDraw((mouseX, mouseY, partialTicks) => {
this.renderGui(mouseX, mouseY)
this.soopyGui._render(mouseX, mouseY, partialTicks)
})
- this.editGui.registerClicked((mouseX, mouseY, button)=>{
+ this.editGui.registerClicked((mouseX, mouseY, button) => {
this.clicked(mouseX, mouseY)
this.soopyGui._onClick(mouseX, mouseY, button)
})
- this.editGui.registerMouseReleased((mouseX, mouseY)=>{
+ this.editGui.registerMouseReleased((mouseX, mouseY) => {
this.released(mouseX, mouseY)
})
locationSettingHolder.addLocationSetting(this)
}
- requires(toggleSetting){
+ requires(toggleSetting) {
this.requiresO = toggleSetting
- toggleSetting.toggleObject.addEvent(new SoopyContentChangeEvent().setHandler((newVal, oldVal, resetFun)=>{
- if(newVal){
+ toggleSetting.toggleObject.addEvent(new SoopyContentChangeEvent().setHandler((newVal, oldVal, resetFun) => {
+ if (newVal) {
this.guiObject.location.size.y.set(0.2, 500)
- }else{
+ } else {
this.guiObject.location.size.y.set(0, 500)
}
}))
let newVal = this.requiresO.getValue()
- if(!newVal){
+ if (!newVal) {
this.guiObject.location.size.y.set(0, 0)
}
return this
}
- _updateValue(){
+ _updateValue() {
this.setValue([this.x, this.y, this.scale, this.shadowType])
}
- editTempText(text){
+ editTempText(text) {
this.editTempTextV = text
return this;
}
- setParent(parent){
+ setParent(parent) {
this.parent = parent
}
- editPosition(){
+ editPosition() {
this.guiObject.main.ctGui.close()
this.soopyGui.open()
}
- clicked(mouseX, mouseY){
+ clicked(mouseX, mouseY) {
let width = this.getWidth()
let height = this.parent.getHeight(true)
- let locations = [[this.x, this.y], [this.x+width*this.scale, this.y], [this.x, this.y+height*this.scale], [this.x+width*this.scale, this.y+height*this.scale]]
+ let locations = [[this.x, this.y], [this.x + width * this.scale, this.y], [this.x, this.y + height * this.scale], [this.x + width * this.scale, this.y + height * this.scale]]
- locations.forEach((loc, i)=>{
- if(mouseX >= loc[0]-1*Math.max(1, this.scale) && mouseX <= loc[0]+1*Math.max(1, this.scale)
- && mouseY >= loc[1]-1*Math.max(1, this.scale) && mouseY <= loc[1]+1*Math.max(1, this.scale)){
- this.resisizing= true
+ locations.forEach((loc, i) => {
+ if (mouseX >= loc[0] - 1 * Math.max(1, this.scale) && mouseX <= loc[0] + 1 * Math.max(1, this.scale)
+ && mouseY >= loc[1] - 1 * Math.max(1, this.scale) && mouseY <= loc[1] + 1 * Math.max(1, this.scale)) {
+ this.resisizing = true
this.resizePoint = i
- this.resizeInitialPos = [mouseX, mouseY, this.x, this.y, width*this.scale, height*this.scale]
+ this.resizeInitialPos = [mouseX, mouseY, this.x, this.y, width * this.scale, height * this.scale]
}
})
- if(this.resisizing) return;
+ if (this.resisizing) return;
- if(mouseX > this.x && mouseX < this.x+width*this.scale
- && mouseY>this.y && mouseY<this.y+height*this.scale){
+ if (mouseX > this.x && mouseX < this.x + width * this.scale
+ && mouseY > this.y && mouseY < this.y + height * this.scale) {
this.dragging = true;
- this.dragOffset = [this.x-mouseX, this.y-mouseY]
+ this.dragOffset = [this.x - mouseX, this.y - mouseY]
return true
}
return false
}
- released(mouseX, mouseY){
+ released(mouseX, mouseY) {
this.updateLocation(mouseX, mouseY)
this.dragging = false
this.resisizing = false
@@ -195,90 +195,90 @@ class LocationSetting extends ButtonSetting {
this._updateValue()
}
- getWidth(){
+ getWidth() {
return this.parent.getWidth(true)
}
- updateLocation(mouseX, mouseY, drawCollidingBox){
+ updateLocation(mouseX, mouseY, drawCollidingBox) {
let width = this.getWidth()
let height = this.parent.getHeight(true)
- if(this.dragging){
- this.x = mouseX+this.dragOffset[0]
- this.y = mouseY+this.dragOffset[1]
+ if (this.dragging) {
+ this.x = mouseX + this.dragOffset[0]
+ this.y = mouseY + this.dragOffset[1]
let snapPoints = []
- locationSettingHolder.getData().forEach(loc=>{
- if(loc === this) return;
+ locationSettingHolder.getData().forEach(loc => {
+ if (loc === this) return;
snapPoints.push([loc.x, loc.y])
- snapPoints.push([loc.x+loc.getWidth()*loc.scale, loc.y])
- snapPoints.push([loc.x+loc.getWidth()*loc.scale, loc.y+height*loc.scale])
- snapPoints.push([loc.x, loc.y+height*loc.scale])
+ snapPoints.push([loc.x + loc.getWidth() * loc.scale, loc.y])
+ snapPoints.push([loc.x + loc.getWidth() * loc.scale, loc.y + height * loc.scale])
+ snapPoints.push([loc.x, loc.y + height * loc.scale])
})
- snapPoints.forEach(point=>{
+ snapPoints.forEach(point => {
//top left
- if(Math.abs(this.x-point[0]) < 5 && Math.abs(this.y-point[1]) < 5){
+ if (Math.abs(this.x - point[0]) < 5 && Math.abs(this.y - point[1]) < 5) {
this.x = point[0]
this.y = point[1]
}
//top right
- if(Math.abs(this.x+width*this.scale-point[0]) < 5 && Math.abs(this.y-point[1]) < 5){
- this.x = point[0]-width*this.scale
+ if (Math.abs(this.x + width * this.scale - point[0]) < 5 && Math.abs(this.y - point[1]) < 5) {
+ this.x = point[0] - width * this.scale
this.y = point[1]
}
//bottom left
- if(Math.abs(this.x-point[0]) < 5 && Math.abs(this.y+height*this.scale-point[1]) < 5){
+ if (Math.abs(this.x - point[0]) < 5 && Math.abs(this.y + height * this.scale - point[1]) < 5) {
this.x = point[0]
- this.y = point[1]-height*this.scale
+ this.y = point[1] - height * this.scale
}
//bottom right
- if(Math.abs(this.x+width*this.scale-point[0]) < 5 && Math.abs(this.y+height*this.scale-point[1]) < 5){
- this.x = point[0]-width*this.scale
- this.y = point[1]-height*this.scale
+ if (Math.abs(this.x + width * this.scale - point[0]) < 5 && Math.abs(this.y + height * this.scale - point[1]) < 5) {
+ this.x = point[0] - width * this.scale
+ this.y = point[1] - height * this.scale
}
})
}
- if(this.resisizing){
- if(this.resizePoint === 3){
- this.scale=(mouseX-this.x)/width
+ if (this.resisizing) {
+ if (this.resizePoint === 3) {
+ this.scale = (mouseX - this.x) / width
this.scale = Math.max(0.25, this.scale)
}
- if(this.resizePoint === 1){
-
+ if (this.resizePoint === 1) {
+
let [oMouseX, oMouseY, oX, oY, ow, oh] = this.resizeInitialPos
-
- this.scale=(mouseX-this.x)/width
+
+ this.scale = (mouseX - this.x) / width
this.scale = Math.max(0.25, this.scale)
- this.y=oY+oh-height*this.scale
+ this.y = oY + oh - height * this.scale
}
- if(this.resizePoint===0){
+ if (this.resizePoint === 0) {
let [oMouseX, oMouseY, oX, oY, ow, oh] = this.resizeInitialPos
-
- this.scale=(oX+ow-mouseX)/width
+
+ this.scale = (oX + ow - mouseX) / width
this.scale = Math.max(0.25, this.scale)
- this.x=oX+ow-width*this.scale
- this.y=oY+oh-height*this.scale
+ this.x = oX + ow - width * this.scale
+ this.y = oY + oh - height * this.scale
}
- if(this.resizePoint === 2){
+ if (this.resizePoint === 2) {
let [oMouseX, oMouseY, oX, oY, ow, oh] = this.resizeInitialPos
-
- this.scale=(oX+ow-mouseX)/width
+
+ this.scale = (oX + ow - mouseX) / width
this.scale = Math.max(0.25, this.scale)
- this.x=oX+ow-width*this.scale
+ this.x = oX + ow - width * this.scale
}
}
}
- renderGui(mouseX, mouseY){
+ renderGui(mouseX, mouseY) {
- if(this.parent){
+ if (this.parent) {
this.parent.editTempTextV = this.editTempTextV
this.parent.editTempTimeV = Date.now()
-
+
this.parent.tempDisableTime = Date.now()
this.parent.renderRaw()
}
@@ -290,42 +290,42 @@ class LocationSetting extends ButtonSetting {
this.renderBox(true)
- if(this.x+width*this.scale/2 > Renderer.screen.getWidth()/2){
- this.elmSettings.location.location.x.set(Math.min(Math.max(this.x/Renderer.screen.getWidth()-0.25-0.03, 0.02), 0.73))
- }else{
- this.elmSettings.location.location.x.set(Math.min(Math.max((this.x+width*this.scale)/Renderer.screen.getWidth()+0.03, 0.02), 0.73))
+ if (this.x + width * this.scale / 2 > Renderer.screen.getWidth() / 2) {
+ this.elmSettings.location.location.x.set(Math.min(Math.max(this.x / Renderer.screen.getWidth() - 0.25 - 0.03, 0.02), 0.73))
+ } else {
+ this.elmSettings.location.location.x.set(Math.min(Math.max((this.x + width * this.scale) / Renderer.screen.getWidth() + 0.03, 0.02), 0.73))
}
- this.elmSettings.location.location.y.set(Math.min(Math.max((this.y+height*this.scale/2)/Renderer.screen.getHeight() - this.elmSettings.location.size.y.get()/2, 0.02), 0.73))
+ this.elmSettings.location.location.y.set(Math.min(Math.max((this.y + height * this.scale / 2) / Renderer.screen.getHeight() - this.elmSettings.location.size.y.get() / 2, 0.02), 0.73))
+
-
- if(this.lastScaleRender !== this.scale.toFixed(2) && !this.scaleInput.text.selected){
+ if (this.lastScaleRender !== this.scale.toFixed(2) && !this.scaleInput.text.selected) {
this.lastScaleRender = this.scale.toFixed(2)
this.scaleInput.setText(this.scale.toFixed(2))
}
- if(this.lastXRender !== this.x.toFixed(0) && !this.xInput.text.selected){
+ if (this.lastXRender !== this.x.toFixed(0) && !this.xInput.text.selected) {
this.lastXRender = this.x.toFixed(0)
this.xInput.setText(this.x.toFixed(0))
}
- if(this.lastYRender !== this.y.toFixed(0) && !this.yInput.text.selected){
+ if (this.lastYRender !== this.y.toFixed(0) && !this.yInput.text.selected) {
this.lastYRender = this.y.toFixed(0)
this.yInput.setText(this.y.toFixed(0))
}
}
- renderBox(drawHandles){
+ renderBox(drawHandles) {
let width = this.getWidth()
let height = this.parent.getHeight(true)
- Renderer.drawRect(Renderer.color(255, 255, 255), this.x, this.y, width*this.scale, 1)
- Renderer.drawRect(Renderer.color(255, 255, 255), this.x, this.y, 1, height*this.scale)
- Renderer.drawRect(Renderer.color(255, 255, 255), this.x, this.y+height*this.scale, width*this.scale, 1)
- Renderer.drawRect(Renderer.color(255, 255, 255), this.x+width*this.scale, this.y, 1, height*this.scale)
+ Renderer.drawRect(Renderer.color(255, 255, 255), this.x, this.y, width * this.scale, 1)
+ Renderer.drawRect(Renderer.color(255, 255, 255), this.x, this.y, 1, height * this.scale)
+ Renderer.drawRect(Renderer.color(255, 255, 255), this.x, this.y + height * this.scale, width * this.scale, 1)
+ Renderer.drawRect(Renderer.color(255, 255, 255), this.x + width * this.scale, this.y, 1, height * this.scale)
- if(drawHandles){
- Renderer.drawRect(Renderer.color(255, 255, 255), this.x-1*Math.max(1, this.scale)+width*this.scale, this.y-1*Math.max(1, this.scale), 2*Math.max(1, this.scale)+1, 2*Math.max(1, this.scale)+1)
- Renderer.drawRect(Renderer.color(255, 255, 255), this.x-1*Math.max(1, this.scale), this.y-1*Math.max(1, this.scale)+height*this.scale, 2*Math.max(1, this.scale)+1, 2*Math.max(1, this.scale)+1)
- Renderer.drawRect(Renderer.color(255, 255, 255), this.x-1*Math.max(1, this.scale)+width*this.scale, this.y-1*Math.max(1, this.scale)+height*this.scale, 2*Math.max(1, this.scale)+1, 2*Math.max(1, this.scale)+1)
- Renderer.drawRect(Renderer.color(255, 255, 255), this.x-1*Math.max(1, this.scale), this.y-1*Math.max(1, this.scale), 2*Math.max(1, this.scale)+1, 2*Math.max(1, this.scale)+1)
+ if (drawHandles) {
+ Renderer.drawRect(Renderer.color(255, 255, 255), this.x - 1 * Math.max(1, this.scale) + width * this.scale, this.y - 1 * Math.max(1, this.scale), 2 * Math.max(1, this.scale) + 1, 2 * Math.max(1, this.scale) + 1)
+ Renderer.drawRect(Renderer.color(255, 255, 255), this.x - 1 * Math.max(1, this.scale), this.y - 1 * Math.max(1, this.scale) + height * this.scale, 2 * Math.max(1, this.scale) + 1, 2 * Math.max(1, this.scale) + 1)
+ Renderer.drawRect(Renderer.color(255, 255, 255), this.x - 1 * Math.max(1, this.scale) + width * this.scale, this.y - 1 * Math.max(1, this.scale) + height * this.scale, 2 * Math.max(1, this.scale) + 1, 2 * Math.max(1, this.scale) + 1)
+ Renderer.drawRect(Renderer.color(255, 255, 255), this.x - 1 * Math.max(1, this.scale), this.y - 1 * Math.max(1, this.scale), 2 * Math.max(1, this.scale) + 1, 2 * Math.max(1, this.scale) + 1)
}
}
}