ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/ChatView.pm
Revision: 1.14
Committed: Thu Mar 20 22:28:34 2008 UTC (16 years, 4 months ago) by root
Branch: MAIN
Changes since 1.13: +4 -2 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.12 package DC::UI::ChatView;
2 root 1.14
3 elmex 1.1 use strict;
4     use utf8;
5    
6 root 1.14 use Deliantra::Protocol::Constants;
7    
8 root 1.12 our @ISA = DC::UI::Dockable::;
9 elmex 1.1
10     sub new {
11     my $class = shift;
12    
13 root 1.10 my $self = $class->SUPER::new (
14     can_close => 1,
15 root 1.12 child => (my $vbox = new DC::UI::VBox),
16 elmex 1.13 @_,
17 root 1.10 );
18    
19 elmex 1.13 $self->update_info ($self->{info});
20    
21 root 1.12 $vbox->add ($self->{txt} = new DC::UI::TextScroller (
22 elmex 1.1 expand => 1,
23     font => $::FONT_FIXED,
24     fontsize => $::CFG->{log_fontsize},
25     indent => -4,
26     can_hover => 1,
27     can_events => 1,
28     max_par => $::CFG->{logview_max_par},
29 elmex 1.13 tooltip => $self->{text_tooltip},
30 elmex 1.1 ));
31    
32 root 1.12 $vbox->add (my $hb = DC::UI::HBox->new);
33 elmex 1.3
34 elmex 1.13 $hb->add (
35     $self->{say_command_label} =
36     DC::UI::Label->new (markup => $self->{say_command}));
37 root 1.10
38 root 1.12 $hb->add ($self->{input} = DC::UI::Entry->new (
39 elmex 1.13 expand => 1,
40     tooltip => $self->{entry_tooltip},
41 elmex 1.1 on_focus_in => sub {
42     my ($input, $prev_focus) = @_;
43    
44     delete $input->{refocus_map};
45    
46     if ($prev_focus == $::MAPWIDGET && $input->{auto_activated}) {
47     $input->{refocus_map} = 1;
48     }
49     delete $input->{auto_activated};
50    
51     0
52     },
53     on_activate => sub {
54     my ($input, $text) = @_;
55     $input->set_text ('');
56    
57 root 1.4 return unless $::CONN;
58    
59 elmex 1.1 if ($text =~ /^\/(.*)/) {
60     $::CONN->user_send ($1);
61 root 1.6 } elsif (length $text) {
62 elmex 1.2 my $say_cmd = $self->{say_command};
63 root 1.4 $::CONN->user_send ($say_cmd . $text);
64 root 1.6 } else {
65     $input->{refocus_map} = 1;
66 elmex 1.1 }
67 root 1.6 if (delete $input->{refocus_map}) {
68 root 1.7 $::MAPWIDGET->grab_focus;
69 elmex 1.1 }
70    
71     0
72     },
73 elmex 1.5 on_key_down => sub {
74     my ($input, $ev) = @_;
75     my $uni = $ev->{unicode};
76     my $mod = $ev->{mod};
77    
78 root 1.12 if ($uni >= ord "0" && $uni <= ord "9" && $mod & DC::KMOD_ALT) {
79 elmex 1.5 $::MAPWIDGET->emit (key_down => $ev);
80     return 1;
81     }
82    
83     0
84     },
85 elmex 1.1 on_escape => sub {
86     $::MAPWIDGET->grab_focus;
87    
88     0
89     },
90     ));
91    
92 elmex 1.13 $self->{initiated} = 1; # for update_info
93    
94 elmex 1.1 $self
95     }
96    
97 elmex 1.13 # (private) This method updates the channel info associated with this chat view.
98     sub update_info {
99     my ($self, $info) = @_;
100     $self->{title} = $info->{title};
101     $self->{text_tooltip} = $info->{tooltip};
102     $self->{say_command} = $info->{reply};
103     $self->{entry_tooltip} =
104     $info->{entry_tooltip}
105     || "Enter a message and press enter to send it to the channel '$info->{title}'.";
106    
107     # TODO: needs some testing maybe, if known that this works: remove comment!
108     if ($self->{initiated}) {
109     $self->{say_command_label}->set_markup ($self->{say_command});
110     $self->{txt}->{tooltip} = $self->{text_tooltip};
111     $self->{input}->{tooltip} = $self->{entry_tooltip};
112     $self->set_title ($self->{title});
113     }
114     }
115    
116     # (private) This method overloads the set_dockbar_tab_active method of
117     # the Dockbar to capture the activation event of the tab. Mainly used
118     # to remove highlightin.
119     sub set_dockbar_tab_active {
120     my ($self, $active) = @_;
121     if ($active) {
122     $self->set_inactive_fg (undef); # reset inactive color
123     }
124     $self->SUPER::set_dockbar_tab_active ($active);
125     }
126    
127     # This method renders a message to the text field and sets highlighting
128     # and does other stuff that a message can cause.
129 elmex 1.1 sub message {
130     my ($self, $para) = @_;
131    
132 elmex 1.13 if ($self->is_docked && !$self->is_docked_active) {
133     if (($para->{color_flags} & NDI_COLOR_MASK) == NDI_RED) {
134     $self->set_inactive_fg ([0, 0, 1]);
135     } else {
136     $self->set_inactive_fg ([0.6, 0.6, 1]);
137     }
138     }
139    
140     if ($para->{color_flags} & NDI_REPLY) {
141     $self->select_my_tab;
142     }
143    
144     if ($para->{color_flags} & NDI_CLEAR) {
145     $self->clear_log;
146     }
147    
148 elmex 1.1 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
149    
150     $para->{markup} = "<span foreground='#ffffff'>$time</span> $para->{markup}";
151    
152     my $txt = $self->{txt};
153     $txt->add_paragraph ($para);
154     $txt->scroll_to_bottom;
155     }
156    
157 elmex 1.13 # This method is called when
158     sub activate {
159 elmex 1.1 my ($self, $preset) = @_;
160    
161 elmex 1.13 $self->SUPER::activate ();
162    
163 elmex 1.1 $self->{input}->{auto_activated} = 1;
164     $self->{input}->grab_focus;
165    
166     if ($preset && $self->{input}->get_text eq '') {
167     $self->{input}->set_text ($preset);
168     }
169     }
170    
171 elmex 1.13 # sets the fontsize of the chats textview
172 elmex 1.1 sub set_fontsize {
173     my ($self, $size) = @_;
174     $self->{txt}->set_fontsize ($size);
175     }
176    
177 elmex 1.13 # sets the maximum of paragraphs shown
178 root 1.14 sub set_max_par {
179 elmex 1.1 my ($self, $max_par) = @_;
180     $self->{txt}{max_par} = $max_par;
181     }
182 root 1.6
183 elmex 1.13 # clears the text log
184 root 1.10 sub clear_log {
185 elmex 1.9 my ($self) = @_;
186 root 1.10
187 elmex 1.9 $self->{txt}->clear;
188     }
189 root 1.10
190     1