1 |
root |
1.12 |
package DC::UI::ChatView; |
2 |
root |
1.14 |
|
3 |
elmex |
1.1 |
use strict; |
4 |
|
|
use utf8; |
5 |
|
|
|
6 |
root |
1.14 |
use Deliantra::Protocol::Constants; |
7 |
|
|
|
8 |
root |
1.12 |
our @ISA = DC::UI::Dockable::; |
9 |
elmex |
1.1 |
|
10 |
|
|
sub new { |
11 |
|
|
my $class = shift; |
12 |
|
|
|
13 |
root |
1.10 |
my $self = $class->SUPER::new ( |
14 |
|
|
can_close => 1, |
15 |
root |
1.12 |
child => (my $vbox = new DC::UI::VBox), |
16 |
elmex |
1.13 |
@_, |
17 |
root |
1.10 |
); |
18 |
|
|
|
19 |
elmex |
1.13 |
$self->update_info ($self->{info}); |
20 |
|
|
|
21 |
root |
1.12 |
$vbox->add ($self->{txt} = new DC::UI::TextScroller ( |
22 |
elmex |
1.1 |
expand => 1, |
23 |
|
|
font => $::FONT_FIXED, |
24 |
|
|
fontsize => $::CFG->{log_fontsize}, |
25 |
|
|
indent => -4, |
26 |
|
|
can_hover => 1, |
27 |
|
|
can_events => 1, |
28 |
|
|
max_par => $::CFG->{logview_max_par}, |
29 |
elmex |
1.13 |
tooltip => $self->{text_tooltip}, |
30 |
elmex |
1.1 |
)); |
31 |
|
|
|
32 |
root |
1.12 |
$vbox->add (my $hb = DC::UI::HBox->new); |
33 |
elmex |
1.3 |
|
34 |
elmex |
1.13 |
$hb->add ( |
35 |
|
|
$self->{say_command_label} = |
36 |
|
|
DC::UI::Label->new (markup => $self->{say_command})); |
37 |
root |
1.10 |
|
38 |
root |
1.12 |
$hb->add ($self->{input} = DC::UI::Entry->new ( |
39 |
elmex |
1.13 |
expand => 1, |
40 |
|
|
tooltip => $self->{entry_tooltip}, |
41 |
elmex |
1.1 |
on_focus_in => sub { |
42 |
|
|
my ($input, $prev_focus) = @_; |
43 |
|
|
|
44 |
elmex |
1.15 |
$::MESSAGE_WINDOW->set_visibility (1); |
45 |
elmex |
1.1 |
delete $input->{refocus_map}; |
46 |
|
|
|
47 |
|
|
if ($prev_focus == $::MAPWIDGET && $input->{auto_activated}) { |
48 |
|
|
$input->{refocus_map} = 1; |
49 |
|
|
} |
50 |
|
|
delete $input->{auto_activated}; |
51 |
|
|
|
52 |
|
|
0 |
53 |
|
|
}, |
54 |
|
|
on_activate => sub { |
55 |
|
|
my ($input, $text) = @_; |
56 |
|
|
$input->set_text (''); |
57 |
|
|
|
58 |
root |
1.4 |
return unless $::CONN; |
59 |
|
|
|
60 |
elmex |
1.1 |
if ($text =~ /^\/(.*)/) { |
61 |
|
|
$::CONN->user_send ($1); |
62 |
root |
1.6 |
} elsif (length $text) { |
63 |
elmex |
1.2 |
my $say_cmd = $self->{say_command}; |
64 |
root |
1.4 |
$::CONN->user_send ($say_cmd . $text); |
65 |
root |
1.6 |
} else { |
66 |
|
|
$input->{refocus_map} = 1; |
67 |
elmex |
1.1 |
} |
68 |
root |
1.6 |
if (delete $input->{refocus_map}) { |
69 |
root |
1.7 |
$::MAPWIDGET->grab_focus; |
70 |
elmex |
1.1 |
} |
71 |
|
|
|
72 |
|
|
0 |
73 |
|
|
}, |
74 |
elmex |
1.5 |
on_key_down => sub { |
75 |
|
|
my ($input, $ev) = @_; |
76 |
root |
1.18 |
my $sym = $ev->{sym}; |
77 |
elmex |
1.5 |
my $mod = $ev->{mod}; |
78 |
|
|
|
79 |
root |
1.18 |
if ($sym >= ord "0" && $sym <= ord "9" && $mod & DC::KMOD_ALT) { |
80 |
elmex |
1.5 |
$::MAPWIDGET->emit (key_down => $ev); |
81 |
|
|
return 1; |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
0 |
85 |
|
|
}, |
86 |
elmex |
1.1 |
on_escape => sub { |
87 |
|
|
$::MAPWIDGET->grab_focus; |
88 |
|
|
|
89 |
|
|
0 |
90 |
|
|
}, |
91 |
|
|
)); |
92 |
|
|
|
93 |
elmex |
1.13 |
$self->{initiated} = 1; # for update_info |
94 |
|
|
|
95 |
elmex |
1.1 |
$self |
96 |
|
|
} |
97 |
|
|
|
98 |
elmex |
1.13 |
# (private) This method updates the channel info associated with this chat view. |
99 |
|
|
sub update_info { |
100 |
|
|
my ($self, $info) = @_; |
101 |
|
|
$self->{title} = $info->{title}; |
102 |
|
|
$self->{text_tooltip} = $info->{tooltip}; |
103 |
|
|
$self->{say_command} = $info->{reply}; |
104 |
|
|
$self->{entry_tooltip} = |
105 |
|
|
$info->{entry_tooltip} |
106 |
|
|
|| "Enter a message and press enter to send it to the channel '$info->{title}'."; |
107 |
|
|
|
108 |
|
|
# TODO: needs some testing maybe, if known that this works: remove comment! |
109 |
|
|
if ($self->{initiated}) { |
110 |
|
|
$self->{say_command_label}->set_markup ($self->{say_command}); |
111 |
|
|
$self->{txt}->{tooltip} = $self->{text_tooltip}; |
112 |
|
|
$self->{input}->{tooltip} = $self->{entry_tooltip}; |
113 |
|
|
$self->set_title ($self->{title}); |
114 |
|
|
} |
115 |
|
|
} |
116 |
|
|
|
117 |
elmex |
1.16 |
sub update_tooltip { |
118 |
|
|
my ($self) = @_; |
119 |
|
|
my $t = $self->{text_tooltip} |
120 |
|
|
. (defined $self->{dockbar_pos} |
121 |
|
|
? "\n\n<small>Alt+" |
122 |
root |
1.17 |
. ($self->{dockbar_pos} == 9 ? '0' : $self->{dockbar_pos} + 1) |
123 |
elmex |
1.16 |
. " - activates this tab.\n" |
124 |
|
|
. "Return - toggles activity of the entry." |
125 |
|
|
. "</small>" |
126 |
|
|
: ""); |
127 |
|
|
$self->{c_tab}->set_tooltip ($t); |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
sub set_dockbar_pos { |
131 |
|
|
my ($self, @a) = @_; |
132 |
|
|
$self->SUPER::set_dockbar_pos (@a); |
133 |
|
|
$self->update_tooltip; |
134 |
|
|
} |
135 |
|
|
|
136 |
elmex |
1.13 |
# (private) This method overloads the set_dockbar_tab_active method of |
137 |
|
|
# the Dockbar to capture the activation event of the tab. Mainly used |
138 |
|
|
# to remove highlightin. |
139 |
|
|
sub set_dockbar_tab_active { |
140 |
|
|
my ($self, $active) = @_; |
141 |
|
|
if ($active) { |
142 |
|
|
$self->set_inactive_fg (undef); # reset inactive color |
143 |
|
|
} |
144 |
|
|
$self->SUPER::set_dockbar_tab_active ($active); |
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
# This method renders a message to the text field and sets highlighting |
148 |
|
|
# and does other stuff that a message can cause. |
149 |
elmex |
1.1 |
sub message { |
150 |
|
|
my ($self, $para) = @_; |
151 |
|
|
|
152 |
elmex |
1.13 |
if ($self->is_docked && !$self->is_docked_active) { |
153 |
|
|
if (($para->{color_flags} & NDI_COLOR_MASK) == NDI_RED) { |
154 |
elmex |
1.15 |
$self->set_inactive_fg ([1, 0, 0]); |
155 |
elmex |
1.13 |
} else { |
156 |
|
|
$self->set_inactive_fg ([0.6, 0.6, 1]); |
157 |
|
|
} |
158 |
|
|
} |
159 |
|
|
|
160 |
|
|
if ($para->{color_flags} & NDI_REPLY) { |
161 |
|
|
$self->select_my_tab; |
162 |
|
|
} |
163 |
|
|
|
164 |
|
|
if ($para->{color_flags} & NDI_CLEAR) { |
165 |
|
|
$self->clear_log; |
166 |
|
|
} |
167 |
|
|
|
168 |
elmex |
1.1 |
my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
169 |
|
|
|
170 |
|
|
$para->{markup} = "<span foreground='#ffffff'>$time</span> $para->{markup}"; |
171 |
|
|
|
172 |
|
|
my $txt = $self->{txt}; |
173 |
|
|
$txt->add_paragraph ($para); |
174 |
|
|
$txt->scroll_to_bottom; |
175 |
|
|
} |
176 |
|
|
|
177 |
elmex |
1.13 |
# This method is called when |
178 |
|
|
sub activate { |
179 |
elmex |
1.1 |
my ($self, $preset) = @_; |
180 |
|
|
|
181 |
elmex |
1.13 |
$self->SUPER::activate (); |
182 |
|
|
|
183 |
elmex |
1.1 |
$self->{input}->{auto_activated} = 1; |
184 |
|
|
$self->{input}->grab_focus; |
185 |
|
|
|
186 |
|
|
if ($preset && $self->{input}->get_text eq '') { |
187 |
|
|
$self->{input}->set_text ($preset); |
188 |
|
|
} |
189 |
|
|
} |
190 |
|
|
|
191 |
elmex |
1.13 |
# sets the fontsize of the chats textview |
192 |
elmex |
1.1 |
sub set_fontsize { |
193 |
|
|
my ($self, $size) = @_; |
194 |
|
|
$self->{txt}->set_fontsize ($size); |
195 |
|
|
} |
196 |
|
|
|
197 |
elmex |
1.13 |
# sets the maximum of paragraphs shown |
198 |
root |
1.14 |
sub set_max_par { |
199 |
elmex |
1.1 |
my ($self, $max_par) = @_; |
200 |
|
|
$self->{txt}{max_par} = $max_par; |
201 |
|
|
} |
202 |
root |
1.6 |
|
203 |
elmex |
1.13 |
# clears the text log |
204 |
root |
1.10 |
sub clear_log { |
205 |
elmex |
1.9 |
my ($self) = @_; |
206 |
root |
1.10 |
|
207 |
elmex |
1.9 |
$self->{txt}->clear; |
208 |
|
|
} |
209 |
root |
1.10 |
|
210 |
|
|
1 |