Skip to content

Commit

Permalink
It is done
Browse files Browse the repository at this point in the history
  • Loading branch information
EnnuiL committed Oct 2, 2023
1 parent 942886d commit 401a834
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
import net.minecraft.text.Text;

public class OkZoomerCommandScreen extends SpruceScreen {
private SpruceOptionListWidget list;
private final SimpleColorBackground darkenedBackground = new SimpleColorBackground(0, 0, 0, 128);
private static final SimpleColorBackground DARKENED_BACKGROUND = new SimpleColorBackground(0, 0, 0, 128);

public OkZoomerCommandScreen() {
super(Text.translatable("command.ok_zoomer.title"));
Expand All @@ -27,7 +26,8 @@ public OkZoomerCommandScreen() {
@Override
protected void init() {
super.init();
this.list = new SpruceOptionListWidget(Position.of(0, 22), this.width, this.height - 36 - 22);
var list = new SpruceOptionListWidget(Position.of(0, 22), this.width, this.height - 36 - 22);
list.setBackground(DARKENED_BACKGROUND);

var configButton = SpruceSimpleActionOption.of(
"command.ok_zoomer.config",
Expand All @@ -39,72 +39,62 @@ protected void init() {
true,
Text.translatable("command.ok_zoomer.restrictions.tooltip"));

this.list.addSingleOptionEntry(configButton);
this.list.addSingleOptionEntry(restrictionsSeparator);
list.addSingleOptionEntry(configButton);
list.addSingleOptionEntry(restrictionsSeparator);


if (ZoomPackets.getHasRestrictions()) {
var textLabel = new SpruceLabelOption("command.ok_zoomer.restrictions.acknowledgement", true);
this.list.addSingleOptionEntry(textLabel);
list.addSingleOptionEntry(new SpruceLabelOption("command.ok_zoomer.restrictions.acknowledgement", true));
}

if (ZoomPackets.getDisableZoom()) {
var textLabel = new SpruceLabelOption("command.ok_zoomer.restrictions.disable_zoom", true);
this.list.addSingleOptionEntry(textLabel);
list.addSingleOptionEntry(new SpruceLabelOption("command.ok_zoomer.restrictions.disable_zoom", true));
}

if (ZoomPackets.getDisableZoomScrolling()) {
var textLabel = new SpruceLabelOption("command.ok_zoomer.restrictions.disable_zoom_scrolling", true);
this.list.addSingleOptionEntry(textLabel);
list.addSingleOptionEntry(new SpruceLabelOption("command.ok_zoomer.restrictions.disable_zoom_scrolling", true));
}

if (ZoomPackets.getForceClassicMode()) {
var textLabel = new SpruceLabelOption("command.ok_zoomer.restrictions.force_classic_mode", true);
this.list.addSingleOptionEntry(textLabel);
list.addSingleOptionEntry(new SpruceLabelOption("command.ok_zoomer.restrictions.force_classic_mode", true));
}

if (ZoomPackets.getForceZoomDivisors()) {
double minimumZoomDivisor = ZoomPackets.getMinimumZoomDivisor();
double maximumZoomDivisor = ZoomPackets.getMaximumZoomDivisor();
var textLabel = new SpruceLabelOption(
list.addSingleOptionEntry(new SpruceLabelOption(
"command.ok_zoomer.restrictions.force_zoom_divisors",
minimumZoomDivisor != maximumZoomDivisor
? Text.translatable("command.ok_zoomer.restrictions.force_zoom_divisors", minimumZoomDivisor, maximumZoomDivisor)
: Text.translatable("command.ok_zoomer.restrictions.force_zoom_divisor", minimumZoomDivisor),
true);
this.list.addSingleOptionEntry(textLabel);
true)
);
}

if (ZoomPackets.getSpyglassDependency()) {
String key = switch (OkZoomerConfigManager.CONFIG.features.spyglass_dependency.value()) {
var key = switch (OkZoomerConfigManager.CONFIG.features.spyglass_dependency.value()) {
case REQUIRE_ITEM -> "command.ok_zoomer.restrictions.force_spyglass.require_item";
case REPLACE_ZOOM -> "command.ok_zoomer.restrictions.force_spyglass.replace_zoom";
case BOTH -> "command.ok_zoomer.restrictions.force_spyglass.both";
default -> "";
};
var textLabel = new SpruceLabelOption(key, true);
this.list.addSingleOptionEntry(textLabel);
list.addSingleOptionEntry(new SpruceLabelOption(key, true));
}

if (ZoomPackets.getSpyglassOverlay()) {
var textLabel = new SpruceLabelOption("command.ok_zoomer.restrictions.force_spyglass_overlay", true);
this.list.addSingleOptionEntry(textLabel);
list.addSingleOptionEntry(new SpruceLabelOption("command.ok_zoomer.restrictions.force_spyglass_overlay", true));
}

if (!ZoomPackets.getHasRestrictions()) {
boolean acknowledged = ZoomPackets.getAcknowledgement().equals(ZoomPackets.Acknowledgement.HAS_NO_RESTRICTIONS);
if (acknowledged) {
var textLabel = new SpruceLabelOption("command.ok_zoomer.restrictions.no_restrictions.acknowledged", true);
this.list.addSingleOptionEntry(textLabel);
} else {
var textLabel = new SpruceLabelOption("command.ok_zoomer.restrictions.no_restrictions", true);
this.list.addSingleOptionEntry(textLabel);
}
list.addSingleOptionEntry(new SpruceLabelOption(acknowledged
? "command.ok_zoomer.restrictions.no_restrictions.acknowledged"
: "command.ok_zoomer.restrictions.no_restrictions",
true)
);
}

this.list.setBackground(darkenedBackground);

this.addDrawableChild(this.list);
this.addDrawableChild(list);
this.addDrawableChild(new SpruceButtonWidget(Position.of(this, this.width / 2 - 100, this.height - 28), 200, 20, SpruceTexts.GUI_DONE,
btn -> this.client.setScreen(null)).asVanilla());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.ennuil.ok_zoomer.config.screen;

import java.lang.reflect.Field;
import java.util.Map;

import net.minecraft.util.CommonColors;
Expand Down Expand Up @@ -47,7 +46,7 @@ public class OkZoomerConfigScreen extends SpruceScreen {
private final Screen parent;
private ZoomPresets preset;

private Map<TrackedValue<Object>, Object> newValues;
private final Map<TrackedValue<Object>, Object> newValues;
private SpruceOption optionBuffer;

public OkZoomerConfigScreen(Screen parent) {
Expand Down Expand Up @@ -118,7 +117,7 @@ public void closeScreen() {

@SuppressWarnings("unchecked")
private void resetNewValues() {
this.newValues = new Reference2ObjectArrayMap<>();
this.newValues.clear();

for (TrackedValue<?> trackedValue : OkZoomerConfigManager.CONFIG.values()) {
if (trackedValue.getRealValue() != null) {
Expand Down Expand Up @@ -166,8 +165,8 @@ private void initializeOptionList() {
for (Constraint<?> constraint : trackedValue.constraints()) {
if (constraint instanceof Constraint.Range<?>) {
try {
Field minField = Constraint.Range.class.getDeclaredField("min");
Field maxField = Constraint.Range.class.getDeclaredField("max");
var minField = Constraint.Range.class.getDeclaredField("min");
var maxField = Constraint.Range.class.getDeclaredField("max");

minField.setAccessible(true);
maxField.setAccessible(true);
Expand All @@ -193,8 +192,8 @@ private void initializeOptionList() {
for (Constraint<?> constraint : trackedValue.constraints()) {
if (constraint instanceof Constraint.Range<?>) {
try {
Field minField = Constraint.Range.class.getDeclaredField("min");
Field maxField = Constraint.Range.class.getDeclaredField("max");
var minField = Constraint.Range.class.getDeclaredField("min");
var maxField = Constraint.Range.class.getDeclaredField("max");

minField.setAccessible(true);
maxField.setAccessible(true);
Expand Down Expand Up @@ -317,7 +316,7 @@ public void resetToPreset(ZoomPresets preset) {
Map.entry(OkZoomerConfigManager.CONFIG.tweaks.print_owo_on_start, preset == ZoomPresets.CLASSIC ? false : true)
);

this.newValues = new Reference2ObjectArrayMap<>();
this.newValues.clear();

for (TrackedValue<?> trackedValue : OkZoomerConfigManager.CONFIG.values()) {
this.newValues.put((TrackedValue<Object>) trackedValue, presets.get(trackedValue));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
@Mixin(InGameHud.class)
public abstract class InGameHudMixin {
@ModifyExpressionValue(
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingSpyglass()Z"),
method = "render"
method = "render",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingSpyglass()Z")
)
private boolean activateSpyglassOverlay(boolean isUsingSpyglass) {
if (switch (OkZoomerConfigManager.CONFIG.features.spyglass_dependency.value()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private void zoomerOnMouseScroll(CallbackInfo ci) {
// Handles the zoom scrolling reset through the middle button
@Inject(
method = "onMouseButton",
at = @At(value = "INVOKE", target = "net/minecraft/client/option/KeyBind.setKeyPressed(Lcom/mojang/blaze3d/platform/InputUtil$Key;Z)V"),
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/KeyBind;setKeyPressed(Lcom/mojang/blaze3d/platform/InputUtil$Key;Z)V"),
cancellable = true,
locals = LocalCapture.CAPTURE_FAILHARD
)
Expand Down

0 comments on commit 401a834

Please sign in to comment.