ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/MessageDistributor.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/MessageDistributor.pm (file contents):
Revision 1.6 by elmex, Tue Oct 28 12:20:36 2008 UTC vs.
Revision 1.9 by root, Wed Jan 4 11:23:23 2012 UTC

1package DC::MessageDistributor; 1package DC::MessageDistributor;
2use strict; 2
3no warnings; 3use common::sense;
4 4
5sub new { 5sub new {
6 my $this = shift; 6 my $this = shift;
7 my $class = ref($this) || $this; 7 my $class = ref($this) || $this;
8 my $self = { @_ }; 8 my $self = bless { @_ }, $class;
9 bless $self, $class;
10 9
11 $self->{dockbar}->add_dock ( 10 $self->{dockbar}->add_dock (
12 $self->{log} = DC::UI::ChatView->new ( 11 $self->{log} = DC::UI::ChatView->new (
13 expand => 1, 12 expand => 1,
14 can_close => 0, 13 can_close => 0,
22 reply => '' 21 reply => ''
23 } 22 }
24 ) 23 )
25 ); 24 );
26 25
26 $self->{dockbar}->select_dockable ($self->{log});
27
27 return $self 28 return $self
28} 29}
29 30
30# called by MAPWIDGET activate console event 31# called by MAPWIDGET activate console event
31sub activate_console { 32sub activate_console {
34 35
35# adding channel 36# adding channel
36sub add_channel { 37sub add_channel {
37 my ($self, $chaninfo) = @_; 38 my ($self, $chaninfo) = @_;
38 39
39 $self->{info}->{$chaninfo->{id}} = $chaninfo; 40 $self->{info}{$chaninfo->{id}} = $chaninfo;
40 $self->touch_channel ($chaninfo->{id}); 41 $self->touch_channel ($chaninfo->{id});
41} 42}
42 43
43# set max paragraphs 44# set max paragraphs
44sub set_max_par { 45sub set_max_par {
60# push message in 61# push message in
61sub message { 62sub message {
62 my ($self, $para) = @_; 63 my ($self, $para) = @_;
63 my $id = $para->{type}; 64 my $id = $para->{type};
64 65
65 if (exists $self->{info}->{$id}) { 66 if (exists $self->{info}{$id}) {
66 unless (exists $self->{chatview}->{$id}) { 67 unless (exists $self->{chatview}->{$id}) {
67 $self->touch_channel ($id); 68 $self->touch_channel ($id);
68 } 69 }
69 70
70 my $cv = $self->{chatview}->{$id}; 71 my $cv = $self->{chatview}{$id};
71 72
72 unless ($cv) { 73 unless ($cv) {
73 warn "message couldn't be delivered to chatview with " 74 warn "message couldn't be delivered to chatview with "
74 ."id '$id', sending it to main log."; 75 ."id '$id', sending it to main log.";
75 $self->{log}->message ($para); 76 $self->{log}->message ($para);
84} 85}
85 86
86sub touch_channel { 87sub touch_channel {
87 my ($self, $id) = @_; 88 my ($self, $id) = @_;
88 89
89 if (exists $self->{chatview}->{$id}) { 90 if (exists $self->{chatview}{$id}) {
90 $self->update_chat ($id); 91 $self->update_chat ($id);
91 } else { 92 } else {
92 $self->init_chat ($id); 93 $self->init_chat ($id);
93 } 94 }
94} 95}
95 96
96sub update_chat { 97sub update_chat {
97 my ($self, $id) = @_; 98 my ($self, $id) = @_;
98 99
99 $self->{chatview}->{$id}->update_info ($self->{info}->{$id}); 100 $self->{chatview}{$id}->update_info ($self->{info}->{$id});
100} 101}
101 102
102sub init_chat { 103sub init_chat {
103 my ($self, $id) = @_; 104 my ($self, $id) = @_;
104 105
105 my $chaninfo = $self->{info}->{$id}; 106 my $chaninfo = $self->{info}{$id};
106 my $dock = $self->{chatview}->{$id} = 107 my $dock = $self->{chatview}{$id} =
107 DC::UI::ChatView->new ( 108 DC::UI::ChatView->new (
108 expand => 1, 109 expand => 1,
109 info => $chaninfo, 110 info => $chaninfo,
110 ); 111 );
111 $dock->connect (close_dock => sub { 112 $dock->connect (close_dock => sub {
112 delete $self->{chatview}->{$id}; 113 delete $self->{chatview}{$id};
113 0 114 0
114 }); 115 });
115 $self->{dockbar}->add_dock ($dock); 116 $self->{dockbar}->add_dock ($dock);
116} 117}
117 118

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines