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.1 |
sub new { |
18 |
|
|
my $class = shift; |
19 |
root |
1.2 |
|
20 |
elmex |
1.1 |
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 |
elmex |
1.3 |
child => (my $nb = CFPlus::UI::Notebook->new (expand => 1)), |
29 |
elmex |
1.1 |
has_close_button => 1 |
30 |
|
|
); |
31 |
root |
1.2 |
|
32 |
elmex |
1.4 |
$self->{nb} = $nb; |
33 |
|
|
$self->{chatviews} = {}; |
34 |
elmex |
1.1 |
|
35 |
elmex |
1.8 |
$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 |
elmex |
1.1 |
$self |
52 |
|
|
} |
53 |
|
|
|
54 |
elmex |
1.3 |
sub add_chat { |
55 |
elmex |
1.4 |
my ($self, $id) = @_; |
56 |
|
|
|
57 |
|
|
my $chatviews = $self->{chatviews}; |
58 |
|
|
my $chaninfo = $self->{channel_info}->{$id}; |
59 |
|
|
my $nb = $self->{nb}; |
60 |
|
|
|
61 |
elmex |
1.6 |
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 |
elmex |
1.4 |
$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 |
elmex |
1.8 |
$cv->{_chat_id} = $id; |
81 |
elmex |
1.4 |
$cv->{_tab_button} = $b; |
82 |
|
|
weaken $cv->{_tab_button}; |
83 |
elmex |
1.1 |
|
84 |
elmex |
1.4 |
$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 |
elmex |
1.1 |
|
93 |
elmex |
1.3 |
my @chld = $nb->pages; |
94 |
|
|
my $cur = pop @chld; |
95 |
elmex |
1.4 |
while (@chld && $cur != $cv) { |
96 |
elmex |
1.3 |
$cur = pop @chld; |
97 |
|
|
} |
98 |
|
|
$cur = pop @chld; |
99 |
elmex |
1.4 |
$nb->remove ($cv); |
100 |
elmex |
1.3 |
$nb->set_current_page ($cur); |
101 |
elmex |
1.4 |
|
102 |
|
|
delete $chatviews->{$id}; |
103 |
elmex |
1.3 |
0 |
104 |
|
|
}); |
105 |
elmex |
1.4 |
|
106 |
|
|
$nb->add ($cv); |
107 |
elmex |
1.5 |
#$nb->set_current_page ($cv); |
108 |
elmex |
1.4 |
} |
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 |
elmex |
1.8 |
$cv->{_channel_highlighted} = 1; |
125 |
elmex |
1.4 |
my $tab = $cv->{_tab_button}; |
126 |
elmex |
1.8 |
$tab->set_markup ( |
127 |
|
|
"<span foreground='#ff0000'>" |
128 |
|
|
.$self->{channel_info}->{$id}->{title} |
129 |
|
|
."</span>" |
130 |
|
|
); |
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.8 |
$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 |
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 |
|
|
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 |
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 |
|
|
|