[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / render / TouchControlsRenderer.kt
diff --git a/core/src/ru/deadsoftware/cavedroid/game/render/TouchControlsRenderer.kt b/core/src/ru/deadsoftware/cavedroid/game/render/TouchControlsRenderer.kt
index e8b19d013f0d5a1431f27582f0d39b59c4b137b2..29702aece89cc3d9fcec5f0b87f429d0de239062 100644 (file)
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.badlogic.gdx.math.Rectangle
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.badlogic.gdx.math.Rectangle
-import ru.deadsoftware.cavedroid.game.GameInput
+import ru.deadsoftware.cavedroid.MainConfig
import ru.deadsoftware.cavedroid.game.GameScope
import ru.deadsoftware.cavedroid.game.GameScope
+import ru.deadsoftware.cavedroid.game.GameUiWindow
+import ru.deadsoftware.cavedroid.game.input.Joystick
+import ru.deadsoftware.cavedroid.game.mobs.MobsController
+import ru.deadsoftware.cavedroid.game.mobs.player.Player.ControlMode
+import ru.deadsoftware.cavedroid.game.ui.windows.GameWindowsManager
import ru.deadsoftware.cavedroid.misc.Assets
import ru.deadsoftware.cavedroid.misc.Assets
-import ru.deadsoftware.cavedroid.misc.ControlMode
import ru.deadsoftware.cavedroid.misc.utils.ArrayMapExtensions.component1
import ru.deadsoftware.cavedroid.misc.utils.ArrayMapExtensions.component2
import ru.deadsoftware.cavedroid.misc.utils.ArrayMapExtensions.component1
import ru.deadsoftware.cavedroid.misc.utils.ArrayMapExtensions.component2
+import ru.deadsoftware.cavedroid.misc.utils.drawSprite
import javax.inject.Inject
@GameScope
import javax.inject.Inject
@GameScope
+@GameRenderer
class TouchControlsRenderer @Inject constructor(
class TouchControlsRenderer @Inject constructor(
- private val gameInput: GameInput
+ private val mainConfig: MainConfig,
+ private val mobsController: MobsController,
+ private val gameWindowsManager: GameWindowsManager,
) : IGameRenderer {
override val renderLayer get() = RENDER_LAYER
private val shadeTexture get() = Assets.textureRegions[SHADE_KEY]
) : IGameRenderer {
override val renderLayer get() = RENDER_LAYER
private val shadeTexture get() = Assets.textureRegions[SHADE_KEY]
+ private fun drawJoystick(spriteBatch: SpriteBatch) {
+ val joystick = mainConfig.joystick?.takeIf { it.active } ?: return
+
+ spriteBatch.drawSprite(
+ sprite = Assets.joyBackground,
+ x = joystick.centerX - Joystick.RADIUS,
+ y = joystick.centerY - Joystick.RADIUS,
+ width = Joystick.SIZE,
+ height = Joystick.SIZE
+ )
+
+ spriteBatch.drawSprite(
+ sprite = Assets.joyStick,
+ x = joystick.activeX - Joystick.STICK_SIZE / 2,
+ y = joystick.activeY - Joystick.STICK_SIZE / 2,
+ width = Joystick.STICK_SIZE,
+ height = Joystick.STICK_SIZE
+ )
+ }
+
override fun draw(spriteBatch: SpriteBatch, shapeRenderer: ShapeRenderer, viewport: Rectangle, delta: Float) {
override fun draw(spriteBatch: SpriteBatch, shapeRenderer: ShapeRenderer, viewport: Rectangle, delta: Float) {
+ if (!mainConfig.isTouch || gameWindowsManager.getCurrentWindow() != GameUiWindow.NONE) {
+ return
+ }
+
val touchControlsMap = Assets.guiMap
touchControlsMap.forEach { (key, value) ->
val touchControlsMap = Assets.guiMap
touchControlsMap.forEach { (key, value) ->
}
// FIXME: Add pressed state for buttons
}
// FIXME: Add pressed state for buttons
- if (gameInput.controlMode == ControlMode.CURSOR) {
+ if (mobsController.player.controlMode == ControlMode.CURSOR) {
val altKeyRect = touchControlsMap.get("alt").rect
spriteBatch.draw(shadeTexture, altKeyRect.x, altKeyRect.y, altKeyRect.width, altKeyRect.height)
}
val altKeyRect = touchControlsMap.get("alt").rect
spriteBatch.draw(shadeTexture, altKeyRect.x, altKeyRect.y, altKeyRect.width, altKeyRect.height)
}
+
+ drawJoystick(spriteBatch)
}
companion object {
}
companion object {