Search in sources :

Example 56 with GameMode

use of pcgen.core.GameMode in project pcgen by PCGen.

the class CharacterStatsPanel method applyOptionValuesToControls.

/**
	 * @see pcgen.gui2.prefs.PCGenPrefsPanel#applyOptionValuesToControls()
	 */
@Override
public void applyOptionValuesToControls() {
    stopListeners();
    final GameMode gameMode = SettingsHandler.getGame();
    boolean bValid = true;
    final int rollMethod = gameMode.getRollMethod();
    switch(rollMethod) {
        case Constants.CHARACTER_STAT_METHOD_USER:
            abilitiesUserRolledButton.setSelected(true);
            break;
        case Constants.CHARACTER_STAT_METHOD_ALL_THE_SAME:
            abilitiesAllSameButton.setSelected(true);
            break;
        case Constants.CHARACTER_STAT_METHOD_PURCHASE:
            if (!abilitiesPurchasedButton.isVisible() || (pMode.length == 0)) {
                bValid = false;
            } else {
                abilitiesPurchasedButton.setSelected(true);
            }
            break;
        case Constants.CHARACTER_STAT_METHOD_ROLLED:
            if (abilitiesRolledButton == null) {
                bValid = false;
            } else {
                abilitiesRolledButton.setSelected(true);
                abilityRolledModeCombo.setSelectedItem(gameMode.getRollMethodExpressionName());
            }
            break;
        default:
            bValid = false;
            break;
    }
    if (!bValid) {
        abilitiesUserRolledButton.setSelected(true);
        gameMode.setRollMethod(Constants.CHARACTER_STAT_METHOD_USER);
    }
    int allStatsValue = Math.min(gameMode.getStatMax(), gameMode.getAllStatsValue());
    allStatsValue = Math.max(gameMode.getStatMin(), allStatsValue);
    gameMode.setAllStatsValue(allStatsValue);
    abilityScoreCombo.setSelectedIndex(allStatsValue - gameMode.getStatMin());
    if ((pMode != null) && (pModeMethodName != null)) {
        final String methodName = gameMode.getPurchaseModeMethodName();
        for (int i = 0; i < pMode.length; ++i) {
            if (pModeMethodName[i].equals(methodName)) {
                abilityPurchaseModeCombo.setSelectedIndex(i);
            }
        }
    }
    startListeners();
}
Also used : GameMode(pcgen.core.GameMode)

Example 57 with GameMode

use of pcgen.core.GameMode in project pcgen by PCGen.

the class CharacterStatsPanel method showPurchaseModeConfiguration.

/**
	 * Create and display purchase mode stats popup frame.
	 */
private void showPurchaseModeConfiguration() {
    if (pmsFrame == null) {
        pmsFrame = new PurchaseModeFrame(parent);
        final GameMode gameMode = SettingsHandler.getGame();
        pmsFrame.setStatMin(gameMode.getStatMin());
        pmsFrame.setStatMax(gameMode.getStatMax());
        // add a listener to know when the window has closed
        pmsFrame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosed(WindowEvent e) {
                Collection<PointBuyMethod> methods = SettingsHandler.getGame().getModeContext().getReferenceContext().getConstructedCDOMObjects(PointBuyMethod.class);
                final int purchaseMethodCount = methods.size();
                pMode = new String[purchaseMethodCount];
                pModeMethodName = new String[purchaseMethodCount];
                final String methodName = SettingsHandler.getGame().getPurchaseModeMethodName();
                abilityPurchaseModeCombo.removeAllItems();
                int i = 0;
                for (PointBuyMethod pbm : methods) {
                    pMode[i] = pbm.getDescription();
                    pModeMethodName[i] = pbm.getDisplayName();
                    abilityPurchaseModeCombo.addItem(pMode[i]);
                    if (pModeMethodName[i].equals(methodName)) {
                        abilityPurchaseModeCombo.setSelectedIndex(i);
                    }
                    i++;
                }
                // free resources
                pmsFrame = null;
                //
                // If user has added at least one method, then make the controls visible. Otherwise
                // it is not a valid choice and cannot be selected, so hide it.
                //
                abilityPurchaseModeCombo.setVisible(purchaseMethodCount != 0);
                abilitiesPurchasedButton.setVisible(purchaseMethodCount != 0);
                //
                if (!abilitiesPurchasedButton.isVisible() && abilitiesPurchasedButton.isSelected()) {
                    abilitiesUserRolledButton.setSelected(true);
                }
            }
        });
    }
    Utility.centerComponent(pmsFrame);
    // ensure the frame is visible (in case user selects menu item again).
    pmsFrame.setVisible(true);
}
Also used : GameMode(pcgen.core.GameMode) PointBuyMethod(pcgen.core.PointBuyMethod) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) Collection(java.util.Collection)

Example 58 with GameMode

use of pcgen.core.GameMode in project pcgen by PCGen.

the class HouseRulesPanel method setOptionsBasedOnControls.

/**
	 * @see pcgen.gui2.prefs.PreferencesPanel#applyPreferences()
	 */
@Override
public void setOptionsBasedOnControls() {
    final GameMode gameMode = SettingsHandler.getGame();
    for (int i = 0; i < hrBoxes.length; i++) {
        if (hrBoxes[i] != null) {
            String aKey = hrBoxes[i].getActionCommand();
            boolean aBool = hrBoxes[i].isSelected();
            // Save settings
            if (gameMode.getModeContext().getReferenceContext().containsConstructedCDOMObject(RuleCheck.class, aKey)) {
                SettingsHandler.setRuleCheck(aKey, aBool);
            }
        }
    }
    for (int i = 0; i < hrRadio.length; i++) {
        if (hrRadio[i] != null) {
            String aKey = hrRadio[i].getActionCommand();
            boolean aBool = hrRadio[i].isSelected();
            // Save settings
            if (gameMode.getModeContext().getReferenceContext().containsConstructedCDOMObject(RuleCheck.class, aKey)) {
                SettingsHandler.setRuleCheck(aKey, aBool);
            }
        }
    }
}
Also used : GameMode(pcgen.core.GameMode)

Aggregations

GameMode (pcgen.core.GameMode)58 PCStat (pcgen.core.PCStat)10 PlayerCharacter (pcgen.core.PlayerCharacter)8 File (java.io.File)7 Campaign (pcgen.core.Campaign)7 LoadContext (pcgen.rules.context.LoadContext)7 LevelInfo (pcgen.core.LevelInfo)6 Race (pcgen.core.Race)6 AbstractReferenceContext (pcgen.rules.context.AbstractReferenceContext)6 ArrayList (java.util.ArrayList)5 PCClass (pcgen.core.PCClass)5 BonusObj (pcgen.core.bonus.BonusObj)4 Before (org.junit.Before)3 Equipment (pcgen.core.Equipment)3 CampaignFacade (pcgen.facade.core.CampaignFacade)3 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 Writer (java.io.Writer)2 HashMap (java.util.HashMap)2 JLabel (javax.swing.JLabel)2