Deliantra-Client
view release on metacpan or search on metacpan
DC/UI/ChatView.pm view on Meta::CPAN
on_focus_in => sub {
my ($input, $prev_focus) = @_;
$::MESSAGE_WINDOW->set_visibility (1);
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);
} elsif (length $text) {
my $say_cmd = $self->{say_command};
$::CONN->user_send ($say_cmd . $text);
} else {
$input->{refocus_map} = 1;
}
if (delete $input->{refocus_map}) {
$::MAPWIDGET->grab_focus;
}
0
},
on_key_down => sub {
my ($input, $ev) = @_;
my $sym = $ev->{sym};
my $mod = $ev->{mod};
if ($sym >= ord "0" && $sym <= ord "9" && $mod & DC::KMOD_ALT) {
$::MAPWIDGET->emit (key_down => $ev);
return 1;
}
0
},
on_escape => sub {
$::MAPWIDGET->grab_focus;
0
},
));
$self->{initiated} = 1; # for update_info
$self->update_tooltip;
$self
}
# (private) This method updates the channel info associated with this chat view.
sub update_info {
my ($self, $info) = @_;
$self->{title} = $info->{title};
$self->{text_tooltip} = $info->{tooltip};
$self->{say_command} = $info->{reply};
$self->{entry_tooltip} =
$info->{entry_tooltip}
|| "Enter a message and press enter to send it to the channel '$info->{title}'.";
if ($self->{initiated}) {
$self->{say_command_label}->set_markup ($self->{say_command});
$self->set_title ($self->{title});
$self->update_tooltip;
}
}
# updates only the
sub update_tooltip {
my ($self) = @_;
my $t = $self->{text_tooltip}
. (defined $self->{dockbar_pos}
? "\n\n<small>Alt+"
. ($self->{dockbar_pos} == 9 ? '0' : $self->{dockbar_pos} + 1)
. " - activates this tab.\n"
. "Return - toggles activity of the entry."
. "</small>"
: "");
$self->{c_tab}->set_tooltip ($t);
$self->{txt}->{tooltip} = $self->{text_tooltip};
$self->{input}->{tooltip} = $self->{entry_tooltip};
}
sub set_dockbar_pos {
my ($self, @a) = @_;
$self->SUPER::set_dockbar_pos (@a);
$self->update_tooltip;
}
# (private) This method overloads the set_dockbar_tab_active method of
# the Dockbar to capture the activation event of the tab. Mainly used
# to remove highlightin.
sub set_dockbar_tab_active {
my ($self, $active) = @_;
if ($active) {
$self->set_inactive_fg (undef); # reset inactive color
}
$self->SUPER::set_dockbar_tab_active ($active);
}
# This method renders a message to the text field and sets highlighting
# and does other stuff that a message can cause.
sub message {
my ($self, $para) = @_;
if ($self->is_docked && !$self->is_docked_active) {
if (($para->{color_flags} & NDI_COLOR_MASK) == NDI_RED) {
$self->set_inactive_fg ([1, 0, 0]);
} else {
$self->set_inactive_fg ([0.6, 0.6, 1]);
}
}
$self->select_my_tab if $para->{color_flags} & NDI_REPLY;
$self->clear_log if $para->{color_flags} & NDI_CLEAR;
my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
$para->{markup} = "<span foreground='#ffffff'><tt>$time </tt></span>$para->{markup}";
# boy this is ugly
$para->{markup} =~ s%\n%\n<tt> </tt>%g;
my $txt = $self->{txt};
$txt->add_paragraph ($para);
$txt->scroll_to_bottom unless $para->{color_flags} & NDI_CLEAR;
}
( run in 1.891 second using v1.01-cache-2.11-cpan-39bf76dae61 )