Adding more implementations
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package org.saturnclient.common.minecraft;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.saturnclient.common.minecraft.bindings.SaturnIdentifier;
|
||||
|
||||
public interface IMinecraftClient {
|
||||
public File getRunDirectory();
|
||||
|
||||
public InputStream getResource(SaturnIdentifier identifier);
|
||||
}
|
||||
@@ -6,4 +6,13 @@ public class MinecraftBinding {
|
||||
public MinecraftBinding(Object binding) {
|
||||
this.inner = binding;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T get() {
|
||||
try {
|
||||
return (T) inner;
|
||||
} catch (ClassCastException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
package org.saturnclient.common.minecraft;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.saturnclient.common.minecraft.bindings.SaturnIdentifier;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public abstract class MinecraftProvider {
|
||||
public static MinecraftProvider PROVIDER;
|
||||
|
||||
public abstract IMinecraftClient getClient();
|
||||
|
||||
public abstract Object createIdentifier(String namespace, String path);
|
||||
|
||||
public abstract boolean isKeyPressed(int key);
|
||||
|
||||
public abstract File getRunDirectory();
|
||||
|
||||
public abstract int getWidth(String text, int font);
|
||||
|
||||
public abstract void registerBufferedImageTexture(SaturnIdentifier i, BufferedImage bi);
|
||||
|
||||
@@ -23,7 +23,7 @@ public class Config {
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
File configFile = new File(MinecraftProvider.PROVIDER.getRunDirectory(), "saturn.json");
|
||||
File configFile = new File(MinecraftProvider.PROVIDER.getClient().getRunDirectory(), "saturn.json");
|
||||
config = new ConfigManager(configFile, "Saturn Client");
|
||||
|
||||
config.property("Realistic logo", realisticLogo);
|
||||
|
||||
@@ -52,8 +52,6 @@ public interface RenderScope {
|
||||
|
||||
public void drawItemWithoutEntity(SaturnItemStack stack, int x, int y, int seed);
|
||||
|
||||
public void drawItem(SaturnItemStack entity, SaturnItemStack stack, int x, int y, int seed);
|
||||
|
||||
public void drawSpriteStretched(SaturnSprite sprite, int x, int y, int width, int height);
|
||||
|
||||
public void drawSpriteStretched(SaturnSprite sprite, int x, int y, int width, int height, int color);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.saturnclient.ui.elements;
|
||||
|
||||
import org.saturnclient.common.minecraft.IMinecraftClient;
|
||||
import org.saturnclient.common.minecraft.MinecraftProvider;
|
||||
import org.saturnclient.common.minecraft.bindings.SaturnIdentifier;
|
||||
import org.saturnclient.ui.Element;
|
||||
import org.saturnclient.ui.ElementContext;
|
||||
@@ -15,11 +17,12 @@ public class ImageTexture extends Element {
|
||||
@Override
|
||||
public void render(RenderScope renderScope, ElementContext ctx) {
|
||||
if (sprite.toString().endsWith(".svg")) {
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
IMinecraftClient client = MinecraftProvider.PROVIDER.getClient();
|
||||
|
||||
// Get the actual window pixel dimensions for the image
|
||||
int renderWidth = (int) (width * client.getWindow().getFramebufferWidth() / client.getWindow().getWidth());
|
||||
int renderHeight = (int) (height * client.getWindow().getFramebufferHeight() / client.getWindow().getHeight());
|
||||
int renderHeight = (int) (height * client.getWindow().getFramebufferHeight()
|
||||
/ client.getWindow().getHeight());
|
||||
|
||||
sprite = SvgTexture.getSvg(client, sprite, renderWidth * 2, renderHeight * 2);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.saturnclient.config.manager.Property;
|
||||
import org.saturnclient.ui.Element;
|
||||
import org.saturnclient.ui.ElementContext;
|
||||
import org.saturnclient.ui.RenderScope;
|
||||
import org.saturnclient.ui.components.ElementRenderer;
|
||||
|
||||
public class Scroll extends Element {
|
||||
private static Property<Integer> scrollBarRadius = Property.integer(10);
|
||||
|
||||
@@ -6,16 +6,13 @@ import org.saturnclient.ui.Element;
|
||||
import org.saturnclient.ui.ElementContext;
|
||||
import org.saturnclient.ui.RenderScope;
|
||||
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class TextureButton extends Element {
|
||||
Identifier sprite;
|
||||
SaturnIdentifier sprite;
|
||||
private Runnable onClick;
|
||||
static int padding = 14;
|
||||
|
||||
public TextureButton(SaturnIdentifier sprite, Runnable onClick) {
|
||||
this.sprite = (Identifier) sprite.inner;
|
||||
this.sprite = sprite;
|
||||
this.onClick = onClick;
|
||||
}
|
||||
|
||||
@@ -24,8 +21,6 @@ public class TextureButton extends Element {
|
||||
renderScope.drawRoundedRectangle(0, 0, width, height, Theme.WIDGET_RADIUS.value,
|
||||
ctx.isHovering() ? Theme.ACCENT.value : Theme.PRIMARY.value);
|
||||
|
||||
renderScope.setRenderLayer(RenderLayer::getGuiTextured);
|
||||
|
||||
int texWidth = width - padding;
|
||||
int texHeight = height - padding;
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ import java.util.List;
|
||||
|
||||
import com.kitfox.svg.SVGDiagram;
|
||||
import com.kitfox.svg.SVGUniverse;
|
||||
|
||||
import org.saturnclient.common.minecraft.IMinecraftClient;
|
||||
import org.saturnclient.common.minecraft.bindings.SaturnIdentifier;
|
||||
|
||||
public class SvgTexture {
|
||||
@@ -47,7 +49,7 @@ public class SvgTexture {
|
||||
return image;
|
||||
}
|
||||
|
||||
public static SaturnIdentifier getSvg(MinecraftClient client, SaturnIdentifier svgImage, int width, int height) {
|
||||
public static SaturnIdentifier getSvg(IMinecraftClient client, SaturnIdentifier svgImage, int width, int height) {
|
||||
SaturnIdentifier id = SaturnIdentifier
|
||||
.of(svgImage.toString().replaceAll("\\.svg$", (width + "_" + height).toString() + ".png"));
|
||||
|
||||
@@ -55,10 +57,7 @@ public class SvgTexture {
|
||||
return id;
|
||||
}
|
||||
|
||||
try (InputStream svgStream = client
|
||||
.getResourceManager()
|
||||
.getResource(svgImage).get()
|
||||
.getInputStream()) {
|
||||
try (InputStream svgStream = client.getResource(svgImage)) {
|
||||
|
||||
BufferedImage image = renderSvg(svgStream, width, height);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user