Skip to content

Commit

Permalink
Merge branch 'refs/heads/refactor/submodules' into dev/1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
SmylerMC committed Jul 6, 2024
2 parents d3c902f + 94aee40 commit 23b58cc
Show file tree
Hide file tree
Showing 95 changed files with 2,148 additions and 1,933 deletions.
6 changes: 6 additions & 0 deletions core/src/main/java/net/smyler/terramap/Terramap.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.gson.Gson;
import net.smyler.terramap.http.HttpClient;
import net.smyler.terramap.tilesets.raster.RasterTileSetManager;
import org.apache.logging.log4j.Logger;

public interface Terramap {
Expand All @@ -11,6 +12,9 @@ static Terramap instance() {
}

String MOD_ID = "terramap";
String STYLE_UPDATE_HOSTNAME = "styles.terramap.thesmyler.fr"; //TODO use smyler.net

String version();

Logger logger();

Expand All @@ -20,6 +24,8 @@ static Terramap instance() {

Gson gsonPretty();

RasterTileSetManager rasterTileSetManager();

class InstanceHolder {
private static Terramap instance;
public static void setInstance(Terramap instance) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
package fr.thesmyler.terramap.gui.widgets;
package net.smyler.terramap.gui.widgets;

import net.smyler.smylib.gui.DrawContext;
import net.smyler.smylib.gui.GlState;
import net.smyler.smylib.gui.UiDrawContext;
import net.smyler.smylib.gui.gl.GlContext;
import net.smyler.smylib.math.Vec2dMutable;
import org.lwjgl.opengl.GL11;

import net.smyler.smylib.gui.containers.WidgetContainer;
import net.smyler.smylib.Animation;
import net.smyler.smylib.Animation.AnimationState;
import net.smyler.smylib.Color;
import net.smyler.smylib.gui.widgets.Widget;
import net.smyler.smylib.math.Mat2d;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;

import static net.smyler.smylib.Color.WHITE;
import static net.smyler.smylib.Color.*;
import static net.smyler.smylib.gui.gl.DrawMode.*;
import static net.smyler.smylib.gui.gl.VertexFormat.*;

public class CircularCompassWidget implements Widget {

private float azimuth = 0f;
private float x, y, size;
private final int z;
private Color backgroundColor = Color.DARKER_OVERLAY;
private Color northColor = Color.RED;
private Color northDarkColor = Color.RED.withRed(0.4f);
private Color northColor = RED;
private Color northDarkColor = RED.withRed(0.4f);
private Color southColor = WHITE;
private Color southColorDark = new Color(0.4f, 0.4f, 0.4f);
private Runnable onClick;
Expand All @@ -35,7 +32,7 @@ public class CircularCompassWidget implements Widget {

private final Animation fader = new Animation(1000);

private double[] vertices;
private double[][] vertices;
private final Vec2dMutable vertexCalculationHelper = new Vec2dMutable();

public CircularCompassWidget(float x, float y, int z, float size) {
Expand All @@ -46,7 +43,7 @@ public CircularCompassWidget(float x, float y, int z, float size) {
}

@Override
public void draw(DrawContext context, float x, float y, float mouseX, float mouseY, boolean hovered, boolean focused, WidgetContainer parent) {
public void draw(UiDrawContext context, float x, float y, float mouseX, float mouseY, boolean hovered, boolean focused, WidgetContainer parent) {

Color background = this.backgroundColor;
Color north = this.northColor;
Expand All @@ -64,37 +61,41 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous

float radius = this.size / 2;

GlState glState = context.glState();
GlStateManager.pushMatrix();
GlStateManager.translate(x + radius, y + radius, 0);
context.drawPolygon(background, this.vertices);
//RenderUtil.drawClosedStrokeLine(Color.BLACK, 1f, vertices);
GlStateManager.rotate(this.azimuth, 0, 0, 1);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder builder = tessellator.getBuffer();
glState.setColor(WHITE);
GlStateManager.shadeModel(7425);
context.glState().enableAlpha();
GlStateManager.enableBlend();
GlStateManager.disableTexture2D();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
builder.begin(GL11.GL_POLYGON, DefaultVertexFormats.POSITION_COLOR);
builder.pos(0d, -radius, 0d).color(north.redf(), north.greenf(), north.bluef(), north.alphaf()).endVertex();
builder.pos(-radius/3, radius * 0.1, 0d).color(north.redf(), north.greenf(), north.bluef(), north.alphaf()).endVertex();
builder.pos(0d, 0d, 0d).color(north.redf(), north.greenf(), north.bluef(), north.alphaf()).endVertex();
builder.pos(radius/3, radius * 0.1, 0d).color(northDark.redf(), northDark.greenf(), northDark.bluef(), northDark.alphaf()).endVertex();
tessellator.draw();
builder.begin(GL11.GL_POLYGON, DefaultVertexFormats.POSITION_COLOR);
builder.pos(0, 0, 0).color(south.redf(), south.greenf(), south.bluef(), south.alphaf()).endVertex();
builder.pos(-radius/3, radius * 0.1, 0).color(south.redf(), south.greenf(), south.bluef(), south.alphaf()).endVertex();
builder.pos(0, radius, 0).color(south.redf(), south.greenf(), south.bluef(), south.alphaf()).endVertex();
builder.pos(radius/3, radius * 0.1, 0).color(southColor.redf(), southColor.greenf(), southColor.bluef(), southColor.alphaf()).endVertex();
tessellator.draw();
GlStateManager.shadeModel(7424);
context.glState().disableAlpha();
GlStateManager.disableBlend();
GlStateManager.enableTexture2D();
GlStateManager.popMatrix();
GlContext gl = context.gl();
gl.enableSmoothShading();
gl.pushViewMatrix();
gl.translate(x + radius, y + radius);

// Background dark circle
gl.startDrawing(TRIANGLE_FAN, POSITION);
gl.setColor(background);
gl.vertex().position(0d, 0d, 0d).end();
for (double[] vertex : this.vertices) {
gl.vertex().position(vertex[0], vertex[1], 0d).end();
}
gl.vertex().position(this.vertices[0][0], this.vertices[0][1], 0d).end();
gl.draw();

gl.rotate(this.azimuth);

// North arrow
gl.startDrawing(TRIANGLE_FAN, POSITION_COLOR);
gl.setColor(WHITE);
gl.vertex().position(0d, -radius, 0d).color(north.redf(), north.greenf(), north.bluef(), north.alphaf()).end();
gl.vertex().position(-radius/3, radius * 0.1, 0d).color(north.redf(), north.greenf(), north.bluef(), north.alphaf()).end();
gl.vertex().position(0d, 0d, 0d).color(north.redf(), north.greenf(), north.bluef(), north.alphaf()).end();
gl.vertex().position(radius/3, radius * 0.1, 0d).color(northDark.redf(), northDark.greenf(), northDark.bluef(), northDark.alphaf()).end();
gl.draw();

// South arrow
gl.startDrawing(TRIANGLE_FAN, POSITION_COLOR);
gl.vertex().position(0, 0, 0).color(south.redf(), south.greenf(), south.bluef(), south.alphaf()).end();
gl.vertex().position(-radius/3, radius * 0.1, 0).color(south.redf(), south.greenf(), south.bluef(), south.alphaf()).end();
gl.vertex().position(0, radius, 0).color(south.redf(), south.greenf(), south.bluef(), south.alphaf()).end();
gl.vertex().position(radius/3, radius * 0.1, 0).color(southColor.redf(), southColor.greenf(), southColor.bluef(), southColor.alphaf()).end();
gl.draw();

gl.popViewMatrix();
}

@Override
Expand Down Expand Up @@ -167,12 +168,14 @@ public void setSize(float size) {
this.size = size;
int vertexCount = (int) (2*Math.PI*this.size);
float radius = this.size / 2;
this.vertices = new double[vertexCount*2];
this.vertices = new double[vertexCount][2];
this.vertexCalculationHelper.set(0, -radius);
Mat2d rot = Mat2d.forRotation(-Math.PI*2 / vertexCount);
for(int i = 0; i < vertexCount; i++) {
this.vertices[2*i] = this.vertexCalculationHelper.x();
this.vertices[2*i + 1] = this.vertexCalculationHelper.y();
this.vertices[i] = new double[] {
this.vertexCalculationHelper.x(),
this.vertexCalculationHelper.y()
};
this.vertexCalculationHelper.apply(rot);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package net.smyler.terramap.gui.widgets;

import net.smyler.smylib.Identifier;
import net.smyler.smylib.gui.UiDrawContext;
import net.smyler.smylib.gui.gl.GlContext;
import net.smyler.terramap.Terramap;

import net.smyler.smylib.gui.containers.WidgetContainer;
import net.smyler.smylib.gui.widgets.Widget;

import static net.smyler.smylib.Color.WHITE;
import static net.smyler.smylib.gui.gl.DrawMode.QUADS;
import static net.smyler.smylib.gui.gl.VertexFormat.POSITION_TEXTURE;
import static net.smyler.smylib.gui.gl.VertexFormat.POSITION_TEXTURE_COLOR;

public class RibbonCompassWidget implements Widget {

private static final Identifier COMPASS_BACKGROUND_TEXTURE = new Identifier(Terramap.MOD_ID, "textures/gui/compass_ribbon_background.png");
private static final Identifier COMPASS_INDICATOR_TEXTURE = new Identifier(Terramap.MOD_ID, "textures/gui/compass_ribbon_indicator.png");

private float x, y;
private final int z;
private float width;
private final float height;
private final float textureWidth;
private final float indicatorWidth;
private final float indicatorHeight;
private float azimuth = 0;
private boolean visibility = true;

public RibbonCompassWidget(float x, float y, int z, float width) {
this.x = x;
this.y = y;
this.z = z;
this.width = width;
this.height = 16f;
this.textureWidth = 360f;
this.indicatorHeight = 16f;
this.indicatorWidth = 1f;
}

@Override
public void draw(UiDrawContext context, float x, float y, float mouseX, float mouseY, boolean hovered, boolean focused, WidgetContainer parent) {
double blendBorder = 10d; // How many pixels to fade to alpha=0 on the sides
double leftU = (double)(this.azimuth - 180) / 360 + (double)(this.textureWidth - this.width) / this.textureWidth / 2;
double leftCU = leftU + blendBorder/this.textureWidth;
double rightU = leftU + (double) this.width / this.textureWidth;
double rightCU = rightU - blendBorder/this.textureWidth;

GlContext gl = context.gl();

gl.enableAlpha();
gl.enableSmoothShading();

gl.startDrawing(QUADS, POSITION_TEXTURE_COLOR);
gl.setTexture(COMPASS_BACKGROUND_TEXTURE);

gl.vertex().position(x, y, 0d).texture(leftU, 0d).color(1f, 1f, 1f, 0f).end();
gl.vertex().position(x, y + this.height, 0d).texture(leftU, 1d).color(1f, 1f, 1f, 0f).end();
gl.vertex().position(x + blendBorder, y + this.height, 0d).texture(leftCU, 1f).color(1f, 1f, 1f, 1f).end();
gl.vertex().position(x + blendBorder, y, 0d).texture(leftCU, 0f).color(1f, 1f, 1f, 1f).end();

gl.vertex().position(x + blendBorder, y, 0d).texture(leftCU, 0d).color(1f, 1f, 1f, 1f).end();
gl.vertex().position(x + blendBorder, y + this.height, 0d).texture(leftCU, 1d).color(1f, 1f, 1f, 1f).end();
gl.vertex().position(x + this.width - blendBorder, y + this.height, 0d).texture(rightCU, 1d).color(1f, 1f, 1f, 1f).end();
gl.vertex().position(x + this.width - blendBorder, y, 0d).texture(rightCU, 0d).color(1f, 1f, 1f, 1f).end();

gl.vertex().position(x + this.width - blendBorder, y, 0d).texture(rightCU, 0d).color(1f, 1f, 1f, 1f).end();
gl.vertex().position(x + this.width - blendBorder, y + this.height, 0d).texture(rightCU, 1d).color(1f, 1f, 1f, 1f).end();
gl.vertex().position(x + this.width, y + this.height, 0d).texture(rightU, 1d).color(1f, 1f, 1f, 0f).end();
gl.vertex().position(x + this.width, y, 0d).texture(rightU, 0d).color(1f, 1f, 1f, 0f).end();

gl.draw();

gl.setColor(WHITE);

double indX = x + (double)(this.width - this.indicatorWidth) / 2;
double indY = y + (double)(this.height - this.indicatorHeight) / 2;

gl.startDrawing(QUADS, POSITION_TEXTURE);
gl.setTexture(COMPASS_INDICATOR_TEXTURE);
gl.vertex().position(indX, indY, 0d).texture(0d, 0d).end();
gl.vertex().position(indX, indY + this.indicatorHeight, 0d).texture(0d, 1d).end();
gl.vertex().position(indX + this.indicatorWidth, indY + this.indicatorHeight, 0d).texture(1d, 1d).end();
gl.vertex().position(indX + this.indicatorWidth, indY, 0d).texture(1d, 0d).end();
gl.draw();

}

@Override
public float getX() {
return x;
}

public RibbonCompassWidget setX(float x) {
this.x = x;
return this;
}

@Override
public float getY() {
return y;
}

public RibbonCompassWidget setY(float y) {
this.y = y;
return this;
}

@Override
public float getWidth() {
return width;
}

public RibbonCompassWidget setWidth(float width) {
this.width = width;
return this;
}

@Override
public float getHeight() {
return height;
}

@Override
public int getZ() {
return z;
}

public float getAzimuth() {
return this.azimuth;
}

public RibbonCompassWidget setAzimuth(float azimuth) {
this.azimuth = azimuth;
return this;
}

@Override
public boolean isVisible(WidgetContainer parent) {
return this.visibility;
}


public RibbonCompassWidget setVisibility(boolean yesNo) {
this.visibility = yesNo;
return this;
}

}
Loading

0 comments on commit 23b58cc

Please sign in to comment.