ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/MessageWindow.pm
Revision: 1.13
Committed: Tue Aug 14 13:26:06 2007 UTC (16 years, 11 months ago) by elmex
Branch: MAIN
Changes since 1.12: +0 -1 lines
Log Message:
(another minor thing removed for now)

File Contents

# User Rev Content
1 elmex 1.1 package CFPlus::UI::MessageWindow;
2    
3     use strict;
4     use utf8;
5    
6 elmex 1.4 use Scalar::Util qw/weaken/;
7 elmex 1.3 use CFPlus::UI::ChatView;
8 elmex 1.12 use Crossfire::Protocol::Constants;
9 elmex 1.3
10 elmex 1.1 our @ISA = CFPlus::UI::Toplevel::;
11    
12 elmex 1.4 our %channel_info;
13    
14 elmex 1.9 sub clr_def($) { "<span foreground=\"#777777\">$_[0]</span>" }
15     sub clr_act($) { "<span foreground=\"#ffffff\">$_[0]</span>" }
16     sub clr_hlt($) { "<span foreground=\"#aaaaff\">$_[0]</span>" }
17     sub clr_hlt2($) { "<span foreground=\"#9999ff\">$_[0]</span>" }
18    
19 elmex 1.1 sub new {
20     my $class = shift;
21 root 1.2
22 elmex 1.1 my $self = $class->SUPER::new (
23     name => "message_window",
24     title => "Messages",
25     border_bg => [1, 1, 1, 1],
26     x => "max",
27     y => 0,
28     force_w => $::WIDTH * 0.4,
29     force_h => $::HEIGHT * 0.5,
30 elmex 1.3 child => (my $nb = CFPlus::UI::Notebook->new (expand => 1)),
31 elmex 1.1 has_close_button => 1
32     );
33 root 1.2
34 elmex 1.4 $self->{nb} = $nb;
35     $self->{chatviews} = {};
36 elmex 1.1
37 elmex 1.8 $nb->connect (page_changed => sub {
38     my ($nb, $page) = @_;
39     $self->update_current_tab ($page);
40     });
41    
42     my $l = $self->{main_log} =
43     CFPlus::UI::ChatView->new (expand => 1, say_command => '');
44     $l->{_tab_button} =
45     $l->{c_tab} =
46     CFPlus::UI::Button->new (
47     markup => "Log", tooltip => "This is the main log of the server."
48     );
49    
50     $nb->add ($l);
51     $self->update_current_tab ($l);
52    
53 elmex 1.1 $self
54     }
55    
56 elmex 1.3 sub add_chat {
57 elmex 1.4 my ($self, $id) = @_;
58    
59     my $chatviews = $self->{chatviews};
60     my $chaninfo = $self->{channel_info}->{$id};
61     my $nb = $self->{nb};
62    
63 elmex 1.6 my $cv = $chatviews->{$id} =
64     CFPlus::UI::ChatView->new (
65     expand => 1,
66     say_command => $chaninfo->{reply},
67     entry_tooltip => $chaninfo->{tooltip},
68     text_tooltip => "Conversation with $chaninfo->{title}"
69     );
70    
71     my $bb = CFPlus::UI::ButtonBin->new (tooltip => $chaninfo->{tooltip});
72 elmex 1.4 $cv->{c_tab} = $bb;
73    
74     $bb->add (my $vb = CFPlus::UI::Box->new);
75     $bb->connect (activate => sub { $self->unhighlight_channel ($id); 0 });
76     $vb->add (
77     my $b = CFPlus::UI::Label->new (
78 elmex 1.9 expand => 1, markup => clr_def ($chaninfo->{title}), valign => 0, align => 0
79 elmex 1.4 )
80     );
81    
82 elmex 1.8 $cv->{_chat_id} = $id;
83 elmex 1.4 $cv->{_tab_button} = $b;
84     weaken $cv->{_tab_button};
85 elmex 1.1
86 elmex 1.4 $vb->add (
87     my $b = CFPlus::UI::ImageButton->new (
88     path => 'x1_close.png',
89     scale => 0.3
90     )
91     );
92     $b->connect (activate => sub {
93     my $b = shift;
94 elmex 1.1
95 elmex 1.3 my @chld = $nb->pages;
96     my $cur = pop @chld;
97 elmex 1.4 while (@chld && $cur != $cv) {
98 elmex 1.3 $cur = pop @chld;
99     }
100     $cur = pop @chld;
101 elmex 1.4 $nb->remove ($cv);
102 elmex 1.3 $nb->set_current_page ($cur);
103 elmex 1.4
104     delete $chatviews->{$id};
105 elmex 1.3 0
106     });
107 elmex 1.4
108 elmex 1.12 my $preadd = $nb->get_current_page;
109 elmex 1.4 $nb->add ($cv);
110 elmex 1.12 $nb->set_current_page ($preadd);
111 elmex 1.4 }
112    
113     sub touch_channel {
114     my ($self, $id) = @_;
115 elmex 1.12
116 elmex 1.10 if (not exists $self->{chatviews}->{$id}) {
117 elmex 1.4 $self->add_chat ($id);
118     }
119     }
120    
121     sub highlight_channel {
122     my ($self, $id) = @_;
123 elmex 1.12
124 elmex 1.4 my $cv = $self->{chatviews}->{$id};
125 elmex 1.8 $cv->{_channel_highlighted} = 1;
126 elmex 1.4 my $tab = $cv->{_tab_button};
127 elmex 1.12
128 elmex 1.8 $tab->set_markup (
129 elmex 1.9 clr_hlt (defined $id ? $self->{channel_info}->{$id}->{title} : "Log")
130 elmex 1.8 );
131 elmex 1.4 }
132    
133     sub unhighlight_channel {
134     my ($self, $id) = @_;
135 elmex 1.8
136 elmex 1.4 my $cv = $self->{chatviews}->{$id};
137 elmex 1.8 $cv->{_channel_highlighted} = 0;
138 elmex 1.4 my $tab = $cv->{_tab_button};
139 elmex 1.9
140     $tab->set_markup (clr_act (defined $id ? $self->{channel_info}->{$id}->{title} : "Log"));
141 elmex 1.8 }
142    
143     sub update_current_tab {
144     my ($self, $page) = @_;
145 elmex 1.12
146 elmex 1.8 my $tab = $page->{_tab_button};
147 elmex 1.9 my $label;
148 elmex 1.12
149 elmex 1.9 if (defined $page->{_chat_id}) {
150     $label = $self->{channel_info}->{$page->{_chat_id}}->{title};
151     }
152 elmex 1.12
153 elmex 1.8 $label = "Log" unless defined $label;
154 elmex 1.9
155     $tab->set_markup (clr_act ($label));
156 elmex 1.8
157     for ($self->{nb}->pages) {
158     next if $_ eq $page;
159 elmex 1.12 next if $_->{_channel_highlighted};
160    
161 elmex 1.8 my $tab = $_->{_tab_button};
162     next unless $tab;
163    
164 elmex 1.9 my $label;
165 elmex 1.12
166 elmex 1.9 if (defined $_->{_chat_id}) {
167     $label = $self->{channel_info}->{$_->{_chat_id}}->{title};
168     }
169 elmex 1.12
170 elmex 1.8 $label = "Log" unless defined $label;
171    
172 elmex 1.9 $tab->set_markup (clr_def ($label));
173 elmex 1.8 }
174 elmex 1.4 }
175    
176     sub add_channel {
177     my ($self, $info) = @_;
178 elmex 1.12
179 elmex 1.4 $self->{channel_info}->{$info->{id}} = $info;
180     $self->touch_channel ($info->{id});
181     }
182    
183 elmex 1.3 sub message {
184     my ($self, $para) = @_;
185 elmex 1.12
186     #d# require Data::Dumper;
187     #d# print "FOO[".Data::Dumper->Dump ([$para])."]\n";
188    
189 elmex 1.4 my $id = $para->{type};
190    
191 elmex 1.9 if (exists $self->{channel_info}->{$id}) {
192 elmex 1.4 $self->touch_channel ($id);
193 elmex 1.12
194 elmex 1.10 if (my $cv = $self->{chatviews}->{$id}) {
195 elmex 1.12
196 elmex 1.10 if ($cv != $self->{nb}->get_current_page) {
197     $self->highlight_channel ($id);
198     }
199 elmex 1.12
200     if ($para->{color_flags} & NDI_REPLY) {
201     $self->{nb}->set_current_page ($cv);
202     }
203 elmex 1.10 }
204 elmex 1.12
205 elmex 1.4 $self->{chatviews}->{$id}->message ($para);
206 elmex 1.12
207 elmex 1.4 } else {
208     $self->{main_log}->message ($para);
209     }
210 elmex 1.1 }
211    
212     sub activate_console {
213     my ($self, $preset) = @_;
214 elmex 1.12
215 elmex 1.3 $self->{main_log}->activate_console ($preset);
216 elmex 1.1 }
217    
218 elmex 1.12 sub activate_current {
219     my ($self) = @_;
220    
221     $self->{nb}->get_current_page->activate_console;
222     }
223    
224 elmex 1.1 sub set_fontsize {
225     my ($self, $size) = @_;
226 elmex 1.12
227 elmex 1.11 for (values %{$self->{chatviews}}, $self->{main_log}) {
228     $_->set_fontsize ($size);
229     }
230 elmex 1.1 }
231    
232     sub set_max_para {
233     my ($self, $max_par) = @_;
234 elmex 1.12
235 elmex 1.11 for (values %{$self->{chatviews}}, $self->{main_log}) {
236     $_->set_max_para ($max_par);
237     }
238 elmex 1.1 }
239 root 1.2
240 elmex 1.12 sub user_switch_to_page {
241     my ($self, $page) = @_;
242    
243     $page = $page eq '0' ? 10 : $page;
244    
245     my @tabs = $self->{nb}->pages;
246    
247     for (my $i = 0; $i < ($page - 1); $i++) {
248     shift @tabs;
249     }
250    
251     my $page = shift @tabs;
252     return unless $page;
253    
254     $self->{nb}->set_current_page ($page);
255     $page->activate_console;
256     }
257    
258 root 1.2 1;
259