@Override
 public void mousePressed(MouseEvent me) {
   x = me.getX();
   y = me.getY();
   altDown = me.isAltDown() || me.isAltGraphDown();
   undo = (me.getButton() == MouseEvent.BUTTON3) || altDown;
   ctrlDown = me.isControlDown() || me.isMetaDown();
   shiftDown = me.isShiftDown();
   first = true;
   if (!oneShot) {
     if (timer == null) {
       timer =
           new Timer(
               delay,
               e -> {
                 Point worldCoords = view.viewToWorld((int) x, (int) y);
                 tick(worldCoords.x, worldCoords.y, undo, first, 1.0f);
                 view.updateStatusBar(worldCoords.x, worldCoords.y);
                 first = false;
               });
       timer.setInitialDelay(0);
       timer.start();
       //                start = System.currentTimeMillis();
     }
   } else {
     Point worldCoords = view.viewToWorld((int) x, (int) y);
     tick(worldCoords.x, worldCoords.y, undo, true, 1.0f);
     view.updateStatusBar(worldCoords.x, worldCoords.y);
     Dimension dimension = getDimension();
     if (dimension != null) {
       dimension.armSavePoint();
     }
     logOperation(undo ? statisticsKeyUndo : statisticsKey);
   }
 }
  /**
   * A chat room was selected. Opens the chat room in the chat window.
   *
   * @param e the <tt>MouseEvent</tt> instance containing details of the event that has just
   *     occurred.
   */
  public void mousePressed(MouseEvent e) {
    // Select the object under the right button click.
    if ((e.getModifiers() & InputEvent.BUTTON2_MASK) != 0
        || (e.getModifiers() & InputEvent.BUTTON3_MASK) != 0
        || (e.isControlDown() && !e.isMetaDown())) {
      int ix = this.chatRoomList.rowAtPoint(e.getPoint());

      if (ix != -1) {
        this.chatRoomList.setRowSelectionInterval(ix, ix);
      }
    }

    Object o = this.chatRoomsTableModel.getValueAt(this.chatRoomList.getSelectedRow());

    Point selectedCellPoint = e.getPoint();

    SwingUtilities.convertPointToScreen(selectedCellPoint, chatRoomList);

    if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) {
      JPopupMenu rightButtonMenu;

      if (o instanceof ChatRoomWrapper)
        rightButtonMenu = new ChatRoomRightButtonMenu((ChatRoomWrapper) o);
      else return;

      rightButtonMenu.setInvoker(this);
      rightButtonMenu.setLocation(selectedCellPoint);
      rightButtonMenu.setVisible(true);
    }
  }
Example #3
0
    public void mouseClicked(MouseEvent e) {
      details = String.format("You clicked %d", e.getClickCount());

      // isMetaDown() = what kind mouse is used now? one button or two
      // button or more?
      if (e.isMetaDown()) details += "with right mouse button";
      else if (e.isAltDown()) details += "with center mouse button";
      else details += "with left mouse";

      statusBar.setText(details);
    }
Example #4
0
 /** Fires weapons when left mouse is pressed */
 public void mousePressed(MouseEvent evt) {
   int mx = evt.getX(); // x-coordinate where user clicked.
   int my = evt.getY(); // y-coordinate where user clicked.
   if (!pause) {
     if (!evt.isMetaDown()) {
       if (weapons[guntrack].equals("gun") && bshoot) {
         weaponList.add(
             new Bullet(
                 mx, my, character.getX(), character.getY(), 0, THA.WIDTH, 0, THA.HEIGHT, 7));
         bshoot = false;
         ammo.useBullet();
         bulletTime.restart();
       }
       if (weapons[guntrack].equals("grenade") && gshoot) {
         weaponList.add(
             new Grenade(
                 mx, my, character.getX(), character.getY(), 0, THA.WIDTH, 0, THA.HEIGHT, 12));
         gshoot = false;
         ammo.useGrenade();
         grenadeTime.restart();
       }
       if (weapons[guntrack].equals("laser") && lshoot) {
         weaponList.add(
             new Laser(
                 mx, my, character.getX(), character.getY(), 0, THA.WIDTH, 0, THA.HEIGHT, 20));
         lshoot = false;
         ammo.useLaser();
         laserTime.restart();
       }
       if (weapons[guntrack].equals("shotgun") && sgshoot) {
         weaponList.add(
             new ShotGun(
                 mx,
                 my,
                 character.getX(),
                 character.getY(),
                 0,
                 THA.WIDTH,
                 0,
                 THA.HEIGHT,
                 7,
                 character.getX(),
                 character.getY(),
                 25,
                 90,
                 weaponList));
         sgshoot = false;
         ammo.useShotgun();
         shotgunTime.restart();
       }
     }
   }
 }
 @Override
 public void mouseMoved(MouseEvent me) {
   altDown = me.isAltDown() || me.isAltGraphDown();
   ctrlDown = me.isControlDown() || me.isMetaDown();
   shiftDown = me.isShiftDown();
 }
