Search in sources :

Example 1 with PlayerCharacterWasLoadedMessage

use of pcgen.pluginmgr.messages.PlayerCharacterWasLoadedMessage in project pcgen by PCGen.

the class CharacterManager method openPcInternal.

@SuppressWarnings("unchecked")
private static PlayerCharacter openPcInternal(File file, UIDelegate delegate, DataSetFacade dataset, boolean blockLoadedMessage) {
    @SuppressWarnings("rawtypes") List campaigns = ListFacades.wrap(dataset.getCampaigns());
    final PCGIOHandler ioHandler = new PCGIOHandler();
    final PlayerCharacter newPC;
    try {
        newPC = new PlayerCharacter(campaigns);
        newPC.setFileName(file.getAbsolutePath());
        ioHandler.read(newPC, file.getAbsolutePath());
        // Ensure any custom equipment held by the character is added to the dataset's list
        dataset.refreshEquipment();
        if (!showLoadNotices(true, ioHandler.getErrors(), file.getName(), delegate)) {
            // if we've had errors, then abort trying to add the new PC, it's most likely "broken"
            return null;
        }
        if (!showLoadNotices(false, ioHandler.getWarnings(), file.getName(), delegate)) {
            return null;
        }
        Logging.log(Logging.INFO, //$NON-NLS-1$
        "Loaded character " + newPC.getName() + " - " + //$NON-NLS-1$
        file.getAbsolutePath());
        // if it's not broken, then only warnings should have been generated, and we won't count those
        // Register the character so that future checks to see if file already loaded will work
        Globals.getPCList().add(newPC);
        if (!blockLoadedMessage) {
            messageHandler.handleMessage(new PlayerCharacterWasLoadedMessage(delegate, newPC));
        }
        return newPC;
    } catch (final Exception e) {
        //$NON-NLS-1$
        Logging.errorPrint("Unable to load character " + file, e);
        delegate.showErrorMessage(//$NON-NLS-1$
        LanguageBundle.getString("in_cmLoadErrorTitle"), //$NON-NLS-1$
        LanguageBundle.getFormattedString(//$NON-NLS-1$
        "in_cmLoadErrorMessage", file, e.getMessage()));
        return null;
    }
}
Also used : PlayerCharacterWasLoadedMessage(pcgen.pluginmgr.messages.PlayerCharacterWasLoadedMessage) PCGIOHandler(pcgen.io.PCGIOHandler) PlayerCharacter(pcgen.core.PlayerCharacter) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException)

Example 2 with PlayerCharacterWasLoadedMessage

use of pcgen.pluginmgr.messages.PlayerCharacterWasLoadedMessage in project pcgen by PCGen.

the class PCGTrackerPlugin method handleMessage.

/**
	 * listens to messages from the GMGen system, and handles them as needed
	 * @param message the source of the event from the system
	 */
@Override
public void handleMessage(PCGenMessage message) {
    if (message instanceof FileMenuOpenMessage) {
        if (isActive()) {
            handleOpen();
        }
    } else if (message instanceof PlayerCharacterWasLoadedMessage) {
        PlayerCharacterWasLoadedMessage cmessage = (PlayerCharacterWasLoadedMessage) message;
        model.add(cmessage.getPc());
    } else if (message instanceof FocusOrStateChangeOccurredMessage) {
        if (isActive()) {
            charToolsItem.setEnabled(false);
            try {
                GMGenSystem.inst.openFileItem.setEnabled(true);
            } catch (Exception e) {
            // TODO Handle this?
            }
        } else {
            charToolsItem.setEnabled(true);
        }
    } else if (message instanceof GMGenBeingClosedMessage) {
        handleClose();
    } else /*else if (message instanceof SavePCGRequestMessage)
		 {
		 SavePCGRequestMessage smessage = (SavePCGRequestMessage) message;
		 savePC(smessage.getPC(), false);
		 }*/
    if (message instanceof PlayerCharacterWasClosedMessage) {
        PlayerCharacterWasClosedMessage cmessage = (PlayerCharacterWasClosedMessage) message;
        model.remove(cmessage.getPC());
    }
}
Also used : PlayerCharacterWasLoadedMessage(pcgen.pluginmgr.messages.PlayerCharacterWasLoadedMessage) FocusOrStateChangeOccurredMessage(pcgen.pluginmgr.messages.FocusOrStateChangeOccurredMessage) FileMenuOpenMessage(gmgen.pluginmgr.messages.FileMenuOpenMessage) PlayerCharacterWasClosedMessage(pcgen.pluginmgr.messages.PlayerCharacterWasClosedMessage) GMGenBeingClosedMessage(gmgen.pluginmgr.messages.GMGenBeingClosedMessage)

