ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/MessageWindow.pm
Revision: 1.9
Committed: Tue Jul 31 06:49:38 2007 UTC (16 years, 11 months ago) by elmex
Branch: MAIN
Changes since 1.8: +22 -22 lines
Log Message:
fixed problem with ghosttabs and changes highlighting colors

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 (my $cv = $self->{chatviews}->{$id}) {
119 if ($cv != $self->{nb}->get_current_page) {
120 $self->highlight_channel ($id);
121 }
122 } else {
123 $self->add_chat ($id);
124 }
125 }
126
127 sub highlight_channel {
128 my ($self, $id) = @_;
129 my $cv = $self->{chatviews}->{$id};
130 $cv->{_channel_highlighted} = 1;
131 my $tab = $cv->{_tab_button};
132 $tab->set_markup (
133 clr_hlt (defined $id ? $self->{channel_info}->{$id}->{title} : "Log")
134 );
135 }
136
137 sub unhighlight_channel {
138 my ($self, $id) = @_;
139
140 my $cv = $self->{chatviews}->{$id};
141 $cv->{_channel_highlighted} = 0;
142 my $tab = $cv->{_tab_button};
143
144 $tab->set_markup (clr_act (defined $id ? $self->{channel_info}->{$id}->{title} : "Log"));
145 }
146
147 sub update_current_tab {
148 my ($self, $page) = @_;
149 my $tab = $page->{_tab_button};
150 my $label;
151 if (defined $page->{_chat_id}) {
152 $label = $self->{channel_info}->{$page->{_chat_id}}->{title};
153 }
154 $label = "Log" unless defined $label;
155
156 $tab->set_markup (clr_act ($label));
157
158 for ($self->{nb}->pages) {
159 next if $_ eq $page;
160 my $tab = $_->{_tab_button};
161 next if $_->{_channel_highlighted};
162 next unless $tab;
163
164 my $label;
165 if (defined $_->{_chat_id}) {
166 $label = $self->{channel_info}->{$_->{_chat_id}}->{title};
167 }
168 $label = "Log" unless defined $label;
169
170 $tab->set_markup (clr_def ($label));
171 }
172 }
173
174 sub add_channel {
175 my ($self, $info) = @_;
176 $self->{channel_info}->{$info->{id}} = $info;
177 $self->touch_channel ($info->{id});
178 }
179
180 sub message {
181 my ($self, $para) = @_;
182 my $id = $para->{type};
183
184 if (exists $self->{channel_info}->{$id}) {
185 $self->touch_channel ($id);
186 $self->{chatviews}->{$id}->message ($para);
187 } else {
188 $self->{main_log}->message ($para);
189 }
190 }
191
192 sub activate_console {
193 my ($self, $preset) = @_;
194 $self->{main_log}->activate_console ($preset);
195 }
196
197 sub set_fontsize {
198 my ($self, $size) = @_;
199 $self->{main_log}->set_fontsize ($size);
200 }
201
202 sub set_max_para {
203 my ($self, $max_par) = @_;
204 $self->{main_log}->set_max_para ($max_par);
205 }
206
207 1;
208