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