Ejemplo n.º 1
0
 void update_rightclickselection() {
   if (Center.rightMouseDown()) {
     if (!checkMouseOver()) return;
     if (Center.rightMouseClicked()) {
       Vector2 mousepos = screenToMap(Center.mousePosition());
       rightclickdragstartposition = mousepos;
       float dist = 99999;
       ArrayList<EventLocation> selectedlocations = new ArrayList<EventLocation>();
       for (EventLocation location : spawns) {
         float d = Vector2.distance(mousepos, location.position);
         if (d == dist) {
           selectedlocations.add(location);
         } else if (d < dist) {
           selectedlocations.clear();
           dist = d;
           selectedlocations.add(location);
         }
       }
       if (!Center.getKey(Keys.SHIFT) && !Center.getKey(Keys.CONTROL)) SpawnList.clearSelections();
       for (EventLocation location : selectedlocations) {
         SpawnList.instance.selectedSpawns.add(location);
         SpawnList.instance.focusOnBar(spawns.indexOf(location));
       }
     }
     if (rightclickdragstartposition == null) return;
     Vector2 mousepos = screenToMap(Center.mousePosition());
     if (!Vector2.distanceLessThan(rightclickdragstartposition, mousepos, .1f)) {
       Vector2 pos0 =
           new Vector2(
               mousepos.x < rightclickdragstartposition.x
                   ? mousepos.x
                   : rightclickdragstartposition.x,
               mousepos.y < rightclickdragstartposition.y
                   ? mousepos.y
                   : rightclickdragstartposition.y);
       Vector2 pos1 =
           new Vector2(
               mousepos.x > rightclickdragstartposition.x
                   ? mousepos.x
                   : rightclickdragstartposition.x,
               mousepos.y > rightclickdragstartposition.y
                   ? mousepos.y
                   : rightclickdragstartposition.y);
       if (!Center.getKey(Keys.SHIFT) && !Center.getKey(Keys.CONTROL)) SpawnList.clearSelections();
       for (EventLocation location : spawns) {
         if (location.position.x > pos0.x
             && location.position.y > pos0.y
             && location.position.x < pos1.x
             && location.position.y < pos1.y) SpawnList.selectedSpawns.add(location);
       }
     }
   } else rightclickdragstartposition = null;
 }
Ejemplo n.º 2
0
  public void update() { // sorry for all the megafunctions here
    super.update();

    scale = desiredscale * SCALELERPAMOUNT + scale * (1 - SCALELERPAMOUNT);
    // drawOffset = viewOffset.add(scale);

    update_middleclickmapmovement();
    update_rightclickselection();

    if (this.checkMouseOver()) {
      if (Center.leftMouseDown()) {
        if (Center.leftMouseClicked()) {
          currentPoint =
              new EventLocation(
                  Center.mousePosition(), Gui.SpawnLocationCreator_getDesiredSpawnType());
          SpawnList.clearSelections();
        }
        if (currentPoint != null) {
          currentPoint.position = screenToMap(Center.mousePosition());
          if (!checkValidSpawnLocation()) {
            showMessage("Invalid location.");
            currentPoint.position = new Vector2(9999, 0);
          } else {
            switch (snapType) {
              case None:
                break;
              case Grid:
                currentPoint.useSnap_Cartesian(.2f);
                break;
              case Ring:
                currentPoint.useSnap_Polar(_G.PI / 12, .2f);
                break;
            }
            String mess = "Placing point.";
            for (int i = 0; i < (_G.cycle % 150) / 50; i++) mess += '.';
            showMessage(mess);
          }
        }
      } else if (currentPoint != null) {
        if (!checkValidSpawnLocation()) { // Out of bounds
          showMessage("Invalid location.");
          currentPoint = null;
        } else {
          /*if(currentPoint.type == EventType.PlotHole){
          	if(currentPoint.position.x > FIELDUNITSIZE.x*2 || currentPoint.position.x < -FIELDUNITSIZE.x*2 || currentPoint.position.y > FIELDUNITSIZE.y*2 || currentPoint.position.y < -FIELDUNITSIZE.y*2){
          		showMessage("WARNING: Plot Hole will be moved.");
          	}else{
          		showMessage("Plot Hole placed!");
          	}
          }else{*/
          if (currentPoint.position.magnitude() < 2) {
            showMessage("WARNING: Location is too close!");
          } else {
            showMessage("Point placed!");
          }
          // }
          addSpawnLocation(currentPoint);
          SpawnList.selectSpawn(currentPoint);
          currentPoint = null;
        }
      }
    } else if (currentPoint != null) {
      if (Center.leftMouseDown()) {
        showMessage("Invalid location.");
        currentPoint.position = new Vector2(9999, 0);
      } else {
        currentPoint = null;
        showMessage("Point placement cancelled.");
      }
    } else if (SpawnList.selectedSpawns.size() != 0) {
      int siz = SpawnList.selectedSpawns.size();
      // showMessage(""+siz+(siz == 1 ? " point selected." : " points selected."));
    }
  }