semi working Store

This commit is contained in:
2025-06-22 16:56:18 -05:00
parent 420ba82b44
commit 0980e3a5d4
13 changed files with 136 additions and 27 deletions
@@ -95,6 +95,16 @@ public class Auth {
playerNames.entrySet().removeIf(entry -> entry.getValue().equals(uuid));
}
break;
case "successful_transaction":
String cloak = parser.getStringOrNull("cloak");
String hat = parser.getStringOrNull("hat");
if (cloak != null) {
Cloaks.availableCloaks.add(cloak);
}
if (hat != null) {
Hats.availableHats.add(hat);
}
default:
if (parser.error != null) {
@@ -218,4 +228,12 @@ public class Auth {
}
}
}
public static void buyCloak(String name) {
try {
Network.write("buy_cloak@cloak=" + name);
} catch (Exception e) {
SaturnClient.LOGGER.error("Request failed", e);
}
}
}
@@ -43,6 +43,11 @@ public class SaturnParser {
}
}
public String getStringOrNull(String i) throws IOException {
String val = params.get(i);
return val;
}
public boolean getBool(String i) throws IOException {
String val = params.get(i);
if (val != null) {
@@ -20,6 +20,7 @@ import org.saturnclient.saturnclient.SaturnClient;
* Originally created by IIpho3nix and modified for Saturn Client by leo.
*/
public class Cloaks {
public static final String[] ALL_CLOAKS = { "glitch", "mercedes_flow", };
private static final String[] ANIMATED_CLOAKS = { "glitch", "mercedes_flow" };
private static final String CLOAKS_RESOURCE_PATH = "assets/saturnclient/textures/cloaks/";
@@ -48,6 +49,17 @@ public class Cloaks {
SaturnClient.LOGGER.info("Cloak set to " + cloakName);
}
/**
* Sets cloak of the current player
*
* @param cloakName Name of the cloak file to load
*/
public static void setCloak(String cloakName) {
if (availableCloaks.contains(cloakName)) {
setCloak(Auth.uuid, cloakName);
}
}
/**
* Handles loading and caching of a new cloak texture, without connecting to the
* server.
@@ -31,45 +31,45 @@ public class Element {
public void charTyped(char typedChar) {
}
public final Element dimensions(int width, int height) {
public Element dimensions(int width, int height) {
this.width = width;
this.height = height;
return this;
}
public final Element position(int x, int y) {
public Element position(int x, int y) {
this.x = x;
this.y = y;
return this;
}
public final Element centerHorizontal(int w, int h, int offsetX, int offsetY) {
public Element centerHorizontal(int w, int h, int offsetX, int offsetY) {
this.x = (w - (int) (width * scale)) / 2 + offsetX;
this.y = offsetY;
return this;
}
public final Element center(int w, int h) {
public Element center(int w, int h) {
this.centerOffset(w, h, 0, 0);
return this;
}
public final Element centerOffset(int w, int h, int offsetX, int offsetY) {
public Element centerOffset(int w, int h, int offsetX, int offsetY) {
this.x = (w - (int) (width * scale)) / 2 + offsetX;
this.y = (h - (int) (height * scale)) / 2 + offsetY;
return this;
}
public final Element animation(Animation animation) {
public Element animation(Animation animation) {
this.animation = animation;
return this;
}
public final Element animation(Animation animation, Function<Double, Double> curve) {
public Element animation(Animation animation, Function<Double, Double> curve) {
this.animation = animation;
this.curve = curve;
return this;
@@ -13,6 +13,7 @@ import org.saturnclient.ui2.screens.CloakMenu;
import org.saturnclient.ui2.screens.ConfigEditor;
import org.saturnclient.ui2.screens.HatMenu;
import org.saturnclient.ui2.screens.ModMenu;
import org.saturnclient.ui2.screens.Store;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.util.Identifier;
@@ -62,7 +63,11 @@ public class Sidebar extends Element {
new Sidebar.SidebarComponent(Textures.CLOSE, () -> {
onClose.run();
}, true)
}, true),
new Sidebar.SidebarComponent(Textures.STORE, () -> {
SaturnClient.client.setScreen(new Store());
}, true),
};
int active = 0;
@@ -61,16 +61,14 @@ public class Scroll extends Element {
public void draw(Element element) {
children.add(element);
}
if (element.width > width) {
width = element.width;
@Override
public Element dimensions(int width, int height) {
for (Element element : children) {
maxScroll = Math.max(maxScroll, element.y + element.height - height);
}
if (element.height > height) {
height = element.height;
}
maxScroll = Math.max(maxScroll, element.y - maxScroll);
return super.dimensions(width, height);
}
int calculateScrollBarHeight() {
@@ -5,6 +5,7 @@ import org.saturnclient.saturnclient.config.ThemeManager;
import org.saturnclient.ui2.Element;
import org.saturnclient.ui2.ElementContext;
import org.saturnclient.ui2.RenderScope;
import org.saturnclient.ui2.resources.Fonts;
public class Text extends Element {
private static ThemeManager theme = new ThemeManager("Text");
@@ -15,6 +16,8 @@ public class Text extends Element {
public Text(String text) {
this.text = text;
width = Fonts.getWidth(text, font.value);
height = Fonts.getHeight();
}
@Override
@@ -17,6 +17,8 @@ public class Textures {
"textures/gui/components/toggle_indicator.png");
public static final Identifier LEFT = Identifier.of("saturnclient", "textures/gui/components/left.png");
public static final Identifier RIGHT = Identifier.of("saturnclient", "textures/gui/components/right.png");
public static final Identifier STORE = Identifier.of("saturnclient", "textures/gui/components/store.png");
public static final Identifier COINS = Identifier.of("saturnclient", "textures/gui/components/coins.png");
public static final Identifier LOGO = Identifier.of("saturnclient", "textures/logo/logo.png");
public static final Identifier REALISTIC_LOGO = Identifier.of("saturnclient", "textures/logo/realistic.png");
@@ -30,7 +30,7 @@ public class CloakMenu extends SaturnScreen {
if (player != null) {
for (String cloak : Cloaks.availableCloaks) {
scroll.draw(new CosmeticPreview(cloak == player.cloak, Textures.getCloakPreview(cloak), () -> {
Cloaks.setCloak(Auth.uuid, cloak);
Cloaks.setCloak(cloak);
}).position((50 + g) * col, (111 + g) * row));
if (col == 5) {
@@ -0,0 +1,66 @@
package org.saturnclient.ui2.screens;
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.components.CosmeticPreview;
import org.saturnclient.ui2.components.Sidebar;
import org.saturnclient.ui2.elements.ImageTexture;
import org.saturnclient.ui2.elements.Scroll;
import org.saturnclient.ui2.elements.Text;
import org.saturnclient.ui2.resources.Fonts;
import org.saturnclient.ui2.resources.Textures;
public class Store extends SaturnScreen {
public Store() {
super("Store");
}
@Override
public void ui() {
int p = 10;
int gx = 10;
int gy = 20;
Scroll scroll = new Scroll(p);
int row = 0;
int col = 0;
SaturnPlayer player = Auth.players.get(Auth.uuid);
if (player != null) {
for (String cloak : Cloaks.ALL_CLOAKS) {
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);
// This is to refresh the screen to remove the cloak because it's in our inventory
resize(client, width, height);
}).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), y + 112).scale(0.5f));
if (col == 8) {
col = 0;
row++;
} else {
col++;
}
}
}
}
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));
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 958 B