ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/MessageWindow.pm
Revision: 1.6
Committed: Wed Jul 25 15:06:21 2007 UTC (17 years ago) by elmex
Branch: MAIN
Changes since 1.5: +11 -8 lines
Log Message:
fixed some issues with the tabs

File Contents

# Content
1 package CFPlus::UI::MessageWindow;
2
3 use strict;
4 use utf8;
5
6 use Scalar::Util qw/weaken/;
7 use CFPlus::UI::ChatView;
8
9 our @ISA = CFPlus::UI::Toplevel::;
10
11 our %channel_info;
12
13 sub add_channel_info {
14 my ($info) = @_;
15 }
16
17 sub new {
18 my $class = shift;
19
20 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 child => (my $nb = CFPlus::UI::Notebook->new (expand => 1)),
29 has_close_button => 1
30 );
31
32 $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
41 $self
42 }
43
44 sub add_chat {
45 my ($self, $id) = @_;
46
47 my $chatviews = $self->{chatviews};
48 my $chaninfo = $self->{channel_info}->{$id};
49 my $nb = $self->{nb};
50
51 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 $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
73 $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
82 my @chld = $nb->pages;
83 my $cur = pop @chld;
84 while (@chld && $cur != $cv) {
85 $cur = pop @chld;
86 }
87 $cur = pop @chld;
88 $nb->remove ($cv);
89 $nb->set_current_page ($cur);
90
91 delete $chatviews->{$id};
92 0
93 });
94
95 $nb->add ($cv);
96 #$nb->set_current_page ($cv);
97 }
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 require Data::Dumper;
127 print "DUMPER:" . Data::Dumper->Dump ([$info]) . "\n";
128 $self->{channel_info}->{$info->{id}} = $info;
129 $self->touch_channel ($info->{id});
130 }
131
132 sub message {
133 my ($self, $para) = @_;
134 my $id = $para->{type};
135
136 if ($self->{channel_info}->{$id}) {
137 $self->touch_channel ($id);
138 $self->{chatviews}->{$id}->message ($para);
139 } else {
140 $self->{main_log}->message ($para);
141 }
142 }
143
144 sub activate_console {
145 my ($self, $preset) = @_;
146 $self->{main_log}->activate_console ($preset);
147 }
148
149 sub set_fontsize {
150 my ($self, $size) = @_;
151 $self->{main_log}->set_fontsize ($size);
152 }
153
154 sub set_max_para {
155 my ($self, $max_par) = @_;
156 $self->{main_log}->set_max_para ($max_par);
157 }
158
159 1;
160