コード例 #1
0
ファイル: ColonyWas.java プロジェクト: Thue/FreeCol
 /** Fire any property changes resulting from actions within a colony. */
 public void fireChanges() {
   int newPopulation = colony.getUnitCount();
   if (newPopulation != population) {
     String pc = ColonyChangeEvent.POPULATION_CHANGE.toString();
     colony.firePropertyChange(pc, population, newPopulation);
   }
   int newProductionBonus = colony.getProductionBonus();
   if (newProductionBonus != productionBonus) {
     String pc = ColonyChangeEvent.BONUS_CHANGE.toString();
     colony.firePropertyChange(pc, productionBonus, newProductionBonus);
   }
   List<BuildableType> newBuildQueue = colony.getBuildQueue();
   if (!newBuildQueue.equals(buildQueue)) {
     String pc = ColonyChangeEvent.BUILD_QUEUE_CHANGE.toString();
     colony.firePropertyChange(pc, buildQueue, newBuildQueue);
   }
   if (colony.getGoodsContainer() != null) {
     colony.getGoodsContainer().fireChanges();
   }
 }
コード例 #2
0
ファイル: UnitWas.java プロジェクト: amrecio/mymom
  /** Fire any property changes resulting from actions of a unit. */
  public void fireChanges() {
    UnitType newType = null;
    Unit.Role newRole = null;
    Location newLoc = null;
    GoodsType newWork = null;
    int newWorkAmount = 0;
    TypeCountMap<EquipmentType> newEquipment = null;
    if (!unit.isDisposed()) {
      newLoc = unit.getLocation();
      if (colony != null) {
        newType = unit.getType();
        newRole = unit.getRole();
        newWork = unit.getWorkType();
        newWorkAmount = (newWork == null) ? 0 : getAmount(newLoc, newWork);
        newEquipment = unit.getEquipment();
      }
    }

    if (loc != newLoc) {
      FreeColGameObject oldFcgo = (FreeColGameObject) loc;
      oldFcgo.firePropertyChange(change(oldFcgo), unit, null);
      if (newLoc != null) {
        FreeColGameObject newFcgo = (FreeColGameObject) newLoc;
        newFcgo.firePropertyChange(change(newFcgo), null, unit);
      }
    }
    if (colony != null) {
      if (type != newType && newType != null) {
        String pc = ColonyChangeEvent.UNIT_TYPE_CHANGE.toString();
        colony.firePropertyChange(pc, type, newType);
      } else if (role != newRole && newRole != null) {
        String pc = Tile.UNIT_CHANGE.toString();
        colony.firePropertyChange(pc, role.toString(), newRole.toString());
      }
      if (work == newWork) {
        if (work != null && workAmount != newWorkAmount) {
          colony.firePropertyChange(work.getId(), workAmount, newWorkAmount);
        }
      } else {
        if (work != null) {
          colony.firePropertyChange(work.getId(), workAmount, 0);
        }
        if (newWork != null) {
          colony.firePropertyChange(newWork.getId(), 0, newWorkAmount);
        }
      }
    }
    if (newEquipment != null) {
      Set<EquipmentType> keys = new HashSet<EquipmentType>();
      keys.addAll(equipment.keySet());
      keys.addAll(newEquipment.keySet());
      for (EquipmentType e : keys) {
        int cOld = equipment.getCount(e);
        int cNew = newEquipment.getCount(e);
        if (cOld != cNew) {
          unit.firePropertyChange(Unit.EQUIPMENT_CHANGE, cOld, cNew);
        }
      }
    }
    if (unit.getGoodsContainer() != null) {
      unit.getGoodsContainer().fireChanges();
    }
  }