Search in sources :

Example 1 with AlignmentFacade

use of pcgen.facade.core.AlignmentFacade in project pcgen by PCGen.

the class CharacterFacadeImpl method validateAlignmentChange.

/**
	 * Validate the new alignment matches those allowed for the character's 
	 * classes. If not offer the user a choice of backing out or making the 
	 * classes into ex-classes.
	 * 
	 * @param newAlign The alignment to be set
	 */
private boolean validateAlignmentChange(AlignmentFacade newAlign) {
    AlignmentFacade oldAlign = this.alignment.get();
    if (oldAlign == null || newAlign.equals(oldAlign)) {
        return true;
    }
    // We can't do any validation if the new alignment isn't a known class
    if (!(newAlign instanceof PCAlignment)) {
        return true;
    }
    //
    // Get a list of classes that will become unqualified (and have an ex-class)
    //
    StringBuilder unqualified = new StringBuilder(100);
    List<PCClass> classList = charDisplay.getClassList();
    List<PCClass> exclassList = new ArrayList<>();
    PCAlignment savedAlignmnet = charDisplay.getPCAlignment();
    for (PCClass aClass : classList) {
        theCharacter.setAlignment((PCAlignment) newAlign);
        {
            if (!theCharacter.isQualified(aClass)) {
                if (aClass.containsKey(ObjectKey.EX_CLASS)) {
                    if (unqualified.length() > 0) {
                        //$NON-NLS-1$
                        unqualified.append(", ");
                    }
                    unqualified.append(aClass.getKeyName());
                    exclassList.add(aClass);
                }
            }
        }
    }
    //
    if (unqualified.length() > 0) {
        if (!delegate.showWarningConfirm(Constants.APPLICATION_NAME, LanguageBundle.getString("in_sumExClassesWarning") + Constants.LINE_SEPARATOR + unqualified)) {
            theCharacter.setAlignment(savedAlignmnet);
            return false;
        }
    }
    //
    for (PCClass aClass : exclassList) {
        theCharacter.makeIntoExClass(aClass);
    }
    // Update the facade and UI
    refreshClassLevelModel();
    return true;
}
Also used : PCAlignment(pcgen.core.PCAlignment) ArrayList(java.util.ArrayList) AlignmentFacade(pcgen.facade.core.AlignmentFacade) PCClass(pcgen.core.PCClass)

Aggregations

ArrayList (java.util.ArrayList)1 PCAlignment (pcgen.core.PCAlignment)1 PCClass (pcgen.core.PCClass)1 AlignmentFacade (pcgen.facade.core.AlignmentFacade)1