blob: e578dd1cd079bd488731ecd4bc2276cbd28d9b7b (
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
|
package NET.worlds.scape;
import NET.worlds.console.Console;
import NET.worlds.console.DefaultConsole;
import NET.worlds.console.MultiLineLabel;
import NET.worlds.core.IniFile;
import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Window;
public class ToolTipManager {
private static ToolTipManager manager_ = null;
private static final int FRAME_DELAY = 15;
private int savedX;
private int savedY;
private int savedLoops;
private boolean toolTipActive;
private WObject savedObject;
private Window toolTipWindow;
private MultiLineLabel toolTipTextArea;
private Font toolTipFont;
private ToolTipManager() {
this.savedX = this.savedY = this.savedLoops = 0;
this.toolTipActive = false;
this.savedObject = null;
this.toolTipFont = new Font("Arial", 0, 10);
Console.getActive();
this.toolTipWindow = new Window((Frame)Console.getFrame());
this.toolTipTextArea = new MultiLineLabel();
this.toolTipTextArea.setBackground(Color.yellow);
this.toolTipTextArea.setForeground(Color.black);
this.toolTipTextArea.setMarginWidth(2);
this.toolTipTextArea.setMarginHeight(2);
this.toolTipWindow.setFont(this.toolTipFont);
this.toolTipWindow.add(this.toolTipTextArea);
}
public static ToolTipManager toolTipManager() {
if (manager_ == null) {
manager_ = new ToolTipManager();
}
return manager_;
}
public void heartbeat() {
if (IniFile.gamma().getIniInt("DisableToolTips", 0) != 1) {
WObject obj = Camera.getMousePickWObject();
int x = (int)Camera.getMousePickX();
int y = (int)Camera.getMousePickY();
if (obj != null && x > 0 && y > 0 && x == this.savedX && y == this.savedY && this.savedObject == obj) {
this.savedLoops++;
} else {
if (this.toolTipActive) {
this.removeToolTip();
this.toolTipActive = false;
}
this.savedLoops = 0;
}
if (!this.toolTipActive && obj != null && this.savedLoops > 15) {
this.toolTipActive = true;
if (obj != null) {
this.savedObject = obj;
if (obj.getToolTipText() != null) {
String oldText = obj.getToolTipText();
String newText = oldText.replace('|', '\n');
this.createToolTip(this.savedX, this.savedY, newText);
}
}
}
this.savedX = x;
this.savedY = y;
this.savedObject = obj;
}
}
void createToolTip(int winX, int winY, String text) {
int baseX = ((DefaultConsole)Console.getActive()).getRender().getLocationOnScreen().x;
int baseY = ((DefaultConsole)Console.getActive()).getRender().getLocationOnScreen().y;
int offsetX = 16;
int offsetY = 16;
this.toolTipWindow.setLocation(winX + baseX + offsetX, winY + baseY + offsetY);
this.toolTipTextArea.setLabel(text);
this.toolTipWindow.setSize(this.toolTipTextArea.preferredSize());
this.toolTipWindow.setEnabled(false);
this.toolTipWindow.show();
}
public void removeToolTip() {
this.toolTipWindow.hide();
}
public void killToolTip() {
this.savedLoops = 0;
this.toolTipWindow.hide();
}
}
|