-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin_Limerhub.java
More file actions
135 lines (100 loc) · 3.44 KB
/
Copy pathPlugin_Limerhub.java
File metadata and controls
135 lines (100 loc) · 3.44 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
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
package haven.plugins;
import haven.*;
import java.util.Collection;
import java.awt.Desktop;
import java.net.URI;
import java.net.URL;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
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 Tex bgImage;
private final Runnable onClose;
private final Button btnFront;
private final Button btnDiscord;
public HelloWorldWindow(Widget parent, Runnable onClose) {
// Set window position coord, inner size; title handled by Window
super(new Coord(300, 200), new Coord(300, 300), parent, "Limer's Hub");
this.justclose = true;
this.onClose = onClose;
// Load remote image (200x200)
try {
BufferedImage img = ImageIO.read(new URL("https://limers.hstn.me/img/logo.png"));
if (img != null)
bgImage = new TexI(img);
} catch (IOException e) {
e.printStackTrace();
}
int buttonWidth = 200;
int buttonHeight = 25;
int imgHeight = 200;
int imgTop = 10;
int buttonSpacing = 8;
// compute center based on inner content area (asz)
int centerX = (this.asz.x - buttonWidth) / 2;
int firstButtonY = imgTop + imgHeight + 10; // inside content coords
// Buttons: second parameter must be Integer (width)
btnFront = new Button(new Coord(centerX, firstButtonY), Integer.valueOf(buttonWidth), this, "The Front") {
public void click() {
openLink("https://limers.hstn.me/index.php");
}
};
btnDiscord = new Button(new Coord(centerX, firstButtonY + buttonHeight + buttonSpacing), Integer.valueOf(buttonWidth), this, "Discord") {
public void click() {
openLink("https://discord.gg/z6YFaeJMrK");
}
};
}
@Override
public void cdraw(GOut g) {
// Fill content background black
g.chcolor(0, 0, 0, 255);
g.frect(Coord.z, asz);
g.chcolor();
// Draw the 200x200 image centered horizontally inside the content area
if (bgImage != null) {
Coord imgPos = new Coord(
(asz.x - 200) / 2,
10
);
// draw with explicit size (200x200)
g.image(bgImage, imgPos, new Coord(200, 200));
}
}
@Override
public void destroy() {
super.destroy();
if (onClose != null)
onClose.run();
}
private void openLink(String url) {
try {
if (Desktop.isDesktopSupported()) {
Desktop.getDesktop().browse(new URI(url));
} else {
Runtime.getRuntime().exec("xdg-open " + url);
}
} catch (IOException | java.net.URISyntaxException e) {
e.printStackTrace();
}
}
}