Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

chat: interface improvements, mini chat in hud.

  • Loading branch information...
commit 13a3958b053ce52ffa15435fb7c19ccbf6aa4174 1 parent ea60578
elmex authored July 19, 2011
201  lib/Games/Construder/Client/Community.pm
@@ -38,6 +38,9 @@ sub new {
38 38
 
39 39
    $self->{con} = AnyEvent::IRC::Client->new;
40 40
 
  41
+   $self->{con}->ctcp_auto_reply ('VERSION', ['VERSION', "Games-Construder:$Games::Construder::VERSION\:Perl"]);
  42
+   $self->{con}->ctcp_auto_reply ('PING', sub { ['PING', $_[4]] });
  43
+
41 44
    $self->{con}->reg_cb (
42 45
       registered => sub {
43 46
          my ($con) = @_;
@@ -48,6 +51,7 @@ sub new {
48 51
       disconnect => sub {
49 52
          my ($con) = @_;
50 53
          $self->chat_log (error => "Disconnected from $con->{host}:$con->{port}: $_[1]");
  54
+         $self->check_chat_update;
51 55
       },
52 56
       connect => sub {
53 57
          my ($con, $err) = @_;
@@ -57,6 +61,11 @@ sub new {
57 61
          } else {
58 62
             $self->chat_log (info => "Connected to $con->{host}:$con->{port}.");
59 63
          }
  64
+
  65
+         $self->{show_hud} = 1;
  66
+         $self->show_hud;
  67
+
  68
+         $self->check_chat_update;
60 69
       },
61 70
       error => sub {
62 71
          my ($con, $code, $msg, $ircmsg) = @_;
@@ -64,13 +73,43 @@ sub new {
64 73
       },
65 74
       privatemsg => sub {
66 75
          my ($con, $nick, $ircmsg) = @_;
67  
-         $self->chat_log (private => "{$nick} $ircmsg->{params}->[-1]");
  76
+         my $n = prefix_nick ($ircmsg);
  77
+         my $msg = sprintf "{%s} %s", $n, $ircmsg->{params}->[-1];
  78
+         if ($ircmsg->{command} eq 'NOTICE') {
  79
+            $self->chat_log (info => $msg);
  80
+         } else {
  81
+            $self->chat_log (private => $msg);
  82
+            unless ($self->{privhelp}->{$n}) {
  83
+               $self->chat_log (info => "(private message from '$n', answer with '/msg $n <your message here>')");
  84
+               $self->{privhelp}->{$n} = 1;
  85
+            }
  86
+         }
68 87
       },
69 88
       publicmsg => sub {
70 89
          my ($con, $targ, $ircmsg) = @_;
71  
-         $self->chat_log (public =>
72  
-            sprintf "<%10s> %s",
73  
-               prefix_nick ($ircmsg), $ircmsg->{params}->[-1]);
  90
+         if ($ircmsg->{command} eq 'NOTICE') {
  91
+            $self->chat_log (info => sprintf "{%s} %s", prefix_nick ($ircmsg), $ircmsg->{params}->[-1]);
  92
+            return;
  93
+         }
  94
+
  95
+         my $nick = $con->nick;
  96
+         if ($ircmsg->{params}->[-1] =~ /^\b$nick\b/i) {
  97
+            $self->chat_log (public_hl =>
  98
+               sprintf "<%s> %s",
  99
+                  prefix_nick ($ircmsg), $ircmsg->{params}->[-1]);
  100
+         } else {
  101
+            $self->chat_log (public =>
  102
+               sprintf "<%s> %s",
  103
+                  prefix_nick ($ircmsg), $ircmsg->{params}->[-1]);
  104
+         }
  105
+      },
  106
+      ctcp_action => sub {
  107
+         my ($con, $src, $targ, $msg, $type) = @_;
  108
+         if ($con->is_channel_name ($targ)) {
  109
+            $self->chat_log (public => sprintf "* %s %s", $src, $msg);
  110
+         } else {
  111
+            $self->chat_log (private => sprintf "* %s %s", $src, $msg);
  112
+         }
74 113
       },
75 114
       quit => sub {
76 115
          my ($con, $nick, $msg) = @_;
@@ -81,7 +120,6 @@ sub new {
81 120
          if ($is_me) {
82 121
             $self->chat_log (public => "* $nick was kicked from $chan by $kicker: $msg");
83 122
             my $settings = ($self->{front}->{res}->{config}->{chat} ||= {});
84  
-            $settings->{con} = "disconnect";
85 123
             $self->check_connection;
86 124
 
87 125
          } else {
@@ -121,19 +159,23 @@ sub chat_log {
121 159
 sub get_chat_settings {
122 160
    my ($self) = @_;
123 161
    my $settings = ($self->{front}->{res}->{config}->{chat} ||= {});
  162
+   my $srv_chat = $self->{front}->{res}->{config}->{srv_chat};
124 163
    my $nick = $settings->{nick} ne '' ? $settings->{nick} : $settings->{recent_login_name};
125  
-   my $chan = $settings->{chan} ne '' ? $settings->{chan} : "#construder";
126  
-   my $host = $settings->{host} ne '' ? $settings->{host} : "irc.perl.org";
127  
-   my $port = $settings->{port} ne '' ? $settings->{port} : 6667;
  164
+   my $chan = $settings->{chan} ne '' ? $settings->{chan} : $srv_chat->{channel};
  165
+   my $host = $settings->{host} ne '' ? $settings->{host} : $srv_chat->{host};
  166
+   my $port = $settings->{port} ne '' ? $settings->{port} : $srv_chat->{port};
128 167
 
129  
-   ($nick, $chan, $host, $port, $settings->{con})
  168
+   ($nick, $chan, $host, $port)
130 169
 }
131 170
 
132 171
 sub check_chat_update {
133 172
    my ($self) = @_;
134  
-   if ($self->{mode} eq 'chat' && $self->{front}->{active_uis}->{irc_chat}) {
  173
+   if ($self->{front}->{active_uis}->{irc_chat}) {
135 174
       $self->show;
136 175
    }
  176
+   if ($self->{front}->{active_uis}->{irc_chat_hud}) {
  177
+      $self->show_hud;
  178
+   }
137 179
 }
138 180
 
139 181
 sub show {
@@ -154,38 +196,22 @@ sub show_chat_settings {
154 196
    $self->{front}->activate_ui (irc_chat => {
155 197
       %{
156 198
          ui_window ("Chat Settings",
157  
-            ui_key_explain (F6 => "Show Chat"),
158  
-            ui_pad_box (hor =>
159  
-               $con eq 'connect'
160  
-                 ? ui_select_item (chat_conn => "disconnect", ui_subtext ("Leave Chat"))
161  
-                 : ui_select_item (chat_conn => "connect",    ui_subtext ("Enter Chat"))),
  199
+            ui_key_inline_expl (F6 => "Show Chat"),
  200
+            ui_key_inline_expl (c => "Toggle HUD Chat"),
  201
+            ui_desc ("Chat Status: "
  202
+                     . ($self->{con}->is_connected ? "connected" : "disconnected")),
  203
+            ($self->{con}->is_connected
  204
+               ? ui_select_item (chat_conn => "disconnect", ui_subtext ("Disconnect"))
  205
+               : ui_select_item (chat_conn => "connect",    ui_subtext ("Connect"))),
162 206
             ui_pad_box (hor =>
163 207
                ui_desc ("Used Nickname: "), ui_subdesc ($nick)),
164 208
             ui_pad_box (hor =>
165 209
                ui_desc ("Custom Nickname:"),
166 210
                ui_entry (cust_nick => $settings->{nick}, 10)),
167  
-            ui_pad_box (hor =>
168  
-               ui_desc ("Used Host: "),
169  
-               ui_subdesc ($host)),
170  
-            ui_pad_box (hor =>
171  
-               ui_desc ("Custom Host:"),
172  
-               ui_entry (cust_host => $settings->{host}, 30)),
173  
-            ui_pad_box (hor =>
174  
-               ui_desc ("Used Port: "),
175  
-               ui_subdesc ($port)),
176  
-            ui_pad_box (hor =>
177  
-               ui_desc ("Custom Port:"),
178  
-               ui_entry (cust_port => $settings->{port}, 6)),
179  
-            ui_pad_box (hor =>
180  
-               ui_desc ("Used Channel: "),
181  
-               ui_subdesc ($chan)),
182  
-            ui_pad_box (hor =>
183  
-               ui_desc ("Custom Channel:"),
184  
-               ui_entry (cust_chan => $settings->{chan}, 6)),
185 211
          )
186 212
       },
187 213
       commands => {
188  
-         default_keys => { return => "set", f6 => "chat" }
  214
+         default_keys => { return => "set", f6 => "chat", c => "hud" }
189 215
       },
190 216
       command_cb => sub {
191 217
          my ($cmd, $arg, $need_selection) = @_;
@@ -194,15 +220,20 @@ sub show_chat_settings {
194 220
             $settings->{nick} = $arg->{cust_nick};
195 221
             $settings->{host} = $arg->{cust_host};
196 222
             $settings->{port} = $arg->{cust_port};
197  
-            $settings->{con}  = $arg->{chat_conn};
  223
+            if ($arg->{chat_conn} eq 'connect') {
  224
+               $self->chat_connect;
  225
+            } elsif ($arg->{chat_conn} eq 'disconnect') {
  226
+               $self->chat_disconnect;
  227
+            }
198 228
             $self->{front}->{res}->save_config;
199 229
             $self->check_connection;
200  
-            if ($settings->{con} eq 'connect') {
201  
-               $self->{mode} = "chat";
202  
-            }
203 230
             $self->show;
204 231
             return 1;
205 232
 
  233
+         } elsif ($cmd eq 'hud') {
  234
+            $self->{show_hud} = not $self->{show_hud};
  235
+            $self->show_hud;
  236
+
206 237
          } elsif ($cmd eq 'chat') {
207 238
             $self->{mode} = "chat";
208 239
             $self->show;
@@ -212,35 +243,22 @@ sub show_chat_settings {
212 243
    });
213 244
 }
214 245
 
215  
-sub check_connection {
  246
+sub chat_connect {
216 247
    my ($self) = @_;
217  
-
218 248
    my ($nick, $chan, $host, $port, $connect) = $self->get_chat_settings;
219  
-
220 249
    my $info = { nick => $nick, real => "G:C:C $Games::Construder::VERSION ($^O)" };
  250
+   $self->{con}->connect ($host, $port, $info);
  251
+}
221 252
 
222  
-   if ($connect eq 'connect'
223  
-       && !$self->{con}->is_connected
224  
-   ) {
225  
-      $self->{con}->connect ($host, $port, $info);
226  
-      return;
227  
-   }
  253
+sub chat_disconnect {
  254
+   my ($self) = @_;
  255
+   $self->{con}->disconnect ("user request");
  256
+}
228 257
 
229  
-   if ($connect eq 'disconnect'
230  
-       && $self->{con}->is_connected
231  
-   ) {
232  
-      $self->{con}->disconnect ("user request");
233  
-      return;
234  
-   }
  258
+sub check_connection {
  259
+   my ($self) = @_;
235 260
 
236  
-   if ($self->{con}->is_connected) {
237  
-      if ($self->{con}->{host} ne $host
238  
-          || $self->{con}->{port} ne $port
239  
-      ) {
240  
-         $self->{con}->connect ($host, $port, $info);
241  
-         return;
242  
-      }
243  
-   }
  261
+   my ($nick, $chan, $host, $port, $connect) = $self->get_chat_settings;
244 262
 
245 263
    if ($self->{con}->registered) {
246 264
       if ($self->{con}->nick ne $nick) {
@@ -249,44 +267,71 @@ sub check_connection {
249 267
    }
250 268
 }
251 269
 
252  
-sub show_chat {
  270
+sub show_hud {
253 271
    my ($self) = @_;
  272
+   unless ($self->{show_hud}) {
  273
+      $self->{front}->deactivate_ui ('irc_chat_hud');
  274
+      return;
  275
+   }
254 276
 
255  
-   my $mode = $self->{mode};
  277
+   my @txt = $self->chat_backlog_as_ui (4, 0, "small");
256 278
 
  279
+   $self->{front}->activate_ui (irc_chat_hud => {
  280
+      %{
  281
+         ui_hud_window_transparent (
  282
+            [left => "center", 0, 0.15], ui_border (@txt))
  283
+      }
  284
+   });
  285
+
  286
+}
  287
+
  288
+sub chat_backlog_as_ui {
  289
+   my ($self, $lines, $scroll, $font) = @_;
  290
+   $font = "normal" if $font eq '';
257 291
    my @backlog = @{$self->{backlog}};
258 292
 
259 293
    my @txt;
260  
-   for (my $i = 0; $i < 15; $i++) {
  294
+   for (my $i = 0; $i < $lines; $i++) {
261 295
       my $l = pop @backlog
262 296
          or last;
263 297
       my ($type, $txt) = @$l;
264  
-      my $txt = sprintf "%10s: %s", $type, $txt;
  298
+      my $txt = sprintf "%7s: %s", $type, $txt;
265 299
       if ($type eq 'public') {
266  
-         $txt = [text => { font => "normal", align => "left", wrap => -60, color => "#ffffff" }, $txt];
  300
+         $txt = [text => { font => $font, align => "left", wrap => -60, color => "#ffffff" }, $txt];
  301
+      } elsif ($type eq 'public_hl') {
  302
+         $txt = [text => { font => $font, align => "left", wrap => -60, color => "#ffffaa" }, $txt];
267 303
       } elsif ($type eq 'private') {
268  
-         $txt = [text => { font => "normal", align => "left", wrap => -60, color => "#ffaaaa" }, $txt];
  304
+         $txt = [text => { font => $font, align => "left", wrap => -60, color => "#ffaaaa" }, $txt];
269 305
       } elsif ($type eq 'error') {
270  
-         $txt = [text => { font => "normal", align => "left", wrap => -60, color => "#ff0000" }, $txt];
  306
+         $txt = [text => { font => $font, align => "left", wrap => -60, color => "#ff0000" }, $txt];
271 307
       } elsif ($type eq 'info') {
272  
-         $txt = [text => { font => "normal", align => "left", wrap => -60, color => "#0000dd" }, $txt];
  308
+         $txt = [text => { font => $font, align => "left", wrap => -60, color => "#6666FF" }, $txt];
273 309
       } else {
274  
-         $txt = [text => { font => "normal", align => "left", wrap => -60, color => "#dddddd" }, $txt];
  310
+         $txt = [text => { font => $font, align => "left", wrap => -60, color => "#dddddd" }, $txt];
275 311
       }
276 312
       unshift @txt, $txt;
277 313
    }
278 314
 
  315
+   @txt
  316
+}
  317
+
  318
+sub show_chat {
  319
+   my ($self) = @_;
  320
+
  321
+   my $mode = $self->{mode};
  322
+
  323
+   my @txt = $self->chat_backlog_as_ui (12);
  324
+
279 325
    $self->{front}->activate_ui (irc_chat => {
280 326
       %{
281 327
          ui_window (($mode eq 'community' ? "Community Chat" : "Chat"),
282  
-            ui_border (
283  
-               @txt
284  
-            ),
285  
-            ui_entry_small (irc => "", 100),
  328
+            ui_border (@txt),
  329
+            ui_border (ui_pad_box (hor =>
  330
+               ui_subdesc ("Entry: "), ui_entry_small (irc => "", 90)
  331
+            )),
286 332
             ui_key_inline_expl (return => "Send message"),
287 333
             ui_key_inline_expl ("page up"   => "Scroll backlog up"),
288 334
             ui_key_inline_expl ("page down" => "Scroll backlog down"),
289  
- #           ui_key_inline_expl ("F5"        => "Toggle Minichat visibility"),
290 335
             ui_key_inline_expl ("F6"        => "Chat Settings"),
291 336
             ui_key_inline_expl ("F9"        => "Hide Chat"),
292 337
          )
@@ -304,18 +349,18 @@ sub show_chat {
304 349
          my ($nick, $chan, $host, $port, $connect) = $self->get_chat_settings;
305 350
 
306 351
          if ($cmd eq 'send') {
307  
-            if ($arg->{irc} =~ /^\/(\S+)\s*(.*)/) {
  352
+            if ($arg->{irc} =~ /^\s*\/(\S+)\s*(.*)/) {
308 353
                my ($c, $a) = ($1, $2);
309 354
                if ($c eq 'msg' && $a =~ /(\S+)\s+(.*)$/) {
310 355
                   $self->{con}->send_srv (PRIVMSG => $1, $2);
311  
-                  $self->chat_log (private => sprintf "<%10s -> %-10s> %s", $self->{con}->nick, $1, $2);
  356
+                  $self->chat_log (private => sprintf "<%s -> %s> %s", $self->{con}->nick, $1, $2);
312 357
                } else {
313 358
                   $self->chat_log (error => "unknown command: /$c");
314 359
                }
315 360
 
316 361
             } else {
317 362
                $self->{con}->send_srv (PRIVMSG => $chan, $arg->{irc});
318  
-               $self->chat_log (public => sprintf "<%10s> %s", $self->{con}->nick, $arg->{irc});
  363
+               $self->chat_log (public => sprintf "<%s> %s", $self->{con}->nick, $arg->{irc});
319 364
             }
320 365
             $self->show;
321 366
             return 1;
2  lib/Games/Construder/Server/UI.pm
@@ -205,7 +205,7 @@ sub layout {
205 205
    });
206 206
 
207 207
    ui_hud_window_transparent (
208  
-      [center => "center", -0.25],
  208
+      [center => "center", -0.3],
209 209
       ui_warning ($msg)
210 210
    );
211 211
 }

0 notes on commit 13a3958

Please sign in to comment.
Something went wrong with that request. Please try again.