… | |
… | |
34 | $self->{nb} = $nb; |
34 | $self->{nb} = $nb; |
35 | $self->{chatviews} = {}; |
35 | $self->{chatviews} = {}; |
36 | |
36 | |
37 | $nb->connect (page_changed => sub { |
37 | $nb->connect (page_changed => sub { |
38 | my ($nb, $page) = @_; |
38 | my ($nb, $page) = @_; |
39 | $self->update_current_tab ($page); |
39 | $self->set_current_tab ($page); |
|
|
40 | }); |
|
|
41 | $nb->connect (c_add => sub { |
|
|
42 | $self->update_tabs; |
40 | }); |
43 | }); |
41 | |
44 | |
42 | my $l = $self->{main_log} = |
45 | my $l = $self->{main_log} = |
43 | CFPlus::UI::ChatView->new (expand => 1, say_command => ''); |
46 | CFPlus::UI::ChatView->new (expand => 1, say_command => ''); |
44 | $l->{_tab_button} = |
47 | $l->{_tab_label} = |
45 | $l->{c_tab} = |
48 | $l->{c_tab} = |
46 | CFPlus::UI::Button->new ( |
49 | CFPlus::UI::Button->new ( |
47 | markup => "Log", tooltip => "This is the main log of the server." |
50 | markup => "Log", tooltip => "This is the main log of the server." |
48 | ); |
51 | ); |
49 | |
52 | |
50 | $nb->add ($l); |
53 | $nb->add ($l); |
51 | $self->update_current_tab ($l); |
54 | $nb->set_current_page ($l); |
52 | |
55 | |
53 | $self |
56 | $self |
54 | } |
57 | } |
55 | |
58 | |
56 | sub add_chat { |
59 | sub add_chat { |
… | |
… | |
77 | expand => 1, markup => clr_def ($chaninfo->{title}), valign => 0, align => 0 |
80 | expand => 1, markup => clr_def ($chaninfo->{title}), valign => 0, align => 0 |
78 | ) |
81 | ) |
79 | ); |
82 | ); |
80 | |
83 | |
81 | $cv->{_chat_id} = $id; |
84 | $cv->{_chat_id} = $id; |
82 | $cv->{_tab_button} = $b; |
85 | $cv->{_tab_label} = $b; |
83 | weaken $cv->{_tab_button}; |
86 | weaken $cv->{_tab_label}; |
84 | |
87 | |
85 | $vb->add ( |
88 | $vb->add ( |
86 | my $b = CFPlus::UI::ImageButton->new ( |
89 | my $b = CFPlus::UI::ImageButton->new ( |
87 | path => 'x1_close.png', |
90 | path => 'x1_close.png', |
88 | scale => 0.3 |
91 | scale => 0.3 |
… | |
… | |
121 | my ($self, $id, $hlt_func) = @_; |
124 | my ($self, $id, $hlt_func) = @_; |
122 | |
125 | |
123 | $hlt_func ||= \&clr_hlt; |
126 | $hlt_func ||= \&clr_hlt; |
124 | |
127 | |
125 | my $cv = $self->{chatviews}->{$id}; |
128 | my $cv = $self->{chatviews}->{$id}; |
|
|
129 | |
|
|
130 | # the clr_hlt2 has a "higher priority" |
|
|
131 | unless ($cv->{_channel_highlighted} eq \&clr_hlt2) { |
126 | $cv->{_channel_highlighted} = 1; |
132 | $cv->{_channel_highlighted} = $hlt_func; |
127 | my $tab = $cv->{_tab_button}; |
133 | } |
128 | |
134 | |
129 | $tab->set_markup ( |
135 | $self->update_tabs; |
130 | $hlt_func->(defined $id ? $self->{channel_info}->{$id}->{title} : "Log") |
|
|
131 | ); |
|
|
132 | } |
136 | } |
133 | |
137 | |
134 | sub unhighlight_channel { |
|
|
135 | my ($self, $id) = @_; |
|
|
136 | |
|
|
137 | my $cv = $self->{chatviews}->{$id}; |
|
|
138 | $cv->{_channel_highlighted} = 0; |
|
|
139 | my $tab = $cv->{_tab_button}; |
|
|
140 | |
|
|
141 | $tab->set_markup (clr_act (defined $id ? $self->{channel_info}->{$id}->{title} : "Log")); |
|
|
142 | } |
|
|
143 | |
|
|
144 | sub update_current_tab { |
138 | sub set_current_tab { |
145 | my ($self, $page) = @_; |
139 | my ($self, $page) = @_; |
146 | |
|
|
147 | my $tab = $page->{_tab_button}; |
|
|
148 | my $label; |
|
|
149 | |
|
|
150 | if (defined $page->{_chat_id}) { |
|
|
151 | $label = $self->{channel_info}->{$page->{_chat_id}}->{title}; |
|
|
152 | $self->unhighlight_channel ($page->{_chat_id}); |
|
|
153 | } |
|
|
154 | |
|
|
155 | $label = "Log" unless defined $label; |
|
|
156 | |
|
|
157 | $tab->set_markup (clr_act ($label)); |
|
|
158 | |
140 | |
159 | for ($self->{nb}->pages) { |
141 | for ($self->{nb}->pages) { |
160 | next if $_ eq $page; |
142 | next if $_ eq $page; |
|
|
143 | $_->{_active} = 0; |
|
|
144 | } |
|
|
145 | $page->{_active} = 1; |
|
|
146 | |
|
|
147 | # $label = "Log" unless defined $label; |
|
|
148 | |
|
|
149 | # $tab->set_markup (clr_act ($label)); |
|
|
150 | |
|
|
151 | $self->update_tabs; |
|
|
152 | # for ($self->{nb}->pages) { |
|
|
153 | # next if $_ eq $page; |
161 | next if $_->{_channel_highlighted}; |
154 | # next if $_->{_channel_highlighted}; |
162 | |
155 | |
|
|
156 | # my $tab = $_->{_tab_label}; |
|
|
157 | # next unless $tab; |
|
|
158 | |
|
|
159 | # my $label; |
|
|
160 | |
|
|
161 | # if (defined $_->{_chat_id}) { |
|
|
162 | # $label = $self->{channel_info}->{$_->{_chat_id}}->{title}; |
|
|
163 | # } |
|
|
164 | |
|
|
165 | # $label = "Log" unless defined $label; |
|
|
166 | |
|
|
167 | # $tab->set_markup (clr_def ($label)); |
|
|
168 | # } |
|
|
169 | } |
|
|
170 | |
|
|
171 | sub update_tabs { |
|
|
172 | my ($self) = @_; |
|
|
173 | |
|
|
174 | my $i = 1; |
|
|
175 | for ($self->{nb}->pages) { |
|
|
176 | if ($i <= 10) { |
|
|
177 | $_->{_tab_pos} = $i++; |
|
|
178 | } else { |
|
|
179 | $_->{_tab_pos} = undef; |
|
|
180 | } |
|
|
181 | |
163 | my $tab = $_->{_tab_button}; |
182 | my $tab = $_->{_tab_label}; |
164 | next unless $tab; |
183 | next unless $tab; |
165 | |
184 | |
166 | my $label; |
185 | my ($label, $tooltip) = |
|
|
186 | ("Log", "This is the main log of the server."); |
167 | |
187 | |
168 | if (defined $_->{_chat_id}) { |
188 | if (defined $_->{_chat_id}) { |
169 | $label = $self->{channel_info}->{$_->{_chat_id}}->{title}; |
189 | my $chinfo = $self->{channel_info}->{$_->{_chat_id}}; |
|
|
190 | $label = $chinfo->{title}; |
|
|
191 | $tooltip = $chinfo->{tooltip}; |
|
|
192 | |
|
|
193 | if ($_->{_active}) { |
|
|
194 | $_->{_channel_highlighted} = 0; |
|
|
195 | } |
170 | } |
196 | } |
171 | |
197 | |
172 | $label = "Log" unless defined $label; |
198 | $_->{c_tab}->set_tooltip ( |
|
|
199 | $tooltip |
|
|
200 | . (defined $_->{_tab_pos} |
|
|
201 | ? "\n<small>To goto this tab press alt+" |
|
|
202 | . ($_->{_tab_pos} == 10 ? '0' : $_->{_tab_pos}) |
|
|
203 | . "</small>" |
|
|
204 | : "") |
|
|
205 | ); |
173 | |
206 | |
174 | $tab->set_markup (clr_def ($label)); |
207 | my $hltfunc = $_->{_channel_highlighted} |
|
|
208 | || ($_->{_active} ? \&clr_act : \&clr_def); |
|
|
209 | |
|
|
210 | $tab->set_markup ($hltfunc->("$label\-$_->{_tab_pos}")); |
175 | } |
211 | } |
176 | } |
212 | } |
177 | |
213 | |
178 | sub add_channel { |
214 | sub add_channel { |
179 | my ($self, $info) = @_; |
215 | my ($self, $info) = @_; |