diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/KillMessageOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/KillMessageOverlay.java index 10ea42814..9837f869a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/KillMessageOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/KillMessageOverlay.java @@ -71,7 +71,35 @@ public class KillMessageOverlay implements LayeredDraw.Layer { return; } - float totalTop = 5; + int screenWidth = guiGraphics.guiWidth(); + int screenHeight = guiGraphics.guiHeight(); + + var pos = KillMessageConfig.KILL_MESSAGE_POSITION.get(); + int posX = screenWidth; + float posY = KillMessageConfig.KILL_MESSAGE_MARGIN_Y.get(); + int count = KillMessageConfig.KILL_MESSAGE_COUNT.get(); + boolean left = false; + + switch (pos) { + case LEFT_TOP -> { + posX = KillMessageConfig.KILL_MESSAGE_MARGIN_X.get(); + posY = KillMessageConfig.KILL_MESSAGE_MARGIN_Y.get(); + left = true; + } + case RIGHT_TOP -> { + posX = screenWidth - KillMessageConfig.KILL_MESSAGE_MARGIN_X.get(); + posY = KillMessageConfig.KILL_MESSAGE_MARGIN_Y.get(); + } + case LEFT_BOTTOM -> { + posX = KillMessageConfig.KILL_MESSAGE_MARGIN_X.get(); + posY = screenHeight - KillMessageConfig.KILL_MESSAGE_MARGIN_Y.get() - count * 10; + left = true; + } + case RIGHT_BOTTOM -> { + posX = screenWidth - KillMessageConfig.KILL_MESSAGE_MARGIN_X.get(); + posY = screenHeight - KillMessageConfig.KILL_MESSAGE_MARGIN_Y.get() - count * 10; + } + } var arr = KillMessageHandler.QUEUE.toArray(new PlayerKillRecord[0]); var record = arr[0]; @@ -93,12 +121,11 @@ public class KillMessageOverlay implements LayeredDraw.Layer { } for (PlayerKillRecord r : KillMessageHandler.QUEUE) { - totalTop = renderKillMessages(r, guiGraphics, deltaTracker, totalTop); + posY = renderKillMessages(r, guiGraphics, deltaTracker.getGameTimeDeltaPartialTick(true), posX, posY, left); } } - private static float renderKillMessages(PlayerKillRecord record, GuiGraphics guiGraphics, DeltaTracker deltaTracker, float baseTop) { - int w = guiGraphics.guiWidth(); + private static float renderKillMessages(PlayerKillRecord record, GuiGraphics guiGraphics, float partialTick, int width, float baseTop, boolean left) { float top = baseTop; Font font = Minecraft.getInstance().font; @@ -124,34 +151,34 @@ public class KillMessageOverlay implements LayeredDraw.Layer { // 入场效果 if (record.tick < 3) { - guiGraphics.pose().translate((3 - record.tick - deltaTracker.getGameTimeDeltaPartialTick(true)) * 33, 0, 0); + guiGraphics.pose().translate((3 - record.tick - partialTick) * 33 * (left ? -1 : 1), 0, 0); } // 4s后开始消失 if (record.tick >= 80) { int animationTickCount = record.fastRemove ? 2 : 20; - float rate = (float) Math.pow((record.tick + deltaTracker.getGameTimeDeltaPartialTick(true) - 80) / animationTickCount, 5); - guiGraphics.pose().translate(rate * 100, 0, 0); + float rate = (float) Math.pow((record.tick + partialTick - 80) / animationTickCount, 5); + guiGraphics.pose().translate(rate * 100 * (left ? -1 : 1), 0, 0); guiGraphics.setColor(1, 1, 1, 1 - rate); baseTop += 10 * (1 - rate); } else { baseTop += 10; } - // 击杀提示是右对齐的,这里从右向左渲染 + // 击杀提示默认是右对齐的,这里从右向左渲染 // 渲染被击杀者名称 guiGraphics.drawString( Minecraft.getInstance().font, targetName.get(), - w - targetNameWidth - 10f, + width - targetNameWidth - 10f, top, record.target.getTeamColor(), false ); // 第一个图标:爆头/爆炸/近战等图标 - int damageTypeIconW = w - targetNameWidth - 28; + int damageTypeIconW = width - targetNameWidth - 28; ResourceLocation damageTypeIcon = getDamageTypeIcon(record); @@ -171,7 +198,7 @@ public class KillMessageOverlay implements LayeredDraw.Layer { Player player = record.attacker; boolean renderItem = false; - int itemIconW = damageTypeIcon != null ? w - targetNameWidth - 64 : w - targetNameWidth - 46; + int itemIconW = damageTypeIcon != null ? width - targetNameWidth - 64 : width - targetNameWidth - 46; if (player != null && player.getVehicle() instanceof VehicleEntity vehicleEntity) { // 载具图标 @@ -255,7 +282,7 @@ public class KillMessageOverlay implements LayeredDraw.Layer { .ifPresent(s -> attackerName.set(s.stack().getHoverName().getString())); int attackerNameWidth = font.width(attackerName.get()); - int nameW = w - targetNameWidth - 16 - attackerNameWidth; + int nameW = width - targetNameWidth - 16 - attackerNameWidth; if (renderItem) { nameW -= 32; } diff --git a/src/main/java/com/atsuishio/superbwarfare/compat/clothconfig/client/KillMessageClothConfig.java b/src/main/java/com/atsuishio/superbwarfare/compat/clothconfig/client/KillMessageClothConfig.java index 5503eddcf..352414577 100644 --- a/src/main/java/com/atsuishio/superbwarfare/compat/clothconfig/client/KillMessageClothConfig.java +++ b/src/main/java/com/atsuishio/superbwarfare/compat/clothconfig/client/KillMessageClothConfig.java @@ -21,12 +21,52 @@ public class KillMessageClothConfig { category.addEntry(entryBuilder .startIntField(Component.translatable("config.superbwarfare.client.kill_message.kill_message_count"), KillMessageConfig.KILL_MESSAGE_COUNT.get()) - .setDefaultValue(5) + .setDefaultValue(10) .setMin(1) .setMax(20) .setSaveConsumer(KillMessageConfig.KILL_MESSAGE_COUNT::set) .setTooltip(Component.translatable("config.superbwarfare.client.kill_message.kill_message_count.des")) .build() ); + + category.addEntry(entryBuilder + .startEnumSelector(Component.translatable("config.superbwarfare.client.kill_message.kill_message_position"), + KillMessageConfig.KillMessagePosition.class, + KillMessageConfig.KILL_MESSAGE_POSITION.get()) + .setDefaultValue(KillMessageConfig.KillMessagePosition.RIGHT_TOP) + .setEnumNameProvider(pos -> switch (pos) { + case KillMessageConfig.KillMessagePosition.LEFT_BOTTOM -> + Component.translatable("config.superbwarfare.client.kill_message.kill_message_position.left_bottom"); + case KillMessageConfig.KillMessagePosition.RIGHT_TOP -> + Component.translatable("config.superbwarfare.client.kill_message.kill_message_position.right_top"); + case KillMessageConfig.KillMessagePosition.RIGHT_BOTTOM -> + Component.translatable("config.superbwarfare.client.kill_message.kill_message_position.right_bottom"); + default -> + Component.translatable("config.superbwarfare.client.kill_message.kill_message_position.left_top"); + }) + .setSaveConsumer(KillMessageConfig.KILL_MESSAGE_POSITION::set) + .setTooltip(Component.translatable("config.superbwarfare.client.kill_message.kill_message_position.des")) + .build() + ); + + category.addEntry(entryBuilder + .startIntField(Component.translatable("config.superbwarfare.client.kill_message.kill_message_margin_x"), KillMessageConfig.KILL_MESSAGE_MARGIN_X.get()) + .setDefaultValue(0) + .setMin(-1000) + .setMax(1000) + .setSaveConsumer(KillMessageConfig.KILL_MESSAGE_MARGIN_X::set) + .setTooltip(Component.translatable("config.superbwarfare.client.kill_message.kill_message_margin_x.des")) + .build() + ); + + category.addEntry(entryBuilder + .startIntField(Component.translatable("config.superbwarfare.client.kill_message.kill_message_margin_y"), KillMessageConfig.KILL_MESSAGE_MARGIN_Y.get()) + .setDefaultValue(5) + .setMin(-1000) + .setMax(1000) + .setSaveConsumer(KillMessageConfig.KILL_MESSAGE_MARGIN_Y::set) + .setTooltip(Component.translatable("config.superbwarfare.client.kill_message.kill_message_margin_y.des")) + .build() + ); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/config/client/KillMessageConfig.java b/src/main/java/com/atsuishio/superbwarfare/config/client/KillMessageConfig.java index bd8cb2782..6fd4b40da 100644 --- a/src/main/java/com/atsuishio/superbwarfare/config/client/KillMessageConfig.java +++ b/src/main/java/com/atsuishio/superbwarfare/config/client/KillMessageConfig.java @@ -6,6 +6,9 @@ public class KillMessageConfig { public static ModConfigSpec.BooleanValue SHOW_KILL_MESSAGE; public static ModConfigSpec.IntValue KILL_MESSAGE_COUNT; + public static ModConfigSpec.IntValue KILL_MESSAGE_MARGIN_X; + public static ModConfigSpec.IntValue KILL_MESSAGE_MARGIN_Y; + public static ModConfigSpec.EnumValue KILL_MESSAGE_POSITION; public static void init(ModConfigSpec.Builder builder) { builder.push("kill_message"); @@ -16,7 +19,19 @@ public class KillMessageConfig { builder.comment("The max count of kill messages to show concurrently"); KILL_MESSAGE_COUNT = builder.defineInRange("kill_message_count", 5, 1, 20); + builder.comment("The position of kill message"); + KILL_MESSAGE_POSITION = builder.defineEnum("kill_message_position", KillMessagePosition.RIGHT_TOP); + + builder.comment("The x margin of kill message"); + KILL_MESSAGE_MARGIN_X = builder.defineInRange("kill_message_margin_x", 0, -1000, 1000); + + builder.comment("The y margin of kill message"); + KILL_MESSAGE_MARGIN_Y = builder.defineInRange("kill_message_margin_y", 5, -1000, 1000); + builder.pop(); } + public enum KillMessagePosition { + LEFT_TOP, LEFT_BOTTOM, RIGHT_TOP, RIGHT_BOTTOM, + } } diff --git a/src/main/resources/assets/superbwarfare/lang/en_us.json b/src/main/resources/assets/superbwarfare/lang/en_us.json index 60d61add9..c9889fe47 100644 --- a/src/main/resources/assets/superbwarfare/lang/en_us.json +++ b/src/main/resources/assets/superbwarfare/lang/en_us.json @@ -532,6 +532,16 @@ "config.superbwarfare.client.kill_message.show_kill_message.des": "Display killing message in the upper right corner when turned on", "config.superbwarfare.client.kill_message.kill_message_count": "Killing message number", "config.superbwarfare.client.kill_message.kill_message_count.des": "The kill indicator will appear around the collimator after a creature is killed when turned on", + "config.superbwarfare.client.kill_message.kill_message_position": "Kill Message Position", + "config.superbwarfare.client.kill_message.kill_message_position.left_bottom": "Left Bottom", + "config.superbwarfare.client.kill_message.kill_message_position.left_top": "Left Top", + "config.superbwarfare.client.kill_message.kill_message_position.right_bottom": "Right Bottom", + "config.superbwarfare.client.kill_message.kill_message_position.right_top": "Right Top", + "config.superbwarfare.client.kill_message.kill_message_position.des": "The base position of kill message", + "config.superbwarfare.client.kill_message.kill_message_margin_x": "Horizontal Offset", + "config.superbwarfare.client.kill_message.kill_message_margin_x.des": "The horizontal offset of kill message", + "config.superbwarfare.client.kill_message.kill_message_margin_y": "Vertical Offset", + "config.superbwarfare.client.kill_message.kill_message_margin_y.des": "The vertical offset of kill message", "config.superbwarfare.client.display": "Display Config", "config.superbwarfare.client.display.kill_indication": "Kill Indication", "config.superbwarfare.client.display.kill_indication.des": "The kill indicator will appear around the cross hair after a creature is killed when turned on", diff --git a/src/main/resources/assets/superbwarfare/lang/zh_cn.json b/src/main/resources/assets/superbwarfare/lang/zh_cn.json index 6f6c668c8..21df2fb45 100644 --- a/src/main/resources/assets/superbwarfare/lang/zh_cn.json +++ b/src/main/resources/assets/superbwarfare/lang/zh_cn.json @@ -533,6 +533,16 @@ "config.superbwarfare.client.kill_message.show_kill_message.des": "开启时,在屏幕右上角显示击杀信息", "config.superbwarfare.client.kill_message.kill_message_count": "击杀信息数量", "config.superbwarfare.client.kill_message.kill_message_count.des": "同时显示的最大击杀信息数量", + "config.superbwarfare.client.kill_message.kill_message_position": "击杀信息位置", + "config.superbwarfare.client.kill_message.kill_message_position.left_bottom": "左下", + "config.superbwarfare.client.kill_message.kill_message_position.left_top": "左上", + "config.superbwarfare.client.kill_message.kill_message_position.right_bottom": "右下", + "config.superbwarfare.client.kill_message.kill_message_position.right_top": "右上", + "config.superbwarfare.client.kill_message.kill_message_position.des": "击杀信息的位置", + "config.superbwarfare.client.kill_message.kill_message_margin_x": "水平偏移", + "config.superbwarfare.client.kill_message.kill_message_margin_x.des": "距离屏幕边缘的水平距离", + "config.superbwarfare.client.kill_message.kill_message_margin_y": "竖直偏移", + "config.superbwarfare.client.kill_message.kill_message_margin_y.des": "距离屏幕边缘的竖直距离", "config.superbwarfare.client.display": "显示配置", "config.superbwarfare.client.display.kill_indication": "击杀提示", "config.superbwarfare.client.display.kill_indication.des": "开启时,击杀生物时会在准星周围显示击杀提示",