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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines