ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/kgsueme/kgsueme/room.pl
(Generate patch)

Comparing kgsueme/kgsueme/room.pl (file contents):
Revision 1.10 by pcg, Sun Jun 1 16:51:38 2003 UTC vs.
Revision 1.30 by root, Wed Jun 2 09:32:32 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines