Gridarta Editor
ScriptArchDataUtils.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.gui.scripts;
21 
22 import java.awt.Frame;
23 import javax.swing.JList;
24 import javax.swing.JOptionPane;
32 import org.apache.log4j.Category;
33 import org.apache.log4j.Logger;
34 import org.jetbrains.annotations.NotNull;
35 
41 public class ScriptArchDataUtils<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> {
42 
46  @NotNull
47  private static final Category LOG = Logger.getLogger(ScriptArchDataUtils.class);
48 
53  private final int eventTypeNo;
54 
58  @NotNull
60 
64  @NotNull
66 
70  @NotNull
72 
81  this.eventTypeNo = eventTypeNo;
82  this.scriptArchUtils = scriptArchUtils;
83  this.scriptedEventFactory = scriptedEventFactory;
84  this.scriptedEventEditor = scriptedEventEditor;
85  }
86 
98  public void modifyEventScript(final int eventIndex, final ScriptTask task, @NotNull final JList<String> panelList, @NotNull final MapManager<?, ?, ?> mapManager, @NotNull final Frame parent, @NotNull final Iterable<G> gameObject) {
99  G oldEvent = null;
100 
101  /* Find the event object */
102  int eventCount = 0;
103  for (final G tmp : gameObject) {
104  if (tmp.getTypeNo() == eventTypeNo) {
105  if (eventCount == eventIndex) {
106  oldEvent = tmp;
107  break;
108  }
109  eventCount++;
110  }
111  }
112 
113  if (oldEvent == null) {
114  LOG.error("Error in modifyEventScript(): No event selected?");
115  } else {
117  switch (task) {
118  case EVENT_OPEN:
119  scriptedEventEditor.openScript(mapManager, event.getScriptPath(), parent);
120  break;
121 
122  case EVENT_EDIT_PATH:
123  scriptedEventEditor.editParameters(event, parent);
124  break;
125 
126  case EVENT_REMOVE:
127  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) {
128  oldEvent.remove();
129  scriptArchUtils.addEventsToJList(panelList, gameObject);
130  }
131  break;
132  }
133  }
134  }
135 
136 }
net.sf.gridarta.model.mapmanager
Definition: AbstractMapManager.java:20
net.sf.gridarta.model.scripts.ScriptedEventFactory
Factory for creating ScriptedEvent instances.
Definition: ScriptedEventFactory.java:31
net.sf.gridarta.gui.scripts.ScriptArchDataUtils.LOG
static final Category LOG
The Logger for printing log messages.
Definition: ScriptArchDataUtils.java:47
net.sf.gridarta.model.mapmanager.MapManager
A MapManager manages all opened maps.
Definition: MapManager.java:37
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.gui.scripts.ScriptArchDataUtils.scriptArchUtils
final ScriptArchUtils scriptArchUtils
The ScriptArchUtils instance to use.
Definition: ScriptArchDataUtils.java:59
net.sf
net.sf.gridarta.model.scripts
Common types for event archetypes.
Definition: AbstractScriptedEvent.java:20
net.sf.gridarta.gui.scripts.ScriptedEventEditor.openScript
void openScript(@NotNull final MapManager<?, ?, ?> mapManager, @NotNull final String scriptPath, @NotNull final Component parent)
Opens the script pad to display a script.
Definition: ScriptedEventEditor.java:99
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.gameobject.GameObject
Reflects a game object (object on a map).
Definition: GameObject.java:36
net.sf.gridarta.gui.scripts.ScriptArchDataUtils.eventTypeNo
final int eventTypeNo
The object type for event objects.
Definition: ScriptArchDataUtils.java:53
net.sf.gridarta.model.scripts.ScriptArchUtils
Definition: ScriptArchUtils.java:26
net.sf.gridarta.model.scripts.ScriptedEvent
Class which stores information about one scripted event.
Definition: ScriptedEvent.java:31
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.gui.scripts.ScriptedEventEditor< G, A, R >
net.sf.gridarta.model.maparchobject.MapArchObject
Interface for MapArchObjects.
Definition: MapArchObject.java:40
net.sf.gridarta.gui.scripts.ScriptArchDataUtils.scriptedEventEditor
final ScriptedEventEditor< G, A, R > scriptedEventEditor
The ScriptedEventEditor to use.
Definition: ScriptArchDataUtils.java:71
net.sf.gridarta.gui.scripts.ScriptTask
Parameter for operation to perform in ScriptTask, javax.swing.JList, net.sf.gridarta....
Definition: ScriptTask.java:28
net.sf.gridarta.model.scripts.ScriptArchUtils.typeName
String typeName(int eventType)
Returns a human readable name for an event type.
net.sf.gridarta.model.scripts.ScriptedEventFactory.newScriptedEvent
ScriptedEvent< G, A, R > newScriptedEvent(int eventType, @NotNull String pluginName, @NotNull String scriptPath, @NotNull String options)
Creates a new ScriptedEvent instance.
net.sf.gridarta.gui.scripts.ScriptArchDataUtils.scriptedEventFactory
final ScriptedEventFactory< G, A, R > scriptedEventFactory
The ScriptedEventFactory instance to use.
Definition: ScriptArchDataUtils.java:65
net.sf.gridarta.model
net.sf.gridarta.model.archetype.Archetype
Reflects an Archetype.
Definition: Archetype.java:41
net.sf.gridarta.gui.scripts.ScriptArchDataUtils.ScriptArchDataUtils
ScriptArchDataUtils(final int eventTypeNo, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptedEventFactory< G, A, R > scriptedEventFactory, @NotNull final ScriptedEventEditor< G, A, R > scriptedEventEditor)
Creates a new instance.
Definition: ScriptArchDataUtils.java:80
net.sf.gridarta.gui.scripts.ScriptArchDataUtils.modifyEventScript
void modifyEventScript(final int eventIndex, final ScriptTask task, @NotNull final JList< String > panelList, @NotNull final MapManager<?, ?, ?> mapManager, @NotNull final Frame parent, @NotNull final Iterable< G > gameObject)
If there is a scripted event of the specified type, the script pad is opened and the appropriate scri...
Definition: ScriptArchDataUtils.java:98
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.model.scripts.ScriptArchUtils.addEventsToJList
void addEventsToJList(@NotNull JList< String > list, @NotNull Iterable<? extends GameObject<?, ?, ?>> gameObject)
Set all ScriptedEvents to appear in the given JList This method should be fast because it may be exec...
net.sf.gridarta.gui.scripts.ScriptedEventEditor.editParameters
void editParameters(@NotNull final ScriptedEvent< G, A, R > scriptedEvent, @NotNull final Frame parent)
Edit path and plugin name for an event.
Definition: ScriptedEventEditor.java:125
net.sf.gridarta.gui.scripts.ScriptArchDataUtils
net.sf.gridarta.model.scripts.ScriptArchData related functions.
Definition: ScriptArchDataUtils.java:41