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