… | |
… | |
3 | use KGS::Constants; |
3 | use KGS::Constants; |
4 | |
4 | |
5 | use base KGS::Listener::Room; |
5 | use base KGS::Listener::Room; |
6 | |
6 | |
7 | use Glib::Object::Subclass |
7 | use Glib::Object::Subclass |
8 | Gtk2::Window; |
8 | Gtk2::Frame; |
9 | |
9 | |
10 | sub new { |
10 | sub new { |
11 | my ($self, %arg) = @_; |
11 | my ($self, %arg) = @_; |
12 | $self = $self->Glib::Object::new; |
12 | $self = $self->Glib::Object::new; |
13 | $self->{$_} = delete $arg{$_} for keys %arg; |
13 | $self->{$_} = delete $arg{$_} for keys %arg; |
14 | |
14 | |
15 | $self->signal_connect (delete_event => sub { $self->part; 1 }); |
|
|
16 | $self->signal_connect (destroy => sub { |
15 | $self->signal_connect (destroy => sub { |
17 | delete $::config->{rooms}{$self->{channel}}; |
16 | delete $::config->{rooms}{$self->{channel}}; |
18 | delete $self->{app}{room}{$self->{channel}}; |
17 | delete $self->{app}{room}{$self->{channel}}; |
19 | (remove Glib::Source delete $self->{gameupdate}) if $self->{gameupdate}; |
18 | (remove Glib::Source delete $self->{gameupdate}) if $self->{gameupdate}; |
20 | $self->unlisten; |
19 | $self->unlisten; |
21 | %{$_[0]} = (); |
20 | %{$_[0]} = (); |
22 | }); |
21 | }); |
23 | |
22 | |
24 | $self->listen ($self->{conn}, qw(msg_room:)); |
23 | $self->listen ($self->{conn}, qw(msg_room:)); |
25 | |
24 | |
26 | $self->set_title ("KGS Room $self->{name}"); |
|
|
27 | gtk::state $self, "room::window", $self->{name}, window_size => [600, 400]; |
|
|
28 | |
|
|
29 | $self->signal_connect (delete_event => sub { $self->part; 1 }); |
25 | $self->signal_connect (delete_event => sub { $self->part; 1 }); |
30 | |
26 | |
31 | $self->add ($self->{hpane} = new Gtk2::HPaned); |
27 | $self->add (my $hbox = new Gtk2::HBox); |
32 | $self->{hpane}->set (position_set => 1); |
|
|
33 | gtk::state $self->{hpane}, "room::hpane", $self->{name}, position => 200; |
|
|
34 | |
28 | |
35 | $self->{hpane}->pack1 ((my $vbox = new Gtk2::VBox), 1, 1); |
29 | $hbox->pack_start ((my $vbox = new Gtk2::VBox), 1, 1, 0); |
36 | |
30 | |
37 | $vbox->add ($self->{chat} = new chat); |
31 | $vbox->add ($self->{chat} = new chat); |
38 | |
32 | |
39 | $self->{chat}->signal_connect(command => sub { |
33 | $self->{chat}->signal_connect(command => sub { |
40 | my ($chat, $cmd, $arg) = @_; |
34 | my ($chat, $cmd, $arg) = @_; |
41 | $self->{app}->do_command ($chat, $cmd, $arg, userlist => $self->{userlist}, room => $self); |
35 | $self->{app}->do_command ($chat, $cmd, $arg, userlist => $self->{userlist}, room => $self); |
42 | }); |
36 | }); |
43 | |
37 | |
|
|
38 | $hbox->pack_start ((my $vbox = new Gtk2::VBox), 0, 1, 0); |
|
|
39 | |
|
|
40 | $vbox->pack_start ((my $button = new_with_label Gtk2::Button "Close"), 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 | |
44 | $self->{hpane}->pack2 ((my $sw = new Gtk2::ScrolledWindow), 0, 1); |
46 | $vbox->pack_start ((my $sw = new Gtk2::ScrolledWindow), 1, 1, 0); |
45 | $sw->set_policy("automatic", "always"); |
47 | $sw->set_policy("automatic", "always"); |
46 | |
48 | |
47 | $sw->add ($self->{userlist} = new userlist); |
49 | $sw->add ($self->{userlist} = new userlist); |
48 | |
50 | |
49 | $self; |
51 | $self; |
… | |
… | |
105 | |
107 | |
106 | $self->{chat}->append_text("\n<user>" . (util::toxml $self->{owner}) . "</user>\n" |
108 | $self->{chat}->append_text("\n<user>" . (util::toxml $self->{owner}) . "</user>\n" |
107 | . "<description>" . (util::toxml $self->{description}) . "</description>\n"); |
109 | . "<description>" . (util::toxml $self->{description}) . "</description>\n"); |
108 | } |
110 | } |
109 | |
111 | |
|
|
112 | sub new_game { |
|
|
113 | my ($self) = @_; |
|
|
114 | |
|
|
115 | $self->{new_game} ||= new game conn => $self->{conn}, app => $self; |
|
|
116 | $self->{new_game}->show_all; |
|
|
117 | } |
|
|
118 | |
110 | 1; |
119 | 1; |
111 | |
120 | |