View Javadoc

1   /*
2    * Copyright (C) 2013 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16   */
17  package nl.tudelft.goal.visualizer.ut3.util;
18  
19  import cz.cuni.amis.pogamut.unreal.communication.messages.gbinfomessages.IPlayer;
20  import cz.cuni.amis.pogamut.unreal.communication.worldview.map.IUnrealWaypoint;
21  import java.awt.Menu;
22  import java.awt.MenuItem;
23  import java.awt.Point;
24  import nl.tudelft.goal.ut2004.visualizer.gui.action.AddInventoryAction;
25  import nl.tudelft.goal.ut2004.visualizer.gui.action.SpawnItemAction;
26  
27  /**
28   *
29   * @author Michiel Hegemans
30   */
31  public class UT3MenuBuilder {
32      /**
33       * Creates an UT3 specific menu for the visualizer.
34       * 
35       * @param navPoint  navPoint where to perform the action.
36       * @param at        Position where to show menu.
37       * 
38       * @return          A menu to control UT3 bots.
39       */
40      public static Menu buildUT3NavPointMenu(final IUnrealWaypoint navPoint, final Point at) {
41          Menu UT3Menu = buildUT3Menu();
42          UT3Menu.add(buildUTObjectMenu(navPoint, "Weapons", Unreal3Actors.WEAPON_TYPES));
43          UT3Menu.add(buildUTObjectMenu(navPoint, "Deployables", Unreal3Actors.DEPLOYABLE_TYPES));
44          UT3Menu.add(buildUTObjectMenu(navPoint, "Ammo", Unreal3Actors.AMMO_TYPES));
45          UT3Menu.add(buildUTObjectMenu(navPoint, "Pickups", Unreal3Actors.PICKUP_TYPES));        
46          // TODO: Not yet implemented.
47          // UT3Menu.add(buildUTObjectMenu(navPoint, "Deployed", Unreal3Actors.DEPLOYED_TYPES));        
48          UT3Menu.add(buildUTObjectMenu(navPoint, "Vehicles", Unreal3Actors.VEHICLE_TYPES));               
49          
50          return UT3Menu;
51      }
52      
53      /**
54       * Creates and agent menu that allows user to add items to bot.
55       * @param bot Target bot.
56       * @return Menu with options to add.
57       */
58      public static Menu buildUT3AgentMenu(final IPlayer bot) {
59          Menu UT3Menu = buildUT3Menu();
60          
61          UT3Menu.add(buildUTObjectInventoryMenu(bot, "Weapons", Unreal3Actors.WEAPON_TYPES));
62          UT3Menu.add(buildUTObjectInventoryMenu(bot, "Deployables", Unreal3Actors.DEPLOYABLE_TYPES));
63          UT3Menu.add(buildUTObjectInventoryMenu(bot, "Ammo", Unreal3Actors.AMMO_TYPES));
64          UT3Menu.add(buildUTObjectInventoryMenu(bot, "Pickups", Unreal3Actors.PICKUP_TYPES));
65          
66          return UT3Menu;
67      }
68      
69      /**
70       * Creates UT3 menu item.
71       * @return Empty menu with name UT3.
72       */
73      private static Menu buildUT3Menu() {
74          return new Menu("UT3");
75      }
76      
77      private static Menu buildUTObjectInventoryMenu(final IPlayer bot, String menuName, String[] UTObjects) {
78          Menu addUTObject = new Menu(menuName);
79          
80          for (String id : UTObjects) {
81              MenuItem UTObject = new MenuItem(id);
82              UTObject.addActionListener(new AddInventoryAction(bot, id));
83              addUTObject.add(UTObject);
84          }
85          
86          return addUTObject;
87      }
88      
89      /**
90       * Creates a menu for specific UT object types.
91       * 
92       * @param navPoint  Location where to spawn item.
93       * @param menuName  Name of the menu.
94       * @param UTObjects List of object types.
95       * 
96       * @return A list of items that can spawn on the navPoint.
97       */
98      private static Menu buildUTObjectMenu(final IUnrealWaypoint navPoint, String menuName, String[] UTObjects) {
99          Menu spawnUTObject = new Menu(menuName);
100         
101         for (String id : UTObjects) {
102             MenuItem UTObject = new MenuItem(id);
103             UTObject.addActionListener(new SpawnItemAction(navPoint, id));
104             spawnUTObject.add(UTObject);
105         }
106         
107         return spawnUTObject;
108     }
109 }