use of me.xjcyan1de.cyanbot.gui.joystick.PointChangeEvent in project CyanBot by XjCyan1de.
the class CommandWalk method initPanel.
@Override
public void initPanel(JPanel commandPanel) {
joystick = new SimpleJoystick(150);
joystick.setPreferredSize(new Dimension(100, 100));
joystick.addChangeListener(e -> {
Bot[] selectedBots = Main.getMainFrame().getSelectedBots();
final PointChangeEvent event = (PointChangeEvent) e;
final Point p = event.p;
double tempX = -p.getX() / 800;
// Шобы понимать пространство майна - z
double tempZ = p.getY() / 800;
x = tempX;
z = tempZ;
if ((-0.0001 < x && x < 0.0001) && (-0.0001 < z && z < 0.0001)) {
for (Bot bot : selectedBots) {
TimerTask walkTask = walkTaskMap.get(bot);
if (walkTask != null) {
walkTask.cancel();
walkTaskMap.remove(bot);
}
}
} else {
for (Bot bot : selectedBots) {
TimerTask walkTask = walkTaskMap.get(bot);
if (walkTask == null) {
walkTask = Schedule.timer(() -> {
bot.getLoc().add(x, 0, z);
}, 50, 50);
}
walkTaskMap.put(bot, walkTask);
}
}
});
commandPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
commandPanel.add(joystick, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
}
Aggregations