Skip to content

Commit

Permalink
Begun refactoring and migration to MUI2
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdmandt committed Jan 14, 2025
1 parent 8cc0844 commit 541475a
Show file tree
Hide file tree
Showing 15 changed files with 341 additions and 109 deletions.
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
*/
dependencies {
shadowImplementation('com.github.cliftonlabs:json-simple:4.0.1')
implementation("com.github.GTNewHorizons:ModularUI2:2.1.14-1.7.10:dev")

runtimeOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.5.4-GTNH:dev")
runtimeOnlyNonPublishable("com.github.GTNewHorizons:GTNH-Web-Map:0.3.29:dev")
Expand Down
13 changes: 12 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ accessTransformersFile =
# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
usesMixins = false

# Set to a non-empty string to configure mixins in a separate source set under src/VALUE, instead of src/main.
# This can speed up compile times thanks to not running the mixin annotation processor on all input sources.
# Mixin classes will have access to "main" classes, but not the other way around.
separateMixinSourceSet =

# Adds some debug arguments like verbose output and class export.
usesMixinDebug = false

Expand Down Expand Up @@ -108,9 +113,15 @@ minimizeShadowedDependencies = true
# If disabled, won't rename the shadowed classes.
relocateShadowedDependencies = true

# Adds the GTNH maven, CurseMaven, Modrinth, and some more well-known 1.7.10 repositories.
# Adds CurseMaven, Modrinth, and some more well-known 1.7.10 repositories.
includeWellKnownRepositories = true

# A list of repositories to exclude from the includeWellKnownRepositories setting. Should be a space separated
# list of strings, with the acceptable keys being(case does not matter):
# cursemaven
# modrinth
excludeWellKnownRepositories =

# Change these to your Maven coordinates if you want to publish to a custom Maven repository instead of the default GTNH Maven.
# Authenticate with the MAVEN_USER and MAVEN_PASSWORD environment variables.
# If you need a more complex setup disable maven publishing here and add a publishing repository to addon.gradle.
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ pluginManagement {
}

plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.22'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.31'
}
4 changes: 4 additions & 0 deletions src/main/java/com/gtnewhorizons/gwmclient/ClientProxy.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.gtnewhorizons.gwmclient;

import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.common.MinecraftForge;

import com.gtnewhorizons.gwmclient.client.ClientEvents;
import com.gtnewhorizons.gwmclient.client.KeyBindings;
import com.gtnewhorizons.gwmclient.command.GwmcCommand;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
Expand All @@ -22,5 +24,7 @@ public void preInit(FMLPreInitializationEvent event) {
FMLCommonHandler.instance()
.bus()
.register(ClientEvents.INSTANCE);

ClientCommandHandler.instance.registerCommand(new GwmcCommand());
}
}
23 changes: 22 additions & 1 deletion src/main/java/com/gtnewhorizons/gwmclient/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,35 @@
import java.io.File;

import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;

