Skip to content
This repository was archived by the owner on Jan 24, 2026. It is now read-only.

Commit f4c7123

Browse files
committed
Make channels work again
1 parent abc21d2 commit f4c7123

File tree

3 files changed

+145
-133
lines changed

3 files changed

+145
-133
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package dev.ultreon.launcher
2+
3+
import com.badlogic.gdx.Gdx
4+
import com.badlogic.gdx.Input
5+
import com.badlogic.gdx.graphics.Texture
6+
import com.badlogic.gdx.graphics.g2d.BitmapFont
7+
import com.badlogic.gdx.graphics.g2d.NinePatch
8+
import com.badlogic.gdx.graphics.g2d.SpriteBatch
9+
import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable
10+
11+
class Button(
12+
private val font: BitmapFont,
13+
var text: String = "...",
14+
val callback: Button.() -> Unit = {},
15+
x: Float = 0f,
16+
y: Float = 0f,
17+
width: Float = 20f,
18+
height: Float = 20f
19+
) : Widget(x, y, width, height) {
20+
private val ninePatch: NinePatchDrawable =
21+
NinePatchDrawable(NinePatch(Texture(Gdx.files.internal("btn/dark.png")), 7, 7, 4, 6))
22+
private val ninePatchPressed: NinePatchDrawable =
23+
NinePatchDrawable(NinePatch(Texture(Gdx.files.internal("btn/dark_pressed.png")), 7, 7, 4, 6))
24+
private val ninePatchDisabled: NinePatchDrawable =
25+
NinePatchDrawable(NinePatch(Texture(Gdx.files.internal("btn/dark_disabled.png")), 7, 7, 4, 6))
26+
private val ninePatchHover: NinePatchDrawable =
27+
NinePatchDrawable(NinePatch(Texture(Gdx.files.internal("btn/dark_hover.png")), 7, 7, 4, 6))
28+
private val ninePatchHoverPressed: NinePatchDrawable =
29+
NinePatchDrawable(NinePatch(Texture(Gdx.files.internal("btn/dark_hover_pressed.png")), 7, 7, 4, 6))
30+
private val ninePatchSelect: NinePatchDrawable =
31+
NinePatchDrawable(NinePatch(Texture(Gdx.files.internal("btn/dark_select.png")), 7, 7, 4, 6))
32+
private val ninePatchHoverSelect: NinePatchDrawable =
33+
NinePatchDrawable(NinePatch(Texture(Gdx.files.internal("btn/dark_hover_select.png")), 7, 7, 4, 6))
34+
private val ninePatchPressedSelect: NinePatchDrawable =
35+
NinePatchDrawable(NinePatch(Texture(Gdx.files.internal("btn/dark_pressed_select.png")), 7, 7, 4, 6))
36+
private val ninePatchHoverPressedSelect: NinePatchDrawable =
37+
NinePatchDrawable(NinePatch(Texture(Gdx.files.internal("btn/dark_hover_pressed_select.png")), 7, 7, 4, 6))
38+
private var wasPressed: Boolean = false
39+
40+
private val pressed: Boolean
41+
get() {
42+
if (!enabled) return false
43+
44+
if (Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
45+
if (Gdx.input.x / 2f > x && (Gdx.graphics.height - Gdx.input.y) / 2f > y && Gdx.input.x / 2f < x + width && (Gdx.graphics.height - Gdx.input.y) / 2f < y + height) {
46+
wasPressed = true
47+
return true
48+
}
49+
} else {
50+
if (wasPressed) {
51+
callback()
52+
}
53+
wasPressed = false
54+
}
55+
56+
return false
57+
}
58+
var enabled: Boolean = true
59+
60+
var selected: Boolean = false
61+
62+
override fun render(batch: SpriteBatch, delta: Float) {
63+
(if (pressed) {
64+
pressed()
65+
} else if (enabled) {
66+
enabled()
67+
} else {
68+
ninePatchDisabled
69+
}).draw(
70+
batch,
71+
x,
72+
y,
73+
width,
74+
height
75+
)
76+
77+
font.draw(
78+
batch,
79+
text,
80+
x + (width - font.width(text)) / 2f,
81+
y + 10 + (height - 9) / 2f - font.lineHeight / 2f + 6 - (if (pressed) 2 else 0)
82+
)
83+
}
84+
85+
private fun enabled() =
86+
if (Gdx.input.x / 2f > x && (Gdx.graphics.height - Gdx.input.y) / 2f > y && Gdx.input.x / 2f < x + width && (Gdx.graphics.height - Gdx.input.y) / 2f < y + height) {
87+
if (selected) ninePatchHoverSelect else ninePatchHover
88+
} else if (selected) {
89+
ninePatchSelect
90+
} else {
91+
ninePatch
92+
}
93+
private fun pressed() =
94+
if (Gdx.input.x / 2f > x && (Gdx.graphics.height - Gdx.input.y) / 2f > y && Gdx.input.x / 2f < x + width && (Gdx.graphics.height - Gdx.input.y) / 2f < y + height) {
95+
if (selected) ninePatchHoverPressedSelect else ninePatchHoverPressed
96+
} else if (selected) {
97+
ninePatchPressedSelect
98+
} else {
99+
ninePatchPressed
100+
}
101+
}

