Skip to content

Commit

Permalink
Merge pull request #88 from bl4ckscor3/accessibility-mode
Browse files Browse the repository at this point in the history
Add accessibility mode and respect FOV effect scale for FOV effects
  • Loading branch information
juancarloscp52 authored Jan 29, 2023
2 parents bd92ce9 + 9b734c4 commit c7e1f0a
Show file tree
Hide file tree
Showing 28 changed files with 212 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ private VotingMode(String text) {
public VotingMode votingMode = VotingMode.PROPORTIONAL;
public UIStyle UIstyle = UIStyle.GTAV;
public List<String> disabledEvents = new ArrayList<>();
public boolean accessibilityMode = false;
}
1 change: 1 addition & 0 deletions src/main/java/me/juancarloscp52/entropy/Variables.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ public class Variables {
public static boolean stuttering = false;
public static boolean forceRiding = false;
public static boolean blackAndWhite = false;
public static boolean fireEvent = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ClientEventHandler {
public VotingClient votingClient;
public MinecraftClient client;
short eventCountDown;

short timerDuration;
UIRenderer renderer = null;
final short timerDurationFinal;
Expand Down Expand Up @@ -102,7 +102,7 @@ public void render(MatrixStack matrixStack, float tickdelta) {
int width = MinecraftClient.getInstance().getWindow().getScaledWidth();

// Render timer bar
/// Only the timer is differentiated in two declination for now but
/// Only the timer is differentiated in two declination for now but
/// it will be interesting to adapt the event queue and poll rendering too
renderer.renderTimer(matrixStack, width, time, timerDuration);

Expand All @@ -124,7 +124,7 @@ public void remove(byte index) {

public void addEvent(String registryIndex) {
Event event = EventRegistry.get(registryIndex);
if(!client.player.isSpectator())
if(!client.player.isSpectator() && !(event.isDisabledByAccessibilityMode() && Entropy.getInstance().settings.accessibilityMode))
event.initClient();
currentEvents.add(event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
package me.juancarloscp52.entropy.client;

import com.google.gson.Gson;

import me.juancarloscp52.entropy.Entropy;
import me.juancarloscp52.entropy.EntropySettings;
import me.juancarloscp52.entropy.NetworkingConstants;
import me.juancarloscp52.entropy.Variables;
import me.juancarloscp52.entropy.events.Event;
Expand All @@ -31,10 +34,15 @@
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.gl.PostEffectProcessor;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.tooltip.Tooltip;
import net.minecraft.client.gui.widget.CyclingButtonWidget;
import net.minecraft.nbt.NbtElement;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.sound.SoundEvent;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -91,7 +99,7 @@ public void onInitializeClient() {
continue;
event.setEnded(ended);
event.setTickCount(tickCount);
if (tickCount > 0 && !ended)
if (tickCount > 0 && !ended && !(event.isDisabledByAccessibilityMode() && Entropy.getInstance().settings.accessibilityMode))
event.initClient();
client.execute(() -> clientEventHandler.currentEvents.add(event));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public EntropyConfigurationScreen(Screen parent) {
}

protected void init() {
int buttonX = this.width / 2 - 100;
int buttonWidth = 200;

eventDurationWidget = new EntropySliderWidget(this.width / 2 - 160, 50, 150, 20,"entropy.options.eventDuration",(settings.baseEventDuration-300)/1200d,(slider, translationKey, value) -> Text.translatable("entropy.options.eventDuration", MathHelper.floor(value*60+15)), value -> settings.baseEventDuration = (short) ((1200*value)+300));
this.addDrawableChild(eventDurationWidget);
Expand All @@ -62,28 +64,34 @@ protected void init() {
this.addDrawableChild(timerDurationWidget);


ButtonWidget eventSettings = ButtonWidget.builder(Text.translatable("entropy.options.disableEvents"), button -> this.client.setScreen(new EntropyEventConfigurationScreen(this))).position(this.width / 2 - 85, 75).width(170).build();
ButtonWidget eventSettings = ButtonWidget.builder(Text.translatable("entropy.options.disableEvents"), button -> this.client.setScreen(new EntropyEventConfigurationScreen(this))).position(buttonX, 75).width(buttonWidth).build();
this.addDrawableChild(eventSettings);

ButtonWidget integrationSettings = ButtonWidget.builder(Text.translatable("entropy.options.integrations.title"), button -> this.client.setScreen(new EntropyIntegrationsScreen(this))).width(170).position(this.width / 2 - 85, 100).build();
ButtonWidget integrationSettings = ButtonWidget.builder(Text.translatable("entropy.options.integrations.title"), button -> this.client.setScreen(new EntropyIntegrationsScreen(this))).width(buttonWidth).position(buttonX, 100).build();
this.addDrawableChild(integrationSettings);

CyclingButtonWidget<VotingMode> votingModeButton = CyclingButtonWidget.<VotingMode>builder(votingMode -> votingMode.text)
.values(VotingMode.values())
.initially(settings.votingMode)
.tooltip(votingMode -> Tooltip.of(votingMode.tooltip))
.build(this.width / 2 - 85, 125, 170, 20, Text.translatable("entropy.options.votingMode"), (button, newValue) -> settings.votingMode = newValue);
.build(buttonX, 125, buttonWidth, 20, Text.translatable("entropy.options.votingMode"), (button, newValue) -> settings.votingMode = newValue);
this.addDrawableChild(votingModeButton);

// UI style button
CyclingButtonWidget<UIStyle> uiStyleButton = CyclingButtonWidget.<UIStyle>builder(uiStyle -> uiStyle.text)
.values(UIStyle.values())
.initially(settings.UIstyle)
.tooltip(uiStyle -> Tooltip.of(uiStyle.tooltip))
.build(this.width / 2 - 85, 150, 170, 20, Text.translatable("entropy.options.ui"), (button, newValue) -> settings.UIstyle = newValue);
.build(buttonX, 150, buttonWidth, 20, Text.translatable("entropy.options.ui"), (button, newValue) -> settings.UIstyle = newValue);
this.addDrawableChild(uiStyleButton);

this.done = ButtonWidget.builder(ScreenTexts.DONE, button -> onDone()).width(200).position(this.width / 2 - 100, this.height - 30).build();
this.addDrawableChild(CyclingButtonWidget.<Boolean>builder(bool -> Text.translatable("entropy.options." + (bool ? "enabled" : "disabled")))
.values(true, false)
.initially(settings.accessibilityMode)
.tooltip(bool -> Tooltip.of(Text.translatable("entropy.options.accessibilityMode.explanation")))
.build(buttonX, 175, buttonWidth, 20, Text.translatable("entropy.options.accessibilityMode"), (button, newValue) -> settings.accessibilityMode = newValue));

this.done = ButtonWidget.builder(ScreenTexts.DONE, button -> onDone()).width(buttonWidth).position(this.width / 2 - 100, this.height - 30).build();
this.addDrawableChild(done);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,22 @@ public boolean mouseReleased(double mouseX, double mouseY, int button) {
private void onDone() {
settings.disabledEvents = new ArrayList<>();
this.list.children().forEach(buttonEntry -> {
if (!buttonEntry.button.isChecked())
settings.disabledEvents.add(buttonEntry.eventID);
if (!buttonEntry.checkbox.isChecked())
settings.disabledEvents.add(buttonEntry.eventInfo.id());
});
Entropy.getInstance().saveSettings();
close();
}

private void onCheckAll() {
this.list.children().forEach(buttonEntry -> {
if (buttonEntry.button.visible && !buttonEntry.button.isChecked()) {buttonEntry.button.onPress();}
if (buttonEntry.checkbox.visible && !buttonEntry.checkbox.isChecked()) {buttonEntry.checkbox.onPress();}
});
}

private void onUncheckAll() {
this.list.children().forEach(buttonEntry -> {
if (buttonEntry.button.visible && buttonEntry.button.isChecked()) {buttonEntry.button.onPress();}
if (buttonEntry.checkbox.visible && buttonEntry.checkbox.isChecked()) {buttonEntry.checkbox.onPress();}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,30 @@
package me.juancarloscp52.entropy.client.Screens.Widgets;

import com.google.common.collect.ImmutableList;
import com.mojang.blaze3d.systems.RenderSystem;

import me.juancarloscp52.entropy.Entropy;
import me.juancarloscp52.entropy.EntropySettings;
import me.juancarloscp52.entropy.events.Event;
import me.juancarloscp52.entropy.events.EventRegistry;
import me.juancarloscp52.entropy.mixin.EntryListWidgetAccessor;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.Selectable;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.tooltip.Tooltip;
import net.minecraft.client.gui.widget.CheckboxWidget;
import net.minecraft.client.gui.widget.ElementListWidget;
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.OrderedText;
import net.minecraft.text.Text;
import net.minecraft.util.Pair;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;

import java.util.ArrayList;
Expand All @@ -50,16 +58,19 @@ public EntropyEventListWidget(MinecraftClient minecraftClient, int i, int j, int
}

public void addAllFromRegistry() {
var list = new ArrayList<Pair<String, String>>();
for(var eventId : EventRegistry.entropyEvents.keySet())
list.add(new Pair<String,String>(Text.translatable(EventRegistry.getTranslationKey(eventId)).getString(), eventId));
var list = new ArrayList<EventInfo>();
for(var event : EventRegistry.entropyEvents.entrySet()) {
String eventId = event.getKey();

list.add(new EventInfo(Text.translatable(EventRegistry.getTranslationKey(eventId)).getString(), eventId, event.getValue().get()));
}

Collections.sort(list, (a, b) -> a.getLeft().compareTo(b.getLeft()));
Collections.sort(list, (a, b) -> a.name.compareTo(b.name));
list.forEach(this::addEvent);
}

public int addEvent(Pair<String,String> event) {
return this.addEntry(EntropyEventListWidget.ButtonEntry.create(event));
public int addEvent(EventInfo eventInfo) {
return this.addEntry(EntropyEventListWidget.ButtonEntry.create(eventInfo));
}

@Override
Expand Down Expand Up @@ -125,7 +136,7 @@ protected void renderList(MatrixStack matrices, int mouseX, int mouseY, float de
int rowTop = this.getRowTop(drawIndex);
int rowBottom = rowTop + this.itemHeight;

if (this.getEntry(index).button.visible) {
if (this.getEntry(index).checkbox.visible) {
drawIndex++;

if (rowBottom >= this.top && rowTop <= this.bottom)
Expand All @@ -140,16 +151,16 @@ public void updateVisibleEntries(String searchText, FilterMode filterMode) {

if (searchText.isBlank())
children().stream().forEach(buttonEntry -> {
buttonEntry.button.visible = filterMode.allowsVisibility(buttonEntry);
buttonEntry.checkbox.visible = filterMode.allowsVisibility(buttonEntry);

if(buttonEntry.button.visible)
if(buttonEntry.checkbox.visible)
visibleEntries.add(buttonEntry);
});
else {
children().stream().forEach(buttonEntry -> {
buttonEntry.button.visible = filterMode.allowsVisibility(buttonEntry) && (buttonEntry.eventName.toLowerCase(Locale.ROOT).contains(lowerCasedNewText) || buttonEntry.eventID.toLowerCase(Locale.ROOT).contains(lowerCasedNewText));
buttonEntry.checkbox.visible = filterMode.allowsVisibility(buttonEntry) && (buttonEntry.eventInfo.name.toLowerCase(Locale.ROOT).contains(lowerCasedNewText) || buttonEntry.eventInfo.id.toLowerCase(Locale.ROOT).contains(lowerCasedNewText));

if(buttonEntry.button.visible)
if(buttonEntry.checkbox.visible)
visibleEntries.add(buttonEntry);
});
}
Expand All @@ -159,41 +170,66 @@ public void updateVisibleEntries(String searchText, FilterMode filterMode) {

@Environment(EnvType.CLIENT)
public static class ButtonEntry extends ElementListWidget.Entry<EntropyEventListWidget.ButtonEntry> {
public final CheckboxWidget button;
public final String eventName;
public final String eventID;

private ButtonEntry(String eventName, String eventID, CheckboxWidget button) {
this.button = button;
this.eventName = eventName;
this.eventID = eventID;
private static final Identifier ICON_OVERLAY_LOCATION = new Identifier("textures/gui/world_selection.png");
private static final Text ACCESSIBILITY_TOOLTIP = Text.translatable("entropy.options.accessibilityMode.eventDisabled");
public final CheckboxWidget checkbox;
public final EventInfo eventInfo;

private ButtonEntry(EventInfo eventInfo, CheckboxWidget checkbox) {
this.checkbox = checkbox;
this.eventInfo = eventInfo;
}

public static EntropyEventListWidget.ButtonEntry create(Pair<String,String> event) {
public static EntropyEventListWidget.ButtonEntry create(EventInfo eventInfo) {
EntropySettings settings = Entropy.getInstance().settings;
String eventID = event.getRight();
return new EntropyEventListWidget.ButtonEntry(event.getLeft(), eventID, new CheckboxWidget(0, 0, MinecraftClient.getInstance().getWindow().getScaledWidth(), 20, Text.translatable(EventRegistry.getTranslationKey(eventID)), !settings.disabledEvents.contains(eventID)));
String eventID = eventInfo.id;
boolean isDisabledByAccessibilityMode = eventInfo.event.isDisabledByAccessibilityMode() && Entropy.getInstance().settings.accessibilityMode;
boolean enableCheckbox = !settings.disabledEvents.contains(eventID) && !isDisabledByAccessibilityMode;
CheckboxWidget checkbox = new CheckboxWidget(0, 0, MinecraftClient.getInstance().getWindow().getScaledWidth(), 20, Text.translatable(EventRegistry.getTranslationKey(eventID)), enableCheckbox);
checkbox.active = !isDisabledByAccessibilityMode;
return new EntropyEventListWidget.ButtonEntry(eventInfo, checkbox);
}

public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
button.setPos(x + 32,y);
button.render(matrices, mouseX, mouseY, tickDelta);
checkbox.setPos(x + 32, y);
checkbox.render(matrices, mouseX, mouseY, tickDelta);

if(Entropy.getInstance().settings.accessibilityMode && eventInfo.event.isDisabledByAccessibilityMode()) {
RenderSystem.setShaderTexture(0, ICON_OVERLAY_LOCATION);
DrawableHelper.drawTexture(matrices, x, y - 6, 64, 32, 32, 32, 256, 256);

if(mouseX >= x && mouseX <= x + 350 && mouseY >= y && mouseY <= y + entryHeight) {
MinecraftClient client = MinecraftClient.getInstance();
List<OrderedText> lines = client.textRenderer.wrapLines(ACCESSIBILITY_TOOLTIP, 200);
int tooltipHeight = client.textRenderer.fontHeight * lines.size();
int tooltipYPosition = (int)(y + tooltipHeight * 1.5D);

//if the tooltip would render further down than the list reaches, render it above the entry
if(tooltipYPosition + tooltipHeight > client.currentScreen.height - 32)
tooltipYPosition = y - 12 - tooltipHeight / 2;

client.currentScreen.renderOrderedTooltip(matrices, lines, x, tooltipYPosition);
}
}
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
this.button.onPress();
MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
if(checkbox.active) {
MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
this.checkbox.onPress();
}

return true;
}

public List<? extends Element> children() {
return ImmutableList.of(this.button);
return ImmutableList.of(this.checkbox);
}

@Override
public List<? extends Selectable> selectableChildren() {
return ImmutableList.of(button);
return ImmutableList.of(checkbox);
}
}

Expand All @@ -209,8 +245,9 @@ private FilterMode(String text) {
}

public boolean allowsVisibility(ButtonEntry buttonEntry) {
return this == ALL || this == ENABLED && buttonEntry.button.isChecked() || this == DISABLED && !buttonEntry.button.isChecked();
return this == ALL || this == ENABLED && buttonEntry.checkbox.isChecked() || this == DISABLED && !buttonEntry.checkbox.isChecked();
}
}

public record EventInfo(String name, String id, Event event) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@

package me.juancarloscp52.entropy.events;

import me.juancarloscp52.entropy.Entropy;
import me.juancarloscp52.entropy.Variables;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.MathHelper;

public abstract class AbstractInstantEvent implements Event {
Expand All @@ -45,8 +48,13 @@ public void renderQueueItem(MatrixStack matrixStack, float tickdelta, int x, int
if(Variables.doNotShowEvents)
return;
MinecraftClient client = MinecraftClient.getInstance();
int size = client.textRenderer.getWidth(Text.translatable(EventRegistry.getTranslationKey(this)));
DrawableHelper.drawTextWithShadow(matrixStack, MinecraftClient.getInstance().textRenderer, Text.translatable(EventRegistry.getTranslationKey(this)), client.getWindow().getScaledWidth() - size - 40, y, MathHelper.packRgb(255, 255, 255));
MutableText eventName = Text.translatable(EventRegistry.getTranslationKey(this));

if(isDisabledByAccessibilityMode() && Entropy.getInstance().settings.accessibilityMode)
eventName.formatted(Formatting.STRIKETHROUGH);

int size = client.textRenderer.getWidth(eventName);
DrawableHelper.drawTextWithShadow(matrixStack, MinecraftClient.getInstance().textRenderer, eventName, client.getWindow().getScaledWidth() - size - 40, y, MathHelper.packRgb(255, 255, 255));
}

public void tick() {
Expand Down
Loading

0 comments on commit c7e1f0a

Please sign in to comment.