Skip to content

Commit

Permalink
tooltip支持显示伤害x弹丸数量
Browse files Browse the repository at this point in the history
  • Loading branch information
xjqsh committed Oct 8, 2024
1 parent 2ef6aca commit 7f74a94
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class ClientGunIndex {
private float @Nullable [] tracerColor = null;
private EnumMap<FireMode, ControllableData> controllableData;
private AmmoCountStyle ammoCountStyle = AmmoCountStyle.NORMAL;
private DamageStyle damageStyle = DamageStyle.PER_PROJECTILE;

private ClientGunIndex() {
}
Expand All @@ -96,6 +97,7 @@ public static ClientGunIndex getInstance(GunIndexPOJO gunIndexPOJO) throws Illeg
index.showCrosshair = display.isShowCrosshair();
index.controllableData = display.getControllableData();
index.ammoCountStyle = display.getAmmoCountStyle();
index.damageStyle = display.getDamageStyle();
return index;
}

Expand Down Expand Up @@ -451,4 +453,8 @@ public EnumMap<FireMode, ControllableData> getControllableData() {
public AmmoCountStyle getAmmoCountStyle() {
return ammoCountStyle;
}

public DamageStyle getDamageStyle() {
return damageStyle;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.tacz.guns.client.resource.pojo.display.gun;

import com.google.gson.annotations.SerializedName;

public enum DamageStyle {
@SerializedName("total")
TOTAL,
@SerializedName("per_projectile")
PER_PROJECTILE
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class GunDisplay {
@NotNull
@SerializedName("ammo_count_style")
private AmmoCountStyle ammoCountStyle = AmmoCountStyle.NORMAL;
@NotNull
@SerializedName("damage_style")
private DamageStyle damageStyle = DamageStyle.PER_PROJECTILE;
@Nullable
@SerializedName("third_person_animation")
private String thirdPersonAnimation;
Expand Down Expand Up @@ -180,4 +183,8 @@ public EnumMap<FireMode, ControllableData> getControllableData() {
public @NotNull AmmoCountStyle getAmmoCountStyle() {
return ammoCountStyle;
}

public @NotNull DamageStyle getDamageStyle() {
return damageStyle;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.tacz.guns.client.resource.index.ClientGunIndex;
import com.tacz.guns.client.resource.pojo.PackInfo;
import com.tacz.guns.client.resource.pojo.display.gun.AmmoCountStyle;
import com.tacz.guns.client.resource.pojo.display.gun.DamageStyle;
import com.tacz.guns.config.sync.SyncConfig;
import com.tacz.guns.inventory.tooltip.GunTooltip;
import com.tacz.guns.item.GunTooltipPart;
Expand Down Expand Up @@ -165,7 +166,13 @@ private void getText() {
this.maxWidth = Math.max(font.width(this.gunType), this.maxWidth);

double damage = AttachmentDataUtils.getDamageWithAttachment(gun, gunData);
MutableComponent value = Component.literal(DAMAGE_FORMAT.format(damage)).withStyle(ChatFormatting.AQUA);
int bulletAmount = gunData.getBulletData().getBulletAmount();
MutableComponent value;
if (clientGunIndex != null && clientGunIndex.getDamageStyle() == DamageStyle.PER_PROJECTILE && bulletAmount > 1) {
value = Component.literal(DAMAGE_FORMAT.format(damage/bulletAmount) + "x" + bulletAmount).withStyle(ChatFormatting.AQUA);
} else {
value = Component.literal(DAMAGE_FORMAT.format(damage)).withStyle(ChatFormatting.AQUA);
}
if (bulletData.getExplosionData() != null && (AttachmentDataUtils.isExplodeEnabled(gun, gunData) || bulletData.getExplosionData().isExplode())) {
value.append(" + ").append(DAMAGE_FORMAT.format(bulletData.getExplosionData().getDamage() * SyncConfig.DAMAGE_BASE_MULTIPLIER.get())).append(Component.translatable("tooltip.tacz.gun.explosion"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"slot": "tacz:gun/slot/ak47",
// 弹药计量样式,可选值:”normal“(显示实际值)、”percent“(显示百分比),默认为”normal“
"ammo_count_style": "normal",
// tooltip的伤害显示样式,可选值:”total“(总伤害)、”per_projectile“(单发弹丸伤害x弹丸数量),默认为”per_projectile“
"damage_style": "per_projectile",
// 调用的动画名,会在包目录下的 animations 文件夹中寻找,不建议为空
"animation": "tacz:ak47",
// 状态机脚本
Expand Down

0 comments on commit 7f74a94

Please sign in to comment.