ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/MessageWindow.pm
Revision: 1.8
Committed: Fri Jul 27 17:24:29 2007 UTC (16 years, 11 months ago) by elmex
Branch: MAIN
Changes since 1.7: +58 -8 lines
Log Message:
tweaked tabs a bit

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 sub new {
18 my $class = shift;
19
20 my $self = $class->SUPER::new (
21 name => "message_window",
22 title => "Messages",
23 border_bg => [1, 1, 1, 1],
24 x => "max",
25 y => 0,
26 force_w => $::WIDTH * 0.4,
27 force_h => $::HEIGHT * 0.5,
28 child => (my $nb = CFPlus::UI::Notebook->new (expand => 1)),
29 has_close_button => 1
30 );
31
32 $self->{nb} = $nb;
33 $self->{chatviews} = {};
34
35 $nb->connect (page_changed => sub {
36 my ($nb, $page) = @_;
37 $self->update_current_tab ($page);
38 });
39
40 my $l = $self->{main_log} =
41 CFPlus::UI::ChatView->new (expand => 1, say_command => '');
42 $l->{_tab_button} =
43 $l->{c_tab} =
44 CFPlus::UI::Button->new (
45 markup => "Log", tooltip => "This is the main log of the server."
46 );
47
48 $nb->add ($l);
49 $self->update_current_tab ($l);
50
51 $self
52 }
53
54 sub add_chat {
55 my ($self, $id) = @_;
56
57 my $chatviews = $self->{chatviews};
58 my $chaninfo = $self->{channel_info}->{$id};
59 my $nb = $self->{nb};
60
61 my $cv = $chatviews->{$id} =
62 CFPlus::UI::ChatView->new (
63 expand => 1,
64 say_command => $chaninfo->{reply},
65 entry_tooltip => $chaninfo->{tooltip},
66 text_tooltip => "Conversation with $chaninfo->{title}"
67 );
68
69 my $bb = CFPlus::UI::ButtonBin->new (tooltip => $chaninfo->{tooltip});
70 $cv->{c_tab} = $bb;
71
72 $bb->add (my $vb = CFPlus::UI::Box->new);
73 $bb->connect (activate => sub { $self->unhighlight_channel ($id); 0 });
74 $vb->add (
75 my $b = CFPlus::UI::Label->new (
76 expand => 1, markup => $chaninfo->{title}, valign => 0, align => 0
77 )
78 );
79
80 $cv->{_chat_id} = $id;
81 $cv->{_tab_button} = $b;
82 weaken $cv->{_tab_button};
83
84 $vb->add (
85 my $b = CFPlus::UI::ImageButton->new (
86 path => 'x1_close.png',
87 scale => 0.3
88 )
89 );
90 $b->connect (activate => sub {
91 my $b = shift;
92
93 my @chld = $nb->pages;
94 my $cur = pop @chld;
95 while (@chld && $cur != $cv) {
96 $cur = pop @chld;
97 }
98 $cur = pop @chld;
99 $nb->remove ($cv);
100 $nb->set_current_page ($cur);
101
102 delete $chatviews->{$id};
103 0
104 });
105
106 $nb->add ($cv);
107 #$nb->set_current_page ($cv);
108 }
109
110 sub touch_channel {
111 my ($self, $id) = @_;
112 if (my $cv = $self->{chatviews}->{$id}) {
113 if ($cv != $self->{nb}->get_current_page) {
114 $self->highlight_channel ($id);
115 }
116 } else {
117 $self->add_chat ($id);
118 }
119 }
120
121 sub highlight_channel {
122 my ($self, $id) = @_;
123 my $cv = $self->{chatviews}->{$id};
124 $cv->{_channel_highlighted} = 1;
125 my $tab = $cv->{_tab_button};
126 $tab->set_markup (
127 "<span foreground='#ff0000'>"
128 .$self->{channel_info}->{$id}->{title}
129 ."</span>"
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 $tab->set_markup (
140 "<span foreground='#ffff00'><b>"
141 .$self->{channel_info}->{$id}->{title}
142 ."</b></span>"
143 );
144 }
145
146 sub update_current_tab {
147 my ($self, $page) = @_;
148 my $tab = $page->{_tab_button};
149 my $label = $self->{channel_info}->{$page->{_chat_id}}->{title};
150 $label = "Log" unless defined $label;
151 $tab->set_markup (
152 "<span foreground='#ffff00'><b>"
153 .$label
154 ."</b></span>"
155 );
156
157 for ($self->{nb}->pages) {
158 next if $_ eq $page;
159 my $tab = $_->{_tab_button};
160 next if $_->{_channel_highlighted};
161 next unless $tab;
162
163 my $label = $self->{channel_info}->{$_->{_chat_id}}->{title};
164 $label = "Log" unless defined $label;
165
166 $tab->set_markup (
167 "<span foreground='#ffffff'>"
168 .$label
169 ."</span>"
170 );
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 ($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