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.Hats;
|
||||||
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
||||||
import org.saturnclient.ui2.SaturnScreen;
|
import org.saturnclient.ui2.Utils;
|
||||||
import org.saturnclient.ui2.elements.Notification;
|
|
||||||
import org.saturnclient.ui2.elements.Notification.NotificationKind;
|
import org.saturnclient.ui2.elements.Notification.NotificationKind;
|
||||||
|
|
||||||
import dev.kosmx.playerAnim.api.layered.AnimationStack;
|
import dev.kosmx.playerAnim.api.layered.AnimationStack;
|
||||||
@@ -165,15 +164,8 @@ public class Auth {
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
if (parser.error != null) {
|
if (parser.error != null) {
|
||||||
SaturnClient.LOGGER.error("Error from the server: " + parser.error);
|
String[] a = parser.error.replace("!", "").split(": ");
|
||||||
|
Utils.notify(NotificationKind.Error, a[0], a[1]);
|
||||||
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]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,15 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
|
import org.saturnclient.ui2.elements.Notification;
|
||||||
|
import org.saturnclient.ui2.elements.Notification.NotificationKind;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
public static boolean isHovering(int mouseX, int mouseY, int elementWidth, int elementHeight, float elementScale) {
|
public static boolean isHovering(int mouseX, int mouseY, int elementWidth, int elementHeight, float elementScale) {
|
||||||
return mouseX >= 0 &&
|
return mouseX >= 0 &&
|
||||||
mouseX <= (elementWidth * elementScale) &&
|
mouseX <= (elementWidth * elementScale) &&
|
||||||
mouseY >= 0 &&
|
mouseY >= 0 &&
|
||||||
mouseY <= (elementHeight * elementScale);
|
mouseY <= (elementHeight * elementScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static char getCharFromKey(int keyCode, int modifiers) {
|
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());
|
SaturnClient.LOGGER.info("Accessing index {} in list of size {}", index, list.size());
|
||||||
return (index >= 0 && index < list.size()) ? list.get(index) : null;
|
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.auth.SaturnPlayer;
|
||||||
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
||||||
import org.saturnclient.ui2.SaturnScreen;
|
import org.saturnclient.ui2.SaturnScreen;
|
||||||
|
import org.saturnclient.ui2.Utils;
|
||||||
import org.saturnclient.ui2.components.CosmeticPreview;
|
import org.saturnclient.ui2.components.CosmeticPreview;
|
||||||
import org.saturnclient.ui2.components.Sidebar;
|
import org.saturnclient.ui2.components.Sidebar;
|
||||||
import org.saturnclient.ui2.elements.ImageTexture;
|
import org.saturnclient.ui2.elements.ImageTexture;
|
||||||
|
import org.saturnclient.ui2.elements.Notification.NotificationKind;
|
||||||
import org.saturnclient.ui2.elements.Scroll;
|
import org.saturnclient.ui2.elements.Scroll;
|
||||||
import org.saturnclient.ui2.elements.TabMenu;
|
import org.saturnclient.ui2.elements.TabMenu;
|
||||||
import org.saturnclient.ui2.elements.TabMenu.TabMenuComponent;
|
import org.saturnclient.ui2.elements.TabMenu.TabMenuComponent;
|
||||||
@@ -16,10 +18,17 @@ import org.saturnclient.ui2.resources.Fonts;
|
|||||||
import org.saturnclient.ui2.resources.Textures;
|
import org.saturnclient.ui2.resources.Textures;
|
||||||
|
|
||||||
public class CloakStore extends SaturnScreen {
|
public class CloakStore extends SaturnScreen {
|
||||||
|
private long lastPurchaseTime = 0;
|
||||||
|
|
||||||
public CloakStore() {
|
public CloakStore() {
|
||||||
super("Hat Store");
|
super("Hat Store");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CloakStore(long lastPurchaseTime) {
|
||||||
|
super("Hat Store");
|
||||||
|
this.lastPurchaseTime = lastPurchaseTime;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ui() {
|
public void ui() {
|
||||||
int p = 10;
|
int p = 10;
|
||||||
@@ -38,16 +47,30 @@ public class CloakStore extends SaturnScreen {
|
|||||||
if (!Cloaks.availableCloaks.contains(cloak)) {
|
if (!Cloaks.availableCloaks.contains(cloak)) {
|
||||||
int x = (50 + gx) * col;
|
int x = (50 + gx) * col;
|
||||||
int y = (111 + gy) * row;
|
int y = (111 + gy) * row;
|
||||||
|
|
||||||
scroll.draw(new CosmeticPreview(cloak == player.cloak, Textures.getCloakPreview(cloak), () -> {
|
scroll.draw(new CosmeticPreview(cloak == player.cloak, Textures.getCloakPreview(cloak), () -> {
|
||||||
Auth.buyCloak(cloak);
|
long now = System.currentTimeMillis();
|
||||||
SaturnClient.client.setScreen(new CloakStore());
|
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));
|
}).position(x, y));
|
||||||
|
|
||||||
String t = "100";
|
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 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) {
|
if (col == 8) {
|
||||||
col = 0;
|
col = 0;
|
||||||
@@ -66,10 +89,10 @@ public class CloakStore extends SaturnScreen {
|
|||||||
draw(new Sidebar(5, this::close).centerOffset(width, height, -((scrollWidth - 30) / 2 + 20), 0));
|
draw(new Sidebar(5, this::close).centerOffset(width, height, -((scrollWidth - 30) / 2 + 20), 0));
|
||||||
|
|
||||||
draw(new TabMenu(0,
|
draw(new TabMenu(0,
|
||||||
new TabMenuComponent(Textures.CLOAK, () -> {}),
|
new TabMenuComponent(Textures.CLOAK, () -> {
|
||||||
new TabMenuComponent(Textures.HAT, () -> {
|
}),
|
||||||
SaturnClient.client.setScreen(new HatStore());
|
new TabMenuComponent(Textures.HAT, () -> {
|
||||||
})
|
SaturnClient.client.setScreen(new HatStore());
|
||||||
).centerOffset(width, height, 0, -195));
|
})).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.auth.SaturnPlayer;
|
||||||
import org.saturnclient.saturnclient.cosmetics.Hats;
|
import org.saturnclient.saturnclient.cosmetics.Hats;
|
||||||
import org.saturnclient.ui2.SaturnScreen;
|
import org.saturnclient.ui2.SaturnScreen;
|
||||||
|
import org.saturnclient.ui2.Utils;
|
||||||
import org.saturnclient.ui2.components.CosmeticPreview;
|
import org.saturnclient.ui2.components.CosmeticPreview;
|
||||||
import org.saturnclient.ui2.components.Sidebar;
|
import org.saturnclient.ui2.components.Sidebar;
|
||||||
import org.saturnclient.ui2.elements.ImageTexture;
|
import org.saturnclient.ui2.elements.ImageTexture;
|
||||||
|
import org.saturnclient.ui2.elements.Notification.NotificationKind;
|
||||||
import org.saturnclient.ui2.elements.Scroll;
|
import org.saturnclient.ui2.elements.Scroll;
|
||||||
import org.saturnclient.ui2.elements.TabMenu;
|
import org.saturnclient.ui2.elements.TabMenu;
|
||||||
import org.saturnclient.ui2.elements.TabMenu.TabMenuComponent;
|
import org.saturnclient.ui2.elements.TabMenu.TabMenuComponent;
|
||||||
@@ -16,10 +18,17 @@ import org.saturnclient.ui2.resources.Fonts;
|
|||||||
import org.saturnclient.ui2.resources.Textures;
|
import org.saturnclient.ui2.resources.Textures;
|
||||||
|
|
||||||
public class HatStore extends SaturnScreen {
|
public class HatStore extends SaturnScreen {
|
||||||
|
private long lastPurchaseTime = 0;
|
||||||
|
|
||||||
public HatStore() {
|
public HatStore() {
|
||||||
super("Hat Store");
|
super("Hat Store");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HatStore(long lastPurchaseTime) {
|
||||||
|
super("Hat Store");
|
||||||
|
this.lastPurchaseTime = lastPurchaseTime;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ui() {
|
public void ui() {
|
||||||
int p = 10;
|
int p = 10;
|
||||||
@@ -38,16 +47,30 @@ public class HatStore extends SaturnScreen {
|
|||||||
if (!Hats.availableHats.contains(hat)) {
|
if (!Hats.availableHats.contains(hat)) {
|
||||||
int x = (50 + gx) * col;
|
int x = (50 + gx) * col;
|
||||||
int y = (50 + gy) * row;
|
int y = (50 + gy) * row;
|
||||||
|
|
||||||
scroll.draw(new CosmeticPreview(hat == player.hat, Textures.getHatPreview(hat), () -> {
|
scroll.draw(new CosmeticPreview(hat == player.hat, Textures.getHatPreview(hat), () -> {
|
||||||
Auth.buyHat(hat);
|
long now = System.currentTimeMillis();
|
||||||
SaturnClient.client.setScreen(new HatStore());
|
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));
|
}).dimensions(50, 50).position(x, y));
|
||||||
|
|
||||||
String t = "50";
|
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 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) {
|
if (col == 8) {
|
||||||
col = 0;
|
col = 0;
|
||||||
@@ -66,10 +89,10 @@ public class HatStore extends SaturnScreen {
|
|||||||
draw(new Sidebar(5, this::close).centerOffset(width, height, -((scrollWidth - 30) / 2 + 20), 0));
|
draw(new Sidebar(5, this::close).centerOffset(width, height, -((scrollWidth - 30) / 2 + 20), 0));
|
||||||
|
|
||||||
draw(new TabMenu(1,
|
draw(new TabMenu(1,
|
||||||
new TabMenuComponent(Textures.CLOAK, () -> {
|
new TabMenuComponent(Textures.CLOAK, () -> {
|
||||||
SaturnClient.client.setScreen(new CloakStore());
|
SaturnClient.client.setScreen(new CloakStore());
|
||||||
}),
|
}),
|
||||||
new TabMenuComponent(Textures.HAT, () -> {})
|
new TabMenuComponent(Textures.HAT, () -> {
|
||||||
).centerOffset(width, height, 0, -195));
|
})).centerOffset(width, height, 0, -195));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user