Skip to content

Commit

Permalink
Improve message formatting
Browse files Browse the repository at this point in the history
Improve Message Formatting

Improve Message Formatting 4
  • Loading branch information
Hikari16665 committed Jul 18, 2024
1 parent e1a2f88 commit c2db34f
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 104 deletions.
53 changes: 22 additions & 31 deletions src/main/java/com/github/zly2006/enclosure/gui/EnclosureScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -54,7 +55,7 @@ protected void init() {
.size(100, 20)
.position(5, 35)
.build());
playerWidget = addDrawableChild(ButtonWidget.builder(Text.translatable("enclosure.widget.player"), button -> {
playerWidget = addDrawableChild(ButtonWidget.builder(Text.translatable("enclosure.widget.showplayer"), button -> {
assert client != null;
button.active = false;
unlistedWidget.active = true;
Expand Down Expand Up @@ -98,38 +99,28 @@ protected void init() {
}, 5, 5, width - 10));
}
textWidgets.add(new ClickableTextWidget(client, this, Text.empty()
.append(Text.translatable("enclosure.info.created"))
.append(Text.literal(area.getFullName()).styled(style -> style.withColor(Formatting.GOLD)))
.append(" ")
.append(Text.translatable("enclosure.info.created_by"))
.append(" ")
.append(owner == null ?
Text.translatable("enclosure.message.unknown_user").styled(style -> style.withColor(Formatting.RED)) :
Text.literal(owner).styled(style -> style.withColor(Formatting.GOLD)))
.append(", ")
.append(Text.translatable("enclosure.info.created_on"))
.append(Text.literal(new SimpleDateFormat().format(area.getCreatedOn())).styled(style -> style.withColor(Formatting.GOLD))),
.append(Text.translatable("enclosure.info.created",
Text.literal(area.getFullName()).styled(style -> style.withColor(Formatting.GOLD)),
(owner == null ?
Text.translatable("enclosure.message.unknown_user").styled(style -> style.withColor(Formatting.RED)) : Text.literal(owner).styled(style -> style.withColor(Formatting.GOLD))),
Text.literal(new SimpleDateFormat().format(area.getCreatedOn())).styled(style -> style.withColor(Formatting.GOLD))
)),
null, null,
5, 5, width - 10));
textWidgets.add(new ClickableTextWidget(client, this, Text.translatable("enclosure.message.select.from")
.append(Text.literal("[").styled(style -> style.withColor(Formatting.DARK_GREEN)))
.append(Text.literal(String.valueOf(area.getMinX())).styled(style -> style.withColor(Formatting.GREEN)))
.append(Text.literal(", ").styled(style -> style.withColor(Formatting.DARK_GREEN)))
.append(Text.literal(String.valueOf(area.getMinY())).styled(style -> style.withColor(Formatting.GREEN)))
.append(Text.literal(", ").styled(style -> style.withColor(Formatting.DARK_GREEN)))
.append(Text.literal(String.valueOf(area.getMinZ())).styled(style -> style.withColor(Formatting.GREEN)))
.append(Text.literal("]").styled(style -> style.withColor(Formatting.DARK_GREEN)))
.append(Text.translatable("enclosure.message.select.to"))
.append(Text.literal("[").styled(style -> style.withColor(Formatting.DARK_GREEN)))
.append(Text.literal(String.valueOf(area.getMaxX())).styled(style -> style.withColor(Formatting.GREEN)))
.append(Text.literal(", ").styled(style -> style.withColor(Formatting.DARK_GREEN)))
.append(Text.literal(String.valueOf(area.getMaxY())).styled(style -> style.withColor(Formatting.GREEN)))
.append(Text.literal(", ").styled(style -> style.withColor(Formatting.DARK_GREEN)))
.append(Text.literal(String.valueOf(area.getMaxZ())).styled(style -> style.withColor(Formatting.GREEN)))
.append(Text.literal("]").styled(style -> style.withColor(Formatting.DARK_GREEN)))
.append(Text.translatable("enclosure.message.select.world"))
.append(Text.literal(handler.worldId.toString()).styled(style -> style.withColor(Formatting.GOLD))),
Text.translatable("enclosure.widget.selection_render.hover"),
MutableText fromCoord = Text.translatable("enclosure.message.select.coordinate",
Text.literal(String.valueOf(area.getMinX())).styled(style -> style.withColor(Formatting.GREEN)),
Text.literal(String.valueOf(area.getMinY())).styled(style -> style.withColor(Formatting.GREEN)),
Text.literal(String.valueOf(area.getMinZ())).styled(style -> style.withColor(Formatting.GREEN))
);
MutableText toCoord = Text.translatable("enclosure.message.select.coordinate",
Text.literal(String.valueOf(area.getMaxX())).styled(style -> style.withColor(Formatting.GREEN)),
Text.literal(String.valueOf(area.getMaxY())).styled(style -> style.withColor(Formatting.GREEN)),
Text.literal(String.valueOf(area.getMaxZ())).styled(style -> style.withColor(Formatting.GREEN))
);
textWidgets.add(new ClickableTextWidget(client, this, Text.translatable("enclosure.widget.selection",
fromCoord,
toCoord
), Text.translatable("enclosure.widget.selection_render.hover"),
button -> {
assert client.player != null;
client.player.networkHandler.sendChatCommand("enclosure select land " + handler.fullName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,11 @@ public void close() {
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
renderInGameBackground(context);
super.render(context, mouseX, mouseY, delta);
MutableText title = Text.translatable("enclosure.widget.set_permission").append(" ");
if (CONSOLE.equals(uuid)) {
title.append(Text.translatable("enclosure.widget.global"));
}
else {
title.append(Text.translatable("enclosure.widget.player"))
.append(" ")
.append(UUIDCacheS2CPacket.getName(uuid));
}
title.append(" ")
.append(Text.translatable("enclosure.widget.in_enclosure"))
.append(" ")
.append(fullName);

MutableText title = Text.translatable("enclosure.widget.set_permission",
(CONSOLE.equals(uuid) ? Text.translatable("enclosure.widget.global") : Text.translatable("enclosure.widget.player", UUIDCacheS2CPacket.getName(uuid))),
fullName
);
context.drawText(textRenderer, title, 10, 10, 0xffffff, false);
}

Expand Down
8 changes: 5 additions & 3 deletions src/main/kotlin/com/github/zly2006/enclosure/Enclosure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import net.minecraft.registry.RegistryWrapper.WrapperLookup
import net.minecraft.server.network.ServerPlayerEntity
import net.minecraft.server.world.ServerWorld
import net.minecraft.text.MutableText
import net.minecraft.text.Text
import net.minecraft.util.Formatting
import net.minecraft.util.math.BlockPos

Expand Down Expand Up @@ -57,17 +58,18 @@ class Enclosure : EnclosureArea {
override fun serialize(settings: SerializationSettings, player: ServerPlayerEntity?): MutableText {
if (settings == SerializationSettings.Full) {
val text = super.serialize(settings, player)
val subLandsText: MutableText = Text.empty()
if (subEnclosures.areas.isNotEmpty()) {
text.append("\n")
text.append(TrT.of("enclosure.message.sub_lands"))
for (area in subEnclosures.areas) {
text.append(area.serialize(SerializationSettings.Name, player).styled {
subLandsText.append(area.serialize(SerializationSettings.Name, player).styled {
it.withColor(Formatting.GOLD)
.hoverText(area.serialize(SerializationSettings.Hover, player))
.clickRun("/enclosure info ${area.fullName}")
})
text.append(" ")
subLandsText.append(" ")
}
text.append(TrT.of("enclosure.message.sub_lands", subLandsText))
}
return text
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class BuilderScope<T: argT>(var parent: T) {
throw e
} catch (e: Throwable) {
LOGGER.error("Error while executing command: " + it.input, e)
error(TrT.of("enclosure.message.error").append("${e.javaClass.simpleName}: ${e.message}"), it)
error(TrT.of("enclosure.message.error","${e.javaClass.simpleName}: ${e.message}"), it)
}
}
}
Expand All @@ -66,11 +66,10 @@ class BuilderScope<T: argT>(var parent: T) {
val firstPage = page == 1
val lastPage = page >= totalPage

val ret: MutableText = TrT.of("enclosure.menu.page.0")
.append(page.toString())
.append(TrT.of("enclosure.menu.page.1"))
.append(totalPage.toString())
.append("\n")
val ret: MutableText = TrT.of("enclosure.menu.page",
page.toString(),
totalPage.toString()
).append("\n")

var i: Int = size * (page - 1)
while (i < size * page && i < list.size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ fun BuilderScope<*>.registerCreate() {
val intersectArea = sessionOf(source).intersect(enclosure.subEnclosures)
if (intersectArea != null) {
error(
TrT.of("enclosure.message.intersected")
.append(intersectArea.serialize(SerializationSettings.Name, source.player)), this
TrT.of("enclosure.message.intersected",
intersectArea.serialize(SerializationSettings.Name, source.player)
), this
)
}
val limits = getLimits(this)
Expand All @@ -80,16 +81,18 @@ fun BuilderScope<*>.registerCreate() {
val count = enclosure.subEnclosures.areas.size.toLong()
if (count > limits.maxSubLands) {
error(
TrT.of("enclosure.message.scle").append(Text.literal(limits.maxSubLands.toString())),
this
TrT.of("enclosure.message.sub_lands.exceed",
Text.literal(limits.maxSubLands.toString())
),this
)
}
}
area.changeWorld(session.world)
enclosure.addChild(area)
source.sendMessage(
TrT.of("enclosure.message.created")
.append(area.serialize(SerializationSettings.Name, source.player))
TrT.of("enclosure.message.created",
area.serialize(SerializationSettings.Name, source.player)
)
)
LOGGER.info("Created subzone {} by {}", area.fullName, source.name)
}
Expand Down Expand Up @@ -136,8 +139,9 @@ private fun createEnclosure(context: CommandContext<ServerCommandSource>) {
session.reset(session.world)
list.addArea(enclosure)
context.source.sendMessage(
TrT.of("enclosure.message.created")
.append(enclosure.serialize(SerializationSettings.Name, context.source.player))
TrT.of("enclosure.message.created",
enclosure.serialize(SerializationSettings.Name, context.source.player)
)
)
LOGGER.info(context.source.name + " created enclosure " + enclosure.name)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ fun BuilderScope<*>.registerRemove() {
true
} ?: list.remove(res.name)
if (success) {
source.sendMessage(TrT.of("enclosure.message.deleted").append(res.fullName))
source.sendMessage(TrT.of("enclosure.message.deleted",
res.fullName)
)
LOGGER.info("${source.name} removed ${res.fullName}")
} else {
error(TrT.of("enclosure.message.no_enclosure"), this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,22 @@ fun BuilderScope<*>.registerSelection() {
session.trySync()
val intersectArea = session.intersect(ServerMain.getAllEnclosures(session.world))
source.sendMessage(
TrT.of("enclosure.message.select.from")
.append(session.pos1.toShortString())
.append(TrT.of("enclosure.message.select.to"))
.append(session.pos2.toShortString())
.append(TrT.of("enclosure.message.select.world"))
.append(session.world.registryKey.value.toString())
TrT.of("enclosure.message.selection",
session.pos1.toShortString(),
session.size().toString(),
session.world.registryKey.value.toString()
)
)
source.sendMessage(
TrT.of("enclosure.message.total_size")
.append(session.size().toString())
TrT.of("enclosure.message.total_size",
session.size().toString()
)
)
if (intersectArea != null) {
source.sendMessage(
TrT.of("enclosure.message.intersected")
.append(intersectArea.serialize(SerializationSettings.Name, source.player))
TrT.of("enclosure.message.intersected",
intersectArea.serialize(SerializationSettings.Name, source.player)
)
)
}
}
Expand Down Expand Up @@ -176,8 +177,9 @@ fun BuilderScope<*>.registerSelection() {
area.maxY = maxY
area.maxZ = maxZ
source.sendMessage(
TrT.of("enclosure.message.resized")
.append(area.serialize(SerializationSettings.Name, source.player))
TrT.of("enclosure.message.resized",
area.serialize(SerializationSettings.Name, source.player)
)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fun formatSelection(
worldId: Identifier,
x1: Int, y1: Int, z1: Int,
x2: Int, y2: Int, z2: Int
): String {
): MutableText {
val fromStr = TrT.of("enclosure.message.select.coordinate",
literalText(x1).green(),
literalText(y1).green(),
Expand Down
Loading

0 comments on commit c2db34f

Please sign in to comment.