ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/ChatView.pm
Revision: 1.20
Committed: Mon Sep 8 12:00:46 2008 UTC (15 years, 9 months ago) by root
Branch: MAIN
Changes since 1.19: +3 -3 lines
Log Message:
*** empty log message ***

File Contents

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