package CFPlus::UI::ChatView;
use strict;
use utf8;
our @ISA = CFPlus::UI::VBox::;
sub new {
my $class = shift;
my $self = $class->SUPER::new (@_);
$self->add ($self->{txt} = new CFPlus::UI::TextScroller (
expand => 1,
font => $::FONT_FIXED,
fontsize => $::CFG->{log_fontsize},
indent => -4,
can_hover => 1,
can_events => 1,
max_par => $::CFG->{logview_max_par},
tooltip =>
$self->{text_tooltip}
|| "Server Log. This text viewer contains all recent messages "
."sent by the server.",
));
$self->add (my $hb = CFPlus::UI::HBox->new);
if ($self->{say_command}) {
$hb->add (CFPlus::UI::Label->new (markup => $self->{say_command}));
}
$hb->add ($self->{input} = CFPlus::UI::Entry->new (
expand => 1,
tooltip =>
$self->{entry_tooltip}
|| "Chat Box. If you enter a text and press return/enter here, the current communication command "
. "from the client setup will be prepended (e.g. shout, chat...). "
. "If you prepend a slash (/), you will submit a command instead (similar to IRC). "
. "A better way to submit commands (and the occasional chat command) is often the map command completer.",
on_focus_in => sub {
my ($input, $prev_focus) = @_;
delete $input->{refocus_map};
if ($prev_focus == $::MAPWIDGET && $input->{auto_activated}) {
$input->{refocus_map} = 1;
}
delete $input->{auto_activated};
0
},
on_activate => sub {
my ($input, $text) = @_;
$input->set_text ('');
return unless $::CONN;
if ($text =~ /^\/(.*)/) {
$::CONN->user_send ($1);
} else {
my $say_cmd = $self->{say_command};
$::CONN->user_send ($say_cmd . $text);
}
if ($input->{refocus_map}) {
delete $input->{refocus_map};
$::MAPWIDGET->focus_in
}
0
},
on_escape => sub {
$::MAPWIDGET->grab_focus;
0
},
));
$self
}
sub message {
my ($self, $para) = @_;
my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
$para->{markup} = "$time $para->{markup}";
my $txt = $self->{txt};
$txt->add_paragraph ($para);
$txt->scroll_to_bottom;
}
sub activate_console {
my ($self, $preset) = @_;
$self->{input}->{auto_activated} = 1;
$self->{input}->grab_focus;
if ($preset && $self->{input}->get_text eq '') {
$self->{input}->set_text ($preset);
}
}
sub set_fontsize {
my ($self, $size) = @_;
$self->{txt}->set_fontsize ($size);
}
sub set_max_para {
my ($self, $max_par) = @_;
$self->{txt}{max_par} = $max_par;
}