1 |
package CFPlus::UI::MessageWindow; |
2 |
|
3 |
use strict; |
4 |
use utf8; |
5 |
|
6 |
our @ISA = CFPlus::UI::Toplevel::; |
7 |
|
8 |
sub new { |
9 |
my $class = shift; |
10 |
|
11 |
my $self = $class->SUPER::new ( |
12 |
name => "message_window", |
13 |
title => "Messages", |
14 |
border_bg => [1, 1, 1, 1], |
15 |
x => "max", |
16 |
y => 0, |
17 |
force_w => $::WIDTH * 0.4, |
18 |
force_h => $::HEIGHT * 0.5, |
19 |
child => (my $vbox = new CFPlus::UI::VBox), |
20 |
has_close_button => 1 |
21 |
); |
22 |
|
23 |
my $nb = $self->{nb} = CFPlus::UI::Notebook->new (expand => 1); |
24 |
my $txt = $self->{log} = new CFPlus::UI::TextScroller |
25 |
expand => 1, |
26 |
font => $::FONT_FIXED, |
27 |
fontsize => $::CFG->{log_fontsize}, |
28 |
indent => -4, |
29 |
can_hover => 1, |
30 |
can_events => 1, |
31 |
max_par => $::CFG->{logview_max_par}, |
32 |
tooltip => "<b>Server Log</b>. This text viewer contains all recent messages sent by the server.", |
33 |
; |
34 |
|
35 |
my $vb2 = CFPlus::UI::VBox->new; |
36 |
$vb2->add ($txt); |
37 |
$nb->add_tab (Log => $vb2, "This is the main log of the server."); |
38 |
$vbox->add ($nb); |
39 |
|
40 |
$vbox->add ($self->{input} = CFPlus::UI::Entry->new ( |
41 |
tooltip => "<b>Chat Box</b>. If you enter a text and press return/enter here, the current <i>communication command</i> " |
42 |
. "from the client setup will be prepended (e.g. <b>shout</b>, <b>chat</b>...). " |
43 |
. "If you prepend a slash (/), you will submit a command instead (similar to IRC). " |
44 |
. "A better way to submit commands (and the occasional chat command) is often the map command completer.", |
45 |
on_focus_in => sub { |
46 |
my ($input, $prev_focus) = @_; |
47 |
|
48 |
delete $input->{refocus_map}; |
49 |
|
50 |
if ($prev_focus == $::MAPWIDGET && $input->{auto_activated}) { |
51 |
$input->{refocus_map} = 1; |
52 |
} |
53 |
delete $input->{auto_activated}; |
54 |
|
55 |
0 |
56 |
}, |
57 |
on_activate => sub { |
58 |
my ($input, $text) = @_; |
59 |
$input->set_text (''); |
60 |
|
61 |
if ($text =~ /^\/(.*)/) { |
62 |
$::CONN->user_send ($1); |
63 |
} else { |
64 |
my $say_cmd = $::CFG->{say_command} || 'say'; |
65 |
$::CONN->user_send ("$say_cmd $text"); |
66 |
} |
67 |
if ($input->{refocus_map}) { |
68 |
delete $input->{refocus_map}; |
69 |
$::MAPWIDGET->focus_in |
70 |
} |
71 |
|
72 |
0 |
73 |
}, |
74 |
on_escape => sub { |
75 |
$::MAPWIDGET->grab_focus; |
76 |
|
77 |
0 |
78 |
}, |
79 |
)); |
80 |
|
81 |
$self |
82 |
} |
83 |
|
84 |
sub message { |
85 |
my ($self, $para) = @_; |
86 |
|
87 |
my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
88 |
|
89 |
$para->{markup} = "<span foreground='#ffffff'>$time</span> $para->{markup}"; |
90 |
|
91 |
my $log = $self->{log}; |
92 |
$log->add_paragraph ($para); |
93 |
$log->scroll_to_bottom; |
94 |
} |
95 |
|
96 |
sub activate_console { |
97 |
my ($self, $preset) = @_; |
98 |
|
99 |
$self->{input}->{auto_activated} = 1; |
100 |
$self->{input}->grab_focus; |
101 |
|
102 |
if ($preset && $self->{input}->get_text eq '') { |
103 |
$self->{input}->set_text ($preset); |
104 |
} |
105 |
} |
106 |
|
107 |
sub set_fontsize { |
108 |
my ($self, $size) = @_; |
109 |
$self->{log}->set_fontsize ($size); |
110 |
} |
111 |
|
112 |
sub set_max_para { |
113 |
my ($self, $max_par) = @_; |
114 |
$self->{log}{max_par} = $max_par; |
115 |
} |
116 |
|
117 |
1; |
118 |
|