1 | package DC::Protocol; |
1 | package DC::Protocol; |
2 | |
2 | |
3 | use utf8; |
3 | use common::sense; |
4 | use strict; |
4 | |
|
|
5 | use Guard (); |
5 | |
6 | |
6 | use Deliantra::Protocol::Constants; |
7 | use Deliantra::Protocol::Constants; |
7 | |
8 | |
8 | use DC; |
9 | use DC; |
9 | use DC::DB; |
10 | use DC::DB; |
… | |
… | |
11 | use DC::Pod; |
12 | use DC::Pod; |
12 | use DC::Macro; |
13 | use DC::Macro; |
13 | use DC::Item; |
14 | use DC::Item; |
14 | |
15 | |
15 | use base 'Deliantra::Protocol::Base'; |
16 | use base 'Deliantra::Protocol::Base'; |
|
|
17 | |
|
|
18 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
|
|
19 | "dialogue.png", minify => 1, mipmap => 1; |
|
|
20 | |
|
|
21 | our $TEX_NOFACE = new_from_resource DC::Texture |
|
|
22 | "noface.png", minify => 1, mipmap => 1, wrap => 1; |
|
|
23 | |
|
|
24 | sub MIN_TEXTURE_UNUSED() { 1 }#d# |
16 | |
25 | |
17 | sub new { |
26 | sub new { |
18 | my ($class, %arg) = @_; |
27 | my ($class, %arg) = @_; |
19 | |
28 | |
20 | my $self = $class->SUPER::new (%arg, |
29 | my $self = $class->SUPER::new (%arg, |
… | |
… | |
64 | $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { |
73 | $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { |
65 | for my $ws (values %{delete $self->{widgetset} || {}}) { |
74 | for my $ws (values %{delete $self->{widgetset} || {}}) { |
66 | $_->destroy |
75 | $_->destroy |
67 | for values %{delete $ws->{w} || {}}; |
76 | for values %{delete $ws->{w} || {}}; |
68 | } |
77 | } |
|
|
78 | |
|
|
79 | delete $self->{items}; |
|
|
80 | $::INV->clear; |
|
|
81 | $::INVR->clear; |
|
|
82 | $::INVR_HB->clear; |
|
|
83 | $::FLOORBOX->clear; |
69 | }); |
84 | }); |
70 | |
85 | |
71 | $self->{map_widget}->add_command (@$_) |
86 | $self->{map_widget}->add_command (@$_) |
72 | for @cmd_help; |
87 | for @cmd_help; |
73 | |
88 | |
74 | { |
89 | { |
75 | $self->{dialogue} = my $tex = new_from_file DC::Texture |
90 | $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}}); |
91 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
78 | } |
92 | } |
79 | |
93 | |
80 | { |
94 | { |
81 | $self->{noface} = my $tex = new_from_file DC::Texture |
95 | $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}}); |
96 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
84 | } |
97 | } |
|
|
98 | |
|
|
99 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
|
|
100 | # $self->{expire_w} = EV::timer 1, 1, sub { |
|
|
101 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
|
|
102 | # |
|
|
103 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
|
|
104 | # warn DC::SvREFCNT $self->{texture}[$_]; |
|
|
105 | # $self->{texture}[$_]->unload; |
|
|
106 | # warn "expire texture $_\n";#d# |
|
|
107 | # } |
|
|
108 | # |
|
|
109 | # ($self->{expire_count} += $count) < @{ $self->{texture} } |
|
|
110 | # or $self->{expire_count} = DC::DB::FIRST_TILE_ID; |
|
|
111 | # warn "count is $count\n";#d# |
|
|
112 | # }; |
85 | |
113 | |
86 | $self->{open_container} = 0; |
114 | $self->{open_container} = 0; |
87 | |
115 | |
88 | # per server |
116 | # per server |
89 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
117 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
… | |
… | |
250 | my %wkw = ( |
278 | my %wkw = ( |
251 | root => $DC::UI::ROOT, |
279 | root => $DC::UI::ROOT, |
252 | tooltip => $DC::UI::TOOLTIP, |
280 | tooltip => $DC::UI::TOOLTIP, |
253 | |
281 | |
254 | mapwidget => $::MAPWIDGET, |
282 | mapwidget => $::MAPWIDGET, |
|
|
283 | menubar => $::MENUBAR, |
|
|
284 | menupopup => $::MENUPOPUP, |
|
|
285 | pickup_enable => $::PICKUP_ENABLE, |
255 | buttonbar => $::BUTTONBAR, |
286 | buttonbar => $::BUTTONBAR, |
256 | metaserver => $::METASERVER, |
287 | metaserver => $::METASERVER, |
257 | buttonbar => $::BUTTONBAR, |
288 | buttonbar => $::BUTTONBAR, |
258 | login_button => $::LOGIN_BUTTON, |
289 | login_button => $::LOGIN_BUTTON, |
259 | quit_dialog => $::QUIT_DIALOG, |
290 | quit_dialog => $::QUIT_DIALOG, |
… | |
… | |
276 | |
307 | |
277 | floorbox => $::FLOORBOX, |
308 | floorbox => $::FLOORBOX, |
278 | help_window => $::HELP_WINDOW, |
309 | help_window => $::HELP_WINDOW, |
279 | message_window => $::MESSAGE_WINDOW, |
310 | message_window => $::MESSAGE_WINDOW, |
280 | message_dist => $::MESSAGE_DIST, |
311 | message_dist => $::MESSAGE_DIST, |
281 | statusbox => $::SDTATUSBOX, |
312 | statusbox => $::STATUSBOX, |
282 | |
313 | |
283 | inv => $::INV, |
314 | inv => $::INV, |
284 | invr => $::INVR, |
315 | invr => $::INVR, |
285 | invr_hb => $::INVR_HB, |
316 | invr_hb => $::INVR_HB, |
286 | ); |
317 | ); |
… | |
… | |
370 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
401 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
371 | : () |
402 | : () |
372 | } |
403 | } |
373 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
404 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
374 | |
405 | |
375 | join "", @diff |
406 | "\u$name: " . (join ", ", @diff) |
376 | } |
407 | } |
377 | |
408 | |
378 | # all stats that are chacked against changes |
409 | # all stats that are chacked against changes |
379 | my @statchange = ( |
410 | my @statchange = ( |
380 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
411 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
… | |
… | |
435 | } |
466 | } |
436 | |
467 | |
437 | if ( |
468 | if ( |
438 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
469 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
439 | ) { |
470 | ) { |
440 | my $msg = "<b>stat change</b>: " . (join " ", @diffs); |
471 | 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); |
472 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
442 | } |
473 | } |
443 | |
474 | |
444 | $self->update_stats_window ($stats, $prev); |
475 | $self->update_stats_window ($stats, $prev); |
445 | |
476 | |
… | |
… | |
483 | |
514 | |
484 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
515 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
485 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
516 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
486 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
517 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
487 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
518 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
488 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
519 | $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d# |
489 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
520 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
490 | $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
521 | $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
491 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
522 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
492 | my $title = $stats->{+CS_STAT_TITLE}; |
523 | my $title = $stats->{+CS_STAT_TITLE}; |
493 | $title =~ s/^Player: //; |
524 | $title =~ s/^Player: //; |
494 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
525 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
495 | |
526 | |
… | |
… | |
536 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
567 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
537 | ]; |
568 | ]; |
538 | |
569 | |
539 | my @add = @$sw; |
570 | my @add = @$sw; |
540 | |
571 | |
541 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; |
572 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>"; |
542 | |
573 | |
543 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
574 | 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); |
575 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
545 | |
576 | |
546 | my ($x, $y) = (0, 1); |
577 | my ($x, $y) = (0, 1); |
… | |
… | |
608 | my $sw = $self->{skillwid}{$idx}; |
639 | my $sw = $self->{skillwid}{$idx}; |
609 | $sw->[0]->set_text (::formsep ($val->[1])); |
640 | $sw->[0]->set_text (::formsep ($val->[1])); |
610 | $sw->[1]->set_text ($val->[0] * 1); |
641 | $sw->[1]->set_text ($val->[0] * 1); |
611 | $sw->[2]->set_value (@$val); |
642 | $sw->[2]->set_value (@$val); |
612 | |
643 | |
613 | $::GAUGES->{sklprg}->set_label ("$name %d%%"); |
644 | $::GAUGES->{skillexp}->set_label ("$name %d%%"); |
614 | $::GAUGES->{sklprg}->set_value (@$val); |
645 | $::GAUGES->{skillexp}->set_value (@$val); |
615 | } |
646 | } |
616 | } |
647 | } |
617 | |
648 | |
618 | sub user_send { |
649 | sub user_send { |
619 | my ($self, $command) = @_; |
650 | my ($self, $command) = @_; |
… | |
… | |
632 | } |
663 | } |
633 | |
664 | |
634 | sub map_scroll { |
665 | sub map_scroll { |
635 | my ($self, $dx, $dy) = @_; |
666 | my ($self, $dx, $dy) = @_; |
636 | |
667 | |
637 | $self->{map}->scroll ($dx, $dy); |
668 | $self->{map_widget}->scroll ($dx, $dy); |
638 | } |
669 | } |
639 | |
670 | |
640 | sub feed_map1a { |
671 | sub feed_map1a { |
641 | my ($self, $data) = @_; |
672 | my ($self, $data) = @_; |
642 | |
673 | |
… | |
… | |
646 | for my $tile (@$missing) { |
677 | for my $tile (@$missing) { |
647 | next if $self->{delay}{$tile}; |
678 | next if $self->{delay}{$tile}; |
648 | |
679 | |
649 | $delay = 1; |
680 | $delay = 1; |
650 | |
681 | |
651 | if (my $tex = $::CONN->{texture}[$tile]) { |
682 | if (my $tex = $self->{texture}[$tile]) { |
652 | $tex->upload; |
683 | $tex->upload; |
653 | } else { |
684 | } else { |
654 | $self->{delay}{$tile} = 1; |
685 | $self->{delay}{$tile} = 1; |
655 | |
686 | |
656 | # we assume the face is in-flight and will eventually come |
687 | # we assume the face is in-flight and will eventually arrive |
657 | push @{$self->{tile_cb}{$tile}}, sub { |
688 | push @{$self->{tile_cb}{$tile}}, sub { |
658 | delete $self->{delay}{$tile}; |
689 | delete $self->{delay}{$tile}; |
659 | $_[0]->upload; |
690 | $_[0]->upload; |
660 | }; |
691 | }; |
661 | } |
692 | } |
662 | } |
693 | } |
663 | |
694 | |
664 | if ($delay) { |
695 | if ($delay) { |
665 | # delay the map drawing a tiny bit in the hope of getting the missing fetched |
696 | # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched |
666 | EV::once undef, 0, 0.03, sub { |
697 | EV::once undef, 0, 0.03, sub { |
667 | $self->{map_widget}->update |
698 | $self->{map_widget}->update |
668 | if $self->{map_widget}; |
699 | if $self->{map_widget}; |
669 | }; |
700 | }; |
670 | } else { |
701 | } else { |
… | |
… | |
679 | } |
710 | } |
680 | |
711 | |
681 | sub flush_map { |
712 | sub flush_map { |
682 | my ($self) = @_; |
713 | my ($self) = @_; |
683 | |
714 | |
684 | my $map_info = delete $self->{map_info} |
715 | return unless $self->{map_info}; |
685 | or return; |
|
|
686 | |
716 | |
|
|
717 | for my $map_info (values %{ $self->{map_cache} || {} }) { |
687 | my ($hash, $x, $y, $w, $h) = @$map_info; |
718 | my ($hash, $rdata, $x, $y, $w, $h) = @$map_info; |
688 | |
719 | |
689 | my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); |
720 | my $data = $self->{map}->get_rect ($x, $y, $w, $h); |
690 | $self->{map_cache_new}{$hash} = \$data; |
721 | |
|
|
722 | if ($data ne $$rdata) { |
|
|
723 | $map_info->[1] = \$data; |
|
|
724 | my $cdata = Compress::LZF::compress $data; |
691 | DC::DB::put $self->{mapcache} => $hash => $data, sub { }; |
725 | DC::DB::put $self->{mapcache} => $hash => $cdata, sub { }; |
|
|
726 | } |
|
|
727 | } |
692 | } |
728 | } |
693 | |
729 | |
694 | sub map_clear { |
730 | sub map_clear { |
695 | my ($self) = @_; |
731 | my ($self) = @_; |
696 | |
732 | |
697 | $self->flush_map; |
733 | $self->flush_map; |
|
|
734 | delete $self->{map_info}; |
698 | delete $self->{neigh_map}; |
735 | delete $self->{neigh_map}; |
699 | |
736 | |
700 | $self->{map}->clear; |
737 | $self->{map}->clear; |
701 | delete $self->{map_widget}{magicmap}; |
738 | delete $self->{map_widget}{magicmap}; |
702 | } |
739 | } |
… | |
… | |
723 | |
760 | |
724 | $self->bg_fetch; |
761 | $self->bg_fetch; |
725 | }; |
762 | }; |
726 | } |
763 | } |
727 | |
764 | |
728 | sub load_map($$$) { |
765 | sub load_map($$$$$$) { |
729 | my ($self, $hash, $x, $y) = @_; |
766 | my ($self, $hash, $x, $y, $w, $h) = @_; |
730 | |
767 | |
731 | my $gen = $self->{map_change_gen}; |
768 | my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h]; |
732 | |
769 | |
733 | my $cb = sub { |
770 | my $cb = sub { |
734 | return unless $gen == $self->{map_change_gen}; |
771 | $map_info->[1] = \$_[0]; |
735 | |
772 | |
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} || [] }; |
773 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
744 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
774 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]); |
745 | $self->bg_fetch unless $inprogress; |
775 | $self->bg_fetch unless $inprogress; |
746 | } |
|
|
747 | }; |
776 | }; |
748 | |
777 | |
749 | if (my $rdata = $self->{map_cache_old}{$hash}) { |
778 | if (my $map_info = $self->{map_cache_old}{$hash}) { |
750 | $cb->($$rdata); |
779 | $cb->(${ $map_info->[1] }); |
751 | } else { |
780 | } else { |
|
|
781 | my $gen = $self->{map_change_gen}; |
|
|
782 | |
752 | DC::DB::get $self->{mapcache} => $hash, $cb; |
783 | DC::DB::get $self->{mapcache} => $hash, sub { |
|
|
784 | return unless $gen == $self->{map_change_gen}; |
|
|
785 | return unless defined $_[0]; |
|
|
786 | $cb->(Compress::LZF::decompress $_[0]); |
|
|
787 | }; |
753 | } |
788 | } |
754 | } |
789 | } |
755 | |
790 | |
756 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
791 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
757 | # (server resource,s latency, bandwidth), so this hack is warranted. |
792 | # (server resources, latency, bandwidth), so this hack is warranted. |
758 | # the right fix is to make real tiled maps with an overview file |
793 | # the right fix is to make real tiled maps with an overview file |
759 | sub send_mapinfo { |
794 | sub send_mapinfo { |
760 | my ($self, $data, $cb) = @_; |
795 | my ($self, $data, $cb) = @_; |
761 | |
796 | |
762 | if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { |
797 | if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { |
… | |
… | |
787 | } |
822 | } |
788 | |
823 | |
789 | # this method does a "flood fill" into every tile direction |
824 | # this method does a "flood fill" into every tile direction |
790 | # it assumes that tiles are arranged in a rectangular grid, |
825 | # 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. |
826 | # 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 |
827 | # failure to comply is harmless and results in display errors |
793 | # at worst. |
828 | # at worst. |
794 | sub flood_fill { |
829 | sub flood_fill { |
795 | my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
830 | my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
796 | |
831 | |
797 | # the server does not allow map paths > 6 |
832 | # the server does not allow map paths > 6 |
… | |
… | |
833 | return if $mode ne "spatial"; |
868 | return if $mode ne "spatial"; |
834 | |
869 | |
835 | $x += $self->{map}->ox; |
870 | $x += $self->{map}->ox; |
836 | $y += $self->{map}->oy; |
871 | $y += $self->{map}->oy; |
837 | |
872 | |
838 | $self->load_map ($hash, $x, $y) |
873 | $self->load_map ($hash, $x, $y, $w, $h) |
839 | unless $self->{neigh_map}{$hash}[5]++;#d# |
874 | unless $self->{neigh_map}{$hash}[5]++;#d# |
840 | |
875 | |
841 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
876 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
842 | |
877 | |
843 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
878 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
… | |
… | |
851 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
886 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
852 | |
887 | |
853 | $self->flush_map; |
888 | $self->flush_map; |
854 | |
889 | |
855 | ++$self->{map_change_gen}; |
890 | ++$self->{map_change_gen}; |
856 | $self->{map_cache_old} = delete $self->{map_cache_new}; |
891 | $self->{map_cache_old} = delete $self->{map_cache}; |
857 | |
892 | |
858 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
893 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
859 | |
894 | |
860 | my $mapmapw = $self->{mapmap}->{w}; |
895 | my $mapmapw = $self->{mapmap}->{w}; |
861 | my $mapmaph = $self->{mapmap}->{h}; |
896 | my $mapmaph = $self->{mapmap}->{h}; |
… | |
… | |
873 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
908 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
874 | |
909 | |
875 | (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
910 | (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
876 | $::STATWIDS->{map}->set_text ("Map: " . $map); |
911 | $::STATWIDS->{map}->set_text ("Map: " . $map); |
877 | |
912 | |
878 | $self->load_map ($hash, $x, $y); |
913 | $self->load_map ($hash, $x, $y, $w, $h); |
879 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
914 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
880 | } |
915 | } |
881 | |
916 | |
882 | sub face_find { |
917 | sub face_find { |
883 | my ($self, $facenum, $face, $cb) = @_; |
918 | my ($self, $facenum, $face, $cb) = @_; |
… | |
… | |
954 | |
989 | |
955 | my $tex = $self->{texture}[$tile] ||= |
990 | my $tex = $self->{texture}[$tile] ||= |
956 | new DC::Texture |
991 | new DC::Texture |
957 | tile => $tile, |
992 | tile => $tile, |
958 | image => $data, delete_image => 1, |
993 | image => $data, delete_image => 1, |
959 | minify => 1, mipmap => 1; |
994 | minify => 1; |
960 | |
995 | |
961 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
996 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
962 | $_->($tex) for @$cbs; |
997 | $_->($tex) for @$cbs; |
963 | } |
998 | } |
964 | } |
999 | } |
… | |
… | |
969 | my ($self, $num, $cb) = @_; |
1004 | my ($self, $num, $cb) = @_; |
970 | |
1005 | |
971 | push @{$self->{face_cb}{$num}}, $cb; |
1006 | push @{$self->{face_cb}{$num}}, $cb; |
972 | |
1007 | |
973 | defined wantarray |
1008 | defined wantarray |
974 | ? DC::guard { |
1009 | ? Guard::guard { |
975 | @{$self->{face_cb}{$num}} |
1010 | @{$self->{face_cb}{$num}} |
976 | = grep $_ != $cb, |
1011 | = grep $_ != $cb, |
977 | @{$self->{face_cb}{$num}}; |
1012 | @{$self->{face_cb}{$num}}; |
978 | } |
1013 | } |
979 | : () |
1014 | : () |
… | |
… | |
1025 | s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; |
1060 | s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; |
1026 | |
1061 | |
1027 | # handle some elements |
1062 | # handle some elements |
1028 | s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; |
1063 | s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; |
1029 | s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; |
1064 | s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; |
|
|
1065 | |
|
|
1066 | s/\s+$//; |
1030 | |
1067 | |
1031 | $_ |
1068 | $_ |
1032 | } |
1069 | } |
1033 | |
1070 | |
1034 | our %NAME_TO_COLOR = ( |
1071 | our %NAME_TO_COLOR = ( |
… | |
… | |
1081 | |
1118 | |
1082 | ## try to create single paragraphs of multiple lines sent by the server |
1119 | ## try to create single paragraphs of multiple lines sent by the server |
1083 | # no longer neecssary with TRT servers |
1120 | # no longer neecssary with TRT servers |
1084 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
1121 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
1085 | |
1122 | |
1086 | for (split /\n/, $text) { |
|
|
1087 | ::message ({ |
1123 | ::message ({ |
1088 | fg => $fg, |
1124 | fg => $fg, |
1089 | markup => $_, |
1125 | markup => $text, |
1090 | type => $type, |
1126 | type => $type, |
1091 | extra => [@extra], |
1127 | extra => [@extra], |
1092 | color_flags => $color, #d# ugly, kill |
1128 | color_flags => $color, #d# ugly, kill |
1093 | }); |
1129 | }); |
1094 | |
1130 | |
1095 | $color &= ~NDI_CLEAR; # only clear once for multiline messages |
1131 | # $color &= ~NDI_CLEAR; # only clear once for multiline messages |
1096 | # actually, this is an ugly design. _we_ should control the channels, |
1132 | # # actually, this is an ugly design. _we_ should control the channels, |
1097 | # not some random other widget, as the channels are clearly protocol-specific. |
1133 | # # 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 |
1134 | # # then we could also react to flags such as CLEAR without resorting to |
1099 | # hacks such as color_flags, above. |
1135 | # # hacks such as color_flags, above. |
1100 | } |
|
|
1101 | |
1136 | |
1102 | $self->{statusbox}->add ($text, |
1137 | $self->{statusbox}->add ($text, |
1103 | group => $text, |
1138 | group => $text, |
1104 | fg => $fg, |
1139 | fg => $fg, |
1105 | timeout => $color >= 2 ? 180 : 10, |
1140 | timeout => $color >= 2 ? 180 : 10, |
… | |
… | |
1170 | $::FLOORBOX->clear; |
1205 | $::FLOORBOX->clear; |
1171 | |
1206 | |
1172 | my @add; |
1207 | my @add; |
1173 | |
1208 | |
1174 | my $row; |
1209 | my $row; |
1175 | for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { |
1210 | for (sort { $b->{count} <=> $a->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { |
|
|
1211 | next if $_->{tag} & 0x80000000; |
1176 | if ($row < 6) { |
1212 | if ($row < 6) { |
1177 | local $_->{face_widget}; # hack to force recreation of widget |
1213 | local $_->{face_widget}; # hack to force recreation of widget |
1178 | local $_->{desc_widget}; # hack to force recreation of widget |
1214 | local $_->{desc_widget}; # hack to force recreation of widget |
1179 | DC::Item::update_widgets $_; |
1215 | DC::Item::update_widgets $_; |
1180 | |
1216 | |
… | |
… | |
1207 | sub set_opencont { |
1243 | sub set_opencont { |
1208 | my ($conn, $tag, $name) = @_; |
1244 | my ($conn, $tag, $name) = @_; |
1209 | $conn->{open_container} = $tag; |
1245 | $conn->{open_container} = $tag; |
1210 | update_floorbox; |
1246 | update_floorbox; |
1211 | |
1247 | |
1212 | $::INVR_HB->clear (); |
1248 | $::INVR_HB->clear; |
1213 | $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name); |
1249 | $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name); |
1214 | |
1250 | |
1215 | if ($tag != 0) { # Floor isn't closable, is it? |
1251 | if ($tag != 0) { # Floor isn't closable, is it? |
1216 | $::INVR_HB->add (new DC::UI::Button |
1252 | $::INVR_HB->add (new DC::UI::Button |
1217 | text => "Close container", |
1253 | text => "Close container", |
… | |
… | |
1273 | } |
1309 | } |
1274 | |
1310 | |
1275 | sub item_update { |
1311 | sub item_update { |
1276 | my ($self, $item) = @_; |
1312 | my ($self, $item) = @_; |
1277 | |
1313 | |
1278 | #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; |
1314 | #print "item_update: $item->{tag} in $item->{container} pt($self->{player}{tag}) oc($::CONN->{open_container}) f($item->{flags})\n"; |
1279 | |
1315 | |
1280 | DC::Item::update_widgets $item; |
1316 | DC::Item::update_widgets $item; |
1281 | |
1317 | |
1282 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
1318 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
1283 | set_opencont ($::CONN, 0, "Floor"); |
1319 | set_opencont ($::CONN, 0, "Floor"); |
1284 | |
1320 | |
1285 | } elsif ($item->{flags} & F_OPEN) { |
1321 | } elsif ($item->{flags} & F_OPEN) { |
1286 | set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item); |
1322 | set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item); |
… | |
… | |
1351 | }); |
1387 | }); |
1352 | |
1388 | |
1353 | $self->update_server_info; |
1389 | $self->update_server_info; |
1354 | |
1390 | |
1355 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1391 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1356 | $self->send_command ("pickup $::CFG->{pickup}"); |
1392 | $self->send_pickup ($::CFG->{pickup}); |
|
|
1393 | |
|
|
1394 | $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]", |
|
|
1395 | DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d# |
1357 | } |
1396 | } |
1358 | |
1397 | |
1359 | sub lookat { |
1398 | sub lookat { |
1360 | my ($self, $x, $y) = @_; |
1399 | my ($self, $x, $y) = @_; |
1361 | |
1400 | |
… | |
… | |
1525 | } |
1564 | } |
1526 | |
1565 | |
1527 | sub send { |
1566 | sub send { |
1528 | my ($self, $msg) = @_; |
1567 | my ($self, $msg) = @_; |
1529 | |
1568 | |
1530 | $self->{textview}->add_paragraph ({ markup => "\n" . DC::asxml $msg }); |
1569 | $self->{textview}->add_paragraph ({ |
|
|
1570 | markup => |
|
|
1571 | "\n<span foreground='#ffff00'><b>" |
|
|
1572 | . (DC::asxml $msg) |
|
|
1573 | . "</b></span>" |
|
|
1574 | }); |
1531 | $self->{textview}->scroll_to_bottom; |
1575 | $self->{textview}->scroll_to_bottom; |
1532 | |
1576 | |
1533 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1577 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1534 | } |
1578 | } |
1535 | |
1579 | |