From: <aki...@us...> - 2008-05-03 09:33:21
|
Revision: 3939 http://gridarta.svn.sourceforge.net/gridarta/?rev=3939&view=rev Author: akirschbaum Date: 2008-05-03 02:33:26 -0700 (Sat, 03 May 2008) Log Message: ----------- Extract code from ScriptArchData into ScriptArchUtils. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchUtils.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchUtils.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-05-03 09:01:40 UTC (rev 3938) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-05-03 09:33:26 UTC (rev 3939) @@ -26,7 +26,7 @@ import cfeditor.gameobject.GameObject; import cfeditor.gameobject.anim.AnimationObjects; import cfeditor.gameobject.face.FaceObjects; -import cfeditor.gameobject.scripts.ScriptArchData; +import cfeditor.gameobject.scripts.ScriptArchUtils; import cfeditor.gui.GameObjectAttributesDialog; import cfeditor.gui.ObjectChooser; import cfeditor.gui.prefs.GUIPrefs; @@ -982,9 +982,9 @@ private List<?> getEventTypes() { final List<Object> result = new ArrayList<Object>(); - for (int typeNumber = 1; ScriptArchData.typeArchName(typeNumber) != null; typeNumber++) { + for (int typeNumber = 1; ScriptArchUtils.typeArchName(typeNumber) != null; typeNumber++) { result.add(typeNumber); - result.add(ScriptArchData.typeName(typeNumber)); + result.add(ScriptArchUtils.typeName(typeNumber)); } return result; } Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 09:01:40 UTC (rev 3938) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 09:33:26 UTC (rev 3939) @@ -92,23 +92,6 @@ private static JTextField inputOptions; - // FIXME: This should NOT BE HERE. Instead, it should be read from types.xml. - private static final String[] allEventTypes = new String[] { - "apply", - "attack", - "death", - "drop", - "pickup", - "say", - "stop", - "time", - "throw", - "trigger", - "close", - "timer", - "destroy", - }; - private final GameObject owner; private boolean changed; @@ -129,8 +112,8 @@ pluginNameBox = new JComboBox(new String[]{" Python"}); pluginNameBox.setSelectedIndex(0); - eventTypeBox = new JComboBox(allEventTypes); - eventTypeBox.setSelectedIndex(Arrays2.linearEqualitySearch("say", allEventTypes)); + eventTypeBox = new JComboBox(ScriptArchUtils.allEventTypes); + eventTypeBox.setSelectedIndex(Arrays2.linearEqualitySearch("say", ScriptArchUtils.allEventTypes)); } /** @@ -179,7 +162,7 @@ final Vector<String> content = new Vector<String>(); for (final GameObject tmp : owner) { if (tmp.getArchTypNr() == Archetype.TYPE_EVENT_CONNECTOR) { - content.add(" " + typeName(tmp.getAttributeInt("subtype"))); + content.add(" " + ScriptArchUtils.typeName(tmp.getAttributeInt("subtype"))); } } @@ -219,7 +202,7 @@ event.editParameters(); } else if (task == GameObjectAttributesPanel.SCRIPT_REMOVE) { // first ask for confirmation - if (JOptionPane.showConfirmDialog(panelList, "Are you sure you want to remove this \"" + typeName(event.getEventType()) + "\" event which is\n" + "linked to the script: '" + event.getScriptPath() + "'?\n" + "(The script file itself is not going to be deleted)", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { + if (JOptionPane.showConfirmDialog(panelList, "Are you sure you want to remove this \"" + ScriptArchUtils.typeName(event.getEventType()) + "\" event which is\n" + "linked to the script: '" + event.getScriptPath() + "'?\n" + "(The script file itself is not going to be deleted)", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { // remove this event from the GameObject oldEvent.remove(); addEventsToJList(panelList); // update panel JList @@ -441,7 +424,7 @@ final GameObject replaceObject = getScriptedEvent(eventType); if (replaceObject != null) { // collision with existing event -> ask user: replace? - if (JOptionPane.showConfirmDialog(frame, "An event of type \"" + typeName(eventType) + "\" already exists for this object.\n" + "Do you want to replace the existing event?", "Event exists", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.NO_OPTION) { + if (JOptionPane.showConfirmDialog(frame, "An event of type \"" + ScriptArchUtils.typeName(eventType) + "\" already exists for this object.\n" + "Do you want to replace the existing event?", "Event exists", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.NO_OPTION) { // bail out return false; } @@ -549,37 +532,6 @@ } /** - * Return a human readable name for an event type. - * - * @param eventType the event type - * - * @return the event type name - */ - public static String typeName(final int eventType) { - if (eventType > 0 && eventType <= allEventTypes.length) { - return allEventTypes[eventType - 1]; - } else { - return "<invalid type>"; - } - } - - /** - * Return the archetype for an event type. - * - * @param eventType the event type - * - * @return the archetype name, or <code>null</code> if the event type is - * invalid - */ - @Nullable public static String typeArchName(final int eventType) { - if (eventType > 0 && eventType <= allEventTypes.length) { - return "event_" + allEventTypes[eventType - 1]; - } else { - return null; - } - } - - /** * Return a guess for the directory to use. * * @return the directory to use Added: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchUtils.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchUtils.java (rev 0) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchUtils.java 2008-05-03 09:33:26 UTC (rev 3939) @@ -0,0 +1,74 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package cfeditor.gameobject.scripts; + +import org.jetbrains.annotations.Nullable; + +public class ScriptArchUtils { + + // FIXME: This should NOT BE HERE. Instead, it should be read from types.xml. + public static final String[] allEventTypes = new String[] { + "apply", + "attack", + "death", + "drop", + "pickup", + "say", + "stop", + "time", + "throw", + "trigger", + "close", + "timer", + "destroy", + }; + + /** + * Return a human readable name for an event type. + * + * @param eventType the event type + * + * @return the event type name + */ + public static String typeName(final int eventType) { + if (eventType > 0 && eventType <= allEventTypes.length) { + return allEventTypes[eventType - 1]; + } else { + return "<invalid type>"; + } + } + + /** + * Return the archetype for an event type. + * + * @param eventType the event type + * + * @return the archetype name, or <code>null</code> if the event type is + * invalid + */ + @Nullable public static String typeArchName(final int eventType) { + if (eventType > 0 && eventType <= allEventTypes.length) { + return "event_" + allEventTypes[eventType - 1]; + } else { + return null; + } + } + +} // class ScriptArchUtils Property changes on: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchUtils.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 09:01:40 UTC (rev 3938) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 09:33:26 UTC (rev 3939) @@ -102,14 +102,14 @@ final int eventType = getEventType(); if (scriptPath == null || scriptPath.length() <= 0) { - log.error("Map Error: Found " + ScriptArchData.typeName(eventType) + " event without file name!"); + log.error("Map Error: Found " + ScriptArchUtils.typeName(eventType) + " event without file name!"); return false; } if (pluginName == null || pluginName.length() <= 0) { pluginName = "Python"; if (log.isInfoEnabled()) { - log.info("Found " + ScriptArchData.typeName(eventType) + " without plugin name. Setting to \"Python\"."); + log.info("Found " + ScriptArchUtils.typeName(eventType) + " without plugin name. Setting to \"Python\"."); } } @@ -304,7 +304,7 @@ * be created */ private static GameObject newEventGameObject(final int eventType) throws UndefinedEventArchetypeException { - final String typeArchName = ScriptArchData.typeArchName(eventType); + final String typeArchName = ScriptArchUtils.typeArchName(eventType); if (typeArchName == null) { throw new UndefinedEventArchetypeTypeException(eventType); } Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 09:01:40 UTC (rev 3938) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 09:33:26 UTC (rev 3939) @@ -92,23 +92,6 @@ private static JTextField inputOptions; - // FIXME: This should NOT BE HERE. Instead, it should be read from types.xml. - private static final String[] allEventTypes = new String[] { - "apply", - "attack", - "death", - "drop", - "pickup", - "say", - "stop", - "time (don't use)", - "throw", - "trigger", - "close", - "examine", - "talk", - }; - private final GameObject owner; private boolean changed; @@ -129,8 +112,8 @@ pluginNameBox = new JComboBox(new String[]{" Lua "}); pluginNameBox.setSelectedIndex(0); - eventTypeBox = new JComboBox(allEventTypes); - eventTypeBox.setSelectedIndex(Arrays2.linearEqualitySearch("say", allEventTypes)); + eventTypeBox = new JComboBox(ScriptArchUtils.allEventTypes); + eventTypeBox.setSelectedIndex(Arrays2.linearEqualitySearch("say", ScriptArchUtils.allEventTypes)); } /** @@ -179,7 +162,7 @@ final Vector<String> content = new Vector<String>(); for (final GameObject tmp : owner) { if (tmp.getArchTypNr() == Archetype.TYPE_EVENT_OBJECT) { - content.add(" " + typeName(tmp.getAttributeInt("sub_type"))); + content.add(" " + ScriptArchUtils.typeName(tmp.getAttributeInt("sub_type"))); } } @@ -219,7 +202,7 @@ event.editParameters(); } else if (task == GameObjectAttributesPanel.SCRIPT_REMOVE) { // first ask for confirmation - if (JOptionPane.showConfirmDialog(panelList, "Are you sure you want to remove this \"" + typeName(event.getEventType()) + "\" event which is\n" + "linked to the script: '" + event.getScriptPath() + "'?\n" + "(The script file itself is not going to be deleted)", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { + if (JOptionPane.showConfirmDialog(panelList, "Are you sure you want to remove this \"" + ScriptArchUtils.typeName(event.getEventType()) + "\" event which is\n" + "linked to the script: '" + event.getScriptPath() + "'?\n" + "(The script file itself is not going to be deleted)", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { // remove this event from the GameObject oldEvent.remove(); addEventsToJList(panelList); // update panel JList @@ -441,7 +424,7 @@ final GameObject replaceObject = getScriptedEvent(eventType); if (replaceObject != null) { // collision with existing event -> ask user: replace? - if (JOptionPane.showConfirmDialog(frame, "An event of type \"" + typeName(eventType) + "\" already exists for this object.\n" + "Do you want to replace the existing event?", "Event exists", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.NO_OPTION) { + if (JOptionPane.showConfirmDialog(frame, "An event of type \"" + ScriptArchUtils.typeName(eventType) + "\" already exists for this object.\n" + "Do you want to replace the existing event?", "Event exists", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.NO_OPTION) { // bail out return false; } @@ -549,21 +532,6 @@ } /** - * Return a human readable name for an event type. - * - * @param eventType the event type - * - * @return the event type name - */ - public static String typeName(final int eventType) { - if (eventType > 0 && eventType <= allEventTypes.length) { - return allEventTypes[eventType - 1]; - } else { - return "<invalid type>"; - } - } - - /** * Return a guess for the directory to use. * * @return the directory to use Added: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchUtils.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchUtils.java (rev 0) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchUtils.java 2008-05-03 09:33:26 UTC (rev 3939) @@ -0,0 +1,56 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package daieditor.gameobject.scripts; + +public class ScriptArchUtils { + + // FIXME: This should NOT BE HERE. Instead, it should be read from types.xml. + public static final String[] allEventTypes = new String[] { + "apply", + "attack", + "death", + "drop", + "pickup", + "say", + "stop", + "time (don't use)", + "throw", + "trigger", + "close", + "examine", + "talk", + }; + + /** + * Return a human readable name for an event type. + * + * @param eventType the event type + * + * @return the event type name + */ + public static String typeName(final int eventType) { + if (eventType > 0 && eventType <= allEventTypes.length) { + return allEventTypes[eventType - 1]; + } else { + return "<invalid type>"; + } + } + +} // class ScriptArchUtils Property changes on: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchUtils.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 09:01:40 UTC (rev 3938) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 09:33:26 UTC (rev 3939) @@ -101,14 +101,14 @@ final int eventType = getEventType(); if (scriptPath == null || scriptPath.length() <= 0) { - log.error("Map Error: Found " + ScriptArchData.typeName(eventType) + " event without file name!"); + log.error("Map Error: Found " + ScriptArchUtils.typeName(eventType) + " event without file name!"); return false; } if (pluginName == null || pluginName.length() <= 0) { pluginName = "Python"; if (log.isInfoEnabled()) { - log.info("Found " + ScriptArchData.typeName(eventType) + " without plugin name. Setting to \"Python\"."); + log.info("Found " + ScriptArchUtils.typeName(eventType) + " without plugin name. Setting to \"Python\"."); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-03 09:46:04
|
Revision: 3940 http://gridarta.svn.sourceforge.net/gridarta/?rev=3940&view=rev Author: akirschbaum Date: 2008-05-03 02:46:09 -0700 (Sat, 03 May 2008) Log Message: ----------- Unify code. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchUtils.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gameobject/scripts/UndefinedEventArchetypeTypeException.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gameobject/scripts/UndefinedEventArchetypeTypeException.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 09:33:26 UTC (rev 3939) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 09:46:09 UTC (rev 3940) @@ -37,6 +37,7 @@ import net.sf.gridarta.gameobject.scripts.PathButtonListener; import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeNameException; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeTypeException; import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; import net.sf.japi.swing.ActionFactory; import org.apache.log4j.Logger; Deleted: trunk/crossfire/src/cfeditor/gameobject/scripts/UndefinedEventArchetypeTypeException.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/UndefinedEventArchetypeTypeException.java 2008-05-03 09:33:26 UTC (rev 3939) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/UndefinedEventArchetypeTypeException.java 2008-05-03 09:46:09 UTC (rev 3940) @@ -1,59 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package cfeditor.gameobject.scripts; - -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; - -/** - * This class implements an {@link UndefinedEventArchetypeException} that - * describes an invalid event type. - * - * @author Andreas Kirschbaum - */ -public class UndefinedEventArchetypeTypeException extends UndefinedEventArchetypeException { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** - * The event type that could not be found. - */ - private final int eventType; - - /** - * Create a new instance. - * - * @param eventType the event type that could not be found - */ - public UndefinedEventArchetypeTypeException(final int eventType) { - super("invalid event type " + eventType); - this.eventType = eventType; - } - - /** - * Return the event type that could not be found. - * - * @return the event type that could not be found - */ - public int getEventType() { - return eventType; - } - -} // class UndefinedEventArchetypeTypeException Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchUtils.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchUtils.java 2008-05-03 09:33:26 UTC (rev 3939) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchUtils.java 2008-05-03 09:46:09 UTC (rev 3940) @@ -19,6 +19,8 @@ package daieditor.gameobject.scripts; +import org.jetbrains.annotations.Nullable; + public class ScriptArchUtils { // FIXME: This should NOT BE HERE. Instead, it should be read from types.xml. @@ -53,4 +55,16 @@ } } + /** + * Return the archetype for an event type. + * + * @param eventType the event type + * + * @return the archetype name, or <code>null</code> if the event type is + * invalid + */ + @Nullable public static String typeArchName(final int eventType) { + return "event_obj"; + } + } // class ScriptArchUtils Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 09:33:26 UTC (rev 3939) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 09:46:09 UTC (rev 3940) @@ -37,6 +37,7 @@ import net.sf.gridarta.gameobject.scripts.PathButtonListener; import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeNameException; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeTypeException; import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; import net.sf.japi.swing.ActionFactory; import org.apache.log4j.Logger; @@ -300,7 +301,10 @@ * be created */ private static GameObject newEventGameObject(final int eventType) throws UndefinedEventArchetypeException { - final String typeArchName = "event_obj"; + final String typeArchName = ScriptArchUtils.typeArchName(eventType); + if (typeArchName == null) { + throw new UndefinedEventArchetypeTypeException(eventType); + } final Archetype eventArch = CMainControl.getInstance().getArchetypeSet().getArchetype(typeArchName); if (eventArch == null) { throw new UndefinedEventArchetypeNameException(typeArchName); Copied: trunk/src/app/net/sf/gridarta/gameobject/scripts/UndefinedEventArchetypeTypeException.java (from rev 3939, trunk/crossfire/src/cfeditor/gameobject/scripts/UndefinedEventArchetypeTypeException.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/UndefinedEventArchetypeTypeException.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/UndefinedEventArchetypeTypeException.java 2008-05-03 09:46:09 UTC (rev 3940) @@ -0,0 +1,57 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gameobject.scripts; + +/** + * This class implements an {@link UndefinedEventArchetypeException} that + * describes an invalid event type. + * + * @author Andreas Kirschbaum + */ +public class UndefinedEventArchetypeTypeException extends UndefinedEventArchetypeException { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** + * The event type that could not be found. + */ + private final int eventType; + + /** + * Create a new instance. + * + * @param eventType the event type that could not be found + */ + public UndefinedEventArchetypeTypeException(final int eventType) { + super("invalid event type " + eventType); + this.eventType = eventType; + } + + /** + * Return the event type that could not be found. + * + * @return the event type that could not be found + */ + public int getEventType() { + return eventType; + } + +} // class UndefinedEventArchetypeTypeException This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-03 10:06:25
|
Revision: 3941 http://gridarta.svn.sourceforge.net/gridarta/?rev=3941&view=rev Author: akirschbaum Date: 2008-05-03 03:06:28 -0700 (Sat, 03 May 2008) Log Message: ----------- Make ScriptArchData.addEventScript() static. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2008-05-03 09:46:09 UTC (rev 3940) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2008-05-03 10:06:28 UTC (rev 3941) @@ -206,7 +206,7 @@ /** {@inheritDoc} */ @Override public void addEventScript(@NotNull final JList eventList, @NotNull final GameObjectAttributesPanel<GameObject, MapArchObject, Archetype, ?, ?> mapanel) { - scriptArchData.addEventScript(eventList, this); + ScriptArchData.addEventScript(eventList, this, scriptArchData); if (!scriptArchData.isEmpty()) { mapanel.setScriptPanelButtonState(true, true, true, true); Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 09:46:09 UTC (rev 3940) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 10:06:28 UTC (rev 3941) @@ -294,8 +294,9 @@ * which gets attached to this gameObject. * @param panelList JList from the MapArchPanel (script tab) which displays the events * @param gameObject GameObject to add event to + * @param scriptArchData the <code>ScriptArchData</code> instance to display */ - public void addEventScript(final JList panelList, final GameObject gameObject) { + public static void addEventScript(final JList panelList, final GameObject gameObject, final ScriptArchData scriptArchData) { final String archName = gameObject.getBestName(); // create a reasonable default script name for lazy users :-) final String defScriptName = chooseDefaultScriptName(archName); @@ -385,7 +386,7 @@ mainPanel.add(Box.createVerticalStrut(10)); final JPanel line6 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); final JButton nsOkButton = new JButton("OK"); - nsOkListener = new PathButtonListener(true, newScriptFrame, this); + nsOkListener = new PathButtonListener(true, newScriptFrame, scriptArchData); nsOkButton.addActionListener(nsOkListener); line6.add(nsOkButton); @@ -403,7 +404,7 @@ headingLabel.setText("New scripted event for \"" + archName + "\":"); inputScriptPath.setText(defScriptName); inputOptions.setText(""); - nsOkListener.setScriptArchData(this); + nsOkListener.setScriptArchData(scriptArchData); newScriptFrame.toFront(); newScriptFrame.setVisible(true); } Modified: trunk/daimonin/src/daieditor/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObject.java 2008-05-03 09:46:09 UTC (rev 3940) +++ trunk/daimonin/src/daieditor/gameobject/GameObject.java 2008-05-03 10:06:28 UTC (rev 3941) @@ -375,7 +375,7 @@ /** {@inheritDoc} */ @Override public void addEventScript(@NotNull final JList eventList, @NotNull final GameObjectAttributesPanel<GameObject, MapArchObject, Archetype, ?, ?> mapanel) { - scriptArchData.addEventScript(eventList, this); + ScriptArchData.addEventScript(eventList, this, scriptArchData); if (!scriptArchData.isEmpty()) { mapanel.setScriptPanelButtonState(true, true, true, true); Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 09:46:09 UTC (rev 3940) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 10:06:28 UTC (rev 3941) @@ -294,8 +294,9 @@ * which gets attached to this gameObject. * @param panelList JList from the MapArchPanel (script tab) which displays the events * @param gameObject GameObject to add event to + * @param scriptArchData the <code>ScriptArchData</code> instance to display */ - public void addEventScript(final JList panelList, final GameObject gameObject) { + public static void addEventScript(final JList panelList, final GameObject gameObject, final ScriptArchData scriptArchData) { final String archName = gameObject.getBestName(); // create a reasonable default script name for lazy users :-) final String defScriptName = chooseDefaultScriptName(archName); @@ -385,7 +386,7 @@ mainPanel.add(Box.createVerticalStrut(10)); final JPanel line6 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); final JButton nsOkButton = new JButton("OK"); - nsOkListener = new PathButtonListener(true, newScriptFrame, this); + nsOkListener = new PathButtonListener(true, newScriptFrame, scriptArchData); nsOkButton.addActionListener(nsOkListener); line6.add(nsOkButton); @@ -403,7 +404,7 @@ headingLabel.setText("New scripted event for \"" + archName + "\":"); inputScriptPath.setText(defScriptName); inputOptions.setText(""); - nsOkListener.setScriptArchData(this); + nsOkListener.setScriptArchData(scriptArchData); newScriptFrame.toFront(); newScriptFrame.setVisible(true); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-03 10:46:29
|
Revision: 3942 http://gridarta.svn.sourceforge.net/gridarta/?rev=3942&view=rev Author: akirschbaum Date: 2008-05-03 03:46:29 -0700 (Sat, 03 May 2008) Log Message: ----------- Make ScriptArchData.createNewEvent() static. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 10:06:28 UTC (rev 3941) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 10:46:29 UTC (rev 3942) @@ -412,6 +412,10 @@ /** {@inheritDoc} */ public boolean createNewEvent(final JDialog frame) { + return createNewEvent(frame, this); + } + + public static boolean createNewEvent(final JDialog frame, final ScriptArchData scriptArchData) { String scriptPath = inputScriptPath.getText().trim(); final String options = inputOptions.getText().trim(); final int eventType = eventTypeBox.getSelectedIndex() + 1; @@ -419,10 +423,10 @@ final File localMapDir = getLocalMapDir(); - changed = false; + scriptArchData.changed = false; // first check if that event type is not already in use - final GameObject replaceObject = getScriptedEvent(eventType); + final GameObject replaceObject = scriptArchData.getScriptedEvent(eventType); if (replaceObject != null) { // collision with existing event -> ask user: replace? if (JOptionPane.showConfirmDialog(frame, "An event of type \"" + ScriptArchUtils.typeName(eventType) + "\" already exists for this object.\n" + "Do you want to replace the existing event?", "Event exists", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.NO_OPTION) { @@ -471,7 +475,7 @@ if (replaceObject != null) { replaceObject.remove(); } - owner.addLast(event.getEventArch()); + scriptArchData.owner.addLast(event.getEventArch()); frame.setVisible(false); // close dialog } } else { @@ -506,8 +510,8 @@ if (replaceObject != null) { replaceObject.remove(); } - changed = true; - owner.addLast(event.getEventArch()); + scriptArchData.changed = true; + scriptArchData.owner.addLast(event.getEventArch()); frame.setVisible(false); // close dialog // open new script file @@ -515,7 +519,7 @@ } } } - return changed; + return scriptArchData.changed; } /** Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 10:06:28 UTC (rev 3941) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 10:46:29 UTC (rev 3942) @@ -412,6 +412,10 @@ /** {@inheritDoc} */ public boolean createNewEvent(final JDialog frame) { + return createNewEvent(frame, this); + } + + public static boolean createNewEvent(final JDialog frame, final ScriptArchData scriptArchData) { String scriptPath = inputScriptPath.getText().trim(); final String options = inputOptions.getText().trim(); final int eventType = eventTypeBox.getSelectedIndex() + 1; @@ -419,10 +423,10 @@ final File localMapDir = getLocalMapDir(); - changed = false; + scriptArchData.changed = false; // first check if that event type is not already in use - final GameObject replaceObject = getScriptedEvent(eventType); + final GameObject replaceObject = scriptArchData.getScriptedEvent(eventType); if (replaceObject != null) { // collision with existing event -> ask user: replace? if (JOptionPane.showConfirmDialog(frame, "An event of type \"" + ScriptArchUtils.typeName(eventType) + "\" already exists for this object.\n" + "Do you want to replace the existing event?", "Event exists", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.NO_OPTION) { @@ -471,7 +475,7 @@ if (replaceObject != null) { replaceObject.remove(); } - owner.addLast(event.getEventArch()); + scriptArchData.owner.addLast(event.getEventArch()); frame.setVisible(false); // close dialog } } else { @@ -506,8 +510,8 @@ if (replaceObject != null) { replaceObject.remove(); } - changed = true; - owner.addLast(event.getEventArch()); + scriptArchData.changed = true; + scriptArchData.owner.addLast(event.getEventArch()); frame.setVisible(false); // close dialog // open new script file @@ -515,7 +519,7 @@ } } } - return changed; + return scriptArchData.changed; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-03 10:49:52
|
Revision: 3943 http://gridarta.svn.sourceforge.net/gridarta/?rev=3943&view=rev Author: akirschbaum Date: 2008-05-03 03:49:57 -0700 (Sat, 03 May 2008) Log Message: ----------- Make methods public. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 10:46:29 UTC (rev 3942) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 10:49:57 UTC (rev 3943) @@ -541,7 +541,7 @@ * * @return the directory to use */ - static File getLocalMapDir() { + public static File getLocalMapDir() { final CMainControl mainControl = CMainControl.getInstance(); final MapControl mapControl = mainControl.getMapManager().getCurrentMap(); Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 10:46:29 UTC (rev 3942) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 10:49:57 UTC (rev 3943) @@ -541,7 +541,7 @@ * * @return the directory to use */ - static File getLocalMapDir() { + public static File getLocalMapDir() { final CMainControl mainControl = CMainControl.getInstance(); final MapControl mapControl = mainControl.getMapManager().getCurrentMap(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-03 11:02:59
|
Revision: 3944 http://gridarta.svn.sourceforge.net/gridarta/?rev=3944&view=rev Author: akirschbaum Date: 2008-05-03 04:03:03 -0700 (Sat, 03 May 2008) Log Message: ----------- Move ScriptArchData.getLocalMapDir() to MainControl. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java trunk/src/app/net/sf/gridarta/AbstractMainControl.java trunk/src/app/net/sf/gridarta/MainControl.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 10:49:57 UTC (rev 3943) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 11:03:03 UTC (rev 3944) @@ -19,11 +19,9 @@ package cfeditor.gameobject.scripts; -import cfeditor.CMainControl; import cfeditor.gameobject.Archetype; import cfeditor.gameobject.GameObject; import cfeditor.gui.GameObjectAttributesPanel; -import cfeditor.map.MapControl; import java.awt.Color; import java.awt.FlowLayout; import java.awt.Insets; @@ -235,7 +233,7 @@ } defScriptName += "Script" + SCRIPT_ENDING; - return PathManager.getMapPath(new File(getLocalMapDir(), defScriptName).getPath()); + return PathManager.getMapPath(new File(AbstractMainControl.getInstance().getLocalMapDir(), defScriptName).getPath()); } /** @@ -246,7 +244,7 @@ * @return local event path */ private static String localizeEventPath(final File f) { - final File localMapDir = getLocalMapDir(); + final File localMapDir = AbstractMainControl.getInstance().getLocalMapDir(); final File mapDir = new File(AbstractMainControl.getInstance().getMapDefaultFolder()); // global map directory if (!mapDir.exists()) { @@ -343,7 +341,7 @@ browseb.setMargin(new Insets(0, 10, 0, 10)); browseb.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { - final File home = getLocalMapDir(); + final File home = AbstractMainControl.getInstance().getLocalMapDir(); final JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Select Script File"); @@ -421,7 +419,7 @@ final int eventType = eventTypeBox.getSelectedIndex() + 1; final String pluginName = ((String) pluginNameBox.getSelectedItem()).trim(); - final File localMapDir = getLocalMapDir(); + final File localMapDir = AbstractMainControl.getInstance().getLocalMapDir(); scriptArchData.changed = false; @@ -536,28 +534,6 @@ return true; } - /** - * Return a guess for the directory to use. - * - * @return the directory to use - */ - public static File getLocalMapDir() { - final CMainControl mainControl = CMainControl.getInstance(); - - final MapControl mapControl = mainControl.getMapManager().getCurrentMap(); - if (mapControl == null) { - return mainControl.getMapDir(); - } - - final File mapFile = mapControl.getMapFile(); - if (mapFile == null) { - ACTION_FACTORY.showMessageDialog(AbstractMainControl.getInstance().getMainView(), "createNewEventNoMapPath"); - return mainControl.getMapDir(); - } - - return mapFile.getParentFile(); - } - /** {@inheritDoc} */ public void setChanged(final boolean changed) { this.changed = changed; Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 10:49:57 UTC (rev 3943) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 11:03:03 UTC (rev 3944) @@ -132,7 +132,7 @@ tmpPath.append(scriptPath); } else { // file path is relative to map dir - final String mapPath = ScriptArchData.getLocalMapDir().getAbsolutePath(); + final String mapPath = AbstractMainControl.getInstance().getLocalMapDir().getAbsolutePath(); tmpPath.append(mapPath); if (!mapPath.endsWith("/")) { tmpPath.append('/'); Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 10:49:57 UTC (rev 3943) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 11:03:03 UTC (rev 3944) @@ -19,11 +19,9 @@ package daieditor.gameobject.scripts; -import daieditor.CMainControl; import daieditor.gameobject.Archetype; import daieditor.gameobject.GameObject; import daieditor.gui.GameObjectAttributesPanel; -import daieditor.map.MapControl; import java.awt.Color; import java.awt.FlowLayout; import java.awt.Insets; @@ -235,7 +233,7 @@ } defScriptName += "Script" + SCRIPT_ENDING; - return PathManager.getMapPath(new File(getLocalMapDir(), defScriptName).getPath()); + return PathManager.getMapPath(new File(AbstractMainControl.getInstance().getLocalMapDir(), defScriptName).getPath()); } /** @@ -246,7 +244,7 @@ * @return local event path */ private static String localizeEventPath(final File f) { - final File localMapDir = getLocalMapDir(); + final File localMapDir = AbstractMainControl.getInstance().getLocalMapDir(); final File mapDir = new File(AbstractMainControl.getInstance().getMapDefaultFolder()); // global map directory if (!mapDir.exists()) { @@ -343,7 +341,7 @@ browseb.setMargin(new Insets(0, 10, 0, 10)); browseb.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { - final File home = getLocalMapDir(); + final File home = AbstractMainControl.getInstance().getLocalMapDir(); final JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Select Script File"); @@ -421,7 +419,7 @@ final int eventType = eventTypeBox.getSelectedIndex() + 1; final String pluginName = ((String) pluginNameBox.getSelectedItem()).trim(); - final File localMapDir = getLocalMapDir(); + final File localMapDir = AbstractMainControl.getInstance().getLocalMapDir(); scriptArchData.changed = false; @@ -536,28 +534,6 @@ return true; } - /** - * Return a guess for the directory to use. - * - * @return the directory to use - */ - public static File getLocalMapDir() { - final CMainControl mainControl = CMainControl.getInstance(); - - final MapControl mapControl = mainControl.getMapManager().getCurrentMap(); - if (mapControl == null) { - return mainControl.getMapDir(); - } - - final File mapFile = mapControl.getMapFile(); - if (mapFile == null) { - ACTION_FACTORY.showMessageDialog(AbstractMainControl.getInstance().getMainView(), "createNewEventNoMapPath"); - return mainControl.getMapDir(); - } - - return mapFile.getParentFile(); - } - /** {@inheritDoc} */ public void setChanged(final boolean changed) { this.changed = changed; Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 10:49:57 UTC (rev 3943) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 11:03:03 UTC (rev 3944) @@ -131,7 +131,7 @@ tmpPath.append(scriptPath); } else { // file path is relative to map dir - final String mapPath = ScriptArchData.getLocalMapDir().getAbsolutePath(); + final String mapPath = AbstractMainControl.getInstance().getLocalMapDir().getAbsolutePath(); tmpPath.append(mapPath); if (!mapPath.endsWith("/")) { tmpPath.append('/'); Modified: trunk/src/app/net/sf/gridarta/AbstractMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/AbstractMainControl.java 2008-05-03 10:49:57 UTC (rev 3943) +++ trunk/src/app/net/sf/gridarta/AbstractMainControl.java 2008-05-03 11:03:03 UTC (rev 3944) @@ -219,4 +219,20 @@ return mapManager; } + /** {@inheritDoc} */ + public File getLocalMapDir() { + final MapControl<G, A, R> mapControl = getMapManager().getCurrentMap(); + if (mapControl == null) { + return getMapDir(); + } + + final File mapFile = mapControl.getMapFile(); + if (mapFile == null) { + ACTION_FACTORY.showMessageDialog(getMainView(), "createNewEventNoMapPath"); + return getMapDir(); + } + + return mapFile.getParentFile(); + } + } // class AbstractMainControl Modified: trunk/src/app/net/sf/gridarta/MainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/MainControl.java 2008-05-03 10:49:57 UTC (rev 3943) +++ trunk/src/app/net/sf/gridarta/MainControl.java 2008-05-03 11:03:03 UTC (rev 3944) @@ -328,4 +328,10 @@ */ @NotNull MainActions<G, A, R, C, V> getMainActions(); + /** + * Returns a guess for a script directory to use. + * @return the directory + */ + File getLocalMapDir(); + } // interface MainControl This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-03 11:09:35
|
Revision: 3945 http://gridarta.svn.sourceforge.net/gridarta/?rev=3945&view=rev Author: akirschbaum Date: 2008-05-03 04:09:41 -0700 (Sat, 03 May 2008) Log Message: ----------- Whitespace changes. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java trunk/src/app/net/sf/gridarta/gameobject/match/NamedGameObjectMatcher.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 11:03:03 UTC (rev 3944) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 11:09:41 UTC (rev 3945) @@ -410,7 +410,7 @@ /** {@inheritDoc} */ public boolean createNewEvent(final JDialog frame) { - return createNewEvent(frame, this); + return createNewEvent(frame, this); } public static boolean createNewEvent(final JDialog frame, final ScriptArchData scriptArchData) { @@ -539,4 +539,9 @@ this.changed = changed; } + /** {@inheritDoc} */ + public boolean isChanged() { + return changed; + } + } // class ScriptArchData Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 11:03:03 UTC (rev 3944) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 11:09:41 UTC (rev 3945) @@ -410,7 +410,7 @@ /** {@inheritDoc} */ public boolean createNewEvent(final JDialog frame) { - return createNewEvent(frame, this); + return createNewEvent(frame, this); } public static boolean createNewEvent(final JDialog frame, final ScriptArchData scriptArchData) { @@ -539,4 +539,9 @@ this.changed = changed; } + /** {@inheritDoc} */ + public boolean isChanged() { + return changed; + } + } // class ScriptArchData Modified: trunk/src/app/net/sf/gridarta/gameobject/match/NamedGameObjectMatcher.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/match/NamedGameObjectMatcher.java 2008-05-03 11:03:03 UTC (rev 3944) +++ trunk/src/app/net/sf/gridarta/gameobject/match/NamedGameObjectMatcher.java 2008-05-03 11:09:41 UTC (rev 3945) @@ -96,7 +96,7 @@ * @return the edit type */ public int getEditType() { - return editType; + return editType; } } // class NamedGameObjectMatcher This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-03 11:27:12
|
Revision: 3947 http://gridarta.svn.sourceforge.net/gridarta/?rev=3947&view=rev Author: akirschbaum Date: 2008-05-03 04:27:12 -0700 (Sat, 03 May 2008) Log Message: ----------- Add ScriptArchData.getOwner(). Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 11:23:33 UTC (rev 3946) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 11:27:12 UTC (rev 3947) @@ -544,4 +544,8 @@ return changed; } + public GameObject getOwner() { + return owner; + } + } // class ScriptArchData Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 11:23:33 UTC (rev 3946) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 11:27:12 UTC (rev 3947) @@ -544,4 +544,8 @@ return changed; } + public GameObject getOwner() { + return owner; + } + } // class ScriptArchData This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-03 11:33:25
|
Revision: 3948 http://gridarta.svn.sourceforge.net/gridarta/?rev=3948&view=rev Author: akirschbaum Date: 2008-05-03 04:33:31 -0700 (Sat, 03 May 2008) Log Message: ----------- Replace access to fields with getter calls. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 11:27:12 UTC (rev 3947) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 11:33:31 UTC (rev 3948) @@ -421,7 +421,7 @@ final File localMapDir = AbstractMainControl.getInstance().getLocalMapDir(); - scriptArchData.changed = false; + scriptArchData.setChanged(false); // first check if that event type is not already in use final GameObject replaceObject = scriptArchData.getScriptedEvent(eventType); @@ -473,7 +473,7 @@ if (replaceObject != null) { replaceObject.remove(); } - scriptArchData.owner.addLast(event.getEventArch()); + scriptArchData.getOwner().addLast(event.getEventArch()); frame.setVisible(false); // close dialog } } else { @@ -508,8 +508,8 @@ if (replaceObject != null) { replaceObject.remove(); } - scriptArchData.changed = true; - scriptArchData.owner.addLast(event.getEventArch()); + scriptArchData.setChanged(true); + scriptArchData.getOwner().addLast(event.getEventArch()); frame.setVisible(false); // close dialog // open new script file @@ -517,7 +517,7 @@ } } } - return scriptArchData.changed; + return scriptArchData.isChanged(); } /** Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 11:27:12 UTC (rev 3947) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 11:33:31 UTC (rev 3948) @@ -421,7 +421,7 @@ final File localMapDir = AbstractMainControl.getInstance().getLocalMapDir(); - scriptArchData.changed = false; + scriptArchData.setChanged(false); // first check if that event type is not already in use final GameObject replaceObject = scriptArchData.getScriptedEvent(eventType); @@ -473,7 +473,7 @@ if (replaceObject != null) { replaceObject.remove(); } - scriptArchData.owner.addLast(event.getEventArch()); + scriptArchData.getOwner().addLast(event.getEventArch()); frame.setVisible(false); // close dialog } } else { @@ -508,8 +508,8 @@ if (replaceObject != null) { replaceObject.remove(); } - scriptArchData.changed = true; - scriptArchData.owner.addLast(event.getEventArch()); + scriptArchData.setChanged(true); + scriptArchData.getOwner().addLast(event.getEventArch()); frame.setVisible(false); // close dialog // open new script file @@ -517,7 +517,7 @@ } } } - return scriptArchData.changed; + return scriptArchData.isChanged(); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-03 11:49:53
|
Revision: 3949 http://gridarta.svn.sourceforge.net/gridarta/?rev=3949&view=rev Author: akirschbaum Date: 2008-05-03 04:50:00 -0700 (Sat, 03 May 2008) Log Message: ----------- Split off ScriptArchEditor from ScriptArchData. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2008-05-03 11:33:31 UTC (rev 3948) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2008-05-03 11:50:00 UTC (rev 3949) @@ -20,6 +20,7 @@ package cfeditor.gameobject; import cfeditor.gameobject.scripts.ScriptArchData; +import cfeditor.gameobject.scripts.ScriptArchEditor; import cfeditor.map.MapArchObject; import java.io.Serializable; import javax.swing.JList; @@ -206,7 +207,7 @@ /** {@inheritDoc} */ @Override public void addEventScript(@NotNull final JList eventList, @NotNull final GameObjectAttributesPanel<GameObject, MapArchObject, Archetype, ?, ?> mapanel) { - ScriptArchData.addEventScript(eventList, this, scriptArchData); + ScriptArchEditor.addEventScript(eventList, this, scriptArchData); if (!scriptArchData.isEmpty()) { mapanel.setScriptPanelButtonState(true, true, true, true); Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 11:33:31 UTC (rev 3948) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 11:50:00 UTC (rev 3949) @@ -22,35 +22,11 @@ import cfeditor.gameobject.Archetype; import cfeditor.gameobject.GameObject; import cfeditor.gui.GameObjectAttributesPanel; -import java.awt.Color; -import java.awt.FlowLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; -import java.io.IOException; import java.util.Iterator; import java.util.Vector; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JComboBox; import javax.swing.JDialog; -import javax.swing.JFileChooser; -import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.WindowConstants; -import net.sf.gridarta.AbstractMainControl; -import net.sf.gridarta.gameobject.scripts.PathButtonListener; -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; -import net.sf.gridarta.io.PathManager; -import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; -import net.sf.japi.swing.ActionFactory; -import net.sf.japi.util.Arrays2; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -69,27 +45,6 @@ /** Serial Version. */ private static final long serialVersionUID = 1L; - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - - /** The ending for scripts. */ - private static final String SCRIPT_ENDING = ".py"; - - // popup frame for new scripts: - private static JDialog newScriptFrame; - - private static JLabel headingLabel; - - private static PathButtonListener nsOkListener; - - private static JComboBox eventTypeBox; - - private static JComboBox pluginNameBox; - - private static JTextField inputScriptPath; - - private static JTextField inputOptions; - private final GameObject owner; private boolean changed; @@ -100,20 +55,11 @@ */ public ScriptArchData(final GameObject owner) { this.owner = owner; - if (eventTypeBox == null) { - initEventTypeBoxes(); + if (ScriptArchEditor.eventTypeBox == null) { + ScriptArchEditor.initEventTypeBoxes(); } } - /** Initialize the JComboBox with the event types. */ - private static synchronized void initEventTypeBoxes() { - pluginNameBox = new JComboBox(new String[]{" Python"}); - pluginNameBox.setSelectedIndex(0); - - eventTypeBox = new JComboBox(ScriptArchUtils.allEventTypes); - eventTypeBox.setSelectedIndex(Arrays2.linearEqualitySearch("say", ScriptArchUtils.allEventTypes)); - } - /** * Search the owner game object for an event object of the specified event * type. @@ -121,7 +67,7 @@ * @return the event game object, or <code>null</code> if no event of this * type exists */ - @Nullable private GameObject getScriptedEvent(final int eventType) { + @Nullable public GameObject getScriptedEvent(final int eventType) { for (final GameObject tmp : owner) { if (tmp.getArchTypNr() == Archetype.TYPE_EVENT_CONNECTOR && tmp.getAttributeInt("subtype") == eventType) { return tmp; @@ -211,315 +157,11 @@ } } - /** - * Try to create a reasonable default script name for lazy users. - * @param archName the best suitable name for the arch (see GameObject.getBestName()) - * @return a nice default script name without whitespaces - */ - private static String chooseDefaultScriptName(final String archName) { - String defScriptName = archName.trim(); - final int i; - if ((i = defScriptName.indexOf(" ")) >= 0) { - if (defScriptName.length() > 12 || defScriptName.lastIndexOf(" ") != i) { - // if there are several whitespaces or the name is too long, just cut off the end - defScriptName = defScriptName.substring(0, i); - } else { - // if there is only one whitespace in a short name, remove whitespace - defScriptName = defScriptName.substring(0, i) + defScriptName.substring(i + 1, i + 2).toUpperCase() + defScriptName.substring(i + 2); - } - } - if (defScriptName.length() >= 3) { - defScriptName = defScriptName.substring(0, 1).toUpperCase() + defScriptName.substring(1); - } - defScriptName += "Script" + SCRIPT_ENDING; - - return PathManager.getMapPath(new File(AbstractMainControl.getInstance().getLocalMapDir(), defScriptName).getPath()); - } - - /** - * This method is called when the user selects a new event to be created. - * The path relative to the map dir is calculated, and if reasonable, - * a relative path is created (relative to the map the event is on). - * @param f script file - * @return local event path - */ - private static String localizeEventPath(final File f) { - final File localMapDir = AbstractMainControl.getInstance().getLocalMapDir(); - final File mapDir = new File(AbstractMainControl.getInstance().getMapDefaultFolder()); // global map directory - - if (!mapDir.exists()) { - log.warn("Map directory '" + mapDir.getAbsolutePath() + "' does not exist!"); - return f.getName(); - } - - // find out if the scriptfile is in a subdirectory of the map file - File tmp; - for (tmp = f.getParentFile(); tmp != null && !tmp.getAbsolutePath().equalsIgnoreCase(localMapDir.getAbsolutePath()); tmp = tmp.getParentFile()) { - ; - } - - // FIXME: It would be a good idea to perform the canonization somewhere else. - // The paths returned by mapFile.getParentFile() and mControl.getMapDefaultFolder() should already be canonical - String path; - if (tmp == null) { - // scriptfile is NOT in a subirectory of mapfile -> absolute path - try { - path = f.getAbsolutePath().substring(mapDir.getCanonicalPath().length()); - } catch (final IOException e) { - path = f.getAbsolutePath().substring(mapDir.getAbsolutePath().length()); - } - path = path.replace('\\', '/'); - if (!path.startsWith("/")) { - path = "/" + path; // leading slash - } - } else { - // scriptfile is in a subirectory of mapfile -> relative path - try { - path = f.getAbsolutePath().substring(localMapDir.getCanonicalPath().length()); - } catch (final IOException e) { - path = f.getAbsolutePath().substring(localMapDir.getAbsolutePath().length()); - } - path = path.replace('\\', '/'); - while (path.length() > 0 && path.startsWith("/")) { - path = path.substring(1); // no leading slash - } - } - return path; - } - - /** - * A popup is opened and the user can create a new scripting event - * which gets attached to this gameObject. - * @param panelList JList from the MapArchPanel (script tab) which displays the events - * @param gameObject GameObject to add event to - * @param scriptArchData the <code>ScriptArchData</code> instance to display - */ - public static void addEventScript(final JList panelList, final GameObject gameObject, final ScriptArchData scriptArchData) { - final String archName = gameObject.getBestName(); - // create a reasonable default script name for lazy users :-) - final String defScriptName = chooseDefaultScriptName(archName); - - if (newScriptFrame == null) { - // initialize popup frame - newScriptFrame = new JDialog(AbstractMainControl.getInstance().getMainView(), "New Scripted Event", true); - newScriptFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); - - final JPanel mainPanel = new JPanel(); - mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); - mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); - - // first line: heading - final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - headingLabel = new JLabel("New scripted event for \"" + archName + "\":"); - headingLabel.setForeground(Color.black); - line1.add(headingLabel); - mainPanel.add(line1); - - // event type - mainPanel.add(Box.createVerticalStrut(10)); - final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - final JLabel tlabel1 = new JLabel("Event type:"); - line2.add(tlabel1); - line2.add(eventTypeBox); - //mainPanel.add(line2); - line2.add(Box.createHorizontalStrut(10)); - - // plugin name - final JLabel tlabel2 = new JLabel("Plugin:"); - line2.add(tlabel2); - line2.add(pluginNameBox); - mainPanel.add(line2); - - // path - mainPanel.add(Box.createVerticalStrut(5)); - final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - final JLabel tlabel3 = new JLabel("Script file:"); - line3.add(tlabel3); - mainPanel.add(line3); - inputScriptPath = new JTextField(defScriptName, 20); - final JButton browseb = new JButton("..."); - browseb.setMargin(new Insets(0, 10, 0, 10)); - browseb.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - final File home = AbstractMainControl.getInstance().getLocalMapDir(); - - final JFileChooser fileChooser = new JFileChooser(); - fileChooser.setDialogTitle("Select Script File"); - fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - fileChooser.setCurrentDirectory(home); - fileChooser.setMultiSelectionEnabled(false); - fileChooser.setFileFilter(AbstractMainControl.getInstance().getScriptFileFilter()); - - if (fileChooser.showOpenDialog(newScriptFrame) == JFileChooser.APPROVE_OPTION) { - // user has selected a file - final File f = fileChooser.getSelectedFile(); - inputScriptPath.setText(localizeEventPath(f)); - } - } - }); - line3.add(inputScriptPath); - line3.add(browseb); - mainPanel.add(line3); - - // options - mainPanel.add(Box.createVerticalStrut(5)); - final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - line4.add(new JLabel("Script options:")); - inputOptions = new JTextField("", 20); - line4.add(inputOptions); - mainPanel.add(line4); - - // description - final JPanel line5 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - final JPanel textPanel = new JPanel(); - textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS)); - final JLabel tlabel4 = new JLabel("When you specify an existing file, the new event will be linked"); - textPanel.add(tlabel4); - final JLabel tlabel5 = new JLabel("to that existing script. Otherwise a new script file is created."); - textPanel.add(tlabel5); - line5.add(textPanel); - mainPanel.add(line5); - - // button panel: - mainPanel.add(Box.createVerticalStrut(10)); - final JPanel line6 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JButton nsOkButton = new JButton("OK"); - nsOkListener = new PathButtonListener(true, newScriptFrame, scriptArchData); - nsOkButton.addActionListener(nsOkListener); - line6.add(nsOkButton); - - final JButton cancelButton = new JButton("Cancel"); - cancelButton.addActionListener(new PathButtonListener(false, newScriptFrame, null)); - line6.add(cancelButton); - mainPanel.add(line6); - - newScriptFrame.getContentPane().add(mainPanel); - newScriptFrame.pack(); - newScriptFrame.setLocationRelativeTo(AbstractMainControl.getInstance().getMainView()); - newScriptFrame.setVisible(true); - } else { - // just set fields and show - headingLabel.setText("New scripted event for \"" + archName + "\":"); - inputScriptPath.setText(defScriptName); - inputOptions.setText(""); - nsOkListener.setScriptArchData(scriptArchData); - newScriptFrame.toFront(); - newScriptFrame.setVisible(true); - } - } - /** {@inheritDoc} */ public boolean createNewEvent(final JDialog frame) { - return createNewEvent(frame, this); + return ScriptArchEditor.createNewEvent(frame, this); } - public static boolean createNewEvent(final JDialog frame, final ScriptArchData scriptArchData) { - String scriptPath = inputScriptPath.getText().trim(); - final String options = inputOptions.getText().trim(); - final int eventType = eventTypeBox.getSelectedIndex() + 1; - final String pluginName = ((String) pluginNameBox.getSelectedItem()).trim(); - - final File localMapDir = AbstractMainControl.getInstance().getLocalMapDir(); - - scriptArchData.setChanged(false); - - // first check if that event type is not already in use - final GameObject replaceObject = scriptArchData.getScriptedEvent(eventType); - if (replaceObject != null) { - // collision with existing event -> ask user: replace? - if (JOptionPane.showConfirmDialog(frame, "An event of type \"" + ScriptArchUtils.typeName(eventType) + "\" already exists for this object.\n" + "Do you want to replace the existing event?", "Event exists", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.NO_OPTION) { - // bail out - return false; - } - } - - // convert localized scriptPath into real, absolute path - scriptPath = scriptPath.replace('\\', '/'); - String absScriptPath; - if (scriptPath.startsWith("/")) { - // script path is absolute - final File mapDir = new File(AbstractMainControl.getInstance().getMapDefaultFolder()); // global map directory - if (!mapDir.exists()) { - // if map dir doesn't exist, this is not going to work - frame.setVisible(false); - ACTION_FACTORY.showMessageDialog(frame, "mapDirDoesntExist", mapDir); - return false; - } else { - absScriptPath = mapDir.getAbsolutePath() + scriptPath; - } - } else { - // script path is relative - absScriptPath = localMapDir.getAbsolutePath() + "/" + scriptPath; - } - - // now check if the specified path points to an existing script - File newScriptFile = new File(absScriptPath); - if (!newScriptFile.exists() && !absScriptPath.endsWith(SCRIPT_ENDING)) { - absScriptPath += SCRIPT_ENDING; - scriptPath += SCRIPT_ENDING; - newScriptFile = new File(absScriptPath); - } - - if (newScriptFile.exists()) { - if (newScriptFile.isFile()) { - // file exists -> link it to the event - final ScriptedEvent event; - try { - event = new ScriptedEvent(eventType, pluginName, scriptPath, options); - } catch (final UndefinedEventArchetypeException ex) { - JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); - return false; - } - if (replaceObject != null) { - replaceObject.remove(); - } - scriptArchData.getOwner().addLast(event.getEventArch()); - frame.setVisible(false); // close dialog - } - } else { - if (!absScriptPath.endsWith(SCRIPT_ENDING)) { - absScriptPath += SCRIPT_ENDING; - scriptPath += SCRIPT_ENDING; - newScriptFile = new File(absScriptPath); - } - - // file does not exist -> aks user: create new file? - if (JOptionPane.showConfirmDialog(frame, "Create new script '" + newScriptFile.getName() + "'?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.YES_OPTION) { - // okay, create new script file and open it - boolean couldCreateFile = false; // true when file creation successful - try { - // try to create new empty file - couldCreateFile = newScriptFile.createNewFile(); - } catch (final IOException e) { - /* ignore (really?) */ - } - - if (!couldCreateFile) { - JOptionPane.showMessageDialog(frame, "File '" + newScriptFile.getName() + "' could not be created.\n" + "Please check your path and write premissions.", "Cannot create file", JOptionPane.ERROR_MESSAGE); - } else { - // file has been created, now link it to the event - final ScriptedEvent event; - try { - event = new ScriptedEvent(eventType, pluginName, scriptPath, options); - } catch (final UndefinedEventArchetypeException ex) { - JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); - return false; - } - if (replaceObject != null) { - replaceObject.remove(); - } - scriptArchData.setChanged(true); - scriptArchData.getOwner().addLast(event.getEventArch()); - frame.setVisible(false); // close dialog - - // open new script file - ScriptEditControl.getInstance().openScriptFile(newScriptFile.getAbsolutePath()); - } - } - } - return scriptArchData.isChanged(); - } - /** * Returns whether this ScriptArchData is empty (contains no events). * (Note that empty ScriptArchData objects always are removed ASAP.) Added: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java (rev 0) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java 2008-05-03 11:50:00 UTC (rev 3949) @@ -0,0 +1,389 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package cfeditor.gameobject.scripts; + +import cfeditor.gameobject.GameObject; +import java.awt.Color; +import java.awt.FlowLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.IOException; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.WindowConstants; +import net.sf.gridarta.AbstractMainControl; +import net.sf.gridarta.gameobject.scripts.PathButtonListener; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; +import net.sf.gridarta.io.PathManager; +import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; +import net.sf.japi.swing.ActionFactory; +import net.sf.japi.util.Arrays2; +import org.apache.log4j.Logger; + +public class ScriptArchEditor { + + /** The Logger for printing log messages. */ + private static final Logger log = Logger.getLogger(ScriptArchEditor.class); + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); + + /** The ending for scripts. */ + private static final String SCRIPT_ENDING = ".py";// popup frame for new scripts: + + private static JDialog newScriptFrame; + + private static JLabel headingLabel; + + private static PathButtonListener nsOkListener; + + public static JComboBox eventTypeBox; + + private static JComboBox pluginNameBox; + + private static JTextField inputScriptPath; + + private static JTextField inputOptions; + + /** Initialize the JComboBox with the event types. */ + public static synchronized void initEventTypeBoxes() { + pluginNameBox = new JComboBox(new String[]{" Python"}); + pluginNameBox.setSelectedIndex(0); + + eventTypeBox = new JComboBox(ScriptArchUtils.allEventTypes); + eventTypeBox.setSelectedIndex(Arrays2.linearEqualitySearch("say", ScriptArchUtils.allEventTypes)); + } + + /** + * Try to create a reasonable default script name for lazy users. + * @param archName the best suitable name for the arch (see GameObject.getBestName()) + * @return a nice default script name without whitespaces + */ + public static String chooseDefaultScriptName(final String archName) { + String defScriptName = archName.trim(); + final int i; + if ((i = defScriptName.indexOf(" ")) >= 0) { + if (defScriptName.length() > 12 || defScriptName.lastIndexOf(" ") != i) { + // if there are several whitespaces or the name is too long, just cut off the end + defScriptName = defScriptName.substring(0, i); + } else { + // if there is only one whitespace in a short name, remove whitespace + defScriptName = defScriptName.substring(0, i) + defScriptName.substring(i + 1, i + 2).toUpperCase() + defScriptName.substring(i + 2); + } + } + if (defScriptName.length() >= 3) { + defScriptName = defScriptName.substring(0, 1).toUpperCase() + defScriptName.substring(1); + } + defScriptName += "Script" + SCRIPT_ENDING; + + return PathManager.getMapPath(new File(AbstractMainControl.getInstance().getLocalMapDir(), defScriptName).getPath()); + } + + /** + * This method is called when the user selects a new event to be created. + * The path relative to the map dir is calculated, and if reasonable, + * a relative path is created (relative to the map the event is on). + * @param f script file + * @return local event path + */ + public static String localizeEventPath(final File f) { + final File localMapDir = AbstractMainControl.getInstance().getLocalMapDir(); + final File mapDir = new File(AbstractMainControl.getInstance().getMapDefaultFolder()); // global map directory + + if (!mapDir.exists()) { + log.warn("Map directory '" + mapDir.getAbsolutePath() + "' does not exist!"); + return f.getName(); + } + + // find out if the scriptfile is in a subdirectory of the map file + File tmp; + for (tmp = f.getParentFile(); tmp != null && !tmp.getAbsolutePath().equalsIgnoreCase(localMapDir.getAbsolutePath()); tmp = tmp.getParentFile()) { + ; + } + + // FIXME: It would be a good idea to perform the canonization somewhere else. + // The paths returned by mapFile.getParentFile() and mControl.getMapDefaultFolder() should already be canonical + String path; + if (tmp == null) { + // scriptfile is NOT in a subirectory of mapfile -> absolute path + try { + path = f.getAbsolutePath().substring(mapDir.getCanonicalPath().length()); + } catch (final IOException e) { + path = f.getAbsolutePath().substring(mapDir.getAbsolutePath().length()); + } + path = path.replace('\\', '/'); + if (!path.startsWith("/")) { + path = "/" + path; // leading slash + } + } else { + // scriptfile is in a subirectory of mapfile -> relative path + try { + path = f.getAbsolutePath().substring(localMapDir.getCanonicalPath().length()); + } catch (final IOException e) { + path = f.getAbsolutePath().substring(localMapDir.getAbsolutePath().length()); + } + path = path.replace('\\', '/'); + while (path.length() > 0 && path.startsWith("/")) { + path = path.substring(1); // no leading slash + } + } + return path; + } + + /** + * A popup is opened and the user can create a new scripting event + * which gets attached to this gameObject. + * @param panelList JList from the MapArchPanel (script tab) which displays the events + * @param gameObject GameObject to add event to + * @param scriptArchData the <code>ScriptArchData</code> instance to display + */ + public static void addEventScript(final JList panelList, final GameObject gameObject, final ScriptArchData scriptArchData) { + final String archName = gameObject.getBestName(); + // create a reasonable default script name for lazy users :-) + final String defScriptName = chooseDefaultScriptName(archName); + + if (newScriptFrame == null) { + // initialize popup frame + newScriptFrame = new JDialog(AbstractMainControl.getInstance().getMainView(), "New Scripted Event", true); + newScriptFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); + + final JPanel mainPanel = new JPanel(); + mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); + mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); + + // first line: heading + final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + headingLabel = new JLabel("New scripted event for \"" + archName + "\":"); + headingLabel.setForeground(Color.black); + line1.add(headingLabel); + mainPanel.add(line1); + + // event type + mainPanel.add(Box.createVerticalStrut(10)); + final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + final JLabel tlabel1 = new JLabel("Event type:"); + line2.add(tlabel1); + line2.add(eventTypeBox); + //mainPanel.add(line2); + line2.add(Box.createHorizontalStrut(10)); + + // plugin name + final JLabel tlabel2 = new JLabel("Plugin:"); + line2.add(tlabel2); + line2.add(pluginNameBox); + mainPanel.add(line2); + + // path + mainPanel.add(Box.createVerticalStrut(5)); + final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + final JLabel tlabel3 = new JLabel("Script file:"); + line3.add(tlabel3); + mainPanel.add(line3); + inputScriptPath = new JTextField(defScriptName, 20); + final JButton browseb = new JButton("..."); + browseb.setMargin(new Insets(0, 10, 0, 10)); + browseb.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent e) { + final File home = AbstractMainControl.getInstance().getLocalMapDir(); + + final JFileChooser fileChooser = new JFileChooser(); + fileChooser.setDialogTitle("Select Script File"); + fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + fileChooser.setCurrentDirectory(home); + fileChooser.setMultiSelectionEnabled(false); + fileChooser.setFileFilter(AbstractMainControl.getInstance().getScriptFileFilter()); + + if (fileChooser.showOpenDialog(newScriptFrame) == JFileChooser.APPROVE_OPTION) { + // user has selected a file + final File f = fileChooser.getSelectedFile(); + inputScriptPath.setText(localizeEventPath(f)); + } + } + }); + line3.add(inputScriptPath); + line3.add(browseb); + mainPanel.add(line3); + + // options + mainPanel.add(Box.createVerticalStrut(5)); + final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + line4.add(new JLabel("Script options:")); + inputOptions = new JTextField("", 20); + line4.add(inputOptions); + mainPanel.add(line4); + + // description + final JPanel line5 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + final JPanel textPanel = new JPanel(); + textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS)); + final JLabel tlabel4 = new JLabel("When you specify an existing file, the new event will be linked"); + textPanel.add(tlabel4); + final JLabel tlabel5 = new JLabel("to that existing script. Otherwise a new script file is created."); + textPanel.add(tlabel5); + line5.add(textPanel); + mainPanel.add(line5); + + // button panel: + mainPanel.add(Box.createVerticalStrut(10)); + final JPanel line6 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JButton nsOkButton = new JButton("OK"); + nsOkListener = new PathButtonListener(true, newScriptFrame, scriptArchData); + nsOkButton.addActionListener(nsOkListener); + line6.add(nsOkButton); + + final JButton cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(new PathButtonListener(false, newScriptFrame, null)); + line6.add(cancelButton); + mainPanel.add(line6); + + newScriptFrame.getContentPane().add(mainPanel); + newScriptFrame.pack(); + newScriptFrame.setLocationRelativeTo(AbstractMainControl.getInstance().getMainView()); + newScriptFrame.setVisible(true); + } else { + // just set fields and show + headingLabel.setText("New scripted event for \"" + archName + "\":"); + inputScriptPath.setText(defScriptName); + inputOptions.setText(""); + nsOkListener.setScriptArchData(scriptArchData); + newScriptFrame.toFront(); + newScriptFrame.setVisible(true); + } + } + + public static boolean createNewEvent(final JDialog frame, final ScriptArchData scriptArchData) { + String scriptPath = inputScriptPath.getText().trim(); + final String options = inputOptions.getText().trim(); + final int eventType = eventTypeBox.getSelectedIndex() + 1; + final String pluginName = ((String) pluginNameBox.getSelectedItem()).trim(); + + final File localMapDir = AbstractMainControl.getInstance().getLocalMapDir(); + + scriptArchData.setChanged(false); + + // first check if that event type is not already in use + final GameObject replaceObject = scriptArchData.getScriptedEvent(eventType); + if (replaceObject != null) { + // collision with existing event -> ask user: replace? + if (JOptionPane.showConfirmDialog(frame, "An event of type \"" + ScriptArchUtils.typeName(eventType) + "\" already exists for this object.\n" + "Do you want to replace the existing event?", "Event exists", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.NO_OPTION) { + // bail out + return false; + } + } + + // convert localized scriptPath into real, absolute path + scriptPath = scriptPath.replace('\\', '/'); + String absScriptPath; + if (scriptPath.startsWith("/")) { + // script path is absolute + final File mapDir = new File(AbstractMainControl.getInstance().getMapDefaultFolder()); // global map directory + if (!mapDir.exists()) { + // if map dir doesn't exist, this is not going to work + frame.setVisible(false); + ACTION_FACTORY.showMessageDialog(frame, "mapDirDoesntExist", mapDir); + return false; + } else { + absScriptPath = mapDir.getAbsolutePath() + scriptPath; + } + } else { + // script path is relative + absScriptPath = localMapDir.getAbsolutePath() + "/" + scriptPath; + } + + // now check if the specified path points to an existing script + File newScriptFile = new File(absScriptPath); + if (!newScriptFile.exists() && !absScriptPath.endsWith(SCRIPT_ENDING)) { + absScriptPath += SCRIPT_ENDING; + scriptPath += SCRIPT_ENDING; + newScriptFile = new File(absScriptPath); + } + + if (newScriptFile.exists()) { + if (newScriptFile.isFile()) { + // file exists -> link it to the event + final ScriptedEvent event; + try { + event = new ScriptedEvent(eventType, pluginName, scriptPath, options); + } catch (final UndefinedEventArchetypeException ex) { + JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); + return false; + } + if (replaceObject != null) { + replaceObject.remove(); + } + scriptArchData.getOwner().addLast(event.getEventArch()); + frame.setVisible(false); // close dialog + } + } else { + if (!absScriptPath.endsWith(SCRIPT_ENDING)) { + absScriptPath += SCRIPT_ENDING; + scriptPath += SCRIPT_ENDING; + newScriptFile = new File(absScriptPath); + } + + // file does not exist -> aks user: create new file? + if (JOptionPane.showConfirmDialog(frame, "Create new script '" + newScriptFile.getName() + "'?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.YES_OPTION) { + // okay, create new script file and open it + boolean couldCreateFile = false; // true when file creation successful + try { + // try to create new empty file + couldCreateFile = newScriptFile.createNewFile(); + } catch (final IOException e) { + /* ignore (really?) */ + } + + if (!couldCreateFile) { + JOptionPane.showMessageDialog(frame, "File '" + newScriptFile.getName() + "' could not be created.\n" + "Please check your path and write premissions.", "Cannot create file", JOptionPane.ERROR_MESSAGE); + } else { + // file has been created, now link it to the event + final ScriptedEvent event; + try { + event = new ScriptedEvent(eventType, pluginName, scriptPath, options); + } catch (final UndefinedEventArchetypeException ex) { + JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); + return false; + } + if (replaceObject != null) { + replaceObject.remove(); + } + scriptArchData.setChanged(true); + scriptArchData.getOwner().addLast(event.getEventArch()); + frame.setVisible(false); // close dialog + + // open new script file + ScriptEditControl.getInstance().openScriptFile(newScriptFile.getAbsolutePath()); + } + } + } + return scriptArchData.isChanged(); + } +} // class ScriptArchEditor Property changes on: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/daimonin/src/daieditor/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObject.java 2008-05-03 11:33:31 UTC (rev 3948) +++ trunk/daimonin/src/daieditor/gameobject/GameObject.java 2008-05-03 11:50:00 UTC (rev 3949) @@ -23,6 +23,7 @@ import daieditor.gameobject.anim.AnimationObject; import daieditor.gameobject.anim.AnimationObjects; import daieditor.gameobject.scripts.ScriptArchData; +import daieditor.gameobject.scripts.ScriptArchEditor; import daieditor.map.MapArchObject; import java.io.Serializable; import javax.swing.ImageIcon; @@ -375,7 +376,7 @@ /** {@inheritDoc} */ @Override public void addEventScript(@NotNull final JList eventList, @NotNull final GameObjectAttributesPanel<GameObject, MapArchObject, Archetype, ?, ?> mapanel) { - ScriptArchData.addEventScript(eventList, this, scriptArchData); + ScriptArchEditor.addEventScript(eventList, this, scriptArchData); if (!scriptArchData.isEmpty()) { mapanel.setScriptPanelButtonState(true, true, true, true); Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 11:33:31 UTC (rev 3948) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 11:50:00 UTC (rev 3949) @@ -22,35 +22,11 @@ import daieditor.gameobject.Archetype; import daieditor.gameobject.GameObject; import daieditor.gui.GameObjectAttributesPanel; -import java.awt.Color; -import java.awt.FlowLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; -import java.io.IOException; import java.util.Iterator; import java.util.Vector; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JComboBox; import javax.swing.JDialog; -import javax.swing.JFileChooser; -import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.WindowConstants; -import net.sf.gridarta.AbstractMainControl; -import net.sf.gridarta.gameobject.scripts.PathButtonListener; -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; -import net.sf.gridarta.io.PathManager; -import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; -import net.sf.japi.swing.ActionFactory; -import net.sf.japi.util.Arrays2; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -69,27 +45,6 @@ /** Serial Version. */ private static final long serialVersionUID = 1L; - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); - - /** The ending for scripts. */ - private static final String SCRIPT_ENDING = ".lua"; - - // popup frame for new scripts: - private static JDialog newScriptFrame; - - private static JLabel headingLabel; - - private static PathButtonListener nsOkListener; - - private static JComboBox eventTypeBox; - - private static JComboBox pluginNameBox; - - private static JTextField inputScriptPath; - - private static JTextField inputOptions; - private final GameObject owner; private boolean changed; @@ -100,20 +55,11 @@ */ public ScriptArchData(final GameObject owner) { this.owner = owner; - if (eventTypeBox == null) { - initEventTypeBoxes(); + if (ScriptArchEditor.eventTypeBox == null) { + ScriptArchEditor.initEventTypeBoxes(); } } - /** Initialize the JComboBox with the event types. */ - private static synchronized void initEventTypeBoxes() { - pluginNameBox = new JComboBox(new String[]{" Lua "}); - pluginNameBox.setSelectedIndex(0); - - eventTypeBox = new JComboBox(ScriptArchUtils.allEventTypes); - eventTypeBox.setSelectedIndex(Arrays2.linearEqualitySearch("say", ScriptArchUtils.allEventTypes)); - } - /** * Search the owner game object for an event object of the specified event * type. @@ -121,7 +67,7 @@ * @return the event game object, or <code>null</code> if no event of this * type exists */ - @Nullable private GameObject getScriptedEvent(final int eventType) { + @Nullable public GameObject getScriptedEvent(final int eventType) { for (final GameObject tmp : owner) { if (tmp.getArchTypNr() == Archetype.TYPE_EVENT_OBJECT && tmp.getAttributeInt("sub_type") == eventType) { return tmp; @@ -211,315 +157,11 @@ } } - /** - * Try to create a reasonable default script name for lazy users. - * @param archName the best suitable name for the arch (see GameObject.getBestName()) - * @return a nice default script name without whitespaces - */ - private static String chooseDefaultScriptName(final String archName) { - String defScriptName = archName.trim(); - final int i; - if ((i = defScriptName.indexOf(" ")) >= 0) { - if (defScriptName.length() > 12 || defScriptName.lastIndexOf(" ") != i) { - // if there are several whitespaces or the name is too long, just cut off the end - defScriptName = defScriptName.substring(0, i); - } else { - // if there is only one whitespace in a short name, remove whitespace - defScriptName = defScriptName.substring(0, i) + defScriptName.substring(i + 1, i + 2).toUpperCase() + defScriptName.substring(i + 2); - } - } - if (defScriptName.length() >= 3) { - defScriptName = defScriptName.substring(0, 1).toUpperCase() + defScriptName.substring(1); - } - defScriptName += "Script" + SCRIPT_ENDING; - - return PathManager.getMapPath(new File(AbstractMainControl.getInstance().getLocalMapDir(), defScriptName).getPath()); - } - - /** - * This method is called when the user selects a new event to be created. - * The path relative to the map dir is calculated, and if reasonable, - * a relative path is created (relative to the map the event is on). - * @param f script file - * @return local event path - */ - private static String localizeEventPath(final File f) { - final File localMapDir = AbstractMainControl.getInstance().getLocalMapDir(); - final File mapDir = new File(AbstractMainControl.getInstance().getMapDefaultFolder()); // global map directory - - if (!mapDir.exists()) { - log.warn("Map directory '" + mapDir.getAbsolutePath() + "' does not exist!"); - return f.getName(); - } - - // find out if the scriptfile is in a subdirectory of the map file - File tmp; - for (tmp = f.getParentFile(); tmp != null && !tmp.getAbsolutePath().equalsIgnoreCase(localMapDir.getAbsolutePath()); tmp = tmp.getParentFile()) { - ; - } - - // FIXME: It would be a good idea to perform the canonization somewhere else. - // The paths returned by mapFile.getParentFile() and mControl.getMapDefaultFolder() should already be canonical - String path; - if (tmp == null) { - // scriptfile is NOT in a subirectory of mapfile -> absolute path - try { - path = f.getAbsolutePath().substring(mapDir.getCanonicalPath().length()); - } catch (final IOException e) { - path = f.getAbsolutePath().substring(mapDir.getAbsolutePath().length()); - } - path = path.replace('\\', '/'); - if (!path.startsWith("/")) { - path = "/" + path; // leading slash - } - } else { - // scriptfile is in a subirectory of mapfile -> relative path - try { - path = f.getAbsolutePath().substring(localMapDir.getCanonicalPath().length()); - } catch (final IOException e) { - path = f.getAbsolutePath().substring(localMapDir.getAbsolutePath().length()); - } - path = path.replace('\\', '/'); - while (path.length() > 0 && path.startsWith("/")) { - path = path.substring(1); // no leading slash - } - } - return path; - } - - /** - * A popup is opened and the user can create a new scripting event - * which gets attached to this gameObject. - * @param panelList JList from the MapArchPanel (script tab) which displays the events - * @param gameObject GameObject to add event to - * @param scriptArchData the <code>ScriptArchData</code> instance to display - */ - public static void addEventScript(final JList panelList, final GameObject gameObject, final ScriptArchData scriptArchData) { - final String archName = gameObject.getBestName(); - // create a reasonable default script name for lazy users :-) - final String defScriptName = chooseDefaultScriptName(archName); - - if (newScriptFrame == null) { - // initialize popup frame - newScriptFrame = new JDialog(AbstractMainControl.getInstance().getMainView(), "New Scripted Event", true); - newScriptFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); - - final JPanel mainPanel = new JPanel(); - mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); - mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); - - // first line: heading - final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - headingLabel = new JLabel("New scripted event for \"" + archName + "\":"); - headingLabel.setForeground(Color.black); - line1.add(headingLabel); - mainPanel.add(line1); - - // event type - mainPanel.add(Box.createVerticalStrut(10)); - final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - final JLabel tlabel1 = new JLabel("Event type:"); - line2.add(tlabel1); - line2.add(eventTypeBox); - //mainPanel.add(line2); - line2.add(Box.createHorizontalStrut(10)); - - // plugin name - final JLabel tlabel2 = new JLabel("Plugin:"); - line2.add(tlabel2); - line2.add(pluginNameBox); - mainPanel.add(line2); - - // path - mainPanel.add(Box.createVerticalStrut(5)); - final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - final JLabel tlabel3 = new JLabel("Script file:"); - line3.add(tlabel3); - mainPanel.add(line3); - inputScriptPath = new JTextField(defScriptName, 20); - final JButton browseb = new JButton("..."); - browseb.setMargin(new Insets(0, 10, 0, 10)); - browseb.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - final File home = AbstractMainControl.getInstance().getLocalMapDir(); - - final JFileChooser fileChooser = new JFileChooser(); - fileChooser.setDialogTitle("Select Script File"); - fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - fileChooser.setCurrentDirectory(home); - fileChooser.setMultiSelectionEnabled(false); - fileChooser.setFileFilter(AbstractMainControl.getInstance().getScriptFileFilter()); - - if (fileChooser.showOpenDialog(newScriptFrame) == JFileChooser.APPROVE_OPTION) { - // user has selected a file - final File f = fileChooser.getSelectedFile(); - inputScriptPath.setText(localizeEventPath(f)); - } - } - }); - line3.add(inputScriptPath); - line3.add(browseb); - mainPanel.add(line3); - - // options - mainPanel.add(Box.createVerticalStrut(5)); - final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - line4.add(new JLabel("Script options:")); - inputOptions = new JTextField("", 20); - line4.add(inputOptions); - mainPanel.add(line4); - - // description - final JPanel line5 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - final JPanel textPanel = new JPanel(); - textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS)); - final JLabel tlabel4 = new JLabel("When you specify an existing file, the new event will be linked"); - textPanel.add(tlabel4); - final JLabel tlabel5 = new JLabel("to that existing script. Otherwise a new script file is created."); - textPanel.add(tlabel5); - line5.add(textPanel); - mainPanel.add(line5); - - // button panel: - mainPanel.add(Box.createVerticalStrut(10)); - final JPanel line6 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JButton nsOkButton = new JButton("OK"); - nsOkListener = new PathButtonListener(true, newScriptFrame, scriptArchData); - nsOkButton.addActionListener(nsOkListener); - line6.add(nsOkButton); - - final JButton cancelButton = new JButton("Cancel"); - cancelButton.addActionListener(new PathButtonListener(false, newScriptFrame, null)); - line6.add(cancelButton); - mainPanel.add(line6); - - newScriptFrame.getContentPane().add(mainPanel); - newScriptFrame.pack(); - newScriptFrame.setLocationRelativeTo(AbstractMainControl.getInstance().getMainView()); - newScriptFrame.setVisible(true); - } else { - // just set fields and show - headingLabel.setText("New scripted event for \"" + archName + "\":"); - inputScriptPath.setText(defScriptName); - inputOptions.setText(""); - nsOkListener.setScriptArchData(scriptArchData); - newScriptFrame.toFront(); - newScriptFrame.setVisible(true); - } - } - /** {@inheritDoc} */ public boolean createNewEvent(final JDialog frame) { - return createNewEvent(frame, this); + return ScriptArchEditor.createNewEvent(frame, this); } - public static boolean createNewEvent(final JDialog frame, final ScriptArchData scriptArchData) { - String scriptPath = inputScriptPath.getText().trim(); - final String options = inputOptions.getText().trim(); - final int eventType = eventTypeBox.getSelectedIndex() + 1; - final String pluginName = ((String) pluginNameBox.getSelectedItem()).trim(); - - final File localMapDir = AbstractMainControl.getInstance().getLocalMapDir(); - - scriptArchData.setChanged(false); - - // first check if that event type is not already in use - final GameObject replaceObject = scriptArchData.getScriptedEvent(eventType); - if (replaceObject != null) { - // collision with existing event -> ask user: replace? - if (JOptionPane.showConfirmDialog(frame, "An event of type \"" + ScriptArchUtils.typeName(eventType) + "\" already exists for this object.\n" + "Do you want to replace the existing event?", "Event exists", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.NO_OPTION) { - // bail out - return false; - } - } - - // convert localized scriptPath into real, absolute path - scriptPath = scriptPath.replace('\\', '/'); - String absScriptPath; - if (scriptPath.startsWith("/")) { - // script path is absolute - final File mapDir = new File(AbstractMainControl.getInstance().getMapDefaultFolder()); // global map directory - if (!mapDir.exists()) { - // if map dir doesn't exist, this is not going to work - frame.setVisible(false); - ACTION_FACTORY.showMessageDialog(frame, "mapDirDoesntExist", mapDir); - return false; - } else { - absScriptPath = mapDir.getAbsolutePath() + scriptPath; - } - } else { - // script path is relative - absScriptPath = localMapDir.getAbsolutePath() + "/" + scriptPath; - } - - // now check if the specified path points to an existing script - File newScriptFile = new File(absScriptPath); - if (!newScriptFile.exists() && !absScriptPath.endsWith(SCRIPT_ENDING)) { - absScriptPath += SCRIPT_ENDING; - scriptPath += SCRIPT_ENDING; - newScriptFile = new File(absScriptPath); - } - - if (newScriptFile.exists()) { - if (newScriptFile.isFile()) { - // file exists -> link it to the event - final ScriptedEvent event; - try { - event = new ScriptedEvent(eventType, pluginName, scriptPath, options); - } catch (final UndefinedEventArchetypeException ex) { - JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); - return false; - } - if (replaceObject != null) { - replaceObject.remove(); - } - scriptArchData.getOwner().addLast(event.getEventArch()); - frame.setVisible(false); // close dialog - } - } else { - if (!absScriptPath.endsWith(SCRIPT_ENDING)) { - absScriptPath += SCRIPT_ENDING; - scriptPath += SCRIPT_ENDING; - newScriptFile = new File(absScriptPath); - } - - // file does not exist -> aks user: create new file? - if (JOptionPane.showConfirmDialog(frame, "Create new script '" + newScriptFile.getName() + "'?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.YES_OPTION) { - // okay, create new script file and open it - boolean couldCreateFile = false; // true when file creation successful - try { - // try to create new empty file - couldCreateFile = newScriptFile.createNewFile(); - } catch (final IOException e) { - /* ignore (really?) */ - } - - if (!couldCreateFile) { - JOptionPane.showMessageDialog(frame, "File '" + newScriptFile.getName() + "' could not be created.\n" + "Please check your path and write premissions.", "Cannot create file", JOptionPane.ERROR_MESSAGE); - } else { - // file has been created, now link it to the event - final ScriptedEvent event; - try { - event = new ScriptedEvent(eventType, pluginName, scriptPath, options); - } catch (final UndefinedEventArchetypeException ex) { - JOptionPane.showMessageDialog(frame, "Cannot create event of type " + eventType + ":\n" + ex.getMessage() + ".", "Cannot create event", JOptionPane.ERROR_MESSAGE); - return false; - } - if (replaceObject != null) { - replaceObject.remove(); - } - scriptArchData.setChanged(true); - scriptArchData.getOwner().addLast(event.getEventArch()); - frame.setVisible(false); // close dialog - - // open new script file - ScriptEditControl.getInstance().openScriptFile(newScriptFile.getAbsolutePath()); - } - } - } - return scriptArchData.isChanged(); - } - /** * Returns whe... [truncated message content] |
From: <aki...@us...> - 2008-05-03 12:01:06
|
Revision: 3950 http://gridarta.svn.sourceforge.net/gridarta/?rev=3950&view=rev Author: akirschbaum Date: 2008-05-03 05:00:46 -0700 (Sat, 03 May 2008) Log Message: ----------- Move code to create event type's combo box. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchUtils.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchUtils.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java 2008-05-03 11:50:00 UTC (rev 3949) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java 2008-05-03 12:00:46 UTC (rev 3950) @@ -46,7 +46,6 @@ import net.sf.gridarta.io.PathManager; import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; import net.sf.japi.swing.ActionFactory; -import net.sf.japi.util.Arrays2; import org.apache.log4j.Logger; public class ScriptArchEditor { @@ -79,8 +78,7 @@ pluginNameBox = new JComboBox(new String[]{" Python"}); pluginNameBox.setSelectedIndex(0); - eventTypeBox = new JComboBox(ScriptArchUtils.allEventTypes); - eventTypeBox.setSelectedIndex(Arrays2.linearEqualitySearch("say", ScriptArchUtils.allEventTypes)); + eventTypeBox = ScriptArchUtils.createEventTypeBox(); } /** Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchUtils.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchUtils.java 2008-05-03 11:50:00 UTC (rev 3949) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchUtils.java 2008-05-03 12:00:46 UTC (rev 3950) @@ -19,12 +19,14 @@ package cfeditor.gameobject.scripts; +import javax.swing.JComboBox; +import net.sf.japi.util.Arrays2; import org.jetbrains.annotations.Nullable; public class ScriptArchUtils { // FIXME: This should NOT BE HERE. Instead, it should be read from types.xml. - public static final String[] allEventTypes = new String[] { + private static final String[] allEventTypes = new String[] { "apply", "attack", "death", @@ -71,4 +73,10 @@ } } + public static JComboBox createEventTypeBox() { + final JComboBox eventTypeBox = new JComboBox(allEventTypes); + eventTypeBox.setSelectedIndex(Arrays2.linearEqualitySearch("say", allEventTypes)); + return eventTypeBox; + } + } // class ScriptArchUtils Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java 2008-05-03 11:50:00 UTC (rev 3949) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java 2008-05-03 12:00:46 UTC (rev 3950) @@ -46,7 +46,6 @@ import net.sf.gridarta.io.PathManager; import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; import net.sf.japi.swing.ActionFactory; -import net.sf.japi.util.Arrays2; import org.apache.log4j.Logger; public class ScriptArchEditor { @@ -79,8 +78,7 @@ pluginNameBox = new JComboBox(new String[]{" Lua "}); pluginNameBox.setSelectedIndex(0); - eventTypeBox = new JComboBox(ScriptArchUtils.allEventTypes); - eventTypeBox.setSelectedIndex(Arrays2.linearEqualitySearch("say", ScriptArchUtils.allEventTypes)); + eventTypeBox = ScriptArchUtils.createEventTypeBox(); } /** Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchUtils.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchUtils.java 2008-05-03 11:50:00 UTC (rev 3949) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchUtils.java 2008-05-03 12:00:46 UTC (rev 3950) @@ -19,12 +19,14 @@ package daieditor.gameobject.scripts; +import javax.swing.JComboBox; +import net.sf.japi.util.Arrays2; import org.jetbrains.annotations.Nullable; public class ScriptArchUtils { // FIXME: This should NOT BE HERE. Instead, it should be read from types.xml. - public static final String[] allEventTypes = new String[] { + private static final String[] allEventTypes = new String[] { "apply", "attack", "death", @@ -67,4 +69,10 @@ return "event_obj"; } + public static JComboBox createEventTypeBox() { + final JComboBox eventTypeBox = new JComboBox(allEventTypes); + eventTypeBox.setSelectedIndex(Arrays2.linearEqualitySearch("say", allEventTypes)); + return eventTypeBox; + } + } // class ScriptArchUtils This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-03 12:07:44
|
Revision: 3951 http://gridarta.svn.sourceforge.net/gridarta/?rev=3951&view=rev Author: akirschbaum Date: 2008-05-03 05:07:52 -0700 (Sat, 03 May 2008) Log Message: ----------- Remove lazy initialization of ScriptArchEditor. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-05-03 12:00:46 UTC (rev 3950) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-05-03 12:07:52 UTC (rev 3951) @@ -26,6 +26,7 @@ import cfeditor.gameobject.GameObject; import cfeditor.gameobject.anim.AnimationObjects; import cfeditor.gameobject.face.FaceObjects; +import cfeditor.gameobject.scripts.ScriptArchEditor; import cfeditor.gameobject.scripts.ScriptArchUtils; import cfeditor.gui.GameObjectAttributesDialog; import cfeditor.gui.ObjectChooser; @@ -301,6 +302,8 @@ } gameObjectSpells.sort(); + ScriptArchEditor.initEventTypeBoxes(); + final boolean mapTileListBottom = prefs.getBoolean(MainView.MAP_TILE_LIST_BOTTOM_KEY, CMainView.MAP_TILE_LIST_BOTTOM_DEFAULT); selectedSquareControl = new SelectedSquareControl<GameObject, MapArchObject, Archetype, MapControl, CMapViewBasic>(ACTION_FACTORY, this, mainView, mapTileListBottom, null); // Initialize the main view Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 12:00:46 UTC (rev 3950) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 12:07:52 UTC (rev 3951) @@ -55,9 +55,6 @@ */ public ScriptArchData(final GameObject owner) { this.owner = owner; - if (ScriptArchEditor.eventTypeBox == null) { - ScriptArchEditor.initEventTypeBoxes(); - } } /** Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java 2008-05-03 12:00:46 UTC (rev 3950) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java 2008-05-03 12:07:52 UTC (rev 3951) @@ -65,7 +65,7 @@ private static PathButtonListener nsOkListener; - public static JComboBox eventTypeBox; + private static JComboBox eventTypeBox; private static JComboBox pluginNameBox; Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-05-03 12:00:46 UTC (rev 3950) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-05-03 12:07:52 UTC (rev 3951) @@ -25,6 +25,7 @@ import daieditor.gameobject.GameObject; import daieditor.gameobject.anim.AnimationObjects; import daieditor.gameobject.face.FaceObjects; +import daieditor.gameobject.scripts.ScriptArchEditor; import daieditor.gui.GameObjectAttributesDialog; import daieditor.gui.ObjectChooser; import daieditor.gui.prefs.AppPrefs; @@ -354,6 +355,8 @@ } numberSpells.sort(); + ScriptArchEditor.initEventTypeBoxes(); + final boolean mapTileListBottom = prefs.getBoolean(MainView.MAP_TILE_LIST_BOTTOM_KEY, CMainView.MAP_TILE_LIST_BOTTOM_DEFAULT); selectedSquareControl = new SelectedSquareControl<GameObject, MapArchObject, Archetype, MapControl, CMapViewBasic>(ACTION_FACTORY, this, mainView, mapTileListBottom, GUIUtils.getSysIcon(IGUIConstants.TILE_NORTH)); // Initialize the main view Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 12:00:46 UTC (rev 3950) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 12:07:52 UTC (rev 3951) @@ -55,9 +55,6 @@ */ public ScriptArchData(final GameObject owner) { this.owner = owner; - if (ScriptArchEditor.eventTypeBox == null) { - ScriptArchEditor.initEventTypeBoxes(); - } } /** Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java 2008-05-03 12:00:46 UTC (rev 3950) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java 2008-05-03 12:07:52 UTC (rev 3951) @@ -65,7 +65,7 @@ private static PathButtonListener nsOkListener; - public static JComboBox eventTypeBox; + private static JComboBox eventTypeBox; private static JComboBox pluginNameBox; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-03 12:49:05
|
Revision: 3952 http://gridarta.svn.sourceforge.net/gridarta/?rev=3952&view=rev Author: akirschbaum Date: 2008-05-03 05:41:18 -0700 (Sat, 03 May 2008) Log Message: ----------- Make ScriptedEvent.editParameters() static. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 12:07:52 UTC (rev 3951) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 12:41:18 UTC (rev 3952) @@ -140,7 +140,7 @@ if (task == GameObjectAttributesPanel.SCRIPT_OPEN) { event.openScript(); } else if (task == GameObjectAttributesPanel.SCRIPT_EDIT_PATH) { - event.editParameters(); + ScriptedEvent.editParameters(event); } else if (task == GameObjectAttributesPanel.SCRIPT_REMOVE) { // first ask for confirmation if (JOptionPane.showConfirmDialog(panelList, "Are you sure you want to remove this \"" + ScriptArchUtils.typeName(event.getEventType()) + "\" event which is\n" + "linked to the script: '" + event.getScriptPath() + "'?\n" + "(The script file itself is not going to be deleted)", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 12:07:52 UTC (rev 3951) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 12:41:18 UTC (rev 3952) @@ -152,10 +152,11 @@ } /** - * Edit path and plugin name for this event. A popup dialog is shown + * Edit path and plugin name for an event. A popup dialog is shown * with input text fields for file path and plugin name. + * @param scriptedEvent the event */ - public void editParameters() { + public static void editParameters(final ScriptedEvent scriptedEvent) { if (pathFrame == null) { // initialize popup frame pathFrame = new JDialog(AbstractMainControl.getInstance().getMainView(), "Edit Parameters", true); @@ -169,7 +170,7 @@ final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); final JLabel text1 = new JLabel("Script:"); line1.add(text1); - inputScriptPath = new JTextField(getScriptPath(), 20); + inputScriptPath = new JTextField(scriptedEvent.getScriptPath(), 20); line1.add(inputScriptPath); mainPanel.add(line1); @@ -177,7 +178,7 @@ final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); final JLabel text2 = new JLabel("Script options:"); line2.add(text2); - inputOptions = new JTextField(getOptions(), 20); + inputOptions = new JTextField(scriptedEvent.getOptions(), 20); line2.add(inputOptions); mainPanel.add(line2); mainPanel.add(Box.createVerticalStrut(5)); @@ -186,7 +187,7 @@ final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); final JLabel text3 = new JLabel("Plugin name:"); line3.add(text3); - inputPluginName = new JTextField(getPluginName(), 20); + inputPluginName = new JTextField(scriptedEvent.getPluginName(), 20); line3.add(inputPluginName); mainPanel.add(line3); mainPanel.add(Box.createVerticalStrut(5)); @@ -195,13 +196,13 @@ final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); final JButton okButton = new JButton("OK"); okListener = new PathButtonListener(true, pathFrame, null); - okListener.setTargetEvent(this); + okListener.setTargetEvent(scriptedEvent); okButton.addActionListener(okListener); line4.add(okButton); final JButton cancelButton = new JButton("Cancel"); cancelListener = new PathButtonListener(false, pathFrame, null); - cancelListener.setTargetEvent(this); + cancelListener.setTargetEvent(scriptedEvent); cancelButton.addActionListener(cancelListener); line4.add(cancelButton); mainPanel.add(line4); @@ -212,11 +213,11 @@ pathFrame.setVisible(true); } else { // just set fields and show - okListener.setTargetEvent(this); - cancelListener.setTargetEvent(this); - inputScriptPath.setText(getScriptPath()); - inputPluginName.setText(getPluginName()); - inputOptions.setText(getOptions()); + okListener.setTargetEvent(scriptedEvent); + cancelListener.setTargetEvent(scriptedEvent); + inputScriptPath.setText(scriptedEvent.getScriptPath()); + inputPluginName.setText(scriptedEvent.getPluginName()); + inputOptions.setText(scriptedEvent.getOptions()); pathFrame.toFront(); pathFrame.setVisible(true); } Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 12:07:52 UTC (rev 3951) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 12:41:18 UTC (rev 3952) @@ -140,7 +140,7 @@ if (task == GameObjectAttributesPanel.SCRIPT_OPEN) { event.openScript(); } else if (task == GameObjectAttributesPanel.SCRIPT_EDIT_PATH) { - event.editParameters(); + ScriptedEvent.editParameters(event); } else if (task == GameObjectAttributesPanel.SCRIPT_REMOVE) { // first ask for confirmation if (JOptionPane.showConfirmDialog(panelList, "Are you sure you want to remove this \"" + ScriptArchUtils.typeName(event.getEventType()) + "\" event which is\n" + "linked to the script: '" + event.getScriptPath() + "'?\n" + "(The script file itself is not going to be deleted)", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 12:07:52 UTC (rev 3951) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 12:41:18 UTC (rev 3952) @@ -151,10 +151,11 @@ } /** - * Edit path and plugin name for this event. A popup dialog is shown + * Edit path and plugin name for an event. A popup dialog is shown * with input text fields for file path and plugin name. + * @param scriptedEvent the event */ - public void editParameters() { + public static void editParameters(final ScriptedEvent scriptedEvent) { if (pathFrame == null) { // initialize popup frame pathFrame = new JDialog(AbstractMainControl.getInstance().getMainView(), "Edit Parameters", true); @@ -168,7 +169,7 @@ final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); final JLabel text1 = new JLabel("Script:"); line1.add(text1); - inputScriptPath = new JTextField(getScriptPath(), 20); + inputScriptPath = new JTextField(scriptedEvent.getScriptPath(), 20); line1.add(inputScriptPath); mainPanel.add(line1); @@ -176,7 +177,7 @@ final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); final JLabel text2 = new JLabel("Script options:"); line2.add(text2); - inputOptions = new JTextField(getOptions(), 20); + inputOptions = new JTextField(scriptedEvent.getOptions(), 20); line2.add(inputOptions); mainPanel.add(line2); mainPanel.add(Box.createVerticalStrut(5)); @@ -185,7 +186,7 @@ final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); final JLabel text3 = new JLabel("Plugin name:"); line3.add(text3); - inputPluginName = new JTextField(getPluginName(), 20); + inputPluginName = new JTextField(scriptedEvent.getPluginName(), 20); line3.add(inputPluginName); mainPanel.add(line3); mainPanel.add(Box.createVerticalStrut(5)); @@ -194,13 +195,13 @@ final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); final JButton okButton = new JButton("OK"); okListener = new PathButtonListener(true, pathFrame, null); - okListener.setTargetEvent(this); + okListener.setTargetEvent(scriptedEvent); okButton.addActionListener(okListener); line4.add(okButton); final JButton cancelButton = new JButton("Cancel"); cancelListener = new PathButtonListener(false, pathFrame, null); - cancelListener.setTargetEvent(this); + cancelListener.setTargetEvent(scriptedEvent); cancelButton.addActionListener(cancelListener); line4.add(cancelButton); mainPanel.add(line4); @@ -211,11 +212,11 @@ pathFrame.setVisible(true); } else { // just set fields and show - okListener.setTargetEvent(this); - cancelListener.setTargetEvent(this); - inputScriptPath.setText(getScriptPath()); - inputPluginName.setText(getPluginName()); - inputOptions.setText(getOptions()); + okListener.setTargetEvent(scriptedEvent); + cancelListener.setTargetEvent(scriptedEvent); + inputScriptPath.setText(scriptedEvent.getScriptPath()); + inputPluginName.setText(scriptedEvent.getPluginName()); + inputOptions.setText(scriptedEvent.getOptions()); pathFrame.toFront(); pathFrame.setVisible(true); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-03 12:50:44
|
Revision: 3953 http://gridarta.svn.sourceforge.net/gridarta/?rev=3953&view=rev Author: akirschbaum Date: 2008-05-03 05:50:45 -0700 (Sat, 03 May 2008) Log Message: ----------- Make ScriptedEvent.openScript() static. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 12:41:18 UTC (rev 3952) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 12:50:45 UTC (rev 3953) @@ -138,7 +138,7 @@ final ScriptedEvent event = new ScriptedEvent(oldEvent); // now decide what to do: if (task == GameObjectAttributesPanel.SCRIPT_OPEN) { - event.openScript(); + ScriptedEvent.openScript(event.getScriptPath()); } else if (task == GameObjectAttributesPanel.SCRIPT_EDIT_PATH) { ScriptedEvent.editParameters(event); } else if (task == GameObjectAttributesPanel.SCRIPT_REMOVE) { Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 12:41:18 UTC (rev 3952) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 12:50:45 UTC (rev 3953) @@ -120,10 +120,11 @@ return true; } - /** Opens the script pad to display the script for this event. */ - public void openScript() { - final String scriptPath = getScriptPath(); - + /** + * Opens the script pad to display a script. + * @param scriptPath the script path + */ + public static void openScript(final String scriptPath) { // trying to get the absolute path to scriptfile: final StringBuilder tmpPath = new StringBuilder(); if (scriptPath.startsWith("/")) { Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 12:41:18 UTC (rev 3952) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 12:50:45 UTC (rev 3953) @@ -138,7 +138,7 @@ final ScriptedEvent event = new ScriptedEvent(oldEvent); // now decide what to do: if (task == GameObjectAttributesPanel.SCRIPT_OPEN) { - event.openScript(); + ScriptedEvent.openScript(event.getScriptPath()); } else if (task == GameObjectAttributesPanel.SCRIPT_EDIT_PATH) { ScriptedEvent.editParameters(event); } else if (task == GameObjectAttributesPanel.SCRIPT_REMOVE) { Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 12:41:18 UTC (rev 3952) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 12:50:45 UTC (rev 3953) @@ -119,10 +119,11 @@ return true; } - /** Opens the script pad to display the script for this event. */ - public void openScript() { - final String scriptPath = getScriptPath(); - + /** + * Opens the script pad to display a script. + * @param scriptPath the script path + */ + public static void openScript(final String scriptPath) { // trying to get the absolute path to scriptfile: final StringBuilder tmpPath = new StringBuilder(); if (scriptPath.startsWith("/")) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-03 14:51:03
|
Revision: 3954 http://gridarta.svn.sourceforge.net/gridarta/?rev=3954&view=rev Author: akirschbaum Date: 2008-05-03 07:51:10 -0700 (Sat, 03 May 2008) Log Message: ----------- Split off ScriptedEventEditor from ScriptedEvent. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEventEditor.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEventEditor.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 12:50:45 UTC (rev 3953) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 14:51:10 UTC (rev 3954) @@ -138,9 +138,9 @@ final ScriptedEvent event = new ScriptedEvent(oldEvent); // now decide what to do: if (task == GameObjectAttributesPanel.SCRIPT_OPEN) { - ScriptedEvent.openScript(event.getScriptPath()); + ScriptedEventEditor.openScript(event.getScriptPath()); } else if (task == GameObjectAttributesPanel.SCRIPT_EDIT_PATH) { - ScriptedEvent.editParameters(event); + ScriptedEventEditor.editParameters(event); } else if (task == GameObjectAttributesPanel.SCRIPT_REMOVE) { // first ask for confirmation if (JOptionPane.showConfirmDialog(panelList, "Are you sure you want to remove this \"" + ScriptArchUtils.typeName(event.getEventType()) + "\" event which is\n" + "linked to the script: '" + event.getScriptPath() + "'?\n" + "(The script file itself is not going to be deleted)", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 12:50:45 UTC (rev 3953) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 14:51:10 UTC (rev 3954) @@ -19,27 +19,8 @@ package cfeditor.gameobject.scripts; -import cfeditor.CMainControl; -import cfeditor.gameobject.Archetype; import cfeditor.gameobject.GameObject; -import java.awt.FlowLayout; -import java.io.File; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.WindowConstants; -import net.sf.gridarta.AbstractMainControl; -import net.sf.gridarta.gameobject.scripts.PathButtonListener; import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeNameException; -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeTypeException; -import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; -import net.sf.japi.swing.ActionFactory; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; @@ -52,25 +33,9 @@ /** The Logger for printing log messages. */ private static final Logger log = Logger.getLogger(ScriptedEvent.class); - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - /** The underlying game object that represents the event. */ private final GameObject event; - private static JTextField inputScriptPath; - - private static JTextField inputPluginName; - - private static JTextField inputOptions; - - private static PathButtonListener cancelListener; - - private static PathButtonListener okListener; - - // popup frame to edit script paths: - private static JDialog pathFrame; - /** * Create a ScriptedEvent of given type (This is used for map-loading). * @param event GameObject that describes the event. @@ -88,7 +53,7 @@ * @throws UndefinedEventArchetypeException In case there is no Archetype to create a ScriptedEvent. */ ScriptedEvent(final int eventType, final String pluginName, final String scriptPath, final String options) throws UndefinedEventArchetypeException { - event = newEventGameObject(eventType); + event = ScriptedEventEditor.newEventGameObject(eventType); setEventData(pluginName, scriptPath, options); } @@ -120,115 +85,11 @@ return true; } - /** - * Opens the script pad to display a script. - * @param scriptPath the script path - */ - public static void openScript(final String scriptPath) { - // trying to get the absolute path to scriptfile: - final StringBuilder tmpPath = new StringBuilder(); - if (scriptPath.startsWith("/")) { - // filepath is absolue (to map base directory): - tmpPath.append(AbstractMainControl.getInstance().getMapDefaultFolder()); - tmpPath.append(scriptPath); - } else { - // file path is relative to map dir - final String mapPath = AbstractMainControl.getInstance().getLocalMapDir().getAbsolutePath(); - tmpPath.append(mapPath); - if (!mapPath.endsWith("/")) { - tmpPath.append('/'); - } - tmpPath.append(scriptPath); - } - final String path = tmpPath.toString().replace('\\', '/'); - - // now see if that file really exists: - final File scriptFile = new File(path); - if (scriptFile.exists() && scriptFile.isFile()) { - ScriptEditControl.getInstance().openScriptFile(scriptFile.getAbsolutePath()); - } else { - // file does not exist! - ACTION_FACTORY.showMessageDialog(AbstractMainControl.getInstance().getMainView(), "openScriptNotFound", path); - } - } - - /** - * Edit path and plugin name for an event. A popup dialog is shown - * with input text fields for file path and plugin name. - * @param scriptedEvent the event - */ - public static void editParameters(final ScriptedEvent scriptedEvent) { - if (pathFrame == null) { - // initialize popup frame - pathFrame = new JDialog(AbstractMainControl.getInstance().getMainView(), "Edit Parameters", true); - pathFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); - - final JPanel mainPanel = new JPanel(); - mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); - mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); - - // input line: script path - final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JLabel text1 = new JLabel("Script:"); - line1.add(text1); - inputScriptPath = new JTextField(scriptedEvent.getScriptPath(), 20); - line1.add(inputScriptPath); - mainPanel.add(line1); - - // input line: plugin options - final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JLabel text2 = new JLabel("Script options:"); - line2.add(text2); - inputOptions = new JTextField(scriptedEvent.getOptions(), 20); - line2.add(inputOptions); - mainPanel.add(line2); - mainPanel.add(Box.createVerticalStrut(5)); - - // input line: plugin name - final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JLabel text3 = new JLabel("Plugin name:"); - line3.add(text3); - inputPluginName = new JTextField(scriptedEvent.getPluginName(), 20); - line3.add(inputPluginName); - mainPanel.add(line3); - mainPanel.add(Box.createVerticalStrut(5)); - - // button panel: - final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JButton okButton = new JButton("OK"); - okListener = new PathButtonListener(true, pathFrame, null); - okListener.setTargetEvent(scriptedEvent); - okButton.addActionListener(okListener); - line4.add(okButton); - - final JButton cancelButton = new JButton("Cancel"); - cancelListener = new PathButtonListener(false, pathFrame, null); - cancelListener.setTargetEvent(scriptedEvent); - cancelButton.addActionListener(cancelListener); - line4.add(cancelButton); - mainPanel.add(line4); - - pathFrame.getContentPane().add(mainPanel); - pathFrame.pack(); - pathFrame.setLocationRelativeTo(AbstractMainControl.getInstance().getMainView()); - pathFrame.setVisible(true); - } else { - // just set fields and show - okListener.setTargetEvent(scriptedEvent); - cancelListener.setTargetEvent(scriptedEvent); - inputScriptPath.setText(scriptedEvent.getScriptPath()); - inputPluginName.setText(scriptedEvent.getPluginName()); - inputOptions.setText(scriptedEvent.getOptions()); - pathFrame.toFront(); - pathFrame.setVisible(true); - } - } - /** {@inheritDoc} */ public void modifyEventPath() { - final String newPath = inputScriptPath.getText().trim(); - final String newPluginName = inputPluginName.getText().trim(); - final String newOptions = inputOptions.getText().trim(); + final String newPath = ScriptedEventEditor.inputScriptPath.getText().trim(); + final String newPluginName = ScriptedEventEditor.inputPluginName.getText().trim(); + final String newOptions = ScriptedEventEditor.inputOptions.getText().trim(); if (newPath.length() > 0) { setScriptPath(newPath); @@ -296,28 +157,4 @@ } } - /** - * Return a new event game object for a given event type. - * - * @param eventType the event type - * - * @return the new event game object - * - * @throws UndefinedEventArchetypeException if the event game object cannot - * be created - */ - private static GameObject newEventGameObject(final int eventType) throws UndefinedEventArchetypeException { - final String typeArchName = ScriptArchUtils.typeArchName(eventType); - if (typeArchName == null) { - throw new UndefinedEventArchetypeTypeException(eventType); - } - final Archetype eventArch = CMainControl.getInstance().getArchetypeSet().getArchetype(typeArchName); - if (eventArch == null) { - throw new UndefinedEventArchetypeNameException(typeArchName); - } - final GameObject event = eventArch.createArch(); - CMainControl.getInstance().getArchetypeParser().postParseGameObject(event, 0); - return event; - } - } // class ScriptedEvent Added: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEventEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEventEditor.java (rev 0) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEventEditor.java 2008-05-03 14:51:10 UTC (rev 3954) @@ -0,0 +1,193 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package cfeditor.gameobject.scripts; + +import cfeditor.CMainControl; +import cfeditor.gameobject.Archetype; +import cfeditor.gameobject.GameObject; +import java.awt.FlowLayout; +import java.io.File; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.WindowConstants; +import net.sf.gridarta.AbstractMainControl; +import net.sf.gridarta.gameobject.scripts.PathButtonListener; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeNameException; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeTypeException; +import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; +import net.sf.japi.swing.ActionFactory; +import org.apache.log4j.Logger; + +public class ScriptedEventEditor { + + /** The Logger for printing log messages. */ + private static final Logger log = Logger.getLogger(ScriptedEventEditor.class); + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); + + public static JTextField inputScriptPath; + + public static JTextField inputPluginName; + + public static JTextField inputOptions; + + private static PathButtonListener cancelListener; + + private static PathButtonListener okListener; + + // popup frame to edit script paths: + private static JDialog pathFrame; + + /** + * Opens the script pad to display a script. + * @param scriptPath the script path + */ + public static void openScript(final String scriptPath) { + // trying to get the absolute path to scriptfile: + final StringBuilder tmpPath = new StringBuilder(); + if (scriptPath.startsWith("/")) { + // filepath is absolue (to map base directory): + tmpPath.append(AbstractMainControl.getInstance().getMapDefaultFolder()); + tmpPath.append(scriptPath); + } else { + // file path is relative to map dir + final String mapPath = AbstractMainControl.getInstance().getLocalMapDir().getAbsolutePath(); + tmpPath.append(mapPath); + if (!mapPath.endsWith("/")) { + tmpPath.append('/'); + } + tmpPath.append(scriptPath); + } + final String path = tmpPath.toString().replace('\\', '/'); + + // now see if that file really exists: + final File scriptFile = new File(path); + if (scriptFile.exists() && scriptFile.isFile()) { + ScriptEditControl.getInstance().openScriptFile(scriptFile.getAbsolutePath()); + } else { + // file does not exist! + ACTION_FACTORY.showMessageDialog(AbstractMainControl.getInstance().getMainView(), "openScriptNotFound", path); + } + } + + /** + * Edit path and plugin name for an event. A popup dialog is shown + * with input text fields for file path and plugin name. + * @param scriptedEvent the event + */ + public static void editParameters(final ScriptedEvent scriptedEvent) { + if (pathFrame == null) { + // initialize popup frame + pathFrame = new JDialog(AbstractMainControl.getInstance().getMainView(), "Edit Parameters", true); + pathFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); + + final JPanel mainPanel = new JPanel(); + mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); + mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); + + // input line: script path + final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JLabel text1 = new JLabel("Script:"); + line1.add(text1); + inputScriptPath = new JTextField(scriptedEvent.getScriptPath(), 20); + line1.add(inputScriptPath); + mainPanel.add(line1); + + // input line: plugin options + final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JLabel text2 = new JLabel("Script options:"); + line2.add(text2); + inputOptions = new JTextField(scriptedEvent.getOptions(), 20); + line2.add(inputOptions); + mainPanel.add(line2); + mainPanel.add(Box.createVerticalStrut(5)); + + // input line: plugin name + final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JLabel text3 = new JLabel("Plugin name:"); + line3.add(text3); + inputPluginName = new JTextField(scriptedEvent.getPluginName(), 20); + line3.add(inputPluginName); + mainPanel.add(line3); + mainPanel.add(Box.createVerticalStrut(5)); + + // button panel: + final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JButton okButton = new JButton("OK"); + okListener = new PathButtonListener(true, pathFrame, null); + okListener.setTargetEvent(scriptedEvent); + okButton.addActionListener(okListener); + line4.add(okButton); + + final JButton cancelButton = new JButton("Cancel"); + cancelListener = new PathButtonListener(false, pathFrame, null); + cancelListener.setTargetEvent(scriptedEvent); + cancelButton.addActionListener(cancelListener); + line4.add(cancelButton); + mainPanel.add(line4); + + pathFrame.getContentPane().add(mainPanel); + pathFrame.pack(); + pathFrame.setLocationRelativeTo(AbstractMainControl.getInstance().getMainView()); + pathFrame.setVisible(true); + } else { + // just set fields and show + okListener.setTargetEvent(scriptedEvent); + cancelListener.setTargetEvent(scriptedEvent); + inputScriptPath.setText(scriptedEvent.getScriptPath()); + inputPluginName.setText(scriptedEvent.getPluginName()); + inputOptions.setText(scriptedEvent.getOptions()); + pathFrame.toFront(); + pathFrame.setVisible(true); + } + } + + /** + * Return a new event game object for a given event type. + * + * @param eventType the event type + * + * @return the new event game object + * + * @throws net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException if the event game object cannot + * be created + */ + static GameObject newEventGameObject(final int eventType) throws UndefinedEventArchetypeException { + final String typeArchName = ScriptArchUtils.typeArchName(eventType); + if (typeArchName == null) { + throw new UndefinedEventArchetypeTypeException(eventType); + } + final Archetype eventArch = CMainControl.getInstance().getArchetypeSet().getArchetype(typeArchName); + if (eventArch == null) { + throw new UndefinedEventArchetypeNameException(typeArchName); + } + final GameObject event = eventArch.createArch(); + CMainControl.getInstance().getArchetypeParser().postParseGameObject(event, 0); + return event; + } +} // class ScriptedEventEditor Property changes on: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEventEditor.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 12:50:45 UTC (rev 3953) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 14:51:10 UTC (rev 3954) @@ -138,9 +138,9 @@ final ScriptedEvent event = new ScriptedEvent(oldEvent); // now decide what to do: if (task == GameObjectAttributesPanel.SCRIPT_OPEN) { - ScriptedEvent.openScript(event.getScriptPath()); + ScriptedEventEditor.openScript(event.getScriptPath()); } else if (task == GameObjectAttributesPanel.SCRIPT_EDIT_PATH) { - ScriptedEvent.editParameters(event); + ScriptedEventEditor.editParameters(event); } else if (task == GameObjectAttributesPanel.SCRIPT_REMOVE) { // first ask for confirmation if (JOptionPane.showConfirmDialog(panelList, "Are you sure you want to remove this \"" + ScriptArchUtils.typeName(event.getEventType()) + "\" event which is\n" + "linked to the script: '" + event.getScriptPath() + "'?\n" + "(The script file itself is not going to be deleted)", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 12:50:45 UTC (rev 3953) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 14:51:10 UTC (rev 3954) @@ -19,27 +19,8 @@ package daieditor.gameobject.scripts; -import daieditor.CMainControl; -import daieditor.gameobject.Archetype; import daieditor.gameobject.GameObject; -import java.awt.FlowLayout; -import java.io.File; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.WindowConstants; -import net.sf.gridarta.AbstractMainControl; -import net.sf.gridarta.gameobject.scripts.PathButtonListener; import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeNameException; -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeTypeException; -import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; -import net.sf.japi.swing.ActionFactory; import org.apache.log4j.Logger; /** @@ -51,25 +32,9 @@ /** The Logger for printing log messages. */ private static final Logger log = Logger.getLogger(ScriptedEvent.class); - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); - /** The underlying game object that represents the event. */ private final GameObject event; - private static JTextField inputScriptPath; - - private static JTextField inputPluginName; - - private static JTextField inputOptions; - - private static PathButtonListener cancelListener; - - private static PathButtonListener okListener; - - // popup frame to edit script paths: - private static JDialog pathFrame; - /** * Create a ScriptedEvent of given type (This is used for map-loading). * @param event GameObject that describes the event. @@ -87,7 +52,7 @@ * @throws UndefinedEventArchetypeException In case there is no Archetype to create a ScriptedEvent. */ ScriptedEvent(final int eventType, final String pluginName, final String scriptPath, final String options) throws UndefinedEventArchetypeException { - event = newEventGameObject(eventType); + event = ScriptedEventEditor.newEventGameObject(eventType); setEventData(pluginName, scriptPath, options); } @@ -119,115 +84,11 @@ return true; } - /** - * Opens the script pad to display a script. - * @param scriptPath the script path - */ - public static void openScript(final String scriptPath) { - // trying to get the absolute path to scriptfile: - final StringBuilder tmpPath = new StringBuilder(); - if (scriptPath.startsWith("/")) { - // filepath is absolue (to map base directory): - tmpPath.append(AbstractMainControl.getInstance().getMapDefaultFolder()); - tmpPath.append(scriptPath); - } else { - // file path is relative to map dir - final String mapPath = AbstractMainControl.getInstance().getLocalMapDir().getAbsolutePath(); - tmpPath.append(mapPath); - if (!mapPath.endsWith("/")) { - tmpPath.append('/'); - } - tmpPath.append(scriptPath); - } - final String path = tmpPath.toString().replace('\\', '/'); - - // now see if that file really exists: - final File scriptFile = new File(path); - if (scriptFile.exists() && scriptFile.isFile()) { - ScriptEditControl.getInstance().openScriptFile(scriptFile.getAbsolutePath()); - } else { - // file does not exist! - ACTION_FACTORY.showMessageDialog(AbstractMainControl.getInstance().getMainView(), "openScriptNotFound", path); - } - } - - /** - * Edit path and plugin name for an event. A popup dialog is shown - * with input text fields for file path and plugin name. - * @param scriptedEvent the event - */ - public static void editParameters(final ScriptedEvent scriptedEvent) { - if (pathFrame == null) { - // initialize popup frame - pathFrame = new JDialog(AbstractMainControl.getInstance().getMainView(), "Edit Parameters", true); - pathFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); - - final JPanel mainPanel = new JPanel(); - mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); - mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); - - // input line: script path - final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JLabel text1 = new JLabel("Script:"); - line1.add(text1); - inputScriptPath = new JTextField(scriptedEvent.getScriptPath(), 20); - line1.add(inputScriptPath); - mainPanel.add(line1); - - // input line: plugin options - final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JLabel text2 = new JLabel("Script options:"); - line2.add(text2); - inputOptions = new JTextField(scriptedEvent.getOptions(), 20); - line2.add(inputOptions); - mainPanel.add(line2); - mainPanel.add(Box.createVerticalStrut(5)); - - // input line: plugin name - final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JLabel text3 = new JLabel("Plugin name:"); - line3.add(text3); - inputPluginName = new JTextField(scriptedEvent.getPluginName(), 20); - line3.add(inputPluginName); - mainPanel.add(line3); - mainPanel.add(Box.createVerticalStrut(5)); - - // button panel: - final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JButton okButton = new JButton("OK"); - okListener = new PathButtonListener(true, pathFrame, null); - okListener.setTargetEvent(scriptedEvent); - okButton.addActionListener(okListener); - line4.add(okButton); - - final JButton cancelButton = new JButton("Cancel"); - cancelListener = new PathButtonListener(false, pathFrame, null); - cancelListener.setTargetEvent(scriptedEvent); - cancelButton.addActionListener(cancelListener); - line4.add(cancelButton); - mainPanel.add(line4); - - pathFrame.getContentPane().add(mainPanel); - pathFrame.pack(); - pathFrame.setLocationRelativeTo(AbstractMainControl.getInstance().getMainView()); - pathFrame.setVisible(true); - } else { - // just set fields and show - okListener.setTargetEvent(scriptedEvent); - cancelListener.setTargetEvent(scriptedEvent); - inputScriptPath.setText(scriptedEvent.getScriptPath()); - inputPluginName.setText(scriptedEvent.getPluginName()); - inputOptions.setText(scriptedEvent.getOptions()); - pathFrame.toFront(); - pathFrame.setVisible(true); - } - } - /** {@inheritDoc} */ public void modifyEventPath() { - final String newPath = inputScriptPath.getText().trim(); - final String newPluginName = inputPluginName.getText().trim(); - final String newOptions = inputOptions.getText().trim(); + final String newPath = ScriptedEventEditor.inputScriptPath.getText().trim(); + final String newPluginName = ScriptedEventEditor.inputPluginName.getText().trim(); + final String newOptions = ScriptedEventEditor.inputOptions.getText().trim(); if (newPath.length() > 0) { setScriptPath(newPath); @@ -292,29 +153,4 @@ } } - /** - * Return a new event game object for a given event type. - * - * @param eventType the event type - * - * @return the new event game object - * - * @throws UndefinedEventArchetypeException if the event game object cannot - * be created - */ - private static GameObject newEventGameObject(final int eventType) throws UndefinedEventArchetypeException { - final String typeArchName = ScriptArchUtils.typeArchName(eventType); - if (typeArchName == null) { - throw new UndefinedEventArchetypeTypeException(eventType); - } - final Archetype eventArch = CMainControl.getInstance().getArchetypeSet().getArchetype(typeArchName); - if (eventArch == null) { - throw new UndefinedEventArchetypeNameException(typeArchName); - } - final GameObject event = eventArch.createArch(); - event.addObjectText("sub_type " + eventType); - CMainControl.getInstance().getArchetypeParser().postParseGameObject(event, 0); - return event; - } - } // class ScriptedEvent Added: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEventEditor.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEventEditor.java (rev 0) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEventEditor.java 2008-05-03 14:51:10 UTC (rev 3954) @@ -0,0 +1,195 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package daieditor.gameobject.scripts; + +import daieditor.CMainControl; +import daieditor.gameobject.Archetype; +import daieditor.gameobject.GameObject; +import java.awt.FlowLayout; +import java.io.File; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.WindowConstants; +import net.sf.gridarta.AbstractMainControl; +import net.sf.gridarta.gameobject.scripts.PathButtonListener; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeNameException; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeTypeException; +import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; +import net.sf.japi.swing.ActionFactory; +import org.apache.log4j.Logger; + +public class ScriptedEventEditor { + + /** The Logger for printing log messages. */ + private static final Logger log = Logger.getLogger(ScriptedEventEditor.class); + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); + + public static JTextField inputScriptPath; + + public static JTextField inputPluginName; + + public static JTextField inputOptions; + + private static PathButtonListener cancelListener; + + private static PathButtonListener okListener; + + // popup frame to edit script paths: + private static JDialog pathFrame; + + /** + * Opens the script pad to display a script. + * @param scriptPath the script path + */ + public static void openScript(final String scriptPath) { + // trying to get the absolute path to scriptfile: + final StringBuilder tmpPath = new StringBuilder(); + if (scriptPath.startsWith("/")) { + // filepath is absolue (to map base directory): + tmpPath.append(AbstractMainControl.getInstance().getMapDefaultFolder()); + tmpPath.append(scriptPath); + } else { + // file path is relative to map dir + final String mapPath = AbstractMainControl.getInstance().getLocalMapDir().getAbsolutePath(); + tmpPath.append(mapPath); + if (!mapPath.endsWith("/")) { + tmpPath.append('/'); + } + tmpPath.append(scriptPath); + } + final String path = tmpPath.toString().replace('\\', '/'); + + // now see if that file really exists: + final File scriptFile = new File(path); + if (scriptFile.exists() && scriptFile.isFile()) { + ScriptEditControl.getInstance().openScriptFile(scriptFile.getAbsolutePath()); + } else { + // file does not exist! + ACTION_FACTORY.showMessageDialog(AbstractMainControl.getInstance().getMainView(), "openScriptNotFound", path); + } + } + + /** + * Edit path and plugin name for an event. A popup dialog is shown + * with input text fields for file path and plugin name. + * @param scriptedEvent the event + */ + public static void editParameters(final ScriptedEvent scriptedEvent) { + if (pathFrame == null) { + // initialize popup frame + pathFrame = new JDialog(AbstractMainControl.getInstance().getMainView(), "Edit Parameters", true); + pathFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); + + final JPanel mainPanel = new JPanel(); + mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); + mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); + + // input line: script path + final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JLabel text1 = new JLabel("Script:"); + line1.add(text1); + inputScriptPath = new JTextField(scriptedEvent.getScriptPath(), 20); + line1.add(inputScriptPath); + mainPanel.add(line1); + + // input line: plugin options + final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JLabel text2 = new JLabel("Script options:"); + line2.add(text2); + inputOptions = new JTextField(scriptedEvent.getOptions(), 20); + line2.add(inputOptions); + mainPanel.add(line2); + mainPanel.add(Box.createVerticalStrut(5)); + + // input line: plugin name + final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JLabel text3 = new JLabel("Plugin name:"); + line3.add(text3); + inputPluginName = new JTextField(scriptedEvent.getPluginName(), 20); + line3.add(inputPluginName); + mainPanel.add(line3); + mainPanel.add(Box.createVerticalStrut(5)); + + // button panel: + final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JButton okButton = new JButton("OK"); + okListener = new PathButtonListener(true, pathFrame, null); + okListener.setTargetEvent(scriptedEvent); + okButton.addActionListener(okListener); + line4.add(okButton); + + final JButton cancelButton = new JButton("Cancel"); + cancelListener = new PathButtonListener(false, pathFrame, null); + cancelListener.setTargetEvent(scriptedEvent); + cancelButton.addActionListener(cancelListener); + line4.add(cancelButton); + mainPanel.add(line4); + + pathFrame.getContentPane().add(mainPanel); + pathFrame.pack(); + pathFrame.setLocationRelativeTo(AbstractMainControl.getInstance().getMainView()); + pathFrame.setVisible(true); + } else { + // just set fields and show + okListener.setTargetEvent(scriptedEvent); + cancelListener.setTargetEvent(scriptedEvent); + inputScriptPath.setText(scriptedEvent.getScriptPath()); + inputPluginName.setText(scriptedEvent.getPluginName()); + inputOptions.setText(scriptedEvent.getOptions()); + pathFrame.toFront(); + pathFrame.setVisible(true); + } + } + + /** + * Return a new event game object for a given event type. + * + * @param eventType the event type + * + * @return the new event game object + * + * @throws net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException if the event game object cannot + * be created + */ + public static GameObject newEventGameObject(final int eventType) throws UndefinedEventArchetypeException { + final String typeArchName = ScriptArchUtils.typeArchName(eventType); + if (typeArchName == null) { + throw new UndefinedEventArchetypeTypeException(eventType); + } + final Archetype eventArch = CMainControl.getInstance().getArchetypeSet().getArchetype(typeArchName); + if (eventArch == null) { + throw new UndefinedEventArchetypeNameException(typeArchName); + } + final GameObject event = eventArch.createArch(); + event.addObjectText("sub_type " + eventType); + CMainControl.getInstance().getArchetypeParser().postParseGameObject(event, 0); + return event; + } + +} // class ScriptedEventEditor Property changes on: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEventEditor.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-03 15:12:39
|
Revision: 3956 http://gridarta.svn.sourceforge.net/gridarta/?rev=3956&view=rev Author: akirschbaum Date: 2008-05-03 08:12:24 -0700 (Sat, 03 May 2008) Log Message: ----------- Rename Archetype.createArch() into createGameObject(). Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEventEditor.java trunk/daimonin/src/daieditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEventEditor.java trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeParser.java trunk/src/app/net/sf/gridarta/gameobject/Archetype.java trunk/src/app/net/sf/gridarta/gameobject/ArchetypeSet.java trunk/src/app/net/sf/gridarta/gameobject/GameObject.java trunk/src/app/net/sf/gridarta/gui/GameObjectAttributesPanel.java trunk/src/app/net/sf/gridarta/map/DefaultMapModel.java trunk/src/app/net/sf/gridarta/spells/GameObjectSpell.java Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2008-05-03 15:00:09 UTC (rev 3955) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2008-05-03 15:12:24 UTC (rev 3956) @@ -218,9 +218,9 @@ } /** {@inheritDoc} */ - @NotNull @Override public GameObject createArch() { + @NotNull @Override public GameObject createGameObject() { if (!isArchetype()) { - return getArchetype().createArch(); + return getArchetype().createGameObject(); } final GameObject arch = new GameObject(); arch.setArchetypeName(archetypeName); Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEventEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEventEditor.java 2008-05-03 15:00:09 UTC (rev 3955) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEventEditor.java 2008-05-03 15:12:24 UTC (rev 3956) @@ -186,7 +186,7 @@ if (eventArch == null) { throw new UndefinedEventArchetypeNameException(typeArchName); } - final GameObject event = eventArch.createArch(); + final GameObject event = eventArch.createGameObject(); CMainControl.getInstance().getArchetypeParser().postParseGameObject(event, 0); return event; } Modified: trunk/daimonin/src/daieditor/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObject.java 2008-05-03 15:00:09 UTC (rev 3955) +++ trunk/daimonin/src/daieditor/gameobject/GameObject.java 2008-05-03 15:12:24 UTC (rev 3956) @@ -387,9 +387,9 @@ } /** {@inheritDoc} */ - @NotNull @Override public GameObject createArch() { + @NotNull @Override public GameObject createGameObject() { if (!isArchetype()) { - return getArchetype().createArch(); + return getArchetype().createGameObject(); } final GameObject arch = new GameObject(); arch.setArchetypeName(archetypeName); Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEventEditor.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEventEditor.java 2008-05-03 15:00:09 UTC (rev 3955) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEventEditor.java 2008-05-03 15:12:24 UTC (rev 3956) @@ -186,7 +186,7 @@ if (eventArch == null) { throw new UndefinedEventArchetypeNameException(typeArchName); } - final GameObject event = eventArch.createArch(); + final GameObject event = eventArch.createGameObject(); event.addObjectText("sub_type " + eventType); CMainControl.getInstance().getArchetypeParser().postParseGameObject(event, 0); return event; Modified: trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeParser.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeParser.java 2008-05-03 15:00:09 UTC (rev 3955) +++ trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeParser.java 2008-05-03 15:12:24 UTC (rev 3956) @@ -133,7 +133,7 @@ // do insertion for all non-head parts of the multi for (G oldPart = archetype.getMultiNext(); oldPart != null; oldPart = oldPart.getMultiNext()) { - final G newarch = oldPart.createArch(); + final G newarch = oldPart.createGameObject(); gameObject.addTailPart(newarch); objects.add(newarch); Modified: trunk/src/app/net/sf/gridarta/gameobject/Archetype.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/Archetype.java 2008-05-03 15:00:09 UTC (rev 3955) +++ trunk/src/app/net/sf/gridarta/gameobject/Archetype.java 2008-05-03 15:12:24 UTC (rev 3956) @@ -39,7 +39,7 @@ * Create a new GameObject from this Archetype. * @return New GameObject based on this Archetype. */ - G createArch(); + G createGameObject(); /** * Get the name of this Archetype. Modified: trunk/src/app/net/sf/gridarta/gameobject/ArchetypeSet.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/ArchetypeSet.java 2008-05-03 15:00:09 UTC (rev 3955) +++ trunk/src/app/net/sf/gridarta/gameobject/ArchetypeSet.java 2008-05-03 15:12:24 UTC (rev 3956) @@ -53,7 +53,7 @@ * Get an Archetype by its name. * @param archetypeName name of the Archetype to get * @return Archetype for <var>archetypeName</var> or <code>null</code> if no such Archetype - * @see GameObject#createArch() for a similar method that instantiates. + * @see GameObject#createGameObject() for a similar method that instantiates. * @see #getOrCreateArchetype(String) for a similar method that creates undefined archetypes */ @Nullable R getArchetype(@NotNull String archetypeName); Modified: trunk/src/app/net/sf/gridarta/gameobject/GameObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2008-05-03 15:00:09 UTC (rev 3955) +++ trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2008-05-03 15:12:24 UTC (rev 3956) @@ -904,7 +904,7 @@ * The newly created GameObject will be based on the Archetype only. * @return new GameObject */ - public abstract G createArch(); + public abstract G createGameObject(); /** * Returns whether this object is a single-part object or the head of the multi-part object. Modified: trunk/src/app/net/sf/gridarta/gui/GameObjectAttributesPanel.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/GameObjectAttributesPanel.java 2008-05-03 15:00:09 UTC (rev 3955) +++ trunk/src/app/net/sf/gridarta/gui/GameObjectAttributesPanel.java 2008-05-03 15:12:24 UTC (rev 3956) @@ -688,7 +688,7 @@ final G invnew; if (arch.isArchetype()) { // create a new copy of a default arch - invnew = arch.createArch(); + invnew = arch.createGameObject(); } else { // create clone from a pickmap invnew = arch.createClone(0, 0); Modified: trunk/src/app/net/sf/gridarta/map/DefaultMapModel.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/DefaultMapModel.java 2008-05-03 15:00:09 UTC (rev 3955) +++ trunk/src/app/net/sf/gridarta/map/DefaultMapModel.java 2008-05-03 15:12:24 UTC (rev 3956) @@ -644,7 +644,7 @@ } else { // insert the new arch into the inventory of a map arch if (newObject.isArchetype()) { - newGameObject = newObject.createArch(); + newGameObject = newObject.createGameObject(); } else { // create clone from a pickmap if (!newObject.isMulti()) { @@ -690,7 +690,7 @@ G head = null; for (R archetypePart = archetype; archetypePart != null; archetypePart = (R) archetypePart.getMultiNext()) { - final G part = archetypePart.createArch(); + final G part = archetypePart.createGameObject(); if (archetypePart == archetype) { head = part; } else { Modified: trunk/src/app/net/sf/gridarta/spells/GameObjectSpell.java =================================================================== --- trunk/src/app/net/sf/gridarta/spells/GameObjectSpell.java 2008-05-03 15:00:09 UTC (rev 3955) +++ trunk/src/app/net/sf/gridarta/spells/GameObjectSpell.java 2008-05-03 15:12:24 UTC (rev 3956) @@ -52,7 +52,7 @@ * @return The copy of the game object. */ @NotNull public G createGameObject() { - return archetype.createArch(); + return archetype.createGameObject(); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-03 15:18:12
|
Revision: 3957 http://gridarta.svn.sourceforge.net/gridarta/?rev=3957&view=rev Author: akirschbaum Date: 2008-05-03 08:18:15 -0700 (Sat, 03 May 2008) Log Message: ----------- Rename variables and methods. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchUtils.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEventEditor.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchUtils.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEventEditor.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-05-03 15:12:24 UTC (rev 3956) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-05-03 15:18:15 UTC (rev 3957) @@ -985,7 +985,7 @@ private List<?> getEventTypes() { final List<Object> result = new ArrayList<Object>(); - for (int typeNumber = 1; ScriptArchUtils.typeArchName(typeNumber) != null; typeNumber++) { + for (int typeNumber = 1; ScriptArchUtils.getArchetypeNameForEventType(typeNumber) != null; typeNumber++) { result.add(typeNumber); result.add(ScriptArchUtils.typeName(typeNumber)); } Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchUtils.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchUtils.java 2008-05-03 15:12:24 UTC (rev 3956) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchUtils.java 2008-05-03 15:18:15 UTC (rev 3957) @@ -65,7 +65,7 @@ * @return the archetype name, or <code>null</code> if the event type is * invalid */ - @Nullable public static String typeArchName(final int eventType) { + @Nullable public static String getArchetypeNameForEventType(final int eventType) { if (eventType > 0 && eventType <= allEventTypes.length) { return "event_" + allEventTypes[eventType - 1]; } else { Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEventEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEventEditor.java 2008-05-03 15:12:24 UTC (rev 3956) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEventEditor.java 2008-05-03 15:18:15 UTC (rev 3957) @@ -178,15 +178,15 @@ * be created */ public static GameObject newEventGameObject(final int eventType) throws UndefinedEventArchetypeException { - final String typeArchName = ScriptArchUtils.typeArchName(eventType); - if (typeArchName == null) { + final String eventArchetypeName = ScriptArchUtils.getArchetypeNameForEventType(eventType); + if (eventArchetypeName == null) { throw new UndefinedEventArchetypeTypeException(eventType); } - final Archetype eventArch = CMainControl.getInstance().getArchetypeSet().getArchetype(typeArchName); - if (eventArch == null) { - throw new UndefinedEventArchetypeNameException(typeArchName); + final Archetype eventArchetype = CMainControl.getInstance().getArchetypeSet().getArchetype(eventArchetypeName); + if (eventArchetype == null) { + throw new UndefinedEventArchetypeNameException(eventArchetypeName); } - final GameObject event = eventArch.createGameObject(); + final GameObject event = eventArchetype.createGameObject(); CMainControl.getInstance().getArchetypeParser().postParseGameObject(event, 0); return event; } Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchUtils.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchUtils.java 2008-05-03 15:12:24 UTC (rev 3956) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchUtils.java 2008-05-03 15:18:15 UTC (rev 3957) @@ -65,7 +65,7 @@ * @return the archetype name, or <code>null</code> if the event type is * invalid */ - @Nullable public static String typeArchName(final int eventType) { + @Nullable public static String getArchetypeNameForEventType(final int eventType) { return "event_obj"; } Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEventEditor.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEventEditor.java 2008-05-03 15:12:24 UTC (rev 3956) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEventEditor.java 2008-05-03 15:18:15 UTC (rev 3957) @@ -178,15 +178,15 @@ * be created */ public static GameObject newEventGameObject(final int eventType) throws UndefinedEventArchetypeException { - final String typeArchName = ScriptArchUtils.typeArchName(eventType); - if (typeArchName == null) { + final String eventArchetypeName = ScriptArchUtils.getArchetypeNameForEventType(eventType); + if (eventArchetypeName == null) { throw new UndefinedEventArchetypeTypeException(eventType); } - final Archetype eventArch = CMainControl.getInstance().getArchetypeSet().getArchetype(typeArchName); - if (eventArch == null) { - throw new UndefinedEventArchetypeNameException(typeArchName); + final Archetype eventArchetype = CMainControl.getInstance().getArchetypeSet().getArchetype(eventArchetypeName); + if (eventArchetype == null) { + throw new UndefinedEventArchetypeNameException(eventArchetypeName); } - final GameObject event = eventArch.createGameObject(); + final GameObject event = eventArchetype.createGameObject(); event.addObjectText("sub_type " + eventType); CMainControl.getInstance().getArchetypeParser().postParseGameObject(event, 0); return event; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-03 15:27:00
|
Revision: 3958 http://gridarta.svn.sourceforge.net/gridarta/?rev=3958&view=rev Author: akirschbaum Date: 2008-05-03 08:27:01 -0700 (Sat, 03 May 2008) Log Message: ----------- Move ScriptedEventEditor.newEventGameObject() to ScriptedEvent Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEventEditor.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEventEditor.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 15:18:15 UTC (rev 3957) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 15:27:01 UTC (rev 3958) @@ -19,8 +19,12 @@ package cfeditor.gameobject.scripts; +import cfeditor.CMainControl; +import cfeditor.gameobject.Archetype; import cfeditor.gameobject.GameObject; import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeNameException; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeTypeException; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; @@ -53,7 +57,7 @@ * @throws UndefinedEventArchetypeException In case there is no Archetype to create a ScriptedEvent. */ ScriptedEvent(final int eventType, final String pluginName, final String scriptPath, final String options) throws UndefinedEventArchetypeException { - event = ScriptedEventEditor.newEventGameObject(eventType); + event = newEventGameObject(eventType); setEventData(pluginName, scriptPath, options); } @@ -157,4 +161,28 @@ } } + /** + * Return a new event game object for a given event type. + * + * @param eventType the event type + * + * @return the new event game object + * + * @throws net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException if the event game object cannot + * be created + */ + private static GameObject newEventGameObject(final int eventType) throws UndefinedEventArchetypeException { + final String eventArchetypeName = ScriptArchUtils.getArchetypeNameForEventType(eventType); + if (eventArchetypeName == null) { + throw new UndefinedEventArchetypeTypeException(eventType); + } + final Archetype eventArchetype = CMainControl.getInstance().getArchetypeSet().getArchetype(eventArchetypeName); + if (eventArchetype == null) { + throw new UndefinedEventArchetypeNameException(eventArchetypeName); + } + final GameObject event = eventArchetype.createGameObject(); + CMainControl.getInstance().getArchetypeParser().postParseGameObject(event, 0); + return event; + } + } // class ScriptedEvent Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEventEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEventEditor.java 2008-05-03 15:18:15 UTC (rev 3957) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEventEditor.java 2008-05-03 15:27:01 UTC (rev 3958) @@ -19,9 +19,6 @@ package cfeditor.gameobject.scripts; -import cfeditor.CMainControl; -import cfeditor.gameobject.Archetype; -import cfeditor.gameobject.GameObject; import java.awt.FlowLayout; import java.io.File; import javax.swing.BorderFactory; @@ -35,9 +32,6 @@ import javax.swing.WindowConstants; import net.sf.gridarta.AbstractMainControl; import net.sf.gridarta.gameobject.scripts.PathButtonListener; -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeNameException; -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeTypeException; import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; import net.sf.japi.swing.ActionFactory; import org.apache.log4j.Logger; @@ -167,28 +161,4 @@ } } - /** - * Return a new event game object for a given event type. - * - * @param eventType the event type - * - * @return the new event game object - * - * @throws net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException if the event game object cannot - * be created - */ - public static GameObject newEventGameObject(final int eventType) throws UndefinedEventArchetypeException { - final String eventArchetypeName = ScriptArchUtils.getArchetypeNameForEventType(eventType); - if (eventArchetypeName == null) { - throw new UndefinedEventArchetypeTypeException(eventType); - } - final Archetype eventArchetype = CMainControl.getInstance().getArchetypeSet().getArchetype(eventArchetypeName); - if (eventArchetype == null) { - throw new UndefinedEventArchetypeNameException(eventArchetypeName); - } - final GameObject event = eventArchetype.createGameObject(); - CMainControl.getInstance().getArchetypeParser().postParseGameObject(event, 0); - return event; - } - } // class ScriptedEventEditor Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 15:18:15 UTC (rev 3957) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 15:27:01 UTC (rev 3958) @@ -19,8 +19,12 @@ package daieditor.gameobject.scripts; +import daieditor.CMainControl; +import daieditor.gameobject.Archetype; import daieditor.gameobject.GameObject; import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeNameException; +import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeTypeException; import org.apache.log4j.Logger; /** @@ -52,7 +56,7 @@ * @throws UndefinedEventArchetypeException In case there is no Archetype to create a ScriptedEvent. */ ScriptedEvent(final int eventType, final String pluginName, final String scriptPath, final String options) throws UndefinedEventArchetypeException { - event = ScriptedEventEditor.newEventGameObject(eventType); + event = newEventGameObject(eventType); setEventData(pluginName, scriptPath, options); } @@ -153,4 +157,29 @@ } } + /** + * Return a new event game object for a given event type. + * + * @param eventType the event type + * + * @return the new event game object + * + * @throws net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException if the event game object cannot + * be created + */ + private static GameObject newEventGameObject(final int eventType) throws UndefinedEventArchetypeException { + final String eventArchetypeName = ScriptArchUtils.getArchetypeNameForEventType(eventType); + if (eventArchetypeName == null) { + throw new UndefinedEventArchetypeTypeException(eventType); + } + final Archetype eventArchetype = CMainControl.getInstance().getArchetypeSet().getArchetype(eventArchetypeName); + if (eventArchetype == null) { + throw new UndefinedEventArchetypeNameException(eventArchetypeName); + } + final GameObject event = eventArchetype.createGameObject(); + event.addObjectText("sub_type " + eventType); + CMainControl.getInstance().getArchetypeParser().postParseGameObject(event, 0); + return event; + } + } // class ScriptedEvent Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEventEditor.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEventEditor.java 2008-05-03 15:18:15 UTC (rev 3957) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEventEditor.java 2008-05-03 15:27:01 UTC (rev 3958) @@ -19,9 +19,6 @@ package daieditor.gameobject.scripts; -import daieditor.CMainControl; -import daieditor.gameobject.Archetype; -import daieditor.gameobject.GameObject; import java.awt.FlowLayout; import java.io.File; import javax.swing.BorderFactory; @@ -35,9 +32,6 @@ import javax.swing.WindowConstants; import net.sf.gridarta.AbstractMainControl; import net.sf.gridarta.gameobject.scripts.PathButtonListener; -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeNameException; -import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeTypeException; import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; import net.sf.japi.swing.ActionFactory; import org.apache.log4j.Logger; @@ -167,29 +161,4 @@ } } - /** - * Return a new event game object for a given event type. - * - * @param eventType the event type - * - * @return the new event game object - * - * @throws net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException if the event game object cannot - * be created - */ - public static GameObject newEventGameObject(final int eventType) throws UndefinedEventArchetypeException { - final String eventArchetypeName = ScriptArchUtils.getArchetypeNameForEventType(eventType); - if (eventArchetypeName == null) { - throw new UndefinedEventArchetypeTypeException(eventType); - } - final Archetype eventArchetype = CMainControl.getInstance().getArchetypeSet().getArchetype(eventArchetypeName); - if (eventArchetype == null) { - throw new UndefinedEventArchetypeNameException(eventArchetypeName); - } - final GameObject event = eventArchetype.createGameObject(); - event.addObjectText("sub_type " + eventType); - CMainControl.getInstance().getArchetypeParser().postParseGameObject(event, 0); - return event; - } - } // class ScriptedEventEditor This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-03 15:46:15
|
Revision: 3959 http://gridarta.svn.sourceforge.net/gridarta/?rev=3959&view=rev Author: akirschbaum Date: 2008-05-03 08:46:16 -0700 (Sat, 03 May 2008) Log Message: ----------- Move ScriptedEventEditor to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptedEvent.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptedEventEditor.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEventEditor.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEventEditor.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 15:27:01 UTC (rev 3958) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2008-05-03 15:46:16 UTC (rev 3959) @@ -27,6 +27,7 @@ import javax.swing.JDialog; import javax.swing.JList; import javax.swing.JOptionPane; +import net.sf.gridarta.gameobject.scripts.ScriptedEventEditor; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 15:27:01 UTC (rev 3958) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 15:46:16 UTC (rev 3959) @@ -22,6 +22,7 @@ import cfeditor.CMainControl; import cfeditor.gameobject.Archetype; import cfeditor.gameobject.GameObject; +import net.sf.gridarta.gameobject.scripts.ScriptedEventEditor; import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeNameException; import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeTypeException; Deleted: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEventEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEventEditor.java 2008-05-03 15:27:01 UTC (rev 3958) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEventEditor.java 2008-05-03 15:46:16 UTC (rev 3959) @@ -1,164 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package cfeditor.gameobject.scripts; - -import java.awt.FlowLayout; -import java.io.File; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.WindowConstants; -import net.sf.gridarta.AbstractMainControl; -import net.sf.gridarta.gameobject.scripts.PathButtonListener; -import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; -import net.sf.japi.swing.ActionFactory; -import org.apache.log4j.Logger; - -public class ScriptedEventEditor { - - /** The Logger for printing log messages. */ - private static final Logger log = Logger.getLogger(ScriptedEventEditor.class); - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - - public static JTextField inputScriptPath; - - public static JTextField inputPluginName; - - public static JTextField inputOptions; - - private static PathButtonListener cancelListener; - - private static PathButtonListener okListener; - - // popup frame to edit script paths: - private static JDialog pathFrame; - - /** - * Opens the script pad to display a script. - * @param scriptPath the script path - */ - public static void openScript(final String scriptPath) { - // trying to get the absolute path to scriptfile: - final StringBuilder tmpPath = new StringBuilder(); - if (scriptPath.startsWith("/")) { - // filepath is absolue (to map base directory): - tmpPath.append(AbstractMainControl.getInstance().getMapDefaultFolder()); - tmpPath.append(scriptPath); - } else { - // file path is relative to map dir - final String mapPath = AbstractMainControl.getInstance().getLocalMapDir().getAbsolutePath(); - tmpPath.append(mapPath); - if (!mapPath.endsWith("/")) { - tmpPath.append('/'); - } - tmpPath.append(scriptPath); - } - final String path = tmpPath.toString().replace('\\', '/'); - - // now see if that file really exists: - final File scriptFile = new File(path); - if (scriptFile.exists() && scriptFile.isFile()) { - ScriptEditControl.getInstance().openScriptFile(scriptFile.getAbsolutePath()); - } else { - // file does not exist! - ACTION_FACTORY.showMessageDialog(AbstractMainControl.getInstance().getMainView(), "openScriptNotFound", path); - } - } - - /** - * Edit path and plugin name for an event. A popup dialog is shown - * with input text fields for file path and plugin name. - * @param scriptedEvent the event - */ - public static void editParameters(final ScriptedEvent scriptedEvent) { - if (pathFrame == null) { - // initialize popup frame - pathFrame = new JDialog(AbstractMainControl.getInstance().getMainView(), "Edit Parameters", true); - pathFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); - - final JPanel mainPanel = new JPanel(); - mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); - mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); - - // input line: script path - final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JLabel text1 = new JLabel("Script:"); - line1.add(text1); - inputScriptPath = new JTextField(scriptedEvent.getScriptPath(), 20); - line1.add(inputScriptPath); - mainPanel.add(line1); - - // input line: plugin options - final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JLabel text2 = new JLabel("Script options:"); - line2.add(text2); - inputOptions = new JTextField(scriptedEvent.getOptions(), 20); - line2.add(inputOptions); - mainPanel.add(line2); - mainPanel.add(Box.createVerticalStrut(5)); - - // input line: plugin name - final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JLabel text3 = new JLabel("Plugin name:"); - line3.add(text3); - inputPluginName = new JTextField(scriptedEvent.getPluginName(), 20); - line3.add(inputPluginName); - mainPanel.add(line3); - mainPanel.add(Box.createVerticalStrut(5)); - - // button panel: - final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JButton okButton = new JButton("OK"); - okListener = new PathButtonListener(true, pathFrame, null); - okListener.setTargetEvent(scriptedEvent); - okButton.addActionListener(okListener); - line4.add(okButton); - - final JButton cancelButton = new JButton("Cancel"); - cancelListener = new PathButtonListener(false, pathFrame, null); - cancelListener.setTargetEvent(scriptedEvent); - cancelButton.addActionListener(cancelListener); - line4.add(cancelButton); - mainPanel.add(line4); - - pathFrame.getContentPane().add(mainPanel); - pathFrame.pack(); - pathFrame.setLocationRelativeTo(AbstractMainControl.getInstance().getMainView()); - pathFrame.setVisible(true); - } else { - // just set fields and show - okListener.setTargetEvent(scriptedEvent); - cancelListener.setTargetEvent(scriptedEvent); - inputScriptPath.setText(scriptedEvent.getScriptPath()); - inputPluginName.setText(scriptedEvent.getPluginName()); - inputOptions.setText(scriptedEvent.getOptions()); - pathFrame.toFront(); - pathFrame.setVisible(true); - } - } - -} // class ScriptedEventEditor Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 15:27:01 UTC (rev 3958) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2008-05-03 15:46:16 UTC (rev 3959) @@ -27,6 +27,7 @@ import javax.swing.JDialog; import javax.swing.JList; import javax.swing.JOptionPane; +import net.sf.gridarta.gameobject.scripts.ScriptedEventEditor; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 15:27:01 UTC (rev 3958) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2008-05-03 15:46:16 UTC (rev 3959) @@ -22,6 +22,7 @@ import daieditor.CMainControl; import daieditor.gameobject.Archetype; import daieditor.gameobject.GameObject; +import net.sf.gridarta.gameobject.scripts.ScriptedEventEditor; import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeNameException; import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeTypeException; Deleted: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEventEditor.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEventEditor.java 2008-05-03 15:27:01 UTC (rev 3958) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEventEditor.java 2008-05-03 15:46:16 UTC (rev 3959) @@ -1,164 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package daieditor.gameobject.scripts; - -import java.awt.FlowLayout; -import java.io.File; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.WindowConstants; -import net.sf.gridarta.AbstractMainControl; -import net.sf.gridarta.gameobject.scripts.PathButtonListener; -import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; -import net.sf.japi.swing.ActionFactory; -import org.apache.log4j.Logger; - -public class ScriptedEventEditor { - - /** The Logger for printing log messages. */ - private static final Logger log = Logger.getLogger(ScriptedEventEditor.class); - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); - - public static JTextField inputScriptPath; - - public static JTextField inputPluginName; - - public static JTextField inputOptions; - - private static PathButtonListener cancelListener; - - private static PathButtonListener okListener; - - // popup frame to edit script paths: - private static JDialog pathFrame; - - /** - * Opens the script pad to display a script. - * @param scriptPath the script path - */ - public static void openScript(final String scriptPath) { - // trying to get the absolute path to scriptfile: - final StringBuilder tmpPath = new StringBuilder(); - if (scriptPath.startsWith("/")) { - // filepath is absolue (to map base directory): - tmpPath.append(AbstractMainControl.getInstance().getMapDefaultFolder()); - tmpPath.append(scriptPath); - } else { - // file path is relative to map dir - final String mapPath = AbstractMainControl.getInstance().getLocalMapDir().getAbsolutePath(); - tmpPath.append(mapPath); - if (!mapPath.endsWith("/")) { - tmpPath.append('/'); - } - tmpPath.append(scriptPath); - } - final String path = tmpPath.toString().replace('\\', '/'); - - // now see if that file really exists: - final File scriptFile = new File(path); - if (scriptFile.exists() && scriptFile.isFile()) { - ScriptEditControl.getInstance().openScriptFile(scriptFile.getAbsolutePath()); - } else { - // file does not exist! - ACTION_FACTORY.showMessageDialog(AbstractMainControl.getInstance().getMainView(), "openScriptNotFound", path); - } - } - - /** - * Edit path and plugin name for an event. A popup dialog is shown - * with input text fields for file path and plugin name. - * @param scriptedEvent the event - */ - public static void editParameters(final ScriptedEvent scriptedEvent) { - if (pathFrame == null) { - // initialize popup frame - pathFrame = new JDialog(AbstractMainControl.getInstance().getMainView(), "Edit Parameters", true); - pathFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); - - final JPanel mainPanel = new JPanel(); - mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); - mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); - - // input line: script path - final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JLabel text1 = new JLabel("Script:"); - line1.add(text1); - inputScriptPath = new JTextField(scriptedEvent.getScriptPath(), 20); - line1.add(inputScriptPath); - mainPanel.add(line1); - - // input line: plugin options - final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JLabel text2 = new JLabel("Script options:"); - line2.add(text2); - inputOptions = new JTextField(scriptedEvent.getOptions(), 20); - line2.add(inputOptions); - mainPanel.add(line2); - mainPanel.add(Box.createVerticalStrut(5)); - - // input line: plugin name - final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JLabel text3 = new JLabel("Plugin name:"); - line3.add(text3); - inputPluginName = new JTextField(scriptedEvent.getPluginName(), 20); - line3.add(inputPluginName); - mainPanel.add(line3); - mainPanel.add(Box.createVerticalStrut(5)); - - // button panel: - final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JButton okButton = new JButton("OK"); - okListener = new PathButtonListener(true, pathFrame, null); - okListener.setTargetEvent(scriptedEvent); - okButton.addActionListener(okListener); - line4.add(okButton); - - final JButton cancelButton = new JButton("Cancel"); - cancelListener = new PathButtonListener(false, pathFrame, null); - cancelListener.setTargetEvent(scriptedEvent); - cancelButton.addActionListener(cancelListener); - line4.add(cancelButton); - mainPanel.add(line4); - - pathFrame.getContentPane().add(mainPanel); - pathFrame.pack(); - pathFrame.setLocationRelativeTo(AbstractMainControl.getInstance().getMainView()); - pathFrame.setVisible(true); - } else { - // just set fields and show - okListener.setTargetEvent(scriptedEvent); - cancelListener.setTargetEvent(scriptedEvent); - inputScriptPath.setText(scriptedEvent.getScriptPath()); - inputPluginName.setText(scriptedEvent.getPluginName()); - inputOptions.setText(scriptedEvent.getOptions()); - pathFrame.toFront(); - pathFrame.setVisible(true); - } - } - -} // class ScriptedEventEditor Modified: trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptedEvent.java 2008-05-03 15:27:01 UTC (rev 3958) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptedEvent.java 2008-05-03 15:46:16 UTC (rev 3959) @@ -31,4 +31,10 @@ */ public abstract void modifyEventPath(); + public abstract String getPluginName(); + + public abstract String getScriptPath(); + + public abstract String getOptions(); + } // class ScriptedEvent Added: trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptedEventEditor.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptedEventEditor.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptedEventEditor.java 2008-05-03 15:46:16 UTC (rev 3959) @@ -0,0 +1,163 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gameobject.scripts; + +import java.awt.FlowLayout; +import java.io.File; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.WindowConstants; +import net.sf.gridarta.AbstractMainControl; +import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; +import net.sf.japi.swing.ActionFactory; +import org.apache.log4j.Logger; + +public class ScriptedEventEditor { + + /** The Logger for printing log messages. */ + private static final Logger log = Logger.getLogger(ScriptedEventEditor.class); + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("net.sf.gridarta"); + + public static JTextField inputScriptPath; + + public static JTextField inputPluginName; + + public static JTextField inputOptions; + + private static PathButtonListener cancelListener; + + private static PathButtonListener okListener; + + // popup frame to edit script paths: + private static JDialog pathFrame; + + /** + * Opens the script pad to display a script. + * @param scriptPath the script path + */ + public static void openScript(final String scriptPath) { + // trying to get the absolute path to scriptfile: + final StringBuilder tmpPath = new StringBuilder(); + if (scriptPath.startsWith("/")) { + // filepath is absolue (to map base directory): + tmpPath.append(AbstractMainControl.getInstance().getMapDefaultFolder()); + tmpPath.append(scriptPath); + } else { + // file path is relative to map dir + final String mapPath = AbstractMainControl.getInstance().getLocalMapDir().getAbsolutePath(); + tmpPath.append(mapPath); + if (!mapPath.endsWith("/")) { + tmpPath.append('/'); + } + tmpPath.append(scriptPath); + } + final String path = tmpPath.toString().replace('\\', '/'); + + // now see if that file really exists: + final File scriptFile = new File(path); + if (scriptFile.exists() && scriptFile.isFile()) { + ScriptEditControl.getInstance().openScriptFile(scriptFile.getAbsolutePath()); + } else { + // file does not exist! + ACTION_FACTORY.showMessageDialog(AbstractMainControl.getInstance().getMainView(), "openScriptNotFound", path); + } + } + + /** + * Edit path and plugin name for an event. A popup dialog is shown + * with input text fields for file path and plugin name. + * @param scriptedEvent the event + */ + public static void editParameters(final ScriptedEvent scriptedEvent) { + if (pathFrame == null) { + // initialize popup frame + pathFrame = new JDialog(AbstractMainControl.getInstance().getMainView(), "Edit Parameters", true); + pathFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); + + final JPanel mainPanel = new JPanel(); + mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); + mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); + + // input line: script path + final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JLabel text1 = new JLabel("Script:"); + line1.add(text1); + inputScriptPath = new JTextField(scriptedEvent.getScriptPath(), 20); + line1.add(inputScriptPath); + mainPanel.add(line1); + + // input line: plugin options + final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JLabel text2 = new JLabel("Script options:"); + line2.add(text2); + inputOptions = new JTextField(scriptedEvent.getOptions(), 20); + line2.add(inputOptions); + mainPanel.add(line2); + mainPanel.add(Box.createVerticalStrut(5)); + + // input line: plugin name + final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JLabel text3 = new JLabel("Plugin name:"); + line3.add(text3); + inputPluginName = new JTextField(scriptedEvent.getPluginName(), 20); + line3.add(inputPluginName); + mainPanel.add(line3); + mainPanel.add(Box.createVerticalStrut(5)); + + // button panel: + final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JButton okButton = new JButton("OK"); + okListener = new PathButtonListener(true, pathFrame, null); + okListener.setTargetEvent(scriptedEvent); + okButton.addActionListener(okListener); + line4.add(okButton); + + final JButton cancelButton = new JButton("Cancel"); + cancelListener = new PathButtonListener(false, pathFrame, null); + cancelListener.setTargetEvent(scriptedEvent); + cancelButton.addActionListener(cancelListener); + line4.add(cancelButton); + mainPanel.add(line4); + + pathFrame.getContentPane().add(mainPanel); + pathFrame.pack(); + pathFrame.setLocationRelativeTo(AbstractMainControl.getInstance().getMainView()); + pathFrame.setVisible(true); + } else { + // just set fields and show + okListener.setTargetEvent(scriptedEvent); + cancelListener.setTargetEvent(scriptedEvent); + inputScriptPath.setText(scriptedEvent.getScriptPath()); + inputPluginName.setText(scriptedEvent.getPluginName()); + inputOptions.setText(scriptedEvent.getOptions()); + pathFrame.toFront(); + pathFrame.setVisible(true); + } + } + +} // class ScriptedEventEditor Property changes on: trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptedEventEditor.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-03 15:49:15
|
Revision: 3960 http://gridarta.svn.sourceforge.net/gridarta/?rev=3960&view=rev Author: akirschbaum Date: 2008-05-03 08:49:22 -0700 (Sat, 03 May 2008) Log Message: ----------- Whitespace changes. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java 2008-05-03 15:46:16 UTC (rev 3959) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java 2008-05-03 15:49:22 UTC (rev 3960) @@ -57,8 +57,9 @@ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); /** The ending for scripts. */ - private static final String SCRIPT_ENDING = ".py";// popup frame for new scripts: + private static final String SCRIPT_ENDING = ".py"; + // popup frame for new scripts: private static JDialog newScriptFrame; private static JLabel headingLabel; Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java 2008-05-03 15:46:16 UTC (rev 3959) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java 2008-05-03 15:49:22 UTC (rev 3960) @@ -57,8 +57,9 @@ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); /** The ending for scripts. */ - private static final String SCRIPT_ENDING = ".lua";// popup frame for new scripts: + private static String scriptEnding; + // popup frame for new scripts: private static JDialog newScriptFrame; private static JLabel headingLabel; @@ -74,8 +75,10 @@ private static JTextField inputOptions; /** Initialize the JComboBox with the event types. */ - public static synchronized void initEventTypeBoxes() { - pluginNameBox = new JComboBox(new String[]{" Lua "}); + public static synchronized void initEventTypeBoxes(final String ending, final String name) { + scriptEnding = ending; + + pluginNameBox = new JComboBox(new String[]{" " + name + " "}); pluginNameBox.setSelectedIndex(0); eventTypeBox = ScriptArchUtils.createEventTypeBox(); @@ -101,7 +104,7 @@ if (defScriptName.length() >= 3) { defScriptName = defScriptName.substring(0, 1).toUpperCase() + defScriptName.substring(1); } - defScriptName += "Script" + SCRIPT_ENDING; + defScriptName += "Script" + scriptEnding; return PathManager.getMapPath(new File(AbstractMainControl.getInstance().getLocalMapDir(), defScriptName).getPath()); } @@ -319,9 +322,9 @@ // now check if the specified path points to an existing script File newScriptFile = new File(absScriptPath); - if (!newScriptFile.exists() && !absScriptPath.endsWith(SCRIPT_ENDING)) { - absScriptPath += SCRIPT_ENDING; - scriptPath += SCRIPT_ENDING; + if (!newScriptFile.exists() && !absScriptPath.endsWith(scriptEnding)) { + absScriptPath += scriptEnding; + scriptPath += scriptEnding; newScriptFile = new File(absScriptPath); } @@ -342,9 +345,9 @@ frame.setVisible(false); // close dialog } } else { - if (!absScriptPath.endsWith(SCRIPT_ENDING)) { - absScriptPath += SCRIPT_ENDING; - scriptPath += SCRIPT_ENDING; + if (!absScriptPath.endsWith(scriptEnding)) { + absScriptPath += scriptEnding; + scriptPath += scriptEnding; newScriptFile = new File(absScriptPath); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-03 16:03:17
|
Revision: 3961 http://gridarta.svn.sourceforge.net/gridarta/?rev=3961&view=rev Author: akirschbaum Date: 2008-05-03 09:03:23 -0700 (Sat, 03 May 2008) Log Message: ----------- Unify ScriptArchEditor. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-05-03 15:49:22 UTC (rev 3960) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-05-03 16:03:23 UTC (rev 3961) @@ -302,7 +302,7 @@ } gameObjectSpells.sort(); - ScriptArchEditor.initEventTypeBoxes(); + ScriptArchEditor.initEventTypeBoxes(".py", "Python"); final boolean mapTileListBottom = prefs.getBoolean(MainView.MAP_TILE_LIST_BOTTOM_KEY, CMainView.MAP_TILE_LIST_BOTTOM_DEFAULT); selectedSquareControl = new SelectedSquareControl<GameObject, MapArchObject, Archetype, MapControl, CMapViewBasic>(ACTION_FACTORY, this, mainView, mapTileListBottom, null); Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java 2008-05-03 15:49:22 UTC (rev 3960) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java 2008-05-03 16:03:23 UTC (rev 3961) @@ -57,7 +57,7 @@ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); /** The ending for scripts. */ - private static final String SCRIPT_ENDING = ".py"; + private static String scriptEnding; // popup frame for new scripts: private static JDialog newScriptFrame; @@ -75,8 +75,10 @@ private static JTextField inputOptions; /** Initialize the JComboBox with the event types. */ - public static synchronized void initEventTypeBoxes() { - pluginNameBox = new JComboBox(new String[]{" Python"}); + public static synchronized void initEventTypeBoxes(final String ending, final String name) { + scriptEnding = ending; + + pluginNameBox = new JComboBox(new String[]{name}); pluginNameBox.setSelectedIndex(0); eventTypeBox = ScriptArchUtils.createEventTypeBox(); @@ -102,7 +104,7 @@ if (defScriptName.length() >= 3) { defScriptName = defScriptName.substring(0, 1).toUpperCase() + defScriptName.substring(1); } - defScriptName += "Script" + SCRIPT_ENDING; + defScriptName += "Script" + scriptEnding; return PathManager.getMapPath(new File(AbstractMainControl.getInstance().getLocalMapDir(), defScriptName).getPath()); } @@ -320,9 +322,9 @@ // now check if the specified path points to an existing script File newScriptFile = new File(absScriptPath); - if (!newScriptFile.exists() && !absScriptPath.endsWith(SCRIPT_ENDING)) { - absScriptPath += SCRIPT_ENDING; - scriptPath += SCRIPT_ENDING; + if (!newScriptFile.exists() && !absScriptPath.endsWith(scriptEnding)) { + absScriptPath += scriptEnding; + scriptPath += scriptEnding; newScriptFile = new File(absScriptPath); } @@ -343,9 +345,9 @@ frame.setVisible(false); // close dialog } } else { - if (!absScriptPath.endsWith(SCRIPT_ENDING)) { - absScriptPath += SCRIPT_ENDING; - scriptPath += SCRIPT_ENDING; + if (!absScriptPath.endsWith(scriptEnding)) { + absScriptPath += scriptEnding; + scriptPath += scriptEnding; newScriptFile = new File(absScriptPath); } Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-05-03 15:49:22 UTC (rev 3960) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-05-03 16:03:23 UTC (rev 3961) @@ -355,7 +355,7 @@ } numberSpells.sort(); - ScriptArchEditor.initEventTypeBoxes(); + ScriptArchEditor.initEventTypeBoxes(".lua", "Lua"); final boolean mapTileListBottom = prefs.getBoolean(MainView.MAP_TILE_LIST_BOTTOM_KEY, CMainView.MAP_TILE_LIST_BOTTOM_DEFAULT); selectedSquareControl = new SelectedSquareControl<GameObject, MapArchObject, Archetype, MapControl, CMapViewBasic>(ACTION_FACTORY, this, mainView, mapTileListBottom, GUIUtils.getSysIcon(IGUIConstants.TILE_NORTH)); Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java 2008-05-03 15:49:22 UTC (rev 3960) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java 2008-05-03 16:03:23 UTC (rev 3961) @@ -78,7 +78,7 @@ public static synchronized void initEventTypeBoxes(final String ending, final String name) { scriptEnding = ending; - pluginNameBox = new JComboBox(new String[]{" " + name + " "}); + pluginNameBox = new JComboBox(new String[]{name}); pluginNameBox.setSelectedIndex(0); eventTypeBox = ScriptArchUtils.createEventTypeBox(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-04 15:38:17
|
Revision: 3962 http://gridarta.svn.sourceforge.net/gridarta/?rev=3962&view=rev Author: akirschbaum Date: 2008-05-04 08:38:13 -0700 (Sun, 04 May 2008) Log Message: ----------- Include path of other face in duplicate faces error message. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/face/FaceObjects.java trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java trunk/daimonin/src/daieditor/gameobject/face/FaceObjects.java trunk/daimonin/src/daieditor/messages.properties trunk/daimonin/src/daieditor/messages_sv.properties trunk/src/app/net/sf/gridarta/gameobject/face/DuplicateFaceException.java Modified: trunk/crossfire/src/cfeditor/gameobject/face/FaceObjects.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/face/FaceObjects.java 2008-05-03 16:03:23 UTC (rev 3961) +++ trunk/crossfire/src/cfeditor/gameobject/face/FaceObjects.java 2008-05-04 15:38:13 UTC (rev 3962) @@ -83,8 +83,9 @@ */ public void addFaceObject(final String faceName, final String originalFilename, final String resourceDirectory, final String resourceName, final int offset, final int size) throws DuplicateFaceException { final FaceObject faceObject = new FaceObject(faceName, originalFilename, resourceDirectory, resourceName, offset, size); - if (containsKey(faceName)) { - throw new DuplicateFaceException(faceObject); + final FaceObject otherFaceObject = get(faceName); + if (otherFaceObject != null) { + throw new DuplicateFaceException(faceObject, otherFaceObject); } put(faceObject); } Modified: trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2008-05-03 16:03:23 UTC (rev 3961) +++ trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2008-05-04 15:38:13 UTC (rev 3962) @@ -323,7 +323,7 @@ // TODO log.error("Error:", e); } catch (final DuplicateFaceException e) { - ACTION_FACTORY.showMessageDialog(mainControl.getMainView(), "loadDuplicateFace", e.getDuplicate().getFaceName(), e.getDuplicate().getFilename()); + ACTION_FACTORY.showMessageDialog(mainControl.getMainView(), "loadDuplicateFace", e.getDuplicate().getFaceName(), e.getDuplicate().getFilename(), e.getExisting().getFilename()); } } @@ -446,7 +446,7 @@ try { mainControl.getFaceObjects().addFaceObject(facename, filename.substring(stripPath, filename.length() - 4).replace('\\', '/')); } catch (final DuplicateFaceException e) { - ACTION_FACTORY.showMessageDialog(mainControl.getMainView(), "loadDuplicateFace", e.getDuplicate().getFaceName(), e.getDuplicate().getFilename()); + ACTION_FACTORY.showMessageDialog(mainControl.getMainView(), "loadDuplicateFace", e.getDuplicate().getFaceName(), e.getDuplicate().getFilename(), e.getExisting().getFilename()); } } Modified: trunk/daimonin/src/daieditor/gameobject/face/FaceObjects.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/face/FaceObjects.java 2008-05-03 16:03:23 UTC (rev 3961) +++ trunk/daimonin/src/daieditor/gameobject/face/FaceObjects.java 2008-05-04 15:38:13 UTC (rev 3962) @@ -214,8 +214,9 @@ */ public void addFaceObject(final String faceName, final String originalFilename, final String actualFilename, final int offset, final int size) throws DuplicateFaceException { final FaceObject faceObject = new FaceObject(faceName, originalFilename, actualFilename, offset, size); - if (containsKey(faceName)) { - throw new DuplicateFaceException(faceObject); + final FaceObject otherFaceObject = get(faceName); + if (otherFaceObject != null) { + throw new DuplicateFaceException(faceObject, otherFaceObject); } put(faceObject); } Modified: trunk/daimonin/src/daieditor/messages.properties =================================================================== --- trunk/daimonin/src/daieditor/messages.properties 2008-05-03 16:03:23 UTC (rev 3961) +++ trunk/daimonin/src/daieditor/messages.properties 2008-05-04 15:38:13 UTC (rev 3962) @@ -138,7 +138,7 @@ errCantLoadFaceTree.message=<html>Can''t load face tree.<br>You won''t be able to easily choose faces from a tree.<br>To change this, you need either a version of <code>arch/</code> that contains <code>arch/dev/editor/conf/facetree</code>,<br>or you have to collect arches yourself.</html> loadDuplicateFace.title=Error: Duplicate face -loadDuplicateFace.message=Warning!\n\nDuplicate face: ''{0}''\nFile: ''{1}''\nI will ignore this duplicate. +loadDuplicateFace.message=Warning!\n\nDuplicate face: ''{0}''\nFiles: ''{1}''\nand ''{2}''\nI will ignore this duplicate. # Map Properties mapMap=Map Modified: trunk/daimonin/src/daieditor/messages_sv.properties =================================================================== --- trunk/daimonin/src/daieditor/messages_sv.properties 2008-05-03 16:03:23 UTC (rev 3961) +++ trunk/daimonin/src/daieditor/messages_sv.properties 2008-05-04 15:38:13 UTC (rev 3962) @@ -138,7 +138,7 @@ errCantLoadFaceTree.message=<html>Kan inte \xF6ppna bildtr\xE4det. <br>Du kommer inte att kunna anv\xE4nda det smidigare gr\xE4nssnittet f\xF6r att v\xE4lja bilder till objekt.<br>F\xF6r att l\xF6sa detta beh\xF6ver du antingen en version <code>arch/</code> som inneh\xE5ller <code>arch/dev/editor/conf/facetree</code>,<br>eller s\xE5 m\xE5ste du sammanst\xE4lla arketyper sj\xE4lv.</html> loadDuplicateFace.title=Fel: duplicerad bild -loadDuplicateFace.message=Varning!\n\nDuplicerad bild: ''{0}''\nFil: ''{1}''\nJag kommer att ignorera detta duplikat. +loadDuplicateFace.message=Varning!\n\nDuplicerad bild: ''{0}''\nFiler: ''{1}''\noch ''{2}''\nJag kommer att ignorera detta duplikat. # Map Properties mapMap=Karta Modified: trunk/src/app/net/sf/gridarta/gameobject/face/DuplicateFaceException.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/face/DuplicateFaceException.java 2008-05-03 16:03:23 UTC (rev 3961) +++ trunk/src/app/net/sf/gridarta/gameobject/face/DuplicateFaceException.java 2008-05-04 15:38:13 UTC (rev 3962) @@ -31,13 +31,18 @@ /** FaceObject causing the problem. */ private final FaceObject duplicate; + /** Other FaceObject causing the problem. */ + private final FaceObject existing; + /** * Create a DuplicateFaceException. * @param duplicate Duplicate face that's the cause + * @param existing the existing face */ - public DuplicateFaceException(final FaceObject duplicate) { + public DuplicateFaceException(final FaceObject duplicate, final FaceObject existing) { super("Non-unique face " + duplicate.getFaceName() + " from " + duplicate.getOriginalFilename()); this.duplicate = duplicate; + this.existing = existing; } /** @@ -48,4 +53,12 @@ return duplicate; } + /** + * Get the other duplicate that caused this exception. + * @return duplicate + */ + public FaceObject getExisting() { + return existing; + } + } // class DuplicateFaceException This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-04 16:18:08
|
Revision: 3964 http://gridarta.svn.sourceforge.net/gridarta/?rev=3964&view=rev Author: akirschbaum Date: 2008-05-04 09:18:07 -0700 (Sun, 04 May 2008) Log Message: ----------- Unify code. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CrossfireObjectsFactory.java trunk/crossfire/src/cfeditor/map/MapControl.java trunk/daimonin/src/daieditor/DaimoninObjectsFactory.java trunk/daimonin/src/daieditor/map/MapControl.java trunk/src/app/net/sf/gridarta/GridartaObjectsFactory.java Modified: trunk/crossfire/src/cfeditor/CrossfireObjectsFactory.java =================================================================== --- trunk/crossfire/src/cfeditor/CrossfireObjectsFactory.java 2008-05-04 16:00:34 UTC (rev 3963) +++ trunk/crossfire/src/cfeditor/CrossfireObjectsFactory.java 2008-05-04 16:18:07 UTC (rev 3964) @@ -22,6 +22,7 @@ import cfeditor.gameobject.Archetype; import cfeditor.gameobject.GameObject; import cfeditor.gameobject.UndefinedArchetype; +import cfeditor.gui.map.SimpleLevelRenderer; import cfeditor.io.GameObjectParser; import cfeditor.io.MapArchObjectParser; import cfeditor.map.MapArchObject; @@ -33,9 +34,12 @@ import net.sf.gridarta.AbstractMainControl; import net.sf.gridarta.GridartaObjectsFactory; import net.sf.gridarta.MainControl; +import net.sf.gridarta.gameobject.ArchetypeSet; import net.sf.gridarta.gameobject.match.GameObjectMatchers; +import net.sf.gridarta.gui.map.LevelRenderer; import net.sf.gridarta.io.DefaultMapReader; import net.sf.gridarta.io.MapReader; +import net.sf.gridarta.map.MapModel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -93,4 +97,9 @@ return new MapControl(CMainControl.getInstance(), objects, mapArchObject, true, GameObjectMatchers.getMatcher("exit")); } + /** {@inheritDoc} */ + @NotNull public LevelRenderer newSimpleLevelRenderer(@NotNull final MapModel<GameObject, MapArchObject, Archetype> mapModel, @NotNull final ArchetypeSet<GameObject, MapArchObject, Archetype> archetypeSet) { + return new SimpleLevelRenderer(mapModel, archetypeSet); + } + } // class CrossfireObjectsFactory Modified: trunk/crossfire/src/cfeditor/map/MapControl.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapControl.java 2008-05-04 16:00:34 UTC (rev 3963) +++ trunk/crossfire/src/cfeditor/map/MapControl.java 2008-05-04 16:18:07 UTC (rev 3964) @@ -57,9 +57,9 @@ private final MapModel<GameObject, MapArchObject, Archetype> mapModel; /** - * Reference to SimpleLevelRenderer, which is only used to get images. + * Reference to LevelRenderer, which is only used to get images. */ - private SoftReference<SimpleLevelRenderer> simpleLevelRendererReference; + private SoftReference<LevelRenderer> levelRendererReference; /** * Each view of this map will get a unique number. @@ -96,15 +96,15 @@ /** {@inheritDoc} */ public LevelRenderer getRenderer() { - final SimpleLevelRenderer tmpLevelRenderer = simpleLevelRendererReference == null ? null : simpleLevelRendererReference.get(); - final SimpleLevelRenderer simpleLevelRenderer; + final LevelRenderer tmpLevelRenderer = levelRendererReference == null ? null : levelRendererReference.get(); + final LevelRenderer levelRenderer; if (tmpLevelRenderer == null) { - simpleLevelRenderer = new SimpleLevelRenderer(mapModel, mainControl.getArchetypeSet()); - simpleLevelRendererReference = new SoftReference<SimpleLevelRenderer>(simpleLevelRenderer); + levelRenderer = mainControl.getGridartaObjectsFactory().newSimpleLevelRenderer(mapModel, mainControl.getArchetypeSet()); + levelRendererReference = new SoftReference<LevelRenderer>(levelRenderer); } else { - simpleLevelRenderer = tmpLevelRenderer; + levelRenderer = tmpLevelRenderer; } - return simpleLevelRenderer; + return levelRenderer; } /** {@inheritDoc} */ Modified: trunk/daimonin/src/daieditor/DaimoninObjectsFactory.java =================================================================== --- trunk/daimonin/src/daieditor/DaimoninObjectsFactory.java 2008-05-04 16:00:34 UTC (rev 3963) +++ trunk/daimonin/src/daieditor/DaimoninObjectsFactory.java 2008-05-04 16:18:07 UTC (rev 3964) @@ -22,6 +22,7 @@ import daieditor.gameobject.Archetype; import daieditor.gameobject.GameObject; import daieditor.gameobject.UndefinedArchetype; +import daieditor.gui.map.SimpleLevelRenderer; import daieditor.io.GameObjectParser; import daieditor.io.MapArchObjectParser; import daieditor.map.MapArchObject; @@ -33,9 +34,12 @@ import net.sf.gridarta.AbstractMainControl; import net.sf.gridarta.GridartaObjectsFactory; import net.sf.gridarta.MainControl; +import net.sf.gridarta.gameobject.ArchetypeSet; import net.sf.gridarta.gameobject.match.GameObjectMatchers; +import net.sf.gridarta.gui.map.LevelRenderer; import net.sf.gridarta.io.DefaultMapReader; import net.sf.gridarta.io.MapReader; +import net.sf.gridarta.map.MapModel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -93,4 +97,9 @@ return new MapControl(CMainControl.getInstance(), objects, mapArchObject, true, GameObjectMatchers.getMatcher("exit")); } + /** {@inheritDoc} */ + @NotNull public LevelRenderer newSimpleLevelRenderer(@NotNull final MapModel<GameObject, MapArchObject, Archetype> mapModel, @NotNull final ArchetypeSet<GameObject, MapArchObject, Archetype> archetypeSet) { + return new SimpleLevelRenderer(mapModel); + } + } // class DaimoninObjectsFactory Modified: trunk/daimonin/src/daieditor/map/MapControl.java =================================================================== --- trunk/daimonin/src/daieditor/map/MapControl.java 2008-05-04 16:00:34 UTC (rev 3963) +++ trunk/daimonin/src/daieditor/map/MapControl.java 2008-05-04 16:18:07 UTC (rev 3964) @@ -59,7 +59,7 @@ /** * Reference to SimpleLevelRenderer, which is only used to get images. */ - private SoftReference<SimpleLevelRenderer> simpleLevelRendererReference; + private SoftReference<LevelRenderer> levelRendererReference; /** * Each view of this map will get a unique number. @@ -96,15 +96,15 @@ /** {@inheritDoc} */ public LevelRenderer getRenderer() { - final SimpleLevelRenderer tmpLevelRenderer = simpleLevelRendererReference == null ? null : simpleLevelRendererReference.get(); - final SimpleLevelRenderer simpleLevelRenderer; + final LevelRenderer tmpLevelRenderer = levelRendererReference == null ? null : levelRendererReference.get(); + final LevelRenderer levelRenderer; if (tmpLevelRenderer == null) { - simpleLevelRenderer = new SimpleLevelRenderer(mapModel); - simpleLevelRendererReference = new SoftReference<SimpleLevelRenderer>(simpleLevelRenderer); + levelRenderer = mainControl.getGridartaObjectsFactory().newSimpleLevelRenderer(mapModel, mainControl.getArchetypeSet()); + levelRendererReference = new SoftReference<LevelRenderer>(levelRenderer); } else { - simpleLevelRenderer = tmpLevelRenderer; + levelRenderer = tmpLevelRenderer; } - return simpleLevelRenderer; + return levelRenderer; } /** {@inheritDoc} */ Modified: trunk/src/app/net/sf/gridarta/GridartaObjectsFactory.java =================================================================== --- trunk/src/app/net/sf/gridarta/GridartaObjectsFactory.java 2008-05-04 16:00:34 UTC (rev 3963) +++ trunk/src/app/net/sf/gridarta/GridartaObjectsFactory.java 2008-05-04 16:18:07 UTC (rev 3964) @@ -23,13 +23,16 @@ import java.io.FileNotFoundException; import java.util.List; import net.sf.gridarta.gameobject.Archetype; +import net.sf.gridarta.gameobject.ArchetypeSet; import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.gui.map.LevelRenderer; import net.sf.gridarta.gui.map.MapViewBasic; import net.sf.gridarta.io.GameObjectParser; import net.sf.gridarta.io.MapArchObjectParser; import net.sf.gridarta.io.MapReader; import net.sf.gridarta.map.MapArchObject; import net.sf.gridarta.map.MapControl; +import net.sf.gridarta.map.MapModel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -111,4 +114,12 @@ */ @NotNull C newPickmapControl(@Nullable List<G> objects, @NotNull A mapArchObject); + /** + * Create a new level renderer instance. + * @param mapModel the map model to render + * @param archetypeSet the archetype set + * @return the new level renderer + */ + @NotNull LevelRenderer newSimpleLevelRenderer(@NotNull MapModel<G, A, R> mapModel, @NotNull ArchetypeSet<G, A, R> archetypeSet); + } // interface GridartaObjectsFactory This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-04 16:26:48
|
Revision: 3965 http://gridarta.svn.sourceforge.net/gridarta/?rev=3965&view=rev Author: akirschbaum Date: 2008-05-04 09:26:48 -0700 (Sun, 04 May 2008) Log Message: ----------- Move MapControl.getRenderer() to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/map/MapControl.java trunk/daimonin/src/daieditor/map/MapControl.java trunk/src/app/net/sf/gridarta/map/AbstractMapControl.java Modified: trunk/crossfire/src/cfeditor/map/MapControl.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapControl.java 2008-05-04 16:18:07 UTC (rev 3964) +++ trunk/crossfire/src/cfeditor/map/MapControl.java 2008-05-04 16:26:48 UTC (rev 3965) @@ -23,12 +23,9 @@ import cfeditor.CMapViewBasic; import cfeditor.gameobject.Archetype; import cfeditor.gameobject.GameObject; -import cfeditor.gui.map.SimpleLevelRenderer; import java.awt.Point; -import java.lang.ref.SoftReference; import java.util.List; import net.sf.gridarta.gameobject.match.GameObjectMatcher; -import net.sf.gridarta.gui.map.LevelRenderer; import net.sf.gridarta.gui.map.MapView; import net.sf.gridarta.map.AbstractMapControl; import net.sf.gridarta.map.DefaultMapModel; @@ -57,11 +54,6 @@ private final MapModel<GameObject, MapArchObject, Archetype> mapModel; /** - * Reference to LevelRenderer, which is only used to get images. - */ - private SoftReference<LevelRenderer> levelRendererReference; - - /** * Each view of this map will get a unique number. */ private int viewCounter = 0; @@ -95,19 +87,6 @@ } /** {@inheritDoc} */ - public LevelRenderer getRenderer() { - final LevelRenderer tmpLevelRenderer = levelRendererReference == null ? null : levelRendererReference.get(); - final LevelRenderer levelRenderer; - if (tmpLevelRenderer == null) { - levelRenderer = mainControl.getGridartaObjectsFactory().newSimpleLevelRenderer(mapModel, mainControl.getArchetypeSet()); - levelRendererReference = new SoftReference<LevelRenderer>(levelRenderer); - } else { - levelRenderer = tmpLevelRenderer; - } - return levelRenderer; - } - - /** {@inheritDoc} */ @NotNull @Override protected MapView<GameObject, MapArchObject, Archetype, MapControl, CMapViewBasic> newMapView(@Nullable final Point viewPosition) { return new MapView<GameObject, MapArchObject, Archetype, MapControl, CMapViewBasic>(mainControl, this, ++viewCounter, new CMapViewBasic(mainControl, this, viewPosition), ActionFactory.getFactory("cfeditor")); } Modified: trunk/daimonin/src/daieditor/map/MapControl.java =================================================================== --- trunk/daimonin/src/daieditor/map/MapControl.java 2008-05-04 16:18:07 UTC (rev 3964) +++ trunk/daimonin/src/daieditor/map/MapControl.java 2008-05-04 16:26:48 UTC (rev 3965) @@ -23,12 +23,9 @@ import daieditor.CMapViewBasic; import daieditor.gameobject.Archetype; import daieditor.gameobject.GameObject; -import daieditor.gui.map.SimpleLevelRenderer; import java.awt.Point; -import java.lang.ref.SoftReference; import java.util.List; import net.sf.gridarta.gameobject.match.GameObjectMatcher; -import net.sf.gridarta.gui.map.LevelRenderer; import net.sf.gridarta.gui.map.MapView; import net.sf.gridarta.map.AbstractMapControl; import net.sf.gridarta.map.DefaultMapModel; @@ -57,11 +54,6 @@ private final MapModel<GameObject, MapArchObject, Archetype> mapModel; /** - * Reference to SimpleLevelRenderer, which is only used to get images. - */ - private SoftReference<LevelRenderer> levelRendererReference; - - /** * Each view of this map will get a unique number. */ private int viewCounter = 0; @@ -95,19 +87,6 @@ } /** {@inheritDoc} */ - public LevelRenderer getRenderer() { - final LevelRenderer tmpLevelRenderer = levelRendererReference == null ? null : levelRendererReference.get(); - final LevelRenderer levelRenderer; - if (tmpLevelRenderer == null) { - levelRenderer = mainControl.getGridartaObjectsFactory().newSimpleLevelRenderer(mapModel, mainControl.getArchetypeSet()); - levelRendererReference = new SoftReference<LevelRenderer>(levelRenderer); - } else { - levelRenderer = tmpLevelRenderer; - } - return levelRenderer; - } - - /** {@inheritDoc} */ @NotNull @Override protected MapView<GameObject, MapArchObject, Archetype, MapControl, CMapViewBasic> newMapView(@Nullable final Point viewPosition) { return new MapView<GameObject, MapArchObject, Archetype, MapControl, CMapViewBasic>(mainControl, this, ++viewCounter, new CMapViewBasic(mainControl, this, viewPosition), ActionFactory.getFactory("daieditor")); } Modified: trunk/src/app/net/sf/gridarta/map/AbstractMapControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/AbstractMapControl.java 2008-05-04 16:18:07 UTC (rev 3964) +++ trunk/src/app/net/sf/gridarta/map/AbstractMapControl.java 2008-05-04 16:26:48 UTC (rev 3965) @@ -23,6 +23,7 @@ import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.lang.ref.SoftReference; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -33,6 +34,7 @@ import net.sf.gridarta.Size2D; import net.sf.gridarta.gameobject.Archetype; import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.gui.map.LevelRenderer; import net.sf.gridarta.gui.map.MapView; import net.sf.gridarta.gui.map.MapViewBasic; import net.sf.gridarta.io.DefaultMapWriter; @@ -98,6 +100,11 @@ private boolean levelClosing = false; /** + * Reference to LevelRenderer, which is only used to get images. + */ + private SoftReference<LevelRenderer> levelRendererReference; + + /** * The {@link MapModelListener} used to detect changes in the underlying * map model and set the {@link #modified} flag accordingly. */ @@ -475,6 +482,19 @@ return getRenderer().getFullImage(); } + /** {@inheritDoc} */ + public LevelRenderer getRenderer() { + final LevelRenderer tmpLevelRenderer = levelRendererReference == null ? null : levelRendererReference.get(); + final LevelRenderer levelRenderer; + if (tmpLevelRenderer == null) { + levelRenderer = mainControl.getGridartaObjectsFactory().newSimpleLevelRenderer(getMapModel(), mainControl.getArchetypeSet()); + levelRendererReference = new SoftReference<LevelRenderer>(levelRenderer); + } else { + levelRenderer = tmpLevelRenderer; + } + return levelRenderer; + } + /** * Save a map. * @param file File to save to This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2008-05-04 16:57:06
|
Revision: 3968 http://gridarta.svn.sourceforge.net/gridarta/?rev=3968&view=rev Author: akirschbaum Date: 2008-05-04 09:57:07 -0700 (Sun, 04 May 2008) Log Message: ----------- Add MapViewBasic.getLevelRenderer(). Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMapViewBasic.java trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java trunk/crossfire/src/cfeditor/gui/map/SimpleLevelRenderer.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/CMapViewBasic.java trunk/daimonin/src/daieditor/gui/map/DefaultLevelRenderer.java trunk/daimonin/src/daieditor/gui/map/SimpleLevelRenderer.java trunk/src/app/net/sf/gridarta/gui/map/LevelRenderer.java trunk/src/app/net/sf/gridarta/gui/map/MapViewBasic.java Modified: trunk/crossfire/src/cfeditor/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapViewBasic.java 2008-05-04 16:31:57 UTC (rev 3967) +++ trunk/crossfire/src/cfeditor/CMapViewBasic.java 2008-05-04 16:57:07 UTC (rev 3968) @@ -32,6 +32,7 @@ import java.util.HashMap; import java.util.Map; import javax.swing.JViewport; +import net.sf.gridarta.gui.map.LevelRenderer; import net.sf.gridarta.gui.map.MapCursor; import net.sf.gridarta.gui.map.MapCursorEvent; import net.sf.gridarta.gui.map.MapViewBasic; @@ -163,7 +164,8 @@ // ignore } - public DefaultLevelRenderer getRenderer() { + /** {@inheritDoc} */ + public LevelRenderer getRenderer() { return renderer; } Modified: trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java 2008-05-04 16:31:57 UTC (rev 3967) +++ trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java 2008-05-04 16:57:07 UTC (rev 3968) @@ -481,22 +481,12 @@ this.erroneousMapSquares = erroneousMapSquares; } - /** - * Returns whether the map grid is rendered. - * - * @return <code>true</code> if the map grid is rendered, otherwise - * <code>false</code> - */ + /** {@inheritDoc} */ public boolean isGridVisible() { return gridVisible; } - /** - * Determine whether the grid should be rendered. - * - * @param gridVisible set if the grid should be rendered, unset if the grid - * should be hidden - */ + /** {@inheritDoc} */ public void setGridVisible(final boolean gridVisible) { if (this.gridVisible == gridVisible) { return; @@ -506,11 +496,7 @@ forceRepaint(); } - /** - * Saves an image of the entire view to a file. - * @param file file to write image file to - * @throws IOException in case of I/O problems - */ + /** {@inheritDoc} */ public void printFullImage(final File file) throws IOException { ImageIO.write(getFullImage(), "png", file); } Modified: trunk/crossfire/src/cfeditor/gui/map/SimpleLevelRenderer.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/SimpleLevelRenderer.java 2008-05-04 16:31:57 UTC (rev 3967) +++ trunk/crossfire/src/cfeditor/gui/map/SimpleLevelRenderer.java 2008-05-04 16:57:07 UTC (rev 3968) @@ -26,6 +26,9 @@ import java.awt.Graphics; import java.awt.Point; import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JComponent; import net.sf.gridarta.Size2D; @@ -129,4 +132,18 @@ } } + /** {@inheritDoc} */ + public boolean isGridVisible() { + return false; + } + + /** {@inheritDoc} */ + public void setGridVisible(final boolean gridVisible) { + } + + /** {@inheritDoc} */ + public void printFullImage(final File file) throws IOException { + ImageIO.write(getFullImage(), "png", file); + } + } // class SimpleLevelRenderer Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-05-04 16:31:57 UTC (rev 3967) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-05-04 16:57:07 UTC (rev 3968) @@ -28,6 +28,7 @@ import daieditor.gameobject.scripts.ScriptArchEditor; import daieditor.gui.GameObjectAttributesDialog; import daieditor.gui.ObjectChooser; +import daieditor.gui.map.DefaultLevelRenderer; import daieditor.gui.prefs.AppPrefs; import daieditor.gui.prefs.DevPrefs; import daieditor.gui.prefs.GUIPrefs; @@ -1086,9 +1087,9 @@ return; } final CMapViewBasic view = (CMapViewBasic) currentMap.getMapViewFrame().getView(); - view.getRenderer().setPaintOnlyMap(true); + ((DefaultLevelRenderer) view.getRenderer()).setPaintOnlyMap(true); new CPreview(view.getRenderer().getFullImage()); - view.getRenderer().setPaintOnlyMap(false); + ((DefaultLevelRenderer) view.getRenderer()).setPaintOnlyMap(false); } /** {@inheritDoc} */ Modified: trunk/daimonin/src/daieditor/CMapViewBasic.java =================================================================== --- trunk/daimonin/src/daieditor/CMapViewBasic.java 2008-05-04 16:31:57 UTC (rev 3967) +++ trunk/daimonin/src/daieditor/CMapViewBasic.java 2008-05-04 16:57:07 UTC (rev 3968) @@ -34,6 +34,7 @@ import java.util.Map; import javax.swing.JViewport; import net.sf.gridarta.Size2D; +import net.sf.gridarta.gui.map.LevelRenderer; import net.sf.gridarta.gui.map.MapCursor; import net.sf.gridarta.gui.map.MapCursorEvent; import net.sf.gridarta.gui.map.MapViewBasic; @@ -194,7 +195,8 @@ // ignore } - public DefaultLevelRenderer getRenderer() { + /** {@inheritDoc} */ + public LevelRenderer getRenderer() { return renderer; } Modified: trunk/daimonin/src/daieditor/gui/map/DefaultLevelRenderer.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/DefaultLevelRenderer.java 2008-05-04 16:31:57 UTC (rev 3967) +++ trunk/daimonin/src/daieditor/gui/map/DefaultLevelRenderer.java 2008-05-04 16:57:07 UTC (rev 3968) @@ -543,22 +543,12 @@ this.erroneousMapSquares = erroneousMapSquares; } - /** - * Returns whether the map grid is rendered. - * - * @return <code>true</code> if the map grid is rendered, otherwise - * <code>false</code> - */ + /** {@inheritDoc} */ public boolean isGridVisible() { return gridVisible; } - /** - * Determine whether the grid should be rendered. - * - * @param gridVisible set if the grid should be rendered, unset if the grid - * should be hidden - */ + /** {@inheritDoc} */ public void setGridVisible(final boolean gridVisible) { if (this.gridVisible == gridVisible) { return; @@ -568,11 +558,7 @@ forceRepaint(); } - /** - * Saves an image of the entire view to a file. - * @param file file to write image file to - * @throws IOException in case of I/O problems - */ + /** {@inheritDoc} */ public void printFullImage(final File file) throws IOException { ImageIO.write(getFullImage(), "png", file); } Modified: trunk/daimonin/src/daieditor/gui/map/SimpleLevelRenderer.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/SimpleLevelRenderer.java 2008-05-04 16:31:57 UTC (rev 3967) +++ trunk/daimonin/src/daieditor/gui/map/SimpleLevelRenderer.java 2008-05-04 16:57:07 UTC (rev 3968) @@ -30,6 +30,9 @@ import java.awt.Point; import java.awt.Rectangle; import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JComponent; import net.sf.gridarta.Size2D; @@ -193,4 +196,18 @@ } } + /** {@inheritDoc} */ + public boolean isGridVisible() { + return false; + } + + /** {@inheritDoc} */ + public void setGridVisible(final boolean gridVisible) { + } + + /** {@inheritDoc} */ + public void printFullImage(final File file) throws IOException { + ImageIO.write(getFullImage(), "png", file); + } + } // class SimpleLevelRenderer Modified: trunk/src/app/net/sf/gridarta/gui/map/LevelRenderer.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/LevelRenderer.java 2008-05-04 16:31:57 UTC (rev 3967) +++ trunk/src/app/net/sf/gridarta/gui/map/LevelRenderer.java 2008-05-04 16:57:07 UTC (rev 3968) @@ -21,6 +21,8 @@ import java.awt.Point; import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -50,4 +52,26 @@ */ void forceRepaint(); + + /** + * Returns whether the map grid is rendered. + * @return <code>true</code> if the map grid is rendered, otherwise + * <code>false</code> + */ + boolean isGridVisible(); + + /** + * Determine whether the grid should be rendered. + * @param gridVisible set if the grid should be rendered, unset if the grid + * should be hidden + */ + void setGridVisible(boolean gridVisible); + + /** + * Saves an image of the entire view to a file. + * @param file file to write image file to + * @throws java.io.IOException in case of I/O problems + */ + void printFullImage(File file) throws IOException; + } // interface LevelRenderer Modified: trunk/src/app/net/sf/gridarta/gui/map/MapViewBasic.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/MapViewBasic.java 2008-05-04 16:31:57 UTC (rev 3967) +++ trunk/src/app/net/sf/gridarta/gui/map/MapViewBasic.java 2008-05-04 16:57:07 UTC (rev 3968) @@ -221,4 +221,6 @@ } } + public abstract LevelRenderer getRenderer(); + } // class MapViewBasic This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |