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 (17 years ago) by elmex
Branch: MAIN
Changes since 1.8: +22 -22 lines
Log Message:
fixed problem with ghosttabs and changes highlighting colors

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     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 elmex 1.8 $cv->{_channel_highlighted} = 1;
131 elmex 1.4 my $tab = $cv->{_tab_button};
132 elmex 1.8 $tab->set_markup (
133 elmex 1.9 clr_hlt (defined $id ? $self->{channel_info}->{$id}->{title} : "Log")
134 elmex 1.8 );
135 elmex 1.4 }
136    
137     sub unhighlight_channel {
138     my ($self, $id) = @_;
139 elmex 1.8
140 elmex 1.4 my $cv = $self->{chatviews}->{$id};
141 elmex 1.8 $cv->{_channel_highlighted} = 0;
142 elmex 1.4 my $tab = $cv->{_tab_button};
143 elmex 1.9
144     $tab->set_markup (clr_act (defined $id ? $self->{channel_info}->{$id}->{title} : "Log"));
145 elmex 1.8 }
146    
147     sub update_current_tab {
148     my ($self, $page) = @_;
149     my $tab = $page->{_tab_button};
150 elmex 1.9 my $label;
151     if (defined $page->{_chat_id}) {
152     $label = $self->{channel_info}->{$page->{_chat_id}}->{title};
153     }
154 elmex 1.8 $label = "Log" unless defined $label;
155 elmex 1.9
156     $tab->set_markup (clr_act ($label));
157 elmex 1.8
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 elmex 1.9 my $label;
165     if (defined $_->{_chat_id}) {
166     $label = $self->{channel_info}->{$_->{_chat_id}}->{title};
167     }
168 elmex 1.8 $label = "Log" unless defined $label;
169    
170 elmex 1.9 $tab->set_markup (clr_def ($label));
171 elmex 1.8 }
172 elmex 1.4 }
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 elmex 1.3 sub message {
181     my ($self, $para) = @_;
182 elmex 1.4 my $id = $para->{type};
183    
184 elmex 1.9 if (exists $self->{channel_info}->{$id}) {
185 elmex 1.4 $self->touch_channel ($id);
186     $self->{chatviews}->{$id}->message ($para);
187     } else {
188     $self->{main_log}->message ($para);
189     }
190 elmex 1.1 }
191    
192     sub activate_console {
193     my ($self, $preset) = @_;
194 elmex 1.3 $self->{main_log}->activate_console ($preset);
195 elmex 1.1 }
196    
197     sub set_fontsize {
198     my ($self, $size) = @_;
199 elmex 1.3 $self->{main_log}->set_fontsize ($size);
200 elmex 1.1 }
201    
202     sub set_max_para {
203     my ($self, $max_par) = @_;
204 elmex 1.3 $self->{main_log}->set_max_para ($max_par);
205 elmex 1.1 }
206 root 1.2
207     1;
208