#! perl # depends=widget # this module implements a rather fancy worldmap our $WORLDMAP_UPDATE_INTERVAL = $cfg::CFG{worldmap_update_interval} || 10; cf::async_ext { my $schedule_interval = Coro::Event->timer (after => 1); while () { $schedule_interval->interval ($WORLDMAP_UPDATE_INTERVAL); $schedule_interval->next; } }; sub create_widgets { my ($ns) = @_; my $info = { }; $info->{ws} = my $ws = $ns->new_widgetset; $info->{toplevel} = my $w = $ws->new (Toplevel => title => "Worldmap", name => "server_item_worldmap", force_w => 400, force_h => 400, x => "center", y => "center", has_close_button => 1, on_delete => sub { shift->hide }, ); my $face = cf::face::find "res/worldmap.jpg"; $ns->send_face ($face); $ns->flush_fx; $w->add (my $sw = $ws->new (ScrolledWindow => scroll_x => 1, scroll_y => 1)); $sw->add (my $canvas = $ws->new (Canvas => expand => 1)); $canvas->add_fixed ($ws->new (Face => expand => 1, size_w => undef, size_h => undef, face => $face), abs => 0, 0, rel => 1, 1); $canvas->add_fixed ($ws->new (Label => text => "lb1"), abs => 10, 10, rel => 1, 1); $info } sub update_worldmap { my ($ns) = @_; my $ws = $ns->{ws_worldmap} or return; } cf::object::attachment item_worldmap => on_apply => sub { my ($self, $who) = @_; my $ns = $who->contr->ns; if ($ns->{can_widget}) { my $ws = $ns->{ws_worldmap} ||= create_widgets $ns; $ws->{toplevel}->toggle_visibility; $ws->{toplevel}->get (visible => sub { update_worldmap $ns; }); } else { $ns->send_msg ("log", "Your client doesn't support the (required) widget extension. Try CFPlus at http://crossfire.schmorp.de/.", cf::NDI_RED); } cf::override 1; }, ;