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

# User Rev Content
1 root 1.12 package DC::UI::ChatView;
2 elmex 1.13 use Deliantra::Protocol::Constants;
3 elmex 1.1 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     can_close => 1,
13 root 1.12 child => (my $vbox = new DC::UI::VBox),
14 elmex 1.13 @_,
15 root 1.10 );
16    
17 elmex 1.13 $self->update_info ($self->{info});
18    
19 root 1.12 $vbox->add ($self->{txt} = new DC::UI::TextScroller (
20 elmex 1.1 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 elmex 1.13 tooltip => $self->{text_tooltip},
28 elmex 1.1 ));
29    
30 root 1.12 $vbox->add (my $hb = DC::UI::HBox->new);
31 elmex 1.3
32 elmex 1.13 $hb->add (
33     $self->{say_command_label} =
34     DC::UI::Label->new (markup => $self->{say_command}));
35 root 1.10
36 root 1.12 $hb->add ($self->{input} = DC::UI::Entry->new (
37 elmex 1.13 expand => 1,
38     tooltip => $self->{entry_tooltip},
39 elmex 1.1 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 root 1.4 return unless $::CONN;
56    
57 elmex 1.1 if ($text =~ /^\/(.*)/) {
58     $::CONN->user_send ($1);
59 root 1.6 } elsif (length $text) {
60 elmex 1.2 my $say_cmd = $self->{say_command};
61 root 1.4 $::CONN->user_send ($say_cmd . $text);
62 root 1.6 } else {
63     $input->{refocus_map} = 1;
64 elmex 1.1 }
65 root 1.6 if (delete $input->{refocus_map}) {
66 root 1.7 $::MAPWIDGET->grab_focus;
67 elmex 1.1 }
68    
69     0
70     },
71 elmex 1.5 on_key_down => sub {
72     my ($input, $ev) = @_;
73     my $uni = $ev->{unicode};
74     my $mod = $ev->{mod};
75    
76 root 1.12 if ($uni >= ord "0" && $uni <= ord "9" && $mod & DC::KMOD_ALT) {
77 elmex 1.5 $::MAPWIDGET->emit (key_down => $ev);
78     return 1;
79     }
80    
81     0
82     },
83 elmex 1.1 on_escape => sub {
84     $::MAPWIDGET->grab_focus;
85    
86     0
87     },
88     ));
89    
90 elmex 1.13 $self->{initiated} = 1; # for update_info
91    
92 elmex 1.1 $self
93     }
94    
95 elmex 1.13 # (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 elmex 1.1 sub message {
128     my ($self, $para) = @_;
129    
130 elmex 1.13 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 elmex 1.1 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 elmex 1.13 # This method is called when
156     sub activate {
157 elmex 1.1 my ($self, $preset) = @_;
158    
159 elmex 1.13 $self->SUPER::activate ();
160    
161 elmex 1.1 $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 elmex 1.13 # sets the fontsize of the chats textview
170 elmex 1.1 sub set_fontsize {
171     my ($self, $size) = @_;
172     $self->{txt}->set_fontsize ($size);
173     }
174    
175 elmex 1.13 # sets the maximum of paragraphs shown
176 elmex 1.1 sub set_max_para {
177     my ($self, $max_par) = @_;
178     $self->{txt}{max_par} = $max_par;
179     }
180 root 1.6
181 elmex 1.13 # clears the text log
182 root 1.10 sub clear_log {
183 elmex 1.9 my ($self) = @_;
184 root 1.10
185 elmex 1.9 $self->{txt}->clear;
186     }
187 root 1.10
188     1