[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / render / windows / SurvivalWindowRenderer.kt
diff --git a/core/src/ru/deadsoftware/cavedroid/game/render/windows/SurvivalWindowRenderer.kt b/core/src/ru/deadsoftware/cavedroid/game/render/windows/SurvivalWindowRenderer.kt
index f8a6ac00b929ce8b9305716b76d1eeda35e946bd..7ee3b27087eb76bd0b75f2549786b54b5eac241c 100644 (file)
import com.badlogic.gdx.math.MathUtils
import com.badlogic.gdx.math.Rectangle
import ru.deadsoftware.cavedroid.MainConfig
+import ru.deadsoftware.cavedroid.game.GameItemsHolder
import ru.deadsoftware.cavedroid.game.GameScope
import ru.deadsoftware.cavedroid.game.mobs.Mob
import ru.deadsoftware.cavedroid.game.mobs.MobsController
import ru.deadsoftware.cavedroid.game.render.IGameRenderer
import ru.deadsoftware.cavedroid.game.render.WindowsRenderer
+import ru.deadsoftware.cavedroid.game.ui.windows.GameWindowsConfigs
+import ru.deadsoftware.cavedroid.game.ui.windows.GameWindowsManager
+import ru.deadsoftware.cavedroid.game.ui.windows.inventory.SurvivalInventoryWindow
import ru.deadsoftware.cavedroid.misc.Assets
import javax.inject.Inject
import kotlin.math.atan
class SurvivalWindowRenderer @Inject constructor(
private val mainConfig: MainConfig,
private val mobsController: MobsController,
+ private val gameWindowsManager: GameWindowsManager,
+ private val gameItemsHolder: GameItemsHolder,
) : AbstractWindowRenderer(), IGameRenderer {
override val renderLayer get() = WindowsRenderer.RENDER_LAYER
}
private fun drawPlayerPortrait(spriteBatch: SpriteBatch, windowX: Float, windowY: Float, delta: Float) {
- val portraitX = windowX + Config.portraitMarginLeft +
- (Config.portraitWidth / 2 - mobsController.player.width / 2)
- val portraitY = windowY + Config.portraitMarginTop +
- (Config.portraitHeight / 2 - mobsController.player.height / 2)
+ val portraitX = windowX + GameWindowsConfigs.Survival.portraitMarginLeft +
+ (GameWindowsConfigs.Survival.portraitWidth / 2 - mobsController.player.width / 2)
+ val portraitY = windowY + GameWindowsConfigs.Survival.portraitMarginTop +
+ (GameWindowsConfigs.Survival.portraitHeight / 2 - mobsController.player.height / 2)
setPortraitHeadRotation(portraitX, portraitY)
mobsController.player.draw(spriteBatch, portraitX, portraitY, delta)
}
override fun draw(spriteBatch: SpriteBatch, shapeRenderer: ShapeRenderer, viewport: Rectangle, delta: Float) {
- val survivalWindow = survivalWindowTexture
+ val windowTexture = survivalWindowTexture
+ val window = gameWindowsManager.currentWindow as SurvivalInventoryWindow
- val windowX = viewport.width / 2 - survivalWindow.regionWidth / 2
- val windowY = viewport.height / 2 - survivalWindow.regionHeight / 2
+ val windowX = viewport.width / 2 - windowTexture.regionWidth / 2
+ val windowY = viewport.height / 2 - windowTexture.regionHeight / 2
- spriteBatch.draw(survivalWindow, windowX, windowY)
+ spriteBatch.draw(windowTexture, windowX, windowY)
drawPlayerPortrait(spriteBatch, windowX, windowY, delta)
drawItemsGrid(
spriteBatch = spriteBatch,
shapeRenderer = shapeRenderer,
- gridX = windowX + Config.itemsGridMarginLeft,
- gridY = windowY + Config.itemsGridMarginTop,
- items = mobsController.player.inventory.asSequence()
- .drop(Config.hotbarCells)
- .take(Config.itemsInCol * Config.itemsInRow)
+ gridX = windowX + GameWindowsConfigs.Survival.itemsGridMarginLeft,
+ gridY = windowY + GameWindowsConfigs.Survival.itemsGridMarginTop,
+ items = mobsController.player.inventory.items.asSequence()
+ .drop(GameWindowsConfigs.Survival.hotbarCells)
+ .take(GameWindowsConfigs.Survival.itemsInCol * GameWindowsConfigs.Survival.itemsInRow)
.asIterable(),
- itemsInRow = Config.itemsInRow,
- cellWidth = Config.itemsGridColWidth,
- cellHeight = Config.itemsGridRowHeight,
+ itemsInRow = GameWindowsConfigs.Survival.itemsInRow,
+ cellWidth = GameWindowsConfigs.Survival.itemsGridColWidth,
+ cellHeight = GameWindowsConfigs.Survival.itemsGridRowHeight,
)
drawItemsGrid(
spriteBatch = spriteBatch,
shapeRenderer = shapeRenderer,
- gridX = windowX + Config.itemsGridMarginLeft,
- gridY = windowY + survivalWindow.regionHeight - Config.hotbarOffsetFromBottom,
- items = mobsController.player.inventory.asSequence()
- .take(Config.hotbarCells)
+ gridX = windowX + GameWindowsConfigs.Survival.itemsGridMarginLeft,
+ gridY = windowY + windowTexture.regionHeight - GameWindowsConfigs.Survival.hotbarOffsetFromBottom,
+ items = mobsController.player.inventory.items.asSequence()
+ .take(GameWindowsConfigs.Survival.hotbarCells)
.asIterable(),
- itemsInRow = Config.hotbarCells,
- cellWidth = Config.itemsGridColWidth,
- cellHeight = Config.itemsGridRowHeight,
+ itemsInRow = GameWindowsConfigs.Survival.hotbarCells,
+ cellWidth = GameWindowsConfigs.Survival.itemsGridColWidth,
+ cellHeight = GameWindowsConfigs.Survival.itemsGridRowHeight,
)
- }
-
- companion object {
- private const val SURVIVAL_WINDOW_KEY = "survival"
-
- private data object Config {
- const val itemsGridMarginLeft = 8f
- const val itemsGridMarginTop = 84f
- const val itemsGridRowHeight = 18f
- const val itemsGridColWidth = 18f
+ drawItemsGrid(
+ spriteBatch = spriteBatch,
+ shapeRenderer = shapeRenderer,
+ gridX = windowX + GameWindowsConfigs.Survival.craftOffsetX,
+ gridY = windowY + GameWindowsConfigs.Survival.craftOffsetY,
+ items = window.craftingItems.asSequence().mapIndexedNotNull { index, it ->
+ if (index % 3 > 1 || index / 3 > 1) {
+ null
+ } else {
+ it ?: gameItemsHolder.fallbackItem.toInventoryItem()
+ }
+ }.asIterable(),
+ itemsInRow = GameWindowsConfigs.Survival.craftGridSize,
+ cellWidth = GameWindowsConfigs.Survival.itemsGridColWidth,
+ cellHeight = GameWindowsConfigs.Survival.itemsGridRowHeight,
+ )
- const val itemsInRow = 8
- const val itemsInCol = 5
+ window.craftResult?.draw(
+ spriteBatch = spriteBatch,
+ shapeRenderer = shapeRenderer,
+ x = windowX + GameWindowsConfigs.Survival.craftResultOffsetX,
+ y = windowY + GameWindowsConfigs.Survival.craftResultOffsetY
+ )
- const val hotbarOffsetFromBottom = 24f
- const val hotbarCells = 9
+ window.selectedItem?.drawSelected(
+ spriteBatch = spriteBatch,
+ x = Gdx.input.x * (viewport.width / Gdx.graphics.width),
+ y = Gdx.input.y * (viewport.height / Gdx.graphics.height)
+ )
+ }
- const val portraitMarginLeft = 24f
- const val portraitMarginTop = 8f
- const val portraitWidth = 48f
- const val portraitHeight = 68f
- }
+ companion object {
+ private const val SURVIVAL_WINDOW_KEY = "survival"
}
}
\ No newline at end of file