1 |
elmex |
1.1 |
package GCE::PickWindow; |
2 |
|
|
|
3 |
|
|
=head1 NAME |
4 |
|
|
|
5 |
|
|
GCE::PickWindow - the arch picker window class for gce |
6 |
|
|
|
7 |
|
|
=cut |
8 |
|
|
|
9 |
|
|
use Gtk2; |
10 |
|
|
use Gtk2::Gdk::Keysyms; |
11 |
elmex |
1.8 |
use Gtk2::SimpleMenu; |
12 |
elmex |
1.1 |
|
13 |
elmex |
1.2 |
use Crossfire; |
14 |
|
|
use Crossfire::MapWidget; |
15 |
elmex |
1.1 |
|
16 |
elmex |
1.8 |
use GCE::AttrEdit; |
17 |
|
|
use GCE::MapEditor; |
18 |
|
|
use GCE::StackView; |
19 |
|
|
use GCE::EditAction; |
20 |
|
|
use GCE::PickWindow; |
21 |
|
|
|
22 |
elmex |
1.16 |
use GCE::DragHelper; |
23 |
|
|
|
24 |
elmex |
1.8 |
use Glib::Object::Subclass |
25 |
|
|
Gtk2::Window; |
26 |
|
|
|
27 |
|
|
use strict; |
28 |
elmex |
1.2 |
|
29 |
elmex |
1.8 |
sub INIT_INSTANCE { |
30 |
elmex |
1.4 |
my ($self) = @_; |
31 |
elmex |
1.3 |
|
32 |
elmex |
1.4 |
$self->{earchs} = editor_archs (); |
33 |
elmex |
1.1 |
|
34 |
elmex |
1.2 |
for (keys %{$self->{earchs}}) { |
35 |
|
|
my @a = split /\//; |
36 |
|
|
push @{$self->{toplevel_archs}->{$a[0]}}, @{$self->{earchs}->{$_}}; |
37 |
|
|
} |
38 |
|
|
|
39 |
elmex |
1.8 |
$self->set_title ("gce - picker"); |
40 |
elmex |
1.2 |
|
41 |
elmex |
1.8 |
$self->add (my $hb = Gtk2::VBox->new); |
42 |
elmex |
1.4 |
|
43 |
elmex |
1.13 |
$hb->pack_start (my $cb = $self->{combo} = Gtk2::ComboBox->new_text, 0, 1, 0); |
44 |
elmex |
1.4 |
|
45 |
elmex |
1.13 |
my $idx = 0; |
46 |
root |
1.6 |
for (sort keys %{$self->{toplevel_archs}}) { |
47 |
elmex |
1.5 |
|
48 |
root |
1.6 |
$cb->append_text ($_); |
49 |
elmex |
1.13 |
$self->{arch_txt_to_idx}->{$_} = $idx++; |
50 |
root |
1.6 |
} |
51 |
elmex |
1.4 |
|
52 |
root |
1.6 |
$cb->signal_connect (changed => sub { |
53 |
elmex |
1.4 |
|
54 |
root |
1.6 |
my $arch = $cb->get_active_text; |
55 |
elmex |
1.8 |
$self->set_selection ($arch); |
56 |
root |
1.6 |
}); |
57 |
elmex |
1.3 |
|
58 |
root |
1.6 |
$hb->pack_start (my $map = $self->{map} = new Crossfire::MapWidget, 1, 1, 0); |
59 |
elmex |
1.16 |
# XXX: Doesn't work yet beacuse of tooltips |
60 |
|
|
# GCE::DragHelper::set_drag_source ( |
61 |
|
|
# $map, arch => sub { { arch => $self->{last_pick} } } |
62 |
|
|
# ); |
63 |
elmex |
1.4 |
|
64 |
root |
1.6 |
$map->set_size_request (TILESIZE * 10, TILESIZE * 10); |
65 |
elmex |
1.4 |
|
66 |
root |
1.6 |
$map->signal_connect (button_press_event => sub { |
67 |
elmex |
1.16 |
my ($map, $event) = @_; |
68 |
elmex |
1.4 |
|
69 |
elmex |
1.19 |
if ($event->button == 1) { |
70 |
elmex |
1.4 |
|
71 |
root |
1.6 |
my ($mx, $my) = $map->coord ($event->x, $event->y); |
72 |
root |
1.7 |
my $as = $map->get ($mx, $my); |
73 |
elmex |
1.2 |
|
74 |
root |
1.7 |
my $arch = $as->[-1] |
75 |
root |
1.6 |
or return; |
76 |
|
|
|
77 |
elmex |
1.11 |
if ($arch->{_virtual}) { |
78 |
|
|
$arch = $arch->{_virtual}; |
79 |
|
|
} |
80 |
|
|
|
81 |
elmex |
1.16 |
$self->{last_pick} = $arch; |
82 |
elmex |
1.21 |
|
83 |
elmex |
1.25 |
my $ar = GCE::ArchRef->new (arch => $arch, source => 'picker'); |
84 |
elmex |
1.21 |
$::MAINWIN->update_attr_editor ($ar); |
85 |
elmex |
1.20 |
|
86 |
|
|
} elsif ($event->button == 3) { |
87 |
|
|
|
88 |
|
|
my ($mx, $my) = $map->coord ($event->x, $event->y); |
89 |
|
|
my $as = $map->get ($mx, $my); |
90 |
|
|
|
91 |
|
|
my $arch = $as->[-1] |
92 |
|
|
or return; |
93 |
|
|
|
94 |
|
|
if ($arch->{_virtual}) { |
95 |
|
|
$arch = $arch->{_virtual}; |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
$self->do_context_menu ($map, $event, $arch); |
99 |
root |
1.6 |
} |
100 |
elmex |
1.16 |
|
101 |
|
|
#my $d = $map->disable_tooltip; |
102 |
|
|
|
103 |
|
|
1 |
104 |
|
|
}); |
105 |
|
|
|
106 |
|
|
$map->signal_connect (button_release_event => sub { |
107 |
|
|
my ($map, $event) = @_; |
108 |
|
|
|
109 |
|
|
# $map->enable_tooltip; |
110 |
|
|
|
111 |
|
|
1 |
112 |
root |
1.6 |
}); |
113 |
elmex |
1.16 |
|
114 |
elmex |
1.8 |
} |
115 |
|
|
|
116 |
elmex |
1.20 |
sub do_context_menu { |
117 |
|
|
my ($self, $map, $event, $arch) = @_; |
118 |
|
|
|
119 |
|
|
my ($x, $y) = $map->coord ($event->x, $event->y); |
120 |
|
|
|
121 |
|
|
my $menu = Gtk2::Menu->new; |
122 |
|
|
foreach my $cm ( |
123 |
|
|
[ |
124 |
|
|
"Add to inventory" => sub { |
125 |
|
|
my $pa = $::MAINWIN->{attr_edit}->get_arch; |
126 |
elmex |
1.21 |
$pa->add_inv ({ _name => $arch->{_name} }) if $pa; |
127 |
elmex |
1.20 |
} |
128 |
|
|
] |
129 |
|
|
) { |
130 |
|
|
my $item = Gtk2::MenuItem->new ($cm->[0]); |
131 |
|
|
$menu->append ($item); |
132 |
|
|
$item->show; |
133 |
|
|
$item->signal_connect (activate => $cm->[1]); |
134 |
|
|
} |
135 |
|
|
$menu->popup (undef, undef, undef, undef, $event->button, $event->time); |
136 |
|
|
} |
137 |
|
|
|
138 |
elmex |
1.8 |
sub set_selection { |
139 |
|
|
my ($self, $arch) = @_; |
140 |
|
|
|
141 |
|
|
return unless defined $arch; |
142 |
|
|
|
143 |
elmex |
1.18 |
return unless defined $self->{toplevel_archs}->{$arch}; |
144 |
|
|
|
145 |
elmex |
1.8 |
$self->{map}->set_map ( |
146 |
elmex |
1.18 |
new_pickmap Crossfire::Map ($self->{toplevel_archs}->{$arch}) |
147 |
elmex |
1.8 |
); |
148 |
elmex |
1.16 |
$self->{map}->enable_tooltip; |
149 |
elmex |
1.8 |
|
150 |
elmex |
1.13 |
$self->{combo}->set_active ($self->{arch_txt_to_idx}->{$arch}); |
151 |
|
|
|
152 |
elmex |
1.8 |
$self->{last_selection} = $arch; |
153 |
elmex |
1.1 |
} |
154 |
|
|
|
155 |
elmex |
1.2 |
|
156 |
elmex |
1.1 |
=head1 AUTHOR |
157 |
|
|
|
158 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
159 |
|
|
http://home.schmorp.de/ |
160 |
|
|
|
161 |
|
|
Robin Redeker <elmex@ta-sa.org> |
162 |
|
|
http://www.ta-sa.org/ |
163 |
|
|
|
164 |
|
|
=cut |
165 |
|
|
1; |