Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/main/java/dev/isxander/controlify/api/guide/GuideInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ public interface GuideInstance<T extends FactCtx> {

boolean update(T context, Font font);

void extractRenderState(GuiGraphicsExtractor graphics, boolean bottomAligned, boolean textContrast);
Renderable renderable(boolean bottomAligned, boolean textContrast);
void extractRenderState(GuiGraphicsExtractor graphics, boolean bottomAligned, boolean textContrast, int guiScale);

default void extractRenderState(GuiGraphicsExtractor graphics, boolean bottomAligned, boolean textContrast) {
extractRenderState(graphics, bottomAligned, textContrast, -1);
}

Renderable renderable(boolean bottomAligned, boolean textContrast, int guiScale);

default Renderable renderable(boolean bottomAligned, boolean textContrast) {
return renderable(bottomAligned, textContrast, -1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import dev.isxander.controlify.config.settings.profile.ProfileSettings;

public final class ControlifyDataFixer {
public static final int CURRENT_VERSION = 6;
public static final int CURRENT_VERSION = 7;

private static final DataFixer FIXER = createFixer();

Expand All @@ -29,15 +29,24 @@ private static DataFixer createFixer() {
var v2 = builder.addSchema(2, ControlifySchemas.V2::new);
var v3 = builder.addSchema(3, ControlifySchemas.V3::new);
var v6 = builder.addSchema(6, ControlifySchemas.V6::new);
var v7 = builder.addSchema(7, ControlifySchemas.V7::new);

var globalDefaults = GlobalSettings.defaults();
var profileDefaults = ProfileSettings.createDefault();

// v1
builder.addFixer(new TheHolyMigrationFix(v1, globalDefaults, profileDefaults));

// v2
builder.addFixer(new AnalogueMovementWhitelistFix(v2));
builder.addFixer(new HorizontalLookInvertFix(v2));

// v6
builder.addFixer(new DualsenseConfigFix(v6, profileDefaults));

// v7
builder.addFixer(new GuideGuiScaleFix(v7, profileDefaults));

return builder.build().fixer();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,10 @@ public V6(int versionKey, Schema parent) {
super(versionKey, parent);
}
}

public static class V7 extends Schema {
public V7(int versionKey, Schema parent) {
super(versionKey, parent);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package dev.isxander.controlify.config.dto.dfu.fixes;

import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.serialization.Dynamic;
import dev.isxander.controlify.config.dto.dfu.ControlifyTypeReferences;
import dev.isxander.controlify.config.settings.profile.ProfileSettings;

public class GuideGuiScaleFix extends DataFix {
private final ProfileSettings profileDefaults;

public GuideGuiScaleFix(Schema outputSchema, ProfileSettings profileDefaults) {
super(outputSchema, true);
this.profileDefaults = profileDefaults;
}

@Override
protected TypeRewriteRule makeRule() {
var profileType = getInputSchema().getType(ControlifyTypeReferences.PROFILE_CONFIG);

return fixTypeEverywhereTyped(
"Controlify: add guide gui scale defaults",
profileType,
typed -> typed.update(DSL.remainderFinder(), this::rewriteProfile)
);
}

private <T> Dynamic<T> rewriteProfile(Dynamic<T> root) {
Dynamic<T> generic = root.get("generic").orElseEmptyMap();
Dynamic<T> guide = generic.get("guide").orElseEmptyMap();

guide = guide
.set("ingame_gui_scale", root.createInt(profileDefaults.generic.guide.ingameGuiScale))
.set("screen_gui_scale", root.createInt(profileDefaults.generic.guide.screenGuiScale));

generic = generic.set("guide", guide);
return root.set("generic", generic);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ public record GuideConfig(
GuideVerbosity verbosity,
boolean showIngameGuide,
boolean ingameGuideButtom,
boolean showScreenGuides
boolean showScreenGuides,
int ingameGuiScale,
int screenGuiScale
) {
public static final Codec<GuideConfig> CODEC = RecordCodecBuilder.create(instance -> instance.group(
GuideVerbosity.CODEC.fieldOf("verbosity").forGetter(GuideConfig::verbosity),
Codec.BOOL.fieldOf("show_ingame_guide").forGetter(GuideConfig::showIngameGuide),
Codec.BOOL.fieldOf("ingame_guide_bottom").forGetter(GuideConfig::ingameGuideButtom),
Codec.BOOL.fieldOf("show_screen_guides").forGetter(GuideConfig::showScreenGuides)
Codec.BOOL.fieldOf("show_screen_guides").forGetter(GuideConfig::showScreenGuides),
Codec.intRange(-1, Integer.MAX_VALUE).fieldOf("ingame_gui_scale").forGetter(GuideConfig::ingameGuiScale),
Codec.intRange(-1, Integer.MAX_VALUE).fieldOf("screen_gui_scale").forGetter(GuideConfig::screenGuiScale)
).apply(instance, GuideConfig::new));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,33 @@ public static class GuideSettings {
public boolean showIngameGuide;
public boolean ingameGuideBottom;
public boolean showScreenGuides;
public int ingameGuiScale;
public int screenGuiScale;

public GuideSettings(
GuideVerbosity verbosity,
boolean showIngameGuide,
boolean ingameGuideBottom,
boolean showScreenGuides
boolean showScreenGuides,
int ingameGuiScale,
int screenGuiScale
) {
this.verbosity = verbosity;
this.showIngameGuide = showIngameGuide;
this.ingameGuideBottom = ingameGuideBottom;
this.showScreenGuides = showScreenGuides;
this.ingameGuiScale = ingameGuiScale;
this.screenGuiScale = screenGuiScale;
}

public static GuideSettings fromDTO(GenericControllerConfig.GuideConfig dto) {
return new GuideSettings(
dto.verbosity(),
dto.showIngameGuide(),
dto.ingameGuideButtom(),
dto.showScreenGuides()
dto.showScreenGuides(),
dto.ingameGuiScale(),
dto.screenGuiScale()
);
}

Expand All @@ -87,7 +95,9 @@ public GenericControllerConfig.GuideConfig toDTO() {
verbosity,
showIngameGuide,
ingameGuideBottom,
showScreenGuides
showScreenGuides,
ingameGuiScale,
screenGuiScale
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,25 @@ public boolean update(T context, Font font) {
}

@Override
public void extractRenderState(GuiGraphicsExtractor graphics, boolean bottomAligned, boolean textContrast) {
GuideRenderer.extractRenderState(graphics, this, Minecraft.getInstance(), bottomAligned, textContrast);
public void extractRenderState(GuiGraphicsExtractor graphics, boolean bottomAligned, boolean textContrast, int guiScale) {
GuideRenderer.extractRenderState(
graphics,
this,
Minecraft.getInstance(),
bottomAligned,
textContrast,
guiScale
);
}

@Override
public Renderable renderable(boolean bottomAligned, boolean textContrast) {
public Renderable renderable(boolean bottomAligned, boolean textContrast, int guiScale) {
return new GuideRenderer.Renderable(
this,
Minecraft.getInstance(),
bottomAligned,
textContrast
textContrast,
guiScale
);
}

Expand Down
46 changes: 38 additions & 8 deletions src/main/java/dev/isxander/controlify/gui/guide/GuideRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package dev.isxander.controlify.gui.guide;

import com.google.common.collect.Lists;
import com.mojang.blaze3d.platform.Window;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphicsExtractor;
Expand All @@ -15,12 +16,35 @@
public final class GuideRenderer {
private GuideRenderer() {}

public static void extractRenderState(GuiGraphicsExtractor graphics, GuideInstanceImpl<?> guideInstance, Minecraft minecraft, boolean bottomAligned, boolean textContrast) {
int width = minecraft.getWindow().getGuiScaledWidth();
int height = minecraft.getWindow().getGuiScaledHeight();
public static void extractRenderState(GuiGraphicsExtractor graphics, GuideInstanceImpl<?> guideInstance, Minecraft minecraft, boolean bottomAligned, boolean textContrast, int guiScale) {
Window window = minecraft.getWindow();
int standardGuiScale = window.getGuiScale();
if (guiScale == -1) { // unset
guiScale = standardGuiScale;
} else if (guiScale == 0) { // automatic
int maxGuiScale = window.calculateScale(0, minecraft.isEnforceUnicode());
// pick 1 less than the largest, but make sure it's not bigger than the standard scale
guiScale = Math.min(maxGuiScale - 1, standardGuiScale);
} else {
guiScale = window.calculateScale(guiScale, minecraft.isEnforceUnicode());
}

graphics.pose().pushMatrix();
int scaledWidth;
int scaledHeight;
if (guiScale > 0 && guiScale != standardGuiScale) {
graphics.pose().scale((float) guiScale / standardGuiScale, (float) guiScale / standardGuiScale);
scaledWidth = window.getWidth() / guiScale;
scaledHeight = window.getHeight() / guiScale;
} else {
scaledWidth = graphics.guiWidth();
scaledHeight = graphics.guiHeight();
}

extractLines(graphics, guideInstance.leftGuides(), minecraft.font, width, height, bottomAligned, false, textContrast);
extractLines(graphics, guideInstance.rightGuides(), minecraft.font, width, height, bottomAligned, true, textContrast);
extractLines(graphics, guideInstance.leftGuides(), minecraft.font, scaledWidth, scaledHeight, bottomAligned, false, textContrast);
extractLines(graphics, guideInstance.rightGuides(), minecraft.font, scaledWidth, scaledHeight, bottomAligned, true, textContrast);

graphics.pose().popMatrix();
}

private static void extractLines(GuiGraphicsExtractor graphics, PrecomputedLines lines, Font font, int width, int height, boolean bottomAligned, boolean rightAligned, boolean textContrast) {
Expand Down Expand Up @@ -51,23 +75,25 @@ private static void extractLines(GuiGraphicsExtractor graphics, PrecomputedLines
}
}

static class Renderable implements net.minecraft.client.gui.components.Renderable {
public static class Renderable implements net.minecraft.client.gui.components.Renderable {
private final GuideInstanceImpl<?> instance;
private final Minecraft minecraft;
private boolean bottomAligned;
private boolean textContrast;
private int guiScale;

public Renderable(GuideInstanceImpl<?> instance, Minecraft minecraft, boolean bottomAligned, boolean textContrast) {
public Renderable(GuideInstanceImpl<?> instance, Minecraft minecraft, boolean bottomAligned, boolean textContrast, int guiScale) {
this.instance = instance;
this.minecraft = minecraft;
this.bottomAligned = bottomAligned;
this.textContrast = textContrast;
this.guiScale = guiScale;
}


@Override
public void extractRenderState(@NonNull GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
GuideRenderer.extractRenderState(graphics, instance, minecraft, bottomAligned, textContrast);
GuideRenderer.extractRenderState(graphics, instance, minecraft, bottomAligned, textContrast, guiScale);
}

public void setBottomAligned(boolean bottomAligned) {
Expand All @@ -77,5 +103,9 @@ public void setBottomAligned(boolean bottomAligned) {
public void setTextContrast(boolean textContrast) {
this.textContrast = textContrast;
}

public void setGuiScale(int guiScale) {
this.guiScale = guiScale;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void extractRenderState(GuiGraphicsExtractor graphics, float tickDelta) {
GenericControllerSettings.GuideSettings settings = controller.settings().generic.guide;

if (!debugOpen && !hideGui && !screenOpen && settings.showIngameGuide) {
this.guideInstance.extractRenderState(graphics, settings.ingameGuideBottom, true);
this.guideInstance.extractRenderState(graphics, settings.ingameGuideBottom, true, settings.ingameGuiScale);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,36 @@ private Optional<OptionGroup> makeAccessibilityGroup(
.binding(gDefaults.guide.showScreenGuides, () -> gSettings.guide.showScreenGuides, v -> gSettings.guide.showScreenGuides = v)
.controller(TickBoxControllerBuilder::create)
.build())
.option(Option.<Integer>createBuilder()
.name(Component.translatable("controlify.gui.ingame_guide_gui_scale"))
.description(OptionDescription.createBuilder()
.text(Component.translatable("controlify.gui.ingame_guide_gui_scale.tooltip"))
.build())
.binding(gDefaults.guide.ingameGuiScale, () -> gSettings.guide.ingameGuiScale, v -> gSettings.guide.ingameGuiScale = v)
.controller(opt -> IntegerSliderControllerBuilder.create(opt)
.range(-1, Minecraft.getInstance().getWindow().calculateScale(0, Minecraft.getInstance().isEnforceUnicode()))
.step(1)
.formatValue(v -> switch (v) {
case -1 -> Component.translatable("controlify.gui.guide_gui_scale.unchanged");
case 0 -> Component.translatable("controlify.gui.guide_gui_scale.auto");
default -> Component.literal(String.valueOf(v));
}))
.build())
.option(Option.<Integer>createBuilder()
.name(Component.translatable("controlify.gui.screen_guide_gui_scale"))
.description(OptionDescription.createBuilder()
.text(Component.translatable("controlify.gui.screen_guide_gui_scale.tooltip"))
.build())
.binding(gDefaults.guide.screenGuiScale, () -> gSettings.guide.screenGuiScale, v -> gSettings.guide.screenGuiScale = v)
.controller(opt -> IntegerSliderControllerBuilder.create(opt)
.range(-1, Minecraft.getInstance().getWindow().calculateScale(0, Minecraft.getInstance().isEnforceUnicode()))
.step(1)
.formatValue(v -> switch (v) {
case -1 -> Component.translatable("controlify.gui.guide_gui_scale.unchanged");
case 0 -> Component.translatable("controlify.gui.guide_gui_scale.auto");
default -> Component.literal(String.valueOf(v));
}))
.build())
.option(Option.<Boolean>createBuilder()
.name(Component.translatable("controlify.gui.show_keyboard"))
.description(OptionDescription.createBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import dev.isxander.controlify.controller.ControllerEntity;
import dev.isxander.controlify.controller.haptic.HapticEffects;
import dev.isxander.controlify.gui.guide.GuideDomains;
import dev.isxander.controlify.gui.guide.GuideRenderer;
import dev.isxander.controlify.mixins.feature.guide.screen.AbstractContainerScreenAccessor;
import dev.isxander.controlify.mixins.feature.screenop.ScreenAccessor;
import dev.isxander.controlify.screenop.ScreenProcessor;
Expand All @@ -32,7 +33,7 @@
public class AbstractContainerScreenProcessor<T extends AbstractContainerScreen<?>> extends ScreenProcessor<T> {

private final GuideInstance<ContainerCtx> guideInstance;
private final Renderable guideRenderable;
private GuideRenderer.Renderable guideRenderable;

private final Supplier<Slot> hoveredSlot;
private final ClickSlotFunction clickSlotFunction;
Expand All @@ -50,7 +51,6 @@ public AbstractContainerScreenProcessor(
this.clickSlotFunction = clickSlotFunction;
this.doItemSlotActions = doItemSlotActions;
this.guideInstance = GuideDomains.CONTAINER.createInstance();
this.guideRenderable = guideInstance.renderable(true, false);
}

@Override
Expand Down Expand Up @@ -112,6 +112,8 @@ protected void handleScreenVMouse(ControllerEntity controller, VirtualMouseHandl

@Override
public void onWidgetRebuild() {
this.guideRenderable = (GuideRenderer.Renderable) guideInstance.renderable(true, false);

if (ControlifyApi.get().currentInputMode().isController()) {
setRenderGuide(true);
}
Expand All @@ -123,6 +125,9 @@ public void onInputModeChanged(InputMode mode) {
}

private void setRenderGuide(boolean render) {
ControlifyApi.get().getCurrentController()
.ifPresent(c -> this.guideRenderable.setGuiScale(c.settings().generic.guide.screenGuiScale));

render &= ControlifyApi.get().getCurrentController().map(c -> c.settings().generic.guide.showScreenGuides).orElse(false);

List<Renderable> renderables = ((ScreenAccessor) screen).controlify$getRenderables();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"verbosity": "full",
"show_ingame_guide": true,
"ingame_guide_bottom": false,
"show_screen_guides": true
"show_screen_guides": true,
"ingame_gui_scale": 0,
"screen_gui_scale": 0
},
"keyboard": {
"show_on_screen_keyboard": true,
Expand Down
Loading
Loading