Example #6
0
  @Override
  public void mouseClicked(MouseEvent e) {

    // To change body of implemented methods use File | Settings | File Templates.
    GameMap temp = panel;
    temp.setStatus("selected");
    Cell selectCell = new Cell();
    Point curPos = e.getPoint();
    int x = (curPos.x + panel.getScrollX()) / Utilizer.TILE_SIZE;
    selectCell.setColPos(x);
    x = x * Utilizer.TILE_SIZE;
    selectCell.setX(x);
    int y = (curPos.y + panel.getScrollY()) / Utilizer.TILE_SIZE;
    selectCell.setRowPos(y);
    y = y * Utilizer.TILE_SIZE;
    selectCell.setY(y);
    temp.setSelectedCell(selectCell);
    panel.requestFocus();
    if (e.isMetaDown()) {
      panel.getFacade().getMainHero().setIsChosen(false);
    }
    model.Character clickedCharacter =
        panel.getFacade().getCharacterByCord(selectCell.getRowPos(), selectCell.getColPos());
    mainHero = panel.getFacade().getMainHero();
    if (clickedCharacter != null && !mainHero.getStatus().equals(HeroStatus.attacking)) {
      if (mainHero.getStatus().equals(HeroStatus.standing))
        controlPanel.setCharacter(clickedCharacter);
      // panel.getFacade().setCurrentHero(clickedHero);
      if (clickedCharacter instanceof Hero) {
        Hero clickedHero = (Hero) clickedCharacter;
        if (clickedHero.equals(mainHero)) {
          mainHero.setIsChosen(true);
          mainHero.resetPath();
          mainHero.calculateRange(
              mainHero.getRow(), mainHero.getCol(), ((int) mainHero.getAP() / 2) + 1);
          if ((mainHero.getCurrentSkill()) != null) {
            if (mainHero.getCurrentSkill() instanceof AOESkill)
              ((AOESkill) mainHero.getCurrentSkill()).clearRangeCell();
          }
        }
      }
      if (panel.getFacade().getIsLocked()) {
        panel.repaint();
        return;
      }
    }
    // To set Hero
    /*if(selectCell.getRowPos()==panel.getHero().getRow() && selectCell.getColPos()==panel.getHero().getCol()){
        panel.getHero().setIsChosen(true);
        panel.getHero().setStatus(HeroStatus.standing);
        panel.getHero().resetPath();
        panel.getHero().calculateRange(panel.getHero().getRow(), panel.getHero().getCol(), ((int) panel.getHero().getAP() / 2) + 1);
        if(( panel.getHero().getCurrentSkill())!=null){
            if( panel.getHero().getCurrentSkill() instanceof AOESkill) ((AOESkill) panel.getHero().getCurrentSkill()).clearRangeCell();
        }
    }*/
    else if (panel.getFacade().getIsLocked()) {
      panel.repaint();
      return;
    } else if (mainHero.getIsChosen()
        && mainHero.getStatus().equals(HeroStatus.standing)
        && Utilizer.inRange(selectCell, mainHero.getRange())) {
      // send moving request
      int gameIndex = panel.getFacade().getGameIndex();
      int heroSlot = panel.getFacade().getHeroSlot();
      mainHero.setShortestPathSelect(mainHero.getShortestpathHover());

      HeroMoveRequest moveRequest = null;
      try {
        moveRequest = new HeroMoveRequest(gameIndex, heroSlot, mainHero.clone());
        moveRequest.setSelectedCell(selectCell.clone());
        com.write(moveRequest);
      } catch (CloneNotSupportedException e1) {
        e1.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      }

      // HeroAnimation.move(mainHero,panel);
      if ((mainHero.getCurrentSkill()) != null) {
        if (mainHero.getCurrentSkill() instanceof AOESkill)
          ((AOESkill) mainHero.getCurrentSkill()).clearRangeCell();
      }
    }
    // cast AOE skill
    else if (mainHero.getIsChosen()
        && mainHero.getStatus().equals(HeroStatus.attacking)
        && mainHero.getCurrentSkill().getStatus().equals(SkillStatus.before)
        && mainHero.getCurrentSkill().getPath().contains(selectCell)
        && (mainHero.getAP() - mainHero.getCurrentSkill().getAP()) >= 0
        && mainHero.getCurrentSkill() != null
        && Utilizer.inRange(selectCell, mainHero.getCurrentSkill().getRangeCell())) {
      // send attack request
      int gameIndex = panel.getFacade().getGameIndex();
      int heroSlot = panel.getFacade().getHeroSlot();
      if (selectCell.getColPos() < mainHero.getCol()) mainHero.setCurrentSprite(16);
      else mainHero.setCurrentSprite(20);

      HeroAttackRequest attackReq = null;
      if (mainHero.getCurrentSkill() instanceof NormalSkill)
        mainHero.getCurrentSkill().getDmgCell().clear();
      mainHero.getCurrentSkill().getDmgCell().add(selectCell);
      try {
        Hero cloneHero = mainHero.clone();

        // cloneHero.getCurrentSkill().clonePath(mainHero.getCurrentSkill().getPath());
        attackReq = new HeroAttackRequest(gameIndex, heroSlot, cloneHero);
        attackReq.setSelectedCell(selectCell.clone());
        attackReq.setPath(mainHero.getCurrentSkill().getPath());
        attackReq.setDmgCell(mainHero.getCurrentSkill().getDmgCell());
        com.write(attackReq);
      } catch (CloneNotSupportedException e1) {
        e1.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      }

      /*if(mainHero.getCurrentSkill() instanceof NormalSkill) mainHero.getCurrentSkill().getDmgCell().clear();
      mainHero.getCurrentSkill().getDmgCell().add(selectCell);
      if(Utilizer.inRange(new Cell(panel.getMonster().getCol(),panel.getMonster().getRow()),
              mainHero.getCurrentSkill().getDmgCell()) ){
          panel.getMonster().setHP(panel.getMonster().getHP()-panel.getHero().getCurrentSkill().getDamage(mainHero));
          panel.setDamage(mainHero.getCurrentSkill().getDamage(panel.getHero()));
      }else panel.setDamage(0);*/
    }

    /*//cast cleave skill
    else if(panel.getHero().getIsChosen() && panel.getHero().getStatus().equals(HeroStatus.attacking)
            && panel.getHero().getCurrentSkill().getStatus().equals(SkillStatus.before)
            && panel.getHero().getCurrentSkill().getPath().contains(selectCell)
            && (panel.getHero().getAP()-panel.getHero().getCurrentSkill().getAP())>=0
            && ! (panel.getHero().getCurrentSkill() instanceof AOESkill)
            && ! (panel.getHero().getCurrentSkill() instanceof NormalSkill)){
        HeroAnimation.attack(panel.getHero(),panel);
        if(Utilizer.inRange(new Cell(panel.getMonster().getCol(),panel.getMonster().getRow()),
                panel.getHero().getCurrentSkill().getPath())){
            panel.getMonster().setHP(panel.getMonster().getHP()-panel.getHero().getCurrentSkill().getDamage());
        }
    }*/

    // cast normal skill
    /* else if(panel.getHero().getIsChosen() && panel.getHero().getStatus().equals(HeroStatus.attacking)
            && panel.getHero().getCurrentSkill().getStatus().equals(SkillStatus.before)
            && panel.getHero().getCurrentSkill().getPath().contains(selectCell)
            && (panel.getHero().getAP()-panel.getHero().getCurrentSkill().getAP())>=0
            && (panel.getHero().getCurrentSkill() instanceof NormalSkill)){
        HeroAnimation.attack(panel.getHero(),panel);
        Cell c = new Cell(panel.getMonster().getCol(),panel.getMonster().getRow());
        if(selectCell.equals(c)){
            panel.getMonster().setHP(panel.getMonster().getHP()-panel.getHero().getCurrentSkill().getDamage());
        }
    }*/
    // System.out.println(panel.getHero().getStatus());
    panel.repaint();
  }