ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/MessageWindow.pm
Revision: 1.11
Committed: Tue Jul 31 14:47:07 2007 UTC (17 years ago) by elmex
Branch: MAIN
Changes since 1.10: +6 -2 lines
Log Message:
expanded the adjustment of message fontsize and max message log lines
to the chat tabs.

File Contents

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