ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/MessageWindow.pm
Revision: 1.12
Committed: Tue Aug 14 13:25:26 2007 UTC (16 years, 11 months ago) by elmex
Branch: MAIN
Changes since 1.11: +54 -7 lines
Log Message:
added alt+numberkey functionality for message window, and added reply-message
detection with activation of the entry

File Contents

# Content
1 package CFPlus::UI::MessageWindow;
2
3 use strict;
4 use utf8;
5
6 use Scalar::Util qw/weaken/;
7 use CFPlus::UI::ChatView;
8 use Crossfire::Protocol::Constants;
9
10 our @ISA = CFPlus::UI::Toplevel::;
11
12 our %channel_info;
13
14 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 sub clr_hlt2($) { "<span foreground=\"#9999ff\">$_[0]</span>" }
18
19 sub new {
20 my $class = shift;
21
22 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 child => (my $nb = CFPlus::UI::Notebook->new (expand => 1)),
31 has_close_button => 1
32 );
33
34 $self->{nb} = $nb;
35 $self->{chatviews} = {};
36
37 $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 $self
54 }
55
56 sub add_chat {
57 my ($self, $id) = @_;
58
59 my $chatviews = $self->{chatviews};
60 my $chaninfo = $self->{channel_info}->{$id};
61 my $nb = $self->{nb};
62
63 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 $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 expand => 1, markup => clr_def ($chaninfo->{title}), valign => 0, align => 0
79 )
80 );
81
82 $cv->{_chat_id} = $id;
83 $cv->{_tab_button} = $b;
84 weaken $cv->{_tab_button};
85
86 $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
95 my @chld = $nb->pages;
96 my $cur = pop @chld;
97 while (@chld && $cur != $cv) {
98 $cur = pop @chld;
99 }
100 $cur = pop @chld;
101 $nb->remove ($cv);
102 $nb->set_current_page ($cur);
103
104 delete $chatviews->{$id};
105 0
106 });
107
108 my $preadd = $nb->get_current_page;
109 $nb->add ($cv);
110 $nb->set_current_page ($preadd);
111 }
112
113 sub touch_channel {
114 my ($self, $id) = @_;
115
116 if (not exists $self->{chatviews}->{$id}) {
117 $self->add_chat ($id);
118 }
119 }
120
121 sub highlight_channel {
122 my ($self, $id) = @_;
123
124 my $cv = $self->{chatviews}->{$id};
125 $cv->{_channel_highlighted} = 1;
126 my $tab = $cv->{_tab_button};
127
128 $tab->set_markup (
129 clr_hlt (defined $id ? $self->{channel_info}->{$id}->{title} : "Log")
130 );
131 }
132
133 sub unhighlight_channel {
134 my ($self, $id) = @_;
135
136 my $cv = $self->{chatviews}->{$id};
137 $cv->{_channel_highlighted} = 0;
138 my $tab = $cv->{_tab_button};
139
140 $tab->set_markup (clr_act (defined $id ? $self->{channel_info}->{$id}->{title} : "Log"));
141 }
142
143 sub update_current_tab {
144 my ($self, $page) = @_;
145
146 my $tab = $page->{_tab_button};
147 my $label;
148
149 if (defined $page->{_chat_id}) {
150 $label = $self->{channel_info}->{$page->{_chat_id}}->{title};
151 }
152
153 $label = "Log" unless defined $label;
154
155 $tab->set_markup (clr_act ($label));
156
157 for ($self->{nb}->pages) {
158 next if $_ eq $page;
159 next if $_->{_channel_highlighted};
160
161 my $tab = $_->{_tab_button};
162 next unless $tab;
163
164 my $label;
165
166 if (defined $_->{_chat_id}) {
167 $label = $self->{channel_info}->{$_->{_chat_id}}->{title};
168 }
169
170 $label = "Log" unless defined $label;
171
172 $tab->set_markup (clr_def ($label));
173 }
174 }
175
176 sub add_channel {
177 my ($self, $info) = @_;
178
179 $self->{channel_info}->{$info->{id}} = $info;
180 $self->touch_channel ($info->{id});
181 }
182
183 sub message {
184 my ($self, $para) = @_;
185
186 #d# require Data::Dumper;
187 #d# print "FOO[".Data::Dumper->Dump ([$para])."]\n";
188
189 my $id = $para->{type};
190
191 if (exists $self->{channel_info}->{$id}) {
192 $self->touch_channel ($id);
193
194 if (my $cv = $self->{chatviews}->{$id}) {
195
196 if ($cv != $self->{nb}->get_current_page) {
197 $self->highlight_channel ($id);
198 }
199
200 if ($para->{color_flags} & NDI_REPLY) {
201 $self->{nb}->set_current_page ($cv);
202 $cv->activate_console;
203 }
204 }
205
206 $self->{chatviews}->{$id}->message ($para);
207
208 } else {
209 $self->{main_log}->message ($para);
210 }
211 }
212
213 sub activate_console {
214 my ($self, $preset) = @_;
215
216 $self->{main_log}->activate_console ($preset);
217 }
218
219 sub activate_current {
220 my ($self) = @_;
221
222 $self->{nb}->get_current_page->activate_console;
223 }
224
225 sub set_fontsize {
226 my ($self, $size) = @_;
227
228 for (values %{$self->{chatviews}}, $self->{main_log}) {
229 $_->set_fontsize ($size);
230 }
231 }
232
233 sub set_max_para {
234 my ($self, $max_par) = @_;
235
236 for (values %{$self->{chatviews}}, $self->{main_log}) {
237 $_->set_max_para ($max_par);
238 }
239 }
240
241 sub user_switch_to_page {
242 my ($self, $page) = @_;
243
244 $page = $page eq '0' ? 10 : $page;
245
246 my @tabs = $self->{nb}->pages;
247
248 for (my $i = 0; $i < ($page - 1); $i++) {
249 shift @tabs;
250 }
251
252 my $page = shift @tabs;
253 return unless $page;
254
255 $self->{nb}->set_current_page ($page);
256 $page->activate_console;
257 }
258
259 1;
260