ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/MessageWindow.pm
Revision: 1.5
Committed: Tue Jul 24 21:23:47 2007 UTC (17 years ago) by elmex
Branch: MAIN
Changes since 1.4: +1 -1 lines
Log Message:
disabled automatic page switching when a new channel occurs

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