Search in sources :

Example 1 with PointChangeEvent

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));
}
Also used : PointChangeEvent(me.xjcyan1de.cyanbot.gui.joystick.PointChangeEvent) TimerTask(java.util.TimerTask) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) Bot(me.xjcyan1de.cyanbot.Bot) SimpleJoystick(me.xjcyan1de.cyanbot.gui.joystick.SimpleJoystick)

Aggregations

GridConstraints (com.intellij.uiDesigner.core.GridConstraints)1 GridLayoutManager (com.intellij.uiDesigner.core.GridLayoutManager)1 TimerTask (java.util.TimerTask)1 Bot (me.xjcyan1de.cyanbot.Bot)1 PointChangeEvent (me.xjcyan1de.cyanbot.gui.joystick.PointChangeEvent)1 SimpleJoystick (me.xjcyan1de.cyanbot.gui.joystick.SimpleJoystick)1