ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/ChatView.pm
Revision: 1.2
Committed: Tue Jul 24 18:39:39 2007 UTC (17 years ago) by elmex
Branch: MAIN
Changes since 1.1: +6 -2 lines
Log Message:
chat tabs are now hopefully finally implemented for now

File Contents

# User Rev Content
1 elmex 1.1 package CFPlus::UI::ChatView;
2    
3     use strict;
4     use utf8;
5    
6     our @ISA = CFPlus::UI::VBox::;
7    
8     sub new {
9     my $class = shift;
10     my $self = $class->SUPER::new (@_);
11    
12     $self->add ($self->{txt} = new CFPlus::UI::TextScroller (
13     expand => 1,
14     font => $::FONT_FIXED,
15     fontsize => $::CFG->{log_fontsize},
16     indent => -4,
17     can_hover => 1,
18     can_events => 1,
19     max_par => $::CFG->{logview_max_par},
20     tooltip => "<b>Server Log</b>. This text viewer contains all recent messages sent by the server.",
21     ));
22    
23     $self->add ($self->{input} = CFPlus::UI::Entry->new (
24     tooltip => "<b>Chat Box</b>. If you enter a text and press return/enter here, the current <i>communication command</i> "
25     . "from the client setup will be prepended (e.g. <b>shout</b>, <b>chat</b>...). "
26     . "If you prepend a slash (/), you will submit a command instead (similar to IRC). "
27     . "A better way to submit commands (and the occasional chat command) is often the map command completer.",
28     on_focus_in => sub {
29     my ($input, $prev_focus) = @_;
30    
31     delete $input->{refocus_map};
32    
33     if ($prev_focus == $::MAPWIDGET && $input->{auto_activated}) {
34     $input->{refocus_map} = 1;
35     }
36     delete $input->{auto_activated};
37    
38     0
39     },
40     on_activate => sub {
41     my ($input, $text) = @_;
42     $input->set_text ('');
43    
44     if ($text =~ /^\/(.*)/) {
45     $::CONN->user_send ($1);
46     } else {
47 elmex 1.2 my $say_cmd = $self->{say_command};
48     if ($say_cmd eq '') {
49     $::CONN->user_send ($text);
50     } else {
51     $::CONN->user_send ("$say_cmd $text");
52     }
53 elmex 1.1 }
54     if ($input->{refocus_map}) {
55     delete $input->{refocus_map};
56     $::MAPWIDGET->focus_in
57     }
58    
59     0
60     },
61     on_escape => sub {
62     $::MAPWIDGET->grab_focus;
63    
64     0
65     },
66     ));
67    
68     $self
69     }
70    
71     sub message {
72     my ($self, $para) = @_;
73    
74     my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
75    
76     $para->{markup} = "<span foreground='#ffffff'>$time</span> $para->{markup}";
77    
78     my $txt = $self->{txt};
79     $txt->add_paragraph ($para);
80     $txt->scroll_to_bottom;
81     }
82    
83     sub activate_console {
84     my ($self, $preset) = @_;
85    
86     $self->{input}->{auto_activated} = 1;
87     $self->{input}->grab_focus;
88    
89     if ($preset && $self->{input}->get_text eq '') {
90     $self->{input}->set_text ($preset);
91     }
92     }
93    
94     sub set_fontsize {
95     my ($self, $size) = @_;
96     $self->{txt}->set_fontsize ($size);
97     }
98    
99     sub set_max_para {
100     my ($self, $max_par) = @_;
101     $self->{txt}{max_par} = $max_par;
102     }