-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make 'Advertisements' in Language Selection Tab
Actually just a message and buttons to make sure poeple know where to find the Localization Packs for Nomi-Labs and Nomi-CEu.
- Loading branch information
1 parent
700bf95
commit 26ae0ef
Showing
8 changed files
with
356 additions
and
7 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
54 changes: 54 additions & 0 deletions
54
src/main/java/com/nomiceu/nomilabs/mixin/GuiLanguageListMixin.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,54 @@ | ||
package com.nomiceu.nomilabs.mixin; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import net.minecraft.client.gui.GuiLanguage; | ||
import net.minecraft.client.resources.Language; | ||
|
||
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.ModifyArg; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import com.nomiceu.nomilabs.config.LabsConfig; | ||
import com.nomiceu.nomilabs.mixinhelper.AccessibleGuiLanguage; | ||
|
||
/** | ||
* Contracts the List Section, and Stops Language Refresh on Element Clicked. | ||
*/ | ||
@Mixin(targets = "net.minecraft.client.gui.GuiLanguage$List") | ||
public abstract class GuiLanguageListMixin { | ||
|
||
@Shadow(aliases = "this$0") | ||
@Final | ||
GuiLanguage this$0; | ||
|
||
@Shadow | ||
@Final | ||
private List<String> langCodeList; | ||
|
||
@Shadow | ||
@Final | ||
private Map<String, Language> languageMap; | ||
|
||
@ModifyArg(method = "<init>(Lnet/minecraft/client/gui/GuiLanguage;Lnet/minecraft/client/Minecraft;)V", | ||
at = @At(value = "INVOKE", | ||
target = "net/minecraft/client/gui/GuiSlot.<init>(Lnet/minecraft/client/Minecraft;IIIII)V"), | ||
index = 3) | ||
private static int getNewArgs(int top) { | ||
if (LabsConfig.advanced.languageModifyOption == LabsConfig.Advanced.LanguageModifyOption.NONE) return top; | ||
return top * 2; | ||
} | ||
|
||
@Inject(method = "elementClicked(IZII)V", at = @At("HEAD"), cancellable = true) | ||
protected void cancelElementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY, CallbackInfo ci) { | ||
if (LabsConfig.advanced.languageModifyOption == LabsConfig.Advanced.LanguageModifyOption.NONE) return; | ||
Language language = languageMap.get(langCodeList.get(slotIndex)); | ||
((AccessibleGuiLanguage) this$0).getLanguageManager().setCurrentLanguage(language); | ||
ci.cancel(); | ||
} | ||
} |
161 changes: 161 additions & 0 deletions
161
src/main/java/com/nomiceu/nomilabs/mixin/GuiLanguageMixin.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,161 @@ | ||
package com.nomiceu.nomilabs.mixin; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
import net.minecraft.client.gui.*; | ||
import net.minecraft.client.resources.I18n; | ||
import net.minecraft.client.resources.LanguageManager; | ||
import net.minecraft.client.settings.GameSettings; | ||
import net.minecraft.util.text.TextFormatting; | ||
import net.minecraftforge.client.resource.VanillaResourceType; | ||
import net.minecraftforge.fml.client.FMLClientHandler; | ||
|
||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import com.nomiceu.nomilabs.NomiLabs; | ||
import com.nomiceu.nomilabs.config.LabsConfig; | ||
import com.nomiceu.nomilabs.mixinhelper.AccessibleGuiLanguage; | ||
import com.nomiceu.nomilabs.mixinhelper.GuiCustomConfirmOpenLink; | ||
|
||
/** | ||
* Adds Nomi-CEu & Nomi-Labs Translation Pack 'Advertisements' to Language Selection Screen. | ||
*/ | ||
@Mixin(GuiLanguage.class) | ||
public abstract class GuiLanguageMixin extends GuiScreen implements AccessibleGuiLanguage { | ||
|
||
@Unique | ||
private static final int DOWNLOAD_PACK_BTN_ID = 10; | ||
|
||
@Unique | ||
private static final int SHOW_GH_BTN_ID = 11; | ||
|
||
@Unique | ||
private static final String TRANSLATIONS_GH = "https://github.com/Nomi-CEu/Nomi-CEu-Translations"; | ||
|
||
@Unique | ||
private static final String TRANSLATIONS_DOWNLOAD = "https://nightly.link/Nomi-CEu/Nomi-CEu-Translations/workflows/pushbuildpack/main?preview"; | ||
|
||
@Unique | ||
private String downloadPackNote; | ||
|
||
@Unique | ||
private String previousLangCode; | ||
|
||
@Shadow | ||
private GuiOptionButton forceUnicodeFontBtn; | ||
|
||
@Shadow | ||
private GuiOptionButton confirmSettingsBtn; | ||
|
||
@Shadow | ||
@Final | ||
private GameSettings game_settings_3; | ||
|
||
@Shadow | ||
@Final | ||
private LanguageManager languageManager; | ||
|
||
@Inject(method = "<init>", at = @At("TAIL")) | ||
public void savePreviousLang(GuiScreen screen, GameSettings gameSettingsObj, LanguageManager manager, | ||
CallbackInfo ci) { | ||
previousLangCode = manager.getCurrentLanguage().getLanguageCode(); | ||
} | ||
|
||
@Inject(method = "initGui", at = @At("TAIL")) | ||
public void moveAndAddElements(CallbackInfo ci) { | ||
if (LabsConfig.advanced.languageModifyOption == LabsConfig.Advanced.LanguageModifyOption.NONE) return; | ||
forceUnicodeFontBtn.y = height - 28; | ||
confirmSettingsBtn.y = height - 28; | ||
confirmSettingsBtn.displayString = I18n.format("nomilabs.gui.language.exit"); | ||
addButton(new GuiOptionButton(DOWNLOAD_PACK_BTN_ID, width / 2 - 155 + 160, height - 56, | ||
I18n.format("nomilabs.gui.language.download"))); | ||
addButton(new GuiOptionButton(SHOW_GH_BTN_ID, width / 2 - 155, height - 56, | ||
I18n.format("nomilabs.gui.language.gh"))); | ||
downloadPackNote = LabsConfig.advanced.languageModifyOption == LabsConfig.Advanced.LanguageModifyOption.LABS ? | ||
I18n.format("nomilabs.gui.language.download.note.labs") : | ||
I18n.format("nomilabs.gui.language.download.note.nomi"); | ||
} | ||
|
||
@Inject(method = "drawScreen", | ||
at = @At(value = "INVOKE", | ||
target = "Lnet/minecraft/client/gui/GuiLanguage$List;drawScreen(IIF)V", | ||
shift = At.Shift.AFTER), | ||
cancellable = true) | ||
public void drawNewLanguageScreen(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { | ||
if (LabsConfig.advanced.languageModifyOption == LabsConfig.Advanced.LanguageModifyOption.NONE) return; | ||
drawCenteredString(fontRenderer, TextFormatting.BOLD + I18n.format("options.language"), width / 2, 10, | ||
0xffffff); | ||
drawCenteredString(fontRenderer, | ||
I18n.format(LabsConfig.advanced.languageModifyOption == LabsConfig.Advanced.LanguageModifyOption.LABS ? | ||
"gui.nomilabs.language_pack_labs" : "gui.nomilabs.language_pack_nomi"), | ||
width / 2, 10 + (int) (fontRenderer.FONT_HEIGHT * 2.5), 0xffffff); | ||
drawCenteredString(fontRenderer, "(" + I18n.format("options.languageWarning") + ")", width / 2, | ||
10 + fontRenderer.FONT_HEIGHT * 4, 0x808080); | ||
super.drawScreen(mouseX, mouseY, partialTicks); | ||
ci.cancel(); | ||
} | ||
|
||
@Inject(method = "actionPerformed", at = @At("HEAD"), cancellable = true) | ||
public void handleCustomActions(GuiButton button, CallbackInfo ci) { | ||
if (LabsConfig.advanced.languageModifyOption == LabsConfig.Advanced.LanguageModifyOption.NONE) return; | ||
switch (button.id) { | ||
case 6: // Done Button | ||
var language = languageManager.getCurrentLanguage(); | ||
var code = language.getLanguageCode(); | ||
if (code.equals(previousLangCode)) break; | ||
|
||
game_settings_3.language = code; | ||
FMLClientHandler.instance().refreshResources(VanillaResourceType.LANGUAGES); | ||
fontRenderer | ||
.setUnicodeFlag(languageManager.isCurrentLocaleUnicode() || game_settings_3.forceUnicodeFont); | ||
fontRenderer.setBidiFlag(languageManager.isCurrentLanguageBidirectional()); | ||
game_settings_3.saveOptions(); | ||
break; | ||
case DOWNLOAD_PACK_BTN_ID: | ||
mc.displayGuiScreen(new GuiCustomConfirmOpenLink(this, TRANSLATIONS_DOWNLOAD, downloadPackNote, | ||
DOWNLOAD_PACK_BTN_ID)); | ||
ci.cancel(); | ||
break; | ||
case SHOW_GH_BTN_ID: | ||
mc.displayGuiScreen(new GuiCustomConfirmOpenLink(this, TRANSLATIONS_GH, null, SHOW_GH_BTN_ID)); | ||
ci.cancel(); | ||
break; | ||
} | ||
} | ||
|
||
@Override | ||
public LanguageManager getLanguageManager() { | ||
return languageManager; | ||
} | ||
|
||
@Override | ||
public void confirmClicked(boolean result, int id) { | ||
if (LabsConfig.advanced.languageModifyOption == LabsConfig.Advanced.LanguageModifyOption.NONE) return; | ||
String url = switch (id) { | ||
case DOWNLOAD_PACK_BTN_ID -> TRANSLATIONS_DOWNLOAD; | ||
case SHOW_GH_BTN_ID -> TRANSLATIONS_GH; | ||
default -> ""; | ||
}; | ||
|
||
if (result) { | ||
try { | ||
Class<?> desktopClass = Class.forName("java.awt.Desktop"); | ||
Object desktopObj = desktopClass.getMethod("getDesktop").invoke((Object) null); | ||
desktopClass.getMethod("browse", URI.class).invoke(desktopObj, new URI(url)); | ||
} catch (URISyntaxException | ClassNotFoundException | InvocationTargetException | IllegalAccessException | | ||
NoSuchMethodException e) { | ||
NomiLabs.LOGGER.error("Failed to Open Link!"); | ||
NomiLabs.LOGGER.throwing(e); | ||
} | ||
} | ||
this.mc.displayGuiScreen(this); | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
src/main/java/com/nomiceu/nomilabs/mixinhelper/AccessibleGuiLanguage.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,8 @@ | ||
package com.nomiceu.nomilabs.mixinhelper; | ||
|
||
import net.minecraft.client.resources.LanguageManager; | ||
|
||
public interface AccessibleGuiLanguage { | ||
|
||
LanguageManager getLanguageManager(); | ||
} |
95 changes: 95 additions & 0 deletions
95
src/main/java/com/nomiceu/nomilabs/mixinhelper/GuiCustomConfirmOpenLink.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,95 @@ | ||
package com.nomiceu.nomilabs.mixinhelper; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import net.minecraft.client.gui.GuiButton; | ||
import net.minecraft.client.gui.GuiScreen; | ||
import net.minecraft.client.gui.GuiYesNoCallback; | ||
import net.minecraft.client.resources.I18n; | ||
import net.minecraft.util.text.TextFormatting; | ||
import net.minecraftforge.fml.relauncher.Side; | ||
import net.minecraftforge.fml.relauncher.SideOnly; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
@SideOnly(Side.CLIENT) | ||
public class GuiCustomConfirmOpenLink extends GuiScreen { | ||
|
||
private final String titleText; | ||
|
||
private final String confirmButtonText; | ||
private final String cancelButtonText; | ||
private final String copyLinkButtonText; | ||
|
||
private final String linkText; | ||
|
||
private final boolean hasNoteText; | ||
private final String noteText; | ||
|
||
private final List<String> listLines; | ||
|
||
private final GuiYesNoCallback parentScreen; | ||
private final int parentButtonClickedId; | ||
|
||
private static final int CONFIRM_ID = 0; | ||
private static final int COPY_ID = 2; | ||
private static final int CANCEL_ID = 1; | ||
|
||
public GuiCustomConfirmOpenLink(GuiYesNoCallback parentScreen, String linkText, @Nullable String noteText, | ||
int parentButtonClickedId) { | ||
this.parentScreen = parentScreen; | ||
this.parentButtonClickedId = parentButtonClickedId; | ||
|
||
this.titleText = TextFormatting.BOLD + I18n.format("chat.link.confirmTrusted"); | ||
|
||
this.confirmButtonText = I18n.format("chat.link.open"); | ||
this.cancelButtonText = I18n.format("gui.cancel"); | ||
this.copyLinkButtonText = I18n.format("chat.copy"); | ||
|
||
this.noteText = noteText; | ||
this.hasNoteText = this.noteText != null; | ||
|
||
this.linkText = linkText; | ||
this.listLines = new ArrayList<>(); | ||
} | ||
|
||
public void initGui() { | ||
super.initGui(); | ||
buttonList.clear(); | ||
makeButton(CONFIRM_ID, -105, confirmButtonText); | ||
makeButton(COPY_ID, 0, copyLinkButtonText); | ||
makeButton(CANCEL_ID, 105, cancelButtonText); | ||
listLines.clear(); | ||
listLines.addAll(fontRenderer.listFormattedStringToWidth(TextFormatting.AQUA + linkText + TextFormatting.RESET, | ||
this.width - 50)); | ||
} | ||
|
||
private void makeButton(int id, int xOffset, String displayText) { | ||
buttonList.add(new GuiButton(id, width / 2 - 50 + xOffset, height / 6 + 96, 100, 20, displayText)); | ||
} | ||
|
||
protected void actionPerformed(GuiButton button) throws IOException { | ||
if (button.id == 2) | ||
setClipboardString(linkText); | ||
|
||
parentScreen.confirmClicked(button.id == 0, parentButtonClickedId); | ||
} | ||
|
||
public void drawScreen(int mouseX, int mouseY, float partialTicks) { | ||
drawDefaultBackground(); | ||
|
||
drawCenteredString(fontRenderer, titleText, width / 2, 70 - (hasNoteText ? 20 : 0), 0xffffff); | ||
if (hasNoteText) | ||
drawCenteredString(fontRenderer, noteText, width / 2, 70, 0xffffff); | ||
|
||
int i = 90; | ||
for (String s : listLines) { | ||
drawCenteredString(fontRenderer, s, width / 2, i, 0xffffff); | ||
i += fontRenderer.FONT_HEIGHT; | ||
} | ||
|
||
super.drawScreen(mouseX, mouseY, partialTicks); | ||
} | ||
} |
Oops, something went wrong.