core/src/main/kotlin/dev/ultreon/launcher/Main.kt

Lines changed: 30 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ package dev.ultreon.launcher
22

33
import com.badlogic.gdx.ApplicationAdapter
44
import com.badlogic.gdx.Gdx
5-
import com.badlogic.gdx.Input
65
import com.badlogic.gdx.InputAdapter
76
import com.badlogic.gdx.graphics.Texture
87
import com.badlogic.gdx.graphics.g2d.BitmapFont
98
import com.badlogic.gdx.graphics.g2d.GlyphLayout
10-
import com.badlogic.gdx.graphics.g2d.NinePatch
119
import com.badlogic.gdx.graphics.g2d.SpriteBatch
12-
import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable
1310
import com.badlogic.gdx.utils.JsonReader
1411
import com.badlogic.gdx.utils.JsonValue
1512
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream
@@ -41,112 +38,9 @@ val root: Path by lazy {
4138
}
4239
}
4340

44-
abstract class Widget(var x: Float = 0f, var y: Float = 0f, var width: Float = 20f, var height: Float = 20f) {
45-
46-
abstract fun render(batch: SpriteBatch, delta: Float)
47-
fun set(x: Float? = null, y: Float? = null, width: Float? = null, height: Float? = null) {
48-
x?.let { this.x = it }
49-
y?.let { this.y = it }
50-
width?.let { this.width = it }
51-
height?.let { this.height = it }
52-
}
53-
}
54-
55-
class Button(
56-
private val font: BitmapFont,
57-
var text: String = "...",
58-
val callback: Button.() -> Unit = {},
59-
x: Float = 0f,
60-
y: Float = 0f,
61-
width: Float = 20f,
62-
height: Float = 20f
63-
) : Widget(x, y, width, height) {
64-
private val ninePatch: NinePatchDrawable =
65-
NinePatchDrawable(NinePatch(Texture(Gdx.files.internal("btn/dark.png")), 7, 7, 4, 6))
66-
private val ninePatchPressed: NinePatchDrawable =
67-
NinePatchDrawable(NinePatch(Texture(Gdx.files.internal("btn/dark_pressed.png")), 7, 7, 4, 6))
68-
private val ninePatchDisabled: NinePatchDrawable =
69-
NinePatchDrawable(NinePatch(Texture(Gdx.files.internal("btn/dark_disabled.png")), 7, 7, 4, 6))
70-
private val ninePatchHover: NinePatchDrawable =
71-
NinePatchDrawable(NinePatch(Texture(Gdx.files.internal("btn/dark_hover.png")), 7, 7, 4, 6))
72-
private val ninePatchHoverPressed: NinePatchDrawable =
73-
NinePatchDrawable(NinePatch(Texture(Gdx.files.internal("btn/dark_hover_pressed.png")), 7, 7, 4, 6))
74-
private val ninePatchSelect: NinePatchDrawable =
75-
NinePatchDrawable(NinePatch(Texture(Gdx.files.internal("btn/dark_select.png")), 7, 7, 4, 6))
76-
private val ninePatchHoverSelect: NinePatchDrawable =
77-
NinePatchDrawable(NinePatch(Texture(Gdx.files.internal("btn/dark_hover_select.png")), 7, 7, 4, 6))
78-
private val ninePatchPressedSelect: NinePatchDrawable =
79-
NinePatchDrawable(NinePatch(Texture(Gdx.files.internal("btn/dark_pressed_select.png")), 7, 7, 4, 6))
80-
private val ninePatchHoverPressedSelect: NinePatchDrawable =
81-
NinePatchDrawable(NinePatch(Texture(Gdx.files.internal("btn/dark_hover_pressed_select.png")), 7, 7, 4, 6))
82-
private var wasPressed: Boolean = false
83-
84-
private val pressed: Boolean
85-
get() {
86-
if (!enabled) return false
87-
88-
if (Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
89-
if (Gdx.input.x / 2f > x && (Gdx.graphics.height - Gdx.input.y) / 2f > y && Gdx.input.x / 2f < x + width && (Gdx.graphics.height - Gdx.input.y) / 2f < y + height) {
90-
wasPressed = true
91-
return true
92-
}
93-
} else {
94-
if (wasPressed) {
95-
callback()
96-
}
97-
wasPressed = false
98-
}
99-
100-
return false
101-
}
102-
var enabled: Boolean = true
103-
104-
var selected: Boolean = false
105-
106-
override fun render(batch: SpriteBatch, delta: Float) {
107-
(if (pressed) {
108-
pressed()
109-
} else if (enabled) {
110-
enabled()
111-
} else {
112-
ninePatchDisabled
113-
}).draw(
114-
batch,
115-
x,
116-
y,
117-
width,
118-
height
119-
)
120-
121-
font.draw(
122-
batch,
123-
text,
124-
x + (width - font.width(text)) / 2f,
125-
y + 10 + (height - 9) / 2f - font.lineHeight / 2f + 6 - (if (pressed) 2 else 0)
126-
)
127-
}
128-
129-
private fun enabled() =
130-
if (Gdx.input.x / 2f > x && (Gdx.graphics.height - Gdx.input.y) / 2f > y && Gdx.input.x / 2f < x + width && (Gdx.graphics.height - Gdx.input.y) / 2f < y + height) {
131-
if (selected) ninePatchHoverSelect else ninePatchHover
132-
} else if (selected) {
133-
ninePatchSelect
134-
} else {
135-
ninePatch
136-
}
137-
private fun pressed() =
138-
if (Gdx.input.x / 2f > x && (Gdx.graphics.height - Gdx.input.y) / 2f > y && Gdx.input.x / 2f < x + width && (Gdx.graphics.height - Gdx.input.y) / 2f < y + height) {
139-
if (selected) ninePatchHoverPressedSelect else ninePatchHoverPressed
140-
} else if (selected) {
141-
ninePatchPressedSelect
142-
} else {
143-
ninePatchPressed
144-
}
145-
}
146-
14741
var layout: GlyphLayout = GlyphLayout()
14842

