summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 87ae3cc)
raw | patch | inline | side by side (parent: 87ae3cc)
author | fredboy <fredboy@protonmail.com> | |
Tue, 23 Apr 2024 04:05:17 +0000 (11:05 +0700) | ||
committer | fredboy <fredboy@protonmail.com> | |
Tue, 23 Apr 2024 04:05:17 +0000 (11:05 +0700) |
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java b/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java
index 7647e69c2a6c0ad9d782de5b5533ccc75123fec1..8118fec05abe59756d90d568f06851b4e7243c45 100644 (file)
import ru.deadsoftware.cavedroid.game.mobs.Player;
import ru.deadsoftware.cavedroid.game.objects.TouchButton;
import ru.deadsoftware.cavedroid.game.render.IGameRenderer;
+import ru.deadsoftware.cavedroid.game.windows.GameWindowsManager;
import ru.deadsoftware.cavedroid.misc.Assets;
import ru.deadsoftware.cavedroid.misc.Renderer;
private final KeyboardInputActionMapper mKeyboardInputActionMapper;
private final Set<IGameInputHandler<MouseInputAction>> mMouseInputHandlers;
private final Set<IGameInputHandler<KeyboardInputAction>> mKeyboardInputHandlers;
+ private final GameWindowsManager mGameWindowsManager;
@Inject
GameRenderer(MainConfig mainConfig,
MouseInputActionMapper mouseInputActionMapper,
KeyboardInputActionMapper keyboardInputActionMapper,
Set<IGameInputHandler<MouseInputAction>> mouseInputHandlers,
- Set<IGameInputHandler<KeyboardInputAction>> keyboardInputHandlers) {
+ Set<IGameInputHandler<KeyboardInputAction>> keyboardInputHandlers,
+ GameWindowsManager gameWindowsManager) {
super(mainConfig.getWidth(), mainConfig.getHeight());
mMainConfig = mainConfig;
mKeyboardInputActionMapper = keyboardInputActionMapper;
mMouseInputHandlers = mouseInputHandlers;
mKeyboardInputHandlers = keyboardInputHandlers;
+ mGameWindowsManager = gameWindowsManager;
Gdx.gl.glClearColor(0f, .6f, .6f, 1f);
}
}
private TouchButton getTouchedKey(float touchX, float touchY) {
+ if (mGameWindowsManager.getCurrentWindow() != GameUiWindow.NONE) {
+ return nullButton;
+ }
for (ObjectMap.Entry<String, TouchButton> entry : Assets.guiMap) {
TouchButton button = entry.value;
if (button.getRect().contains(touchX, touchY)) {
diff --git a/core/src/ru/deadsoftware/cavedroid/game/input/MouseInputHandlersModule.kt b/core/src/ru/deadsoftware/cavedroid/game/input/MouseInputHandlersModule.kt
index e17662eb22bc05631d1f5fb9c7d2402d8b8b2bc4..aef4c0bca680d01f3624114a19bf6e92ee5ce3df 100644 (file)
fun bindUseItemMouseInputActionHandler(handler: UseItemMouseInputHandler): IGameInputHandler<MouseInputAction> {
return handler
}
+
+ @Binds
+ @IntoSet
+ @GameScope
+ fun bindSelectSurvivalInventoryItemMouseInputHandler(handler: SelectSurvivalInventoryItemMouseInputHandler): IGameInputHandler<MouseInputAction> {
+ return handler
+ }
}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectSurvivalInventoryItemMouseInputHandler.kt b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectSurvivalInventoryItemMouseInputHandler.kt
--- /dev/null
@@ -0,0 +1,65 @@
+package ru.deadsoftware.cavedroid.game.input.handler.mouse
+
+import com.badlogic.gdx.Gdx
+import ru.deadsoftware.cavedroid.game.GameItemsHolder
+import ru.deadsoftware.cavedroid.game.GameScope
+import ru.deadsoftware.cavedroid.game.GameUiWindow
+import ru.deadsoftware.cavedroid.game.input.IGameInputHandler
+import ru.deadsoftware.cavedroid.game.input.action.MouseInputAction
+import ru.deadsoftware.cavedroid.game.input.action.keys.MouseInputActionKey
+import ru.deadsoftware.cavedroid.game.input.isInsideWindow
+import ru.deadsoftware.cavedroid.game.mobs.MobsController
+import ru.deadsoftware.cavedroid.game.windows.GameWindowsConfigs
+import ru.deadsoftware.cavedroid.game.windows.GameWindowsManager
+import ru.deadsoftware.cavedroid.misc.Assets
+import javax.inject.Inject
+
+@GameScope
+class SelectSurvivalInventoryItemMouseInputHandler @Inject constructor(
+ private val gameWindowsManager: GameWindowsManager,
+ private val mobsController: MobsController,
+ private val gameItemsHolder: GameItemsHolder,
+) : IGameInputHandler<MouseInputAction> {
+
+ private val survivalWindowTexture get() = requireNotNull(Assets.textureRegions["survival"])
+
+ override fun checkConditions(action: MouseInputAction): Boolean {
+ return gameWindowsManager.getCurrentWindow() == GameUiWindow.SURVIVAL_INVENTORY &&
+ isInsideWindow(action, survivalWindowTexture) &&
+ (action.actionKey is MouseInputActionKey.Left || action.actionKey is MouseInputActionKey.Touch)
+ && action.actionKey.touchUp
+ }
+
+ override fun handle(action: MouseInputAction) {
+ val survivalTexture = survivalWindowTexture
+ val xOnGrid = (action.screenX - (action.cameraViewport.width / 2 - survivalTexture.regionWidth / 2 +
+ GameWindowsConfigs.Survival.itemsGridMarginLeft)) /
+ GameWindowsConfigs.Survival.itemsGridColWidth
+ val yOnGrid = (action.screenY - (action.cameraViewport.height / 2 - survivalTexture.regionHeight / 2 +
+ GameWindowsConfigs.Survival.itemsGridMarginTop)) /
+ GameWindowsConfigs.Survival.itemsGridRowHeight
+
+ if (xOnGrid < 0 || xOnGrid >= GameWindowsConfigs.Survival.itemsInRow ||
+ yOnGrid < 0 || yOnGrid > GameWindowsConfigs.Survival.itemsInCol) {
+ return
+ }
+
+ var itemIndex = ((xOnGrid.toInt() + yOnGrid.toInt() * GameWindowsConfigs.Survival.itemsInRow))
+ itemIndex += GameWindowsConfigs.Survival.hotbarCells
+
+ if (itemIndex >= mobsController.player.inventory.size) {
+ itemIndex -= mobsController.player.inventory.size
+ }
+
+ val item = mobsController.player.inventory[itemIndex]
+ mobsController.player.inventory[itemIndex] = gameWindowsManager.selectedItem ?: gameItemsHolder.fallbackItem.toInventoryItem()
+ gameWindowsManager.selectedItem = item
+
+ Gdx.app.debug(TAG, "selected item: ${gameWindowsManager.selectedItem?.item?.params?.key ?: "null"}; index $itemIndex, grid ($xOnGrid;$yOnGrid)")
+ }
+
+ companion object {
+ private const val TAG = "SelectSurvivalInventoryItemMouseInputHandler"
+
+ }
+}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/model/item/InventoryItem.kt b/core/src/ru/deadsoftware/cavedroid/game/model/item/InventoryItem.kt
index 49cc59d6a5366f484df8a51a6ecd400d538a2a14..89186595d360ee3f2642306baefeb893ab94e223 100644 (file)
spriteBatch.drawString(text, x, y, Color.WHITE)
}
+ fun drawSelected(spriteBatch: SpriteBatch, x: Float, y: Float) {
+ if (item.isNone()) {
+ return
+ }
+
+ val sprite = item.sprite
+ sprite.setOriginCenter()
+ sprite.setPosition(x, y)
+ sprite.setScale(1.25f)
+ sprite.draw(spriteBatch)
+ sprite.setScale(1f)
+ }
+
fun draw(spriteBatch: SpriteBatch, shapeRenderer: ShapeRenderer, x: Float, y: Float) {
if (item.isNone()) {
return
diff --git a/core/src/ru/deadsoftware/cavedroid/game/render/TouchControlsRenderer.kt b/core/src/ru/deadsoftware/cavedroid/game/render/TouchControlsRenderer.kt
index d9dc5c48ab9b01818874852802643cc256aafe2f..5c95d696c675cadba52dcaf7fd1d8186e9a79491 100644 (file)
import com.badlogic.gdx.math.Rectangle
import ru.deadsoftware.cavedroid.MainConfig
import ru.deadsoftware.cavedroid.game.GameScope
+import ru.deadsoftware.cavedroid.game.GameUiWindow
import ru.deadsoftware.cavedroid.game.mobs.MobsController
import ru.deadsoftware.cavedroid.game.mobs.Player.ControlMode
+import ru.deadsoftware.cavedroid.game.windows.GameWindowsManager
import ru.deadsoftware.cavedroid.misc.Assets
import ru.deadsoftware.cavedroid.misc.utils.ArrayMapExtensions.component1
import ru.deadsoftware.cavedroid.misc.utils.ArrayMapExtensions.component2
class TouchControlsRenderer @Inject constructor(
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]
override fun draw(spriteBatch: SpriteBatch, shapeRenderer: ShapeRenderer, viewport: Rectangle, delta: Float) {
- if (!mainConfig.isTouch) {
+ if (!mainConfig.isTouch || gameWindowsManager.getCurrentWindow() != GameUiWindow.NONE) {
return
}
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..39580de82cecd8a42d63a0dcf9eb25fd991ddb97 100644 (file)
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.windows.GameWindowsConfigs
+import ru.deadsoftware.cavedroid.game.windows.GameWindowsManager
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,
) : 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)
drawItemsGrid(
spriteBatch = spriteBatch,
shapeRenderer = shapeRenderer,
- gridX = windowX + Config.itemsGridMarginLeft,
- gridY = windowY + Config.itemsGridMarginTop,
+ gridX = windowX + GameWindowsConfigs.Survival.itemsGridMarginLeft,
+ gridY = windowY + GameWindowsConfigs.Survival.itemsGridMarginTop,
items = mobsController.player.inventory.asSequence()
- .drop(Config.hotbarCells)
- .take(Config.itemsInCol * Config.itemsInRow)
+ .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,
+ gridX = windowX + GameWindowsConfigs.Survival.itemsGridMarginLeft,
+ gridY = windowY + survivalWindow.regionHeight - GameWindowsConfigs.Survival.hotbarOffsetFromBottom,
items = mobsController.player.inventory.asSequence()
- .take(Config.hotbarCells)
+ .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,
+ )
+
+ gameWindowsManager.selectedItem?.drawSelected(
+ spriteBatch = spriteBatch,
+ x = Gdx.input.x * (viewport.width / Gdx.graphics.width),
+ y = Gdx.input.y * (viewport.height / Gdx.graphics.height)
)
}
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
-
- const val itemsInRow = 8
- const val itemsInCol = 5
-
- const val hotbarOffsetFromBottom = 24f
- const val hotbarCells = 9
-
- const val portraitMarginLeft = 24f
- const val portraitMarginTop = 8f
- const val portraitWidth = 48f
- const val portraitHeight = 68f
- }
}
}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/windows/GameWindowsConfigs.kt b/core/src/ru/deadsoftware/cavedroid/game/windows/GameWindowsConfigs.kt
index cf8112720b64d60158e755f58d32c088e9c7c03f..6dde753a860c02360c47631413e310f897a6813e 100644 (file)
val itemsOnPage get() = itemsInCol * itemsInRow
}
+
+ data object Survival {
+ const val itemsGridMarginLeft = 8f
+ const val itemsGridMarginTop = 84f
+
+ const val itemsGridRowHeight = 18f
+ const val itemsGridColWidth = 18f
+
+ const val itemsInRow = 9
+ const val itemsInCol = 5
+
+ const val hotbarOffsetFromBottom = 24f
+ const val hotbarCells = 9
+
+ const val portraitMarginLeft = 24f
+ const val portraitMarginTop = 8f
+ const val portraitWidth = 48f
+ const val portraitHeight = 68f
+ }
}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/windows/GameWindowsManager.kt b/core/src/ru/deadsoftware/cavedroid/game/windows/GameWindowsManager.kt
index 22476350367c54e5f4b5d3a0fa949b648748589f..302562fb9b60d086b30bc79ca6b1baf22099ef12 100644 (file)
import ru.deadsoftware.cavedroid.game.GameScope
import ru.deadsoftware.cavedroid.game.GameUiWindow
import ru.deadsoftware.cavedroid.game.mobs.MobsController
+import ru.deadsoftware.cavedroid.game.model.item.InventoryItem
import javax.inject.Inject
@GameScope
var creativeScrollAmount = 0
var isDragging = false
+ var selectedItem: InventoryItem? = null
fun getCurrentWindow(): GameUiWindow {
return mainConfig.gameUiWindow