package NET.worlds.console; import NET.worlds.core.IniFile; import NET.worlds.scape.Pilot; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Event; import java.awt.Panel; public class WhisperDialog extends PolledDialog { private static final long serialVersionUID = -5767168735798633258L; protected static java.awt.Window parent; protected boolean building; protected boolean isTrading = false; protected WhisperPart whisperPart; protected String partner; protected boolean isBroadcast; protected boolean built; protected static int counter = 0; protected static final int OFFSET = 20; protected static final int OFF_TOT = 6; static void setParent(java.awt.Window p) { parent = p; } static void sendTalkMessage(final String msg) { Main.register(new MainCallback() { @Override public void mainCallback() { System.out.println("Sending a Text Message: " + msg); Pilot.sendText(msg); Main.unregister(this); } }); } protected WhisperDialog(java.awt.Window parent, String partner) { super(parent, null, Console.message("Whisper-to-from2") + Console.parseExtended(partner), false); this.partner = partner; this.isBroadcast = true; if (partner.equals("room")) { this.setTitle(Console.message("Broadcast-Users")); } else if (partner.equals("world")) { this.setTitle(Console.message("Broadcast-All")); } else { this.isBroadcast = false; } this.whisperPart = new WhisperPart(partner); Console active = Console.getActive(); if (active != null) { active.addPart(this.whisperPart); } int tier = counter / 6; int pos = counter % 6; this.setAlignment(1, ((pos + tier) % 12 - 5) * 20, (pos % 6 - 5) * 20); counter++; } protected void takeFocus() { this.whisperPart.forceTakeFocus(); } @Override public void show() { super.show(); this.whisperPart.scrollToBottom(); int toFront = IniFile.override().getIniInt("whispersToFront", 0); if (toFront != 0) { this.toFront(); } } protected void send(String msg) { this.whisperPart.println("< " + msg); } protected synchronized void print(String msg) { this.whisperPart.println("> " + msg); } @Override protected synchronized void build() { this.building = false; if (this.built) { this.removeAll(); } this.built = true; Color bg1 = new Color(0, 0, 0); Color bg2 = new Color(0, 192, 192); Color fg1 = new Color(255, 255, 255); this.setBackground(fg1); this.setForeground(bg1); this.whisperPart.line.setBackground(this.isTrading ? bg2 : fg1); this.whisperPart.listen.setBackground(fg1); Panel insListen = new InsetPanel(new BorderLayout(), 3, 1, 1, 1); insListen.setBackground(Color.lightGray); insListen.add("Center", this.whisperPart.listen.getComponent()); this.add("Center", insListen); Panel insLine = new InsetPanel(new BorderLayout(), 2, 1, 2, 1); insLine.setBackground(Color.lightGray); insLine.add("Center", this.whisperPart.line); this.add("South", insLine); this.validate(); } protected boolean setValue() { return true; } @Override public synchronized boolean keyDown(Event event, int key) { this.whisperPart.line.requestFocus(); if (key == 10) { this.whisperPart.trigger(); return true; } else { return false; } } @Override public Dimension preferredSize() { return super.preferredSize(); } @Override public Dimension minimumSize() { return super.minimumSize(); } }