blob: aed4c7c96195ea607b8e04d2c7f9b43b94c0c095 (
plain) (
blame)
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
|
package NET.worlds.console;
import NET.worlds.scape.FrameEvent;
import NET.worlds.scape.InventoryAction;
import NET.worlds.scape.InventoryItem;
import NET.worlds.scape.InventoryManager;
import NET.worlds.scape.Pilot;
import java.awt.Container;
import java.awt.Event;
import java.util.Vector;
public class ActionsPart implements FramePart {
static int actionToPerform = -1;
private Pilot curPilot;
private Vector<String> curAnimations;
private int numPilotAnims;
private static ActionsPart activePart;
private static ActionDialog dialog;
static boolean showDialog;
public void present() {
showDialog = true;
this.curPilot = null;
}
@Override
public void activate(Console c, Container f, Console prev) {
}
@Override
public void deactivate() {
}
@Override
public boolean action(Event event, Object what) {
return false;
}
public static boolean listEquals(Vector<String> a, Vector<String> b) {
if (a != null && b != null) {
if (a.size() != b.size()) {
return false;
} else {
int i = a.size();
while (--i >= 0) {
Object ao = a.elementAt(i);
Object bo = b.elementAt(i);
if (ao == null || bo == null) {
if (ao != null || bo != null) {
return false;
}
} else if (!ao.equals(bo)) {
return false;
}
}
return true;
}
} else {
return a == null == (b == null);
}
}
public static void updateActionDialog() {
if (activePart != null && dialog != null && showDialog && dialog.isVisible()) {
Main.register(new MainCallback() {
@Override
public void mainCallback() {
ActionsPart.activePart.regenActionDialog();
Main.unregister(this);
}
});
}
}
public void regenActionDialog() {
Vector<String> newAnimations = this.curPilot.getAnimationList();
this.numPilotAnims = newAnimations.size();
Vector<InventoryItem> specials = InventoryManager.getInventoryManager().getInventoryActionList();
for (int i = 0; i < specials.size(); i++) {
InventoryAction act = (InventoryAction)specials.elementAt(i);
newAnimations.addElement(act.getItemName());
}
if (dialog != null) {
boolean showWas = showDialog;
if (showWas && dialog.isVisible() && listEquals(newAnimations, this.curAnimations)) {
return;
}
dialog.done(true);
showDialog = showWas;
}
this.curAnimations = newAnimations;
if (showDialog) {
dialog = new ActionDialog(this.curAnimations);
}
}
@Override
public synchronized boolean handle(FrameEvent f) {
Pilot pilot = Pilot.getActive();
if (pilot != this.curPilot) {
this.curPilot = pilot;
activePart = this;
this.regenActionDialog();
} else if (actionToPerform != -1 && actionToPerform < this.curAnimations.size()) {
String act = this.curAnimations.elementAt(actionToPerform);
if (actionToPerform < this.numPilotAnims) {
pilot.animate(act);
} else {
InventoryManager.getInventoryManager().doInventoryAction(act);
}
}
actionToPerform = -1;
return true;
}
}
|