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

# 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.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 elmex 1.6 require Data::Dumper;
127     print "DUMPER:" . Data::Dumper->Dump ([$info]) . "\n";
128 elmex 1.4 $self->{channel_info}->{$info->{id}} = $info;
129     $self->touch_channel ($info->{id});
130     }
131    
132 elmex 1.3 sub message {
133     my ($self, $para) = @_;
134 elmex 1.4 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 elmex 1.1 }
143    
144     sub activate_console {
145     my ($self, $preset) = @_;
146 elmex 1.3 $self->{main_log}->activate_console ($preset);
147 elmex 1.1 }
148    
149     sub set_fontsize {
150     my ($self, $size) = @_;
151 elmex 1.3 $self->{main_log}->set_fontsize ($size);
152 elmex 1.1 }
153    
154     sub set_max_para {
155     my ($self, $max_par) = @_;
156 elmex 1.3 $self->{main_log}->set_max_para ($max_par);
157 elmex 1.1 }
158 root 1.2
159     1;
160