aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/notenoughupdates/gui/RepoManagementGui.kt
blob: ecdb05bb516f34c832d5c79cbad9e9b8ece795e8 (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
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
package moe.nea.notenoughupdates.gui

import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription
import io.github.cottonmc.cotton.gui.widget.WButton
import io.github.cottonmc.cotton.gui.widget.WLabel
import io.github.cottonmc.cotton.gui.widget.WTextField
import io.github.cottonmc.cotton.gui.widget.WToggleButton
import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment
import io.github.cottonmc.cotton.gui.widget.data.Insets
import io.github.cottonmc.cotton.gui.widget.data.VerticalAlignment
import moe.nea.notenoughupdates.repo.RepoManager
import net.minecraft.network.chat.Component
import java.util.function.Consumer

class RepoManagementGui : LightweightGuiDescription() {
    init {
        val root = WGridPanelWithPadding(verticalPadding = 5)
        setRootPanel(root)
        root.setSize(0, 0)
        root.insets = Insets.ROOT_PANEL
        var col = 0

        WLabel(Component.literal("NotEnoughUpdates Repo Settings")).apply {
            root.add(this, 0, col, 11, 1)
            this.verticalAlignment = VerticalAlignment.TOP
            this.horizontalAlignment = HorizontalAlignment.CENTER
        }
        col += 1

        WLabel(Component.literal("Auto Update")).apply {
            root.add(this, 0, col, 5, 1)
            this.verticalAlignment = VerticalAlignment.CENTER
        }

        WToggleButton(Component.literal("Auto Update")).apply {
            this.toggle = RepoManager.config.autoUpdate
            this.onToggle = Consumer {
                RepoManager.config.autoUpdate = it
                RepoManager.markDirty()
            }
            root.add(this, 5, col, 1, 1)
        }
        col += 1

        WLabel(Component.literal("Repo Username")).apply {
            root.add(this, 0, col, 5, 1)
            this.verticalAlignment = VerticalAlignment.CENTER

        }

        val userName = WTextField(Component.literal("username")).apply {
            this.isEditable = true
            this.text = RepoManager.config.user
            this.setChangedListener {
                RepoManager.config.user = it
                RepoManager.markDirty()
            }
            root.add(this, 5, col, 6, 1)
        }

        col += 1
        WLabel(Component.literal("Repo Name")).apply {
            root.add(this, 0, col, 5, 1)
            this.verticalAlignment = VerticalAlignment.CENTER
        }

        val repoName = WTextField(Component.literal("repo name")).apply {
            this.isEditable = true
            this.text = RepoManager.config.repo
            this.setChangedListener {
                RepoManager.config.repo = it
                RepoManager.markDirty()
            }
            root.add(this, 5, col, 6, 1)
        }
        col += 1

        WLabel(Component.literal("Repo Branch")).apply {
            root.add(this, 0, col, 5, 1)
            this.verticalAlignment = VerticalAlignment.CENTER
        }

        val branchName = WTextField(Component.literal("repo branch")).apply {
            this.isEditable = true
            this.text = RepoManager.config.branch
            this.setChangedListener {
                RepoManager.config.branch = it
                RepoManager.markDirty()
            }
            root.add(this, 5, col, 6, 1)
        }
        col += 1

        WLabel(Component.literal("Reset to Defaults")).apply {
            root.add(this, 0, col, 5, 1)
            this.verticalAlignment = VerticalAlignment.CENTER
        }

        WButton(Component.literal("Reset")).apply {
            this.setOnClick {
                branchName.text = "master"
                userName.text = "NotEnoughUpdates"
                repoName.text = "NotEnoughUpdates-REPO"
                RepoManager.markDirty()
            }
            root.add(this, 5, col, 6, 1)
        }
    }
}