Exemplo n.º 1
0
  private void executeClick(UIDisplayElement element, int id) {
    lblError.setText("");
    if (MinionSystem.getNewZone() == null) {
      newzonefound = false;
      MinionSystem.resetNewSelection();
      lblError.setText("Something went wrong. Please close the book and recreate the selection.");
    }
    if (MinionSystem.getNewZone().zonetype == ZoneType.OreonFarm) {
      if (MinionSystem.getNewZone().getEndPosition() == null) {
        newzonefound = false;
        MinionSystem.resetNewSelection();
        lblError.setText("Something went wrong. Please close the book and recreate the selection.");
      } else {

      }
    }
    if ((!cmbType.isVisible()) && MinionSystem.getNewZone() == null) {
      newzonefound = false;
      this.close();
    }
    if (cmbType.isVisible() && cmbType.getSelection() == null) {
      lblError.setText("Please select a zone type");
      return;
    }
    if (cmbType.isVisible() && cmbType.getSelection() != null) {
      if (ZoneType.valueOf(cmbType.getSelection().getText()) == ZoneType.OreonFarm) {
        if (MinionSystem.getNewZone().getMinBounds().y
            != MinionSystem.getNewZone().getMaxBounds().y) {
          newzonefound = false;
          lblError.setText(
              "A farm zone needs to be level. Please select a flat zone and try again");
          return;
        }
      }
    }
    if (txtzonename.getText().length() < 3) {
      lblError.setText("Zone name needs to be longer then 2 characters!");
      return;
    }
    for (Zone zone : MinionSystem.getGatherZoneList()) {
      if (zone.Name.matches(txtzonename.getText())) {
        lblError.setText("Zone name already exists!");
        return;
      }
    }
    for (Zone zone : MinionSystem.getTerraformZoneList()) {
      if (zone.Name.matches(txtzonename.getText())) {
        lblError.setText("Zone name already exists!");
        return;
      }
    }
    for (Zone zone : MinionSystem.getWorkZoneList()) {
      if (zone.Name.matches(txtzonename.getText())) {
        lblError.setText("Zone name already exists!");
        return;
      }
    }
    int tmp;
    try {
      tmp = Integer.parseInt(txtheight.getText());
      tmp = Integer.parseInt(txtwidth.getText());
      tmp = Integer.parseInt(txtdepth.getText());
      lblError.setText("value needs to be an number, check for trailing spaces!");
    } catch (NumberFormatException e) {
      return;
    }
    Zone newzone =
        new Zone(
            MinionSystem.getNewZone().getStartPosition(),
            MinionSystem.getNewZone().getEndPosition());
    newzone.Name = txtzonename.getText();
    newzone.zoneheight = Integer.parseInt(txtheight.getText());
    newzone.zonewidth = Integer.parseInt(txtwidth.getText());
    newzone.zonedepth = Integer.parseInt(txtdepth.getText());
    if (cmbType.isVisible()) {
      newzone.zonetype = ZoneType.valueOf(cmbType.getSelection().getText());
    } else {
      newzone.zonetype = MinionSystem.getNewZone().zonetype;
    }
    MinionSystem.addZone(newzone);
    newzonefound = false;
    lblzonetype.setText("");
    MinionSystem.resetNewSelection();
    this.close();
  }