add option to show message

main
Matthias 1 year ago
parent f6a7cfaafb
commit e0ca135712

@ -3,15 +3,12 @@ package com.last.commit
import GameState import GameState
import com.badlogic.gdx.Game import com.badlogic.gdx.Game
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.assets.AssetManager import com.badlogic.gdx.InputMultiplexer
import com.last.commit.audio.SoundEngine import com.last.commit.audio.SoundEngine
import com.last.commit.config.GameSettings import com.last.commit.config.GameSettings
import com.last.commit.config.TimeTravelAssetManager import com.last.commit.config.TimeTravelAssetManager
import com.last.commit.inventory.Inventory import com.last.commit.inventory.Inventory
import com.last.commit.screen.* import com.last.commit.screen.*
import com.last.commit.map.MapState
import java.awt.AWTEventMulticaster
import java.sql.Time
/** [com.badlogic.gdx.ApplicationListener] implementation shared by all platforms. */ /** [com.badlogic.gdx.ApplicationListener] implementation shared by all platforms. */
@ -19,17 +16,19 @@ class Game : Game() {
lateinit var state: GameState lateinit var state: GameState
lateinit var menu : TimeTravelScreen lateinit var menu: TimeTravelScreen
lateinit var gameplay: TimeTravelScreen lateinit var gameplay: TimeTravelScreen
lateinit var settings: TimeTravelScreen lateinit var settings: TimeTravelScreen
val inputProcessors = InputMultiplexer()
lateinit var inputProcessor: GameInputProcessor lateinit var inputProcessor: GameInputProcessor
override fun create() { override fun create() {
createState() createState()
createScreens() createScreens()
inputProcessor = GameInputProcessor(this) inputProcessor = GameInputProcessor(this)
Gdx.input.inputProcessor = inputProcessor gameplay.getInputProcessors().forEach { it -> inputProcessors.addProcessor(it) }
inputProcessors.addProcessor(inputProcessor)
Gdx.input.inputProcessor = inputProcessors
changeScreen(Screens.MAIN_MENU) changeScreen(Screens.MAIN_MENU)
} }
@ -41,7 +40,7 @@ class Game : Game() {
settings = Settings(this) settings = Settings(this)
} }
fun changeScreen(screen : Screens) { fun changeScreen(screen: Screens) {
println("changing screen to $screen") println("changing screen to $screen")
when (screen) { when (screen) {
Screens.MAIN_MENU -> setScreen(menu) Screens.MAIN_MENU -> setScreen(menu)

@ -11,4 +11,6 @@ enum class ActionCommand {
//program interaction //program interaction
OPEN_MENU, OPEN_MENU,
JUMP
} }

@ -1,7 +1,7 @@
package com.last.commit.config package com.last.commit.config
import com.badlogic.gdx.Input.Keys import com.badlogic.gdx.Input.Keys
import com.badlogic.gdx.Preferences import com.badlogic.gdx.math.MathUtils
import java.util.* import java.util.*
class GameSettings { class GameSettings {
@ -15,11 +15,11 @@ class GameSettings {
var musicVolume: Float = 0.5F var musicVolume: Float = 0.5F
set(newValue: Float) { set(newValue: Float) {
field = valueRegulator(newValue, 1F, 0F) as Float field = MathUtils.clamp(newValue, 1f, 0f)
} }
var sfxVolume: Float = 0.5F var sfxVolume: Float = 0.5F
set(newValue: Float) { set(newValue: Float) {
field = valueRegulator(newValue, 1F, 0F) as Float field = MathUtils.clamp(newValue, 1f, 0f)
} }
@ -31,6 +31,7 @@ class GameSettings {
actionKeys[ActionCommand.OPEN_MENU] = listOf(Keys.ESCAPE) actionKeys[ActionCommand.OPEN_MENU] = listOf(Keys.ESCAPE)
actionKeys[ActionCommand.TIME_TRAVEL] = listOf(Keys.T) actionKeys[ActionCommand.TIME_TRAVEL] = listOf(Keys.T)
actionKeys[ActionCommand.INTERACT] = listOf(Keys.E) actionKeys[ActionCommand.INTERACT] = listOf(Keys.E)
actionKeys[ActionCommand.JUMP] = listOf(Keys.SPACE)
musicVolume = 0.5F musicVolume = 0.5F
@ -38,19 +39,8 @@ class GameSettings {
} }
private fun <T> valueRegulator(newValue: T, maxValue: T, minValue: T): T where T : Number, T : Comparable<T>{
return if (newValue.compareTo(maxValue) > 0) {
maxValue
} else if (newValue.compareTo(minValue) < 0) {
minValue
} else {
newValue
}
}
private fun setReversed(actionKeys: EnumMap<ActionCommand, List<Int>>) { private fun setReversed(actionKeys: EnumMap<ActionCommand, List<Int>>) {
for (actionCode in actionKeys.keys){ for (actionCode in actionKeys.keys) {
for (key in actionKeys.getValue(actionCode)) { for (key in actionKeys.getValue(actionCode)) {
actionKeysReversed[key] = actionCode actionKeysReversed[key] = actionCode
} }

@ -1,6 +1,7 @@
package com.last.commit.screen package com.last.commit.screen
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.InputProcessor
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.GL20 import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.OrthographicCamera
@ -11,6 +12,7 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.badlogic.gdx.math.MathUtils import com.badlogic.gdx.math.MathUtils
import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.math.Vector2
import com.badlogic.gdx.math.Vector3 import com.badlogic.gdx.math.Vector3
import com.badlogic.gdx.scenes.scene2d.ui.Skin
import com.badlogic.gdx.utils.Json import com.badlogic.gdx.utils.Json
import com.last.commit.Game import com.last.commit.Game
import com.last.commit.Player import com.last.commit.Player
@ -19,6 +21,7 @@ import com.last.commit.config.ActionCommand
import com.last.commit.config.GameConfig import com.last.commit.config.GameConfig
import com.last.commit.map.Interactable import com.last.commit.map.Interactable
import com.last.commit.map.TimeMap import com.last.commit.map.TimeMap
import com.last.commit.stages.DialogStage
import com.last.commit.stages.UIStage import com.last.commit.stages.UIStage
import kotlin.math.floor import kotlin.math.floor
@ -45,6 +48,7 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
var pause = true var pause = true
var uiStage: UIStage var uiStage: UIStage
val dialogStage = DialogStage(Skin(Gdx.files.internal("ui/uiskin.json")))
init { init {
@ -65,6 +69,10 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
} }
override fun getInputProcessors(): Array<InputProcessor> {
return arrayOf(dialogStage)
}
override fun handleKeyInput(action: ActionCommand) { override fun handleKeyInput(action: ActionCommand) {
if (!pause) { if (!pause) {
when (action) { when (action) {
@ -76,6 +84,11 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
map.teleport(player) map.teleport(player)
} }
ActionCommand.JUMP -> {
dialogStage.setTexts("Hello", "Please read the documentation")
dialogStage.show()
}
else -> {} else -> {}
} }
if (action == ActionCommand.OPEN_MENU) { if (action == ActionCommand.OPEN_MENU) {
@ -111,6 +124,8 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
override fun render(delta: Float) { override fun render(delta: Float) {
if (!pause) { if (!pause) {
uiStage.act(delta)
dialogStage.act(delta)
handleInput(delta) handleInput(delta)
handleMapBorderCollision() handleMapBorderCollision()
@ -126,8 +141,8 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
val interactables = map.getInteractablesAt(player.getAbsoluteDirection()) val interactables = map.getInteractablesAt(player.getAbsoluteDirection())
renderInteractables(interactables) renderInteractables(interactables)
uiStage.act(delta)
uiStage.draw() uiStage.draw()
dialogStage.draw()
} }
} }
@ -250,6 +265,7 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
override fun resize(width: Int, height: Int) { override fun resize(width: Int, height: Int) {
// Resize your screen here. The parameters represent the new window size. // Resize your screen here. The parameters represent the new window size.
uiStage.resize(width, height) uiStage.resize(width, height)
dialogStage.resize(width, height)
handleRatioChange() handleRatioChange()
} }
@ -292,7 +308,6 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
} }
fun openDoor() { fun openDoor() {
println("Attempt to toggle door")
val playerDirection: Vector2 = player.getAbsoluteDirection() val playerDirection: Vector2 = player.getAbsoluteDirection()
map.interactWith(playerDirection.x, playerDirection.y, player.getCollider()) map.interactWith(playerDirection.x, playerDirection.y, player.getCollider())
} }

@ -1,6 +1,7 @@
package com.last.commit.screen package com.last.commit.screen
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.InputProcessor
import com.badlogic.gdx.graphics.GL20 import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.Stage import com.badlogic.gdx.scenes.scene2d.Stage
@ -26,6 +27,7 @@ class MainMenu(val parent: Game) : TimeTravelScreen() {
stage = Stage(ScreenViewport()) stage = Stage(ScreenViewport())
uiSkin = parent.state.assetManager.getUiTexture() uiSkin = parent.state.assetManager.getUiTexture()
} }
override fun handleKeyInput(action: ActionCommand) { override fun handleKeyInput(action: ActionCommand) {
parent.changeScreen(Screens.GAME) parent.changeScreen(Screens.GAME)
} }
@ -35,6 +37,10 @@ class MainMenu(val parent: Game) : TimeTravelScreen() {
stage.touchUp(screenX, screenY, pointer, button) stage.touchUp(screenX, screenY, pointer, button)
} }
override fun getInputProcessors(): Array<InputProcessor> {
return emptyArray()
}
override fun show() { override fun show() {
stage.addActor(table); stage.addActor(table);
@ -85,7 +91,6 @@ class MainMenu(val parent: Game) : TimeTravelScreen() {
}) })
} }
val state = ColorState() val state = ColorState()

@ -1,17 +1,15 @@
package com.last.commit.screen package com.last.commit.screen
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.InputProcessor
import com.badlogic.gdx.graphics.GL20 import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.Stage import com.badlogic.gdx.scenes.scene2d.Stage
import com.badlogic.gdx.scenes.scene2d.ui.* import com.badlogic.gdx.scenes.scene2d.ui.*
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener
import com.badlogic.gdx.utils.viewport.ScreenViewport import com.badlogic.gdx.utils.viewport.ScreenViewport
import com.last.commit.ColorState
import com.last.commit.Game import com.last.commit.Game
import com.last.commit.config.ActionCommand import com.last.commit.config.ActionCommand
class Settings (val parent: Game) : TimeTravelScreen() { class Settings(val parent: Game) : TimeTravelScreen() {
var stage: Stage var stage: Stage
@ -38,6 +36,9 @@ class Settings (val parent: Game) : TimeTravelScreen() {
stage.touchUp(screenX, screenY, pointer, button) stage.touchUp(screenX, screenY, pointer, button)
} }
override fun getInputProcessors(): Array<InputProcessor> {
return emptyArray()
}
override fun show() { override fun show() {

@ -1,10 +1,13 @@
package com.last.commit.screen package com.last.commit.screen
import com.badlogic.gdx.InputProcessor
import com.badlogic.gdx.Screen import com.badlogic.gdx.Screen
import com.last.commit.config.ActionCommand import com.last.commit.config.ActionCommand
abstract class TimeTravelScreen : Screen{ abstract class TimeTravelScreen : Screen {
abstract fun handleKeyInput(action : ActionCommand) abstract fun handleKeyInput(action: ActionCommand)
abstract fun handleMouseInput(screenX: Int, screenY: Int, pointer: Int, button: Int) abstract fun handleMouseInput(screenX: Int, screenY: Int, pointer: Int, button: Int)
abstract fun getInputProcessors(): Array<InputProcessor>
} }

@ -0,0 +1,83 @@
package com.last.commit.stages
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.scenes.scene2d.Stage
import com.badlogic.gdx.scenes.scene2d.ui.Skin
import com.badlogic.gdx.scenes.scene2d.ui.TextArea
/**
* Stage for dialog
*/
class DialogStage(skin: Skin?) : Stage() {
private var isVisible = false
private val texts = com.badlogic.gdx.utils.Array<String>()
private val area: TextArea
init {
area = TextArea("#", skin)
area.width = Gdx.graphics.width.toFloat()
area.height = 100f
addActor(area)
}
fun setTexts(vararg texts: String?) {
this.texts.clear()
this.texts.addAll(*texts)
next()
}
fun show() {
isVisible = true
}
fun hide() {
isVisible = false
}
fun resize(width: Int, height: Int) {
viewport.update(width, height, true)
}
override fun draw() {
if (isVisible) {
super.draw()
}
}
override fun act() {
if (isVisible) {
super.act()
}
}
override fun act(delta: Float) {
if (isVisible) {
super.act(delta)
}
}
override fun keyDown(keyCode: Int): Boolean {
if (!isVisible) {
return false
}
if (keyCode == Input.Keys.SPACE) {
if (texts.size > 0) {
//set next dialog text
next()
} else {
// hide dialog area cause there is no more text to show
hide()
}
}
return true
}
private operator fun next() {
area.clear()
area.text = texts.first()
texts.removeIndex(0)
}
}
Loading…
Cancel
Save