summaryrefslogtreecommitdiff
path: root/NET/worlds/console/WhisperDialog.java
blob: fd3e3f440fa6feb3cb23056e30fd9d33ca1f6aeb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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();
   }
}