Skip to content

Commit

Permalink
Use new APIs where possible in Terramap core module
Browse files Browse the repository at this point in the history
  • Loading branch information
SmylerMC committed Jun 17, 2024
1 parent 7bf37c7 commit 9d77efa
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.UUID;

import fr.thesmyler.smylibgui.toast.TextureToast;
import net.smyler.smylib.game.GameClient;
import net.smyler.smylib.game.MinecraftServerInfo;
import fr.thesmyler.terramap.saving.client.ClientSaveManager;
import fr.thesmyler.terramap.saving.client.SavedClientState;
Expand Down Expand Up @@ -500,15 +501,17 @@ public void tryShowWelcomeToast() {
}

public void openMap() {
getGameClient().displayScreen(new TerramapScreen(Minecraft.getMinecraft().currentScreen, this.getSavedState().mainScreen));
GameClient client = getGameClient();
client.displayScreen(new TerramapScreen(client.getCurrentScreen(), this.getSavedState().mainScreen));
}

public void openMapAt(double zoom, double lon, double lat) {
SavedMainScreenState state = this.getSavedState().mainScreen;
GameClient client = getGameClient();
state.map.center.set(lon, lat);
state.map.zoom = zoom;
state.map.trackedMarker = null;
getGameClient().displayScreen(new TerramapScreen(Minecraft.getMinecraft().currentScreen, state));
client.displayScreen(new TerramapScreen(client.getCurrentScreen(), state));
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.*;
import java.util.function.Consumer;

import net.minecraft.util.text.TextFormatting;
import net.smyler.smylib.game.Key;
import net.smyler.smylib.gui.DrawContext;
import net.smyler.smylib.gui.Scissor;
Expand Down Expand Up @@ -62,10 +61,8 @@
import net.buildtheearth.terraplusplus.projection.GeographicProjection;
import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.profiler.Profiler.Result;
import net.minecraft.util.ITabCompleter;
import org.lwjgl.input.Keyboard;

import static fr.thesmyler.terramap.gui.widgets.map.MapLayerRegistry.LayerRegistration;
import static fr.thesmyler.terramap.util.geo.GeoServices.formatZoomLevelForDisplay;
Expand All @@ -75,13 +72,14 @@
import static net.smyler.smylib.game.Key.*;
import static net.smyler.smylib.math.Math.clamp;
import static java.util.stream.Collectors.toMap;
import static net.smyler.smylib.text.Formatting.*;
import static net.smyler.smylib.text.ImmutableText.ofPlainText;
import static net.smyler.smylib.text.ImmutableText.ofTranslation;


public class TerramapScreen extends Screen implements ITabCompleter {

private final GuiScreen parent;
private final Screen parent;

private final ChatWidget chat = new ChatWidget(1000);

Expand Down Expand Up @@ -118,7 +116,7 @@ public class TerramapScreen extends Screen implements ITabCompleter {
private boolean f1Mode = false;
private boolean debugMode = false;

public TerramapScreen(GuiScreen parent, SavedMainScreenState state) {
public TerramapScreen(Screen parent, SavedMainScreenState state) {
super(BackgroundOption.OVERLAY);
this.parent = parent;
this.map = new MapWidget(10, MapContext.FULLSCREEN, TerramapConfig.CLIENT.getEffectiveTileScaling());
Expand Down Expand Up @@ -152,7 +150,7 @@ public void init() {

// Map control buttons
this.closeButton.setX(width - this.closeButton.getWidth() - 5).setY(5);
this.closeButton.setOnClick(() -> Minecraft.getMinecraft().displayGuiScreen(this.parent));
this.closeButton.setOnClick(() -> game.displayScreen(this.parent));
this.closeButton.setTooltip(translator.format("terramap.terramapscreen.buttons.close.tooltip"));
this.closeButton.enable();
this.addWidget(this.closeButton);
Expand Down Expand Up @@ -416,7 +414,7 @@ public void onUpdate(float mouseX, float mouseY, WidgetContainer parent) {
Locale locale = Locale.US;
TerramapClientContext srv = TerramapClientContext.getContext();
EarthGeneratorSettings generationSettings = srv.getGeneratorSettings();
debugBuilder.append(String.format(locale, "FPS: %s", Minecraft.getDebugFPS()));
debugBuilder.append(String.format(locale, "FPS: %s", getGameClient().currentFPS()));
debugBuilder.append(String.format(locale, "\nClient: %s", TerramapMod.getVersion()));
debugBuilder.append(String.format(locale, "\nServer: %s", srv.getServerVersion()));
debugBuilder.append(String.format(locale, "\nSledgehammer: %s", srv.getSledgehammerVersion()));
Expand All @@ -439,11 +437,11 @@ public void onUpdate(float mouseX, float mouseY, WidgetContainer parent) {
debugBuilder.append(String.format(locale, "\nScaling: %.2f/%s", this.map.getTileScaling(), getGameClient().scaleFactor()));
debugBuilder.append("\n\n");
debugBuilder.append("Locations: ")
.append(TextFormatting.RED).append("center ")
.append(TextFormatting.BLUE).append("center target ")
.append(TextFormatting.GREEN).append("zoom target ")
.append(TextFormatting.GOLD).append("rotation target ")
.append(TextFormatting.RESET);
.append(RED).append("center ")
.append(BLUE).append("center target ")
.append(GREEN).append("zoom target ")
.append(GOLD).append("rotation target ")
.append(RESET);
debugBuilder.append('\n');
this.buildProfilingResult(debugBuilder, "", "");
this.debugText.setText(ofPlainText(debugBuilder.toString()));
Expand Down Expand Up @@ -509,14 +507,14 @@ public void onKeyTyped(char typedChar, Key key, WidgetContainer parent) {
if(this.getFocusedWidget() == null || (!this.getFocusedWidget().equals(this.searchBox) && !this.chat.isOpen())) {
MapController controller = this.map.getController();
if(key.code == KeyBindings.TOGGLE_DEBUG.getKeyCode()) this.setDebugMode(!this.debugMode);
if(key.code == Keyboard.KEY_F1) this.setF1Mode(!this.f1Mode);
if(key == KEY_F1) this.setF1Mode(!this.f1Mode);
if(key.code == Minecraft.getMinecraft().gameSettings.keyBindForward.getKeyCode() || key == KEY_UP) controller.moveMap(0, 30, true);
if(key.code == Minecraft.getMinecraft().gameSettings.keyBindBack.getKeyCode() || key == KEY_DOWN) controller.moveMap(0, -30, true);
if(key.code == Minecraft.getMinecraft().gameSettings.keyBindRight.getKeyCode() || key == KEY_RIGHT) controller.moveMap(-30, 0, true);
if(key.code == Minecraft.getMinecraft().gameSettings.keyBindLeft.getKeyCode() || key == KEY_LEFT) controller.moveMap(30, 0, true);
if(key.code == KeyBindings.ZOOM_IN.getKeyCode()) this.zoomInButton.getOnClick().run();
if(key.code == KeyBindings.ZOOM_OUT.getKeyCode()) this.zoomOutButton.getOnClick().run();
if(key.code == KeyBindings.OPEN_MAP.getKeyCode() || key == KEY_ESCAPE) Minecraft.getMinecraft().displayGuiScreen(this.parent);
if(key.code == KeyBindings.OPEN_MAP.getKeyCode() || key == KEY_ESCAPE) getGameClient().displayScreen(this.parent);
if(key.code == Minecraft.getMinecraft().gameSettings.keyBindChat.getKeyCode()) {
this.map.stopPassiveInputs();
this.chat.setOpen(!this.chat.isOpen());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ private void saveAndClose() {
}

private void close() {
Minecraft.getMinecraft().displayGuiScreen(null);
getGameClient().displayScreen(null);
}

private void reset() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public boolean onClick(float mouseX, float mouseY, int mouseButton, WidgetContai
if(this.isShortcutEnabled()) {
this.map.getRightClickMenu().teleport();
if(this.map.getContext().equals(MapContext.FULLSCREEN)) {
Minecraft.getMinecraft().displayGuiScreen(null); //TODO change this so it can work from any menu
getGameClient().displayScreen(null); //TODO change this so it can work from any menu
}
}
if(this.map.isRightClickMenuEnabled() && mouseButton == 1 && WebMercatorUtil.PROJECTION_BOUNDS.contains(this.mouseLocation)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.smyler.smylib.gui.containers.FlexibleWidgetContainer;
import net.smyler.smylib.gui.containers.WidgetContainer;
import net.smyler.smylib.Color;
import fr.thesmyler.smylibgui.util.RenderUtil;
import fr.thesmyler.terramap.gui.widgets.map.MapLayer;
import fr.thesmyler.terramap.gui.widgets.map.MapWidget;
import net.smyler.smylib.gui.DrawContext;
Expand Down

0 comments on commit 9d77efa

Please sign in to comment.