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 |
|
|
$vb->add ( |
76 |
|
|
my $b = CFPlus::UI::Label->new ( |
77 |
elmex |
1.9 |
expand => 1, markup => clr_def ($chaninfo->{title}), valign => 0, align => 0 |
78 |
elmex |
1.4 |
) |
79 |
|
|
); |
80 |
|
|
|
81 |
elmex |
1.8 |
$cv->{_chat_id} = $id; |
82 |
elmex |
1.4 |
$cv->{_tab_button} = $b; |
83 |
|
|
weaken $cv->{_tab_button}; |
84 |
elmex |
1.1 |
|
85 |
elmex |
1.4 |
$vb->add ( |
86 |
|
|
my $b = CFPlus::UI::ImageButton->new ( |
87 |
|
|
path => 'x1_close.png', |
88 |
|
|
scale => 0.3 |
89 |
|
|
) |
90 |
|
|
); |
91 |
|
|
$b->connect (activate => sub { |
92 |
|
|
my $b = shift; |
93 |
elmex |
1.1 |
|
94 |
elmex |
1.3 |
my @chld = $nb->pages; |
95 |
|
|
my $cur = pop @chld; |
96 |
elmex |
1.4 |
while (@chld && $cur != $cv) { |
97 |
elmex |
1.3 |
$cur = pop @chld; |
98 |
|
|
} |
99 |
|
|
$cur = pop @chld; |
100 |
elmex |
1.4 |
$nb->remove ($cv); |
101 |
elmex |
1.3 |
$nb->set_current_page ($cur); |
102 |
elmex |
1.4 |
|
103 |
|
|
delete $chatviews->{$id}; |
104 |
elmex |
1.3 |
0 |
105 |
|
|
}); |
106 |
elmex |
1.4 |
|
107 |
elmex |
1.12 |
my $preadd = $nb->get_current_page; |
108 |
elmex |
1.4 |
$nb->add ($cv); |
109 |
elmex |
1.12 |
$nb->set_current_page ($preadd); |
110 |
elmex |
1.4 |
} |
111 |
|
|
|
112 |
|
|
sub touch_channel { |
113 |
|
|
my ($self, $id) = @_; |
114 |
elmex |
1.12 |
|
115 |
elmex |
1.10 |
if (not exists $self->{chatviews}->{$id}) { |
116 |
elmex |
1.4 |
$self->add_chat ($id); |
117 |
|
|
} |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
sub highlight_channel { |
121 |
elmex |
1.14 |
my ($self, $id, $hlt_func) = @_; |
122 |
|
|
|
123 |
|
|
$hlt_func ||= \&clr_hlt; |
124 |
elmex |
1.12 |
|
125 |
elmex |
1.4 |
my $cv = $self->{chatviews}->{$id}; |
126 |
elmex |
1.8 |
$cv->{_channel_highlighted} = 1; |
127 |
elmex |
1.4 |
my $tab = $cv->{_tab_button}; |
128 |
elmex |
1.12 |
|
129 |
elmex |
1.8 |
$tab->set_markup ( |
130 |
elmex |
1.14 |
$hlt_func->(defined $id ? $self->{channel_info}->{$id}->{title} : "Log") |
131 |
elmex |
1.8 |
); |
132 |
elmex |
1.4 |
} |
133 |
|
|
|
134 |
|
|
sub unhighlight_channel { |
135 |
|
|
my ($self, $id) = @_; |
136 |
elmex |
1.8 |
|
137 |
elmex |
1.4 |
my $cv = $self->{chatviews}->{$id}; |
138 |
elmex |
1.8 |
$cv->{_channel_highlighted} = 0; |
139 |
elmex |
1.4 |
my $tab = $cv->{_tab_button}; |
140 |
elmex |
1.9 |
|
141 |
|
|
$tab->set_markup (clr_act (defined $id ? $self->{channel_info}->{$id}->{title} : "Log")); |
142 |
elmex |
1.8 |
} |
143 |
|
|
|
144 |
|
|
sub update_current_tab { |
145 |
|
|
my ($self, $page) = @_; |
146 |
elmex |
1.12 |
|
147 |
elmex |
1.8 |
my $tab = $page->{_tab_button}; |
148 |
elmex |
1.9 |
my $label; |
149 |
elmex |
1.12 |
|
150 |
elmex |
1.9 |
if (defined $page->{_chat_id}) { |
151 |
|
|
$label = $self->{channel_info}->{$page->{_chat_id}}->{title}; |
152 |
elmex |
1.16 |
$self->unhighlight_channel ($page->{_chat_id}); |
153 |
elmex |
1.9 |
} |
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 |
|
|
} |
264 |
|
|
|
265 |
root |
1.2 |
1; |
266 |
|
|
|