Search in sources :

Example 1 with MouseEventAdapter

use of com.cas.robot.common.MouseEventAdapter in project TeachingInSimulation by ScOrPiOzzy.

the class MultimeterState_MF47 method putPenToTerminal.

/**
 * 将表笔放到端子上
 * @param terminal
 */
public void putPenToTerminal(Terminal terminal, Spatial termMdl) {
    if (now_pen_mdl_ref == null || V_SHORT_PEN.equals(now_pen_mdl_ref)) {
        return;
    }
    MouseEventState mouseEventState = stateManager.getState(MouseEventState.class);
    // 如果当前拿着红表笔
    if (V_RED_PEN.equals(now_pen_mdl_ref)) {
        // 加载表笔模型
        c_red_pen_mdl = (Node) MdlMapUtil.loadMdlWithAbbr(C_RED_PEN, assetManager);
        ((Node) termMdl).attachChild(c_red_pen_mdl);
        // 给表笔加监听
        mouseEventState.addCandidate(c_red_pen_mdl, new MouseEventAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                getBackRedPen();
            }
        });
        redPenTerm = terminal;
        if (blackPenTerm != null) {
            JmeUtil.transparent(mu_pen, 0);
            now_pen_mdl_ref = null;
        } else {
            loadHandPen(V_BLACK_PEN);
        }
        refreshMultimeter();
    } else if (V_BLACK_PEN.equals(now_pen_mdl_ref)) {
        c_black_pen_mdl = (Node) MdlMapUtil.loadMdlWithAbbr(C_BLACK_PEN, assetManager);
        ((Node) termMdl).attachChild(c_black_pen_mdl);
        mouseEventState.addCandidate(c_black_pen_mdl, new MouseEventAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                getBackBlackPen();
            }
        });
        blackPenTerm = terminal;
        if (redPenTerm != null) {
            JmeUtil.transparent(mu_pen, 0);
            now_pen_mdl_ref = null;
        } else {
            loadHandPen(V_RED_PEN);
        }
        refreshMultimeter();
    }
}
Also used : MouseEvent(com.cas.robot.common.MouseEvent) MouseEventAdapter(com.cas.robot.common.MouseEventAdapter) Node(com.jme3.scene.Node) MouseEventState(com.cas.robot.common.MouseEventState)

Example 2 with MouseEventAdapter

use of com.cas.robot.common.MouseEventAdapter in project TeachingInSimulation by ScOrPiOzzy.

the class MultimeterState_MF47 method initEvents.

private void initEvents() {
    MouseEventState mouseEventState = stateManager.getState(MouseEventState.class);
    final Spatial xuanniuMdl = ((Node) multimeter).getChild("xuanniu");
    if (xuanniuMdl != null) {
        mouseEventState.addCandidate(xuanniuMdl, new MouseEventAdapter() {

            @Override
            public void mouseWheel(MouseEvent e) {
                super.mouseWheel(e);
                // System.out.println(e.getWheel());
                boolean wheelUp = (e.getWheel() == 0);
                xuanniuMdl.rotate(0, 0, (wheelUp ? -1 : 1) * 360 * FastMath.DEG_TO_RAD / 24f);
                // JmeUtil.rotateModel(xuanniuMdl, JmeConst.AXIS_Z, (e.getWheel() == 0 ? -1 : 1) * 360 / 24f);
                if (wheelUp && nowDangIndex == 0) {
                    nowDangIndex = dangNames.size() - 1;
                } else if (!wheelUp && nowDangIndex == dangNames.size() - 1) {
                    nowDangIndex = 0;
                } else {
                    nowDangIndex = nowDangIndex + (wheelUp ? -1 : 1);
                }
                refreshMultimeter();
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                super.mouseEntered(e);
                // TODO
                JmeUtil.setSpatialHighLight(e.getSpatial(), JmeConst.YELLOW);
            // JmeUtil.select(e.getSpatial());
            }

            @Override
            public void mouseExited(MouseEvent e) {
                super.mouseExited(e);
                // TODO
                JmeUtil.setSpatialHighLight(e.getSpatial(), ColorRGBA.BlackNoAlpha);
            // JmeUtil.unselect(e.getSpatial());
            }
        });
    }
    final Spatial weitiaoMdl = ((Node) multimeter).getChild("ADJ");
    if (weitiaoMdl != null) {
        mouseEventState.addCandidate(weitiaoMdl, new MouseEventAdapter() {

            @Override
            public void mouseWheel(MouseEvent e) {
                super.mouseWheel(e);
                boolean wheelUp = (e.getWheel() == 1);
                if (rWeiR1 < 0) {
                    rWeiR1 = 0;
                } else if (rWeiR1 > 10000) {
                    rWeiR1 = 10000;
                } else if (rWeiR1 > 0 && rWeiR1 < 10000) {
                    rWeiR1 = rWeiR1 + (wheelUp ? 100 : -100);
                    weitiaoMdl.rotate(0, 0, (wheelUp ? 1 : -1) * 27f * FastMath.DEG_TO_RAD / 24f);
                    refreshMultimeter();
                } else if (rWeiR1 == 0 && wheelUp) {
                    rWeiR1 = rWeiR1 + 100;
                    refreshMultimeter();
                } else if (rWeiR1 == 10000 && !wheelUp) {
                    rWeiR1 = rWeiR1 - 100;
                    refreshMultimeter();
                }
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                super.mouseEntered(e);
                JmeUtil.setSpatialHighLight(e.getSpatial(), JmeConst.YELLOW);
            // JmeUtil.select(e.getSpatial());
            }

            @Override
            public void mouseExited(MouseEvent e) {
                super.mouseExited(e);
                JmeUtil.setSpatialHighLight(e.getSpatial(), ColorRGBA.BlackNoAlpha);
            // JmeUtil.unselect(e.getSpatial());
            }
        });
    }
}
Also used : MouseEvent(com.cas.robot.common.MouseEvent) Spatial(com.jme3.scene.Spatial) MouseEventAdapter(com.cas.robot.common.MouseEventAdapter) Node(com.jme3.scene.Node) MouseEventState(com.cas.robot.common.MouseEventState)

Aggregations

MouseEvent (com.cas.robot.common.MouseEvent)2 MouseEventAdapter (com.cas.robot.common.MouseEventAdapter)2 MouseEventState (com.cas.robot.common.MouseEventState)2 Node (com.jme3.scene.Node)2 Spatial (com.jme3.scene.Spatial)1