From b676dffdecaf83f6d499cb3841a31cf099edddf1 Mon Sep 17 00:00:00 2001 From: Light2 Date: Tue, 17 Sep 2013 22:51:03 +0200 Subject: [PATCH] Fixed SUI List Boxes, added clone window --- .../general/cloning_facility_general.py | 4 +- scripts/static_map_locations.py | 16 +++--- src/services/PlayerService.java | 48 ++++++++++++++++-- src/services/StaticService.java | 7 +-- src/services/map/MapService.java | 2 +- src/services/sui/SUIListBoxItem.java | 50 +++++++++++++++++++ src/services/sui/SUIService.java | 25 ++++++---- src/services/sui/SUIWindow.java | 25 +++++++++- src/services/sui/SUIWindowComponent.java | 7 --- 9 files changed, 149 insertions(+), 35 deletions(-) create mode 100644 src/services/sui/SUIListBoxItem.java diff --git a/scripts/object/building/general/cloning_facility_general.py b/scripts/object/building/general/cloning_facility_general.py index ccad8904..b7879b33 100644 --- a/scripts/object/building/general/cloning_facility_general.py +++ b/scripts/object/building/general/cloning_facility_general.py @@ -1,4 +1,6 @@ import sys def setup(core, object): - return \ No newline at end of file + + return + \ No newline at end of file diff --git a/scripts/static_map_locations.py b/scripts/static_map_locations.py index dad930c8..098d0ebf 100644 --- a/scripts/static_map_locations.py +++ b/scripts/static_map_locations.py @@ -66,8 +66,8 @@ def nabooLocations(core, planet): mapService.addLocation(planet, 'Theed', -5488, 4380, 17, 0, 0) mapService.addLocation(planet, 'Keren', 1888, 2700, 17, 0, 0) - mapService.addLocation(planet, 'Moeina', 4836, -4830.5, 17, 0, 0) - mapService.addLocation(planet, 'Deeja Park', -4686, -1375, 17, 0, 0) + mapService.addLocation(planet, 'Moenia', 4836, -4830.5, 17, 0, 0) + mapService.addLocation(planet, 'Deeja Peek', -4686, -1375, 17, 0, 0) mapService.addLocation(planet, 'Kaadara', 5288, 6687, 17, 0, 0) def roriLocations(core, planet): @@ -78,7 +78,7 @@ def roriLocations(core, planet): mapService.addLocation(planet, 'Narmle', -5140, -2368, 17, 0, 0) mapService.addLocation(planet, 'Restuss', 5318, 5680, 17, 0, 0) - mapService.addLocation(planet, 'a Rebel outpost', 3677, -6447, 17, 0, 0) + mapService.addLocation(planet, 'Rebel outpost', 3677, -6447, 17, 0, 0) def endorLocations(core, planet): @@ -96,7 +96,7 @@ def talusLocations(core, planet): mapService.addLocation(planet, 'Dearic', 422, -3004, 17, 0, 0) mapService.addLocation(planet, 'Nashal', 4163, 5220, 17, 0, 0) - mapService.addLocation(planet, 'an Imperial outpost', -2178, 2300, 17, 0, 0) + mapService.addLocation(planet, 'Imperial outpost', -2178, 2300, 17, 0, 0) def yavin4Locations(core, planet): @@ -113,9 +113,9 @@ def dantooineLocations(core, planet): # Cities - mapService.addLocation(planet, 'a mining outpost', -640, 2486, 17, 0, 0) - mapService.addLocation(planet, 'a pirate outpost', 1588, -6399, 17, 0, 0) - mapService.addLocation(planet, 'an Imperial outpost', -4224, -2400, 17, 0, 0) + mapService.addLocation(planet, 'Mining outpost', -640, 2486, 17, 0, 0) + mapService.addLocation(planet, 'Pirate outpost', 1588, -6399, 17, 0, 0) + mapService.addLocation(planet, 'Imperial outpost', -4224, -2400, 17, 0, 0) def dathomirLocations(core, planet): @@ -134,6 +134,6 @@ def lokLocations(core, planet): # Cities mapService.addLocation(planet, 'Nym\'s Stronghold', 440, 5029, 17, 0, 0) - mapService.addLocation(planet, 'an Imperial outpost', -1920, -3084, 17, 0, 0) + mapService.addLocation(planet, 'Imperial outpost', -1920, -3084, 17, 0, 0) \ No newline at end of file diff --git a/src/services/PlayerService.java b/src/services/PlayerService.java index 1518d4cf..c592b091 100644 --- a/src/services/PlayerService.java +++ b/src/services/PlayerService.java @@ -22,8 +22,10 @@ package services; import java.nio.ByteOrder; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Random; import java.util.Vector; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -37,10 +39,14 @@ import protocol.swg.ExpertiseRequestMessage; import protocol.swg.ServerTimeMessage; import resources.common.FileUtilities; import resources.common.Opcodes; +import resources.common.SpawnPoint; +import resources.objects.building.BuildingObject; import resources.objects.creature.CreatureObject; import resources.objects.player.PlayerObject; import services.sui.SUIService.ListBoxType; import services.sui.SUIWindow; +import services.sui.SUIWindow.Trigger; +import services.sui.SUIWindow.SUICallback; import main.NGECore; @@ -193,20 +199,56 @@ public class PlayerService implements INetworkDispatch { // return; List cloners = core.staticService.getCloningFacilitiesByPlanet(creature.getPlanet()); - Vector cloneData = new Vector(); + Map cloneData = new HashMap(); Point3D position = creature.getWorldPosition(); for(SWGObject cloner : cloners) { - cloneData.add(core.mapService.getClosestCityName(cloner) + " (" + String.valueOf(position.getDistance2D(cloner.getPosition())) + "m)"); + cloneData.put(cloner.getObjectID(), core.mapService.getClosestCityName(cloner) /*+ " (" + String.valueOf(position.getDistance2D(cloner.getPosition())) + "m)"*/); } - SUIWindow window = core.suiService.createListBox(ListBoxType.LIST_BOX_OK_CANCEL, "@base_player:revive_title", "@base_player:revive_closest : " + "\n" + "@base_player:revive_bind : " + "\n" + "Cash Balance : " + creature.getCashCredits() + "\n" + "Select the desired option and click OK.", + final SUIWindow window = core.suiService.createListBox(ListBoxType.LIST_BOX_OK_CANCEL, "@base_player:revive_title", "Select the desired option and click OK.", cloneData, creature, null, 0); + Vector returnList = new Vector(); + returnList.add("List.lstList:SelectedRow"); + window.addHandler(0, "", Trigger.TRIGGER_OK, returnList, new SUICallback() { + + @SuppressWarnings("unchecked") + @Override + public void process(SWGObject owner, int eventType, Vector returnList) { + + // if(((CreatureObject)owner).getPosture() != 14) + // return; + + int index = Integer.parseInt(returnList.get(0)); + + if(window.getObjectIdByIndex(index) == 0 || core.objectService.getObject(window.getObjectIdByIndex(index)) == null) + return; + + + SWGObject cloner = core.objectService.getObject(window.getObjectIdByIndex(index)); + + if(cloner.getAttachment("spawnPoints") == null) + return; + + Vector spawnPoints = (Vector) cloner.getAttachment("spawnPoints"); + + SpawnPoint spawnPoint = spawnPoints.get(new Random().nextInt(spawnPoints.size())); + + handleCloneRequest((CreatureObject) owner, (BuildingObject) cloner, spawnPoint); + + } + + }); core.suiService.openSUIWindow(window); + } + + public void handleCloneRequest(CreatureObject creature, BuildingObject cloner, SpawnPoint spawnPoint) { + + } @Override diff --git a/src/services/StaticService.java b/src/services/StaticService.java index 433a63da..e4531ba1 100644 --- a/src/services/StaticService.java +++ b/src/services/StaticService.java @@ -106,10 +106,11 @@ public class StaticService implements INetworkDispatch { List cloners = new ArrayList(); for(SWGObject obj : objects) { - if(obj instanceof BuildingObject && (obj.getTemplate().contains("cloning_facility") || obj.getTemplate().contains("cloning_tatooine") || obj.getTemplate().contains("cloning_naboo") || obj.getTemplate().contains("cloning_corellia"))) - cloners.add(obj); + if(obj instanceof BuildingObject && (obj.getTemplate().contains("cloning_facility") || obj.getTemplate().contains("cloning_tatooine") || obj.getTemplate().contains("cloning_naboo") || obj.getTemplate().contains("cloning_corellia"))) { + if(!obj.getTemplate().equals("object/building/general/shared_cloning_facility_general.iff")) + cloners.add(obj); + } } - return cloners; } diff --git a/src/services/map/MapService.java b/src/services/map/MapService.java index e749e61f..d6a0f821 100644 --- a/src/services/map/MapService.java +++ b/src/services/map/MapService.java @@ -132,7 +132,7 @@ public class MapService implements INetworkDispatch { } } - + return closestName; } diff --git a/src/services/sui/SUIListBoxItem.java b/src/services/sui/SUIListBoxItem.java new file mode 100644 index 00000000..b73fce9f --- /dev/null +++ b/src/services/sui/SUIListBoxItem.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2013 + * + * This File is part of NGECore2. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Using NGEngine to work with NGECore2 is making a combined work based on NGEngine. + * Therefore all terms and conditions of the GNU Lesser General Public License cover the combination. + ******************************************************************************/ +package services.sui; + +public class SUIListBoxItem { + + private String name; + private long objectId; + + public SUIListBoxItem(String name, long objectId) { + this.name = name; + this.objectId = objectId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public long getObjectId() { + return objectId; + } + + public void setObjectId(long objectId) { + this.objectId = objectId; + } + +} diff --git a/src/services/sui/SUIService.java b/src/services/sui/SUIService.java index 1a7bb121..5d1c494a 100644 --- a/src/services/sui/SUIService.java +++ b/src/services/sui/SUIService.java @@ -23,6 +23,7 @@ package services.sui; import java.nio.ByteOrder; import java.util.Map; +import java.util.Map.Entry; import java.util.Random; import java.util.Vector; import java.util.concurrent.ConcurrentHashMap; @@ -148,13 +149,13 @@ public class SUIService implements INetworkDispatch { PyObject func = window.getFunctionByEventId(suiEvent.getEventType()); - if(func == null) - return; - - func.__call__(Py.java2py(core), Py.java2py(owner), Py.java2py(suiEvent.getEventType()), Py.java2py(suiEvent.getReturnList())); + if(func != null) + func.__call__(Py.java2py(core), Py.java2py(owner), Py.java2py(suiEvent.getEventType()), Py.java2py(suiEvent.getReturnList())); SUICallback callback = window.getCallbackByEventId(suiEvent.getEventType()); - callback.process(owner, suiEvent.getEventType(), suiEvent.getReturnList()); + + if(callback != null) + callback.process(owner, suiEvent.getEventType(), suiEvent.getReturnList()); windowMap.remove(window.getWindowId()); @@ -219,7 +220,7 @@ public class SUIService implements INetworkDispatch { } - public SUIWindow createListBox(int type, String title, String promptText, Vector data, SWGObject owner, SWGObject rangeObject, float maxDistance) { + public SUIWindow createListBox(int type, String title, String promptText, Map cloneData, SWGObject owner, SWGObject rangeObject, float maxDistance) { SUIWindow window = createSUIWindow("Script.listBox", owner, rangeObject, maxDistance); @@ -244,15 +245,17 @@ public class SUIService implements INetworkDispatch { window.clearDataSource("List.dataList"); - int index = 0; + //int index = 0; - for(String string : data) { + for(Entry e : cloneData.entrySet()) { - window.addDataItem("List.dataList:Name", String.valueOf(index)); + /*window.addDataItem("List.dataList:Name", String.valueOf(index)); - window.setProperty("List.dataList" + index + ":Text", string); + window.setProperty("List.dataList." + index + ":Text", string); - ++index; + ++index;*/ + + window.addListBoxMenuItem(e.getValue(), e.getKey()); } diff --git a/src/services/sui/SUIWindow.java b/src/services/sui/SUIWindow.java index f03c0b4f..dd256ae2 100644 --- a/src/services/sui/SUIWindow.java +++ b/src/services/sui/SUIWindow.java @@ -39,7 +39,7 @@ public class SUIWindow { private Vector components = new Vector(); private Map callbacks = new ConcurrentHashMap(); private Map javaCallbacks = new ConcurrentHashMap(); - + private Vector menuItems = new Vector(); public SUIWindow(String script, SWGObject owner, int windowId, SWGObject rangeObject, float maxDistance) { @@ -153,6 +153,17 @@ public class SUIWindow { components.add(component); } + + public void addListBoxMenuItem(String itemName, long objectId) { + SUIListBoxItem menuItem = new SUIListBoxItem(itemName, objectId); + + int index = menuItems.size(); + + addDataItem("List.dataList:Name", String.valueOf(index)); + setProperty("List.dataList." + index + ":Text", itemName); + + menuItems.add(menuItem); + } public int getWindowId() { @@ -211,6 +222,18 @@ public class SUIWindow { return javaCallbacks.get(eventId); } + public Vector getMenuItems() { + return menuItems; + } + + public long getObjectIdByIndex(int index) { + SUIListBoxItem item = getMenuItems().get(index); + + if(item != null) + return item.getObjectId(); + + return 0; + } public enum Trigger {; public static byte TRIGGER_UPDATE = 4; diff --git a/src/services/sui/SUIWindowComponent.java b/src/services/sui/SUIWindowComponent.java index fa5bac02..4a1c3a73 100644 --- a/src/services/sui/SUIWindowComponent.java +++ b/src/services/sui/SUIWindowComponent.java @@ -28,7 +28,6 @@ public class SUIWindowComponent { private byte type; private Vector narrowParams = new Vector(); private Vector wideParams = new Vector(); - private long objectId; public byte getType() { return type; @@ -48,12 +47,6 @@ public class SUIWindowComponent { public void setWideParams(Vector wideParams) { this.wideParams = wideParams; } - public long getObjectId() { - return objectId; - } - public void setObjectId(long objectId) { - this.objectId = objectId; - } }