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 |
$nb->add_tab ( |
33 |
|
|
"Log", |
34 |
|
|
$self->{main_log} = CFPlus::UI::ChatView->new (expand => 1, say_command => ''), |
35 |
|
|
"This is the main log of the server." |
36 |
|
|
); |
37 |
|
|
|
38 |
|
|
$self->{nb} = $nb; |
39 |
|
|
$self->{chatviews} = {}; |
40 |
elmex |
1.1 |
|
41 |
|
|
$self |
42 |
|
|
} |
43 |
|
|
|
44 |
elmex |
1.3 |
sub add_chat { |
45 |
elmex |
1.4 |
my ($self, $id) = @_; |
46 |
|
|
|
47 |
|
|
my $chatviews = $self->{chatviews}; |
48 |
|
|
my $chaninfo = $self->{channel_info}->{$id}; |
49 |
|
|
my $nb = $self->{nb}; |
50 |
|
|
|
51 |
elmex |
1.6 |
my $cv = $chatviews->{$id} = |
52 |
|
|
CFPlus::UI::ChatView->new ( |
53 |
|
|
expand => 1, |
54 |
|
|
say_command => $chaninfo->{reply}, |
55 |
|
|
entry_tooltip => $chaninfo->{tooltip}, |
56 |
|
|
text_tooltip => "Conversation with $chaninfo->{title}" |
57 |
|
|
); |
58 |
|
|
|
59 |
|
|
my $bb = CFPlus::UI::ButtonBin->new (tooltip => $chaninfo->{tooltip}); |
60 |
elmex |
1.4 |
$cv->{c_tab} = $bb; |
61 |
|
|
|
62 |
|
|
$bb->add (my $vb = CFPlus::UI::Box->new); |
63 |
|
|
$bb->connect (activate => sub { $self->unhighlight_channel ($id); 0 }); |
64 |
|
|
$vb->add ( |
65 |
|
|
my $b = CFPlus::UI::Label->new ( |
66 |
|
|
expand => 1, markup => $chaninfo->{title}, valign => 0, align => 0 |
67 |
|
|
) |
68 |
|
|
); |
69 |
|
|
|
70 |
|
|
$cv->{_tab_button} = $b; |
71 |
|
|
weaken $cv->{_tab_button}; |
72 |
elmex |
1.1 |
|
73 |
elmex |
1.4 |
$vb->add ( |
74 |
|
|
my $b = CFPlus::UI::ImageButton->new ( |
75 |
|
|
path => 'x1_close.png', |
76 |
|
|
scale => 0.3 |
77 |
|
|
) |
78 |
|
|
); |
79 |
|
|
$b->connect (activate => sub { |
80 |
|
|
my $b = shift; |
81 |
elmex |
1.1 |
|
82 |
elmex |
1.3 |
my @chld = $nb->pages; |
83 |
|
|
my $cur = pop @chld; |
84 |
elmex |
1.4 |
while (@chld && $cur != $cv) { |
85 |
elmex |
1.3 |
$cur = pop @chld; |
86 |
|
|
} |
87 |
|
|
$cur = pop @chld; |
88 |
elmex |
1.4 |
$nb->remove ($cv); |
89 |
elmex |
1.3 |
$nb->set_current_page ($cur); |
90 |
elmex |
1.4 |
|
91 |
|
|
delete $chatviews->{$id}; |
92 |
elmex |
1.3 |
0 |
93 |
|
|
}); |
94 |
elmex |
1.4 |
|
95 |
|
|
$nb->add ($cv); |
96 |
elmex |
1.5 |
#$nb->set_current_page ($cv); |
97 |
elmex |
1.4 |
} |
98 |
|
|
|
99 |
|
|
sub touch_channel { |
100 |
|
|
my ($self, $id) = @_; |
101 |
|
|
if (my $cv = $self->{chatviews}->{$id}) { |
102 |
|
|
if ($cv != $self->{nb}->get_current_page) { |
103 |
|
|
$self->highlight_channel ($id); |
104 |
|
|
} |
105 |
|
|
} else { |
106 |
|
|
$self->add_chat ($id); |
107 |
|
|
} |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
sub highlight_channel { |
111 |
|
|
my ($self, $id) = @_; |
112 |
|
|
my $cv = $self->{chatviews}->{$id}; |
113 |
|
|
my $tab = $cv->{_tab_button}; |
114 |
|
|
$tab->set_markup ("<span foreground='#ff0000'>" . $self->{channel_info}->{$id}->{title} . "</span>"); |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
sub unhighlight_channel { |
118 |
|
|
my ($self, $id) = @_; |
119 |
|
|
my $cv = $self->{chatviews}->{$id}; |
120 |
|
|
my $tab = $cv->{_tab_button}; |
121 |
|
|
$tab->set_markup ($self->{channel_info}->{$id}->{title}); |
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
sub add_channel { |
125 |
|
|
my ($self, $info) = @_; |
126 |
|
|
$self->{channel_info}->{$info->{id}} = $info; |
127 |
|
|
$self->touch_channel ($info->{id}); |
128 |
|
|
} |
129 |
|
|
|
130 |
elmex |
1.3 |
sub message { |
131 |
|
|
my ($self, $para) = @_; |
132 |
elmex |
1.4 |
my $id = $para->{type}; |
133 |
|
|
|
134 |
|
|
if ($self->{channel_info}->{$id}) { |
135 |
|
|
$self->touch_channel ($id); |
136 |
|
|
$self->{chatviews}->{$id}->message ($para); |
137 |
|
|
} else { |
138 |
|
|
$self->{main_log}->message ($para); |
139 |
|
|
} |
140 |
elmex |
1.1 |
} |
141 |
|
|
|
142 |
|
|
sub activate_console { |
143 |
|
|
my ($self, $preset) = @_; |
144 |
elmex |
1.3 |
$self->{main_log}->activate_console ($preset); |
145 |
elmex |
1.1 |
} |
146 |
|
|
|
147 |
|
|
sub set_fontsize { |
148 |
|
|
my ($self, $size) = @_; |
149 |
elmex |
1.3 |
$self->{main_log}->set_fontsize ($size); |
150 |
elmex |
1.1 |
} |
151 |
|
|
|
152 |
|
|
sub set_max_para { |
153 |
|
|
my ($self, $max_par) = @_; |
154 |
elmex |
1.3 |
$self->{main_log}->set_max_para ($max_par); |
155 |
elmex |
1.1 |
} |
156 |
root |
1.2 |
|
157 |
|
|
1; |
158 |
|
|
|