Fixed cloak store
This commit is contained in:
@@ -10,8 +10,7 @@ import net.minecraft.util.Identifier;
|
||||
|
||||
import org.saturnclient.saturnclient.cosmetics.Hats;
|
||||
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
||||
import org.saturnclient.ui2.SaturnScreen;
|
||||
import org.saturnclient.ui2.elements.Notification;
|
||||
import org.saturnclient.ui2.Utils;
|
||||
import org.saturnclient.ui2.elements.Notification.NotificationKind;
|
||||
|
||||
import dev.kosmx.playerAnim.api.layered.AnimationStack;
|
||||
@@ -165,15 +164,8 @@ public class Auth {
|
||||
|
||||
default:
|
||||
if (parser.error != null) {
|
||||
SaturnClient.LOGGER.error("Error from the server: " + parser.error);
|
||||
|
||||
if (SaturnClient.client.currentScreen instanceof SaturnScreen) {
|
||||
String[] a = parser.error.replace("!", "").split(": ");
|
||||
((SaturnScreen) SaturnClient.client.currentScreen)
|
||||
.draw(new Notification(SaturnClient.client.currentScreen.width,
|
||||
SaturnClient.client.currentScreen.height, NotificationKind.Error,
|
||||
a[0], a[1]));
|
||||
}
|
||||
String[] a = parser.error.replace("!", "").split(": ");
|
||||
Utils.notify(NotificationKind.Error, a[0], a[1]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -4,13 +4,15 @@ import java.util.List;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.ui2.elements.Notification;
|
||||
import org.saturnclient.ui2.elements.Notification.NotificationKind;
|
||||
|
||||
public class Utils {
|
||||
public static boolean isHovering(int mouseX, int mouseY, int elementWidth, int elementHeight, float elementScale) {
|
||||
return mouseX >= 0 &&
|
||||
mouseX <= (elementWidth * elementScale) &&
|
||||
mouseY >= 0 &&
|
||||
mouseY <= (elementHeight * elementScale);
|
||||
mouseX <= (elementWidth * elementScale) &&
|
||||
mouseY >= 0 &&
|
||||
mouseY <= (elementHeight * elementScale);
|
||||
}
|
||||
|
||||
public static char getCharFromKey(int keyCode, int modifiers) {
|
||||
@@ -52,4 +54,13 @@ public class Utils {
|
||||
SaturnClient.LOGGER.info("Accessing index {} in list of size {}", index, list.size());
|
||||
return (index >= 0 && index < list.size()) ? list.get(index) : null;
|
||||
}
|
||||
|
||||
public static void notify(NotificationKind kind, String title, String toast) {
|
||||
if (SaturnClient.client.currentScreen instanceof SaturnScreen) {
|
||||
((SaturnScreen) SaturnClient.client.currentScreen)
|
||||
.draw(new Notification(SaturnClient.client.currentScreen.width,
|
||||
SaturnClient.client.currentScreen.height, kind,
|
||||
title, toast));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,11 @@ import org.saturnclient.saturnclient.auth.Auth;
|
||||
import org.saturnclient.saturnclient.auth.SaturnPlayer;
|
||||
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
||||
import org.saturnclient.ui2.SaturnScreen;
|
||||
import org.saturnclient.ui2.Utils;
|
||||
import org.saturnclient.ui2.components.CosmeticPreview;
|
||||
import org.saturnclient.ui2.components.Sidebar;
|
||||
import org.saturnclient.ui2.elements.ImageTexture;
|
||||
import org.saturnclient.ui2.elements.Notification.NotificationKind;
|
||||
import org.saturnclient.ui2.elements.Scroll;
|
||||
import org.saturnclient.ui2.elements.TabMenu;
|
||||
import org.saturnclient.ui2.elements.TabMenu.TabMenuComponent;
|
||||
@@ -16,10 +18,17 @@ import org.saturnclient.ui2.resources.Fonts;
|
||||
import org.saturnclient.ui2.resources.Textures;
|
||||
|
||||
public class CloakStore extends SaturnScreen {
|
||||
private long lastPurchaseTime = 0;
|
||||
|
||||
public CloakStore() {
|
||||
super("Hat Store");
|
||||
}
|
||||
|
||||
public CloakStore(long lastPurchaseTime) {
|
||||
super("Hat Store");
|
||||
this.lastPurchaseTime = lastPurchaseTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ui() {
|
||||
int p = 10;
|
||||
@@ -30,7 +39,7 @@ public class CloakStore extends SaturnScreen {
|
||||
|
||||
int row = 0;
|
||||
int col = 0;
|
||||
|
||||
|
||||
SaturnPlayer player = Auth.players.get(Auth.uuid);
|
||||
|
||||
if (player != null) {
|
||||
@@ -38,17 +47,31 @@ public class CloakStore extends SaturnScreen {
|
||||
if (!Cloaks.availableCloaks.contains(cloak)) {
|
||||
int x = (50 + gx) * col;
|
||||
int y = (111 + gy) * row;
|
||||
|
||||
scroll.draw(new CosmeticPreview(cloak == player.cloak, Textures.getCloakPreview(cloak), () -> {
|
||||
Auth.buyCloak(cloak);
|
||||
SaturnClient.client.setScreen(new CloakStore());
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - lastPurchaseTime >= 3000) {
|
||||
Utils.notify(NotificationKind.Info, "Purchase processing", "Please wait 3 seconds");
|
||||
Auth.buyCloak(cloak);
|
||||
lastPurchaseTime = now;
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
SaturnClient.client.setScreen(new CloakStore(now));
|
||||
} else {
|
||||
Utils.notify(NotificationKind.Error, "Timeout error", "Please wait 3 seconds");
|
||||
}
|
||||
}).position(x, y));
|
||||
|
||||
String t = "100";
|
||||
|
||||
scroll.draw(new Text(t).position(x + Fonts.centerX(50, t, Text.font.value), y + 113).scale(0.5f));
|
||||
|
||||
scroll.draw(new ImageTexture(Textures.COINS).dimensions(16, 16).position(x + Fonts.getWidth(t, Text.font.value) - 1, y + 112).scale(0.5f));
|
||||
|
||||
scroll.draw(new ImageTexture(Textures.COINS).dimensions(16, 16)
|
||||
.position(x + Fonts.getWidth(t, Text.font.value) - 1, y + 112).scale(0.5f));
|
||||
|
||||
if (col == 8) {
|
||||
col = 0;
|
||||
row++;
|
||||
@@ -60,16 +83,16 @@ public class CloakStore extends SaturnScreen {
|
||||
}
|
||||
|
||||
int scrollWidth = 480 + 40 + (gx * 2) + (p * 2);
|
||||
|
||||
|
||||
draw(scroll.dimensions(scrollWidth, 350).centerOffset(width, height, 15, 0));
|
||||
|
||||
draw(new Sidebar(5, this::close).centerOffset(width, height, -((scrollWidth - 30) / 2 + 20), 0));
|
||||
|
||||
draw(new TabMenu(0,
|
||||
new TabMenuComponent(Textures.CLOAK, () -> {}),
|
||||
new TabMenuComponent(Textures.HAT, () -> {
|
||||
SaturnClient.client.setScreen(new HatStore());
|
||||
})
|
||||
).centerOffset(width, height, 0, -195));
|
||||
new TabMenuComponent(Textures.CLOAK, () -> {
|
||||
}),
|
||||
new TabMenuComponent(Textures.HAT, () -> {
|
||||
SaturnClient.client.setScreen(new HatStore());
|
||||
})).centerOffset(width, height, 0, -195));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,11 @@ import org.saturnclient.saturnclient.auth.Auth;
|
||||
import org.saturnclient.saturnclient.auth.SaturnPlayer;
|
||||
import org.saturnclient.saturnclient.cosmetics.Hats;
|
||||
import org.saturnclient.ui2.SaturnScreen;
|
||||
import org.saturnclient.ui2.Utils;
|
||||
import org.saturnclient.ui2.components.CosmeticPreview;
|
||||
import org.saturnclient.ui2.components.Sidebar;
|
||||
import org.saturnclient.ui2.elements.ImageTexture;
|
||||
import org.saturnclient.ui2.elements.Notification.NotificationKind;
|
||||
import org.saturnclient.ui2.elements.Scroll;
|
||||
import org.saturnclient.ui2.elements.TabMenu;
|
||||
import org.saturnclient.ui2.elements.TabMenu.TabMenuComponent;
|
||||
@@ -16,10 +18,17 @@ import org.saturnclient.ui2.resources.Fonts;
|
||||
import org.saturnclient.ui2.resources.Textures;
|
||||
|
||||
public class HatStore extends SaturnScreen {
|
||||
private long lastPurchaseTime = 0;
|
||||
|
||||
public HatStore() {
|
||||
super("Hat Store");
|
||||
}
|
||||
|
||||
public HatStore(long lastPurchaseTime) {
|
||||
super("Hat Store");
|
||||
this.lastPurchaseTime = lastPurchaseTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ui() {
|
||||
int p = 10;
|
||||
@@ -30,7 +39,7 @@ public class HatStore extends SaturnScreen {
|
||||
|
||||
int row = 0;
|
||||
int col = 0;
|
||||
|
||||
|
||||
SaturnPlayer player = Auth.players.get(Auth.uuid);
|
||||
|
||||
if (player != null) {
|
||||
@@ -38,17 +47,31 @@ public class HatStore extends SaturnScreen {
|
||||
if (!Hats.availableHats.contains(hat)) {
|
||||
int x = (50 + gx) * col;
|
||||
int y = (50 + gy) * row;
|
||||
|
||||
scroll.draw(new CosmeticPreview(hat == player.hat, Textures.getHatPreview(hat), () -> {
|
||||
Auth.buyHat(hat);
|
||||
SaturnClient.client.setScreen(new HatStore());
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - lastPurchaseTime >= 3000) {
|
||||
Utils.notify(NotificationKind.Info, "Purchase processing", "Please wait 3 seconds");
|
||||
Auth.buyHat(hat);
|
||||
lastPurchaseTime = now;
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
SaturnClient.client.setScreen(new HatStore(now));
|
||||
} else {
|
||||
Utils.notify(NotificationKind.Error, "Timeout error", "Please wait 3 seconds");
|
||||
}
|
||||
}).dimensions(50, 50).position(x, y));
|
||||
|
||||
String t = "50";
|
||||
|
||||
scroll.draw(new Text(t).position(x + Fonts.centerX(50, t, Text.font.value), y + 53).scale(0.5f));
|
||||
|
||||
scroll.draw(new ImageTexture(Textures.COINS).dimensions(16, 16).position(x + Fonts.getWidth(t, Text.font.value) + 4, y + 52).scale(0.5f));
|
||||
|
||||
scroll.draw(new ImageTexture(Textures.COINS).dimensions(16, 16)
|
||||
.position(x + Fonts.getWidth(t, Text.font.value) + 4, y + 52).scale(0.5f));
|
||||
|
||||
if (col == 8) {
|
||||
col = 0;
|
||||
row++;
|
||||
@@ -60,16 +83,16 @@ public class HatStore extends SaturnScreen {
|
||||
}
|
||||
|
||||
int scrollWidth = 480 + 40 + (gx * 2) + (p * 2);
|
||||
|
||||
|
||||
draw(scroll.dimensions(scrollWidth, 350).centerOffset(width, height, 15, 0));
|
||||
|
||||
draw(new Sidebar(5, this::close).centerOffset(width, height, -((scrollWidth - 30) / 2 + 20), 0));
|
||||
|
||||
draw(new TabMenu(1,
|
||||
new TabMenuComponent(Textures.CLOAK, () -> {
|
||||
SaturnClient.client.setScreen(new CloakStore());
|
||||
}),
|
||||
new TabMenuComponent(Textures.HAT, () -> {})
|
||||
).centerOffset(width, height, 0, -195));
|
||||
new TabMenuComponent(Textures.CLOAK, () -> {
|
||||
SaturnClient.client.setScreen(new CloakStore());
|
||||
}),
|
||||
new TabMenuComponent(Textures.HAT, () -> {
|
||||
})).centerOffset(width, height, 0, -195));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user