1 | package DC::Protocol; |
1 | package DC::Protocol; |
2 | |
2 | |
3 | use utf8; |
3 | use utf8; |
4 | use strict; |
4 | use strict; |
|
|
5 | |
|
|
6 | use Guard (); |
5 | |
7 | |
6 | use Deliantra::Protocol::Constants; |
8 | use Deliantra::Protocol::Constants; |
7 | |
9 | |
8 | use DC; |
10 | use DC; |
9 | use DC::DB; |
11 | use DC::DB; |
… | |
… | |
11 | use DC::Pod; |
13 | use DC::Pod; |
12 | use DC::Macro; |
14 | use DC::Macro; |
13 | use DC::Item; |
15 | use DC::Item; |
14 | |
16 | |
15 | use base 'Deliantra::Protocol::Base'; |
17 | use base 'Deliantra::Protocol::Base'; |
|
|
18 | |
|
|
19 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
|
|
20 | "dialogue.png", minify => 1, mipmap => 1; |
|
|
21 | |
|
|
22 | our $TEX_NOFACE = new_from_resource DC::Texture |
|
|
23 | "noface.png", minify => 1, mipmap => 1, wrap => 1; |
|
|
24 | |
|
|
25 | our $TEX_HIDDEN = new_from_resource DC::Texture # MUST be POT |
|
|
26 | "hidden-0.png", minify => 1, mipmap => 1, wrap => 1; |
|
|
27 | |
|
|
28 | sub MIN_TEXTURE_UNUSED() { 1 }#d# |
16 | |
29 | |
17 | sub new { |
30 | sub new { |
18 | my ($class, %arg) = @_; |
31 | my ($class, %arg) = @_; |
19 | |
32 | |
20 | my $self = $class->SUPER::new (%arg, |
33 | my $self = $class->SUPER::new (%arg, |
… | |
… | |
64 | $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { |
77 | $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { |
65 | for my $ws (values %{delete $self->{widgetset} || {}}) { |
78 | for my $ws (values %{delete $self->{widgetset} || {}}) { |
66 | $_->destroy |
79 | $_->destroy |
67 | for values %{delete $ws->{w} || {}}; |
80 | for values %{delete $ws->{w} || {}}; |
68 | } |
81 | } |
|
|
82 | |
|
|
83 | delete $self->{items}; |
|
|
84 | $::INV->clear; |
|
|
85 | $::INVR->clear; |
|
|
86 | $::INVR_HB->clear; |
|
|
87 | $::FLOORBOX->clear; |
69 | }); |
88 | }); |
70 | |
89 | |
71 | $self->{map_widget}->add_command (@$_) |
90 | $self->{map_widget}->add_command (@$_) |
72 | for @cmd_help; |
91 | for @cmd_help; |
73 | |
92 | |
74 | { |
93 | { |
75 | $self->{dialogue} = my $tex = new_from_file DC::Texture |
94 | $self->{dialogue} = my $tex = $TEX_DIALOGUE; |
76 | DC::find_rcfile "dialogue.png", minify => 1, mipmap => 1; |
|
|
77 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
95 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
78 | } |
96 | } |
79 | |
97 | |
80 | { |
98 | { |
81 | $self->{noface} = my $tex = new_from_file DC::Texture |
99 | $self->{noface} = my $tex = $TEX_NOFACE; |
82 | DC::find_rcfile "noface.png", minify => 1, mipmap => 1; |
|
|
83 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
100 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
84 | } |
101 | } |
|
|
102 | |
|
|
103 | { |
|
|
104 | $self->{hidden} = my $tex = $TEX_HIDDEN; |
|
|
105 | $self->{map}->set_texture (3, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
|
|
106 | $self->{map_widget}{hidden_tex} = $tex;#d# |
|
|
107 | } |
|
|
108 | |
|
|
109 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
|
|
110 | # $self->{expire_w} = EV::timer 1, 1, sub { |
|
|
111 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
|
|
112 | # |
|
|
113 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
|
|
114 | # warn DC::SvREFCNT $self->{texture}[$_]; |
|
|
115 | # $self->{texture}[$_]->unload; |
|
|
116 | # warn "expire texture $_\n";#d# |
|
|
117 | # } |
|
|
118 | # |
|
|
119 | # ($self->{expire_count} += $count) < @{ $self->{texture} } |
|
|
120 | # or $self->{expire_count} = DC::DB::FIRST_TILE_ID; |
|
|
121 | # warn "count is $count\n";#d# |
|
|
122 | # }; |
85 | |
123 | |
86 | $self->{open_container} = 0; |
124 | $self->{open_container} = 0; |
87 | |
125 | |
88 | # per server |
126 | # per server |
89 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
127 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
… | |
… | |
250 | my %wkw = ( |
288 | my %wkw = ( |
251 | root => $DC::UI::ROOT, |
289 | root => $DC::UI::ROOT, |
252 | tooltip => $DC::UI::TOOLTIP, |
290 | tooltip => $DC::UI::TOOLTIP, |
253 | |
291 | |
254 | mapwidget => $::MAPWIDGET, |
292 | mapwidget => $::MAPWIDGET, |
|
|
293 | menubar => $::MENUBAR, |
|
|
294 | menupopup => $::MENUPOPUP, |
|
|
295 | pickup_enable => $::PICKUP_ENABLE, |
255 | buttonbar => $::BUTTONBAR, |
296 | buttonbar => $::BUTTONBAR, |
256 | metaserver => $::METASERVER, |
297 | metaserver => $::METASERVER, |
257 | buttonbar => $::BUTTONBAR, |
298 | buttonbar => $::BUTTONBAR, |
258 | login_button => $::LOGIN_BUTTON, |
299 | login_button => $::LOGIN_BUTTON, |
259 | quit_dialog => $::QUIT_DIALOG, |
300 | quit_dialog => $::QUIT_DIALOG, |
… | |
… | |
276 | |
317 | |
277 | floorbox => $::FLOORBOX, |
318 | floorbox => $::FLOORBOX, |
278 | help_window => $::HELP_WINDOW, |
319 | help_window => $::HELP_WINDOW, |
279 | message_window => $::MESSAGE_WINDOW, |
320 | message_window => $::MESSAGE_WINDOW, |
280 | message_dist => $::MESSAGE_DIST, |
321 | message_dist => $::MESSAGE_DIST, |
281 | statusbox => $::SDTATUSBOX, |
322 | statusbox => $::STATUSBOX, |
282 | |
323 | |
283 | inv => $::INV, |
324 | inv => $::INV, |
284 | invr => $::INVR, |
325 | invr => $::INVR, |
285 | invr_hb => $::INVR_HB, |
326 | invr_hb => $::INVR_HB, |
286 | ); |
327 | ); |
… | |
… | |
370 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
411 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
371 | : () |
412 | : () |
372 | } |
413 | } |
373 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
414 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
374 | |
415 | |
375 | join "", @diff |
416 | "\u$name: " . (join ", ", @diff) |
376 | } |
417 | } |
377 | |
418 | |
378 | # all stats that are chacked against changes |
419 | # all stats that are chacked against changes |
379 | my @statchange = ( |
420 | my @statchange = ( |
380 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
421 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
… | |
… | |
435 | } |
476 | } |
436 | |
477 | |
437 | if ( |
478 | if ( |
438 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
479 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
439 | ) { |
480 | ) { |
440 | my $msg = "<b>stat change</b>: " . (join " ", @diffs); |
481 | my $msg = "<b>stat change</b>: " . (join " ", map "($_)", @diffs); |
441 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
482 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
442 | } |
483 | } |
443 | |
484 | |
444 | $self->update_stats_window ($stats, $prev); |
485 | $self->update_stats_window ($stats, $prev); |
445 | |
486 | |
… | |
… | |
483 | |
524 | |
484 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
525 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
485 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
526 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
486 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
527 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
487 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
528 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
488 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
529 | $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d# |
489 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
530 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
490 | $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
531 | $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
491 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
532 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
492 | my $title = $stats->{+CS_STAT_TITLE}; |
533 | my $title = $stats->{+CS_STAT_TITLE}; |
493 | $title =~ s/^Player: //; |
534 | $title =~ s/^Player: //; |
494 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
535 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
495 | |
536 | |
… | |
… | |
536 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
577 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
537 | ]; |
578 | ]; |
538 | |
579 | |
539 | my @add = @$sw; |
580 | my @add = @$sw; |
540 | |
581 | |
541 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; |
582 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>"; |
542 | |
583 | |
543 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
584 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
544 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
585 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
545 | |
586 | |
546 | my ($x, $y) = (0, 1); |
587 | my ($x, $y) = (0, 1); |
… | |
… | |
608 | my $sw = $self->{skillwid}{$idx}; |
649 | my $sw = $self->{skillwid}{$idx}; |
609 | $sw->[0]->set_text (::formsep ($val->[1])); |
650 | $sw->[0]->set_text (::formsep ($val->[1])); |
610 | $sw->[1]->set_text ($val->[0] * 1); |
651 | $sw->[1]->set_text ($val->[0] * 1); |
611 | $sw->[2]->set_value (@$val); |
652 | $sw->[2]->set_value (@$val); |
612 | |
653 | |
613 | $::GAUGES->{sklprg}->set_label ("$name %d%%"); |
654 | $::GAUGES->{skillexp}->set_label ("$name %d%%"); |
614 | $::GAUGES->{sklprg}->set_value (@$val); |
655 | $::GAUGES->{skillexp}->set_value (@$val); |
615 | } |
656 | } |
616 | } |
657 | } |
617 | |
658 | |
618 | sub user_send { |
659 | sub user_send { |
619 | my ($self, $command) = @_; |
660 | my ($self, $command) = @_; |
… | |
… | |
632 | } |
673 | } |
633 | |
674 | |
634 | sub map_scroll { |
675 | sub map_scroll { |
635 | my ($self, $dx, $dy) = @_; |
676 | my ($self, $dx, $dy) = @_; |
636 | |
677 | |
637 | $self->{map}->scroll ($dx, $dy); |
678 | $self->{map_widget}->scroll ($dx, $dy); |
638 | } |
679 | } |
639 | |
680 | |
640 | sub feed_map1a { |
681 | sub feed_map1a { |
641 | my ($self, $data) = @_; |
682 | my ($self, $data) = @_; |
642 | |
683 | |
… | |
… | |
646 | for my $tile (@$missing) { |
687 | for my $tile (@$missing) { |
647 | next if $self->{delay}{$tile}; |
688 | next if $self->{delay}{$tile}; |
648 | |
689 | |
649 | $delay = 1; |
690 | $delay = 1; |
650 | |
691 | |
651 | if (my $tex = $::CONN->{texture}[$tile]) { |
692 | if (my $tex = $self->{texture}[$tile]) { |
652 | $tex->upload; |
693 | $tex->upload; |
653 | } else { |
694 | } else { |
654 | $self->{delay}{$tile} = 1; |
695 | $self->{delay}{$tile} = 1; |
655 | |
696 | |
656 | # we assume the face is in-flight and will eventually come |
697 | # we assume the face is in-flight and will eventually arrive |
657 | push @{$self->{tile_cb}{$tile}}, sub { |
698 | push @{$self->{tile_cb}{$tile}}, sub { |
658 | delete $self->{delay}{$tile}; |
699 | delete $self->{delay}{$tile}; |
659 | $_[0]->upload; |
700 | $_[0]->upload; |
660 | }; |
701 | }; |
661 | } |
702 | } |
662 | } |
703 | } |
663 | |
704 | |
664 | if ($delay) { |
705 | if ($delay) { |
665 | # delay the map drawing a tiny bit in the hope of getting the missing fetched |
706 | # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched |
666 | EV::once undef, 0, 0.03, sub { |
707 | EV::once undef, 0, 0.03, sub { |
667 | $self->{map_widget}->update |
708 | $self->{map_widget}->update |
668 | if $self->{map_widget}; |
709 | if $self->{map_widget}; |
669 | }; |
710 | }; |
670 | } else { |
711 | } else { |
… | |
… | |
679 | } |
720 | } |
680 | |
721 | |
681 | sub flush_map { |
722 | sub flush_map { |
682 | my ($self) = @_; |
723 | my ($self) = @_; |
683 | |
724 | |
684 | my $map_info = delete $self->{map_info} |
725 | return unless $self->{map_info}; |
685 | or return; |
|
|
686 | |
726 | |
|
|
727 | for my $map_info (values %{ $self->{map_cache} || {} }) { |
687 | my ($hash, $x, $y, $w, $h) = @$map_info; |
728 | my ($hash, $rdata, $x, $y, $w, $h) = @$map_info; |
688 | |
729 | |
689 | my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); |
730 | my $data = $self->{map}->get_rect ($x, $y, $w, $h); |
690 | $self->{map_cache_new}{$hash} = \$data; |
731 | |
|
|
732 | if ($data ne $$rdata) { |
|
|
733 | $map_info->[1] = \$data; |
|
|
734 | my $cdata = Compress::LZF::compress $data; |
691 | DC::DB::put $self->{mapcache} => $hash => $data, sub { }; |
735 | DC::DB::put $self->{mapcache} => $hash => $cdata, sub { }; |
|
|
736 | } |
|
|
737 | } |
692 | } |
738 | } |
693 | |
739 | |
694 | sub map_clear { |
740 | sub map_clear { |
695 | my ($self) = @_; |
741 | my ($self) = @_; |
696 | |
742 | |
697 | $self->flush_map; |
743 | $self->flush_map; |
|
|
744 | delete $self->{map_info}; |
698 | delete $self->{neigh_map}; |
745 | delete $self->{neigh_map}; |
699 | |
746 | |
700 | $self->{map}->clear; |
747 | $self->{map}->clear; |
701 | delete $self->{map_widget}{magicmap}; |
748 | delete $self->{map_widget}{magicmap}; |
702 | } |
749 | } |
… | |
… | |
723 | |
770 | |
724 | $self->bg_fetch; |
771 | $self->bg_fetch; |
725 | }; |
772 | }; |
726 | } |
773 | } |
727 | |
774 | |
728 | sub load_map($$$) { |
775 | sub load_map($$$$$$) { |
729 | my ($self, $hash, $x, $y) = @_; |
776 | my ($self, $hash, $x, $y, $w, $h) = @_; |
730 | |
777 | |
731 | my $gen = $self->{map_change_gen}; |
778 | my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h]; |
732 | |
779 | |
733 | my $cb = sub { |
780 | my $cb = sub { |
734 | return unless $gen == $self->{map_change_gen}; |
781 | $map_info->[1] = \$_[0]; |
735 | |
782 | |
736 | my ($data) = @_; |
|
|
737 | |
|
|
738 | if (defined $data) { |
|
|
739 | $self->{map_cache_new}{$hash} = \$data; |
|
|
740 | |
|
|
741 | my $data = Compress::LZF::decompress $data; |
|
|
742 | |
|
|
743 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
783 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
744 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
784 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]); |
745 | $self->bg_fetch unless $inprogress; |
785 | $self->bg_fetch unless $inprogress; |
746 | } |
|
|
747 | }; |
786 | }; |
748 | |
787 | |
749 | if (my $rdata = $self->{map_cache_old}{$hash}) { |
788 | if (my $map_info = $self->{map_cache_old}{$hash}) { |
750 | $cb->($$rdata); |
789 | $cb->(${ $map_info->[1] }); |
751 | } else { |
790 | } else { |
|
|
791 | my $gen = $self->{map_change_gen}; |
|
|
792 | |
752 | DC::DB::get $self->{mapcache} => $hash, $cb; |
793 | DC::DB::get $self->{mapcache} => $hash, sub { |
|
|
794 | return unless $gen == $self->{map_change_gen}; |
|
|
795 | return unless defined $_[0]; |
|
|
796 | $cb->(Compress::LZF::decompress $_[0]); |
|
|
797 | }; |
753 | } |
798 | } |
754 | } |
799 | } |
755 | |
800 | |
756 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
801 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
757 | # (server resource,s latency, bandwidth), so this hack is warranted. |
802 | # (server resources, latency, bandwidth), so this hack is warranted. |
758 | # the right fix is to make real tiled maps with an overview file |
803 | # the right fix is to make real tiled maps with an overview file |
759 | sub send_mapinfo { |
804 | sub send_mapinfo { |
760 | my ($self, $data, $cb) = @_; |
805 | my ($self, $data, $cb) = @_; |
761 | |
806 | |
762 | if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { |
807 | if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { |
… | |
… | |
787 | } |
832 | } |
788 | |
833 | |
789 | # this method does a "flood fill" into every tile direction |
834 | # this method does a "flood fill" into every tile direction |
790 | # it assumes that tiles are arranged in a rectangular grid, |
835 | # it assumes that tiles are arranged in a rectangular grid, |
791 | # i.e. a map is the same as the left of the right map etc. |
836 | # i.e. a map is the same as the left of the right map etc. |
792 | # failure to comply are harmless and result in display errors |
837 | # failure to comply is harmless and results in display errors |
793 | # at worst. |
838 | # at worst. |
794 | sub flood_fill { |
839 | sub flood_fill { |
795 | my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
840 | my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
796 | |
841 | |
797 | # the server does not allow map paths > 6 |
842 | # the server does not allow map paths > 6 |
… | |
… | |
833 | return if $mode ne "spatial"; |
878 | return if $mode ne "spatial"; |
834 | |
879 | |
835 | $x += $self->{map}->ox; |
880 | $x += $self->{map}->ox; |
836 | $y += $self->{map}->oy; |
881 | $y += $self->{map}->oy; |
837 | |
882 | |
838 | $self->load_map ($hash, $x, $y) |
883 | $self->load_map ($hash, $x, $y, $w, $h) |
839 | unless $self->{neigh_map}{$hash}[5]++;#d# |
884 | unless $self->{neigh_map}{$hash}[5]++;#d# |
840 | |
885 | |
841 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
886 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
842 | |
887 | |
843 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
888 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
… | |
… | |
851 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
896 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
852 | |
897 | |
853 | $self->flush_map; |
898 | $self->flush_map; |
854 | |
899 | |
855 | ++$self->{map_change_gen}; |
900 | ++$self->{map_change_gen}; |
856 | $self->{map_cache_old} = delete $self->{map_cache_new}; |
901 | $self->{map_cache_old} = delete $self->{map_cache}; |
857 | |
902 | |
858 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
903 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
859 | |
904 | |
860 | my $mapmapw = $self->{mapmap}->{w}; |
905 | my $mapmapw = $self->{mapmap}->{w}; |
861 | my $mapmaph = $self->{mapmap}->{h}; |
906 | my $mapmaph = $self->{mapmap}->{h}; |
… | |
… | |
873 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
918 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
874 | |
919 | |
875 | (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
920 | (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
876 | $::STATWIDS->{map}->set_text ("Map: " . $map); |
921 | $::STATWIDS->{map}->set_text ("Map: " . $map); |
877 | |
922 | |
878 | $self->load_map ($hash, $x, $y); |
923 | $self->load_map ($hash, $x, $y, $w, $h); |
879 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
924 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
880 | } |
925 | } |
881 | |
926 | |
882 | sub face_find { |
927 | sub face_find { |
883 | my ($self, $facenum, $face, $cb) = @_; |
928 | my ($self, $facenum, $face, $cb) = @_; |
… | |
… | |
954 | |
999 | |
955 | my $tex = $self->{texture}[$tile] ||= |
1000 | my $tex = $self->{texture}[$tile] ||= |
956 | new DC::Texture |
1001 | new DC::Texture |
957 | tile => $tile, |
1002 | tile => $tile, |
958 | image => $data, delete_image => 1, |
1003 | image => $data, delete_image => 1, |
959 | minify => 1, mipmap => 1; |
1004 | minify => 1; |
960 | |
1005 | |
961 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
1006 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
962 | $_->($tex) for @$cbs; |
1007 | $_->($tex) for @$cbs; |
963 | } |
1008 | } |
964 | } |
1009 | } |
… | |
… | |
969 | my ($self, $num, $cb) = @_; |
1014 | my ($self, $num, $cb) = @_; |
970 | |
1015 | |
971 | push @{$self->{face_cb}{$num}}, $cb; |
1016 | push @{$self->{face_cb}{$num}}, $cb; |
972 | |
1017 | |
973 | defined wantarray |
1018 | defined wantarray |
974 | ? DC::guard { |
1019 | ? Guard::guard { |
975 | @{$self->{face_cb}{$num}} |
1020 | @{$self->{face_cb}{$num}} |
976 | = grep $_ != $cb, |
1021 | = grep $_ != $cb, |
977 | @{$self->{face_cb}{$num}}; |
1022 | @{$self->{face_cb}{$num}}; |
978 | } |
1023 | } |
979 | : () |
1024 | : () |
… | |
… | |
1025 | s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; |
1070 | s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; |
1026 | |
1071 | |
1027 | # handle some elements |
1072 | # handle some elements |
1028 | s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; |
1073 | s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; |
1029 | s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; |
1074 | s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; |
|
|
1075 | |
|
|
1076 | s/\s+$//; |
1030 | |
1077 | |
1031 | $_ |
1078 | $_ |
1032 | } |
1079 | } |
1033 | |
1080 | |
1034 | our %NAME_TO_COLOR = ( |
1081 | our %NAME_TO_COLOR = ( |
… | |
… | |
1081 | |
1128 | |
1082 | ## try to create single paragraphs of multiple lines sent by the server |
1129 | ## try to create single paragraphs of multiple lines sent by the server |
1083 | # no longer neecssary with TRT servers |
1130 | # no longer neecssary with TRT servers |
1084 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
1131 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
1085 | |
1132 | |
1086 | for (split /\n/, $text) { |
|
|
1087 | ::message ({ |
1133 | ::message ({ |
1088 | fg => $fg, |
1134 | fg => $fg, |
1089 | markup => $_, |
1135 | markup => $text, |
1090 | type => $type, |
1136 | type => $type, |
1091 | extra => [@extra], |
1137 | extra => [@extra], |
1092 | color_flags => $color, #d# ugly, kill |
1138 | color_flags => $color, #d# ugly, kill |
1093 | }); |
1139 | }); |
1094 | |
1140 | |
1095 | $color &= ~NDI_CLEAR; # only clear once for multiline messages |
1141 | # $color &= ~NDI_CLEAR; # only clear once for multiline messages |
1096 | # actually, this is an ugly design. _we_ should control the channels, |
1142 | # # actually, this is an ugly design. _we_ should control the channels, |
1097 | # not some random other widget, as the channels are clearly protocol-specific. |
1143 | # # not some random other widget, as the channels are clearly protocol-specific. |
1098 | # then we could also react to flags such as CLEAR without resorting to |
1144 | # # then we could also react to flags such as CLEAR without resorting to |
1099 | # hacks such as color_flags, above. |
1145 | # # hacks such as color_flags, above. |
1100 | } |
|
|
1101 | |
1146 | |
1102 | $self->{statusbox}->add ($text, |
1147 | $self->{statusbox}->add ($text, |
1103 | group => $text, |
1148 | group => $text, |
1104 | fg => $fg, |
1149 | fg => $fg, |
1105 | timeout => $color >= 2 ? 180 : 10, |
1150 | timeout => $color >= 2 ? 180 : 10, |
… | |
… | |
1170 | $::FLOORBOX->clear; |
1215 | $::FLOORBOX->clear; |
1171 | |
1216 | |
1172 | my @add; |
1217 | my @add; |
1173 | |
1218 | |
1174 | my $row; |
1219 | my $row; |
1175 | for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { |
1220 | for (sort { $b->{count} <=> $a->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { |
|
|
1221 | next if $_->{tag} & 0x80000000; |
1176 | if ($row < 6) { |
1222 | if ($row < 6) { |
1177 | local $_->{face_widget}; # hack to force recreation of widget |
1223 | local $_->{face_widget}; # hack to force recreation of widget |
1178 | local $_->{desc_widget}; # hack to force recreation of widget |
1224 | local $_->{desc_widget}; # hack to force recreation of widget |
1179 | DC::Item::update_widgets $_; |
1225 | DC::Item::update_widgets $_; |
1180 | |
1226 | |
… | |
… | |
1207 | sub set_opencont { |
1253 | sub set_opencont { |
1208 | my ($conn, $tag, $name) = @_; |
1254 | my ($conn, $tag, $name) = @_; |
1209 | $conn->{open_container} = $tag; |
1255 | $conn->{open_container} = $tag; |
1210 | update_floorbox; |
1256 | update_floorbox; |
1211 | |
1257 | |
1212 | $::INVR_HB->clear (); |
1258 | $::INVR_HB->clear; |
1213 | $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name); |
1259 | $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name); |
1214 | |
1260 | |
1215 | if ($tag != 0) { # Floor isn't closable, is it? |
1261 | if ($tag != 0) { # Floor isn't closable, is it? |
1216 | $::INVR_HB->add (new DC::UI::Button |
1262 | $::INVR_HB->add (new DC::UI::Button |
1217 | text => "Close container", |
1263 | text => "Close container", |
… | |
… | |
1273 | } |
1319 | } |
1274 | |
1320 | |
1275 | sub item_update { |
1321 | sub item_update { |
1276 | my ($self, $item) = @_; |
1322 | my ($self, $item) = @_; |
1277 | |
1323 | |
1278 | #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; |
1324 | #print "item_update: $item->{tag} in $item->{container} pt($self->{player}{tag}) oc($::CONN->{open_container}) f($item->{flags})\n"; |
1279 | |
1325 | |
1280 | DC::Item::update_widgets $item; |
1326 | DC::Item::update_widgets $item; |
1281 | |
1327 | |
1282 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
1328 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
1283 | set_opencont ($::CONN, 0, "Floor"); |
1329 | set_opencont ($::CONN, 0, "Floor"); |
1284 | |
1330 | |
1285 | } elsif ($item->{flags} & F_OPEN) { |
1331 | } elsif ($item->{flags} & F_OPEN) { |
1286 | set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item); |
1332 | set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item); |
… | |
… | |
1351 | }); |
1397 | }); |
1352 | |
1398 | |
1353 | $self->update_server_info; |
1399 | $self->update_server_info; |
1354 | |
1400 | |
1355 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1401 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1356 | $self->send_command ("pickup $::CFG->{pickup}"); |
1402 | $self->send_pickup ($::CFG->{pickup}); |
|
|
1403 | |
|
|
1404 | $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]", |
|
|
1405 | DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d# |
1357 | } |
1406 | } |
1358 | |
1407 | |
1359 | sub lookat { |
1408 | sub lookat { |
1360 | my ($self, $x, $y) = @_; |
1409 | my ($self, $x, $y) = @_; |
1361 | |
1410 | |
… | |
… | |
1525 | } |
1574 | } |
1526 | |
1575 | |
1527 | sub send { |
1576 | sub send { |
1528 | my ($self, $msg) = @_; |
1577 | my ($self, $msg) = @_; |
1529 | |
1578 | |
1530 | $self->{textview}->add_paragraph ({ markup => "\n" . DC::asxml $msg }); |
1579 | $self->{textview}->add_paragraph ({ |
|
|
1580 | markup => |
|
|
1581 | "\n<span foreground='#ffff00'><b>" |
|
|
1582 | . (DC::asxml $msg) |
|
|
1583 | . "</b></span>" |
|
|
1584 | }); |
1531 | $self->{textview}->scroll_to_bottom; |
1585 | $self->{textview}->scroll_to_bottom; |
1532 | |
1586 | |
1533 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1587 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1534 | } |
1588 | } |
1535 | |
1589 | |