DEADSOFTWARE

Add items count and tools duration
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / render / HudRenderer.kt
index 911df5a301749aefd61ed385d9f1f456037cf7f3..7bbb87689d7b6adb77742385a8ae2f2c454355ab 100644 (file)
@@ -29,11 +29,14 @@ class HudRenderer @Inject constructor(
     private val halfHeartTexture get() = requireNotNull(Assets.textureRegions[HALF_HEART_KEY])
 
     private fun drawCursor(spriteBatch: SpriteBatch, viewport: Rectangle) {
-        if (gameWorld.hasForeAt(gameInput.curX, gameInput.curY) ||
-            gameWorld.hasBackAt(gameInput.curX, gameInput.curY) ||
+        val cursorX = mobsController.player.cursorX
+        val cursorY = mobsController.player.cursorY
+
+        if (gameWorld.hasForeAt(cursorX, cursorY) ||
+            gameWorld.hasBackAt(cursorX, cursorY) ||
             gameInput.controlMode == ControlMode.CURSOR
         ) {
-            spriteBatch.draw(cursorTexture, gameInput.curX.px - viewport.x, gameInput.curY.px - viewport.y)
+            spriteBatch.draw(cursorTexture, cursorX.px - viewport.x, cursorY.px - viewport.y)
         }
     }
 
@@ -56,19 +59,19 @@ class HudRenderer @Inject constructor(
         }
     }
 
-    private fun drawHotbarItems(spriteBatch: SpriteBatch, hotbarX: Float) {
-        mobsController.player.inventory.asSequence()
-            .map(InventoryItem::item)
+    private fun drawHotbarItems(spriteBatch: SpriteBatch, shapeRenderer: ShapeRenderer,  hotbarX: Float) {
+        mobsController.player.inventory
             .forEachIndexed { index, item ->
-                if (item.isNone()) {
+                if (item.item.isNone()) {
                     return@forEachIndexed
                 }
 
-                spriteBatch.draw(
-                    /* region = */ item.sprite,
-                    /* x = */ hotbarX + HotbarConfig.horizontalMargin
-                            + index * (HotbarConfig.itemSeparatorWidth + HotbarConfig.itemSlotSpace),
-                    /* y = */ HotbarConfig.verticalMargin,
+                item.draw(
+                    spriteBatch = spriteBatch,
+                    shapeRenderer = shapeRenderer,
+                    x = hotbarX + HotbarConfig.horizontalMargin +
+                            index * (HotbarConfig.itemSeparatorWidth + HotbarConfig.itemSlotSpace),
+                    y = HotbarConfig.verticalMargin,
                 )
             }
     }
@@ -82,19 +85,19 @@ class HudRenderer @Inject constructor(
         )
     }
 
-    private fun drawHotbar(spriteBatch: SpriteBatch, viewport: Rectangle) {
+    private fun drawHotbar(spriteBatch: SpriteBatch, shapeRenderer: ShapeRenderer, viewport: Rectangle) {
         val hotbar = hotbarTexture
         val hotbarX = viewport.width / 2 - hotbar.regionWidth / 2
 
         spriteBatch.draw(hotbar, hotbarX, 0f)
         drawHealth(spriteBatch, hotbarX, hotbarTexture.regionHeight.toFloat())
-        drawHotbarItems(spriteBatch, hotbarX)
         drawHotbarSelector(spriteBatch, hotbarX)
+        drawHotbarItems(spriteBatch, shapeRenderer, hotbarX)
     }
 
     override fun draw(spriteBatch: SpriteBatch, shapeRenderer: ShapeRenderer, viewport: Rectangle, delta: Float) {
         drawCursor(spriteBatch, viewport)
-        drawHotbar(spriteBatch, viewport)
+        drawHotbar(spriteBatch, shapeRenderer, viewport)
     }
 
     companion object {