ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/MapEditor.pm
(Generate patch)

Comparing deliantra/gde/GCE/MapEditor.pm (file contents):
Revision 1.73 by elmex, Thu Nov 27 22:47:14 2008 UTC vs.
Revision 1.73.2.2 by elmex, Tue Jul 7 15:42:18 2009 UTC

21use POSIX qw/strftime/; 21use POSIX qw/strftime/;
22 22
23use Glib::Object::Subclass 23use Glib::Object::Subclass
24 Gtk2::Window; 24 Gtk2::Window;
25 25
26use Scalar::Util qw/weaken/;
26use Storable qw/dclone/; 27use Storable qw/dclone/;
28
29use Guard;
27 30
28use strict; 31use strict;
29 32
30################################################################# 33#################################################################
31###### WINDOW MANAGEMENT ######################################## 34###### WINDOW MANAGEMENT ########################################
399 $self->{map}->set_map (my $m = new_from_file Deliantra::Map $path); 402 $self->{map}->set_map (my $m = new_from_file Deliantra::Map $path);
400 $self->{meta_info} = load_meta_info ($path); 403 $self->{meta_info} = load_meta_info ($path);
401 $self->set_window_title ($self->{path}); 404 $self->set_window_title ($self->{path});
402 $::MAINWIN->add_recent($path); 405 $::MAINWIN->add_recent($path);
403 } 406 }
407
404 $self->update_overlays; 408 $self->update_overlays;
405 $self->close_windows; 409 $self->close_windows;
406} 410}
407 411
408sub save_map { 412sub save_map {
791 $w->signal_connect (destroy => sub { delete $self->{map_properties} }); 795 $w->signal_connect (destroy => sub { delete $self->{map_properties} });
792 $w->show_all; 796 $w->show_all;
793} 797}
794 798
795################################################################# 799#################################################################
800###### CURSORS ##################################################
801#################################################################
802
803sub cursor {
804 my ($self, $owner, $x, $y, $z, @inv_path) = @_;
805
806 my $cursmap = ($self->{_cursors} ||= []);
807 my $cursor;
808
809 weaken $self;
810
811 #d# warn "NEWCURSOR $x, $y, ($owner)\n";
812
813 eval {
814 $cursor = GCE::ArchRef->new (
815 x => $x,
816 y => $y,
817 map => $self,
818 owner => $owner
819 );
820 push @{$cursmap->[$x]->[$y]}, $cursor
821 };
822 if ($@) {
823 if ($@ =~ /bad arch cursor/) {
824 #d# warn "BAD CURSOR $x, $y, $owner\n";
825 return undef;
826 } else {
827 die $@;
828 }
829 }
830
831 #d# warn "ADDED CURSOR $owner, $x, $y, => [$cursor] " . (1 * $cursor) . "\n";
832
833 weaken $cursmap->[$x]->[$y]->[-1];
834
835 $cursor->{z} = $z if defined $z;
836 $cursor->{inv} = \@inv_path if @inv_path;
837
838 my ($cx, $cy, $cid) = ($cursor->{x}, $cursor->{y}, 1 * $cursor);
839 $cursor->{guard} = guard {
840 if ($cid == $self->{_last_attr_edit_overlay_cid}) {
841 $self->{map}->overlay ('attr_edit');
842 }
843 };
844
845 $self->update_cursor_overlay ($cursor);
846 $cursor
847}
848
849sub cursors_at {
850 my ($self, $x, $y) = @_;
851 my $cursmap = ($self->{_cursors} ||= []);
852 $cursmap->[$x]->[$y] || []
853}
854
855sub update_cursor_overlay {
856 my ($self, $cursor) = @_;
857
858 if ($cursor->{owner} eq 'attr_edit') {
859 $self->{_last_attr_edit_overlay_cid} = 1 * $cursor;
860
861 $self->{map}->overlay (attr_edit =>
862 $cursor->{x} * TILESIZE,
863 $cursor->{y} * TILESIZE,
864 TILESIZE,
865 TILESIZE,
866 sub {
867 my ($self, $x, $y) = @_;
868
869 if (!$self->{_conn_upd_curs_gc_fg}) {
870 my $gc
871 = $self->{_conn_upd_curs_gc_fg}
872 = Gtk2::Gdk::GC->new ($self->{window});
873 my $cm = $self->{window}->get_colormap;
874 $gc->set_foreground (gtk2_get_color ($self, "green"));
875 $gc->set_background (gtk2_get_color ($self, "black"));
876 }
877
878 $self->{window}->draw_rectangle (
879 $_ & 1 ? $self->style->black_gc : $self->{_conn_upd_curs_gc_fg},
880 0,
881 $x + $_, $y + $_,
882 TILESIZE - 1 - $_ * 2,
883 TILESIZE - 1 - $_ * 2
884 ) for 0..3;
885 }
886 );
887 }
888}
889
890
891#################################################################
796###### MAP EDITOR INIT ########################################## 892###### MAP EDITOR INIT ##########################################
797################################################################# 893#################################################################
798 894
799sub INIT_INSTANCE { 895sub INIT_INSTANCE {
800 my ($self) = @_; 896 my ($self) = @_;
803 $self->add (my $vb = Gtk2::VBox->new); 899 $self->add (my $vb = Gtk2::VBox->new);
804 900
805 $vb->pack_start (my $menu = $self->build_menu, 0, 1, 0); 901 $vb->pack_start (my $menu = $self->build_menu, 0, 1, 0);
806 902
807 $vb->pack_start (my $map = $self->{map} = Deliantra::MapWidget->new, 1, 1, 0); 903 $vb->pack_start (my $map = $self->{map} = Deliantra::MapWidget->new, 1, 1, 0);
904
905 $self->{map}->{editor} = $self;
906 weaken $self->{map}->{editor};
808 907
809 $map->signal_connect_after (stack_change => sub { 908 $map->signal_connect_after (stack_change => sub {
810 my ($map, $x, $y, $stack) = @_; 909 my ($map, $x, $y, $stack) = @_;
811 $self->update_overlays ($x, $y, $stack); 910 $self->update_overlays ($x, $y, $stack);
812 $::MAINWIN->update_map_pos ($self, $x, $y); 911 # old: $::MAINWIN->update_map_pos ($self, $x, $y);
813 }); 912 });
814 $map->signal_connect_after (swap_stack_change => sub { 913 $map->signal_connect_after (swap_stack_change => sub {
815 my ($map, $x, $y, $stack) = @_; 914 my ($map, $x, $y, $stack) = @_;
816 $self->update_overlays ($x, $y, $stack); 915 $self->update_overlays ($x, $y, $stack);
817 $::MAINWIN->update_map_pos ($self, $x, $y); 916 # old: $::MAINWIN->update_map_pos ($self, $x, $y);
818 }); 917 });
819 918
820 $self->{connection_overlay_foreground} 919 $self->{connection_overlay_foreground}
821 = Gtk2::Gdk::Color->new (257 * 255, 257 * 255, 0); 920 = Gtk2::Gdk::Color->new (257 * 255, 257 * 255, 0);
822 $self->{connection_overlay_background} 921 $self->{connection_overlay_background}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines