⏱️❕
отображение применяемой способности и её статус при нажатии кнопки (#123)
This commit is contained in:
parent
3fa0933ac8
commit
4de6be0289
@ -195,6 +195,7 @@ public final class OverdriveThatMatters {
|
||||
EVENT_BUS.addListener(EventPriority.NORMAL, AndroidMenuKeyMapping.INSTANCE::onRenderGuiEvent);
|
||||
EVENT_BUS.addListener(EventPriority.NORMAL, AndroidMenuKeyMapping.INSTANCE::onMouseClick);
|
||||
|
||||
EVENT_BUS.addListener(EventPriority.NORMAL, AndroidAbilityKeyMapping.INSTANCE::onRenderGuiEvent);
|
||||
EVENT_BUS.addListener(EventPriority.NORMAL, AndroidAbilityKeyMapping.INSTANCE::onRenderLevel);
|
||||
|
||||
event.enqueueWork(GlobalEventHandlerKt::recordClientThread);
|
||||
|
@ -22,6 +22,7 @@ abstract class AndroidSwitchableFeature(type: AndroidFeatureType<*>, android: Ma
|
||||
|
||||
open val allowToSwitchByPlayer: Boolean get() = true
|
||||
open val allowToSwitchByPlayerWhileSpectator: Boolean get() = true
|
||||
open val isOnCooldown: Boolean get() = false
|
||||
|
||||
// TODO: PoseStack is stripped from server dist
|
||||
// but it doesn't seem to cause issues?
|
||||
|
@ -56,8 +56,11 @@ class EnderTeleporterFeature(capability: MatteryPlayerCapability) : AndroidActiv
|
||||
var lastTeleport = 0
|
||||
private set
|
||||
|
||||
override val isOnCooldown: Boolean
|
||||
get() = cooldown > 0
|
||||
|
||||
private fun canUse(): Boolean {
|
||||
return cooldown <= 0 && android.androidEnergy.extractEnergyInnerExact(ServerConfig.EnderTeleporter.ENERGY_COST, true).isPositive
|
||||
return !isOnCooldown && android.androidEnergy.extractEnergyInnerExact(ServerConfig.EnderTeleporter.ENERGY_COST, true).isPositive
|
||||
}
|
||||
|
||||
override fun serializeNBT(): CompoundTag {
|
||||
|
@ -3,12 +3,15 @@ package ru.dbotthepony.mc.otm.client
|
||||
import com.mojang.blaze3d.platform.InputConstants
|
||||
import net.minecraft.client.KeyMapping
|
||||
import net.minecraftforge.client.event.RegisterKeyMappingsEvent
|
||||
import net.minecraftforge.client.event.RenderGuiEvent
|
||||
import net.minecraftforge.client.event.RenderLevelStageEvent
|
||||
import net.minecraftforge.client.settings.KeyConflictContext
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
||||
import ru.dbotthepony.mc.otm.android.AndroidActiveFeature
|
||||
import ru.dbotthepony.mc.otm.capability.matteryPlayer
|
||||
import ru.dbotthepony.mc.otm.client.render.Widgets18
|
||||
import ru.dbotthepony.mc.otm.client.render.is3DContext
|
||||
import ru.dbotthepony.mc.otm.core.RGBAColor
|
||||
import ru.dbotthepony.mc.otm.network.ActivateAndroidFeaturePacket
|
||||
import ru.dbotthepony.mc.otm.network.MatteryPlayerNetworkChannel
|
||||
|
||||
@ -40,6 +43,30 @@ object AndroidAbilityKeyMapping : KeyMapping("key.otm.android_ability", KeyConfl
|
||||
}
|
||||
}
|
||||
|
||||
fun onRenderGuiEvent(event: RenderGuiEvent.Post) {
|
||||
if (!isDown) {
|
||||
return
|
||||
}
|
||||
|
||||
val feature = feature ?: return
|
||||
|
||||
val size = minecraft.window.guiScaledHeight.coerceAtMost(minecraft.window.guiScaledWidth).toFloat() * 0.25f
|
||||
val iconSize = size * 0.25f
|
||||
|
||||
val x = minecraft.window.guiScaledWidth.toFloat() * .5f + iconSize / 2f
|
||||
val y = minecraft.window.guiScaledHeight.toFloat() * .5f - iconSize / 2f
|
||||
|
||||
RGBAColor.WHITE.setSystemColor()
|
||||
|
||||
feature.renderIcon(event.poseStack, x, y, iconSize, iconSize)
|
||||
|
||||
if (feature.isOnCooldown) {
|
||||
RGBAColor.WHITE.setSystemColor()
|
||||
|
||||
Widgets18.COOLDOWN.render(event.poseStack, x, y + iconSize, iconSize, iconSize)
|
||||
}
|
||||
}
|
||||
|
||||
fun onRenderLevel(event: RenderLevelStageEvent) {
|
||||
if (!isDown) {
|
||||
return
|
||||
|
@ -45,4 +45,5 @@ object Widgets18 {
|
||||
|
||||
val BUTTON_DISABLED_STRETCHABLE = makeButton(GRID)
|
||||
val BUTTON_DISABLED = GRID.next()
|
||||
val COOLDOWN = GRID.next()
|
||||
}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
Loading…
Reference in New Issue
Block a user