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