summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/SelectAvatarAction.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/scape/SelectAvatarAction.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/scape/SelectAvatarAction.java')
-rw-r--r--NET/worlds/scape/SelectAvatarAction.java152
1 files changed, 152 insertions, 0 deletions
diff --git a/NET/worlds/scape/SelectAvatarAction.java b/NET/worlds/scape/SelectAvatarAction.java
new file mode 100644
index 0000000..fef58eb
--- /dev/null
+++ b/NET/worlds/scape/SelectAvatarAction.java
@@ -0,0 +1,152 @@
+package NET.worlds.scape;
+
+import NET.worlds.console.Console;
+import NET.worlds.console.OkCancelDialog;
+import NET.worlds.console.PolledDialog;
+import NET.worlds.core.ServerTableManager;
+import NET.worlds.network.URL;
+import java.io.IOException;
+
+public class SelectAvatarAction extends DialogAction {
+ URL url = null;
+ String description;
+ static String[] avatarAliases = ServerTableManager.instance().getTable("avatarAliases");
+ private static Object classCookie = new Object();
+
+ private URL getURLVal() {
+ URL val = this.url;
+ if (val == null) {
+ SuperRoot o = this.getOwner();
+ if (o instanceof Drone) {
+ val = ((Drone)o).getSourceURL();
+ } else if (o instanceof PosableShape) {
+ val = ((Shape)o).getURL();
+ } else if (o instanceof Hologram) {
+ val = ((Hologram)o).getMovieName();
+ }
+ }
+
+ return val;
+ }
+
+ @Override
+ public void doIt() {
+ Console console = Console.getActive();
+ URL val = this.getURLVal();
+ if (console != null && val != null) {
+ console.setAvatar(val);
+ }
+ }
+
+ @Override
+ public PolledDialog getDialog() {
+ URL val = this.getURLVal();
+ if (!Console.getActive().getVIP() && val.getInternal().toLowerCase().endsWith(".rwg")) {
+ return new OkCancelDialog(
+ Console.getFrame(), this, Console.message("Cant-change-AV"), Console.message("OK"), null, Console.message("Only-VIPs-change"), false
+ );
+ } else {
+ String desc = this.description;
+ if (desc == null || desc.length() == 0) {
+ desc = getPrettyAvatarName(val.getBase());
+ }
+
+ return new ChangeAvatarDialog(Console.getFrame(), this, desc);
+ }
+ }
+
+ public static String getPrettyAvatarName(String name) {
+ int extIndex = name.indexOf(46);
+ if (extIndex >= 0) {
+ name = name.substring(0, extIndex).toLowerCase();
+ } else {
+ name = name.toLowerCase();
+ }
+
+ for (int i = 0; i < avatarAliases.length; i += 2) {
+ if (avatarAliases[i].equals(name)) {
+ return avatarAliases[i + 1];
+ }
+ }
+
+ String properName = name.substring(0, 1).toUpperCase();
+ if (name.length() > 1) {
+ properName = properName + name.substring(1);
+ }
+
+ return properName;
+ }
+
+ @Override
+ public Persister trigger(Event e, Persister seqID) {
+ URL val = this.getURLVal();
+ return val == null ? null : super.trigger(e, seqID);
+ }
+
+ @Override
+ public Object properties(int index, int offset, int mode, Object value) throws NoSuchPropertyException {
+ Object ret = null;
+ switch (index - offset) {
+ case 0:
+ if (mode == 0) {
+ ret = URLPropertyEditor.make(new Property(this, index, "Avatar URL").allowSetNull(), "pilot;drone;rwx;rwg;mov");
+ } else if (mode == 1) {
+ ret = this.url;
+ } else if (mode == 2) {
+ this.url = (URL)value;
+ }
+ break;
+ default:
+ ret = super.properties(index, offset + 1, mode, value);
+ }
+
+ return ret;
+ }
+
+ @Override
+ public String toString() {
+ return super.toString() + "[url " + (this.url == null ? "null" : this.url.getRelativeTo(this) + "]");
+ }
+
+ @Override
+ public void saveState(Saver s) throws IOException {
+ s.saveVersion(4, classCookie);
+ super.saveState(s);
+ URL.save(s, this.url);
+ s.saveString(this.description);
+ }
+
+ @Override
+ public void restoreState(Restorer r) throws IOException, TooNewException {
+ int ver = r.restoreVersion(classCookie);
+ switch (ver) {
+ case 0:
+ r.setOldFlag();
+ this.dialogActionSkipRestore(r);
+ this.url = URL.restore(r, ".world");
+ break;
+ case 1:
+ r.setOldFlag();
+ this.dialogActionSkipRestore(r);
+ this.url = URL.restore(r, ".world");
+ this.showDialog = r.restoreBoolean();
+ break;
+ case 2:
+ this.dialogActionSkipRestore(r);
+ this.url = URL.restore(r, ".world");
+ this.showDialog = r.restoreBoolean();
+ this.cancelOnly = r.restoreBoolean();
+ break;
+ case 3:
+ case 4:
+ super.restoreState(r);
+ this.url = URL.restore(r, ".world");
+ if (ver >= 4) {
+ this.description = r.restoreString();
+ }
+ break;
+ default:
+ throw new TooNewException();
+ }
+ }
+}