From 7e7398f02e224dda47c0fe4c0ca5ca2b39499c87 Mon Sep 17 00:00:00 2001 From: goumo <76694659+goumo@users.noreply.github.com> Date: Wed, 15 Jan 2025 01:46:18 +0800 Subject: [PATCH] =?UTF-8?q?Tip=E7=BC=96=E8=BE=91=E5=99=A8:=201.=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=E5=B0=86=E5=86=85=E5=AE=B9=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E4=B8=BA=E7=BF=BB=E8=AF=91=E9=94=AE=E5=80=BC=E5=B9=B6=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E5=88=B0=E5=89=AA=E8=B4=B4=E6=9D=BF=E7=9A=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD;=202.=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=B0=86=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E7=BC=96=E8=BE=91=E7=9A=84=E6=8F=90=E7=A4=BA=E5=8F=91?= =?UTF-8?q?=E9=80=81=E7=BB=99=E6=89=80=E6=9C=89=E7=8E=A9=E5=AE=B6=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/teammoeg/frostedheart/FHNetwork.java | 2 + .../gui/widget/ActionStateIconButton.java | 41 ++++++++++++++ .../base/client/gui/widget/ColorEditbox.java | 2 +- .../base/client/gui/widget/IconButton.java | 11 ++-- .../{TipAPI.java => ServerTipSender.java} | 16 ++++-- .../frostedheart/content/tips/Tip.java | 18 +++---- .../tips/client/gui/TipEditorScreen.java | 32 +++++++---- .../tips/client/gui/widget/TipEditsList.java | 53 +++++++++++++++---- .../DisplayCustomTipRequestPacket.java | 37 +++++++++++++ .../infrastructure/command/TipCommand.java | 4 +- .../util/client/FHColorHelper.java | 2 +- .../assets/frostedheart/lang/en_us/en_us.json | 11 +++- .../assets/frostedheart/lang/zh_cn/zh_cn.json | 12 ++++- 13 files changed, 199 insertions(+), 42 deletions(-) create mode 100644 src/main/java/com/teammoeg/frostedheart/base/client/gui/widget/ActionStateIconButton.java rename src/main/java/com/teammoeg/frostedheart/content/tips/{TipAPI.java => ServerTipSender.java} (68%) create mode 100644 src/main/java/com/teammoeg/frostedheart/content/tips/network/DisplayCustomTipRequestPacket.java diff --git a/src/main/java/com/teammoeg/frostedheart/FHNetwork.java b/src/main/java/com/teammoeg/frostedheart/FHNetwork.java index a3e102043..5d901b044 100644 --- a/src/main/java/com/teammoeg/frostedheart/FHNetwork.java +++ b/src/main/java/com/teammoeg/frostedheart/FHNetwork.java @@ -62,6 +62,7 @@ import com.teammoeg.frostedheart.content.steamenergy.HeatNetworkRequestC2SPacket; import com.teammoeg.frostedheart.content.steamenergy.HeatNetworkResponseS2CPacket; import com.teammoeg.frostedheart.content.tips.network.DisplayCustomTipPacket; +import com.teammoeg.frostedheart.content.tips.network.DisplayCustomTipRequestPacket; import com.teammoeg.frostedheart.content.tips.network.DisplayTipPacket; import com.teammoeg.frostedheart.content.town.TeamTownDataS2CPacket; import com.teammoeg.frostedheart.content.trade.network.BargainRequestPacket; @@ -197,6 +198,7 @@ public static void register() { // Tip Messages registerMessage("single_tip", DisplayTipPacket.class); registerMessage("custom_tip", DisplayCustomTipPacket.class); + registerMessage("display_request", DisplayCustomTipRequestPacket.class); // Waypoint Messages registerMessage("waypoint_remove", WaypointRemovePacket.class); diff --git a/src/main/java/com/teammoeg/frostedheart/base/client/gui/widget/ActionStateIconButton.java b/src/main/java/com/teammoeg/frostedheart/base/client/gui/widget/ActionStateIconButton.java new file mode 100644 index 000000000..bd55ae699 --- /dev/null +++ b/src/main/java/com/teammoeg/frostedheart/base/client/gui/widget/ActionStateIconButton.java @@ -0,0 +1,41 @@ +package com.teammoeg.frostedheart.base.client.gui.widget; + +import lombok.Getter; +import lombok.Setter; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.network.chat.Component; +import org.jetbrains.annotations.NotNull; + +/** + * 按下后显示另一条信息的 IconButton + */ +public class ActionStateIconButton extends IconButton { + private final Component originalMessage; + @Getter + @Setter + private Component clickedMessage; + + public ActionStateIconButton(int x, int y, Icon icon, int color, Component message, Component clickedMessage, OnPress pressedAction) { + this(x, y, icon, color, 1, message, clickedMessage, pressedAction); + } + + public ActionStateIconButton(int x, int y, Icon icon, int color, int scale, Component message, Component clickedMessage, OnPress pressedAction) { + super(x, y, icon, color, scale, message, pressedAction); + this.originalMessage = message; + this.clickedMessage = clickedMessage; + } + + @Override + public void renderWidget(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) { + super.renderWidget(graphics, mouseX, mouseY, partialTicks); + if (!isHovered()) { + setMessage(originalMessage); + } + } + + @Override + public void onClick(double pMouseX, double pMouseY) { + super.onClick(pMouseX, pMouseY); + setMessage(clickedMessage); + } +} diff --git a/src/main/java/com/teammoeg/frostedheart/base/client/gui/widget/ColorEditbox.java b/src/main/java/com/teammoeg/frostedheart/base/client/gui/widget/ColorEditbox.java index 154735248..96ec32489 100644 --- a/src/main/java/com/teammoeg/frostedheart/base/client/gui/widget/ColorEditbox.java +++ b/src/main/java/com/teammoeg/frostedheart/base/client/gui/widget/ColorEditbox.java @@ -42,7 +42,7 @@ public void renderWidget(@NotNull GuiGraphics graphics, int mouseX, int mouseY, PoseStack pose = graphics.pose(); pose.pushPose(); pose.translate(1, 1, 0); - graphics.fill(getX()+getWidth()+2, getY(), getX()+getWidth()+getHeight()+2, getY()+getHeight(), FHColorHelper.makeDark(getColorValue(), 0.25F)); + graphics.fill(getX()+getWidth()+2, getY(), getX()+getWidth()+getHeight()+2, getY()+getHeight(), FHColorHelper.makeDark(getColorValue(), 0.75F)); pose.translate(-1, -1, 0); graphics.fill(getX()+getWidth()+2, getY(), getX()+getWidth()+getHeight()+2, getY()+getHeight(), getColorValue()); pose.popPose(); diff --git a/src/main/java/com/teammoeg/frostedheart/base/client/gui/widget/IconButton.java b/src/main/java/com/teammoeg/frostedheart/base/client/gui/widget/IconButton.java index 57a9dabd8..ca9512f16 100644 --- a/src/main/java/com/teammoeg/frostedheart/base/client/gui/widget/IconButton.java +++ b/src/main/java/com/teammoeg/frostedheart/base/client/gui/widget/IconButton.java @@ -40,8 +40,11 @@ public IconButton(int x, int y, Icon icon, int color, int scale, Component title @Override public void renderWidget(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) { + int color = isActive() ? this.color : 0xFF666666; + int backgroundColor = FHColorHelper.makeDark(color, 0.3F); + float alpha = 0.5F; if (isHoveredOrFocused()) { - graphics.fill(getX(), getY(), getX()+getWidth(), getY()+getHeight(), FHColorHelper.setAlpha(color, 50)); + graphics.fill(getX(), getY(), getX()+getWidth(), getY()+getHeight(), FHColorHelper.setAlpha(backgroundColor, alpha)); if (!getMessage().getString().isBlank() && isHovered()) { int textWidth = ClientUtils.font().width(getMessage()); int renderX = getX()-textWidth+8; @@ -50,21 +53,21 @@ public void renderWidget(@NotNull GuiGraphics graphics, int mouseX, int mouseY, getY()-12, getX()+2 + textWidth, getY(), - FHColorHelper.setAlpha(color, 50)); + FHColorHelper.setAlpha(backgroundColor, alpha)); graphics.drawString(ClientUtils.font(), getMessage(), getX()+2, getY()-10, color); } else { graphics.fill(getX()-textWidth+getWidth()-1, getY()-12, getX()+getWidth(), getY(), - FHColorHelper.setAlpha(color, 50)); + FHColorHelper.setAlpha(backgroundColor, alpha)); graphics.drawString(ClientUtils.font(), getMessage(), getX()-textWidth+getWidth(), getY()-10, color); } } } FHGuiHelper.bindTexture(ICON_LOCATION); - FHGuiHelper.blitColored(graphics.pose(), getX(), getY(), getWidth(), getHeight(), icon.x*scale, icon.y*scale, getWidth(), getHeight(), TEXTURE_WIDTH*scale, TEXTURE_HEIGHT*scale, color, alpha); + FHGuiHelper.blitColored(graphics.pose(), getX(), getY(), getWidth(), getHeight(), icon.x*scale, icon.y*scale, getWidth(), getHeight(), TEXTURE_WIDTH*scale, TEXTURE_HEIGHT*scale, color, this.alpha); } public void setScale(int scale) { diff --git a/src/main/java/com/teammoeg/frostedheart/content/tips/TipAPI.java b/src/main/java/com/teammoeg/frostedheart/content/tips/ServerTipSender.java similarity index 68% rename from src/main/java/com/teammoeg/frostedheart/content/tips/TipAPI.java rename to src/main/java/com/teammoeg/frostedheart/content/tips/ServerTipSender.java index e40f0afb6..f320f950f 100644 --- a/src/main/java/com/teammoeg/frostedheart/content/tips/TipAPI.java +++ b/src/main/java/com/teammoeg/frostedheart/content/tips/ServerTipSender.java @@ -6,7 +6,7 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraftforge.network.PacketDistributor; -public class TipAPI { +public class ServerTipSender { /** * 使客户端显示对应 id 的 tip @@ -18,13 +18,23 @@ public static void sendGeneral(String id, ServerPlayer player) { } /** - * 向客户端发送自定义 tip + * 向所有玩家发送自定义 tip + *

+ * 注意:自定义 tip 不会储存任何状态 + * @param tip tip + */ + public static void sendCustomToAll(Tip tip) { + FHNetwork.sendToServer(new DisplayCustomTipPacket(tip)); + } + + /** + * 向玩家发送自定义 tip *

* 注意:自定义 tip 不会储存任何状态 * @param tip tip * @param player 目标玩家 */ public static void sendCustom(Tip tip, ServerPlayer player) { - FHNetwork.send(PacketDistributor.PLAYER.with(() -> player), new DisplayCustomTipPacket(tip)); + FHNetwork.sendPlayer(player, new DisplayCustomTipPacket(tip)); } } 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 b9d6b99cd..24c34b2fa 100644 --- a/src/main/java/com/teammoeg/frostedheart/content/tips/Tip.java +++ b/src/main/java/com/teammoeg/frostedheart/content/tips/Tip.java @@ -114,6 +114,14 @@ protected Tip(Tip.Builder builder) { this.backgroundColor = builder.BGColor; } + public void display() { + TipManager.INSTANCE.display().general(this); + } + + public void forceDisplay() { + TipManager.INSTANCE.display().force(this); + } + public boolean hasNext() { return TipManager.INSTANCE.hasTip(nextTip); } @@ -126,7 +134,7 @@ public boolean saveAsFile() { return true; } catch (IOException e) { LOGGER.error("Unable to save file: '{}'", file, e); - Tip.builder("exception").error(ErrorType.SAVE, e, Lang.str(file.getName())).forceDisplay(); + Tip.builder("exception").error(ErrorType.SAVE, e, Lang.str(file.getName())).build().forceDisplay(); return false; } } @@ -225,14 +233,6 @@ public Builder(String id) { setTemporary(); } - public void display() { - TipManager.INSTANCE.display().general(build()); - } - - public void forceDisplay() { - TipManager.INSTANCE.display().force(build()); - } - public Tip build() { return new Tip(this); } diff --git a/src/main/java/com/teammoeg/frostedheart/content/tips/client/gui/TipEditorScreen.java b/src/main/java/com/teammoeg/frostedheart/content/tips/client/gui/TipEditorScreen.java index 63b8c8d01..a33f046f1 100644 --- a/src/main/java/com/teammoeg/frostedheart/content/tips/client/gui/TipEditorScreen.java +++ b/src/main/java/com/teammoeg/frostedheart/content/tips/client/gui/TipEditorScreen.java @@ -1,8 +1,11 @@ package com.teammoeg.frostedheart.content.tips.client.gui; +import com.teammoeg.frostedheart.FHNetwork; +import com.teammoeg.frostedheart.base.client.gui.widget.ActionStateIconButton; import com.teammoeg.frostedheart.content.tips.Tip; import com.teammoeg.frostedheart.base.client.gui.widget.IconButton; import com.teammoeg.frostedheart.content.tips.client.gui.widget.TipEditsList; +import com.teammoeg.frostedheart.content.tips.network.DisplayCustomTipRequestPacket; import com.teammoeg.frostedheart.util.client.ClientUtils; import com.teammoeg.frostedheart.util.client.FHColorHelper; import com.teammoeg.frostedheart.util.lang.Lang; @@ -14,18 +17,11 @@ public class TipEditorScreen extends Screen { private final TipEditsList list; - private final IconButton saveButton; public TipEditorScreen() { super(Lang.str("Tip Editor")); this.list = new TipEditsList(ClientUtils.mc(), ClientUtils.screenWidth(), ClientUtils.screenHeight(), 10, ClientUtils.screenHeight() - 30, 28); list.setRenderBackground(false); - this.saveButton = new IconButton(ClientUtils.screenWidth()/2 - 10, ClientUtils.screenHeight()-25, IconButton.Icon.FOLDER, FHColorHelper.CYAN, 2, Component.literal("Save"), (b) -> { - var json = list.getJson(); - if (json != null) { - Tip.builder("").fromJson(json).build().saveAsFile(); - } - }); } @Override @@ -39,14 +35,32 @@ public void render(@NotNull GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, public void resize(@NotNull Minecraft pMinecraft, int pWidth, int pHeight) { super.resize(pMinecraft, pWidth, pHeight); list.updateSize(ClientUtils.screenWidth(), ClientUtils.screenHeight(), 10, ClientUtils.screenHeight() - 30); - saveButton.setPosition(ClientUtils.screenWidth()/2 - 10, ClientUtils.screenHeight()-25); } @Override protected void init() { super.init(); addWidget(list); - addRenderableWidget(saveButton); + // 保存按钮 + addRenderableWidget(new ActionStateIconButton(ClientUtils.screenWidth()/2 - 30, ClientUtils.screenHeight()-25, IconButton.Icon.FOLDER, FHColorHelper.CYAN, 2, Component.translatable("gui.frostedheart.save_as_file"), Component.translatable("gui.frostedheart.saved"), (b) -> { + var json = list.getJson(); + if (json != null) { + Tip.builder("").fromJson(json).build().saveAsFile(); + } + })); + // 发送按钮 + ActionStateIconButton sendButton = new ActionStateIconButton(ClientUtils.screenWidth()/2 + 5, ClientUtils.screenHeight()-25, IconButton.Icon.GIVE, FHColorHelper.CYAN, 2, Component.translatable("gui.frostedheart.tip_editor.send"), Component.translatable("gui.frostedheart.sent"), (b) -> { + var json = list.getJson(); + if (json != null) { + Tip tip = Tip.builder("").fromJson(json).build(); + FHNetwork.sendToServer(new DisplayCustomTipRequestPacket(tip)); + } + }); + if (!ClientUtils.getPlayer().hasPermissions(2)) { + sendButton.active = false; + sendButton.setMessage(Component.translatable("gui.frostedheart.tip_editor.no_permission")); + } + addRenderableWidget(sendButton); } @Override 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 de24762b2..cc9e1fdbc 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 @@ -5,13 +5,14 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; +import com.teammoeg.frostedheart.base.client.gui.widget.ActionStateIconButton; import com.teammoeg.frostedheart.base.client.gui.widget.ColorEditbox; import com.teammoeg.frostedheart.base.client.gui.widget.IconButton; import com.teammoeg.frostedheart.base.client.gui.widget.IconCheckbox; import com.teammoeg.frostedheart.content.tips.Tip; import com.teammoeg.frostedheart.content.tips.TipRenderer; +import com.teammoeg.frostedheart.util.client.ClientUtils; import com.teammoeg.frostedheart.util.client.FHColorHelper; -import com.teammoeg.frostedheart.util.lang.Lang; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; @@ -28,6 +29,7 @@ public class TipEditsList extends ContainerObjectSelectionList { private final Font font; + private String cachedId; public TipEditsList(Minecraft pMinecraft, int pWidth, int pHeight, int pY0, int pY1, int pItemHeight) { super(pMinecraft, pWidth, pHeight, pY0, pY1, pItemHeight); @@ -50,7 +52,9 @@ public TipEditsList(Minecraft pMinecraft, int pWidth, int pHeight, int pY0, int public void updatePreview() { TipRenderer.TIP_QUEUE.clear(); TipRenderer.forceClose(); - Tip.builder("").fromJson(getJson()).alwaysVisible(true).forceDisplay(); + Tip tip = Tip.builder("").fromJson(getJson()).alwaysVisible(true).build(); + tip.forceDisplay(); + this.cachedId = tip.getId(); } public JsonObject getJson() { @@ -109,21 +113,46 @@ public JsonElement getValue() { public class MultiComponentEntry extends StringEntry { protected final IconButton addButton; protected final IconButton deleteButton; - protected final List contents = new ArrayList<>(); + protected final IconButton translationButton; + protected final List contents = new ArrayList<>(); public MultiComponentEntry(String property, Component message) { super(property, message); - this.addButton = new IconButton(0, 0, IconButton.Icon.CHECK, FHColorHelper.CYAN, Component.translatable("gui.add"), b -> { + this.addButton = new IconButton(0, 0, IconButton.Icon.CHECK, FHColorHelper.CYAN, Component.translatable("gui.frostedheart.tip_editor.add_line"), b -> { if (input.getValue().isBlank()) return; - contents.add(Lang.str(this.input.getValue())); + contents.add(this.input.getValue()); input.setValue(""); updatePreview(); }); - this.deleteButton = new IconButton(0, 0, IconButton.Icon.TRASH_CAN, FHColorHelper.CYAN, Component.translatable("key.keyboard.delete"), b -> { - if (!contents.isEmpty()) contents.remove(contents.size()-1); - updatePreview(); + this.deleteButton = new IconButton(0, 0, IconButton.Icon.TRASH_CAN, FHColorHelper.CYAN, Component.translatable("gui.frostedheart.tip_editor.delete_last_line"), b -> { + if (!contents.isEmpty()) { + contents.remove(contents.size() - 1); + updatePreview(); + } + }); + + this.translationButton = new ActionStateIconButton(0, 0, IconButton.Icon.LIST, FHColorHelper.CYAN, Component.translatable("gui.frostedheart.tip_editor.convert_and_copy"), Component.translatable("gui.frostedheart.copied"), b -> { + if (!contents.isEmpty()) { + String prefix = "tips.frostedheart." + cachedId; + StringBuilder copy = new StringBuilder(); + List converted = new ArrayList<>(); + + converted.add(prefix + ".title"); + copy.append(prefix).append(".title: \"").append(contents.get(0)).append("\",\n"); + for (int i = 1; i < contents.size(); i++) { + //tips.frostedheart.example.desc1 + String s = prefix + ".desc" + i; + converted.add(s); + copy.append(s).append(": \"").append(contents.get(i)).append("\",\n"); + } + + contents.clear(); + contents.addAll(converted); + ClientUtils.mc().keyboardHandler.setClipboard(copy.substring(0, copy.length()-2)); // 删除最后一行的逗号和换行 + updatePreview(); + } }); } @@ -134,23 +163,25 @@ public void render(@NotNull GuiGraphics pGuiGraphics, int pIndex, int pTop, int addButton.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick); deleteButton.setPosition(pLeft + 132, pTop + (pHeight/2) - 10); deleteButton.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick); + translationButton.setPosition(pLeft + 118, pTop + (pHeight/2) - 10); + translationButton.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick); } @Override public JsonElement getValue() { JsonArray contents = new JsonArray(); - this.contents.stream().map(Lang::getKeyOrElseStr).forEach(contents::add); + this.contents.forEach(contents::add); return contents; } @Override public @NotNull List narratables() { - return ImmutableList.of(addButton, deleteButton, input); + return ImmutableList.of(addButton, deleteButton, translationButton, input); } @Override public @NotNull List children() { - return ImmutableList.of(addButton, deleteButton, input); + return ImmutableList.of(addButton, deleteButton, translationButton, input); } } diff --git a/src/main/java/com/teammoeg/frostedheart/content/tips/network/DisplayCustomTipRequestPacket.java b/src/main/java/com/teammoeg/frostedheart/content/tips/network/DisplayCustomTipRequestPacket.java new file mode 100644 index 000000000..015cb761d --- /dev/null +++ b/src/main/java/com/teammoeg/frostedheart/content/tips/network/DisplayCustomTipRequestPacket.java @@ -0,0 +1,37 @@ +package com.teammoeg.frostedheart.content.tips.network; + +import com.teammoeg.frostedheart.FHMain; +import com.teammoeg.frostedheart.base.network.FHMessage; +import com.teammoeg.frostedheart.content.tips.ServerTipSender; +import com.teammoeg.frostedheart.content.tips.Tip; +import com.teammoeg.frostedheart.util.lang.Lang; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraftforge.network.NetworkEvent; + +import java.util.function.Supplier; + +public record DisplayCustomTipRequestPacket(Tip tip) implements FHMessage { + + public DisplayCustomTipRequestPacket(FriendlyByteBuf buffer) { + this(Tip.builder("").fromNBT(buffer.readNbt()).build()); + } + + @Override + public void encode(FriendlyByteBuf buffer) { + tip.write(buffer); + } + + @Override + public void handle(Supplier context) { + var player = context.get().getSender(); + if (player != null) { + if (!player.hasPermissions(2)) { + FHMain.LOGGER.warn("{} IS A HACKER!", player.getName().getString()); + ServerTipSender.sendCustom(Tip.builder("warning").line(Lang.str("HACKER!")).pin(true).alwaysVisible(true).build(), player); + } else { + context.get().enqueueWork(() -> ServerTipSender.sendCustomToAll(tip)); + } + } + context.get().setPacketHandled(true); + } +} diff --git a/src/main/java/com/teammoeg/frostedheart/infrastructure/command/TipCommand.java b/src/main/java/com/teammoeg/frostedheart/infrastructure/command/TipCommand.java index 5d25c00d5..eb98f873f 100644 --- a/src/main/java/com/teammoeg/frostedheart/infrastructure/command/TipCommand.java +++ b/src/main/java/com/teammoeg/frostedheart/infrastructure/command/TipCommand.java @@ -25,7 +25,7 @@ import com.teammoeg.frostedheart.FHMain; import com.teammoeg.frostedheart.FHNetwork; import com.teammoeg.frostedheart.content.tips.Tip; -import com.teammoeg.frostedheart.content.tips.network.DisplayCustomTipPacket; +import com.teammoeg.frostedheart.content.tips.ServerTipSender; import com.teammoeg.frostedheart.content.tips.network.DisplayTipPacket; import com.teammoeg.frostedheart.util.lang.Lang; import net.minecraft.client.resources.language.I18n; @@ -75,7 +75,7 @@ public static void register(RegisterCommandsEvent event) { int i = 0; for(ServerPlayer sp : EntityArgument.getPlayers(c, "targets")) { - FHNetwork.send(PacketDistributor.PLAYER.with(() -> sp), new DisplayCustomTipPacket(toTip(title, content, displayTime))); + ServerTipSender.sendCustom(toTip(title, content, displayTime), sp); i++; } diff --git a/src/main/java/com/teammoeg/frostedheart/util/client/FHColorHelper.java b/src/main/java/com/teammoeg/frostedheart/util/client/FHColorHelper.java index 09116d1dd..5ba3cb4e8 100644 --- a/src/main/java/com/teammoeg/frostedheart/util/client/FHColorHelper.java +++ b/src/main/java/com/teammoeg/frostedheart/util/client/FHColorHelper.java @@ -30,7 +30,7 @@ public static int blendColor(int color1, int color2, float ratio) { } public static int makeDark(int color, float darkness) { - darkness = Mth.clamp(darkness, 0, 1); + darkness = 1-Mth.clamp(darkness, 0, 1); int a = FastColor.ARGB32.alpha(color); int r = (int)(FastColor.ARGB32.red (color) * darkness); diff --git a/src/main/resources/assets/frostedheart/lang/en_us/en_us.json b/src/main/resources/assets/frostedheart/lang/en_us/en_us.json index b4b496fe6..dc20b107b 100644 --- a/src/main/resources/assets/frostedheart/lang/en_us/en_us.json +++ b/src/main/resources/assets/frostedheart/lang/en_us/en_us.json @@ -457,6 +457,10 @@ "tips.frostedheart.error.load.invalid_image": "Invalid texture ResourceLocation '%s'", "tips.frostedheart.error.load.invalid_digit": "Invalid hexadecimal number '%s'", "gui.frostedheart.close": "Close", + "gui.frostedheart.copied": "Copied!", + "gui.frostedheart.save_as_file": "Save as file", + "gui.frostedheart.saved": "Saved!", + "gui.frostedheart.sent": "Sent!", "gui.frostedheart.tip_editor.title": "Tip Editor", "gui.frostedheart.tip_editor.id": "ID", "gui.frostedheart.tip_editor.category": "Category", @@ -468,5 +472,10 @@ "gui.frostedheart.tip_editor.display_time": "Display Time", "gui.frostedheart.tip_editor.once_only": "Once Only", "gui.frostedheart.tip_editor.hide": "Hide", - "gui.frostedheart.tip_editor.pin": "Pin" + "gui.frostedheart.tip_editor.pin": "Pin", + "gui.frostedheart.tip_editor.add_line": "Add a new line", + "gui.frostedheart.tip_editor.delete_last_line": "Delete the last line", + "gui.frostedheart.tip_editor.convert_and_copy": "Convert content to localization key values and copy to clipboard", + "gui.frostedheart.tip_editor.send": "Send this tip to all players", + "gui.frostedheart.tip_editor.no_permission": "You don't have permission to use this button" } \ No newline at end of file diff --git a/src/main/resources/assets/frostedheart/lang/zh_cn/zh_cn.json b/src/main/resources/assets/frostedheart/lang/zh_cn/zh_cn.json index 962921c24..670f6cfe7 100644 --- a/src/main/resources/assets/frostedheart/lang/zh_cn/zh_cn.json +++ b/src/main/resources/assets/frostedheart/lang/zh_cn/zh_cn.json @@ -934,6 +934,10 @@ "tips.frostedheart.error.load.invalid_image": "无效的纹理资源路径 '%s'", "tips.frostedheart.error.load.invalid_digit": "无效的16进制数字 '%s'", "gui.frostedheart.close": "关闭", + "gui.frostedheart.copied": "已复制!", + "gui.frostedheart.save_as_file": "保存为文件", + "gui.frostedheart.saved": "已保存!", + "gui.frostedheart.sent": "已发送!", "gui.frostedheart.tip_editor.title": "提示编辑器", "gui.frostedheart.tip_editor.id": "ID", "gui.frostedheart.tip_editor.category": "分类", @@ -945,5 +949,11 @@ "gui.frostedheart.tip_editor.display_time": "显示时长", "gui.frostedheart.tip_editor.once_only": "只显示一次", "gui.frostedheart.tip_editor.hide": "隐藏该提示", - "gui.frostedheart.tip_editor.pin": "显示时置顶" + "gui.frostedheart.tip_editor.pin": "显示时置顶", + "gui.frostedheart.tip_editor.add_line": "添加新行", + "gui.frostedheart.tip_editor.delete_last_line": "删除最后一行", + "gui.frostedheart.tip_editor.convert_and_copy": "将内容转换为本地化键值并复制到剪贴板", + "gui.frostedheart.tip_editor.send": "将此提示发送给所有玩家", + "gui.frostedheart.tip_editor.no_permission": "你没有权限使用这个按钮" + } \ No newline at end of file