summaryrefslogtreecommitdiff
path: root/src/main/kotlin/de/romjaki/pluggabledino/states/SettingsState.kt
blob: d55d76f02d343d706d6b9a8dc8d157735ddeb363 (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
package de.romjaki.pluggabledino.states

import de.romjaki.pluggabledino.*
import de.romjaki.pluggabledino.api.Button
import de.romjaki.pluggabledino.api.SettingsElement
import de.romjaki.pluggabledino.api.ToggleButton
import org.newdawn.slick.Color
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics
import org.newdawn.slick.state.BasicGameState
import org.newdawn.slick.state.StateBasedGame

class SettingsState : BasicGameState() {
    override fun init(container: GameContainer?, game: StateBasedGame?) {
        game!!
        backButton.addClickHandler {
            game.enterState(MAINMENU)
        }
    }

    override fun enter(container: GameContainer?, game: StateBasedGame?) {
        backButton.enter()
        scoreButton.enter()
        additionals.forEach {
            it.enter()
        }
    }

    override fun update(container: GameContainer?, game: StateBasedGame?, delta: Int) {
        container!!
        scoreButton.update(container.input)
        backButton.update(container.input)
        additionals.forEach {
            it.update(container.input)
        }
    }

    override fun getID(): Int =
            SETTINGS

    fun addSettingsElement(el: SettingsElement) {
        additionals.add(el)
    }

    val scoreButton = ToggleButton(listOf("ON", "OFF"), WIDTH * 3 / 4f, HEIGHT / 8f)

    val backButton = Button("BACK", WIDTH / 2f, HEIGHT / 8 * 7f)

    val additionals = mutableListOf<SettingsElement>()

    override fun render(container: GameContainer?, game: StateBasedGame?, g: Graphics?) {
        g!!
        g.scale(WIDTH_RATIO, HEIGHT_RATIO)
        g.background = Color.lightGray
        backButton.draw(g)
        scoreButton.draw(g)
        additionals.forEach { it.render(g) }

    }

}