ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/MessageDistributor.pm
Revision: 1.9
Committed: Wed Jan 4 11:23:23 2012 UTC (12 years, 5 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +9 -10 lines
Log Message:
*** empty log message ***

File Contents

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