-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring back the translation prompt screen, but simplified
- Loading branch information
Showing
7 changed files
with
111 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/com/lovetropics/extras/mixin/client/translation/MinecraftMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/com/lovetropics/extras/translation/TranslationPromptScreen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters