fixed panorama

This commit is contained in:
2025-05-03 11:19:33 -05:00
parent 52e8e572be
commit 22ad088ca4
5 changed files with 23 additions and 21 deletions
@@ -13,8 +13,7 @@ import org.saturnclient.saturnclient.config.ThemeManager;
import org.saturnclient.saturnclient.cosmetics.Hats;
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
import org.saturnclient.saturnclient.event.KeyInputHandler;
import org.saturnclient.saturnclient.menus.SaturnMenu;
import org.saturnclient.saturnclient.menus.SaturnTitleScreen;
import org.saturnclient.ui2.screens.TitleMenu;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,8 +40,8 @@ public class SaturnClient implements ModInitializer {
ClientLifecycleEvents.CLIENT_STOPPING.register(_o -> ConfigManager.save());
ScreenEvents.BEFORE_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
if (SaturnClientConfig.saturnTitleScreen.value && screen instanceof TitleScreen
&& !(screen instanceof SaturnMenu)) {
client.setScreen(new SaturnTitleScreen());
&& !(screen instanceof TitleMenu)) {
client.setScreen(new TitleMenu());
}
});
@@ -13,6 +13,7 @@ public class Element {
public float opacity = 1.0f;
public boolean focused;
public Animation animation;
public float scale = 1.0f;
public Function<Double, Double> curve = Curve::easeInOutCubic;
public void render(RenderScope renderScope, RenderContext ctx) {
@@ -36,15 +37,13 @@ public class Element {
}
public final Element center(int w, int h) {
this.x = (w - width) / 2;
this.y = (h - height) / 2;
this.centerOffset(w, h, 0, 0);
return this;
}
public final Element centerOffset(int w, int h, int offsetX, int offsetY) {
this.x = (w - width) / 2 + offsetX;
this.y = (h - height) / 2 + offsetY;
this.x = (w - (int) (width * scale)) / 2 + offsetX;
this.y = (h - (int) (height * scale)) / 2 + offsetY;
return this;
}
@@ -59,4 +58,9 @@ public class Element {
this.curve = curve;
return this;
}
public Element scale(float scale) {
this.scale = scale;
return this;
}
}
@@ -4,6 +4,7 @@ public class RenderContext {
public int mouseX, mouseY;
public int elementX, elementY;
public int elementWidth, elementHeight;
public float elementScale;
public RenderContext(int mouseX, int mouseY, Element e) {
this.mouseX = mouseX;
@@ -12,12 +13,10 @@ public class RenderContext {
this.elementY = e.y;
this.elementWidth = e.width;
this.elementHeight = e.height;
this.elementScale = e.scale;
}
public boolean isHovering() {
return mouseX >= elementX &&
mouseX <= elementX + elementWidth &&
mouseY >= elementY &&
mouseY <= elementY + elementHeight;
return Utils.isHovering(mouseX - elementX, mouseY - elementY, elementWidth, elementHeight, elementScale);
}
}
@@ -17,7 +17,7 @@ import net.minecraft.client.util.Pool;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
public class SaturnScreen extends Screen {
public abstract class SaturnScreen extends Screen {
private final Pool pool = new Pool(3);
protected List<Element> elements = new ArrayList<>();
public int blurDuration = 700;
@@ -74,8 +74,7 @@ public class SaturnScreen extends Screen {
}, blurDuration);
}
public void ui() {
}
public abstract void ui();
@SuppressWarnings("deprecation")
@Override
@@ -102,12 +101,13 @@ public class SaturnScreen extends Screen {
renderScope.matrices.push();
renderScope.matrices.scale(0.5f, 0.5f, 1.0f);
renderScope.matrices.scale(0.5f, 0.5f, 0.5f);
for (Element element : elements) {
renderScope.matrices.push();
renderScope.setOpacity(element.opacity);
renderScope.matrices.translate(element.x, element.y, 0);
renderScope.matrices.scale(element.scale, element.scale, 1.0f);
element.render(renderScope, new RenderContext(mouseX, mouseY, element));
renderScope.matrices.pop();
renderScope.setRenderLayer(null);
@@ -127,7 +127,7 @@ public class SaturnScreen extends Screen {
int adjustedMouseX = (int) mouseX - element.x;
int adjustedMouseY = (int) mouseY - element.y;
if (Utils.isHovering(adjustedMouseX, adjustedMouseY, element.width, element.height)) {
if (Utils.isHovering(adjustedMouseX, adjustedMouseY, element.width, element.height, element.scale)) {
element.focused = true;
element.click(adjustedMouseX, adjustedMouseY);
}
@@ -1,10 +1,10 @@
package org.saturnclient.ui2;
public class Utils {
public static boolean isHovering(int mouseX, int mouseY, int elementWidth, int elementHeight) {
public static boolean isHovering(int mouseX, int mouseY, int elementWidth, int elementHeight, float elementScale) {
return mouseX >= 0 &&
mouseX <= elementWidth &&
mouseX <= (elementWidth * elementScale) &&
mouseY >= 0 &&
mouseY <= elementHeight;
mouseY <= (elementHeight * elementScale);
}
}