package CFPlus::UI::MessageWindow; use strict; use utf8; our @ISA = CFPlus::UI::Toplevel::; sub new { my $class = shift; my $self = $class->SUPER::new ( name => "message_window", title => "Messages", border_bg => [1, 1, 1, 1], x => "max", y => 0, force_w => $::WIDTH * 0.4, force_h => $::HEIGHT * 0.5, child => (my $vbox = new CFPlus::UI::VBox), has_close_button => 1 ); my $nb = $self->{nb} = CFPlus::UI::Notebook->new (expand => 1); my $txt = $self->{log} = 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 => "Server Log. This text viewer contains all recent messages sent by the server.", ; my $vb2 = CFPlus::UI::VBox->new; $vb2->add ($txt); $nb->add_tab (Log => $vb2, "This is the main log of the server."); $vbox->add ($nb); $vbox->add ($self->{input} = CFPlus::UI::Entry->new ( 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 (''); if ($text =~ /^\/(.*)/) { $::CONN->user_send ($1); } else { my $say_cmd = $::CFG->{say_command} || 'say'; $::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 $log = $self->{log}; $log->add_paragraph ($para); $log->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->{log}->set_fontsize ($size); } sub set_max_para { my ($self, $max_par) = @_; $self->{log}{max_par} = $max_par; } 1;