ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/MessageWindow.pm
Revision: 1.14
Committed: Tue Aug 14 14:06:17 2007 UTC (16 years, 11 months ago) by elmex
Branch: MAIN
Changes since 1.13: +13 -5 lines
Log Message:
implemented that red messages cause red tab highlighting

File Contents

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