… | |
… | |
126 | our $FONT_FIXED; |
126 | our $FONT_FIXED; |
127 | |
127 | |
128 | our $MAP; |
128 | our $MAP; |
129 | our $MAPMAP; |
129 | our $MAPMAP; |
130 | our $MAPWIDGET; |
130 | our $MAPWIDGET; |
|
|
131 | our $COMPLETER; |
131 | our $BUTTONBAR; |
132 | our $BUTTONBAR; |
132 | our $METASERVER; |
133 | our $METASERVER; |
133 | our $LOGIN_BUTTON; |
134 | our $LOGIN_BUTTON; |
134 | our $QUIT_DIALOG; |
135 | our $QUIT_DIALOG; |
135 | our $HOST_ENTRY; |
136 | our $HOST_ENTRY; |
… | |
… | |
146 | our $PL_WINDOW; |
147 | our $PL_WINDOW; |
147 | |
148 | |
148 | our $MUSIC_PLAYING_WIDGET; |
149 | our $MUSIC_PLAYING_WIDGET; |
149 | our $LICENSE_WIDGET; |
150 | our $LICENSE_WIDGET; |
150 | |
151 | |
|
|
152 | our $PICKUP_PAGE; |
151 | our $INVENTORY_PAGE; |
153 | our $INVENTORY_PAGE; |
152 | our $STATS_PAGE; |
154 | our $STATS_PAGE; |
153 | our $SKILL_PAGE; |
155 | our $SKILL_PAGE; |
154 | our $SPELL_PAGE; |
156 | our $SPELL_PAGE; |
155 | our $SPELL_LIST; |
157 | our $SPELL_LIST; |
… | |
… | |
313 | |
315 | |
314 | my $NOW = time; |
316 | my $NOW = time; |
315 | |
317 | |
316 | if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { |
318 | if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { |
317 | my $pos = $MUSIC_PLAYING_META->{stop_pos}; |
319 | my $pos = $MUSIC_PLAYING_META->{stop_pos}; |
318 | $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos); |
320 | $MUSIC_PLAYER->fade_in_pos (0, 700, $pos); |
319 | $MUSIC_START = time - $pos; |
321 | $MUSIC_START = time - $pos; |
320 | } else { |
322 | } else { |
321 | $MUSIC_PLAYER->play (0); |
323 | $MUSIC_PLAYER->play (0); |
322 | $MUSIC_START = time; |
324 | $MUSIC_START = time; |
323 | } |
325 | } |
… | |
… | |
341 | my @have = |
343 | my @have = |
342 | grep $_ && $_->{data}, |
344 | grep $_ && $_->{data}, |
343 | map $CONN->{face}[$_], |
345 | map $CONN->{face}[$_], |
344 | @$MUSIC_WANT; |
346 | @$MUSIC_WANT; |
345 | |
347 | |
|
|
348 | # randomize music a bit so that the order is not always the same |
|
|
349 | $_->{stop_time} ||= rand for @have; |
|
|
350 | |
346 | @MUSIC_HAVE = @have |
351 | @MUSIC_HAVE = @have |
347 | if @have; |
352 | if @have; |
348 | |
353 | |
349 | # default MUSIC_HAVE == MUSIC_DEFAULT |
354 | # default MUSIC_HAVE == MUSIC_DEFAULT |
350 | @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE; |
355 | @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE; |
351 | $fade_out = 1000; |
356 | $fade_out = 700; |
352 | } |
357 | } |
353 | |
358 | |
354 | # if the currently playing song is acceptable, let it continue |
359 | # if the currently playing song is acceptable, let it continue |
355 | return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE; |
360 | return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE; |
356 | |
361 | |
… | |
… | |
365 | @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE; |
370 | @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE; |
366 | |
371 | |
367 | # if the most recently-played piece played very recently, |
372 | # if the most recently-played piece played very recently, |
368 | # resume it, else choose the oldest piece for rotation. |
373 | # resume it, else choose the oldest piece for rotation. |
369 | audio_music_set_meta |
374 | audio_music_set_meta |
370 | $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME |
375 | $MUSIC_HAVE[-1]{stop_pos} && $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME |
371 | ? $MUSIC_HAVE[-1] |
376 | ? $MUSIC_HAVE[-1] |
372 | : $MUSIC_HAVE[0]; |
377 | : $MUSIC_HAVE[0]; |
373 | |
378 | |
374 | audio_music_start; |
379 | audio_music_start; |
375 | } |
380 | } |
… | |
… | |
381 | $MUSIC_WANT = $songs; |
386 | $MUSIC_WANT = $songs; |
382 | audio_music_push; |
387 | audio_music_push; |
383 | } |
388 | } |
384 | |
389 | |
385 | sub audio_music_finished { |
390 | sub audio_music_finished { |
|
|
391 | if ($MUSIC_PLAYING_META) { |
|
|
392 | $MUSIC_PLAYING_META->{stop_time} = time; |
|
|
393 | } |
|
|
394 | |
386 | # we compress multiple jingles of the same type |
395 | # we compress multiple jingles of the same type |
387 | shift @MUSIC_JINGLE |
396 | shift @MUSIC_JINGLE |
388 | while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0]; |
397 | while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0]; |
389 | |
398 | |
390 | $MUSIC_PLAYING_WIDGET->clear; |
399 | $MUSIC_PLAYING_WIDGET->clear; |
… | |
… | |
984 | $hb->add (my $hg = new CFPlus::UI::Gauge type => 'hp', tooltip => "#stat_health"); |
993 | $hb->add (my $hg = new CFPlus::UI::Gauge type => 'hp', tooltip => "#stat_health"); |
985 | $hb->add (my $mg = new CFPlus::UI::Gauge type => 'mana', tooltip => "#stat_mana"); |
994 | $hb->add (my $mg = new CFPlus::UI::Gauge type => 'mana', tooltip => "#stat_mana"); |
986 | $hb->add (my $gg = new CFPlus::UI::Gauge type => 'grace', tooltip => "#stat_grace"); |
995 | $hb->add (my $gg = new CFPlus::UI::Gauge type => 'grace', tooltip => "#stat_grace"); |
987 | $hb->add (my $fg = new CFPlus::UI::Gauge type => 'food', tooltip => "#stat_food"); |
996 | $hb->add (my $fg = new CFPlus::UI::Gauge type => 'food', tooltip => "#stat_food"); |
988 | |
997 | |
989 | $vbox->add (my $exp = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp"); |
998 | $vbox->add (my $exp = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp"); |
990 | $vbox->add (my $prg = new CFPlus::UI::ExperienceProgress); |
999 | $vbox->add (my $prg = new CFPlus::UI::ExperienceProgress); |
|
|
1000 | $vbox->add (my $sklprg = new CFPlus::UI::ExperienceProgress); |
991 | $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged"); |
1001 | $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged"); |
992 | |
1002 | |
993 | $GAUGES = { |
1003 | $GAUGES = { |
994 | exp => $exp, prg => $prg, win => $win, range => $rng, |
1004 | exp => $exp, prg => $prg, sklprg => $sklprg, |
995 | food => $fg, mana => $mg, hp => $hg, grace => $gg |
1005 | win => $win, range => $rng, |
|
|
1006 | hp => $hg, mana => $mg, grace => $gg, food => $fg, |
996 | }; |
1007 | }; |
997 | |
1008 | |
998 | &set_gauge_window_fontsize; |
1009 | &set_gauge_window_fontsize; |
999 | |
1010 | |
1000 | $win |
1011 | $win |
… | |
… | |
1722 | $ntb->add_tab ( |
1733 | $ntb->add_tab ( |
1723 | "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, |
1734 | "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, |
1724 | "Toggles the inventory window, where you can manage your loot (or treasures :). " |
1735 | "Toggles the inventory window, where you can manage your loot (or treasures :). " |
1725 | . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." |
1736 | . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." |
1726 | ); |
1737 | ); |
1727 | $ntb->add_tab (Pickup => autopickup_setup, |
1738 | $ntb->add_tab (Pickup => $PICKUP_PAGE = autopickup_setup, |
1728 | "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); |
1739 | "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); |
1729 | |
1740 | |
1730 | $ntb->add_tab (Media => media_window, |
1741 | $ntb->add_tab (Media => media_window, |
1731 | "License, Author and Source info for media sent by the server."); |
1742 | "License, Author and Source info for media sent by the server."); |
1732 | |
1743 | |
… | |
… | |
1973 | |
1984 | |
1974 | $SDL_ACTIVE = 1; |
1985 | $SDL_ACTIVE = 1; |
1975 | $LAST_REFRESH = time - 0.01; |
1986 | $LAST_REFRESH = time - 0.01; |
1976 | |
1987 | |
1977 | CFPlus::OpenGL::init; |
1988 | CFPlus::OpenGL::init; |
|
|
1989 | CFPlus::Macro::init; |
1978 | |
1990 | |
1979 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
1991 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
1980 | |
1992 | |
1981 | $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# |
1993 | $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# |
1982 | |
1994 | |
1983 | ############################################################################# |
1995 | ############################################################################# |
1984 | |
1996 | |
1985 | if ($DEBUG_STATUS) { |
1997 | if ($DEBUG_STATUS) { |
1986 | CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h; |
1998 | CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h; |
1987 | } else { |
1999 | } else { |
1988 | # create the widgets |
2000 | # create/configure the widgets |
|
|
2001 | |
|
|
2002 | $CFPlus::UI::ROOT->connect (key_down => sub { |
|
|
2003 | my (undef, $ev) = @_; |
|
|
2004 | |
|
|
2005 | if (my @macros = CFPlus::Macro::find $ev) { |
|
|
2006 | CFPlus::Macro::execute $_ for @macros; |
|
|
2007 | |
|
|
2008 | return 1; |
|
|
2009 | } |
|
|
2010 | |
|
|
2011 | 0 |
|
|
2012 | }); |
1989 | |
2013 | |
1990 | $DEBUG_STATUS = new CFPlus::UI::Label |
2014 | $DEBUG_STATUS = new CFPlus::UI::Label |
1991 | padding => 0, |
2015 | padding => 0, |
1992 | z => 100, |
2016 | z => 100, |
1993 | force_x => "max", |
2017 | force_x => "max", |
… | |
… | |
2023 | $MESSAGE_WINDOW->activate_console ($preset) |
2047 | $MESSAGE_WINDOW->activate_console ($preset) |
2024 | if $MESSAGE_WINDOW; |
2048 | if $MESSAGE_WINDOW; |
2025 | }); |
2049 | }); |
2026 | $MAPWIDGET->show; |
2050 | $MAPWIDGET->show; |
2027 | $MAPWIDGET->grab_focus; |
2051 | $MAPWIDGET->grab_focus; |
|
|
2052 | |
|
|
2053 | $COMPLETER = new CFPlus::MapWidget::Command:: |
|
|
2054 | command => { }, |
|
|
2055 | tooltip => "#completer_help", |
|
|
2056 | ; |
2028 | |
2057 | |
2029 | $SETUP_DIALOG = new CFPlus::UI::Toplevel |
2058 | $SETUP_DIALOG = new CFPlus::UI::Toplevel |
2030 | title => "Setup", |
2059 | title => "Setup", |
2031 | name => "setup_dialog", |
2060 | name => "setup_dialog", |
2032 | x => 'center', |
2061 | x => 'center', |
… | |
… | |
2157 | delete $animate_object{$widget}; |
2186 | delete $animate_object{$widget}; |
2158 | } |
2187 | } |
2159 | |
2188 | |
2160 | %SDL_CB = ( |
2189 | %SDL_CB = ( |
2161 | CFPlus::SDL_QUIT => sub { |
2190 | CFPlus::SDL_QUIT => sub { |
2162 | exit; |
2191 | Event::unloop_all; |
2163 | }, |
2192 | }, |
2164 | CFPlus::SDL_VIDEORESIZE => sub { |
2193 | CFPlus::SDL_VIDEORESIZE => sub { |
2165 | }, |
2194 | }, |
2166 | CFPlus::SDL_VIDEOEXPOSE => sub { |
2195 | CFPlus::SDL_VIDEOEXPOSE => sub { |
2167 | CFPlus::UI::full_refresh; |
2196 | CFPlus::UI::full_refresh; |
… | |
… | |
2300 | # } |
2329 | # } |
2301 | # my $t2 = Time::HiRes::time; |
2330 | # my $t2 = Time::HiRes::time; |
2302 | # warn $t2-$t1; |
2331 | # warn $t2-$t1; |
2303 | # } |
2332 | # } |
2304 | |
2333 | |
2305 | $startup_done->(); |
|
|
2306 | |
|
|
2307 | video_init; |
2334 | video_init; |
2308 | audio_init; |
2335 | audio_init; |
2309 | } |
2336 | } |
2310 | |
2337 | |
2311 | show_tip_of_the_day if $CFG->{show_tips}; |
2338 | show_tip_of_the_day if $CFG->{show_tips}; |
|
|
2339 | |
|
|
2340 | Event->idle (cb => sub { |
|
|
2341 | $_[0]->w->cancel; |
|
|
2342 | $startup_done->(); |
|
|
2343 | }); |
2312 | |
2344 | |
2313 | Event::loop; |
2345 | Event::loop; |
2314 | |
2346 | |
2315 | #video_shutdown; |
2347 | #video_shutdown; |
2316 | #audio_shutdown; |
2348 | #audio_shutdown; |