1 |
root |
1.12 |
package DC::UI::ChatView; |
2 |
elmex |
1.1 |
|
3 |
|
|
use strict; |
4 |
|
|
use utf8; |
5 |
|
|
|
6 |
root |
1.12 |
our @ISA = DC::UI::Dockable::; |
7 |
elmex |
1.1 |
|
8 |
|
|
sub new { |
9 |
|
|
my $class = shift; |
10 |
|
|
|
11 |
root |
1.10 |
my $self = $class->SUPER::new ( |
12 |
|
|
@_, |
13 |
|
|
can_close => 1, |
14 |
root |
1.12 |
child => (my $vbox = new DC::UI::VBox), |
15 |
root |
1.10 |
); |
16 |
|
|
|
17 |
root |
1.12 |
$vbox->add ($self->{txt} = new DC::UI::TextScroller ( |
18 |
elmex |
1.1 |
expand => 1, |
19 |
|
|
font => $::FONT_FIXED, |
20 |
|
|
fontsize => $::CFG->{log_fontsize}, |
21 |
|
|
indent => -4, |
22 |
|
|
can_hover => 1, |
23 |
|
|
can_events => 1, |
24 |
|
|
max_par => $::CFG->{logview_max_par}, |
25 |
elmex |
1.3 |
tooltip => |
26 |
|
|
$self->{text_tooltip} |
27 |
|
|
|| "<b>Server Log</b>. This text viewer contains all recent messages " |
28 |
|
|
."sent by the server.", |
29 |
elmex |
1.1 |
)); |
30 |
|
|
|
31 |
root |
1.12 |
$vbox->add (my $hb = DC::UI::HBox->new); |
32 |
elmex |
1.3 |
|
33 |
|
|
if ($self->{say_command}) { |
34 |
root |
1.12 |
$hb->add (DC::UI::Label->new (markup => $self->{say_command})); |
35 |
elmex |
1.3 |
} |
36 |
root |
1.10 |
|
37 |
root |
1.12 |
$hb->add ($self->{input} = DC::UI::Entry->new ( |
38 |
elmex |
1.3 |
expand => 1, |
39 |
|
|
tooltip => |
40 |
|
|
$self->{entry_tooltip} |
41 |
root |
1.8 |
|| "<b>Command Entry</b>. If you enter something and press return/enter here, " |
42 |
|
|
. "the line you entered will be sent to the server as a command.", |
43 |
elmex |
1.1 |
on_focus_in => sub { |
44 |
|
|
my ($input, $prev_focus) = @_; |
45 |
|
|
|
46 |
|
|
delete $input->{refocus_map}; |
47 |
|
|
|
48 |
|
|
if ($prev_focus == $::MAPWIDGET && $input->{auto_activated}) { |
49 |
|
|
$input->{refocus_map} = 1; |
50 |
|
|
} |
51 |
|
|
delete $input->{auto_activated}; |
52 |
|
|
|
53 |
|
|
0 |
54 |
|
|
}, |
55 |
|
|
on_activate => sub { |
56 |
|
|
my ($input, $text) = @_; |
57 |
|
|
$input->set_text (''); |
58 |
|
|
|
59 |
root |
1.4 |
return unless $::CONN; |
60 |
|
|
|
61 |
elmex |
1.1 |
if ($text =~ /^\/(.*)/) { |
62 |
|
|
$::CONN->user_send ($1); |
63 |
root |
1.6 |
} elsif (length $text) { |
64 |
elmex |
1.2 |
my $say_cmd = $self->{say_command}; |
65 |
root |
1.4 |
$::CONN->user_send ($say_cmd . $text); |
66 |
root |
1.6 |
} else { |
67 |
|
|
$input->{refocus_map} = 1; |
68 |
elmex |
1.1 |
} |
69 |
root |
1.6 |
if (delete $input->{refocus_map}) { |
70 |
root |
1.7 |
$::MAPWIDGET->grab_focus; |
71 |
elmex |
1.1 |
} |
72 |
|
|
|
73 |
|
|
0 |
74 |
|
|
}, |
75 |
elmex |
1.5 |
on_key_down => sub { |
76 |
|
|
my ($input, $ev) = @_; |
77 |
|
|
my $uni = $ev->{unicode}; |
78 |
|
|
my $mod = $ev->{mod}; |
79 |
|
|
|
80 |
root |
1.12 |
if ($uni >= ord "0" && $uni <= ord "9" && $mod & DC::KMOD_ALT) { |
81 |
elmex |
1.5 |
$::MAPWIDGET->emit (key_down => $ev); |
82 |
|
|
return 1; |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
0 |
86 |
|
|
}, |
87 |
elmex |
1.1 |
on_escape => sub { |
88 |
|
|
$::MAPWIDGET->grab_focus; |
89 |
|
|
|
90 |
|
|
0 |
91 |
|
|
}, |
92 |
|
|
)); |
93 |
|
|
|
94 |
|
|
$self |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
sub message { |
98 |
|
|
my ($self, $para) = @_; |
99 |
|
|
|
100 |
|
|
my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
101 |
|
|
|
102 |
|
|
$para->{markup} = "<span foreground='#ffffff'>$time</span> $para->{markup}"; |
103 |
|
|
|
104 |
|
|
my $txt = $self->{txt}; |
105 |
|
|
$txt->add_paragraph ($para); |
106 |
|
|
$txt->scroll_to_bottom; |
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
sub activate_console { |
110 |
|
|
my ($self, $preset) = @_; |
111 |
|
|
|
112 |
|
|
$self->{input}->{auto_activated} = 1; |
113 |
|
|
$self->{input}->grab_focus; |
114 |
|
|
|
115 |
|
|
if ($preset && $self->{input}->get_text eq '') { |
116 |
|
|
$self->{input}->set_text ($preset); |
117 |
|
|
} |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
sub set_fontsize { |
121 |
|
|
my ($self, $size) = @_; |
122 |
|
|
$self->{txt}->set_fontsize ($size); |
123 |
|
|
} |
124 |
|
|
|
125 |
|
|
sub set_max_para { |
126 |
|
|
my ($self, $max_par) = @_; |
127 |
|
|
$self->{txt}{max_par} = $max_par; |
128 |
|
|
} |
129 |
root |
1.6 |
|
130 |
root |
1.10 |
sub clear_log { |
131 |
elmex |
1.9 |
my ($self) = @_; |
132 |
root |
1.10 |
|
133 |
elmex |
1.9 |
$self->{txt}->clear; |
134 |
|
|
} |
135 |
root |
1.10 |
|
136 |
|
|
1 |