149-
private fun BitmapFont.width(text: String): Float {
43+
fun BitmapFont.width(text: String): Float {
15044
layout.setText(this, text)
15145
return layout.width
15246
}
@@ -161,26 +55,29 @@ private fun launchGame(version: GameVersion, button: Button): Process {
16155
}
16256

16357
try {
164-
return if (version.id in arrayOf("0.0.0-indev", "0.0.1-indev") || version is ChannelVersion) {
165-
// if (osName.startsWith("Windows")) {
166-
// ProcessBuilder("cmd", "/c", "gradlew.bat --no-daemon lwjgl3:run").run {
167-
// environment()["JAVA_HOME"] = JAVA_HOME.toString()
168-
// directory(path("versions/${version.id}/").toFile())
169-
// }.start()
170-
// } else if (osName.startsWith("Linux")) {
171-
// ProcessBuilder("bash", "-c", "chmod +x gradlew && chmod +x ./gradle/wrapper/gradle-wrapper.jar && ./gradlew --info --stacktrace --console=plain --no-daemon lwjgl3:run").run {
172-
// environment()["JAVA_HOME"] = JAVA_HOME.toString()
173-
// directory(path("versions/${version.id}/").toFile())
174-
// }.start()
175-
// } else if (osName.startsWith("Mac")) {
176-
// ProcessBuilder("bash", "-c", "chmod +x gradlew && chmod +x ./gradle/wrapper/gradle-wrapper.jar && ./gradlew --info --stacktrace --console=plain --no-daemon lwjgl3:run").run {
177-
// environment()["JAVA_HOME"] = JAVA_HOME.toString()
178-
// directory(path("versions/${version.id}/").toFile())
179-
// }.start()
180-
// } else {
181-
// throw UnsupportedOperationException()
182-
// }
183-
throw UnsupportedOperationException()
58+
val b = version.id in arrayOf("0.0.0-indev", "0.0.1-indev")
59+
return if (b || version is ChannelVersion) {
60+
if (osName.startsWith("Windows")) {
61+
ProcessBuilder("cmd", "/c", "gradlew.bat --no-daemon lwjgl3:run").run {
62+
environment()["PATH"] = "$JAVA_HOME/bin:${System.getenv("PATH")}"
63+
environment()["GRADLE_OPTS"] = "-Dorg.gradle.daemon=false -Djdk.lang.Process.launchMechanism=fork"
64+
directory(path("versions/${version.id}/").toFile())
65+
}.inheritIO().start()
66+
} else if (osName.startsWith("Linux")) {
67+
ProcessBuilder("bash", "-c", "chmod +x gradlew && chmod +x ./gradle/wrapper/gradle-wrapper.jar && ./gradlew --info --stacktrace --console=plain --no-daemon lwjgl3:run").run {
68+
environment()["PATH"] = "$JAVA_HOME/bin:${System.getenv("PATH")}"
69+
environment()["GRADLE_OPTS"] = "-Dorg.gradle.daemon=false -Djdk.lang.Process.launchMechanism=fork"
70+
directory(path("versions/${version.id}/").toFile())
71+
}.inheritIO().start()
72+
} else if (osName.startsWith("Mac")) {
73+
ProcessBuilder("zsh", "-c", "GRADLE_OPTS=\"-Dorg.gradle.daemon=false -Djdk.lang.Process.launchMechanism=fork\" chmod +x gradlew && ./gradlew --no-daemon --stacktrace lwjgl3:run").run {
74+
environment()["PATH"] = "$JAVA_HOME/bin:${System.getenv("PATH")}"
75+
environment()["GRADLE_OPTS"] = "-Dorg.gradle.daemon=false -Djdk.lang.Process.launchMechanism=fork"
76+
directory(path("versions/${version.id}/").toFile())
77+
}.inheritIO().start()
78+
} else {
79+
throw UnsupportedOperationException()
80+
}
18481
} else {
18582
if (osName.startsWith("Windows")) {
18683
ProcessBuilder(
@@ -290,6 +187,8 @@ fun log(text: String?) {
290187
synchronized(logFile) {
291188
logFile.seek(logFile.length())
292189
logFile.write("INFO: $text\n".toByteArray())
190+
191+
println("INFO: $text")
293192
}
294193
}
295194

@@ -735,18 +634,16 @@ object Main : ApplicationAdapter() {
735634
private val channels by lazy {
736635
val list = mutableListOf<String>()
737636
list += "edge"
738-
list += "beta"
739-
list += "release"
637+
// list += "beta"
638+
// list += "release"
740639

741640
list.map { GameChannel(it, "https://github.com/QuantumVoxel/game/archive/refs/heads/channels/$it.zip") }
742641
}
743642

744643
private val availableVersions by lazy {
745644
val list = mutableListOf<GameVersion>()
746-
// list += channels.map { ChannelVersion(it) }
747-
list += versionsFromGitHub().filter {
748-
it.id != "0.0.0-indev" && it.id != "0.0.1-indev" && it.id != "0.0.2-indev" && it.id != "0.0.3-indev"
749-
}
645+
list += channels.map { ChannelVersion(it) }
646+
list += versionsFromGitHub().filter { it.id != "0.0.0-indev" && it.id != "0.0.1-indev" && it.id != "0.0.2-indev" && it.id != "0.0.3-indev" }
750647
list
751648
}
752649

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package dev.ultreon.launcher
2+
3+
import com.badlogic.gdx.graphics.g2d.SpriteBatch
4+
5+
abstract class Widget(var x: Float = 0f, var y: Float = 0f, var width: Float = 20f, var height: Float = 20f) {
6+
7+
abstract fun render(batch: SpriteBatch, delta: Float)
8+
fun set(x: Float? = null, y: Float? = null, width: Float? = null, height: Float? = null) {
9+
x?.let { this.x = it }
10+
y?.let { this.y = it }
11+
width?.let { this.width = it }
12+
height?.let { this.height = it }
13+
}
14+
}

0 commit comments

Comments
 (0)