1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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();
}
}
}
|