Skip to content

Commit

Permalink
修复了配置文件不生效的bug
Browse files Browse the repository at this point in the history
添加了项目透明度选项
  • Loading branch information
zxy19 committed Apr 15, 2024
1 parent dcec787 commit 064f1cd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 27 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod_name=Damage Number
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=MIT
# The mod version. See https://semver.org/
mod_version=1.1.0
mod_version=1.2.0
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
44 changes: 32 additions & 12 deletions src/main/java/cc/xypp/damage_number/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ public RankOptionItem(String title, long color, long amount){
private static final ForgeConfigSpec.ConfigValue<Integer> NUMBER_Y = BUILDER
.translation("config.damage_number.number.y")
.define("number.y", 100);
private static final ForgeConfigSpec.ConfigValue<Float> NUMBER_SCALE = BUILDER
private static final ForgeConfigSpec.DoubleValue NUMBER_SCALE = BUILDER
.translation("config.damage_number.number.scale")
.define("number.scale", 2.5f);
.defineInRange("number.scale", 2.5,0.0,10.0);
private static final ForgeConfigSpec.DoubleValue NUMBER_OPACITY = BUILDER
.translation("config.damage_number.number.opacity")
.defineInRange("number.opacity", 1.0,0.0,1.0);
private static final ForgeConfigSpec.BooleanValue NUMBER_SHOW = BUILDER
.translation("config.damage_number.number.show")
.define("number.show", true);
Expand All @@ -53,9 +56,12 @@ public RankOptionItem(String title, long color, long amount){
private static final ForgeConfigSpec.ConfigValue<Integer> TITLE_Y = BUILDER
.translation("config.damage_number.title.y")
.define("title.y", 75);
private static final ForgeConfigSpec.ConfigValue<Float> TITLE_SCALE = BUILDER
private static final ForgeConfigSpec.DoubleValue TITLE_SCALE = BUILDER
.translation("config.damage_number.title.scale")
.define("title.scale", 1.8f);
.defineInRange("title.scale", 1.8,0.0,10.0);
private static final ForgeConfigSpec.DoubleValue TITLE_OPACITY = BUILDER
.translation("config.damage_number.title.opacity")
.defineInRange("title.opacity", 1.0,0.0,1.0);
private static final ForgeConfigSpec.BooleanValue TITLE_SHOW = BUILDER
.translation("config.damage_number.title.show")
.define("title.show", true);
Expand All @@ -66,9 +72,12 @@ public RankOptionItem(String title, long color, long amount){
private static final ForgeConfigSpec.ConfigValue<Integer> COMBO_Y = BUILDER
.translation("config.damage_number.combo.y")
.define("combo.y", 125);
private static final ForgeConfigSpec.ConfigValue<Float> COMBO_SCALE = BUILDER
private static final ForgeConfigSpec.DoubleValue COMBO_OPACITY = BUILDER
.translation("config.damage_number.combo.opacity")
.defineInRange("combo.opacity", 1.0,0.0,1.0);
private static final ForgeConfigSpec.DoubleValue COMBO_SCALE = BUILDER
.translation("config.damage_number.combo.scale")
.define("combo.scale", 1.2f);
.defineInRange("combo.scale", 1.2,0.0,10.0);
private static final ForgeConfigSpec.BooleanValue COMBO_SHOW = BUILDER
.translation("config.damage_number.combo.show")
.define("combo.show", true);
Expand All @@ -79,9 +88,12 @@ public RankOptionItem(String title, long color, long amount){
private static final ForgeConfigSpec.ConfigValue<Integer> DAMAGE_LIST_Y = BUILDER
.translation("config.damage_number.damage_list.y")
.define("damage_list.y", 100);
private static final ForgeConfigSpec.ConfigValue<Float> DAMAGE_LIST_SCALE = BUILDER
private static final ForgeConfigSpec.DoubleValue DAMAGE_LIST_OPACITY = BUILDER
.translation("config.damage_number.damage_list.opacity")
.defineInRange("damage_list.opacity", 1.0,0.0,1.0);
private static final ForgeConfigSpec.DoubleValue DAMAGE_LIST_SCALE = BUILDER
.translation("config.damage_number.damage_list.scale")
.define("damage_list.scale", 0.8f);
.defineInRange("damage_list.scale", 0.8,0.0,10.0);
private static final ForgeConfigSpec.BooleanValue DAMAGE_LIST_SHOW = BUILDER
.translation("config.damage_number.damage_list.show")
.define("damage_list.show", true);
Expand Down Expand Up @@ -140,24 +152,28 @@ public RankOptionItem(String title, long color, long amount){
public static int numberX;
public static int numberY;
public static float numberScale;
public static float numberOpacity;
public static boolean numberShow;

//Title Options
public static int titleX;
public static int titleY;
public static float titleScale;
public static float titleOpacity;
public static boolean titleShow;

//Combo Options
public static int comboX;
public static int comboY;
public static float comboScale;
public static float comboOpacity;
public static boolean comboShow;

//Damage List Options
public static int damageListX;
public static int damageListY;
public static float damageListScale;
public static float damageListOpacity;
public static boolean damageListShow;

//Damage Rank Options
Expand Down Expand Up @@ -194,19 +210,23 @@ static void onLoad(final ModConfigEvent event)
showDamage = SHOW_DAMAGE.get();
numberX = NUMBER_X.get();
numberY = NUMBER_Y.get();
numberScale = NUMBER_SCALE.get();
numberScale = (float) (double)NUMBER_SCALE.get();
numberOpacity = (float) (double)NUMBER_OPACITY.get();
numberShow = NUMBER_SHOW.get();
titleX = TITLE_X.get();
titleY = TITLE_Y.get();
titleScale = TITLE_SCALE.get();
titleScale = (float) (double)TITLE_SCALE.get();
titleOpacity = (float) (double)TITLE_OPACITY.get();
titleShow = TITLE_SHOW.get();
comboX = COMBO_X.get();
comboY = COMBO_Y.get();
comboScale = COMBO_SCALE.get();
comboScale = (float) (double)COMBO_SCALE.get();
comboOpacity = (float) (double)COMBO_OPACITY.get();
comboShow = COMBO_SHOW.get();
damageListX = DAMAGE_LIST_X.get();
damageListY = DAMAGE_LIST_Y.get();
damageListScale = DAMAGE_LIST_SCALE.get();
damageListScale = (float) (double)DAMAGE_LIST_SCALE.get();
damageListOpacity = (float) (double)DAMAGE_LIST_OPACITY.get();
damageListShow = DAMAGE_LIST_SHOW.get();
damageRankEnabled = DAMAGE_RANK_USE.get();
damageRankList = DAMAGE_RANK_OPT.get().stream().map(item->{
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/cc/xypp/damage_number/client/DamageRender.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ public void render(ForgeGui gui, PoseStack poseStack, float partialTick, int scr
RankColor = item.color;
}
}
if(Config.damageRankColorDamageNumber){
if (Config.damageRankColorDamageNumber) {
damageColor = RankColor;
}
if(Config.damageRankColorTitle){
if (Config.damageRankColorTitle) {
titleColor = RankColor;
}
if(Config.damageRankColorCombo){
if (Config.damageRankColorCombo) {
comboColor = RankColor;
}
}
Expand All @@ -65,20 +65,20 @@ public void render(ForgeGui gui, PoseStack poseStack, float partialTick, int scr
RankColor = item.color;
}
}
if(Config.comboRankColorDamageNumber){
if (Config.comboRankColorDamageNumber) {
damageColor = RankColor;
}
if(Config.comboRankColorTitle){
if (Config.comboRankColorTitle) {
titleColor = RankColor;
}
if(Config.comboRankColorCombo){
if (Config.comboRankColorCombo) {
comboColor = RankColor;
}
}
}//RANK OPT


{//TITLE Render
if (Config.titleShow) {//TITLE Render
float scale = (float) Config.titleScale;
poseStack.pushPose();
poseStack.scale(scale, scale, scale);
Expand All @@ -88,21 +88,21 @@ public void render(ForgeGui gui, PoseStack poseStack, float partialTick, int scr
y = (int) (y / scale);


GuiComponent.drawString(poseStack, gui.getFont(), titleContent, x, y, (int) titleColor);
GuiComponent.drawString(poseStack, gui.getFont(), titleContent, x, y, ((int) titleColor) | ((int) (Config.titleOpacity * 255) << 24));
poseStack.popPose();
}//TITLE Render
{//COMBO Render
if (Config.comboShow) {//COMBO Render
float scale = (float) Config.comboScale;
poseStack.pushPose();
poseStack.scale(scale, scale, scale);
int x = valTransform(Config.comboX, screenWidth);
int y = valTransform(Config.comboY, screenHeight);
x = (int) (x / scale);
y = (int) (y / scale);
GuiComponent.drawString(poseStack, gui.getFont(), i18n("combo.content", String.valueOf(Data.combo)), x, y, (int)comboColor);
GuiComponent.drawString(poseStack, gui.getFont(), i18n("combo.content", String.valueOf(Data.combo)), x, y, ((int) comboColor) | ((int) (Config.comboOpacity * 255) << 24));
poseStack.popPose();
}//COMBO Render
{//List Render
if (Config.damageListShow) {//List Render
float scale = (float) Config.damageListScale;
poseStack.pushPose();
poseStack.scale(scale, scale, scale);
Expand All @@ -117,13 +117,13 @@ public void render(ForgeGui gui, PoseStack poseStack, float partialTick, int scr
Data.latest.remove(0);
}
for (Pair<Float, Long> pair : Data.latest) {
GuiComponent.drawString(poseStack, gui.getFont(), i18n("damage_list.content", String.format("%.1f", pair.getLeft())), x, y, 0xFFFFFF);
GuiComponent.drawString(poseStack, gui.getFont(), i18n("damage_list.content", String.format("%.1f", pair.getLeft())), x, y, (0xFFFFFF) | ((int) (Config.damageListOpacity * 255) << 24));
y += lh;
}

poseStack.popPose();
}//List Render
{//Number Render
if (Config.numberShow) {//Number Render
float scale = (float) Config.numberScale;
poseStack.pushPose();
poseStack.scale(scale, scale, scale);
Expand Down Expand Up @@ -161,7 +161,7 @@ public void render(ForgeGui gui, PoseStack poseStack, float partialTick, int scr
i18n("number.content", String.format("%.1f", Data.amount)),
x,
y,
Data.confirm ? 0xf9a825 : (int)damageColor);
(Data.confirm ? 0xf9a825 : (int) damageColor) | ((int) (Config.numberOpacity * 255) << 24));
poseStack.popPose();
}//Number Render
}
Expand Down

0 comments on commit 064f1cd

Please sign in to comment.