ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/MessageDistributor.pm
Revision: 1.5
Committed: Fri Sep 19 01:23:36 2008 UTC (15 years, 8 months ago) by root
Branch: MAIN
CVS Tags: rel-0_9977
Changes since 1.4: +5 -6 lines
Log Message:
*** empty log message ***

File Contents

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