ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/MessageDistributor.pm
Revision: 1.3
Committed: Thu Mar 20 22:28:33 2008 UTC (16 years, 3 months ago) by root
Branch: MAIN
Changes since 1.2: +3 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 elmex 1.1 package DC::MessageDistributor;
2     use strict;
3     no warnings;
4    
5     sub new {
6     my $this = shift;
7     my $class = ref($this) || $this;
8     my $self = { @_ };
9     bless $self, $class;
10    
11     $self->{dockbar}->add_dock (
12     $self->{log} = DC::UI::ChatView->new (
13     expand => 1,
14     can_close => 0,
15     can_undock => 0,
16     info => {
17     title => "Log",
18     tooltip =>
19     "<b>Server Log</b>. This text viewer contains all recent message sent by the server.",
20     entry_tooltip =>
21     "<b>Command Entry</b>. If you enter something and press return/enter here, "
22     ."the line you entered will be sent to the server as a command.",
23     reply => ''
24     }
25     )
26     );
27    
28     return $self
29     }
30    
31     # called by MAPWIDGET activate console event
32     sub activate_console {
33 root 1.3 # nop
34 elmex 1.1 }
35    
36     # adding channel
37     sub add_channel {
38     my ($self, $chaninfo) = @_;
39    
40     $self->{info}->{$chaninfo->{id}} = $chaninfo;
41     $self->touch_channel ($chaninfo->{id});
42     }
43    
44     # set max paragraphs
45 root 1.3 sub set_max_par {
46     # nop
47 elmex 1.1 }
48    
49 elmex 1.2 # set fontsize for all chatviews
50 elmex 1.1 sub set_fontsize {
51 elmex 1.2 my ($self, $s) = @_;
52    
53     for ($self->{log}, values %{$self->{chatview}}) {
54     $_->set_fontsize ($s);
55     }
56 elmex 1.1 }
57    
58     # push message in
59     sub message {
60     my ($self, $para) = @_;
61     my $id = $para->{type};
62    
63     if (exists $self->{info}->{$id}) {
64     unless (exists $self->{chatview}->{$id}) {
65     $self->touch_channel ($id);
66     }
67    
68     my $cv = $self->{chatview}->{$id};
69    
70     unless ($cv) {
71     warn "message couldn't be delivered to chatview with "
72     ."id '$id', sending it to main log.";
73     $self->{log}->message ($para);
74     return;
75     }
76    
77     $cv->message ($para);
78    
79     } else {
80     $self->{log}->message ($para);
81     }
82     }
83    
84     sub touch_channel {
85     my ($self, $id) = @_;
86    
87     if (exists $self->{chatview}->{$id}) {
88     $self->update_chat ($id);
89     } else {
90     $self->init_chat ($id);
91     }
92     }
93    
94     sub update_chat {
95     my ($self, $id) = @_;
96     $self->{chatview}->{$id}->update_info ($self->{info}->{$id});
97     }
98    
99     sub init_chat {
100     my ($self, $id) = @_;
101    
102     my $chaninfo = $self->{info}->{$id};
103     my $dock = $self->{chatview}->{$id} =
104     DC::UI::ChatView->new (
105     expand => 1,
106     info => $chaninfo,
107     );
108     $dock->connect (close_dock => sub {
109     delete $self->{chatview}->{$id};
110     0
111     });
112     $self->{dockbar}->add_dock ($dock);
113     }
114    
115     1;