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-2015 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 
80  public ScriptArchDataUtils(final int eventTypeNo, @NotNull final ScriptArchUtils scriptArchUtils, @NotNull final ScriptedEventFactory<G, A, R> scriptedEventFactory, @NotNull final ScriptedEventEditor<G, A, R> scriptedEventEditor) {
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  final ScriptedEvent<G, A, R> event = scriptedEventFactory.newScriptedEvent(oldEvent);
115  switch (task) {
116  case EVENT_OPEN:
117  scriptedEventEditor.openScript(mapManager, event.getScriptPath(), parent);
118  break;
119 
120  case EVENT_EDIT_PATH:
121  scriptedEventEditor.editParameters(event, parent);
122  break;
123 
124  case EVENT_REMOVE:
125  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) {
126  oldEvent.remove();
127  scriptArchUtils.addEventsToJList(panelList, gameObject);
128  }
129  break;
130  }
131  } else {
132  LOG.error("Error in modifyEventScript(): No event selected?");
133  }
134  }
135 
136 }
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.
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...
Package with common types for event archetypes.
A MapManager manages all opened maps.
Definition: MapManager.java:37
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...
final ScriptedEventEditor< G, A, R > scriptedEventEditor
The ScriptedEventEditor to use.
Parameter for operation to perform in ScriptTask, javax.swing.JList, net.sf.gridarta.model.mapmanager.MapManager, java.awt.Frame, Iterable).
Definition: ScriptTask.java:28
final ScriptedEventFactory< G, A, R > scriptedEventFactory
The ScriptedEventFactory instance to use.
Factory for creating ScriptedEvent instances.
final ScriptArchUtils scriptArchUtils
The ScriptArchUtils instance to use.
final int eventTypeNo
The object type for event objects.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Definition: GameObject.java:36
void openScript(@NotNull final MapManager<?, ?, ?> mapManager, @NotNull final String scriptPath, @NotNull final Component parent)
Opens the script pad to display a script.
GameObjects are the objects based on Archetypes found on maps.
ScriptedEvent< G, A, R > newScriptedEvent(int eventType, @NotNull String pluginName, @NotNull String scriptPath, @NotNull String options)
Creates a new ScriptedEvent instance.
net.sf.gridarta.model.scripts.ScriptArchData related functions.
void editParameters(@NotNull final ScriptedEvent< G, A, R > scriptedEvent, @NotNull final Frame parent)
Edit path and plugin name for an event.
static final Category LOG
The Logger for printing log messages.
String typeName(int eventType)
Returns a human readable name for an event type.
Class which stores information about one scripted event.