ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/ChatView.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI/ChatView.pm (file contents):
Revision 1.12 by root, Wed Dec 26 21:03:21 2007 UTC vs.
Revision 1.13 by elmex, Sun Jan 6 16:28:49 2008 UTC

1package DC::UI::ChatView; 1package DC::UI::ChatView;
2 2use Deliantra::Protocol::Constants;
3use strict; 3use strict;
4use utf8; 4use utf8;
5 5
6our @ISA = DC::UI::Dockable::; 6our @ISA = DC::UI::Dockable::;
7 7
8sub new { 8sub new {
9 my $class = shift; 9 my $class = shift;
10 10
11 my $self = $class->SUPER::new ( 11 my $self = $class->SUPER::new (
12 @_,
13 can_close => 1, 12 can_close => 1,
14 child => (my $vbox = new DC::UI::VBox), 13 child => (my $vbox = new DC::UI::VBox),
14 @_,
15 ); 15 );
16
17 $self->update_info ($self->{info});
16 18
17 $vbox->add ($self->{txt} = new DC::UI::TextScroller ( 19 $vbox->add ($self->{txt} = new DC::UI::TextScroller (
18 expand => 1, 20 expand => 1,
19 font => $::FONT_FIXED, 21 font => $::FONT_FIXED,
20 fontsize => $::CFG->{log_fontsize}, 22 fontsize => $::CFG->{log_fontsize},
21 indent => -4, 23 indent => -4,
22 can_hover => 1, 24 can_hover => 1,
23 can_events => 1, 25 can_events => 1,
24 max_par => $::CFG->{logview_max_par}, 26 max_par => $::CFG->{logview_max_par},
25 tooltip =>
26 $self->{text_tooltip} 27 tooltip => $self->{text_tooltip},
27 || "<b>Server Log</b>. This text viewer contains all recent messages "
28 ."sent by the server.",
29 )); 28 ));
30 29
31 $vbox->add (my $hb = DC::UI::HBox->new); 30 $vbox->add (my $hb = DC::UI::HBox->new);
32 31
33 if ($self->{say_command}) { 32 $hb->add (
33 $self->{say_command_label} =
34 $hb->add (DC::UI::Label->new (markup => $self->{say_command})); 34 DC::UI::Label->new (markup => $self->{say_command}));
35 }
36 35
37 $hb->add ($self->{input} = DC::UI::Entry->new ( 36 $hb->add ($self->{input} = DC::UI::Entry->new (
38 expand => 1, 37 expand => 1,
39 tooltip =>
40 $self->{entry_tooltip} 38 tooltip => $self->{entry_tooltip},
41 || "<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 on_focus_in => sub { 39 on_focus_in => sub {
44 my ($input, $prev_focus) = @_; 40 my ($input, $prev_focus) = @_;
45 41
46 delete $input->{refocus_map}; 42 delete $input->{refocus_map};
47 43
89 85
90 0 86 0
91 }, 87 },
92 )); 88 ));
93 89
90 $self->{initiated} = 1; # for update_info
91
94 $self 92 $self
95} 93}
96 94
95# (private) This method updates the channel info associated with this chat view.
96sub 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.
117sub 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.
97sub message { 127sub message {
98 my ($self, $para) = @_; 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 }
99 145
100 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; 146 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
101 147
102 $para->{markup} = "<span foreground='#ffffff'>$time</span> $para->{markup}"; 148 $para->{markup} = "<span foreground='#ffffff'>$time</span> $para->{markup}";
103 149
104 my $txt = $self->{txt}; 150 my $txt = $self->{txt};
105 $txt->add_paragraph ($para); 151 $txt->add_paragraph ($para);
106 $txt->scroll_to_bottom; 152 $txt->scroll_to_bottom;
107} 153}
108 154
155# This method is called when
109sub activate_console { 156sub activate {
110 my ($self, $preset) = @_; 157 my ($self, $preset) = @_;
158
159 $self->SUPER::activate ();
111 160
112 $self->{input}->{auto_activated} = 1; 161 $self->{input}->{auto_activated} = 1;
113 $self->{input}->grab_focus; 162 $self->{input}->grab_focus;
114 163
115 if ($preset && $self->{input}->get_text eq '') { 164 if ($preset && $self->{input}->get_text eq '') {
116 $self->{input}->set_text ($preset); 165 $self->{input}->set_text ($preset);
117 } 166 }
118} 167}
119 168
169# sets the fontsize of the chats textview
120sub set_fontsize { 170sub set_fontsize {
121 my ($self, $size) = @_; 171 my ($self, $size) = @_;
122 $self->{txt}->set_fontsize ($size); 172 $self->{txt}->set_fontsize ($size);
123} 173}
124 174
175# sets the maximum of paragraphs shown
125sub set_max_para { 176sub set_max_para {
126 my ($self, $max_par) = @_; 177 my ($self, $max_par) = @_;
127 $self->{txt}{max_par} = $max_par; 178 $self->{txt}{max_par} = $max_par;
128} 179}
129 180
181# clears the text log
130sub clear_log { 182sub clear_log {
131 my ($self) = @_; 183 my ($self) = @_;
132 184
133 $self->{txt}->clear; 185 $self->{txt}->clear;
134} 186}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines