ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/MessageWindow.pm
Revision: 1.29
Committed: Sun Jan 6 16:28:49 2008 UTC (16 years, 6 months ago) by elmex
Branch: MAIN
CVS Tags: rel-0_9965, rel-0_9964, rel-0_9963
Changes since 1.28: +2 -0 lines
Log Message:
committed the big Dockbar patch.

File Contents

# User Rev Content
1 root 1.27 package DC::UI::MessageWindow;
2 elmex 1.1
3 elmex 1.29 # Deprecated due to Dockbar
4    
5 elmex 1.1 use strict;
6     use utf8;
7    
8 elmex 1.4 use Scalar::Util qw/weaken/;
9 root 1.27 use DC::UI::ChatView;
10 root 1.25 use Deliantra::Protocol::Constants;
11 elmex 1.3
12 root 1.27 our @ISA = DC::UI::Toplevel::;
13 elmex 1.1
14 elmex 1.4 our %channel_info;
15    
16 root 1.23 sub clr_def($) { "<span foreground=\"#ffffff\">$_[0]</span>" }
17     sub clr_act($) { "<span foreground=\"#ffffff\">$_[0]</span>" }
18     sub clr_hlt($) { "<span foreground=\"#aaaaff\">$_[0]</span>" }
19     sub clr_hlt2($) { "<span foreground=\"#ff0000\">$_[0]</span>" }
20 elmex 1.9
21 elmex 1.1 sub new {
22     my $class = shift;
23 root 1.2
24 elmex 1.1 my $self = $class->SUPER::new (
25     name => "message_window",
26     title => "Messages",
27     border_bg => [1, 1, 1, 1],
28     x => "max",
29     y => 0,
30     force_w => $::WIDTH * 0.4,
31     force_h => $::HEIGHT * 0.5,
32 root 1.27 child => (my $nb = DC::UI::Notebook->new (expand => 1)),
33 elmex 1.1 has_close_button => 1
34     );
35 root 1.2
36 elmex 1.4 $self->{nb} = $nb;
37     $self->{chatviews} = {};
38 elmex 1.1
39 elmex 1.8 $nb->connect (page_changed => sub {
40     my ($nb, $page) = @_;
41 elmex 1.17 $self->set_current_tab ($page);
42     });
43     $nb->connect (c_add => sub {
44     $self->update_tabs;
45 elmex 1.8 });
46    
47     my $l = $self->{main_log} =
48 root 1.27 DC::UI::ChatView->new (expand => 1, say_command => '');
49 root 1.23
50 elmex 1.17 $l->{_tab_label} =
51 elmex 1.8 $l->{c_tab} =
52 root 1.27 DC::UI::Button->new (
53 elmex 1.8 markup => "Log", tooltip => "This is the main log of the server."
54     );
55    
56     $nb->add ($l);
57 elmex 1.17 $nb->set_current_page ($l);
58 elmex 1.8
59 elmex 1.1 $self
60     }
61    
62 elmex 1.3 sub add_chat {
63 elmex 1.4 my ($self, $id) = @_;
64    
65     my $chatviews = $self->{chatviews};
66     my $chaninfo = $self->{channel_info}->{$id};
67     my $nb = $self->{nb};
68    
69 elmex 1.6 my $cv = $chatviews->{$id} =
70 root 1.27 DC::UI::ChatView->new (
71 elmex 1.6 expand => 1,
72     say_command => $chaninfo->{reply},
73     entry_tooltip => $chaninfo->{tooltip},
74     text_tooltip => "Conversation with $chaninfo->{title}"
75     );
76    
77 root 1.27 my $bb = DC::UI::ButtonBin->new (tooltip => $chaninfo->{tooltip});
78 elmex 1.4 $cv->{c_tab} = $bb;
79    
80 root 1.27 $bb->add (my $vb = DC::UI::Box->new);
81 elmex 1.4 $vb->add (
82 root 1.27 my $b = DC::UI::Label->new (
83 root 1.28 expand => 1, markup => clr_def ($chaninfo->{title}),
84 elmex 1.4 )
85     );
86    
87 elmex 1.8 $cv->{_chat_id} = $id;
88 elmex 1.17 $cv->{_tab_label} = $b;
89     weaken $cv->{_tab_label};
90 elmex 1.1
91 elmex 1.4 $vb->add (
92 root 1.27 my $b = DC::UI::ImageButton->new (
93 root 1.23 path => 'x1_close.png',
94     scale => 0.3,
95 elmex 1.4 )
96     );
97     $b->connect (activate => sub {
98     my $b = shift;
99 elmex 1.24 $self->close_chatview ($cv);
100 elmex 1.3 0
101     });
102 elmex 1.4
103 elmex 1.12 my $preadd = $nb->get_current_page;
104 elmex 1.4 $nb->add ($cv);
105 elmex 1.12 $nb->set_current_page ($preadd);
106 elmex 1.4 }
107    
108 elmex 1.24 sub close_chatview {
109     my ($self, $cv) = @_;
110     return unless defined $cv->{_chat_id};
111    
112     my $chatviews = $self->{chatviews};
113     my $nb = $self->{nb};
114     my @chld = $nb->pages;
115     my $cur = pop @chld;
116     while (@chld && $cur != $cv) {
117     $cur = pop @chld;
118     }
119     $cur = pop @chld;
120     $nb->remove ($cv);
121     $nb->set_current_page ($cur);
122    
123     delete $chatviews->{$cv->{_chat_id}};
124     }
125    
126 elmex 1.4 sub touch_channel {
127     my ($self, $id) = @_;
128 elmex 1.12
129 elmex 1.10 if (not exists $self->{chatviews}->{$id}) {
130 elmex 1.4 $self->add_chat ($id);
131     }
132     }
133    
134     sub highlight_channel {
135 elmex 1.14 my ($self, $id, $hlt_func) = @_;
136    
137     $hlt_func ||= \&clr_hlt;
138 elmex 1.12
139 elmex 1.4 my $cv = $self->{chatviews}->{$id};
140 elmex 1.12
141 elmex 1.17 # the clr_hlt2 has a "higher priority"
142     unless ($cv->{_channel_highlighted} eq \&clr_hlt2) {
143     $cv->{_channel_highlighted} = $hlt_func;
144     }
145    
146     $self->update_tabs;
147 elmex 1.4 }
148    
149 elmex 1.17 sub set_current_tab {
150     my ($self, $page) = @_;
151    
152     for ($self->{nb}->pages) {
153     next if $_ eq $page;
154     $_->{_active} = 0;
155     }
156     $page->{_active} = 1;
157    
158     $self->update_tabs;
159     }
160 elmex 1.9
161 elmex 1.24 sub close_current_tab {
162     my ($self) = @_;
163     $self->close_chatview ($self->{nb}->get_current_page);
164     }
165    
166 elmex 1.17 sub update_tabs {
167     my ($self) = @_;
168 elmex 1.8
169 elmex 1.17 my $i = 1;
170 elmex 1.8 for ($self->{nb}->pages) {
171 elmex 1.17 if ($i <= 10) {
172     $_->{_tab_pos} = $i++;
173     } else {
174     $_->{_tab_pos} = undef;
175     }
176 elmex 1.12
177 elmex 1.17 my $tab = $_->{_tab_label};
178 elmex 1.8 next unless $tab;
179    
180 elmex 1.17 my ($label, $tooltip) =
181     ("Log", "This is the main log of the server.");
182 elmex 1.12
183 elmex 1.9 if (defined $_->{_chat_id}) {
184 elmex 1.17 my $chinfo = $self->{channel_info}->{$_->{_chat_id}};
185     $label = $chinfo->{title};
186     $tooltip = $chinfo->{tooltip};
187    
188     if ($_->{_active}) {
189     $_->{_channel_highlighted} = 0;
190     }
191 elmex 1.9 }
192 elmex 1.12
193 elmex 1.17 $_->{c_tab}->set_tooltip (
194     $tooltip
195     . (defined $_->{_tab_pos}
196 elmex 1.18 ? "\n\n<small>Alt+"
197 elmex 1.17 . ($_->{_tab_pos} == 10 ? '0' : $_->{_tab_pos})
198 elmex 1.18 . " - activates this tab.\n"
199     . "Return - toggles activity of the entry."
200 elmex 1.17 . "</small>"
201     : "")
202     );
203    
204     my $hltfunc = $_->{_channel_highlighted}
205     || ($_->{_active} ? \&clr_act : \&clr_def);
206 elmex 1.8
207 elmex 1.19 $tab->set_markup (
208     $hltfunc->($label . (defined $_->{_tab_pos} ? "\-$_->{_tab_pos}" : ""))
209     );
210 elmex 1.8 }
211 elmex 1.4 }
212    
213     sub add_channel {
214     my ($self, $info) = @_;
215 elmex 1.12
216 elmex 1.4 $self->{channel_info}->{$info->{id}} = $info;
217     $self->touch_channel ($info->{id});
218     }
219    
220 elmex 1.3 sub message {
221     my ($self, $para) = @_;
222 elmex 1.12
223     #d# require Data::Dumper;
224     #d# print "FOO[".Data::Dumper->Dump ([$para])."]\n";
225    
226 elmex 1.4 my $id = $para->{type};
227    
228 elmex 1.9 if (exists $self->{channel_info}->{$id}) {
229 elmex 1.4 $self->touch_channel ($id);
230 elmex 1.12
231 elmex 1.10 if (my $cv = $self->{chatviews}->{$id}) {
232 elmex 1.12
233 elmex 1.10 if ($cv != $self->{nb}->get_current_page) {
234 elmex 1.14
235     if (($para->{color_flags} & NDI_COLOR_MASK) == NDI_RED) {
236     $self->highlight_channel ($id, \&clr_hlt2);
237     } else {
238     $self->highlight_channel ($id);
239     }
240 elmex 1.10 }
241 elmex 1.12
242     if ($para->{color_flags} & NDI_REPLY) {
243     $self->{nb}->set_current_page ($cv);
244 elmex 1.14 }
245    
246 elmex 1.21 if ($para->{color_flags} & NDI_CLEAR) {
247 root 1.22 $cv->clear_log;
248 elmex 1.21 }
249 elmex 1.10 }
250 elmex 1.12
251 elmex 1.4 $self->{chatviews}->{$id}->message ($para);
252 elmex 1.12
253 elmex 1.4 } else {
254     $self->{main_log}->message ($para);
255     }
256 elmex 1.1 }
257    
258     sub activate_console {
259     my ($self, $preset) = @_;
260 elmex 1.12
261 elmex 1.3 $self->{main_log}->activate_console ($preset);
262 elmex 1.1 }
263    
264 elmex 1.12 sub activate_current {
265     my ($self) = @_;
266    
267     $self->{nb}->get_current_page->activate_console;
268     }
269    
270 elmex 1.1 sub set_fontsize {
271     my ($self, $size) = @_;
272 elmex 1.12
273 elmex 1.11 for (values %{$self->{chatviews}}, $self->{main_log}) {
274     $_->set_fontsize ($size);
275     }
276 elmex 1.1 }
277    
278     sub set_max_para {
279     my ($self, $max_par) = @_;
280 elmex 1.12
281 elmex 1.11 for (values %{$self->{chatviews}}, $self->{main_log}) {
282     $_->set_max_para ($max_par);
283     }
284 elmex 1.1 }
285 root 1.2
286 elmex 1.12 sub user_switch_to_page {
287     my ($self, $page) = @_;
288    
289     $page = $page eq '0' ? 10 : $page;
290    
291     my @tabs = $self->{nb}->pages;
292    
293     for (my $i = 0; $i < ($page - 1); $i++) {
294     shift @tabs;
295     }
296    
297     my $page = shift @tabs;
298     return unless $page;
299    
300     $self->{nb}->set_current_page ($page);
301     }
302    
303 root 1.22 1
304 root 1.2