From 6c3a8f04db0909b8c7f3924347c7643dff72f8e0 Mon Sep 17 00:00:00 2001 From: Light2 Date: Tue, 9 Jul 2013 19:38:36 +0200 Subject: [PATCH] Added SUI windows, added bank --- scripts/radial/bank.py | 48 +++ src/main/NGECore.java | 1 - src/protocol/swg/SUICreatePageMessage.java | 330 +++--------------- src/protocol/swg/SUIEventNotification.java | 104 ++++++ .../swg/SUIForceClosePageMessage.java | 2 +- src/protocol/swg/SUIUpdatePageMessage.java | 94 +++++ src/resources/common/Opcodes.java | 3 +- .../creature/CreatureMessageBuilder.java | 25 ++ .../objects/creature/CreatureObject.java | 6 + src/services/sui/SUIService.java | 234 +++++++++++++ src/services/sui/SUIWindow.java | 167 ++++++++- src/services/sui/SUIWindowComponent.java | 52 +++ 12 files changed, 767 insertions(+), 299 deletions(-) create mode 100644 src/protocol/swg/SUIEventNotification.java create mode 100644 src/protocol/swg/SUIUpdatePageMessage.java create mode 100644 src/services/sui/SUIWindowComponent.java diff --git a/scripts/radial/bank.py b/scripts/radial/bank.py index 4fe4097e..96f528e1 100644 --- a/scripts/radial/bank.py +++ b/scripts/radial/bank.py @@ -1,4 +1,7 @@ from resources.common import RadialOptions +from services.sui import SUIWindow +from services.sui.SUIWindow import Trigger +from java.util import Vector import sys def createRadial(core, owner, target, radials): @@ -22,6 +25,51 @@ def handleSelection(core, owner, target, option): bank = owner.getSlottedObject('bank') if bank: core.simulationService.openContainer(owner, bank) + if option == RadialOptions.bankTransfer: + suiSvc = core.suiService + suiWindow = suiSvc.createSUIWindow('Script.transfer', owner, target, 10) + suiWindow.setProperty('transaction.txtInputFrom:Text', 'From') + suiWindow.setProperty('transaction.txtInputFrom:Text', 'From') + suiWindow.setProperty('bg.caption.lblTitle:Text', '@base_player:bank_title') + suiWindow.setProperty('Prompt.lblPrompt:Text', '@base_player:bank_prompt') + suiWindow.setProperty('transaction.txtInputTo:Text', 'To') + suiWindow.setProperty('transaction.lblFrom:Text', 'Cash') + suiWindow.setProperty('transaction.lblTo:Text', 'Bank') + suiWindow.setProperty('transaction.lblStartingFrom:Text', str(owner.getCashCredits())) + suiWindow.setProperty('transaction.lblStartingTo:Text', str(owner.getBankCredits())) + suiWindow.setProperty('transaction.txtInputFrom:Text', str(owner.getCashCredits())) + suiWindow.setProperty('transaction.txtInputTo:Text', str(owner.getBankCredits())) + suiWindow.setProperty('transaction:ConversionRatioFrom', '1') + suiWindow.setProperty('transaction:ConversionRatioTo', '1') + returnParams = Vector() + returnParams.add('transaction.txtInputFrom:Text') + returnParams.add('transaction.txtInputTo:Text') + suiWindow.addHandler(0, '', Trigger.TRIGGER_OK, returnParams, handleTransfer) + suiWindow.addHandler(1, '', Trigger.TRIGGER_CANCEL, returnParams, handleTransfer) + + suiSvc.openSUIWindow(suiWindow) + if option == RadialOptions.bankWithdrawAll: + withdrawAmount = owner.getBankCredits() + owner.setCashCredits(withdrawAmount + owner.getCashCredits()) + owner.setBankCredits(0) + owner.sendSystemMessage('You successfully withdraw ' + str(withdrawAmount) + ' credits from your account.', 0) + if option == RadialOptions.bankDepositAll: + depositAmount = owner.getCashCredits() + owner.setBankCredits(depositAmount + owner.getBankCredits()) + owner.setCashCredits(0) + owner.sendSystemMessage('You successfully deposit ' + str(depositAmount) + ' credits to your account.', 0) return + +def handleTransfer(core, owner, eventType, returnList): + + if eventType == 0 and len(returnList) == 2: + cashCredits = int(returnList.get(0)) + bankCredits = int(returnList.get(1)) + + if bankCredits + cashCredits == owner.getCashCredits() + owner.getBankCredits(): + owner.setCashCredits(cashCredits) + owner.setBankCredits(bankCredits) + owner.sendSystemMessage('@base_player:bank_success', 0) + return \ No newline at end of file diff --git a/src/main/NGECore.java b/src/main/NGECore.java index 019aacfa..0a395ead 100644 --- a/src/main/NGECore.java +++ b/src/main/NGECore.java @@ -179,7 +179,6 @@ public class NGECore { didServerCrash = false; System.out.println("Started Server."); - } diff --git a/src/protocol/swg/SUICreatePageMessage.java b/src/protocol/swg/SUICreatePageMessage.java index bc72aafd..4bbfe4eb 100644 --- a/src/protocol/swg/SUICreatePageMessage.java +++ b/src/protocol/swg/SUICreatePageMessage.java @@ -23,283 +23,37 @@ package protocol.swg; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.util.Vector; import org.apache.mina.core.buffer.IoBuffer; +import engine.resources.common.Utilities; + +import services.sui.SUIWindowComponent; + public class SUICreatePageMessage extends SWGMessage{ private String script; - private byte[] header; - private int optionCount; private int windowId; - private byte[] body; - private long objectId; + private Vector components; + private long rangeObjectId; + private float range; - - public SUICreatePageMessage() { + public SUICreatePageMessage(String script, int windowId, Vector components, long rangeObjectId, float range) { - ByteBuffer result = ByteBuffer.allocate(6).order(ByteOrder.LITTLE_ENDIAN); - - - - - - /* - result.putShort((short) 2); - result.putInt(0xD44B7259); // CRC - result.putInt(0x00F85E88); //I'm gonna guess this is an ID of sorts. - result.put(getAsciiString("Script.transfer")); // change this to Script.InputBox and look at the things you can select lol - - result.putInt(8); //list size/number of lists - - //---------------------1 - - - - result.put((byte)5); - result.putInt(0); //counter I think. - - - result.putInt(3); //list size - result.putShort((short) 0); - result.putShort((short) 1); // unks - result.put((byte) 9); - result.put(getAsciiString("handleSUI")); - - //---------------------2 - - - - result.put((byte)5); - result.putInt(0); //counter I think. - - - result.putInt(3); //list size - result.putShort((short) 0); - result.putShort((short) 1); // unks - result.put((byte) 0x0A); - result.put(getAsciiString("handleSUI")); - - - //--------------------------- 3 - result.put((byte)3); - result.putInt(1); //counter I think - result.put(getUnicodeString("@travel:ticket_purchase_complete")); - - result.putInt(2); //counter I think - result.put(getAsciiString("Prompt.lblPrompt")); - result.put(getAsciiString("Text")); - - - - - //--------------------------- 4 - result.put((byte)3); - result.putInt(1); //counter I think - result.put(getUnicodeString("@base_player:swg")); - - result.putInt(2); //counter I think - result.put(getAsciiString("bg.caption.lblTitle")); - result.put(getAsciiString("Text")); - - - - //--------------------------- 5 - result.put((byte)3); - result.putInt(1); //counter I think - result.put(getUnicodeString("True")); - - result.putInt(2); //counter I think - result.put(getAsciiString("btnCancel")); - result.put(getAsciiString("Enabled")); - - //--------------------------- 6 - result.put((byte)3); - result.putInt(1); //counter I think - result.put(getUnicodeString("False")); - - result.putInt(2); //counter I think - result.put(getAsciiString("btnCancel")); - result.put(getAsciiString("Visible")); - - - - - //--------------------------- 7 - result.put((byte)4); - result.putInt(1); - result.put(getUnicodeString("False")); - result.putInt(2); //counter I think - result.put(getAsciiString("btnRevert")); - result.put(getAsciiString("Enabled")); - - //--------------------------- 8 - result.put((byte)3); - result.putInt(1); - result.put(getUnicodeString("False")); - result.putInt(2); //counter I think - result.put(getAsciiString("btnRevert")); - result.put(getAsciiString("Visible")); - - - //I dunno what these are/do. - result.putLong(0); - - result.putInt(0x7F7FFFFF); - result.putInt(0x7F7FFFFF); - result.putInt(0x7F7FFFFF); - result.putInt(0); - */ - - - result.putShort((short) 2); - result.putInt(0xD44B7259); // CRC - - - - data = result.array(); - - - - } - - public void addHeader(String handler, String[] options, int windowId, String script, long objectId) { - - - this.windowId = windowId; this.script = script; - this.objectId = objectId; - - if(options != null) { - ByteBuffer result = ByteBuffer.allocate((18 + handler.length() + options.length) * 2).order(ByteOrder.LITTLE_ENDIAN); - result.put((byte) 5); - result.putInt(0); - int counter = 0; - for (int i = 0; i < options.length; i ++){ - if (options[i] != null) { - counter ++; - } - - } - result.putInt(counter+3); - result.putShort((short) 0); - result.putShort((short) 1); - result.put((byte) 0x09); - result.put(getAsciiString(handler)); - for (int i = 0; i < options.length; i ++){ - if (options[i] != null) { - result.put(getAsciiString(options[i])); - } - - } - - result.put((byte) 5); - result.putInt(0); - - result.putInt(counter+3); - result.putShort((short) 0); - result.putShort((short) 1); - result.put((byte) 0x0A); - result.put(getAsciiString(handler)); - for (int i = 0; i < options.length; i ++){ - if (options[i] != null) { - result.put(getAsciiString(options[i])); - } - - } - - - if (header == null) - header = result.array(); - else - header = ByteBuffer.allocate(header.length + result.capacity()) - .put(header) - .put(result.array()) - .array(); - optionCount++; - } - - else { - ByteBuffer result = ByteBuffer.allocate((16 + handler.length()) * 2).order(ByteOrder.LITTLE_ENDIAN); - result.put((byte) 5); - result.putInt(0); - - result.putInt(3); - result.putShort((short) 0); - result.putShort((short) 1); - result.put((byte) 0x09); - result.put(getAsciiString(handler)); - - - result.put((byte) 5); - result.putInt(0); - - result.putInt(3); - result.putShort((short) 0); - result.putShort((short) 1); - result.put((byte) 0x0A); - result.put(getAsciiString(handler)); - - - - header = result.array(); - optionCount++; - optionCount++; - - } - + this.windowId = windowId; + this.components = components; + this.rangeObjectId = rangeObjectId; + this.range = range; + } + + + - public void addBodyElement(byte type, String wideParameter, String narrowParameterVariable, String narrowParameterSetting) { - - - - if(type == 3 || type == 4) { - ByteBuffer result = ByteBuffer.allocate(17 + wideParameter.length() * 2 + narrowParameterVariable.length() + narrowParameterSetting.length()).order(ByteOrder.LITTLE_ENDIAN); - - - result.put(type); - result.putInt(1); - result.put(getUnicodeString(wideParameter)); - result.putInt(2); - result.put(getAsciiString(narrowParameterVariable)); - result.put(getAsciiString(narrowParameterSetting)); - - if (body == null) - body = result.array(); - else - body = ByteBuffer.allocate(body.length + result.capacity()) - .put(body) - .put(result.array()) - .array(); - optionCount++; - - - } - - else { - ByteBuffer result = ByteBuffer.allocate(13 + wideParameter.length() * 2).order(ByteOrder.LITTLE_ENDIAN); - - result.put(type); - result.putInt(0); - result.putInt(1); - result.put(getUnicodeString(wideParameter)); - - if (body == null) - body = result.array(); - else - body = ByteBuffer.allocate(body.length + result.capacity()) - .put(body) - .put(result.array()) - .array(); - optionCount++; - - - } - - } public void deserialize(IoBuffer data) { @@ -307,21 +61,41 @@ public class SUICreatePageMessage extends SWGMessage{ public IoBuffer serialize() { - IoBuffer result = IoBuffer.allocate(34 + data.length + header.length + body.length + script.length()).order(ByteOrder.LITTLE_ENDIAN); - result.put(data); - result.putInt(windowId); - result.put(getAsciiString(script)); - result.putInt(optionCount); //list size/number of lists - result.put(header); - result.put(body); - result.putLong(objectId); - result.putFloat(0); //range to object specified by objectId, if 0 range is unlimited - result.putLong(0); - /*result.putInt(0x7F7FFFFF); - result.putInt(0x7F7FFFFF); - result.putInt(0x7F7FFFFF); - result.putInt(0);*/ + IoBuffer result = IoBuffer.allocate(100).order(ByteOrder.LITTLE_ENDIAN); + result.setAutoExpand(true); - return result; + result.putShort((short) 2); + result.putInt(0xD44B7259); + + result.putInt(windowId); + result.put(getAsciiString(script)); + result.putInt(components.size()); + + for(SUIWindowComponent component : components) { + + result.put(component.getType()); + result.putInt(component.getWideParams().size()); + + for(String param : component.getWideParams()) { + result.put(getUnicodeString(param)); + } + + result.putInt(component.getNarrowParams().size()); + + for(String param : component.getNarrowParams()) { + result.put(getAsciiString(param)); + } + + } + + result.putLong(rangeObjectId); + result.putFloat(range); + result.putLong(0); + result.putInt(0); + + int size = result.position(); + result = IoBuffer.allocate(size).put(result.array(), 0, size); + + return result.flip(); } } diff --git a/src/protocol/swg/SUIEventNotification.java b/src/protocol/swg/SUIEventNotification.java new file mode 100644 index 00000000..8cbbf2a4 --- /dev/null +++ b/src/protocol/swg/SUIEventNotification.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * 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 protocol.swg; + +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; +import java.util.Vector; + +import org.apache.mina.core.buffer.IoBuffer; + +public class SUIEventNotification extends SWGMessage { + + private int windowId; + private int eventType; + private int updateCounter; + private Vector returnList = new Vector(); + + @Override + public void deserialize(IoBuffer buffer) { + + buffer.getShort(); + buffer.getInt(); + + windowId = buffer.getInt(); + eventType = buffer.getInt(); + int count = buffer.getInt(); + updateCounter = buffer.getInt(); + + for(int i = 0; i < count; ++i) { + + int size = buffer.getInt(); + if(size > 0) { + + try { + returnList.add(new String(ByteBuffer.allocate(size * 2).put(buffer.array(), buffer.position(), size * 2).array(), "UTF-16LE")); + buffer.position(buffer.position() + size * 2); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + } + + } + + } + + @Override + public IoBuffer serialize() { + // TODO Auto-generated method stub + return null; + } + + public int getWindowId() { + return windowId; + } + + public void setWindowId(int windowId) { + this.windowId = windowId; + } + + public int getEventType() { + return eventType; + } + + public void setEventType(int eventType) { + this.eventType = eventType; + } + + public int getUpdateCounter() { + return updateCounter; + } + + public void setUpdateCounter(int updateCounter) { + this.updateCounter = updateCounter; + } + + public Vector getReturnList() { + return returnList; + } + + public void setReturnList(Vector returnList) { + this.returnList = returnList; + } + +} diff --git a/src/protocol/swg/SUIForceClosePageMessage.java b/src/protocol/swg/SUIForceClosePageMessage.java index b014ce46..702d6294 100644 --- a/src/protocol/swg/SUIForceClosePageMessage.java +++ b/src/protocol/swg/SUIForceClosePageMessage.java @@ -44,6 +44,6 @@ public class SUIForceClosePageMessage extends SWGMessage { result.putInt(0x990B5DE0); result.putInt(windowId); - return result; + return result.flip(); } } diff --git a/src/protocol/swg/SUIUpdatePageMessage.java b/src/protocol/swg/SUIUpdatePageMessage.java new file mode 100644 index 00000000..af733a2c --- /dev/null +++ b/src/protocol/swg/SUIUpdatePageMessage.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * 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 protocol.swg; + +import java.nio.ByteOrder; +import java.util.Vector; + +import org.apache.mina.core.buffer.IoBuffer; + +import services.sui.SUIWindowComponent; + +public class SUIUpdatePageMessage extends SWGMessage { + + private String script; + private int windowId; + private Vector components; + private long rangeObjectId; + private float range; + + + public SUIUpdatePageMessage(String script, int windowId, Vector components, long rangeObjectId, float range) { + + this.script = script; + this.windowId = windowId; + this.components = components; + this.rangeObjectId = rangeObjectId; + this.range = range; + + } + + public void deserialize(IoBuffer data) { + + } + + public IoBuffer serialize() { + + IoBuffer result = IoBuffer.allocate(100).order(ByteOrder.LITTLE_ENDIAN); + result.setAutoExpand(true); + + result.putShort((short) 2); + result.putInt(0x5F3342F6); + + result.putInt(windowId); + result.put(getAsciiString(script)); + result.putInt(components.size()); + + for(SUIWindowComponent component : components) { + + result.put(component.getType()); + result.putInt(component.getWideParams().size()); + + for(String param : component.getWideParams()) { + result.put(getUnicodeString(param)); + } + + result.putInt(component.getNarrowParams().size()); + + for(String param : component.getNarrowParams()) { + result.put(getAsciiString(param)); + } + + } + + result.putLong(rangeObjectId); + result.putFloat(range); + result.putLong(0); + result.putInt(0); + + int size = result.position(); + result = IoBuffer.allocate(size).put(result.array(), 0, size); + + return result.flip(); + } + +} diff --git a/src/resources/common/Opcodes.java b/src/resources/common/Opcodes.java index cbe41e47..a84429ad 100644 --- a/src/resources/common/Opcodes.java +++ b/src/resources/common/Opcodes.java @@ -42,5 +42,6 @@ public class Opcodes { public static int ObjectSelectMenuMessage = 0x7CA18726; public static int RequestGalaxyLoopTimes = 0x7D842D68; public static int SelectCharacter = 0xB5098D76; - + public static int SuiEventNotification = 0x092D3564; + } diff --git a/src/resources/objects/creature/CreatureMessageBuilder.java b/src/resources/objects/creature/CreatureMessageBuilder.java index 0fa477a8..7f8daad4 100644 --- a/src/resources/objects/creature/CreatureMessageBuilder.java +++ b/src/resources/objects/creature/CreatureMessageBuilder.java @@ -402,6 +402,31 @@ public class CreatureMessageBuilder extends ObjectMessageBuilder { } + public IoBuffer buildCashCreditsDelta(int credits) { + + IoBuffer buffer = bufferPool.allocate(4, false).order(ByteOrder.LITTLE_ENDIAN); + buffer.putInt(credits); + int size = buffer.position(); + buffer.flip(); + buffer = createDelta("CREO", (byte) 1, (short) 1, (short) 1, buffer, size + 4); + + return buffer; + + } + + public IoBuffer buildBankCreditsDelta(int credits) { + + IoBuffer buffer = bufferPool.allocate(4, false).order(ByteOrder.LITTLE_ENDIAN); + buffer.putInt(credits); + int size = buffer.position(); + buffer.flip(); + buffer = createDelta("CREO", (byte) 1, (short) 1, (short) 0, buffer, size + 4); + + return buffer; + + } + + public IoBuffer buildPostureDelta(byte posture) { IoBuffer buffer = bufferPool.allocate(1, false).order(ByteOrder.LITTLE_ENDIAN); diff --git a/src/resources/objects/creature/CreatureObject.java b/src/resources/objects/creature/CreatureObject.java index c9e235da..2b33fe5b 100644 --- a/src/resources/objects/creature/CreatureObject.java +++ b/src/resources/objects/creature/CreatureObject.java @@ -159,6 +159,9 @@ public class CreatureObject extends SWGObject implements IPersistent { synchronized(objectMutex) { this.bankCredits = bankCredits; } + if(getClient() != null && getClient().getSession() != null) { + getClient().getSession().write(messageBuilder.buildBankCreditsDelta(bankCredits)); + } } public int getCashCredits() { @@ -171,6 +174,9 @@ public class CreatureObject extends SWGObject implements IPersistent { synchronized(objectMutex) { this.cashCredits = cashCredits; } + if(getClient() != null && getClient().getSession() != null) { + getClient().getSession().write(messageBuilder.buildCashCreditsDelta(cashCredits)); + } } public List getSkills() { diff --git a/src/services/sui/SUIService.java b/src/services/sui/SUIService.java index d0a8af16..2bfa9da4 100644 --- a/src/services/sui/SUIService.java +++ b/src/services/sui/SUIService.java @@ -23,15 +23,23 @@ package services.sui; import java.nio.ByteOrder; import java.util.Map; +import java.util.Random; import java.util.Vector; +import java.util.concurrent.ConcurrentHashMap; import main.NGECore; import org.apache.mina.core.buffer.IoBuffer; import org.apache.mina.core.session.IoSession; +import org.python.core.Py; +import org.python.core.PyObject; import protocol.swg.ObjControllerMessage; import protocol.swg.ObjectMenuSelect; +import protocol.swg.SUICreatePageMessage; +import protocol.swg.SUIEventNotification; +import protocol.swg.SUIForceClosePageMessage; +import protocol.swg.SUIUpdatePageMessage; import protocol.swg.objectControllerObjects.ObjectMenuRequest; import protocol.swg.objectControllerObjects.ObjectMenuResponse; @@ -47,6 +55,7 @@ import engine.resources.service.INetworkRemoteEvent; public class SUIService implements INetworkDispatch { private NGECore core; + private Map windowMap = new ConcurrentHashMap(); public SUIService(NGECore core) { this.core = core; @@ -110,6 +119,44 @@ public class SUIService implements INetworkDispatch { }); + swgOpcodes.put(Opcodes.SuiEventNotification, new INetworkRemoteEvent() { + + @Override + public void handlePacket(IoSession session, IoBuffer data) throws Exception { + + data.order(ByteOrder.LITTLE_ENDIAN); + data.position(0); + + SUIEventNotification suiEvent = new SUIEventNotification(); + suiEvent.deserialize(data); + + SUIWindow window = getWindowById(suiEvent.getWindowId()); + + if(window == null) + return; + + Client client = core.getClient((Integer) session.getAttribute("connectionId")); + + if(client == null || client.getSession() == null) + return; + + SWGObject owner = client.getParent(); + + if(owner == null) + return; + + 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())); + + windowMap.remove(window.getWindowId()); + + } + + }); } @Override @@ -137,4 +184,191 @@ public class SUIService implements INetworkDispatch { owner.getClient().getSession().write(objController.serialize()); } + public Map getWindowMap() { + return windowMap; + } + + public SUIWindow getWindowById(int id) { + if(windowMap.containsKey(id)) + return windowMap.get(id); + return null; + } + + public int createWindowId() { + + Random rand = new Random(); + + int id = rand.nextInt(); + + if(windowMap.containsKey(id)) + return createWindowId(); + + return id; + + } + + public SUIWindow createSUIWindow(String script, SWGObject owner, SWGObject rangeObject, float maxDistance) { + + SUIWindow window = new SUIWindow(script, owner, createWindowId(), rangeObject, maxDistance); + windowMap.put(window.getWindowId(), window); + return window; + + } + + public SUIWindow createListBox(int type, String title, String promptText, Vector data, SWGObject owner, SWGObject rangeObject, float maxDistance) { + + SUIWindow window = createSUIWindow("Script.listBox", owner, rangeObject, maxDistance); + + window.setProperty("bg.caption.lblTitle:Text", title); + window.setProperty("Prompt.lblPrompt:Text", promptText); + + switch(type) { + + case ListBoxType.LIST_BOX_OK: + window.setProperty("btnOk:visible", "True"); + window.setProperty("btnOk:Text", "@ok"); + window.setProperty("btnCancel:visible", "False"); + break; + case ListBoxType.LIST_BOX_OK_CANCEL: + window.setProperty("btnOk:visible", "True"); + window.setProperty("btnCancel:visible", "True"); + window.setProperty("btnOk:Text", "@ok"); + window.setProperty("btnCancel:Text", "@cancel"); + break; + + } + + window.clearDataSource("List.dataList"); + + int index = 0; + + for(String string : data) { + + window.addDataItem("List.dataList:Name", String.valueOf(index)); + + window.setProperty("List.dataList" + index + ":Text", string); + + ++index; + + } + + return window; + + } + + public SUIWindow createMessageBox(int type, String title, String promptText, SWGObject owner, SWGObject rangeObject, float maxDistance) { + + SUIWindow window = createSUIWindow("Script.messageBox", owner, rangeObject, maxDistance); + + window.setProperty("bg.caption.lblTitle:Text", title); + window.setProperty("Prompt.lblPrompt:Text", promptText); + + window.setProperty("btnRevert:visible", "False"); + + switch(type) { + + case MessageBoxType.MESSAGE_BOX_OK: + window.setProperty("btnOk:visible", "True"); + window.setProperty("btnOk:Text", "@ok"); + window.setProperty("btnCancel:visible", "False"); + break; + case MessageBoxType.MESSAGE_BOX_OK_CANCEL: + window.setProperty("btnOk:visible", "True"); + window.setProperty("btnCancel:visible", "True"); + window.setProperty("btnOk:Text", "@ok"); + window.setProperty("btnCancel:Text", "@cancel"); + break; + case MessageBoxType.MESSAGE_BOX_YES_NO: + window.setProperty("btnOk:visible", "True"); + window.setProperty("btnCancel:visible", "True"); + window.setProperty("btnOk:Text", "@yes"); + window.setProperty("btnCancel:Text", "@no"); + break; + + } + + return window; + + } + + public void closeSUIWindow(SWGObject owner, int id) { + + if(owner.getClient() == null || owner.getClient().getSession() == null) + return; + + windowMap.remove(id); + + SUIForceClosePageMessage closeMsg = new SUIForceClosePageMessage(id); + owner.getClient().getSession().write(closeMsg.serialize()); + + } + + public void openSUIWindow(SUIWindow window) { + + SWGObject owner = window.getOwner(); + + if(owner == null) + return; + + if(owner.getClient() == null || owner.getClient().getSession() == null) + return; + + float range; + long rangeObjectId; + + if(window.getRangeObject() == null) { + range = 0; + rangeObjectId = 0; + } else { + range = window.getMaxDistance(); + rangeObjectId = window.getRangeObject().getObjectID(); + } + + SUICreatePageMessage create = new SUICreatePageMessage(window.getScript(), window.getWindowId(), window.getComponents(), rangeObjectId, range); + owner.getClient().getSession().write(create.serialize()); + + } + + public void updateSUIWindow(SUIWindow window) { + + SWGObject owner = window.getOwner(); + + if(owner == null) + return; + + if(owner.getClient() == null || owner.getClient().getSession() == null) + return; + + float range; + long rangeObjectId; + + if(window.getRangeObject() == null) { + range = 0; + rangeObjectId = 0; + } else { + range = window.getMaxDistance(); + rangeObjectId = window.getRangeObject().getObjectID(); + } + + SUIUpdatePageMessage update = new SUIUpdatePageMessage(window.getScript(), window.getWindowId(), window.getComponents(), rangeObjectId, range); + owner.getClient().getSession().write(update.serialize()); + + + } + + public enum ListBoxType {; + public static final int LIST_BOX_OK = 1; + public static final int LIST_BOX_OK_CANCEL = 2; + } + + public enum MessageBoxType {; + public static final int MESSAGE_BOX_OK = 1; + public static final int MESSAGE_BOX_OK_CANCEL = 2; + public static final int MESSAGE_BOX_YES_NO = 3; + } + + public enum InputBoxType {; + public static final int INPUT_BOX_OK = 1; + public static final int INPUT_BOX_OK_CANCEL = 2; + } } diff --git a/src/services/sui/SUIWindow.java b/src/services/sui/SUIWindow.java index 0a447d64..fcfea8c6 100644 --- a/src/services/sui/SUIWindow.java +++ b/src/services/sui/SUIWindow.java @@ -21,40 +21,171 @@ ******************************************************************************/ package services.sui; +import java.util.Map; +import java.util.Vector; +import java.util.concurrent.ConcurrentHashMap; + +import org.python.core.PyObject; + +import engine.clients.Client; import engine.clients.GameClient; +import engine.resources.objects.SWGObject; public class SUIWindow { - @SuppressWarnings("unused") private String script; - private GameClient client; + private SWGObject owner; private int windowId; - @SuppressWarnings("unused") - private int type; // this should link to a constant which describes which type of window we have i.e. Bank Deposit Window + private SWGObject rangeObject; + private float maxDistance = 0; + private Vector components = new Vector(); + private Map callbacks = new ConcurrentHashMap(); - - public SUIWindow(String script, GameClient client, int windowId, int type) { + public SUIWindow(String script, SWGObject owner, int windowId, SWGObject rangeObject, float maxDistance) { - this.script = script; - this.client = client; + this.setScript(script); + this.setOwner(owner); this.windowId = windowId; - this.type = type; + this.setRangeObject(rangeObject); + this.setMaxDistance(maxDistance); + + } + + public void clearDataSource(String name) { + + SUIWindowComponent component = new SUIWindowComponent(); + component.setType((byte) 1); + + component.getNarrowParams().add(name); + + components.add(component); + + } + + public void setProperty(String name, String value) { + + SUIWindowComponent component = new SUIWindowComponent(); + component.setType((byte) 3); + + for(String str : name.split(":")) { + component.getNarrowParams().add(str); + } + + component.getWideParams().add(value); + + components.add(component); + + } + public void addDataItem(String name, String value) { + + SUIWindowComponent component = new SUIWindowComponent(); + component.setType((byte) 4); + + for(String str : name.split(":")) { + component.getNarrowParams().add(str); + } + + component.getWideParams().add(value); + + components.add(component); + + } + + public void addHandler(int eventId, String source, byte trigger, Vector returnParams, PyObject handleFunc) { + + SUIWindowComponent component = new SUIWindowComponent(); + component.setType((byte) 5); + + component.getNarrowParams().add(source); + + component.getNarrowParams().add(new String(new byte[] { trigger })); + component.getNarrowParams().add("handleSUI"); + + for(String returnParam : returnParams) { + + for(String str : returnParam.split(":")) { + component.getNarrowParams().add(str); + } + + } + + components.add(component); + callbacks.put(eventId, handleFunc); + + } + + public void addDataSource(String name, String value) { + + SUIWindowComponent component = new SUIWindowComponent(); + component.setType((byte) 6); + + for(String str : name.split(":")) { + component.getNarrowParams().add(str); + } + + component.getWideParams().add(value); + + components.add(component); } - - public GameClient getClient() { - - return client; - } - - - - public int getwindowId() { + public int getWindowId() { return windowId; } + + public String getScript() { + return script; + } + + public void setScript(String script) { + this.script = script; + } + + public SWGObject getOwner() { + return owner; + } + + public void setOwner(SWGObject owner) { + this.owner = owner; + } + + public SWGObject getRangeObject() { + return rangeObject; + } + + public void setRangeObject(SWGObject rangeObject) { + this.rangeObject = rangeObject; + } + + public float getMaxDistance() { + return maxDistance; + } + + public void setMaxDistance(float maxDistance) { + this.maxDistance = maxDistance; + } + + public Vector getComponents() { + return components; + } + + public void setComponents(Vector components) { + this.components = components; + } + + public PyObject getFunctionByEventId(int eventId) { + return callbacks.get(eventId); + } + + public enum Trigger {; + public static byte TRIGGER_UPDATE = 4; + public static byte TRIGGER_OK = 9; + public static byte TRIGGER_CANCEL = 10; + + } + } diff --git a/src/services/sui/SUIWindowComponent.java b/src/services/sui/SUIWindowComponent.java new file mode 100644 index 00000000..4a1c3a73 --- /dev/null +++ b/src/services/sui/SUIWindowComponent.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * 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; + +import java.util.Vector; + +public class SUIWindowComponent { + + private byte type; + private Vector narrowParams = new Vector(); + private Vector wideParams = new Vector(); + + public byte getType() { + return type; + } + public void setType(byte type) { + this.type = type; + } + public Vector getNarrowParams() { + return narrowParams; + } + public void setNarrowParams(Vector narrowParams) { + this.narrowParams = narrowParams; + } + public Vector getWideParams() { + return wideParams; + } + public void setWideParams(Vector wideParams) { + this.wideParams = wideParams; + } + + +}