ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/PickWindow.pm
Revision: 1.3
Committed: Tue Feb 7 14:28:23 2006 UTC (18 years, 3 months ago) by elmex
Branch: MAIN
Changes since 1.2: +25 -2 lines
Log Message:
implemented basic editing, placement and deletion of arches from map.
also implemented attribute viewer/editor - but that one has to be reworked
to be able to change values.

File Contents

# Content
1
2 package GCE::PickWindow;
3
4 =head1 NAME
5
6 GCE::PickWindow - the arch picker window class for gce
7
8 =cut
9
10 use strict;
11 use Gtk2;
12 use Gtk2::Gdk::Keysyms;
13
14 use Crossfire;
15 use Crossfire::MapWidget;
16
17 sub new {
18 my $class = shift;
19 my $self = { @_ };
20 bless $self, $class;
21 return $self;
22 }
23
24 sub init {
25 my ($self, $set_sel_cb) = @_;
26
27 $self->{setselcb} = $set_sel_cb;
28
29 $self->{earchs} = editor_archs ();
30 for (keys %{$self->{earchs}}) {
31 my @a = split /\//;
32 push @{$self->{toplevel_archs}->{$a[0]}}, @{$self->{earchs}->{$_}};
33 }
34
35 my $w = $self->{w} = Gtk2::Window->new ('toplevel');
36 $w->set_title ("gce - picker");
37
38 $w->add (my $hb = Gtk2::VBox->new);
39 $hb->pack_start (my $cb = Gtk2::ComboBox->new_text, 0, 1, 0);
40 for (sort keys %{$self->{toplevel_archs}}) {
41 $cb->append_text ($_);
42 }
43 $cb->signal_connect (changed => sub {
44 my $arch = $cb->get_active_text;
45 $self->{map}->set_map (arch2pickmap sort { ${$a}->{_name} cmp ${$b}->{_name} } $self->{toplevel_archs}->{$arch});
46 });
47 $hb->pack_start (my $map = new Crossfire::MapWidget, 1, 1, 0);
48 $self->{map} = $map;
49 $map->signal_connect (button_release_event => sub {
50 my ($f, $event) = @_;
51
52 if ($event->button == 1 && $event->state & "shift-mask") {
53 my ($mx, $my) = $map->coord ($event->x, $event->y);
54 my $s = map_get_tile_stack ($map, $mx, $my);
55 my $arch = $s->[-1];
56 return unless $arch;
57
58 $self->{arch_edit_cb} and $self->{arch_edit_cb}->($arch);
59
60 } elsif ($event->button == 1) {
61 my ($mx, $my) = $map->coord ($event->x, $event->y);
62 my $s = map_get_tile_stack ($map, $mx, $my);
63 my $arch = $s->[-1];
64 return unless $arch;
65
66 $self->{set_sel_cb} and $self->{set_sel_cb}->($arch);
67 }
68 });
69
70
71 $w->show_all;
72 }
73
74
75 =head1 AUTHOR
76
77 Marc Lehmann <schmorp@schmorp.de>
78 http://home.schmorp.de/
79
80 Robin Redeker <elmex@ta-sa.org>
81 http://www.ta-sa.org/
82
83 =cut
84 1;