Skip to content

Commit

Permalink
added game selector menu
Browse files Browse the repository at this point in the history
Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com>
  • Loading branch information
j10a1n15 committed Sep 21, 2024
1 parent 17d8398 commit 9549d16
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package gay.j10a1n15.sillygames.commands


import gay.j10a1n15.sillygames.games.wordle.Wordle
import gay.j10a1n15.sillygames.screens.FullScreen
import gay.j10a1n15.sillygames.screens.GameSelector
import gay.j10a1n15.sillygames.screens.PictureInPicture
import gay.j10a1n15.sillygames.utils.SillyUtils.display
import net.minecraft.command.ICommandSender
Expand All @@ -12,8 +11,8 @@ import net.minecraftforge.client.ClientCommandHandler
class CommandManager {

init {
registerCommand("fullscreen") {
FullScreen(Wordle()).display()
registerCommand("games") {
GameSelector().display()
}
registerCommand("pip") {
PictureInPicture.visible = !PictureInPicture.visible
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/gay/j10a1n15/sillygames/games/Game.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import gg.essential.elementa.UIComponent
abstract class Game {
abstract fun getDisplay(): UIComponent

abstract val name: String

open fun onTick() {}

open fun onKeyHeld(key: Int) {}
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/gay/j10a1n15/sillygames/games/Snake.kt
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,6 @@ class Snake : Game() {
}

override val pip = true

override val name = "Snake"
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,6 @@ class Wordle : Game() {
}
}
}

override val name = "Wordle"
}
63 changes: 63 additions & 0 deletions src/main/kotlin/gay/j10a1n15/sillygames/screens/GameSelector.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package gay.j10a1n15.sillygames.screens

import gay.j10a1n15.sillygames.games.Snake
import gay.j10a1n15.sillygames.games.wordle.Wordle
import gay.j10a1n15.sillygames.utils.SillyUtils.display
import gg.essential.elementa.ElementaVersion
import gg.essential.elementa.WindowScreen
import gg.essential.elementa.components.UIBlock
import gg.essential.elementa.components.UIText
import gg.essential.elementa.constraints.CenterConstraint
import gg.essential.elementa.dsl.childOf
import gg.essential.elementa.dsl.constrain
import gg.essential.elementa.dsl.percent
import gg.essential.elementa.dsl.toConstraint
import gg.essential.elementa.utils.withAlpha
import gg.essential.universal.GuiScale
import java.awt.Color

val gameFactories = setOf(
{ Wordle() },
{ Snake() },
)

class GameSelector : WindowScreen(
version = ElementaVersion.V5,
newGuiScale = GuiScale.scaleForScreenSize().ordinal,
drawDefaultBackground = false,
) {
private val container = UIBlock().constrain {
x = CenterConstraint()
y = CenterConstraint()
width = 75.percent()
height = 75.percent()
color = Color(0x212121).withAlpha(0.85f).toConstraint()
} childOf window

private val title = UIText("Select a game").constrain {
x = CenterConstraint()
y = 10.percent()
} childOf container

init {
gameFactories.forEachIndexed { index, factory ->
val button = UIBlock().constrain {
x = CenterConstraint()
y = (20 + 10 * index).percent()
width = 50.percent()
height = 5.percent()
color = Color(0x424242).withAlpha(0.95f).toConstraint()
} childOf container

UIText(factory().name).constrain {
x = CenterConstraint()
y = CenterConstraint()
} childOf button

button.onMouseClick {
FullScreen(factory.invoke()).display()
}
}
}

}

0 comments on commit 9549d16

Please sign in to comment.