-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin_InGameWindow.java
More file actions
78 lines (52 loc) · 1.61 KB
/
Copy pathPlugin_InGameWindow.java
File metadata and controls
78 lines (52 loc) · 1.61 KB
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
package haven.plugins;
import haven.*;
import java.util.Collection;
public class MyFirstPlugin extends Plugin {
private boolean shown = false;
private HelloWorldWindow wnd = null;
public void load(UI ui) {
Glob glob = ui.sess.glob;
Collection<Glob.Pagina> p = glob.paginae;
p.add(glob.paginafor(Resource.load("paginae/add/hello")));
XTendedPaginae.registerPlugin("hello", this);
}
public void execute(UI ui) {
if (!shown) {
shown = true;
wnd = new HelloWorldWindow(ui.root, () -> {
shown = false;
wnd = null;
});
}
}
}
class HelloWorldWindow extends Window {
private final Text helloText;
private final Runnable onClose;
public HelloWorldWindow(Widget parent, Runnable onClose) {
super(new Coord(300, 200), new Coord(400, 200), parent, "Hello World");
this.justclose = true;
this.onClose = onClose;
helloText = Text.render("Hello World!");
this.asz = new Coord(Math.max(asz.x, helloText.sz().x + 20),
Math.max(asz.y, helloText.sz().y + 20));
}
@Override
public void cdraw(GOut g) {
g.chcolor(0, 0, 0, 255);
g.frect(Coord.z, asz);
g.chcolor();
Coord textPos = new Coord(
(asz.x - helloText.sz().x) / 2,
(asz.y - helloText.sz().y) / 2
);
g.image(helloText.tex(), textPos);
}
@Override
public void destroy() {
super.destroy();
if (onClose != null) {
onClose.run();
}
}
}