Skip to content

Commit

Permalink
#11 fixed crash in mod menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekeras committed May 14, 2023
1 parent 07e7041 commit 599fac4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 25 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
minecraftVersion=1.19.1
minecraftVersion=1.19.4
modVersion=1.5.2
forgeVersion=42.0.1
forgeVersion=45.0.0
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pluginManagement {
repositories {
maven("https://maven.minecraftforge.net")
mavenCentral()
gradlePluginPortal()
}
resolutionStrategy {
eachPlugin {
Expand Down
40 changes: 20 additions & 20 deletions src/main/java/de/nekeras/borderless/client/gui/ConfigScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ protected void init() {
fullscreenModeButton = ConfigScreenOption.fullscreenMode.createButton(minecraft.options, x, LINE_HEIGHT * 3, LAYOUT_MAX_WIDTH);
focusLossButton = ConfigScreenOption.focusLoss.createButton(minecraft.options, x, LINE_HEIGHT * 4, LAYOUT_MAX_WIDTH);

Button applyButton = new Button(width / 2 - 125, height - 75, 100, 20, applyText, btn -> {
Button applyButton = Button.builder(applyText, btn -> {
log.info("Apply button in Borderless Window Config Screen pressed");
FullscreenDisplayModeHolder.setFullscreenDisplayModeFromConfig();
onClose();
});
}).bounds(width / 2 - 125, height - 75, 100, 20).build();

Button cancelButton = new Button(width / 2 + 25, height - 75, 100, 20, CommonComponents.GUI_CANCEL, btn -> {
Button cancelButton = Button.builder(CommonComponents.GUI_CANCEL, btn -> {
log.info("Cancel button in Borderless Window Config Screen pressed, resetting to {}, {}, {}",
initialEnabledState, initialFullscreenMode, initialFocusLossMode);
Config.GENERAL.enabled.set(initialEnabledState);
Config.GENERAL.fullscreenMode.set(initialFullscreenMode);
Config.GENERAL.focusLoss.set(initialFocusLossMode);
onClose();
});
}).bounds(width / 2 + 25, height - 75, 100, 20).build();

addRenderableWidget(enabledButton);
addRenderableWidget(fullscreenModeButton);
Expand All @@ -91,16 +91,16 @@ public void tick() {
}

@Override
public void render(@Nonnull PoseStack matrixStack, int mouseX, int mouseY, float frameTime) {
public void render(@Nonnull PoseStack poseStack, int mouseX, int mouseY, float frameTime) {
Minecraft minecraft = Minecraft.getInstance();

this.renderBackground(matrixStack);
this.renderBackground(poseStack);

renderTitle(matrixStack, minecraft, width);
renderDescription(minecraft, width);
renderChangedWarning(minecraft, width, height);
renderTitle(poseStack, minecraft, width);
renderDescription(poseStack, minecraft, width);
renderChangedWarning(poseStack, minecraft, width, height);

super.render(matrixStack, mouseX, mouseY, frameTime);
super.render(poseStack, mouseX, mouseY, frameTime);
}

@Override
Expand All @@ -109,38 +109,38 @@ public void onClose() {
Minecraft.getInstance().setScreen(parent);
}

private void renderTitle(@Nonnull PoseStack matrixStack, @Nonnull Minecraft minecraft, int width) {
drawCenteredString(matrixStack, minecraft.font, title, width / 2, 20, WHITE);
private void renderTitle(@Nonnull PoseStack postStack, @Nonnull Minecraft minecraft, int width) {
drawCenteredString(postStack, minecraft.font, title, width / 2, 20, WHITE);
}

private void renderDescription(@Nonnull Minecraft minecraft, int width) {
private void renderDescription(@Nonnull PoseStack poseStack, @Nonnull Minecraft minecraft, int width) {
int x = getHorizontalLayoutStart(width);
int y = LINE_HEIGHT * 5;

if (Config.GENERAL.enabled.get()) {
minecraft.font.drawWordWrap(Component.translatable(getDescriptionKey()), x, y, LAYOUT_MAX_WIDTH, WHITE);
minecraft.font.drawWordWrap(poseStack, Component.translatable(getDescriptionKey()), x, y, LAYOUT_MAX_WIDTH, WHITE);
} else {
minecraft.font.drawWordWrap(disabledText, x, y, LAYOUT_MAX_WIDTH, RED);
minecraft.font.drawWordWrap(poseStack, disabledText, x, y, LAYOUT_MAX_WIDTH, RED);
}
}

private void renderChangedWarning(@Nonnull Minecraft minecraft, int width, int height) {
private void renderChangedWarning(@Nonnull PoseStack poseStack, @Nonnull Minecraft minecraft, int width, int height) {
int x = getHorizontalLayoutStart(width);
int y = height - 50;

minecraft.font.drawWordWrap(changedWarningText, x, y, LAYOUT_MAX_WIDTH, YELLOW);
minecraft.font.drawWordWrap(poseStack, changedWarningText, x, y, LAYOUT_MAX_WIDTH, YELLOW);
}

private String getDescriptionKey() {
FullscreenModeConfig mode = Config.GENERAL.fullscreenMode.get();
String modeKey = String.format(DESCRIPTION_KEY_BASE, mode.name().toLowerCase());

if (mode != FullscreenModeConfig.NATIVE) {
return modeKey;
} else {
if (mode == FullscreenModeConfig.NATIVE) {
FocusLossConfig focusLoss = Config.GENERAL.focusLoss.get();

return String.format("%s.%s", modeKey, focusLoss.name().toLowerCase());
} else {
return modeKey;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import de.nekeras.borderless.config.Config;
import de.nekeras.borderless.config.FocusLossConfig;
import de.nekeras.borderless.config.FullscreenModeConfig;
import net.minecraft.client.Minecraft;
import net.minecraft.client.OptionInstance;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.network.chat.Component;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
Expand All @@ -21,7 +23,7 @@ public class ConfigScreenOption {

public static final OptionInstance<Boolean> enabled = OptionInstance.createBoolean(
ENABLED_KEY,
mc -> value -> mc.font.split(enabledTooltip, 200),
value -> Tooltip.create(enabledTooltip),
Config.GENERAL.enabled.get(),
Config.GENERAL.enabled::set
);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
modLoader = "javafml"
loaderVersion = "[41,)"
loaderVersion = "[44,)"
license = "MIT License"
issueTrackerURL = "https://github.com/Nekeras/borderless/issues"

Expand Down

0 comments on commit 599fac4

Please sign in to comment.