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

# 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    
9 elmex 1.1 our @ISA = CFPlus::UI::Toplevel::;
10    
11 elmex 1.4 our %channel_info;
12    
13     sub add_channel_info {
14     my ($info) = @_;
15     }
16    
17 elmex 1.9
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 elmex 1.1 sub new {
24     my $class = shift;
25 root 1.2
26 elmex 1.1 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 elmex 1.3 child => (my $nb = CFPlus::UI::Notebook->new (expand => 1)),
35 elmex 1.1 has_close_button => 1
36     );
37 root 1.2
38 elmex 1.4 $self->{nb} = $nb;
39     $self->{chatviews} = {};
40 elmex 1.1
41 elmex 1.8 $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 elmex 1.1 $self
58     }
59    
60 elmex 1.3 sub add_chat {
61 elmex 1.4 my ($self, $id) = @_;
62    
63     my $chatviews = $self->{chatviews};
64     my $chaninfo = $self->{channel_info}->{$id};
65     my $nb = $self->{nb};
66    
67 elmex 1.6 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 elmex 1.4 $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 elmex 1.9 expand => 1, markup => clr_def ($chaninfo->{title}), valign => 0, align => 0
83 elmex 1.4 )
84     );
85    
86 elmex 1.8 $cv->{_chat_id} = $id;
87 elmex 1.4 $cv->{_tab_button} = $b;
88     weaken $cv->{_tab_button};
89 elmex 1.1
90 elmex 1.4 $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 elmex 1.1
99 elmex 1.3 my @chld = $nb->pages;
100     my $cur = pop @chld;
101 elmex 1.4 while (@chld && $cur != $cv) {
102 elmex 1.3 $cur = pop @chld;
103     }
104     $cur = pop @chld;
105 elmex 1.4 $nb->remove ($cv);
106 elmex 1.3 $nb->set_current_page ($cur);
107 elmex 1.4
108     delete $chatviews->{$id};
109 elmex 1.3 0
110     });
111 elmex 1.4
112     $nb->add ($cv);
113 elmex 1.5 #$nb->set_current_page ($cv);
114 elmex 1.4 }
115    
116     sub touch_channel {
117     my ($self, $id) = @_;
118 elmex 1.10 if (not exists $self->{chatviews}->{$id}) {
119 elmex 1.4 $self->add_chat ($id);
120     }
121     }
122    
123     sub highlight_channel {
124     my ($self, $id) = @_;
125     my $cv = $self->{chatviews}->{$id};
126 elmex 1.8 $cv->{_channel_highlighted} = 1;
127 elmex 1.4 my $tab = $cv->{_tab_button};
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     my $tab = $page->{_tab_button};
146 elmex 1.9 my $label;
147     if (defined $page->{_chat_id}) {
148     $label = $self->{channel_info}->{$page->{_chat_id}}->{title};
149     }
150 elmex 1.8 $label = "Log" unless defined $label;
151 elmex 1.9
152     $tab->set_markup (clr_act ($label));
153 elmex 1.8
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 elmex 1.9 my $label;
161     if (defined $_->{_chat_id}) {
162     $label = $self->{channel_info}->{$_->{_chat_id}}->{title};
163     }
164 elmex 1.8 $label = "Log" unless defined $label;
165    
166 elmex 1.9 $tab->set_markup (clr_def ($label));
167 elmex 1.8 }
168 elmex 1.4 }
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 elmex 1.3 sub message {
177     my ($self, $para) = @_;
178 elmex 1.4 my $id = $para->{type};
179    
180 elmex 1.9 if (exists $self->{channel_info}->{$id}) {
181 elmex 1.4 $self->touch_channel ($id);
182 elmex 1.10 if (my $cv = $self->{chatviews}->{$id}) {
183     if ($cv != $self->{nb}->get_current_page) {
184     $self->highlight_channel ($id);
185     }
186     }
187 elmex 1.4 $self->{chatviews}->{$id}->message ($para);
188     } else {
189     $self->{main_log}->message ($para);
190     }
191 elmex 1.1 }
192    
193     sub activate_console {
194     my ($self, $preset) = @_;
195 elmex 1.3 $self->{main_log}->activate_console ($preset);
196 elmex 1.1 }
197    
198     sub set_fontsize {
199     my ($self, $size) = @_;
200 elmex 1.11 for (values %{$self->{chatviews}}, $self->{main_log}) {
201     $_->set_fontsize ($size);
202     }
203 elmex 1.1 }
204    
205     sub set_max_para {
206     my ($self, $max_par) = @_;
207 elmex 1.11 for (values %{$self->{chatviews}}, $self->{main_log}) {
208     $_->set_max_para ($max_par);
209     }
210 elmex 1.1 }
211 root 1.2
212     1;
213