mirror of
https://github.com/Miasmusa/Shadow.git
synced 2024-11-14 19:04:54 -05:00
i put the bezier
This commit is contained in:
parent
8198b8dc07
commit
abef647beb
6 changed files with 149 additions and 11 deletions
|
@ -119,8 +119,8 @@ public class HomeScreen extends ClientScreen implements FastTickable {
|
|||
buttonsMap.add(new AbstractMap.SimpleEntry<>("Multiplayer", () -> ShadowMain.client.setScreen(new MultiplayerScreen(this))));
|
||||
buttonsMap.add(new AbstractMap.SimpleEntry<>("Realms", () -> ShadowMain.client.setScreen(new RealmsMainScreen(this))));
|
||||
buttonsMap.add(new AbstractMap.SimpleEntry<>("Alts", () -> ShadowMain.client.setScreen(
|
||||
AltManagerScreen.instance()
|
||||
// new AddonManagerScreen()
|
||||
// AltManagerScreen.instance()
|
||||
new TestScreen()
|
||||
)));
|
||||
buttonsMap.add(new AbstractMap.SimpleEntry<>("Settings", () -> ShadowMain.client.setScreen(new OptionsScreen(this, ShadowMain.client.options))));
|
||||
widgetsHeight = buttonsMap.size() * (widgetHeight + widPad) - widPad;
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Copyright (c) Shadow client, 0x150, Saturn5VFive 2022. All rights reserved.
|
||||
*/
|
||||
|
||||
package net.shadow.client.feature.gui.screen;
|
||||
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.math.Vec2f;
|
||||
import net.shadow.client.ShadowMain;
|
||||
import net.shadow.client.feature.gui.FastTickable;
|
||||
import net.shadow.client.helper.Timer;
|
||||
import net.shadow.client.helper.render.Renderer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class StatsScreen extends ClientScreen implements FastTickable {
|
||||
static List<Float> packetIn = Util.make(() -> {
|
||||
List<Float> f = new ArrayList<>();
|
||||
for(int i = 0;i<100;i++) f.add(0f);
|
||||
return f;
|
||||
});
|
||||
static List<Float> packetOut = Util.make(() -> {
|
||||
List<Float> f = new ArrayList<>();
|
||||
for(int i = 0;i<100;i++) f.add(0f);
|
||||
return f;
|
||||
});
|
||||
Timer packetUpdater = new Timer();
|
||||
|
||||
@Override
|
||||
public void onFastTick() {
|
||||
if (packetUpdater.hasExpired(500)) {
|
||||
packetUpdater.reset();
|
||||
float in = ShadowMain.client.getNetworkHandler().getConnection().getAveragePacketsReceived();
|
||||
packetIn.add(in);
|
||||
float out = ShadowMain.client.getNetworkHandler().getConnection().getAveragePacketsSent();
|
||||
packetOut.add(out);
|
||||
while(packetIn.size() > 100) {
|
||||
packetIn.remove(0);
|
||||
}
|
||||
while(packetOut.size() > 100) packetOut.remove(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderInternal(MatrixStack stack, int mouseX, int mouseY, float delta) {
|
||||
renderBackground(stack);
|
||||
double contentWidth = width;
|
||||
|
||||
List<Vec2f> bezPositions = new ArrayList<>();
|
||||
List<Float> pIn = new ArrayList<>(StatsScreen.packetIn);
|
||||
List<Float> pOut = new ArrayList<>(StatsScreen.packetOut);
|
||||
pIn.removeIf(Objects::isNull);
|
||||
float highest = Math.max(pIn.stream().max(Comparator.comparingDouble(value -> (double) value)).orElse(0f),
|
||||
pOut.stream().max(Comparator.comparingDouble(value -> (double) value)).orElse(0f));
|
||||
double maxHeight = 300;
|
||||
float scaleFactor = (float) Math.min(1,maxHeight/highest);
|
||||
for (int i = 0; i < pIn.size(); i++) {
|
||||
double prog = (i)/(double)(pIn.size()-3);
|
||||
float x = (float) (prog*contentWidth-((System.currentTimeMillis()-packetUpdater.getLastReset())/500f*(1f/(pIn.size()-1)*contentWidth)));
|
||||
float y = (float) height-pIn.get(i)*scaleFactor;
|
||||
Vec2f a = new Vec2f(x,y);
|
||||
bezPositions.add(a);
|
||||
}
|
||||
Renderer.R2D.renderBezierCurve(stack,bezPositions.toArray(new Vec2f[0]), 1f,1f,0f,1f,0.01f);
|
||||
bezPositions.clear();
|
||||
for (int i = 0; i < pOut.size(); i++) {
|
||||
double prog = (i)/(double)(pOut.size()-3);
|
||||
float x = (float) (prog*contentWidth-((System.currentTimeMillis()-packetUpdater.getLastReset())/500f*(1f/(pOut.size()-1)*contentWidth)));
|
||||
float y = (float) height-pOut.get(i)*scaleFactor;
|
||||
Vec2f a = new Vec2f(x,y);
|
||||
bezPositions.add(a);
|
||||
}
|
||||
Renderer.R2D.renderBezierCurve(stack,bezPositions.toArray(new Vec2f[0]), 0f,1f,1f,1f,0.01f);
|
||||
|
||||
super.renderInternal(stack, mouseX, mouseY, delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldPause() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -5,27 +5,30 @@
|
|||
package net.shadow.client.feature.gui.screen;
|
||||
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.util.math.Vec2f;
|
||||
import net.shadow.client.helper.GifPlayer;
|
||||
import net.shadow.client.helper.render.Renderer;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class TestScreen extends ClientScreen {
|
||||
private static final GifPlayer gp = GifPlayer.createFromFile(new File("/home/x150/Downloads/img.gif"), 30);
|
||||
|
||||
public TestScreen() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
gp.setGifFile(new File("/home/x150/Downloads/img.gif"));
|
||||
super.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderInternal(MatrixStack stack, int mouseX, int mouseY, float delta) {
|
||||
renderBackground(stack);
|
||||
gp.renderFrame(stack, 10, 10, 300, 300);
|
||||
Vec2f[] points = new Vec2f[] {
|
||||
new Vec2f(0,0),
|
||||
new Vec2f(100,100),
|
||||
new Vec2f(mouseX,mouseY),
|
||||
new Vec2f(500,300),
|
||||
new Vec2f(200,200),
|
||||
new Vec2f(600,200)
|
||||
};
|
||||
Renderer.R2D.renderBezierCurve(stack,points,1f,1f,1f,1f,0.01f);
|
||||
super.renderInternal(stack, mouseX, mouseY, delta);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,4 +18,8 @@ public class Timer {
|
|||
public boolean hasExpired(long timeout) {
|
||||
return System.currentTimeMillis() - lastReset > timeout;
|
||||
}
|
||||
|
||||
public long getLastReset() {
|
||||
return lastReset;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -518,6 +518,49 @@ public class Renderer {
|
|||
renderTexturedQuad(matrices.peek()
|
||||
.getPositionMatrix(), x0, x1, y0, y1, z, (u + 0.0F) / (float) textureWidth, (u + (float) regionWidth) / (float) textureWidth, (v + 0.0F) / (float) textureHeight, (v + (float) regionHeight) / (float) textureHeight);
|
||||
}
|
||||
static Vec2f lerp(Vec2f p1, Vec2f p2, float delta) {
|
||||
float x = MathHelper.lerp(delta,p1.x,p2.x);
|
||||
float y = MathHelper.lerp(delta,p1.y,p2.y);
|
||||
return new Vec2f(x,y);
|
||||
}
|
||||
static Vec2f getMultiBezPoint(Vec2f[] vertecies, float delta) {
|
||||
List<Vec2f> verts = new ArrayList<>(List.of(vertecies));
|
||||
while(verts.size() > 1) {
|
||||
for(int i = 0;i<verts.size()-1;i++) {
|
||||
Vec2f current = verts.get(i);
|
||||
Vec2f next = verts.get(i+1);
|
||||
verts.set(i, lerp(current, next, delta));
|
||||
}
|
||||
verts.remove(verts.size()-1);
|
||||
}
|
||||
return verts.get(0);
|
||||
}
|
||||
static Vec2f getTriBezierPoint(Vec2f p1, Vec2f p2, Vec2f p3, float delta) {
|
||||
Vec2f p1inner = lerp(p1,p2,delta);
|
||||
Vec2f p2inner = lerp(p2,p3,delta);
|
||||
return lerp(p1inner,p2inner,delta);
|
||||
}
|
||||
public static void renderBezierCurve(MatrixStack stack, Vec2f[] points, float r, float g, float b, float a, float laziness) {
|
||||
if (points.length < 2) return;
|
||||
float minIncr = 0.0001f;
|
||||
laziness = MathHelper.clamp(laziness,minIncr,1);
|
||||
Vec2f prev = null;
|
||||
// for (int i = 1; i < points.length; i++) {
|
||||
// Vec2f prev1 = points[i-1];
|
||||
// Vec2f c = points[i];
|
||||
// renderLine(stack,Color.RED,prev1.x,prev1.y,c.x,c.y);
|
||||
// }
|
||||
for(float d = 0;d<=1;d+=Math.min(laziness,Math.max(minIncr,1-d))) {
|
||||
Vec2f pos = getMultiBezPoint(points,d);
|
||||
if (prev == null) {
|
||||
prev = pos;
|
||||
continue;
|
||||
}
|
||||
renderLine(stack,new Color(r,g,b,a),prev.x,prev.y,pos.x,pos.y);
|
||||
prev = pos;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void renderLoadingSpinner(MatrixStack stack, float alpha, double x, double y, double rad, double width, double segments) {
|
||||
stack.push();
|
||||
|
|
|
@ -8,6 +8,7 @@ import net.minecraft.client.gui.screen.GameMenuScreen;
|
|||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.text.Text;
|
||||
import net.shadow.client.feature.gui.screen.AddonManagerScreen;
|
||||
import net.shadow.client.feature.gui.screen.StatsScreen;
|
||||
import net.shadow.client.feature.gui.widget.RoundButton;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
@ -24,7 +25,8 @@ public class GameMenuMixin extends Screen {
|
|||
void addAddons(CallbackInfo ci) {
|
||||
addDrawableChild(new RoundButton(RoundButton.STANDARD, 5, 5, 60, 20, "Addons", () -> {
|
||||
assert client != null;
|
||||
client.setScreen(new AddonManagerScreen());
|
||||
// client.setScreen(new AddonManagerScreen());
|
||||
client.setScreen(new StatsScreen());
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue