diff --git a/src/main/java/com/minelittlepony/unicopia/ability/Ability.java b/src/main/java/com/minelittlepony/unicopia/ability/Ability.java index 1b950cf0..338053a2 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/Ability.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/Ability.java @@ -6,6 +6,8 @@ import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.ability.data.Hit; import com.minelittlepony.unicopia.entity.player.Pony; +import net.minecraft.text.Text; +import net.minecraft.text.TranslatableText; import net.minecraft.util.Identifier; import net.minecraft.world.World; @@ -63,6 +65,14 @@ public interface Ability { return new Identifier(id.getNamespace(), "textures/gui/ability/" + id.getPath() + ".png"); } + /** + * The display name for this ability. + */ + default Text getName() { + Identifier id = Abilities.REGISTRY.getId(this); + return new TranslatableText("ability." + id.getNamespace() + "." + id.getPath().replace('/', '.')); + } + /** * Called to actually apply the ability. * Only called on the server side. diff --git a/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java b/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java index f1b70924..48f7d3ed 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java @@ -40,11 +40,12 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable { } } - public void activate(AbilitySlot slot, long page) { + public Optional> activate(AbilitySlot slot, long page) { Stat stat = getStat(slot); if (stat.canSwitchStates()) { - stat.getAbility(page).ifPresent(stat::setActiveAbility); + return stat.getAbility(page).flatMap(stat::setActiveAbility); } + return Optional.empty(); } public Collection getStats() { @@ -218,13 +219,15 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable { .count(); } - protected synchronized void setActiveAbility(Ability power) { + protected synchronized Optional> setActiveAbility(@Nullable Ability power) { if (activeAbility.orElse(null) != power) { triggered = false; activeAbility = Optional.ofNullable(power); setWarmup(activeAbility.map(p -> p.getWarmupTime(player)).orElse(0)); setCooldown(0); + return activeAbility; } + return Optional.empty(); } protected synchronized Optional> getActiveAbility() { diff --git a/src/main/java/com/minelittlepony/unicopia/client/KeyBindingsHandler.java b/src/main/java/com/minelittlepony/unicopia/client/KeyBindingsHandler.java index 04a413d8..49d1466a 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/KeyBindingsHandler.java +++ b/src/main/java/com/minelittlepony/unicopia/client/KeyBindingsHandler.java @@ -7,6 +7,7 @@ import java.util.Set; import org.lwjgl.glfw.GLFW; +import com.minelittlepony.unicopia.ability.Ability; import com.minelittlepony.unicopia.ability.AbilityDispatcher; import com.minelittlepony.unicopia.ability.AbilitySlot; import com.minelittlepony.unicopia.client.gui.UHud; @@ -17,7 +18,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.options.KeyBinding; import net.minecraft.client.sound.PositionedSoundInstance; import net.minecraft.sound.SoundEvents; -import net.minecraft.text.LiteralText; +import net.minecraft.text.TranslatableText; import net.minecraft.util.math.MathHelper; public class KeyBindingsHandler { @@ -82,7 +83,7 @@ public class KeyBindingsHandler { PressedState state = checkPressed(i); if (state != PressedState.UNCHANGED) { if (state == PressedState.PRESSED) { - abilities.activate(slot, page); + abilities.activate(slot, page).map(Ability::getName).ifPresent(UHud.INSTANCE::setMessage); } else { abilities.clear(slot); } @@ -94,7 +95,7 @@ public class KeyBindingsHandler { private void changePage(MinecraftClient client, long max, int sigma) { page += sigma; client.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.75F + (0.25F * sigma))); - UHud.instance.setMessage(new LiteralText(page + " of " + max)); + UHud.INSTANCE.setMessage(new TranslatableText("gui.unicopia.page_num", page, max)); } private PressedState checkPressed(KeyBinding binding) { @@ -104,7 +105,6 @@ public class KeyBindingsHandler { return PressedState.UNPRESSED; } - return PressedState.UNCHANGED; } diff --git a/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java b/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java index 57ed6052..9d6411d0 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java +++ b/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java @@ -63,7 +63,7 @@ public class UnicopiaClient implements ClientModInitializer { private void onTick(MinecraftClient client) { KeyBindingsHandler.INSTANCE.tick(client); - UHud.instance.tick(); + UHud.INSTANCE.tick(); } private void onScreenInit(Screen screen, ButtonList buttons) { diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/ManaRingSlot.java b/src/main/java/com/minelittlepony/unicopia/client/gui/ManaRingSlot.java index c82f9b72..95bac4ab 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/ManaRingSlot.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/ManaRingSlot.java @@ -19,9 +19,10 @@ import net.minecraft.util.math.Matrix4f; class ManaRingSlot extends Slot { private static final double TWO_PI = Math.PI * 2; - public ManaRingSlot(UHud uHud, AbilitySlot normalSlot, AbilitySlot backupSlot, int x, int y, int padding, int size, - int labelOffset, int iconSize) { - super(uHud, normalSlot, backupSlot, x, y, padding, size, labelOffset, iconSize); + public ManaRingSlot(UHud uHud, AbilitySlot normalSlot, AbilitySlot backupSlot, int x, int y) { + super(uHud, normalSlot, backupSlot, x, y, 8, 49, 33, 43, 42); + background(0, 5); + foreground(0, 59); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/Slot.java b/src/main/java/com/minelittlepony/unicopia/client/gui/Slot.java index 88d4e736..94f5cfef 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/Slot.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/Slot.java @@ -21,37 +21,44 @@ class Slot { private float lastCooldown; private final int slotPadding; - private final int labelOffset; + private final int labelX; + private final int labelY; private final int size; private final int iconSize; - private int textureU; - private int textureV; + private int backgroundU; + private int backgroundV; - private int backgroundU = 105; - private int backgroundV = 105; + private int foregroundU = 105; + private int foregroundV = 105; - public Slot(UHud uHud, AbilitySlot normalSlot, AbilitySlot backupSlot, int x, int y, int padding, int size, int labelOffset, int iconSize) { + public Slot(UHud uHud, AbilitySlot normalSlot, AbilitySlot backupSlot, int x, int y) { + this(uHud, normalSlot, backupSlot, x, y, 3, 22, 17, 17, 19); + background(80, 105); + } + + public Slot(UHud uHud, AbilitySlot normalSlot, AbilitySlot backupSlot, int x, int y, int padding, int size, int labelX, int labelY, int iconSize) { this.uHud = uHud; this.aSlot = normalSlot; this.bSlot = backupSlot; this.x = x; this.y = y; this.slotPadding = padding; - this.labelOffset = labelOffset; + this.labelX = labelX; + this.labelY = labelY; this.size = size; this.iconSize = iconSize; } Slot background(int u, int v) { - textureU = u; - textureV = v; + backgroundU = u; + backgroundV = v; return this; } Slot foreground(int u, int v) { - backgroundU = u; - backgroundV = v; + foregroundU = u; + foregroundV = v; return this; } @@ -62,11 +69,10 @@ class Slot { float cooldown = abilities.getStat(bSwap ? bSlot : aSlot).getFillProgress(); // background - UHud.drawTexture(matrices, 0, 0, textureU, textureV, size, size, 128, 128); + UHud.drawTexture(matrices, 0, 0, backgroundU, backgroundV, size, size, 128, 128); uHud.renderAbilityIcon(matrices, abilities.getStat(bSwap ? bSlot : aSlot), slotPadding / 2, slotPadding / 2, iconSize, iconSize, iconSize, iconSize); - if (cooldown > 0 && cooldown <= 1) { float lerpCooldown = MathHelper.lerp(tickDelta, cooldown, lastCooldown); @@ -88,15 +94,14 @@ class Slot { protected void renderContents(MatrixStack matrices, AbilityDispatcher abilities, boolean bSwap, float tickDelta) { // contents - - UHud.drawTexture(matrices, 0, 0, backgroundU, backgroundV, size, size, 128, 128); + UHud.drawTexture(matrices, 0, 0, foregroundU, foregroundV, size, size, 128, 128); } void renderLabel(MatrixStack matrices, AbilityDispatcher abilities, float tickDelta) { Text label = KeyBindingsHandler.INSTANCE.getBinding(aSlot).getBoundKeyLocalizedText(); matrices.push(); - matrices.translate(x + labelOffset, y + labelOffset, 0); + matrices.translate(x + labelX, y + labelY, 0); matrices.scale(0.5F, 0.5F, 0.5F); UHud.drawTextWithShadow(matrices, uHud.font, label, 0, 0, 0xFFFFFF); diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java b/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java index 373337a6..b79818ea 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java @@ -26,7 +26,7 @@ import net.minecraft.util.Util; public class UHud extends DrawableHelper { - public static final UHud instance = new UHud(); + public static final UHud INSTANCE = new UHud(); public static final Identifier HUD_TEXTURE = new Identifier("unicopia", "textures/gui/hud.png"); @@ -35,9 +35,9 @@ public class UHud extends DrawableHelper { final MinecraftClient client = MinecraftClient.getInstance(); private final List slots = Util.make(new ArrayList<>(), slots -> { - slots.add(new ManaRingSlot(this, AbilitySlot.PRIMARY, AbilitySlot.PASSIVE, 0, 0, 8, 49, 38, 42).background(0, 5).foreground(0, 59)); - slots.add(new Slot(this, AbilitySlot.SECONDARY, AbilitySlot.SECONDARY, 26, -5, 3, 22, 17, 19).background(80, 105)); - slots.add(new Slot(this, AbilitySlot.TERTIARY, AbilitySlot.TERTIARY, 36, 19, 3, 22, 17, 19).background(80, 105)); + slots.add(new ManaRingSlot(this, AbilitySlot.PRIMARY, AbilitySlot.PASSIVE, 0, 0)); + slots.add(new Slot(this, AbilitySlot.SECONDARY, AbilitySlot.SECONDARY, 26, -5)); + slots.add(new Slot(this, AbilitySlot.TERTIARY, AbilitySlot.TERTIARY, 36, 19)); }); @Nullable diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinInGameHud.java b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinInGameHud.java index ace01587..f7bb7132 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinInGameHud.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinInGameHud.java @@ -14,6 +14,6 @@ import net.minecraft.client.util.math.MatrixStack; public class MixinInGameHud { @Inject(method = "render(Lnet/minecraft/client/util/math/MatrixStack;F)V", at = @At("HEAD")) private void onRender(MatrixStack stack, float tickDelta, CallbackInfo info) { - UHud.instance.render((InGameHud)(Object)this, stack, tickDelta); + UHud.INSTANCE.render((InGameHud)(Object)this, stack, tickDelta); } } diff --git a/src/main/resources/assets/unicopia/lang/en_us.json b/src/main/resources/assets/unicopia/lang/en_us.json index 05c8e2bb..4e83dd5f 100644 --- a/src/main/resources/assets/unicopia/lang/en_us.json +++ b/src/main/resources/assets/unicopia/lang/en_us.json @@ -26,6 +26,8 @@ "unicopia.effect.tribe.stage.determination": "As your bones realign you are filled determination.", "unicopia.effect.tribe.stage.resurection": "Knowing you will return to this world as a %s", + "effect.food_poisoning": "Food Poisoning", + "effect.unicopia.change_race_earth": "Earth Pony Metamorphosis", "item.minecraft.potion.effect.unicopia.tribe_swap_earth": "Potion of Earth Pony Metamorphosis", "item.minecraft.splash_potion.effect.unicopia.tribe_swap_earth": "Splash Potion of Earth Pony Metamorphosis", @@ -123,7 +125,25 @@ "toxicity.severe.name": "Toxic", "toxicity.lethal.name": "Lethal", + "ability.unicopia.shoot": "Magic Missle", + "ability.unicopia.cast": "Counterspell", + "ability.unicopia.teleport": "Teleport", + "ability.unicopia.grow": "Earthly Nourishment", + "ability.unicopia.stomp": "Ground Pound", + "ability.unicopia.pummel": "Crushing Blow", + "ability.unicopia.carry": "Pickup/Drop Passenger", + "ability.unicopia.hang": "Cling to Ceiling", + "ability.unicopia.eee": "Deafening Screech", + "gui.unicopia": "Unicopia...", + "gui.unicopia.page_num": "%d of %d", + + "unicopia.category.name": "Pony Abilities", + + "key.unicopia.primary": "Primary Ability", + "key.unicopia.secondary": "Secondary Ability", + "key.unicopia.tertiary": "Tertiary Ability", + "key.unicopia.passive": "Passive Ability", "commands.race.success.self": "Your race has been updated", "commands.race.success.otherself": "%1$s changed race to %2$s", @@ -206,13 +226,6 @@ "unicopia.race.bat": "Bat Pony", "unicopia.race.bat.alt": "Bat Ponies", - "unicopia.category.name": "Pony Abilities", - - "key.unicopia.primary": "Primary Ability", - "key.unicopia.secondary": "Secondary Ability", - "key.unicopia.tertiary": "Tertiary Ability", - "key.unicopia.passive": "Passive Ability", - "death.attack.tribe_swap": "%1$s was reborn into a different tribe", "death.attack.magical_exhaustion": "%1$s exhausted themselves", "death.attack.alicorn_amulet": "%1$s was driven insane", @@ -230,8 +243,6 @@ "death.attack.food_poisoning": "%1$s died of food poisoning", "death.attack.food_poisoning.attacker": "%2$s poisoned %1$s to death", - "effect.food_poisoning": "Food Poisoning", - "unicopia.subtitle.flap_wings": "Wing Flaps", "unicopia.subtitle.wind_rush": "Wind Gust", "unicopia.subtitle.insects": "Insects Scurrying",