ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/kgsueme/kgsueme/room.pl
Revision: 1.33
Committed: Tue Jun 8 19:00:39 2004 UTC (19 years, 11 months ago) by elmex
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.32: +9 -12 lines
Log Message:
Rearranged buttons

File Contents

# Content
1 package room;
2
3 use KGS::Constants;
4
5 use base KGS::Listener::Room;
6
7 use Glib::Object::Subclass
8 Gtk2::Frame;
9
10 sub new {
11 my ($self, %arg) = @_;
12
13 $self = $self->Glib::Object::new;
14 $self->{$_} = delete $arg{$_} for keys %arg;
15
16 $self->signal_connect (destroy => sub {
17 delete $::config->{rooms}{$self->{channel}};
18 delete $self->{app}{room}{$self->{channel}};
19 (remove Glib::Source delete $self->{gameupdate}) if $self->{gameupdate};
20 $self->unlisten;
21 %{$_[0]} = ();
22 });
23
24 $self->listen ($self->{conn}, qw(msg_room:));
25
26 $self->signal_connect (delete_event => sub { $self->part; 1 });
27
28 $self->add (my $hpane = new Gtk2::HPaned);
29 gtk::state $hpane, "room::hpane", undef, position => 500;
30
31 $hpane->pack1 (($self->{chat} = new chat app => $self->{app}), 1, 0);
32
33 $self->{chat}->signal_connect (command => sub {
34 my ($chat, $cmd, $arg) = @_;
35 $self->{app}->do_command ($chat, $cmd, $arg, userlist => $self->{userlist}, room => $self);
36 });
37
38 $hpane->pack2 ((my $vbox = new Gtk2::VBox), 1, 0);
39
40 $vbox->pack_start ((my $button = new_with_label Gtk2::Button "Leave"), 0, 1, 0);
41 $button->signal_connect (clicked => sub { $self->part });
42
43 $vbox->pack_start ((my $button = new_with_label Gtk2::Button "New Game"), 0, 1, 0);
44 $button->signal_connect (clicked => sub { $self->new_game });
45 $vbox->pack_start((my $sw = new Gtk2::ScrolledWindow), 1, 1, 0);
46
47 $sw->set_policy ("automatic", "always");
48
49 $sw->add ($self->{userlist} = new userlist);
50
51 $self;
52 }
53
54 sub FINALIZE_INSTANCE { print "FIN room\n" } # never called MEMLEAK #d#TODO#
55
56 sub part {
57 my ($self) = @_;
58
59 $self->hide;
60 $self->SUPER::part;
61 }
62
63 sub inject_msg_room {
64 my ($self, $msg) = @_;
65
66 # secret typoe ;-)
67 $self->{chat}->append_text ("\n<user>" . (util::toxml $msg->{name})
68 . "</user>: " . (util::toxml $msg->{message}));
69 }
70
71 sub event_update_users {
72 my ($self, $add, $update, $remove) = @_;
73
74 $self->{userlist}->update ($add, $update, $remove);
75 }
76
77 sub event_update_games {
78 my ($self, $add, $update, $remove) = @_;
79
80 $self->{app}{gamelist}->update ($self, $add, $update, $remove);
81
82 # try to identify any new games assigned to us. stupid protocol
83 # first updates the game, joins you and THEN tells you that
84 # which of the games you asked for this is.
85
86 for (@$add) {
87 if (($_->{black}{name} eq $self->{conn}{name}
88 || $_->{white}{name} eq $self->{conn}{name}
89 || $_->{owner}{name} eq $self->{conn}{name})
90 && (my $game = shift @{$self->{new_game}})) {
91 $game->inject_upd_game ({ game => $_ });
92 $game->set_channel ($game->{channel});
93 }
94 }
95 }
96
97 sub event_join {
98 my ($self) = @_;
99 $self->SUPER::event_join;
100
101 $::config->{rooms}{$self->{channel}} = { channel => $self->{channel}, name => $self->{name} };
102
103 # mysteriously enough, we have to request game updates manually
104 $self->{gameupdate} ||= add Glib::Timeout INTERVAL_GAMEUPDATES * 1000, sub {
105 $self->req_games;
106 1;
107 };
108
109 $self->show_all;
110 }
111
112 sub event_part {
113 my ($self) = @_;
114
115 $self->SUPER::event_part;
116 $self->destroy;
117 }
118
119 sub event_quit {
120 my ($self) = @_;
121
122 $self->SUPER::event_quit;
123 $self->destroy;
124 }
125
126 sub event_update_roominfo {
127 my ($self) = @_;
128
129 $self->{chat}->append_text("\n<user>" . (util::toxml $self->{owner}) . "</user>\n"
130 . "<description>" . (util::toxml $self->{description}) . "</description>\n");
131 }
132
133 sub new_game {
134 my ($self) = @_;
135
136 my $game = new game conn => $self->{conn}, app => $self->{app}, roomid => $self->{channel};
137 $game->new_game_challenge;
138 $game->show_all;
139
140 push @{$self->{new_game}}, $game;
141 }
142
143 1;
144