From: <aki...@us...> - 2008-07-30 20:05:23
|
Revision: 4589 http://gridarta.svn.sourceforge.net/gridarta/?rev=4589&view=rev Author: akirschbaum Date: 2008-07-30 20:05:21 +0000 (Wed, 30 Jul 2008) Log Message: ----------- Move code to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/gameobjectattributesdialog/GameObjectAttributesDialog.java trunk/daimonin/src/daieditor/gui/gameobjectattributesdialog/GameObjectAttributesDialog.java trunk/src/app/net/sf/gridarta/gui/gameobjectattributesdialog/AbstractGameObjectAttributesDialog.java Modified: trunk/crossfire/src/cfeditor/gui/gameobjectattributesdialog/GameObjectAttributesDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/gameobjectattributesdialog/GameObjectAttributesDialog.java 2008-07-30 19:48:39 UTC (rev 4588) +++ trunk/crossfire/src/cfeditor/gui/gameobjectattributesdialog/GameObjectAttributesDialog.java 2008-07-30 20:05:21 UTC (rev 4589) @@ -23,26 +23,15 @@ import cfeditor.gameobject.GameObject; import cfeditor.gui.map.CMapViewBasic; import cfeditor.map.MapArchObject; -import java.util.Vector; -import javax.swing.JComboBox; import javax.swing.filechooser.FileFilter; import net.sf.gridarta.MainControl; import net.sf.gridarta.MapManager; -import net.sf.gridarta.archtype.ArchetypeAttribute; -import net.sf.gridarta.archtype.ArchetypeAttributeTypeFixed; -import net.sf.gridarta.archtype.ArchetypeAttributeTypeZSpell; -import net.sf.gridarta.archtype.ArchetypeType; import net.sf.gridarta.archtype.ArchetypeTypeSet; import net.sf.gridarta.gameobject.ArchetypeSet; import net.sf.gridarta.gameobject.anim.AnimationObjects; import net.sf.gridarta.gameobject.face.FaceObjects; import net.sf.gridarta.gui.gameobjectattributesdialog.AbstractGameObjectAttributesDialog; import net.sf.gridarta.gui.gameobjectattributesdialog.AbstractGameObjectAttributesDialogFactory; -import net.sf.gridarta.gui.gameobjectattributesdialog.DialogAttrib; -import net.sf.gridarta.gui.gameobjectattributesdialog.StringKeyManager; -import net.sf.gridarta.spells.NumberSpell; -import net.sf.gridarta.spells.Spell; -import net.sf.gridarta.spells.Spells; import net.sf.gridarta.treasurelist.CFTreasureListTree; import org.jetbrains.annotations.NotNull; @@ -57,16 +46,7 @@ /** Serial Version UID. */ private static final long serialVersionUID = 1L; - /** The map manager. */ - @NotNull - private final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager; - /** - * The index used for "no" spell. - */ - private final int undefinedSpellIndex; - - /** * Constructor, creates the GUI layout. * @param gameObjectAttributesDialogFactory the associated factory * @param archetypeTypeSet the list of CF type-data @@ -84,160 +64,7 @@ * text */ public GameObjectAttributesDialog(@NotNull final AbstractGameObjectAttributesDialogFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> gameObjectAttributesDialogFactory, @NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final GameObject gameObject, @NotNull final MainControl<GameObject, MapArchObject, Archetype, CMapViewBasic> mainControl, @NotNull final ArchetypeSet<GameObject, MapArchObject, Archetype> archetypeSet, @NotNull final AnimationObjects<?> animationObjects, @NotNull final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager, @NotNull final CFTreasureListTree<GameObject, MapArchObject, Archetype> treasureListTree, @NotNull final FaceObjects faceObjects, @NotNull final FileFilter mapFileFilter, final int typeNoEventConnector, final int undefinedSpellIndex, final boolean includeFaceText) { - super(gameObjectAttributesDialogFactory, archetypeTypeSet, gameObject, mainControl, archetypeSet, animationObjects, treasureListTree, faceObjects, mapFileFilter, typeNoEventConnector, undefinedSpellIndex, includeFaceText); - this.mapManager = mapManager; - this.undefinedSpellIndex = undefinedSpellIndex; + super(gameObjectAttributesDialogFactory, archetypeTypeSet, gameObject, mainControl, archetypeSet, mapManager, animationObjects, treasureListTree, faceObjects, mapFileFilter, typeNoEventConnector, undefinedSpellIndex, includeFaceText); } - /** {@inheritDoc} */ - @Override - protected JComboBox buildSpellBox(final ArchetypeAttribute attr) { - // first parse the spell-number value from gameObject - int spnum = gameObject.getAttributeInt(attr.getNameOld()); // spell number - - if (spnum < 0 || spnum >= mainControl.getNumberSpells().size()) { - spnum = undefinedSpellIndex; - } - - // do we have "none" spell? - final int selectedIndex; - if (spnum == undefinedSpellIndex && attr.getDataType() instanceof ArchetypeAttributeTypeZSpell) { - selectedIndex = 0; - } else { - // now look up the spell-number in the array of spells - selectedIndex = 1 + findSpellIndex(spnum); - } - - final Vector<String> content = new Vector<String>(); - content.add("<none>"); - for (final Spell spell : mainControl.getNumberSpells()) { - content.add(spell.getName()); - } - final JComboBox comboBox = new JComboBox(content); - comboBox.setSelectedIndex(selectedIndex); - comboBox.setMaximumRowCount(10); - comboBox.setKeySelectionManager(new StringKeyManager(comboBox)); - comboBox.setName(attr.getNameNew()); - return comboBox; - } - - /** - * Return the spell index for a spell number. - * @param number The spell number. - * @return The spell object. - */ - private int findSpellIndex(final int number) { - final Spells<NumberSpell> spells = mainControl.getNumberSpells(); - for (int i = 0; i < spells.size(); i++) { - if (spells.getSpell(i).getNumber() == number) { - return i; - } - } - return -1; - } - - /** {@inheritDoc} */ - @Override - protected boolean applySettings2() { - final ArchetypeType typeStruct = archetypeTypeSet.getTypeOfArch(gameObject); // the type structure for this gameObject - - final StringBuilder newArchText = new StringBuilder(); - final String[] newName = new String[1]; - final String[] newFace = new String[1]; - final String[] newMsg = new String[1]; - final String[] newAnim = new String[1]; - for (final DialogAttrib<GameObject, MapArchObject, Archetype, ?> attr : dialogAttribs) { - final String text = attr.getText2(gameObject, archetype, newName, newFace, newMsg, newAnim, typeStruct, this); - if (text == null) { - return false; - } - if (text.length() > 0) { - newArchText.append(text).append("\n"); - } - } - - // Also write all the 'fixed' attributes into the archtext - for (int i = 0; type.getAttr().length > i; i++) { - // ### TODO: for changed types, copy fixed attributes over default arches ### - if (type.getAttr()[i].getDataType() instanceof ArchetypeAttributeTypeFixed) { - final String defaultValue = archetype.getAttributeString(type.getAttr()[i].getNameOld()); - if (defaultValue.length() == 0 || (gameObject.getArchTypNr() != archetype.getArchTypNr() && !defaultValue.equalsIgnoreCase(type.getAttr()[i].getNameNew()))) { - // usually, fixed attributes are only applied when *not* defined in the archetype. - // the reason behind this is: if the default gameObject violates our fixed attribute, - // we assume the default gameObject is "right" and we are "wrong". The typedefs aren't that trustworthy. - // BUT - if the gameObject has a changed type, the archetype has lost it's credibility. - // So, in this special case, the fixed attribute applies always. - newArchText.append(type.getAttr()[i].getNameOld()).append(" ").append(type.getAttr()[i].getNameNew()).append("\n"); - } - } - } - - /* we have excluded direction hard coded from the attribut panel - * because we have a better interface in the gameObject panel. - * But we need to add when needed the gameObject text - we do it here. - */ - if (gameObject.getDirection() != archetype.getDirection()) { - newArchText.append("direction ").append(gameObject.getDirection()).append("\n"); - } - // before we modify the archtext, we look for errors and save them. - // later the user must confirm whether to keep or dump those errors - final String errors = gameObject.getSyntaxErrors(typeStruct); - - // --- parsing succeeded, now we write it into the gameObject/map --- - gameObject.setObjectText(newArchText.toString()); - //gameObject.setArchTypNr(); - if (newName[0] != null) { - if (newName[0].length() == 0) { - gameObject.setObjName(null); - } else { - gameObject.setObjName(newName[0]); - } - } - - if (newFace[0] != null) { - gameObject.setRealFace(newFace[0]); - } - - // now lets assign the visible face - perhaps we have still a anim - gameObject.setObjectFace(); - imagePanel.setIcon(getFace(gameObject)); - - if (newMsg[0] != null) { - // set new msg text only when it is not equal to Archetype - if (!newMsg[0].trim().equals(archetype.getMsgText() == null ? "" : archetype.getMsgText().trim())) { - gameObject.deleteMsgText(); - gameObject.addMsgText(newMsg[0]); - } else { - gameObject.deleteMsgText(); - } - } else - if (archetype.getMsgText() != null && archetype.getMsgText().trim().length() > 0) { - // we must override archetype msg by an empty msg - gameObject.deleteMsgText(); - gameObject.addMsgText(""); - } else { - gameObject.deleteMsgText(); // all empty - } - - if (newAnim[0] != null) { - gameObject.setAnimName(newAnim[0]); - } - - // deal with syntax errors now - if (errors != null) { - if (typeStruct == archetypeTypeSet.getArchetypeType(0)) { - // for generic (misc) type, all errors are automatically kept. - // "misc" is no real type - it is more a default mask for unknown types - gameObject.addObjectText(errors.trim()); - } else { - // open a popup dialog and ask user to decide what to do with his errors - askConfirmErrors(errors); - } - } - - gameObject.updateEditType(mapManager.getCurrentMap().getActiveEditType()); - - return true; // apply succeeded - } - } // class GameObjectAttributesDialog Modified: trunk/daimonin/src/daieditor/gui/gameobjectattributesdialog/GameObjectAttributesDialog.java =================================================================== --- trunk/daimonin/src/daieditor/gui/gameobjectattributesdialog/GameObjectAttributesDialog.java 2008-07-30 19:48:39 UTC (rev 4588) +++ trunk/daimonin/src/daieditor/gui/gameobjectattributesdialog/GameObjectAttributesDialog.java 2008-07-30 20:05:21 UTC (rev 4589) @@ -23,26 +23,15 @@ import daieditor.gameobject.GameObject; import daieditor.gui.map.CMapViewBasic; import daieditor.map.MapArchObject; -import java.util.Vector; -import javax.swing.JComboBox; import javax.swing.filechooser.FileFilter; import net.sf.gridarta.MainControl; import net.sf.gridarta.MapManager; -import net.sf.gridarta.archtype.ArchetypeAttribute; -import net.sf.gridarta.archtype.ArchetypeAttributeTypeFixed; -import net.sf.gridarta.archtype.ArchetypeAttributeTypeZSpell; -import net.sf.gridarta.archtype.ArchetypeType; import net.sf.gridarta.archtype.ArchetypeTypeSet; import net.sf.gridarta.gameobject.ArchetypeSet; import net.sf.gridarta.gameobject.anim.AnimationObjects; import net.sf.gridarta.gameobject.face.FaceObjects; import net.sf.gridarta.gui.gameobjectattributesdialog.AbstractGameObjectAttributesDialog; import net.sf.gridarta.gui.gameobjectattributesdialog.AbstractGameObjectAttributesDialogFactory; -import net.sf.gridarta.gui.gameobjectattributesdialog.DialogAttrib; -import net.sf.gridarta.gui.gameobjectattributesdialog.StringKeyManager; -import net.sf.gridarta.spells.NumberSpell; -import net.sf.gridarta.spells.Spell; -import net.sf.gridarta.spells.Spells; import net.sf.gridarta.treasurelist.CFTreasureListTree; import org.jetbrains.annotations.NotNull; @@ -57,16 +46,7 @@ /** Serial Version UID. */ private static final long serialVersionUID = 1L; - /** The map manager. */ - @NotNull - private final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager; - /** - * The index used for "no" spell. - */ - private final int undefinedSpellIndex; - - /** * Constructor, creates the GUI layout. * @param gameObjectAttributesDialogFactory the associated factory * @param archetypeTypeSet the list of CF type-data @@ -84,160 +64,7 @@ * text */ public GameObjectAttributesDialog(@NotNull final AbstractGameObjectAttributesDialogFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> gameObjectAttributesDialogFactory, @NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final GameObject gameObject, @NotNull final MainControl<GameObject, MapArchObject, Archetype, CMapViewBasic> mainControl, @NotNull final ArchetypeSet<GameObject, MapArchObject, Archetype> archetypeSet, @NotNull final AnimationObjects<?> animationObjects, @NotNull final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager, @NotNull final CFTreasureListTree<GameObject, MapArchObject, Archetype> treasureListTree, @NotNull final FaceObjects faceObjects, @NotNull final FileFilter mapFileFilter, final int typeNoEventConnector, final int undefinedSpellIndex, final boolean includeFaceText) { - super(gameObjectAttributesDialogFactory, archetypeTypeSet, gameObject, mainControl, archetypeSet, animationObjects, treasureListTree, faceObjects, mapFileFilter, typeNoEventConnector, undefinedSpellIndex, includeFaceText); - this.mapManager = mapManager; - this.undefinedSpellIndex = undefinedSpellIndex; + super(gameObjectAttributesDialogFactory, archetypeTypeSet, gameObject, mainControl, archetypeSet, mapManager, animationObjects, treasureListTree, faceObjects, mapFileFilter, typeNoEventConnector, undefinedSpellIndex, includeFaceText); } - /** {@inheritDoc} */ - @Override - protected JComboBox buildSpellBox(final ArchetypeAttribute attr) { - // first parse the spell-number value from gameObject - int spnum = gameObject.getAttributeInt(attr.getNameOld()); // spell number - - if (spnum < 0 || spnum >= mainControl.getNumberSpells().size()) { - spnum = undefinedSpellIndex; - } - - // do we have "none" spell? - final int selectedIndex; - if (spnum == undefinedSpellIndex && attr.getDataType() instanceof ArchetypeAttributeTypeZSpell) { - selectedIndex = 0; - } else { - // now look up the spell-number in the array of spells - selectedIndex = 1 + findSpellIndex(spnum); - } - - final Vector<String> content = new Vector<String>(); - content.add("<none>"); - for (final Spell spell : mainControl.getNumberSpells()) { - content.add(spell.getName()); - } - final JComboBox comboBox = new JComboBox(content); - comboBox.setSelectedIndex(selectedIndex); - comboBox.setMaximumRowCount(10); - comboBox.setKeySelectionManager(new StringKeyManager(comboBox)); - comboBox.setName(attr.getNameNew()); - return comboBox; - } - - /** - * Return the spell index for a spell number. - * @param number The spell number. - * @return The spell object. - */ - private int findSpellIndex(final int number) { - final Spells<NumberSpell> spells = mainControl.getNumberSpells(); - for (int i = 0; i < spells.size(); i++) { - if (spells.getSpell(i).getNumber() == number) { - return i; - } - } - return -1; - } - - /** {@inheritDoc} */ - @Override - protected boolean applySettings2() { - final ArchetypeType typeStruct = archetypeTypeSet.getTypeOfArch(gameObject); // the type structure for this gameObject - - final StringBuilder newArchText = new StringBuilder(); - final String[] newName = new String[1]; - final String[] newFace = new String[1]; - final String[] newMsg = new String[1]; - final String[] newAnim = new String[1]; - for (final DialogAttrib<GameObject, MapArchObject, Archetype, ?> attr : dialogAttribs) { - final String text = attr.getText2(gameObject, archetype, newName, newFace, newMsg, newAnim, typeStruct, this); - if (text == null) { - return false; - } - if (text.length() > 0) { - newArchText.append(text).append("\n"); - } - } - - // Also write all the 'fixed' attributes into the archtext - for (int i = 0; type.getAttr().length > i; i++) { - // ### TODO: for changed types, copy fixed attributes over default arches ### - if (type.getAttr()[i].getDataType() instanceof ArchetypeAttributeTypeFixed) { - final String defaultValue = archetype.getAttributeString(type.getAttr()[i].getNameOld()); - if (defaultValue.length() == 0 || (gameObject.getArchTypNr() != archetype.getArchTypNr() && !defaultValue.equalsIgnoreCase(type.getAttr()[i].getNameNew()))) { - // usually, fixed attributes are only applied when *not* defined in the archetype. - // the reason behind this is: if the default gameObject violates our fixed attribute, - // we assume the default gameObject is "right" and we are "wrong". The typedefs aren't that trustworthy. - // BUT - if the gameObject has a changed type, the archetype has lost it's credibility. - // So, in this special case, the fixed attribute applies always. - newArchText.append(type.getAttr()[i].getNameOld()).append(" ").append(type.getAttr()[i].getNameNew()).append("\n"); - } - } - } - - /* we have excluded direction hard coded from the attribut panel - * because we have a better interface in the gameObject panel. - * But we need to add when needed the gameObject text - we do it here. - */ - if (gameObject.getDirection() != archetype.getDirection()) { - newArchText.append("direction ").append(gameObject.getDirection()).append("\n"); - } - // before we modify the archtext, we look for errors and save them. - // later the user must confirm whether to keep or dump those errors - final String errors = gameObject.getSyntaxErrors(typeStruct); - - // --- parsing succeeded, now we write it into the gameObject/map --- - gameObject.setObjectText(newArchText.toString()); - //gameObject.setArchTypNr(); - if (newName[0] != null) { - if (newName[0].length() == 0) { - gameObject.setObjName(null); - } else { - gameObject.setObjName(newName[0]); - } - } - - if (newFace[0] != null) { - gameObject.setRealFace(newFace[0]); - } - - // now lets assign the visible face - perhaps we have still a anim - gameObject.setObjectFace(); - imagePanel.setIcon(getFace(gameObject)); - - if (newMsg[0] != null) { - // set new msg text only when it is not equal to Archetype - if (!newMsg[0].trim().equals(archetype.getMsgText() == null ? "" : archetype.getMsgText().trim())) { - gameObject.deleteMsgText(); - gameObject.addMsgText(newMsg[0]); - } else { - gameObject.deleteMsgText(); - } - } else - if (archetype.getMsgText() != null && archetype.getMsgText().trim().length() > 0) { - // we must override archetype msg by an empty msg - gameObject.deleteMsgText(); - gameObject.addMsgText(""); - } else { - gameObject.deleteMsgText(); // all empty - } - - if (newAnim[0] != null) { - gameObject.setAnimName(newAnim[0]); - } - - // deal with syntax errors now - if (errors != null) { - if (typeStruct == archetypeTypeSet.getArchetypeType(0)) { - // for generic (misc) type, all errors are automatically kept. - // "misc" is no real type - it is more a default mask for unknown types - gameObject.addObjectText(errors.trim()); - } else { - // open a popup dialog and ask user to decide what to do with his errors - askConfirmErrors(errors); - } - } - - gameObject.updateEditType(mapManager.getCurrentMap().getActiveEditType()); - - return true; // apply succeeded - } - } // class GameObjectAttributesDialog Modified: trunk/src/app/net/sf/gridarta/gui/gameobjectattributesdialog/AbstractGameObjectAttributesDialog.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/gameobjectattributesdialog/AbstractGameObjectAttributesDialog.java 2008-07-30 19:48:39 UTC (rev 4588) +++ trunk/src/app/net/sf/gridarta/gui/gameobjectattributesdialog/AbstractGameObjectAttributesDialog.java 2008-07-30 20:05:21 UTC (rev 4589) @@ -73,6 +73,7 @@ import javax.swing.text.StyleContext; import net.sf.gridarta.CommonConstants; import net.sf.gridarta.MainControl; +import net.sf.gridarta.MapManager; import net.sf.gridarta.archtype.ArchetypeAttribute; import net.sf.gridarta.archtype.ArchetypeAttributeType; import net.sf.gridarta.archtype.ArchetypeAttributeTypeAnimName; @@ -110,7 +111,9 @@ import net.sf.gridarta.map.MapModel; import net.sf.gridarta.map.MapSquare; import net.sf.gridarta.spells.GameObjectSpell; +import net.sf.gridarta.spells.NumberSpell; import net.sf.gridarta.spells.Spell; +import net.sf.gridarta.spells.Spells; import net.sf.gridarta.textedit.textarea.JEditTextArea; import net.sf.gridarta.textedit.textarea.SyntaxDocument; import net.sf.gridarta.textedit.textarea.tokenmarker.TokenMarkerFactory; @@ -142,7 +145,7 @@ private final AbstractGameObjectAttributesDialogFactory<G, A, R, ?> gameObjectAttributesDialogFactory; /** Reference to the {@link ArchetypeTypeSet}. */ - protected final ArchetypeTypeSet archetypeTypeSet; + private final ArchetypeTypeSet archetypeTypeSet; /** * The index used for "no" spell. @@ -155,14 +158,18 @@ private final boolean includeFaceText; /** Reference to MainControl. */ - protected final MainControl<G, A, R, ?> mainControl; + private final MainControl<G, A, R, ?> mainControl; /** * The archetype set to use. */ @NotNull - protected final ArchetypeSet<G, A, R> archetypeSet; + private final ArchetypeSet<G, A, R> archetypeSet; + /** The map manager. */ + @NotNull + private final MapManager<G, A, R, ?> mapManager; + /** The animation objects to use. */ @NotNull private final AnimationObjects<?> animationObjects; @@ -182,19 +189,19 @@ */ private int typeNoEventConnector; - protected final List<DialogAttrib<G, A, R, ?>> dialogAttribs = new ArrayList<DialogAttrib<G, A, R, ?>>(); + private final List<DialogAttrib<G, A, R, ?>> dialogAttribs = new ArrayList<DialogAttrib<G, A, R, ?>>(); private JComboBox typesel; // selection box for type - protected JLabel imagePanel; // panel for object's face (png) + private JLabel imagePanel; // panel for object's face (png) /** The game object being modified. */ @NotNull public final G gameObject; - protected final R archetype; + private final R archetype; - protected ArchetypeType type; // reference to the type data + private ArchetypeType type; // reference to the type data // this differs from the GameObject if the type is undefined private int listNr; // the position of this type in the type list @@ -235,6 +242,7 @@ * @param gameObject GameObject to show dialog for. * @param mainControl MainControl, for retrieving AnimationObjects etc. * @param archetypeSet the archetype set to use + * @param mapManager the map manager to use * @param animationObjects the animation objects instance to use * @param treasureListTree the treasure list tree * @param faceObjects the face objects instance to use @@ -244,7 +252,7 @@ * @param includeFaceText whether face names are included in the object * text */ - protected AbstractGameObjectAttributesDialog(@NotNull final AbstractGameObjectAttributesDialogFactory<G, A, R, ?> gameObjectAttributesDialogFactory, final ArchetypeTypeSet archetypeTypeSet, @NotNull final G gameObject, @NotNull final MainControl<G, A, R, ?> mainControl, @NotNull final ArchetypeSet<G, A, R> archetypeSet, @NotNull final AnimationObjects<?> animationObjects, @NotNull final CFTreasureListTree<G, A, R> treasureListTree, @NotNull final FaceObjects faceObjects, @NotNull final FileFilter mapFileFilter, final int typeNoEventConnector, final int undefinedSpellIndex, final boolean includeFaceText) { + protected AbstractGameObjectAttributesDialog(@NotNull final AbstractGameObjectAttributesDialogFactory<G, A, R, ?> gameObjectAttributesDialogFactory, final ArchetypeTypeSet archetypeTypeSet, @NotNull final G gameObject, @NotNull final MainControl<G, A, R, ?> mainControl, @NotNull final ArchetypeSet<G, A, R> archetypeSet, @NotNull final MapManager<G, A, R, ?> mapManager, @NotNull final AnimationObjects<?> animationObjects, @NotNull final CFTreasureListTree<G, A, R> treasureListTree, @NotNull final FaceObjects faceObjects, @NotNull final FileFilter mapFileFilter, final int typeNoEventConnector, final int undefinedSpellIndex, final boolean includeFaceText) { this.gameObjectAttributesDialogFactory = gameObjectAttributesDialogFactory; this.archetypeTypeSet = archetypeTypeSet; this.typeNoEventConnector = typeNoEventConnector; @@ -253,6 +261,7 @@ this.gameObject = gameObject.getHead(); this.mainControl = mainControl; this.archetypeSet = archetypeSet; + this.mapManager = mapManager; this.animationObjects = animationObjects; this.treasureListTree = treasureListTree; this.faceObjects = faceObjects; @@ -340,8 +349,36 @@ * @param attr spell attribute * @return the completed <code>JComboBox</code> */ - protected abstract JComboBox buildSpellBox(final ArchetypeAttribute attr); + private JComboBox buildSpellBox(final ArchetypeAttribute attr) { + // first parse the spell-number value from gameObject + int spnum = gameObject.getAttributeInt(attr.getNameOld()); // spell number + if (spnum < 0 || spnum >= mainControl.getNumberSpells().size()) { + spnum = undefinedSpellIndex; + } + + // do we have "none" spell? + final int selectedIndex; + if (spnum == undefinedSpellIndex && attr.getDataType() instanceof ArchetypeAttributeTypeZSpell) { + selectedIndex = 0; + } else { + // now look up the spell-number in the array of spells + selectedIndex = 1 + findSpellIndex(spnum); + } + + final Vector<String> content = new Vector<String>(); + content.add("<none>"); + for (final Spell spell : mainControl.getNumberSpells()) { + content.add(spell.getName()); + } + final JComboBox comboBox = new JComboBox(content); + comboBox.setSelectedIndex(selectedIndex); + comboBox.setMaximumRowCount(10); + comboBox.setKeySelectionManager(new StringKeyManager(comboBox)); + comboBox.setName(attr.getNameNew()); + return comboBox; + } + /** * Construct the Combo box of the available spells. * @param attr spell attribute @@ -769,8 +806,108 @@ * settings from the dialog get written into the GameObject. * @return true if the settings were applied, false if error occurred */ - protected abstract boolean applySettings2(); + private boolean applySettings2() { + final ArchetypeType typeStruct = archetypeTypeSet.getTypeOfArch(gameObject); // the type structure for this gameObject + final StringBuilder newArchText = new StringBuilder(); + final String[] newName = new String[1]; + final String[] newFace = new String[1]; + final String[] newMsg = new String[1]; + final String[] newAnim = new String[1]; + for (final DialogAttrib<G, A, R, ?> attr : dialogAttribs) { + final String text = attr.getText2(gameObject, archetype, newName, newFace, newMsg, newAnim, typeStruct, this); + if (text == null) { + return false; + } + if (text.length() > 0) { + newArchText.append(text).append("\n"); + } + } + + // Also write all the 'fixed' attributes into the archtext + for (int i = 0; type.getAttr().length > i; i++) { + // ### TODO: for changed types, copy fixed attributes over default arches ### + if (type.getAttr()[i].getDataType() instanceof ArchetypeAttributeTypeFixed) { + final String defaultValue = archetype.getAttributeString(type.getAttr()[i].getNameOld()); + if (defaultValue.length() == 0 || (gameObject.getArchTypNr() != archetype.getArchTypNr() && !defaultValue.equalsIgnoreCase(type.getAttr()[i].getNameNew()))) { + // usually, fixed attributes are only applied when *not* defined in the archetype. + // the reason behind this is: if the default gameObject violates our fixed attribute, + // we assume the default gameObject is "right" and we are "wrong". The typedefs aren't that trustworthy. + // BUT - if the gameObject has a changed type, the archetype has lost it's credibility. + // So, in this special case, the fixed attribute applies always. + newArchText.append(type.getAttr()[i].getNameOld()).append(" ").append(type.getAttr()[i].getNameNew()).append("\n"); + } + } + } + + /* we have excluded direction hard coded from the attribut panel + * because we have a better interface in the gameObject panel. + * But we need to add when needed the gameObject text - we do it here. + */ + if (gameObject.getDirection() != archetype.getDirection()) { + newArchText.append("direction ").append(gameObject.getDirection()).append("\n"); + } + // before we modify the archtext, we look for errors and save them. + // later the user must confirm whether to keep or dump those errors + final String errors = gameObject.getSyntaxErrors(typeStruct); + + // --- parsing succeeded, now we write it into the gameObject/map --- + gameObject.setObjectText(newArchText.toString()); + //gameObject.setArchTypNr(); + if (newName[0] != null) { + if (newName[0].length() == 0) { + gameObject.setObjName(null); + } else { + gameObject.setObjName(newName[0]); + } + } + + if (newFace[0] != null) { + gameObject.setRealFace(newFace[0]); + } + + // now lets assign the visible face - perhaps we have still a anim + gameObject.setObjectFace(); + imagePanel.setIcon(getFace(gameObject)); + + if (newMsg[0] != null) { + // set new msg text only when it is not equal to Archetype + if (!newMsg[0].trim().equals(archetype.getMsgText() == null ? "" : archetype.getMsgText().trim())) { + gameObject.deleteMsgText(); + gameObject.addMsgText(newMsg[0]); + } else { + gameObject.deleteMsgText(); + } + } else + if (archetype.getMsgText() != null && archetype.getMsgText().trim().length() > 0) { + // we must override archetype msg by an empty msg + gameObject.deleteMsgText(); + gameObject.addMsgText(""); + } else { + gameObject.deleteMsgText(); // all empty + } + + if (newAnim[0] != null) { + gameObject.setAnimName(newAnim[0]); + } + + // deal with syntax errors now + if (errors != null) { + if (typeStruct == archetypeTypeSet.getArchetypeType(0)) { + // for generic (misc) type, all errors are automatically kept. + // "misc" is no real type - it is more a default mask for unknown types + gameObject.addObjectText(errors.trim()); + } else { + // open a popup dialog and ask user to decide what to do with his errors + askConfirmErrors(errors); + } + } + + gameObject.updateEditType(mapManager.getCurrentMap().getActiveEditType()); + + return true; // apply succeeded + } + /** * Open a popup dialog and ask the user to confirm (or modify) the * encountered syntax errors. If the user chooses to keep any errors, these @@ -831,6 +968,21 @@ frame.setVisible(true); } + /** + * Return the spell index for a spell number. + * @param number The spell number. + * @return The spell object. + */ + private int findSpellIndex(final int number) { + final Spells<NumberSpell> spells = mainControl.getNumberSpells(); + for (int i = 0; i < spells.size(); i++) { + if (spells.getSpell(i).getNumber() == number) { + return i; + } + } + return -1; + } + /** ItemListener for the type-selection box on the attribute-dialog. */ private final class TypesBoxAL implements ItemListener { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |