diff --git a/src/main/java/com/teammoeg/frostedheart/content/tips/ClientEvents.java b/src/main/java/com/teammoeg/frostedheart/content/tips/ClientEvents.java new file mode 100644 index 000000000..97d9b89b1 --- /dev/null +++ b/src/main/java/com/teammoeg/frostedheart/content/tips/ClientEvents.java @@ -0,0 +1,34 @@ +package com.teammoeg.frostedheart.content.tips; + +import com.teammoeg.chorda.util.lang.Components; +import com.teammoeg.frostedheart.FHMain; +import com.teammoeg.frostedheart.content.waypoint.ClientWaypointManager; +import net.minecraft.resources.ResourceLocation; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.client.event.ClientPlayerNetworkEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; + +@Mod.EventBusSubscriber(modid = FHMain.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) +public class ClientEvents { + + @SubscribeEvent + public static void onPlayerLoggedIn(ClientPlayerNetworkEvent.LoggingIn event) { + // default tip + if (!TipManager.INSTANCE.hasTip("default")) { + Tip.builder("default").line(Components.str("Default Tip")).image(new ResourceLocation(FHMain.MODID, "textures/item/debug_item.png")).build().saveAsFile(); + TipManager.INSTANCE.loadFromFile(); + } + TipManager.INSTANCE.display().clearRenderQueue(); + TipManager.INSTANCE.display().general("default"); +// if (Minecraft.getInstance().gameSettings.getSoundLevel(SoundCategory.MUSIC) == 0) { +// TipDisplayManager.displayTip("music_warning", false); +// } + } + + @SubscribeEvent + public static void onPlayerLoggedOut(ClientPlayerNetworkEvent.LoggingOut event) { + TipManager.INSTANCE.display().clearRenderQueue(); + ClientWaypointManager.clear(); + } +} diff --git a/src/main/java/com/teammoeg/frostedheart/content/tips/Tip.java b/src/main/java/com/teammoeg/frostedheart/content/tips/Tip.java index e8727267b..b6461adab 100644 --- a/src/main/java/com/teammoeg/frostedheart/content/tips/Tip.java +++ b/src/main/java/com/teammoeg/frostedheart/content/tips/Tip.java @@ -131,8 +131,14 @@ public boolean hasNext() { } public boolean saveAsFile() { - if (isTipIdInvalid(this.id)) { - builder("exception").error(ErrorType.LOAD, Component.literal("ID: " + this.id), Component.translatable("tips.frostedheart.error.invalid_id")).build().forceDisplay(); + if (this.id.isBlank()) { + builder("exception").error(ErrorType.SAVE, Component.translatable("tips.frostedheart.error.load.no_id")).build().forceDisplay(); + return false; + } else if (isTipIdInvalid(this.id)) { + builder("exception").error(ErrorType.SAVE, Component.literal("ID: " + this.id), Component.translatable("tips.frostedheart.error.invalid_id")).build().forceDisplay(); + return false; + } else if (TipManager.INSTANCE.hasTip(this.id)) { + builder("exception").error(ErrorType.SAVE, Component.literal("ID: " + this.id), Component.translatable("tips.frostedheart.error.load.duplicate_id")).build().forceDisplay(); return false; } @@ -244,7 +250,6 @@ public static class Builder { public Builder(String id) { if (isTipIdInvalid(id)) { error(ErrorType.LOAD, Component.literal("ID: " + id), Component.translatable("tips.frostedheart.error.invalid_id")); - return; } this.id = id; setTemporary(); @@ -392,7 +397,7 @@ public Builder fromNBT(CompoundTag nbt) { this.contents.addAll(list); } if (id.isBlank()) { - error(ErrorType.OTHER, Component.literal("NBT does not contain tip")); + error(ErrorType.OTHER, Component.literal("NBT does not contain a tip")); } return this; } @@ -404,13 +409,8 @@ public Builder fromJson(JsonObject json) { String s = json.get("id").getAsString(); if (s.isBlank()) { error(ErrorType.LOAD,Component.translatable("tips.frostedheart.error.load.no_id")); - return this; - } else if (TipManager.INSTANCE.hasTip(s)) { - error(ErrorType.LOAD, Component.literal("ID: " + s), Component.translatable("tips.frostedheart.error.load.duplicate_id")); - return this; } else if (isTipIdInvalid(s)) { error(ErrorType.LOAD, Component.literal("ID: " + s), Component.translatable("tips.frostedheart.error.invalid_id")); - return this; } id = s; } else { diff --git a/src/main/java/com/teammoeg/frostedheart/content/tips/TipManager.java b/src/main/java/com/teammoeg/frostedheart/content/tips/TipManager.java index 38fd515c7..4d5d23efc 100644 --- a/src/main/java/com/teammoeg/frostedheart/content/tips/TipManager.java +++ b/src/main/java/com/teammoeg/frostedheart/content/tips/TipManager.java @@ -91,7 +91,6 @@ public boolean hasTip(String id) { */ public void loadFromFile() { TIP_PATH.mkdirs(); - display.clearRenderQueue(); loadedTips.clear(); // 加载所有 tip 文件 diff --git a/src/main/java/com/teammoeg/frostedheart/content/tips/client/gui/widget/TipEditsList.java b/src/main/java/com/teammoeg/frostedheart/content/tips/client/gui/widget/TipEditsList.java index c518cbbb5..32083d9e8 100644 --- a/src/main/java/com/teammoeg/frostedheart/content/tips/client/gui/widget/TipEditsList.java +++ b/src/main/java/com/teammoeg/frostedheart/content/tips/client/gui/widget/TipEditsList.java @@ -42,7 +42,11 @@ public TipEditsList(Minecraft pMinecraft, int pWidth, int pHeight, int pY0, int var idEntry = (StringEntry)children().get(addEntry(new StringEntry("id", Component.translatable("gui.frostedheart.tip_editor.id")))); idEntry.input.setMaxLength(240); idEntry.input.setResponder(s -> { - if (TipManager.INSTANCE.hasTip(s) || Tip.isTipIdInvalid(s)) { + if (TipManager.INSTANCE.hasTip(s)) { + idEntry.input.setTextColor(ColorHelper.RED); + updatePreview(Component.translatable("tips.frostedheart.error.load.duplicate_id").withStyle(ChatFormatting.RED)); + return; + } else if (Tip.isTipIdInvalid(s)) { idEntry.input.setTextColor(ColorHelper.RED); } else { idEntry.input.setTextColor(ColorHelper.WHITE); @@ -59,7 +63,7 @@ public TipEditsList(Minecraft pMinecraft, int pWidth, int pHeight, int pY0, int updatePreview( Component.translatable("tips.frostedheart.error.invalid_id").withStyle(ChatFormatting.RED), Component.translatable("tips.frostedheart.error.load.tip_not_exists", s).withStyle(ChatFormatting.GOLD)); - } else if (!TipManager.INSTANCE.hasTip(s)) { + } else if (!s.isBlank() && !TipManager.INSTANCE.hasTip(s)) { nextTipEntry.input.setTextColor(0xFFFF9F00); updatePreview(Component.translatable("tips.frostedheart.error.load.tip_not_exists", s).withStyle(ChatFormatting.GOLD, ChatFormatting.BOLD)); } else { @@ -132,7 +136,7 @@ public IntegerEntry(String property, Component message) { this.input.setResponder(s -> { try { input.setTextColor(ColorHelper.WHITE); - Integer.parseUnsignedInt(s, 16); + Integer.parseInt(s); } catch (NumberFormatException e) { input.setTextColor(ColorHelper.RED); } @@ -146,7 +150,7 @@ public JsonElement getValue() { try { value = Integer.parseInt(input.getValue()); } catch (NumberFormatException e) { - value = ColorHelper.CYAN; + value = 0; } return new JsonPrimitive(value); } diff --git a/src/main/java/com/teammoeg/frostedheart/events/FHClientEvents.java b/src/main/java/com/teammoeg/frostedheart/events/FHClientEvents.java index 51d47c583..d1f8c3cd3 100644 --- a/src/main/java/com/teammoeg/frostedheart/events/FHClientEvents.java +++ b/src/main/java/com/teammoeg/frostedheart/events/FHClientEvents.java @@ -36,8 +36,6 @@ import com.teammoeg.frostedheart.content.research.research.effects.EffectShowCategory; import com.teammoeg.frostedheart.content.scenario.client.ClientScene; import com.teammoeg.frostedheart.content.scenario.client.dialog.HUDDialog; -import com.teammoeg.frostedheart.content.tips.Tip; -import com.teammoeg.frostedheart.content.tips.TipManager; import com.teammoeg.frostedheart.content.waypoint.ClientWaypointManager; import com.teammoeg.frostedheart.infrastructure.config.FHConfig; import com.teammoeg.frostedheart.util.FHVersion; @@ -56,7 +54,6 @@ import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.Style; -import net.minecraft.resources.ResourceLocation; import net.minecraft.util.FormattedCharSequence; import net.minecraft.util.Mth; import net.minecraft.world.entity.player.Player; @@ -464,26 +461,6 @@ public static void onWorldRender(RenderLevelStageEvent event) { } } - @SubscribeEvent - public static void onPlayerLoggedIn(ClientPlayerNetworkEvent.LoggingIn event) { - // default tip - if (!TipManager.INSTANCE.hasTip("default")) { - Tip.builder("default").line(Components.str("Default Tip")).image(new ResourceLocation(FHMain.MODID, "textures/item/debug_item.png")).build().saveAsFile(); - TipManager.INSTANCE.loadFromFile(); - } - TipManager.INSTANCE.display().clearRenderQueue(); - TipManager.INSTANCE.display().general("default"); -// if (Minecraft.getInstance().gameSettings.getSoundLevel(SoundCategory.MUSIC) == 0) { -// TipDisplayManager.displayTip("music_warning", false); -// } - } - - @SubscribeEvent - public static void onPlayerLoggedOut(ClientPlayerNetworkEvent.LoggingOut event) { - TipManager.INSTANCE.display().clearRenderQueue(); - ClientWaypointManager.clear(); - } - // @SubscribeEvent // public static void onGUIOpen(ScreenEvent.Opening event) { // if (event.getScreen() instanceof TitleScreen) {