public class Config {

private static File configFile;
private static String remoteUrlBase;
private static Property remoteUrlProperty;
static Configuration configuration;

public static void synchronizeConfiguration(File configFile) {
Configuration configuration = new Configuration(configFile);
Config.configFile = configFile;
if (configuration == null) configuration = new Configuration(configFile);

if (remoteUrlProperty == null)
remoteUrlProperty = configuration.get("remote", "baseUrl", "http://127.0.0.1:8123");

remoteUrlBase = remoteUrlProperty.getString();

if (configuration.hasChanged()) {
configuration.save();
}
}

public static void setRemoteUrlBase(String newRemoteUrlBase) {
remoteUrlBase = newRemoteUrlBase;
remoteUrlProperty.set(remoteUrlBase);
if (configuration.hasChanged()) {
configuration.save();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import net.minecraft.client.Minecraft;

import com.cleanroommc.modularui.factory.ClientGUI;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;
import cpw.mods.fml.relauncher.Side;
Expand All @@ -16,7 +18,9 @@ public class ClientEvents {
public void onKey(InputEvent.KeyInputEvent event) {
if (KeyBindings.openMap.isPressed()) {
Minecraft mc = Minecraft.getMinecraft();
mc.displayGuiScreen(new MapScreen());
// mc.displayGuiScreen(new MapScreen());

ClientGUI.open(ModularTest.createGUI());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
package com.gtnewhorizons.gwmclient.client;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;

import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.Point;
import org.lwjgl.util.Rectangle;

import com.github.cliftonlabs.json_simple.JsonArray;
import com.github.cliftonlabs.json_simple.JsonException;
import com.github.cliftonlabs.json_simple.JsonObject;
import com.github.cliftonlabs.json_simple.Jsoner;
import com.cleanroommc.modularui.widget.sizer.Area;
import com.gtnewhorizons.gwmclient.storage.PerMapTileDataBase;
import com.gtnewhorizons.gwmclient.storage.RemoteConfiguration;
import com.gtnewhorizons.gwmclient.storage.Tile;

public class MapScreen extends GuiScreen {
public class MapDrawer {

static ExecutorService backgroundLoader = Executors.newSingleThreadExecutor();
RemoteConfiguration remoteConfig;
private final int width;
private final int height;
Rectangle drawArea = new Rectangle(0, 0, 100, 100);

PerMapTileDataBase currentMap;
Expand All @@ -39,7 +34,9 @@ public class MapScreen extends GuiScreen {

boolean loadingMapList = true;

public MapScreen() {
public MapDrawer(int width, int height) {
this.width = width;
this.height = height;

backgroundLoader.submit(() -> loadMapList());

Expand All @@ -49,44 +46,14 @@ public MapScreen() {
}

private void loadMapList() {
try {
URL imageURL = new URL("http://127.0.0.1:8123/up/configuration");
InputStream is = imageURL.openConnection()
.getInputStream();

JsonObject jsonObject = (JsonObject) Jsoner.deserialize(new InputStreamReader(is));
remoteConfig = new RemoteConfiguration();
remoteConfig.load();

JsonArray worlds = (JsonArray) jsonObject.get("worlds");
allMaps = remoteConfig.allMaps;

for (Object obj : worlds) {
if (obj instanceof JsonObject worldObj) {
String worldName = (String) worldObj.get("name");
String worldTitle = (String) worldObj.get("title");

JsonArray mapsArr = (JsonArray) worldObj.get("maps");

for (Object tmpMapObj : mapsArr) {
if (tmpMapObj instanceof JsonObject mapObj) {
String mapName = (String) mapObj.get("name");
String mapTitle = (String) mapObj.get("title");
String mapPrefix = (String) mapObj.get("prefix");

allMaps.add(new PerMapTileDataBase(worldName, mapPrefix, worldTitle + " - " + mapTitle));
}
}
}
}

if (allMaps.size() > 0) {
currentMap = allMaps.get(0);
}

} catch (MalformedURLException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (JsonException e) {
throw new RuntimeException(e);
if (allMaps.size() > 0) {
currentMap = allMaps.get(0);
}
loadingMapList = false;
}
Expand All @@ -96,15 +63,10 @@ Tile getTile(int x, int y, int zoom) {
return currentMap.getTileAt(x, y, zoom);
}

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);

drawBackground(0);

void draw() {
if (currentMap == null) {
if (loadingMapList) drawString(fontRendererObj, "Loading maps...", 10, 10, 0xFFFFFF);
else drawString(fontRendererObj, "Failed to load maps!", 10, 10, 0xFF0000);
// if (loadingMapList) drawString(fontRendererObj, "Loading maps...", 10, 10, 0xFFFFFF);
// else drawString(fontRendererObj, "Failed to load maps!", 10, 10, 0xFF0000);
return;
}

Expand Down Expand Up @@ -174,16 +136,16 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
}
}

drawString(fontRendererObj, currentMap.title, 10, 10, 0xFFFFFF);
// drawString(fontRendererObj, currentMap.title, 10, 10, 0xFFFFFF);
}

Point lastMousePos;
Point dragStartMousePos;
double dragStartViewX, dragStartViewY;
boolean dragging;

@Override
public void handleMouseInput() {
Minecraft mc = Minecraft.getMinecraft();
boolean lmbDown = Mouse.isButtonDown(0);
Point currentMousePos = new Point(
(Mouse.getEventX() * width) / mc.displayWidth,
Expand Down Expand Up @@ -212,48 +174,26 @@ public void handleMouseInput() {
dragStartViewY = viewPortY;
}
}

if (wheel < 0) {
viewPortW *= 2;
viewPortH = viewPortW * drawArea.getHeight() / drawArea.getWidth();

viewPortX -= viewPortW / 4;
viewPortY -= viewPortH / 4;
} else if (wheel > 0) {
double mouseOverX = (currentMousePos.getX() - drawArea.getX()) * viewPortW / drawArea.getWidth()
+ viewPortX;
double mouseOverY = (currentMousePos.getY() - drawArea.getY()) * viewPortH / drawArea.getHeight()
+ viewPortY;

viewPortX += (mouseOverX - viewPortX) / 2;
viewPortY += (mouseOverY - viewPortY) / 2;

viewPortW /= 2;
viewPortH = viewPortW * drawArea.getHeight() / drawArea.getWidth();
}

lastMousePos = currentMousePos;
}

@Override
public void handleKeyboardInput() {
super.handleKeyboardInput();
}
public void zoomIn(Point currentMousePos) {
double mouseOverX = (currentMousePos.getX() - drawArea.getX()) * viewPortW / drawArea.getWidth() + viewPortX;
double mouseOverY = (currentMousePos.getY() - drawArea.getY()) * viewPortH / drawArea.getHeight() + viewPortY;

@Override
protected void keyTyped(char typedChar, int keyCode) {
super.keyTyped(typedChar, keyCode);
viewPortX += (mouseOverX - viewPortX) / 2;
viewPortY += (mouseOverY - viewPortY) / 2;

switch (keyCode) {
case Keyboard.KEY_HOME:
setNewMapIndex(currentMapIndex - 1);
break;
case Keyboard.KEY_END:
setNewMapIndex(currentMapIndex + 1);
viewPortW /= 2;
viewPortH = viewPortW * drawArea.getHeight() / drawArea.getWidth();
}

break;
}
public void zoomOut(Point currentMousePos) {
viewPortW *= 2;
viewPortH = viewPortW * drawArea.getHeight() / drawArea.getWidth();

viewPortX -= viewPortW / 4;
viewPortY -= viewPortH / 4;
}

void setNewMapIndex(int newIndex) {
Expand All @@ -265,20 +205,19 @@ void setNewMapIndex(int newIndex) {
currentMapIndex = newIndex;
}

@Override
public void updateScreen() {
super.updateScreen();
public void updateScreen(Area a) {
drawArea.setSize(a.w(), a.h());

drawArea.setSize(this.width, this.height);

if (viewPortW <= 0) viewPortW = this.width / 128.0;
if (viewPortW <= 0) viewPortW = a.w() / 128.0;

viewPortH = viewPortW * drawArea.getHeight() / drawArea.getWidth();
}

@Override
public void onGuiClosed() {
super.onGuiClosed();
public void onClose() {
currentMap.clear();
}

public int getCurrentMapIndex() {
return currentMapIndex;
}
}
Loading

0 comments on commit 541475a

Please sign in to comment.