Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extremely basic fullscreen toggler #29

Merged
merged 9 commits into from
Aug 19, 2023
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
14 changes: 14 additions & 0 deletions src/main/java/dev/lambdaurora/lambdamap/LambdaMapConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
public final class LambdaMapConfig {
private static final boolean DEFAULT_RENDER_BIOME_COLORS = true;
private static final boolean DEFAULT_SHOW_HUD = true;
private static final boolean DEFAULT_FULLSCREEN = false;
private static final int DEFAULT_HUD_SCALE = 2;
private static final boolean DEFAULT_SHOW_DIRECTION_INDICATORS = true;
private static final boolean DEFAULT_NORTH_LOCK = false;
Expand All @@ -65,6 +66,7 @@ public final class LambdaMapConfig {

private boolean renderBiomeColors;
private boolean showHud;
private boolean worldMapFullscreen;
private int hudScale;
private boolean northLock;
private boolean showDirectionIndicators;
Expand Down Expand Up @@ -125,6 +127,7 @@ public void load() {
return null;
}).map(HudDecorators::get)
.orElse(HudDecorators.MAP);
this.worldMapFullscreen = this.config.getOrElse("map.config.world_map.fullscreen", DEFAULT_FULLSCREEN);

LOGGER.info("Configuration loaded.");
}
Expand All @@ -144,6 +147,8 @@ public void reset() {
this.setHudVisible(DEFAULT_SHOW_HUD);
this.setHudScale(DEFAULT_HUD_SCALE);
this.setNorthLock(DEFAULT_NORTH_LOCK);
this.setDirectionIndicatorsVisible(DEFAULT_SHOW_DIRECTION_INDICATORS);
this.setHudDecorator(HudDecorators.MAP);
}

public boolean shouldRenderBiomeColors() {
Expand Down Expand Up @@ -248,4 +253,13 @@ public void setHudDecorator(HudDecorator decorator) {
public SpruceOption getHudDecoratorOption() {
return this.hudDecoratorOption;
}

public void setWorldMapFullscreen(boolean visible) {
this.worldMapFullscreen = visible;
this.config.set("map.config.fullscreen", visible);
}

public Boolean isWorldMapFullscreen() {
return this.worldMapFullscreen;
}
}
20 changes: 12 additions & 8 deletions src/main/java/dev/lambdaurora/lambdamap/gui/WorldMapScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,18 @@ public void removed() {
protected void init() {
super.init();

SpruceTabbedWidget tabs = this.addDrawableChild(new SpruceTabbedWidget(Position.origin(), this.width, this.height, Text.literal("LambdaMap")));
tabs.getList().setBackground(RandomPrideFlagBackground.random());
tabs.addTabEntry(Text.translatable("lambdamap.tabs.world_map"), Text.translatable("lambdamap.tabs.world_map.description").formatted(Formatting.GRAY),
(width, height) -> new WorldMapWidget(Position.origin(), width, height));
tabs.addTabEntry(Text.translatable("lambdamap.tabs.markers"), Text.translatable("lambdamap.tabs.markers.description").formatted(Formatting.GRAY),
(width, height) -> new MarkerTabWidget(mod, Position.origin(), width, height));
tabs.addTabEntry(Text.translatable("lambdamap.tabs.config"), Text.translatable("lambdamap.tabs.config.description").formatted(Formatting.GRAY),
this::buildConfigTab);
if (this.mod.getConfig().isWorldMapFullscreen()) {
this.addDrawableChild(new WorldMapWidget(Position.origin(), width, height));
} else {
SpruceTabbedWidget tabs = this.addDrawableChild(new SpruceTabbedWidget(Position.origin(), this.width, this.height, Text.literal("LambdaMap")));
tabs.getList().setBackground(RandomPrideFlagBackground.random());
tabs.addTabEntry(Text.translatable("lambdamap.tabs.world_map"), Text.translatable("lambdamap.tabs.world_map.description").formatted(Formatting.GRAY),
(width, height) -> new WorldMapWidget(Position.origin(), width, height));
tabs.addTabEntry(Text.translatable("lambdamap.tabs.markers"), Text.translatable("lambdamap.tabs.markers.description").formatted(Formatting.GRAY),
(width, height) -> new MarkerTabWidget(this.mod, Position.origin(), width, height));
tabs.addTabEntry(Text.translatable("lambdamap.tabs.config"), Text.translatable("lambdamap.tabs.config.description").formatted(Formatting.GRAY),
this::buildConfigTab);
}
}

private SpruceOptionListWidget buildConfigTab(int width, int height) {
Expand Down
36 changes: 31 additions & 5 deletions src/main/java/dev/lambdaurora/lambdamap/gui/WorldMapWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ public boolean onNavigation(NavigationDirection direction, boolean tab) {

@Override
protected boolean onMouseClick(double mouseX, double mouseY, int button) {
double mouseXOffset = mouseX - this.getX();
double mouseYOffset = mouseY - this.getY();

if (mouseXOffset > 0 && mouseXOffset < this.renderer.width() * this.scale && mouseYOffset > this.renderer.height() * this.scale) {
this.mod.getConfig().setWorldMapFullscreen(!this.mod.getConfig().isWorldMapFullscreen());
this.client.setScreen(new WorldMapScreen());
}

return button == GLFW.GLFW_MOUSE_BUTTON_1;
}

Expand Down Expand Up @@ -133,7 +141,9 @@ protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float
if (this.renderer.scale() != 1) {
scaleCompensation = this.renderer.scale();
}
if (mouseXOffset > 0 && mouseXOffset < this.renderer.width() * this.scale && mouseYOffset > 0 && mouseYOffset < this.renderer.height() * this.scale) {

if (mouseXOffset > 0 && mouseXOffset < this.renderer.width() * this.scale
&& mouseYOffset > 0 && mouseYOffset < this.renderer.height() * this.scale) {
float x = this.renderer.cornerX() + mouseXOffset * scaleCompensation;
float z = this.renderer.cornerZ() + mouseYOffset * scaleCompensation;
graphics.drawCenteredShadowedText(this.client.textRenderer, String.format("X: %.1f Z: %.1f", x, z),
Expand All @@ -153,10 +163,26 @@ protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float
}
}

var scale = "1:" + this.renderer.scale();
if (this.intScale < 0) {
scale = -this.intScale + ":1";
if (!this.mod.getConfig().isWorldMapFullscreen()
|| mouseXOffset <= 0 || mouseYOffset < this.renderer.height() * this.scale) {
var scale = "1:" + this.renderer.scale();
if (this.intScale < 0) {
scale = -this.intScale + ":1";
}
graphics.drawShadowedText(this.client.textRenderer, scale, this.getX(), this.getY() + this.getHeight() - 9, 0xffffffff);
}

if (mouseXOffset > 0 && mouseYOffset >= this.renderer.height() * this.scale) {
if (this.mod.getConfig().isWorldMapFullscreen())
graphics.drawShadowedText(this.client.textRenderer, "LambdaMap",
this.getX(), this.getY() + this.getHeight() - 9,
0xffffffff
);
else
graphics.drawCenteredShadowedText(this.client.textRenderer, "[Toggle Fullscreen]",
this.getX() + this.getWidth() / 2, this.getY() + this.getHeight() - 9,
0xffffffff
);
}
graphics.drawShadowedText(this.client.textRenderer, scale, this.getX(), this.getY() + this.getHeight() - 9, 0xffffffff);
}
}
Loading