diff --git a/src/intents/sui/SuiWindowIntent.java b/src/intents/sui/SuiWindowIntent.java new file mode 100644 index 00000000..dcb68c79 --- /dev/null +++ b/src/intents/sui/SuiWindowIntent.java @@ -0,0 +1,29 @@ +package intents.sui; + +import resources.control.Intent; +import resources.player.Player; +import resources.sui.SuiWindow; + +public class SuiWindowIntent extends Intent { + public static final String TYPE = "SuiWindowIntent"; + + private SuiWindow window; + private Player player; + private SuiWindowEvent event; + + public SuiWindowIntent(Player player, SuiWindow window, SuiWindowEvent event) { + super(TYPE); + this.player = player; + this.window = window; + this.event = event; + } + + public SuiWindow getWindow() { return this.window; } + public Player getPlayer() { return this.player; } + public SuiWindowEvent getEvent() { return event; } + + public enum SuiWindowEvent { + NEW, + UPDATE; + } +} diff --git a/src/resources/sui/SuiMessageBox.java b/src/resources/sui/SuiMessageBox.java new file mode 100644 index 00000000..ef9f2d74 --- /dev/null +++ b/src/resources/sui/SuiMessageBox.java @@ -0,0 +1,45 @@ +package resources.sui; + +import resources.player.Player; + +public class SuiMessageBox extends SuiWindow { + + public SuiMessageBox(Player owner, MessageBoxType type, String title, String prompt) { + super("Script.messageBox", owner); + + setProperty("bg.caption.lblTitle:Text", title); + setProperty("Prompt.lblPrompt:Text", prompt); + + switch(type) { + case OK: + setProperty("btnOk:visible", "True"); + setProperty("btnOk:Text", "@ok"); + setProperty("btnCancel:visible", "False"); + break; + case OK_CANCEL: + setProperty("btnOk:visible", "True"); + setProperty("btnCancel:visible", "True"); + setProperty("btnOk:Text", "@ok"); + setProperty("btnCancel:Text", "@cancel"); + break; + case YES_NO: + setProperty("btnOk:visible", "True"); + setProperty("btnCancel:visible", "True"); + setProperty("btnOk:Text", "@yes"); + setProperty("btnCancel:Text", "@no"); + break; + default: break; + } + } + + public SuiMessageBox(Player owner, String title, String prompt) { + this(owner, MessageBoxType.OK_CANCEL, title, prompt); + } + + public enum MessageBoxType { + OK, + OK_CANCEL, + YES_NO, + DEFAULT; + } +} diff --git a/src/resources/sui/SuiWindow.java b/src/resources/sui/SuiWindow.java index 32fe21be..06319f4d 100644 --- a/src/resources/sui/SuiWindow.java +++ b/src/resources/sui/SuiWindow.java @@ -1,5 +1,8 @@ package resources.sui; +import intents.sui.SuiWindowIntent; +import intents.sui.SuiWindowIntent.SuiWindowEvent; + import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -18,13 +21,12 @@ public class SuiWindow { //private Map scriptCallbacks; private Map javaCallbacks; - public SuiWindow(int id, String script, Player owner) { - this.id = id; + public SuiWindow(String script, Player owner) { this.script = script; this.owner = owner; } - public void addCallback(int eventId, String source, byte trigger, List returnParams, ISuiCallback callback) { + public final void addCallback(int eventId, String source, byte trigger, List returnParams, ISuiCallback callback) { SuiWindowComponent component = new SuiWindowComponent(); component.setType((byte) 5); component.getNarrowParams().add(source); @@ -41,7 +43,7 @@ public class SuiWindow { javaCallbacks.put(eventId, callback); } - public void setProperty(String property, String value) { + public final void setProperty(String property, String value) { SuiWindowComponent component = new SuiWindowComponent(); component.setType((byte) 3); @@ -53,14 +55,19 @@ public class SuiWindow { components.add(component); } - public long getRangeObjId() { return rangeObjId; } - public void setRangeObjId(long rangeObjId) { this.rangeObjId = rangeObjId; } - public int getId() { return id; } - public String getScript() { return script; } - public Player getOwner() { return owner; } - public float getMaxDistance() { return maxDistance; } - public void setMaxDistance(float maxDistance) { this.maxDistance = maxDistance; } + public final void display() { new SuiWindowIntent(owner, this, SuiWindowEvent.NEW).broadcast(); } + public final void display(Player player) { new SuiWindowIntent(player, this, SuiWindowEvent.NEW).broadcast();} + public final long getRangeObjId() { return rangeObjId; } + public final void setRangeObjId(long rangeObjId) { this.rangeObjId = rangeObjId; } + public final int getId() { return id; } + public final void setId(int id) { this.id = id; } + public final String getScript() { return script; } + public final Player getOwner() { return owner; } + public final float getMaxDistance() { return maxDistance; } + public final void setMaxDistance(float maxDistance) { this.maxDistance = maxDistance; } + public final List getComponents() { return components; } + public enum Trigger {; public static byte UPDATE = 4; public static byte OK = 9; diff --git a/src/services/sui/SuiService.java b/src/services/sui/SuiService.java index 90ee72cd..177e8c96 100644 --- a/src/services/sui/SuiService.java +++ b/src/services/sui/SuiService.java @@ -1,20 +1,68 @@ package services.sui; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import network.packets.swg.zone.server_ui.SuiCreatePageMessage; +import network.packets.swg.zone.server_ui.SuiEventNotification; +import intents.GalacticPacketIntent; +import intents.sui.SuiWindowIntent; +import intents.sui.SuiWindowIntent.SuiWindowEvent; import resources.control.Intent; import resources.control.Service; +import resources.player.Player; +import resources.sui.SuiWindow; public class SuiService extends Service { + private Map windows; + private int maxWindowId; + + public SuiService() { + windows = new ConcurrentHashMap(); + maxWindowId = 0; + } + @Override public boolean initialize() { - // TODO Auto-generated method stub + registerForIntent(GalacticPacketIntent.TYPE); + registerForIntent(SuiWindowIntent.TYPE); return super.initialize(); } @Override public void onIntentReceived(Intent i) { - + if (i instanceof SuiWindowIntent) + handleSuiWindowIntent((SuiWindowIntent) i); + else if (i instanceof GalacticPacketIntent) { + if (((GalacticPacketIntent) i).getPacket() instanceof SuiEventNotification) { + long netId = ((GalacticPacketIntent) i).getNetworkId(); + Player player = ((GalacticPacketIntent) i).getPlayerManager().getPlayerFromNetworkId(netId); + handleSuiEventNotification(player, (SuiEventNotification) (((GalacticPacketIntent) i).getPacket())); + } + } } - + private void handleSuiWindowIntent(SuiWindowIntent i) { + if (i.getEvent() == SuiWindowEvent.NEW) + displayWindow(i.getPlayer(), i.getWindow()); + } + + private void handleSuiEventNotification(Player player, SuiEventNotification r) { + // TODO: SUI Events + } + + private void displayWindow(Player player, SuiWindow wnd) { + int id = getNextWindowId(); + wnd.setId(id); + + SuiCreatePageMessage packet = new SuiCreatePageMessage(id, wnd.getScript(), wnd.getComponents(), player.getCreatureObject().getObjectId(), wnd.getMaxDistance()); + player.sendPacket(packet); + + windows.put(id, wnd); + } + + private int getNextWindowId() { + return maxWindowId++; + } }