Example 3 with PlayerCharacterWasLoadedMessage

use of pcgen.pluginmgr.messages.PlayerCharacterWasLoadedMessage in project pcgen by PCGen.

the class GMGenMessageHandler method handleFetchOpenPCGRequestMessage.

private void handleFetchOpenPCGRequestMessage() {
    for (int i = 0; i < CharacterManager.getCharacters().getSize(); i++) {
        CharacterFacade facade = CharacterManager.getCharacters().getElementAt(i);
        if (facade instanceof CharacterFacadeImpl) {
            CharacterFacadeImpl cfi = (CharacterFacadeImpl) facade;
            messageHandler.handleMessage(new PlayerCharacterWasLoadedMessage(this, cfi.getTheCharacter()));
        }
    }
}
Also used : PlayerCharacterWasLoadedMessage(pcgen.pluginmgr.messages.PlayerCharacterWasLoadedMessage) CharacterFacade(pcgen.facade.core.CharacterFacade)

Example 4 with PlayerCharacterWasLoadedMessage

use of pcgen.pluginmgr.messages.PlayerCharacterWasLoadedMessage in project pcgen by PCGen.

the class CharacterManager method createNewCharacter.

/**
	 * Create a new character using the supplied data sets.
	 * @param delegate the UIDelegate that this character will use.
	 * @param dataset the dataset that this will be loaded with.
	 * @return The character that was created.
	 */
public static CharacterFacade createNewCharacter(UIDelegate delegate, DataSetFacade dataset) {
    @SuppressWarnings("rawtypes") List campaigns = ListFacades.wrap(dataset.getCampaigns());
    try {
        @SuppressWarnings("unchecked") PlayerCharacter pc = new PlayerCharacter(campaigns);
        Globals.getPCList().add(pc);
        CharacterFacade character = new CharacterFacadeImpl(pc, delegate, dataset);
        String name = createNewCharacterName();
        character.setName(name);
        characters.addElement(character);
        //$NON-NLS-1$ //$NON-NLS-2$
        Logging.log(Logging.INFO, "Created new character " + name + '.');
        messageHandler.handleMessage(new PlayerCharacterWasLoadedMessage(delegate, pc));
        return character;
    } catch (final Exception e) {
        Logging.errorPrint(//$NON-NLS-1$
        "Unable to create character with data " + dataset, e);
        delegate.showErrorMessage(//$NON-NLS-1$
        LanguageBundle.getString("in_cmCreateErrorTitle"), //$NON-NLS-1$
        LanguageBundle.getFormattedString(//$NON-NLS-1$
        "in_cmCreateErrorMessage", e.getMessage()));
        return null;
    }
}
Also used : PlayerCharacterWasLoadedMessage(pcgen.pluginmgr.messages.PlayerCharacterWasLoadedMessage) PlayerCharacter(pcgen.core.PlayerCharacter) ArrayList(java.util.ArrayList) List(java.util.List) CharacterFacade(pcgen.facade.core.CharacterFacade) IOException(java.io.IOException) CharacterFacadeImpl(pcgen.gui2.facade.CharacterFacadeImpl)

Aggregations

PlayerCharacterWasLoadedMessage (pcgen.pluginmgr.messages.PlayerCharacterWasLoadedMessage)4 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 PlayerCharacter (pcgen.core.PlayerCharacter)2 CharacterFacade (pcgen.facade.core.CharacterFacade)2 FileMenuOpenMessage (gmgen.pluginmgr.messages.FileMenuOpenMessage)1 GMGenBeingClosedMessage (gmgen.pluginmgr.messages.GMGenBeingClosedMessage)1 CharacterFacadeImpl (pcgen.gui2.facade.CharacterFacadeImpl)1 PCGIOHandler (pcgen.io.PCGIOHandler)1 FocusOrStateChangeOccurredMessage (pcgen.pluginmgr.messages.FocusOrStateChangeOccurredMessage)1 PlayerCharacterWasClosedMessage (pcgen.pluginmgr.messages.PlayerCharacterWasClosedMessage)1