Very hacky progress view
This commit is contained in:
parent
cecdd1c611
commit
7cd7ee0298
@ -12,10 +12,16 @@ public class Cfg implements ConfigData {
|
||||
public boolean breakFully = false;
|
||||
@Comment("The API key for Yandex Translate (this is REQUIRED for updating the cache, since Yandex doesn't give them out for free anymore you might want to google \"trnsl.1.1.\" to find keys on the web)")
|
||||
public String key = "trnsl.1.1.20130811T164454Z.2facd8a3323b8111.e9f682063308aff12357de3c8a3260d6d6b71be7";
|
||||
@Comment("Enable this to get more information about what is happening currently - useful when caching takes long")
|
||||
public boolean verboseLogging = false;
|
||||
@Comment("The language to translate to - Leave empty for auto-detection (might break text even more)")
|
||||
public String targetLanguage = "en";
|
||||
@Comment("Significantly slows down the loading time but gives a visual of the progress. Values: Full, Console, None")
|
||||
public progressMode renderProgress = progressMode.None;
|
||||
@Comment("Use this if something is broken. This initiate the regeneration of the cache")
|
||||
public boolean forceRegenerate = false;
|
||||
|
||||
public enum progressMode {
|
||||
Full,
|
||||
Console,
|
||||
None
|
||||
}
|
||||
}
|
||||
|
5
src/main/java/io/gitlab/jfronny/translater/IMClient.java
Normal file
5
src/main/java/io/gitlab/jfronny/translater/IMClient.java
Normal file
@ -0,0 +1,5 @@
|
||||
package io.gitlab.jfronny.translater;
|
||||
|
||||
public interface IMClient {
|
||||
void runRender(boolean tick);
|
||||
}
|
@ -35,4 +35,5 @@ public class ModInit implements ModInitializer {
|
||||
Log("Loaded translater");
|
||||
}
|
||||
|
||||
public static TransformingMap map = null;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.gitlab.jfronny.translater;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -7,19 +9,30 @@ import java.util.Set;
|
||||
public class TransformingMap implements Map<String, String> {
|
||||
private final Map<String, String> backer;
|
||||
private final StringTransformer transformer;
|
||||
public boolean initializing;
|
||||
public int initI;
|
||||
public int initMax;
|
||||
|
||||
public TransformingMap(Map<String, String> m, StringTransformer t) {
|
||||
backer = m;
|
||||
transformer = t;
|
||||
Collection<String> strings = m.values();
|
||||
int i = 0;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
Collection<String> strings = backer.values();
|
||||
initI = 0;
|
||||
initMax = strings.size();
|
||||
initializing = true;
|
||||
for (String value : strings) {
|
||||
if (ModInit.cfg.verboseLogging) {
|
||||
i++;
|
||||
ModInit.Log("Transforming " + i + "/" + strings.size());
|
||||
if (ModInit.cfg.renderProgress == Cfg.progressMode.Console || ModInit.cfg.renderProgress == Cfg.progressMode.Full) {
|
||||
initI++;
|
||||
ModInit.Log("Transforming " + initI + "/" + initMax);
|
||||
}
|
||||
transformer.transform(value);
|
||||
if (ModInit.cfg.renderProgress == Cfg.progressMode.Full && initI % 10 == 0)
|
||||
((IMClient)MinecraftClient.getInstance()).runRender(false);
|
||||
}
|
||||
initializing = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -87,7 +87,7 @@ public class YnTransformer extends CachingTransformer {
|
||||
currentLang = newLang;
|
||||
}
|
||||
currentState = api.translationApi().translate(currentState, startLang).text();
|
||||
if (ModInit.cfg.verboseLogging)
|
||||
if (ModInit.cfg.renderProgress == Cfg.progressMode.Console || ModInit.cfg.renderProgress == Cfg.progressMode.Full)
|
||||
ModInit.Log("Transformed: \"" + str + "\" to: \"" + currentState + "\"");
|
||||
return currentState;
|
||||
} catch (Exception e) {
|
||||
|
@ -37,7 +37,9 @@ public class MixinLanguage {
|
||||
}
|
||||
if (language instanceof TranslationStorage) {
|
||||
try {
|
||||
FIELD.set(language, new TransformingMap((Map<String, String>) FIELD.get(language), transformer));
|
||||
ModInit.map = new TransformingMap((Map<String, String>) FIELD.get(language), transformer);
|
||||
ModInit.map.init();
|
||||
FIELD.set(language, ModInit.map);
|
||||
} catch (IllegalAccessException | ClassCastException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
package io.gitlab.jfronny.translater.mixin;
|
||||
|
||||
import io.gitlab.jfronny.translater.IMClient;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@Mixin(MinecraftClient.class)
|
||||
public class MixinMinecraftClient implements IMClient {
|
||||
@Override
|
||||
public void runRender(boolean tick) {
|
||||
render(tick);
|
||||
}
|
||||
|
||||
@Shadow
|
||||
private void render(boolean tick) {}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package io.gitlab.jfronny.translater.mixin;
|
||||
|
||||
import com.google.gson.JsonParser;
|
||||
import io.gitlab.jfronny.translater.Cfg;
|
||||
import io.gitlab.jfronny.translater.ModInit;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.FontStorage;
|
||||
import net.minecraft.client.font.FontType;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.screen.Overlay;
|
||||
import net.minecraft.client.gui.screen.SplashScreen;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
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.awt.*;
|
||||
import java.util.Collections;
|
||||
|
||||
@Mixin(SplashScreen.class)
|
||||
public abstract class MixinSplashScreen extends Overlay {
|
||||
@Shadow @Final
|
||||
private MinecraftClient client;
|
||||
|
||||
@Shadow public abstract void render(MatrixStack matrices, int mouseX, int mouseY, float delta);
|
||||
|
||||
@Inject(at = @At("RETURN"), method = "renderProgressBar")
|
||||
private void RenderTrnslProgress(MatrixStack matrixStack, int i, int j, int k, int l, float f, CallbackInfo ci) {
|
||||
if (ModInit.cfg.renderProgress == Cfg.progressMode.Full && ModInit.map != null && ModInit.map.initializing) {
|
||||
int n = Math.round(f * 255.0F);
|
||||
renderer.draw(matrixStack, "Transforming " + ModInit.map.initI + "/" + ModInit.map.initMax, 10, 10, colorString("0,0,0") & 16777215 | n);
|
||||
}
|
||||
}
|
||||
|
||||
private TextRenderer renderer;
|
||||
|
||||
private static final String FONT_JSON = //Taken from loadingspice (https://github.com/therealfarfetchd/loadingspice)
|
||||
"{\n" +
|
||||
" \"type\": \"bitmap\",\n" +
|
||||
" \"file\": \"minecraft:font/ascii.png\",\n" +
|
||||
" \"ascent\": 7,\n" +
|
||||
" \"chars\": [\n" +
|
||||
" \"\\u00c0\\u00c1\\u00c2\\u00c8\\u00ca\\u00cb\\u00cd\\u00d3\\u00d4\\u00d5\\u00da\\u00df\\u00e3\\u00f5\\u011f\\u0130\",\n" +
|
||||
" \"\\u0131\\u0152\\u0153\\u015e\\u015f\\u0174\\u0175\\u017e\\u0207\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\",\n" +
|
||||
" \"\\u0020\\u0021\\\"\\u0023\\u0024\\u0025\\u0026\\u0027\\u0028\\u0029\\u002a\\u002b\\u002c\\u002d\\u002e\\u002f\",\n" +
|
||||
" \"\\u0030\\u0031\\u0032\\u0033\\u0034\\u0035\\u0036\\u0037\\u0038\\u0039\\u003a\\u003b\\u003c\\u003d\\u003e\\u003f\",\n" +
|
||||
" \"\\u0040\\u0041\\u0042\\u0043\\u0044\\u0045\\u0046\\u0047\\u0048\\u0049\\u004a\\u004b\\u004c\\u004d\\u004e\\u004f\",\n" +
|
||||
" \"\\u0050\\u0051\\u0052\\u0053\\u0054\\u0055\\u0056\\u0057\\u0058\\u0059\\u005a\\u005b\\\\\\u005d\\u005e\\u005f\",\n" +
|
||||
" \"\\u0060\\u0061\\u0062\\u0063\\u0064\\u0065\\u0066\\u0067\\u0068\\u0069\\u006a\\u006b\\u006c\\u006d\\u006e\\u006f\",\n" +
|
||||
" \"\\u0070\\u0071\\u0072\\u0073\\u0074\\u0075\\u0076\\u0077\\u0078\\u0079\\u007a\\u007b\\u007c\\u007d\\u007e\\u0000\",\n" +
|
||||
" \"\\u00c7\\u00fc\\u00e9\\u00e2\\u00e4\\u00e0\\u00e5\\u00e7\\u00ea\\u00eb\\u00e8\\u00ef\\u00ee\\u00ec\\u00c4\\u00c5\",\n" +
|
||||
" \"\\u00c9\\u00e6\\u00c6\\u00f4\\u00f6\\u00f2\\u00fb\\u00f9\\u00ff\\u00d6\\u00dc\\u00f8\\u00a3\\u00d8\\u00d7\\u0192\",\n" +
|
||||
" \"\\u00e1\\u00ed\\u00f3\\u00fa\\u00f1\\u00d1\\u00aa\\u00ba\\u00bf\\u00ae\\u00ac\\u00bd\\u00bc\\u00a1\\u00ab\\u00bb\",\n" +
|
||||
" \"\\u2591\\u2592\\u2593\\u2502\\u2524\\u2561\\u2562\\u2556\\u2555\\u2563\\u2551\\u2557\\u255d\\u255c\\u255b\\u2510\",\n" +
|
||||
" \"\\u2514\\u2534\\u252c\\u251c\\u2500\\u253c\\u255e\\u255f\\u255a\\u2554\\u2569\\u2566\\u2560\\u2550\\u256c\\u2567\",\n" +
|
||||
" \"\\u2568\\u2564\\u2565\\u2559\\u2558\\u2552\\u2553\\u256b\\u256a\\u2518\\u250c\\u2588\\u2584\\u258c\\u2590\\u2580\",\n" +
|
||||
" \"\\u03b1\\u03b2\\u0393\\u03c0\\u03a3\\u03c3\\u03bc\\u03c4\\u03a6\\u0398\\u03a9\\u03b4\\u221e\\u2205\\u2208\\u2229\",\n" +
|
||||
" \"\\u2261\\u00b1\\u2265\\u2264\\u2320\\u2321\\u00f7\\u2248\\u00b0\\u2219\\u00b7\\u221a\\u207f\\u00b2\\u25a0\\u0000\"\n" +
|
||||
" ]\n" +
|
||||
"}";
|
||||
|
||||
@Inject(method = "<init>", at = @At("RETURN"))
|
||||
public void setup(CallbackInfo ci) {
|
||||
final FontStorage fontStorage_1 = new FontStorage(client.getTextureManager(), new Identifier("loading"));
|
||||
fontStorage_1.setFonts(Collections.singletonList(FontType.BITMAP.createLoader(new JsonParser().parse(FONT_JSON).getAsJsonObject()).load(client.getResourceManager())));
|
||||
renderer = new TextRenderer(id -> fontStorage_1);
|
||||
}
|
||||
|
||||
private static int colorString(String color) {
|
||||
String[] rgb = color.split(",");
|
||||
if (rgb.length != 3) {
|
||||
throw new IllegalArgumentException(color + " is not a valid color string. Too many values - format is '255,255,255'");
|
||||
} else {
|
||||
int[] rgb2 = new int[3];
|
||||
for (int i = 0; i < rgb.length; i++) {
|
||||
rgb2[i] = Integer.valueOf(rgb[i]);
|
||||
}
|
||||
return new Color(rgb2[0], rgb2[1], rgb2[2]).getRGB();
|
||||
}
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
"text.autoconfig.TranslaterCF.option.rounds": "Rounds",
|
||||
"text.autoconfig.TranslaterCF.option.breakFully": "Break Fully",
|
||||
"text.autoconfig.TranslaterCF.option.key": "API Key",
|
||||
"text.autoconfig.TranslaterCF.option.verboseLogging": "Verbose Logging",
|
||||
"text.autoconfig.TranslaterCF.option.targetLanguage": "Target Language",
|
||||
"text.autoconfig.TranslaterCF.option.renderProgress": "Progress Renderer ",
|
||||
"text.autoconfig.TranslaterCF.option.forceRegenerate": "Force Regenerate"
|
||||
}
|
@ -4,7 +4,9 @@
|
||||
"package": "io.gitlab.jfronny.translater.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"client": [
|
||||
"MixinLanguage"
|
||||
"MixinLanguage",
|
||||
"MixinSplashScreen",
|
||||
"MixinMinecraftClient"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
Loading…
Reference in New Issue
Block a user