添加一部分新的配置项

This commit is contained in:
17146 2025-05-05 15:04:36 +08:00 committed by Light_Quanta
parent 94858f214a
commit 8d97fdd7ba
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
5 changed files with 115 additions and 13 deletions

View file

@ -71,7 +71,35 @@ public class KillMessageOverlay implements LayeredDraw.Layer {
return; 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 arr = KillMessageHandler.QUEUE.toArray(new PlayerKillRecord[0]);
var record = arr[0]; var record = arr[0];
@ -93,12 +121,11 @@ public class KillMessageOverlay implements LayeredDraw.Layer {
} }
for (PlayerKillRecord r : KillMessageHandler.QUEUE) { 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) { private static float renderKillMessages(PlayerKillRecord record, GuiGraphics guiGraphics, float partialTick, int width, float baseTop, boolean left) {
int w = guiGraphics.guiWidth();
float top = baseTop; float top = baseTop;
Font font = Minecraft.getInstance().font; Font font = Minecraft.getInstance().font;
@ -124,34 +151,34 @@ public class KillMessageOverlay implements LayeredDraw.Layer {
// 入场效果 // 入场效果
if (record.tick < 3) { 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后开始消失 // 4s后开始消失
if (record.tick >= 80) { if (record.tick >= 80) {
int animationTickCount = record.fastRemove ? 2 : 20; int animationTickCount = record.fastRemove ? 2 : 20;
float rate = (float) Math.pow((record.tick + deltaTracker.getGameTimeDeltaPartialTick(true) - 80) / animationTickCount, 5); float rate = (float) Math.pow((record.tick + partialTick - 80) / animationTickCount, 5);
guiGraphics.pose().translate(rate * 100, 0, 0); guiGraphics.pose().translate(rate * 100 * (left ? -1 : 1), 0, 0);
guiGraphics.setColor(1, 1, 1, 1 - rate); guiGraphics.setColor(1, 1, 1, 1 - rate);
baseTop += 10 * (1 - rate); baseTop += 10 * (1 - rate);
} else { } else {
baseTop += 10; baseTop += 10;
} }
// 击杀提示是右对齐的这里从右向左渲染 // 击杀提示默认是右对齐的这里从右向左渲染
// 渲染被击杀者名称 // 渲染被击杀者名称
guiGraphics.drawString( guiGraphics.drawString(
Minecraft.getInstance().font, Minecraft.getInstance().font,
targetName.get(), targetName.get(),
w - targetNameWidth - 10f, width - targetNameWidth - 10f,
top, top,
record.target.getTeamColor(), record.target.getTeamColor(),
false false
); );
// 第一个图标爆头/爆炸/近战等图标 // 第一个图标爆头/爆炸/近战等图标
int damageTypeIconW = w - targetNameWidth - 28; int damageTypeIconW = width - targetNameWidth - 28;
ResourceLocation damageTypeIcon = getDamageTypeIcon(record); ResourceLocation damageTypeIcon = getDamageTypeIcon(record);
@ -171,7 +198,7 @@ public class KillMessageOverlay implements LayeredDraw.Layer {
Player player = record.attacker; Player player = record.attacker;
boolean renderItem = false; 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) { 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())); .ifPresent(s -> attackerName.set(s.stack().getHoverName().getString()));
int attackerNameWidth = font.width(attackerName.get()); int attackerNameWidth = font.width(attackerName.get());
int nameW = w - targetNameWidth - 16 - attackerNameWidth; int nameW = width - targetNameWidth - 16 - attackerNameWidth;
if (renderItem) { if (renderItem) {
nameW -= 32; nameW -= 32;
} }

View file

@ -21,12 +21,52 @@ public class KillMessageClothConfig {
category.addEntry(entryBuilder category.addEntry(entryBuilder
.startIntField(Component.translatable("config.superbwarfare.client.kill_message.kill_message_count"), KillMessageConfig.KILL_MESSAGE_COUNT.get()) .startIntField(Component.translatable("config.superbwarfare.client.kill_message.kill_message_count"), KillMessageConfig.KILL_MESSAGE_COUNT.get())
.setDefaultValue(5) .setDefaultValue(10)
.setMin(1) .setMin(1)
.setMax(20) .setMax(20)
.setSaveConsumer(KillMessageConfig.KILL_MESSAGE_COUNT::set) .setSaveConsumer(KillMessageConfig.KILL_MESSAGE_COUNT::set)
.setTooltip(Component.translatable("config.superbwarfare.client.kill_message.kill_message_count.des")) .setTooltip(Component.translatable("config.superbwarfare.client.kill_message.kill_message_count.des"))
.build() .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()
);
} }
} }

View file

@ -6,6 +6,9 @@ public class KillMessageConfig {
public static ModConfigSpec.BooleanValue SHOW_KILL_MESSAGE; public static ModConfigSpec.BooleanValue SHOW_KILL_MESSAGE;
public static ModConfigSpec.IntValue KILL_MESSAGE_COUNT; 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<KillMessagePosition> KILL_MESSAGE_POSITION;
public static void init(ModConfigSpec.Builder builder) { public static void init(ModConfigSpec.Builder builder) {
builder.push("kill_message"); builder.push("kill_message");
@ -16,7 +19,19 @@ public class KillMessageConfig {
builder.comment("The max count of kill messages to show concurrently"); builder.comment("The max count of kill messages to show concurrently");
KILL_MESSAGE_COUNT = builder.defineInRange("kill_message_count", 5, 1, 20); 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(); builder.pop();
} }
public enum KillMessagePosition {
LEFT_TOP, LEFT_BOTTOM, RIGHT_TOP, RIGHT_BOTTOM,
}
} }

View file

@ -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.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": "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_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": "Display Config",
"config.superbwarfare.client.display.kill_indication": "Kill Indication", "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", "config.superbwarfare.client.display.kill_indication.des": "The kill indicator will appear around the cross hair after a creature is killed when turned on",

View file

@ -533,6 +533,16 @@
"config.superbwarfare.client.kill_message.show_kill_message.des": "开启时,在屏幕右上角显示击杀信息", "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": "击杀信息数量",
"config.superbwarfare.client.kill_message.kill_message_count.des": "同时显示的最大击杀信息数量", "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": "显示配置",
"config.superbwarfare.client.display.kill_indication": "击杀提示", "config.superbwarfare.client.display.kill_indication": "击杀提示",
"config.superbwarfare.client.display.kill_indication.des": "开启时,击杀生物时会在准星周围显示击杀提示", "config.superbwarfare.client.display.kill_indication.des": "开启时,击杀生物时会在准星周围显示击杀提示",