Skip to content

Commit

Permalink
Localization update
Browse files Browse the repository at this point in the history
  • Loading branch information
xTracr committed May 3, 2024
1 parent a56182a commit 590c69a
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 89 deletions.
7 changes: 3 additions & 4 deletions common/src/main/java/com/xtracr/realcamera/KeyBindings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.xtracr.realcamera.config.ConfigFile;
import com.xtracr.realcamera.gui.ModelViewScreen;
import com.xtracr.realcamera.util.LocUtil;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import org.lwjgl.glfw.GLFW;
Expand All @@ -11,12 +12,10 @@
import java.util.function.Consumer;

public final class KeyBindings {
private static final String KEY_CATEGORY = "key.category." + RealCamera.FULL_ID;
private static final String KEY_ID = "key." + RealCamera.FULL_ID + ".";
private static final Map<KeyBinding, Consumer<MinecraftClient>> KEY_BINDINGS = new HashMap<>();

static {
createKeyBinding("modelViewGui", client -> client.setScreen(new ModelViewScreen()));
createKeyBinding("modelViewScreen", client -> client.setScreen(new ModelViewScreen()));
createKeyBinding("togglePerspective", GLFW.GLFW_KEY_F6, client -> {
boolean enabled = ConfigFile.config().enabled();
ConfigFile.load();
Expand All @@ -38,7 +37,7 @@ private static void createKeyBinding(String id, Consumer<MinecraftClient> whenPr
}

private static void createKeyBinding(String id, int code, Consumer<MinecraftClient> whenPressed) {
KEY_BINDINGS.put(new KeyBinding(KEY_ID + id, code, KEY_CATEGORY), whenPressed);
KEY_BINDINGS.put(new KeyBinding("key." + RealCamera.FULL_ID + "." + id, code, LocUtil.KEY_MOD_NAME), whenPressed);
}

public static void register(Consumer<KeyBinding> registerer) {
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/com/xtracr/realcamera/RealCamera.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class RealCamera {
public static final Logger LOGGER = LoggerFactory.getLogger(MODID);

public static void initialize() {
ConfigFile.load();
CompatibilityHelper.initialize();
DisableHelper.initialize();
ConfigFile.load();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.xtracr.realcamera.compat.DisableHelper;
import com.xtracr.realcamera.config.BindingTarget;
import com.xtracr.realcamera.config.ConfigFile;
import com.xtracr.realcamera.util.LocUtil;
import com.xtracr.realcamera.util.MathUtil;
import com.xtracr.realcamera.util.VertexRecorder;
import net.minecraft.client.MinecraftClient;
Expand All @@ -11,7 +12,6 @@
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.text.Text;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Vec3d;
Expand Down Expand Up @@ -123,7 +123,7 @@ public static void computeCamera() {
}
if (currentTarget.isEmpty()) {
Entity player = MinecraftClient.getInstance().player;
if (readyToSendMessage && player != null) player.sendMessage(Text.translatable("message." + RealCamera.FULL_ID + ".bindingFailed"));
if (readyToSendMessage && player != null) player.sendMessage(LocUtil.MESSAGE("bindingFailed", LocUtil.MOD_NAME(), LocUtil.MODEL_VIEW_TITLE()));
active = readyToSendMessage = false;
} else readyToSendMessage = true;
normal.rotateLocal((float) Math.toRadians(currentTarget.yaw()), normal.m10, normal.m11, normal.m12);
Expand Down
84 changes: 39 additions & 45 deletions common/src/main/java/com/xtracr/realcamera/config/ConfigScreen.java
Original file line number Diff line number Diff line change
@@ -1,148 +1,142 @@
package com.xtracr.realcamera.config;

import com.xtracr.realcamera.RealCamera;
import com.xtracr.realcamera.util.LocUtil;
import me.shedaniel.clothconfig2.api.ConfigBuilder;
import me.shedaniel.clothconfig2.api.ConfigCategory;
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
import me.shedaniel.clothconfig2.impl.builders.SubCategoryBuilder;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

public class ConfigScreen {
private static final String CATEGORY = "config.category." + RealCamera.FULL_ID + ".";
private static final String OPTION = "config.option." + RealCamera.FULL_ID + ".";
private static final String TOOLTIP = "config.tooltip." + RealCamera.FULL_ID + ".";

public static Screen create(Screen parent) {
ConfigFile.load();
final ModConfig config = ConfigFile.config();
final ConfigBuilder builder = ConfigBuilder.create()
.setParentScreen(parent)
.transparentBackground()
.setSavingRunnable(ConfigFile::save)
.setTitle(Text.translatable("config.title." + RealCamera.FULL_ID));
.setTitle(LocUtil.MOD_NAME());
ConfigEntryBuilder entryBuilder = builder.entryBuilder();
ConfigCategory general = builder.getOrCreateCategory(Text.translatable(CATEGORY + "general"));
ConfigCategory classic = builder.getOrCreateCategory(Text.translatable(CATEGORY + "classic"));
ConfigCategory binding = builder.getOrCreateCategory(Text.translatable(CATEGORY + "binding"));
ConfigCategory general = builder.getOrCreateCategory(LocUtil.CONFIG_CATEGORY("general"));
ConfigCategory classic = builder.getOrCreateCategory(LocUtil.CONFIG_CATEGORY("classic"));
ConfigCategory binding = builder.getOrCreateCategory(LocUtil.CONFIG_CATEGORY("binding"));

general.addEntry(entryBuilder.startBooleanToggle(Text.translatable(OPTION + "enabled"), config.enabled)
general.addEntry(entryBuilder.startBooleanToggle(LocUtil.CONFIG_OPTION("enabled"), config.enabled)
.setSaveConsumer(b -> config.enabled = b)
.build());
general.addEntry(entryBuilder.startBooleanToggle(Text.translatable(OPTION + "isClassic"), config.isClassic)
general.addEntry(entryBuilder.startBooleanToggle(LocUtil.CONFIG_OPTION("isClassic"), config.isClassic)
.setDefaultValue(false)
.setTooltip(Text.translatable(TOOLTIP + "isClassic"))
.setTooltip(LocUtil.CONFIG_TOOLTIP("isClassic"))
.setSaveConsumer(b -> config.isClassic = b)
.build());
general.addEntry(entryBuilder.startBooleanToggle(Text.translatable(OPTION + "dynamicCrosshair"), config.dynamicCrosshair)
general.addEntry(entryBuilder.startBooleanToggle(LocUtil.CONFIG_OPTION("dynamicCrosshair"), config.dynamicCrosshair)
.setDefaultValue(false)
.setTooltip(Text.translatable(TOOLTIP + "dynamicCrosshair"))
.setTooltip(LocUtil.CONFIG_TOOLTIP("dynamicCrosshair"))
.setSaveConsumer(b -> config.dynamicCrosshair = b)
.build());
general.addEntry(entryBuilder.startBooleanToggle(Text.translatable(OPTION + "renderModel"), config.renderModel)
general.addEntry(entryBuilder.startBooleanToggle(LocUtil.CONFIG_OPTION("renderModel"), config.renderModel)
.setDefaultValue(true)
.setTooltip(Text.translatable(TOOLTIP + "renderModel"))
.setTooltip(LocUtil.CONFIG_TOOLTIP("renderModel"))
.setSaveConsumer(b -> config.renderModel = b)
.build());
general.addEntry(entryBuilder.startDoubleField(Text.translatable(OPTION + "adjustStep"), config.adjustStep)
general.addEntry(entryBuilder.startDoubleField(LocUtil.CONFIG_OPTION("adjustStep"), config.adjustStep)
.setDefaultValue(0.01)
.setMin(0.0)
.setMax(ModConfig.MAX_DOUBLE)
.setTooltip(Text.translatable(TOOLTIP + "adjustStep"))
.setTooltip(LocUtil.CONFIG_TOOLTIP("adjustStep"))
.setSaveConsumer(d -> config.adjustStep = d)
.build());

classic.addEntry(entryBuilder.startEnumSelector(Text.translatable(OPTION + "classicAdjustMode"), ModConfig.Classic.AdjustMode.class, config.classic.adjustMode)
classic.addEntry(entryBuilder.startEnumSelector(LocUtil.CONFIG_OPTION("classicAdjustMode"), ModConfig.Classic.AdjustMode.class, config.classic.adjustMode)
.setDefaultValue(ModConfig.Classic.AdjustMode.CAMERA)
.setTooltip(Text.translatable(TOOLTIP + "classicAdjustMode"))
.setTooltip(LocUtil.CONFIG_TOOLTIP("classicAdjustMode"))
.setSaveConsumer(e -> config.classic.adjustMode = e)
.build());
classic.addEntry(entryBuilder.startDoubleField(Text.translatable(OPTION + "scale"), config.classic.scale)
classic.addEntry(entryBuilder.startDoubleField(LocUtil.CONFIG_OPTION("scale"), config.classic.scale)
.setDefaultValue(8.0)
.setMin(0.0)
.setMax(64.0)
.setTooltip(Text.translatable(TOOLTIP + "scale"))
.setTooltip(LocUtil.CONFIG_TOOLTIP("scale"))
.setSaveConsumer(d -> config.classic.scale = d)
.build());
SubCategoryBuilder classicCameraOffset = entryBuilder.startSubCategory(Text.translatable(CATEGORY + "cameraOffset"))
.setTooltip(Text.translatable(TOOLTIP + "classicOffset"), Text.translatable(TOOLTIP + "classicOffset_n"));
classicCameraOffset.add(entryBuilder.startDoubleField(Text.translatable(OPTION + "cameraOffset", "X"), config.classic.cameraX)
SubCategoryBuilder classicCameraOffset = entryBuilder.startSubCategory(LocUtil.CONFIG_CATEGORY("cameraOffset"))
.setTooltip(LocUtil.CONFIG_TOOLTIP("classicOffset"), LocUtil.CONFIG_TOOLTIP("classicOffset_n"));
classicCameraOffset.add(entryBuilder.startDoubleField(LocUtil.CONFIG_OPTION("cameraOffset", "X"), config.classic.cameraX)
.setDefaultValue(-0.5)
.setMin(ModConfig.MIN_DOUBLE)
.setMax(ModConfig.MAX_DOUBLE)
.setSaveConsumer(d -> config.classic.cameraX = d)
.build());
classicCameraOffset.add(entryBuilder.startDoubleField(Text.translatable(OPTION + "cameraOffset", "Y"), config.classic.cameraY)
classicCameraOffset.add(entryBuilder.startDoubleField(LocUtil.CONFIG_OPTION("cameraOffset", "Y"), config.classic.cameraY)
.setDefaultValue(0.04)
.setMin(ModConfig.MIN_DOUBLE)
.setMax(ModConfig.MAX_DOUBLE)
.setSaveConsumer(d -> config.classic.cameraY = d)
.build());
classicCameraOffset.add(entryBuilder.startDoubleField(Text.translatable(OPTION + "cameraOffset", "Z"), config.classic.cameraZ)
classicCameraOffset.add(entryBuilder.startDoubleField(LocUtil.CONFIG_OPTION("cameraOffset", "Z"), config.classic.cameraZ)
.setDefaultValue(-0.15)
.setMin(ModConfig.MIN_DOUBLE)
.setMax(ModConfig.MAX_DOUBLE)
.setSaveConsumer(d -> config.classic.cameraZ = d)
.build());
classic.addEntry(classicCameraOffset.build());
SubCategoryBuilder classicCenterOffset = entryBuilder.startSubCategory(Text.translatable(CATEGORY + "centerOffset"))
.setTooltip(Text.translatable(TOOLTIP + "centerOffset"));
classicCenterOffset.add(entryBuilder.startDoubleField(Text.translatable(OPTION + "centerOffset", "X"), config.classic.centerX)
SubCategoryBuilder classicCenterOffset = entryBuilder.startSubCategory(LocUtil.CONFIG_CATEGORY("centerOffset")).setTooltip(LocUtil.CONFIG_TOOLTIP("centerOffset"));
classicCenterOffset.add(entryBuilder.startDoubleField(LocUtil.CONFIG_OPTION("centerOffset", "X"), config.classic.centerX)
.setDefaultValue(0.0)
.setMin(ModConfig.MIN_DOUBLE)
.setMax(ModConfig.MAX_DOUBLE)
.setSaveConsumer(d -> config.classic.centerX = d)
.build());
classicCenterOffset.add(entryBuilder.startDoubleField(Text.translatable(OPTION + "centerOffset", "Y"), config.classic.centerY)
classicCenterOffset.add(entryBuilder.startDoubleField(LocUtil.CONFIG_OPTION("centerOffset", "Y"), config.classic.centerY)
.setDefaultValue(0.0)
.setMin(ModConfig.MIN_DOUBLE)
.setMax(ModConfig.MAX_DOUBLE)
.setSaveConsumer(d -> config.classic.centerY = d)
.build());
classicCenterOffset.add(entryBuilder.startDoubleField(Text.translatable(OPTION + "centerOffset", "Z"), config.classic.centerZ)
classicCenterOffset.add(entryBuilder.startDoubleField(LocUtil.CONFIG_OPTION("centerOffset", "Z"), config.classic.centerZ)
.setDefaultValue(0.0)
.setMin(ModConfig.MIN_DOUBLE)
.setMax(ModConfig.MAX_DOUBLE)
.setSaveConsumer(d -> config.classic.centerZ = d)
.build());
classic.addEntry(classicCenterOffset.build());
SubCategoryBuilder classicCameraRotation = entryBuilder.startSubCategory(Text.translatable(CATEGORY + "cameraRotation"))
.setTooltip(Text.translatable(TOOLTIP + "cameraRotation"), Text.translatable(TOOLTIP + "cameraRotation_n"));
classicCameraRotation.add(entryBuilder.startFloatField(Text.translatable(OPTION + "pitch"), config.classic.pitch)
SubCategoryBuilder classicCameraRotation = entryBuilder.startSubCategory(LocUtil.CONFIG_CATEGORY("cameraRotation"))
.setTooltip(LocUtil.CONFIG_TOOLTIP("cameraRotation"), LocUtil.CONFIG_TOOLTIP("cameraRotation_n"));
classicCameraRotation.add(entryBuilder.startFloatField(LocUtil.CONFIG_OPTION("pitch"), config.classic.pitch)
.setDefaultValue(0.0f)
.setMin(-180.0f)
.setMax(180.0f)
.setSaveConsumer(f -> config.classic.pitch = f)
.build());
classicCameraRotation.add(entryBuilder.startFloatField(Text.translatable(OPTION + "yaw"), config.classic.yaw)
classicCameraRotation.add(entryBuilder.startFloatField(LocUtil.CONFIG_OPTION("yaw"), config.classic.yaw)
.setDefaultValue(18.0f)
.setMin(-180.0f)
.setMax(180.0f)
.setSaveConsumer(f -> config.classic.yaw = f)
.build());
classicCameraRotation.add(entryBuilder.startFloatField(Text.translatable(OPTION + "roll"), config.classic.roll)
classicCameraRotation.add(entryBuilder.startFloatField(LocUtil.CONFIG_OPTION("roll"), config.classic.roll)
.setDefaultValue(0.0f)
.setMin(-180.0f)
.setMax(180.0f)
.setSaveConsumer(f -> config.classic.roll = f)
.build());
classic.addEntry(classicCameraRotation.build());

binding.addEntry(entryBuilder.startTextDescription(Text.translatable(OPTION + "toModelViewGui",
Text.translatable("screen." + RealCamera.FULL_ID + ".modelView_title").styled(s -> s.withColor(Formatting.BLUE))))
binding.addEntry(entryBuilder.startTextDescription(LocUtil.CONFIG_OPTION("toModelViewScreen",
LocUtil.MODEL_VIEW_TITLE().styled(s -> s.withColor(Formatting.BLUE))))
.build());
binding.addEntry(entryBuilder.startBooleanToggle(Text.translatable(OPTION + "adjustOffset"), config.binding.adjustOffset)
binding.addEntry(entryBuilder.startBooleanToggle(LocUtil.CONFIG_OPTION("adjustOffset"), config.binding.adjustOffset)
.setDefaultValue(true)
.setTooltip(Text.translatable(TOOLTIP + "adjustOffset"))
.setTooltip(LocUtil.CONFIG_TOOLTIP("adjustOffset"))
.setSaveConsumer(b -> config.binding.adjustOffset = b)
.build());
binding.addEntry(entryBuilder.startBooleanToggle(Text.translatable(OPTION + "renderStuckObjects"), config.renderModel)
binding.addEntry(entryBuilder.startBooleanToggle(LocUtil.CONFIG_OPTION("renderStuckObjects"), config.renderModel)
.setDefaultValue(true)
.setTooltip(Text.translatable(TOOLTIP + "renderStuckObjects"))
.setTooltip(LocUtil.CONFIG_TOOLTIP("renderStuckObjects"))
.setSaveConsumer(b -> config.renderModel = b)
.build());
binding.addEntry(entryBuilder.startStrList(Text.translatable(OPTION + "disableRenderItems"), config.binding.disableRenderItems)
binding.addEntry(entryBuilder.startStrList(LocUtil.CONFIG_OPTION("disableRenderItems"), config.binding.disableRenderItems)
.setDefaultValue(ModConfig.Binding.defaultDisableRenderItems)
.setSaveConsumer(l -> config.binding.disableRenderItems = l)
.build());
Expand Down
Loading

0 comments on commit 590c69a

Please sign in to comment.