aboutsummaryrefslogtreecommitdiff
path: root/features/settings/settingThings/textSetting.js
blob: edc0989be69530b38b9910a8d579512344d31e7c (plain)
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
import SoopyContentChangeEvent from "../../../../guimanager/EventListener/SoopyContentChangeEvent";
import TextBox from "../../../../guimanager/GuiElement/TextBox";
import PasswordInput from "../../../../guimanager/GuiElement/PasswordInput"
import SettingBase from "./settingBase";

class TextSetting extends SettingBase {
    constructor(name, description, defaultVal, settingId, module, placeholder, isSecret) {
        super(name, description, defaultVal, settingId, module)

        this.textObject = (isSecret ? new PasswordInput() : new TextBox()).setLocation(0, 0.2, 0.9, 0.6).setText(this.getValue() || "").setPlaceholder(placeholder)
        this.settingObject.addChild(this.textObject)

        this.settingObject.setLocation(0.6, 0, 0.4, 1)
        this.guiObject.text.setLocation(0, 0, 0.6, 0.6)
        this.guiObject.description.setLocation(0, 0.6, 0.55, 0.4)

        this.textObject.text.addEvent(new SoopyContentChangeEvent().setHandler((newVal, oldVal, resetFun) => {
            this.setValue(newVal)
        }))

    }
    update() {
        if (this.hasHelp()) {
            this.guiObject.addChild(this.helpButton)

            this.guiObject.text.setLocation(0.075, 0, 0.6 - 0.075, 0.6)
        } else {
            this.guiObject.text.setLocation(0, 0, 0.6, 0.6)
        }
    }
    setValue(newVal) {
        super.setValue(newVal)

        this.textObject.setText(newVal)

        return this
    }
}

export default TextSetting