X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavedroid%2Fgame%2Frender%2FHudRenderer.kt;h=a2570e25f3120f8208233038f3b85e4738409dc4;hb=cb0605053ce3de493b0d1f43cd7ec1e4a9cf0ac5;hp=7bbb87689d7b6adb77742385a8ae2f2c454355ab;hpb=409a22b3fe7c43b7f686f33cc2f01b6277edec78;p=cavedroid.git diff --git a/core/src/ru/deadsoftware/cavedroid/game/render/HudRenderer.kt b/core/src/ru/deadsoftware/cavedroid/game/render/HudRenderer.kt index 7bbb876..a2570e2 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/render/HudRenderer.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/render/HudRenderer.kt @@ -3,21 +3,22 @@ package ru.deadsoftware.cavedroid.game.render 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.game.GameScope import ru.deadsoftware.cavedroid.game.mobs.MobsController -import ru.deadsoftware.cavedroid.game.model.item.InventoryItem +import ru.deadsoftware.cavedroid.game.mobs.player.Player +import ru.deadsoftware.cavedroid.game.mobs.player.Player.ControlMode +import ru.deadsoftware.cavedroid.game.ui.TooltipManager import ru.deadsoftware.cavedroid.game.world.GameWorld import ru.deadsoftware.cavedroid.misc.Assets -import ru.deadsoftware.cavedroid.misc.ControlMode +import ru.deadsoftware.cavedroid.misc.utils.drawString import ru.deadsoftware.cavedroid.misc.utils.px import javax.inject.Inject @GameScope class HudRenderer @Inject constructor( - private val gameInput: GameInput, private val gameWorld: GameWorld, private val mobsController: MobsController, + private val tooltipManager: TooltipManager, ) : IGameRenderer { override val renderLayer = RENDER_LAYER @@ -26,6 +27,7 @@ class HudRenderer @Inject constructor( private val hotbarTexture get() = requireNotNull(Assets.textureRegions[HOTBAR_KEY]) private val hotbarSelectorTexture get() = requireNotNull(Assets.textureRegions[HOTBAR_SELECTOR_KEY]) private val wholeHeartTexture get() = requireNotNull(Assets.textureRegions[WHOLE_HEART_KEY]) + private val emptyHeartTexture get() = requireNotNull(Assets.textureRegions[EMPTY_HEART_KEY]) private val halfHeartTexture get() = requireNotNull(Assets.textureRegions[HALF_HEART_KEY]) private fun drawCursor(spriteBatch: SpriteBatch, viewport: Rectangle) { @@ -34,7 +36,7 @@ class HudRenderer @Inject constructor( if (gameWorld.hasForeAt(cursorX, cursorY) || gameWorld.hasBackAt(cursorX, cursorY) || - gameInput.controlMode == ControlMode.CURSOR + mobsController.player.controlMode == ControlMode.CURSOR ) { spriteBatch.draw(cursorTexture, cursorX.px - viewport.x, cursorY.px - viewport.y) } @@ -48,19 +50,29 @@ class HudRenderer @Inject constructor( } val wholeHeart = wholeHeartTexture + val halfHeart = halfHeartTexture + val emptyHeart = emptyHeartTexture + + val totalHearts = Player.MAX_HEALTH / 2 val wholeHearts = player.health / 2 - for (i in 0.. if (item.item.isNone()) { return@forEachIndexed @@ -80,7 +92,7 @@ class HudRenderer @Inject constructor( spriteBatch.draw( /* region = */ hotbarSelectorTexture, /* x = */ hotbarX - HotbarSelectorConfig.horizontalPadding - + mobsController.player.slot * (HotbarConfig.itemSeparatorWidth + HotbarConfig.itemSlotSpace), + + mobsController.player.inventory.activeSlot * (HotbarConfig.itemSeparatorWidth + HotbarConfig.itemSlotSpace), /* y = */ -HotbarSelectorConfig.verticalPadding ) } @@ -93,6 +105,15 @@ class HudRenderer @Inject constructor( drawHealth(spriteBatch, hotbarX, hotbarTexture.regionHeight.toFloat()) drawHotbarSelector(spriteBatch, hotbarX) drawHotbarItems(spriteBatch, shapeRenderer, hotbarX) + + val tooltip = tooltipManager.currentHotbarTooltip + if (tooltip.isNotBlank()) { + spriteBatch.drawString( + str = tooltip, + x = viewport.width / 2 - Assets.getStringWidth(tooltip) / 2, + y = hotbarTexture.regionHeight.toFloat() + ) + } } override fun draw(spriteBatch: SpriteBatch, shapeRenderer: ShapeRenderer, viewport: Rectangle, delta: Float) { @@ -108,12 +129,14 @@ class HudRenderer @Inject constructor( private const val HOTBAR_SELECTOR_KEY = "hotbar_selector" private const val WHOLE_HEART_KEY = "heart_whole" private const val HALF_HEART_KEY = "heart_half" + private const val EMPTY_HEART_KEY = "heart_empty" private data object HotbarConfig { const val horizontalMargin = 3f const val verticalMargin = 3f const val itemSeparatorWidth = 4f const val itemSlotSpace = 16f + const val hotbarCells = 9 } private data object HotbarSelectorConfig {