ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/ChatView.pm
Revision: 1.13
Committed: Sun Jan 6 16:28:49 2008 UTC (16 years, 5 months ago) by elmex
Branch: MAIN
CVS Tags: rel-0_9965, rel-0_9964, rel-0_9963
Changes since 1.12: +67 -15 lines
Log Message:
committed the big Dockbar patch.

File Contents

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