Skip to content

Commit

Permalink
Bring back the translation prompt screen, but simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
Gegy committed Nov 3, 2024
1 parent 145a397 commit 40eb3ec
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/generated/resources/assets/ltextras/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@
"item.ltextras.tropicoin": "uıoƆıdoɹ⟘",
"itemGroup.ltextras.ltextras": "sɐɹʇxƎ⟘Ꞁ",
"ltextras.friction": "uoıʇɔıɹℲ",
"screen.ltextras.translation_prompt.message": "˙ɥɔuǝɹℲ puɐ 'ɥsıuɐdS 'ɥsıןbuƎ ɹoɟ pǝʇɐןsuɐɹʇ sı ʇuǝʇuoɔ ǝɯɐb-uI\n\n˙ǝǝs oʇ ǝʞıן pןnoʍ puɐ buıʞɐǝds ǝq ןןıʍ noʎ ǝbɐnbuɐן ʇɐɥʍ ʍouʞ oʇ pǝǝu ǝʍ 'sıɥʇ op oʇ ʇnq - noʎ ɹoɟ ʇɐɥɔ ǝʇɐןsuɐɹʇ oʇ ʇsǝq ɹno ʎɹʇ ןןıʍ ǝM ¡ןɐnbuıן-ıʇןnɯ sı sɔıdoɹ⟘ ǝʌoꞀ",
"screen.ltextras.translation_prompt.title": "uoıʇɐןsuɐɹ⟘ ʇɐɥƆ",
"spawnitems.restored_successfully": "¡pǝɹoʇsǝɹ sɯǝʇI",
"spawnitems.set_not_restorable": "¡pǝɹoʇsǝɹ ǝq ʇouuɐɔ %s ʇǝs ɯǝʇı uʍɐds ǝɥ⟘",
"spawnitems.unknown_set": "%s :ʇǝs ɯǝʇı uʍɐds uʍouʞu∩",
Expand Down
2 changes: 2 additions & 0 deletions src/generated/resources/assets/ltextras/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@
"item.ltextras.tropicoin": "TropiCoin",
"itemGroup.ltextras.ltextras": "LTExtras",
"ltextras.friction": "Friction",
"screen.ltextras.translation_prompt.message": "Love Tropics is multi-lingual! We will try our best to translate chat for you - but to do this, we need to know what language you will be speaking and would like to see.\n\nIn-game content is translated for English, Spanish, and French.",
"screen.ltextras.translation_prompt.title": "Chat Translation",
"spawnitems.restored_successfully": "Items restored!",
"spawnitems.set_not_restorable": "The spawn item set %s cannot be restored!",
"spawnitems.unknown_set": "Unknown spawn item set: %s",
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/lovetropics/extras/ExtraLangKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public enum ExtraLangKeys {
CLUB_INVITE_1_BOTTOM("invite", "club_1.bottom", "Did you know disguises are fireproof?"),
CLUB_INVITE_2_TOP("invite", "club_2.top", "See you there.\nWear a disguise.\nGrab a drink."),
CLUB_INVITE_2_BOTTOM("invite", "club_2.bottom", "I hear the Limeade's good."),
TRANSLATION_PROMPT_TITLE("screen", "translation_prompt.title", "Chat Translation"),
TRANSLATION_PROMPT("screen", "translation_prompt.message", "Love Tropics is multi-lingual! We will try our best to translate chat for you - but to do this, we need to know what language you will be speaking and would like to see.\n\nIn-game content is translated for English, Spanish, and French."),
;

private final String key;
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/com/lovetropics/extras/ExtrasConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,11 @@ private CategoryCommands() {
}

public static final class CategoryTranslation {
public final ModConfigSpec.ConfigValue<Boolean> translateOutgoing;
public final ModConfigSpec.ConfigValue<Boolean> translateIncoming;
public final ModConfigSpec.ConfigValue<Boolean> prompted;

private CategoryTranslation() {
CLIENT_BUILDER.comment("Translation").push("translation");

translateOutgoing = CLIENT_BUILDER
.comment("True if messages that you send should be translated for other players")
.define("translateOutgoing", true);

translateIncoming = CLIENT_BUILDER
.comment("True if messages that others send should be translated for you")
.define("translateIncoming", true);

prompted = CLIENT_BUILDER
.comment("True if the player has been prompted to select translation options yet")
.define("prompted", false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.lovetropics.extras.mixin.client.translation;

import com.lovetropics.extras.ExtrasConfig;
import com.lovetropics.extras.translation.TranslationPromptScreen;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.screens.Screen;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;
import java.util.function.Function;

@Mixin(Minecraft.class)
public abstract class MinecraftMixin {
@Shadow
@Final
public Font font;

@Shadow
public abstract void setScreen(@Nullable Screen screen);

@Inject(method = "addInitialScreens", at = @At("RETURN"))
private void showPrompt(List<Function<Runnable, Screen>> output, CallbackInfo ci) {
if (!ExtrasConfig.TRANSLATION.prompted.get()) {
output.add(onClose -> new TranslationPromptScreen(onClose, (Minecraft) (Object) this, font));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.lovetropics.extras.translation;

import com.lovetropics.extras.ExtraLangKeys;
import com.lovetropics.extras.ExtrasConfig;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.CommonButtons;
import net.minecraft.client.gui.components.MultiLineTextWidget;
import net.minecraft.client.gui.components.StringWidget;
import net.minecraft.client.gui.layouts.FrameLayout;
import net.minecraft.client.gui.layouts.LinearLayout;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.options.LanguageSelectScreen;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;

public class TranslationPromptScreen extends Screen {
private static final Component TITLE = ExtraLangKeys.TRANSLATION_PROMPT_TITLE.get();
private static final Component MESSAGE = ExtraLangKeys.TRANSLATION_PROMPT.get();

private static final int MAX_WIDTH = 300;

private final Runnable callback;
private final LinearLayout layout = LinearLayout.vertical().spacing(8);

public TranslationPromptScreen(Runnable callback, Minecraft minecraft, Font font) {
super(TITLE);
this.callback = callback;

layout.defaultCellSetting().alignHorizontallyCenter();

layout.addChild(new StringWidget(TITLE, font).alignCenter(), layout.newCellSettings().paddingVertical(10));

layout.addChild(new MultiLineTextWidget(MESSAGE, font).setCentered(true).setMaxWidth(MAX_WIDTH));

layout.addChild(CommonButtons.language(Button.DEFAULT_WIDTH, button -> minecraft.setScreen(new LanguageSelectScreen(this, minecraft.options, minecraft.getLanguageManager())), false));

layout.addChild(Button.builder(CommonComponents.GUI_DONE, b -> onClose()).build(), layout.newCellSettings().paddingVertical(10));
}

@Override
protected void init() {
layout.visitWidgets(this::addRenderableWidget);
repositionElements();
}

@Override
protected void repositionElements() {
layout.arrangeElements();
FrameLayout.centerInRectangle(layout, getRectangle());
}

@Override
public Component getNarrationMessage() {
return CommonComponents.joinForNarration(TITLE, MESSAGE);
}

@Override
public boolean shouldCloseOnEsc() {
return false;
}

@Override
public void onClose() {
ExtrasConfig.TRANSLATION.prompted.set(true);
ExtrasConfig.CLIENT_CONFIG.save();
callback.run();
}
}
1 change: 1 addition & 0 deletions src/main/resources/ltextras.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"client.perf.ClientWorldMixin",
"client.perf.ViewFrustumAccess",
"client.perf.WorldRendererAccess",
"client.translation.MinecraftMixin",
"client.world_effect.ClientLevelMixin"
],
"injectors": {
Expand Down

0 comments on commit 40eb3ec

Please sign in to comment.