Skip to content

Commit

Permalink
Refactor window mode option
Browse files Browse the repository at this point in the history
  • Loading branch information
xCollateral committed Dec 13, 2024
1 parent 70d5cdc commit d8f2073
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/vulkanmod/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Config {

public int frameQueueSize = 2;
public VideoModeSet.VideoMode videoMode = VideoModeManager.getFirstAvailable().getVideoMode();
public boolean windowedFullscreen = false;
public int windowMode = 0;

public int advCulling = 2;
public boolean indirectDraw = true;
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/net/vulkanmod/config/option/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.vulkanmod.config.gui.OptionBlock;
import net.vulkanmod.config.video.VideoModeManager;
import net.vulkanmod.config.video.VideoModeSet;
import net.vulkanmod.config.video.WindowMode;
import net.vulkanmod.render.chunk.build.light.LightMode;
import net.vulkanmod.render.vertex.TerrainRenderType;
import net.vulkanmod.vulkan.Renderer;
Expand Down Expand Up @@ -77,19 +78,18 @@ public static OptionBlock[] getVideoOpts() {
new OptionBlock("", new Option<?>[]{
resolutionOption,
RefreshRate,
new SwitchOption(Component.translatable("options.fullscreen"),
new CyclingOption<>(Component.translatable("vulkanmod.options.windowMode"),
WindowMode.values(),
value -> {
minecraftOptions.fullscreen().set(value);
// window.toggleFullScreen();
fullscreenDirty = true;
},
() -> minecraftOptions.fullscreen().get()),
new SwitchOption(Component.translatable("vulkanmod.options.windowedFullscreen"),
value -> {
config.windowedFullscreen = value;
boolean exclusiveFullscreen = value == WindowMode.EXCLUSIVE_FULLSCREEN;
minecraftOptions.fullscreen()
.set(exclusiveFullscreen);

config.windowMode = value.mode;
fullscreenDirty = true;
},
() -> config.windowedFullscreen),
() -> WindowMode.fromValue(config.windowMode))
.setTranslator(value -> Component.translatable(WindowMode.getComponentName(value))),
new RangeOption(Component.translatable("options.framerateLimit"),
10, 260, 10,
value -> Component.nullToEmpty(value == 260 ?
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/net/vulkanmod/config/video/WindowMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.vulkanmod.config.video;

public enum WindowMode {
WINDOWED(0),
WINDOWED_FULLSCREEN(1),
EXCLUSIVE_FULLSCREEN(2);

public final int mode;

WindowMode(int mode) {
this.mode = mode;
}

public static WindowMode fromValue(int value) {
return switch (value) {
case 0 -> WINDOWED;
case 1 -> WINDOWED_FULLSCREEN;
case 2 -> EXCLUSIVE_FULLSCREEN;

default -> throw new IllegalStateException("Unexpected value: " + value);
};
}

public static String getComponentName(WindowMode windowMode) {
return switch (windowMode) {
case WINDOWED -> "vulkanmod.options.windowMode.windowed";
case WINDOWED_FULLSCREEN -> "vulkanmod.options.windowMode.windowedFullscreen";
case EXCLUSIVE_FULLSCREEN -> "options.fullscreen";
};
}
}
3 changes: 2 additions & 1 deletion src/main/java/net/vulkanmod/mixin/window/WindowMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.vulkanmod.config.video.VideoModeManager;
import net.vulkanmod.config.option.Options;
import net.vulkanmod.config.video.VideoModeSet;
import net.vulkanmod.config.video.WindowMode;
import net.vulkanmod.vulkan.Renderer;
import net.vulkanmod.vulkan.VRenderSystem;
import net.vulkanmod.vulkan.Vulkan;
Expand Down Expand Up @@ -163,7 +164,7 @@ private void setMode() {
this.wasOnFullscreen = true;
}
}
else if (config.windowedFullscreen) {
else if (config.windowMode == WindowMode.WINDOWED_FULLSCREEN.mode) {
VideoModeSet.VideoMode videoMode = VideoModeManager.getOsVideoMode();

if (!this.wasOnFullscreen) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/assets/vulkanmod/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@
"vulkanmod.options.uniqueOpaqueLayer": "Unique opaque layer",
"vulkanmod.options.uniqueOpaqueLayer.tooltip": "Use a unique render layer for opaque terrain to improve performance.",

"vulkanmod.options.windowedFullscreen": "Windowed Fullscreen"
"vulkanmod.options.windowMode": "Window Mode",
"vulkanmod.options.windowMode.windowed": "Windowed",
"vulkanmod.options.windowMode.windowedFullscreen": "Windowed Fullscreen"
}

0 comments on commit d8f2073

Please sign in to comment.