Added some text prompts to show R option for battle overlay switching

This commit is contained in:
Paul committed 2022-06-08 21:31:14 +10:00
1 parent cb25ae4453
commit aa191e76e8
7 files changed
+42 -4

No files matched your search

@@ -8,17 +8,16 @@ import com.cablemc.pokemoncobbled.common.client.battle.SingleActionRequest
import com.cablemc.pokemoncobbled.common.client.gui.battle.subscreen.BattleActionSelection
import com.cablemc.pokemoncobbled.common.client.gui.battle.subscreen.BattleGeneralActionSelection
import com.cablemc.pokemoncobbled.common.client.gui.battle.subscreen.BattleSwitchPokemonSelection
import com.cablemc.pokemoncobbled.common.client.gui.battle.widgets.BattleOptionTile
import com.cablemc.pokemoncobbled.common.client.keybind.currentKey
import com.cablemc.pokemoncobbled.common.client.keybind.keybinds.PartySendBinding
import com.cablemc.pokemoncobbled.common.client.render.drawScaledText
import com.cablemc.pokemoncobbled.common.client.render.models.blockbench.wavefunction.sineFunction
import com.cablemc.pokemoncobbled.common.net.messages.server.battle.BattleSelectActionsPacket
import com.cablemc.pokemoncobbled.common.util.battleLang
import com.cablemc.pokemoncobbled.common.util.cobbledResource
import net.minecraft.client.MinecraftClient
import net.minecraft.client.gui.screen.Screen
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.text.MutableText
import net.minecraft.util.Identifier
class BattleGUI : Screen(battleLang("gui.title")) {
companion object {
@@ -102,6 +101,15 @@ class BattleGUI : Screen(battleLang("gui.title")) {
}
}
drawScaledText(
matrixStack = poseStack,
text = battleLang("ui.hide_label", PartySendBinding.currentKey().localizedText),
scaleX = 0.8F,
scaleY = 0.8F,
x = 40,
y = MinecraftClient.getInstance().window.scaledHeight - 40,
opacity = 0.75F * opacity
)
queuedActions.forEach { it() }
queuedActions.clear()
@@ -6,11 +6,15 @@ import com.cablemc.pokemoncobbled.common.api.text.text
import com.cablemc.pokemoncobbled.common.client.CobbledResources
import com.cablemc.pokemoncobbled.common.client.PokemonCobbledClient
import com.cablemc.pokemoncobbled.common.client.battle.ActiveClientBattlePokemon
import com.cablemc.pokemoncobbled.common.client.keybind.currentKey
import com.cablemc.pokemoncobbled.common.client.keybind.keybinds.PartySendBinding
import com.cablemc.pokemoncobbled.common.client.render.drawScaledText
import com.cablemc.pokemoncobbled.common.client.render.getDepletableRedGreen
import com.cablemc.pokemoncobbled.common.client.render.models.blockbench.PoseableEntityState
import com.cablemc.pokemoncobbled.common.client.render.models.blockbench.wavefunction.sineFunction
import com.cablemc.pokemoncobbled.common.entity.pokemon.PokemonEntity
import com.cablemc.pokemoncobbled.common.pokemon.Species
import com.cablemc.pokemoncobbled.common.util.battleLang
import com.cablemc.pokemoncobbled.common.util.cobbledResource
import com.cablemc.pokemoncobbled.common.util.lang
import com.mojang.blaze3d.systems.RenderSystem
@@ -39,6 +43,7 @@ class BattleOverlay : InGameHud(MinecraftClient.getInstance()) {
const val PORTRAIT_DIAMETER = 116 / 432F * TILE_WIDTH
const val PORTRAIT_OFFSET = 10 / 432F * TILE_WIDTH
private val PROMPT_TEXT_OPACITY_CURVE = sineFunction(period = 4F, verticalShift = 0.5F, amplitude = 0.5F)
val battleInfoBase = cobbledResource("ui/battle/battle_info_base.png")
val battleInfoBaseFlipped = cobbledResource("ui/battle/battle_info_base_flipped.png")
@@ -48,8 +53,13 @@ class BattleOverlay : InGameHud(MinecraftClient.getInstance()) {
var opacity = MIN_OPACITY
val opacityRatio: Double
get() = (opacity - MIN_OPACITY) / (MAX_OPACITY - MIN_OPACITY)
var passedSeconds = 0F
override fun render(matrices: MatrixStack, tickDelta: Float) {
passedSeconds += tickDelta / 20
if (passedSeconds > 100) {
passedSeconds -= 100
}
val battle = PokemonCobbledClient.battle ?: return
opacity = if (battle.minimised) {
max(opacity - tickDelta * OPACITY_CHANGE_PER_SECOND, MIN_OPACITY)
@@ -63,6 +73,18 @@ class BattleOverlay : InGameHud(MinecraftClient.getInstance()) {
side1.activeClientBattlePokemon.forEachIndexed { index, activeClientBattlePokemon -> drawTile(matrices, tickDelta, activeClientBattlePokemon, true, index) }
side2.activeClientBattlePokemon.forEachIndexed { index, activeClientBattlePokemon -> drawTile(matrices, tickDelta, activeClientBattlePokemon, false, index) }
if (MinecraftClient.getInstance().currentScreen !is BattleGUI && battle.mustChoose) {
val textOpacity = PROMPT_TEXT_OPACITY_CURVE(passedSeconds)
drawScaledText(
matrixStack = matrices,
text = battleLang("ui.actions_label", PartySendBinding.currentKey().localizedText),
x = MinecraftClient.getInstance().window.scaledWidth / 2,
y = 40,
opacity = textOpacity,
centered = true
)
}
}
@@ -93,11 +93,14 @@ class BattleMoveSelection(
fun isHovered(mouseX: Double, mouseY: Double) = mouseX >= x && mouseX <= x + MOVE_WIDTH && mouseY >= y && mouseY <= y + MOVE_HEIGHT
fun onClick() {
moveSelection.playDownSound(MinecraftClient.getInstance().soundManager)
val targets = move.target.targetList(moveSelection.request.activePokemon)
if (targets == null) {
moveSelection.battleGUI.selectAction(moveSelection.request, MoveActionResponse(move.id, null))
} else if (targets.size == 1) {
moveSelection.battleGUI.selectAction(moveSelection.request, MoveActionResponse(move.id, targets[0].getPNX()))
} else {
// Target selection
}
}
}
@@ -96,6 +96,7 @@ class BattleSwitchPokemonSelection(
override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
val clicked = tiles.find { it.isHovered(mouseX, mouseY) } ?: return false
val pokemon = clicked.pokemon
playDownSound(MinecraftClient.getInstance().soundManager)
battleGUI.selectAction(request, SwitchActionResponse(pokemon.uuid))
return true
}
@@ -8,6 +8,7 @@ import com.cablemc.pokemoncobbled.common.net.messages.client.battle.BattleMakeCh
object BattleMakeChoiceHandler : PacketHandler<BattleMakeChoicePacket> {
override fun invoke(packet: BattleMakeChoicePacket, ctx: CobbledNetwork.NetworkContext) {
val battle = PokemonCobbledClient.battle ?: return
PokemonCobbledClient.battleOverlay.passedSeconds = 0F
battle.mustChoose = true
}
}
@@ -64,6 +64,9 @@ fun drawScaledText(
centered: Boolean = false,
shadow: Boolean = false
) {
if (opacity.toFloat() < 0.05F) {
return
}
matrixStack.push()
matrixStack.scale(scaleX, scaleY, 1F)
drawText(
@@ -74,7 +74,7 @@
"pokemoncobbled.ui.changemove": "Change",
"pokemoncobbled.battle.ui.fight": "Fight",
"pokemoncobbled.battle.ui.switch": "Switch",
"pokemoncobbled.battle.ui.hide_label": "Press %1$s to move.",
"pokemoncobbled.battle.ui.hide_label": "Press %1$s to move around.",
"pokemoncobbled.battle.ui.actions_label": "You need to choose an action. Press %1$s.",
"pokemoncobbled.challenge_label": "Press %1$s to battle.",