Fixed SUI List Boxes, added clone window

This commit is contained in:
Light2
2013-09-17 22:51:03 +02:00
parent ee43b34757
commit b676dffdec
9 changed files with 149 additions and 35 deletions
@@ -1,4 +1,6 @@
import sys
def setup(core, object):
return
return
+8 -8
View File
@@ -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)
+45 -3
View File
@@ -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<SWGObject> cloners = core.staticService.getCloningFacilitiesByPlanet(creature.getPlanet());
Vector<String> cloneData = new Vector<String>();
Map<Long, String> cloneData = new HashMap<Long, String>();
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<String> returnList = new Vector<String>();
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<String> 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<SpawnPoint> spawnPoints = (Vector<SpawnPoint>) 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
+4 -3
View File
@@ -106,10 +106,11 @@ public class StaticService implements INetworkDispatch {
List<SWGObject> cloners = new ArrayList<SWGObject>();
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;
}
+1 -1
View File
@@ -132,7 +132,7 @@ public class MapService implements INetworkDispatch {
}
}
return closestName;
}
+50
View File
@@ -0,0 +1,50 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* 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 <http://www.gnu.org/licenses/>.
*
* 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;
}
}
+14 -11
View File
@@ -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<String> data, SWGObject owner, SWGObject rangeObject, float maxDistance) {
public SUIWindow createListBox(int type, String title, String promptText, Map<Long, String> 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<Long, String> 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());
}
+24 -1
View File
@@ -39,7 +39,7 @@ public class SUIWindow {
private Vector<SUIWindowComponent> components = new Vector<SUIWindowComponent>();
private Map<Integer, PyObject> callbacks = new ConcurrentHashMap<Integer, PyObject>();
private Map<Integer, SUICallback> javaCallbacks = new ConcurrentHashMap<Integer, SUICallback>();
private Vector<SUIListBoxItem> menuItems = new Vector<SUIListBoxItem>();
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<SUIListBoxItem> 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;
-7
View File
@@ -28,7 +28,6 @@ public class SUIWindowComponent {
private byte type;
private Vector<String> narrowParams = new Vector<String>();
private Vector<String> wideParams = new Vector<String>();
private long objectId;
public byte getType() {
return type;
@@ -48,12 +47,6 @@ public class SUIWindowComponent {
public void setWideParams(Vector<String> wideParams) {
this.wideParams = wideParams;
}
public long getObjectId() {
return objectId;
}
public void setObjectId(long objectId) {
this.objectId = objectId;
}
}