… | |
… | |
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; |
… | |
… | |
180 | sub debug { |
182 | sub debug { |
181 | $DEBUG_STATUS->set_text ($_[0]); |
183 | $DEBUG_STATUS->set_text ($_[0]); |
182 | } |
184 | } |
183 | |
185 | |
184 | sub message { |
186 | sub message { |
185 | my ($para) = @_; |
|
|
186 | $MESSAGE_WINDOW->message ($para); |
187 | $MESSAGE_WINDOW->message (@_); |
187 | } |
188 | } |
188 | |
189 | |
189 | ############################################################################# |
190 | ############################################################################# |
190 | #TODO: maybe move into own audio module... |
191 | #TODO: maybe move into own audio module... |
191 | |
192 | |
… | |
… | |
313 | |
314 | |
314 | my $NOW = time; |
315 | my $NOW = time; |
315 | |
316 | |
316 | if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { |
317 | if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { |
317 | my $pos = $MUSIC_PLAYING_META->{stop_pos}; |
318 | my $pos = $MUSIC_PLAYING_META->{stop_pos}; |
318 | $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos); |
319 | $MUSIC_PLAYER->fade_in_pos (0, 700, $pos); |
319 | $MUSIC_START = time - $pos; |
320 | $MUSIC_START = time - $pos; |
320 | } else { |
321 | } else { |
321 | $MUSIC_PLAYER->play (0); |
322 | $MUSIC_PLAYER->play (0); |
322 | $MUSIC_START = time; |
323 | $MUSIC_START = time; |
323 | } |
324 | } |
… | |
… | |
341 | my @have = |
342 | my @have = |
342 | grep $_ && $_->{data}, |
343 | grep $_ && $_->{data}, |
343 | map $CONN->{face}[$_], |
344 | map $CONN->{face}[$_], |
344 | @$MUSIC_WANT; |
345 | @$MUSIC_WANT; |
345 | |
346 | |
|
|
347 | # randomize music a bit so that the order is not always the same |
|
|
348 | $_->{stop_time} ||= rand for @have; |
|
|
349 | |
346 | @MUSIC_HAVE = @have |
350 | @MUSIC_HAVE = @have |
347 | if @have; |
351 | if @have; |
348 | |
352 | |
349 | # default MUSIC_HAVE == MUSIC_DEFAULT |
353 | # default MUSIC_HAVE == MUSIC_DEFAULT |
350 | @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE; |
354 | @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE; |
351 | $fade_out = 1000; |
355 | $fade_out = 700; |
352 | } |
356 | } |
353 | |
357 | |
354 | # if the currently playing song is acceptable, let it continue |
358 | # if the currently playing song is acceptable, let it continue |
355 | return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE; |
359 | return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE; |
356 | |
360 | |
… | |
… | |
365 | @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE; |
369 | @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE; |
366 | |
370 | |
367 | # if the most recently-played piece played very recently, |
371 | # if the most recently-played piece played very recently, |
368 | # resume it, else choose the oldest piece for rotation. |
372 | # resume it, else choose the oldest piece for rotation. |
369 | audio_music_set_meta |
373 | audio_music_set_meta |
370 | $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME |
374 | $MUSIC_HAVE[-1]{stop_pos} && $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME |
371 | ? $MUSIC_HAVE[-1] |
375 | ? $MUSIC_HAVE[-1] |
372 | : $MUSIC_HAVE[0]; |
376 | : $MUSIC_HAVE[0]; |
373 | |
377 | |
374 | audio_music_start; |
378 | audio_music_start; |
375 | } |
379 | } |
… | |
… | |
381 | $MUSIC_WANT = $songs; |
385 | $MUSIC_WANT = $songs; |
382 | audio_music_push; |
386 | audio_music_push; |
383 | } |
387 | } |
384 | |
388 | |
385 | sub audio_music_finished { |
389 | sub audio_music_finished { |
|
|
390 | if ($MUSIC_PLAYING_META) { |
|
|
391 | $MUSIC_PLAYING_META->{stop_time} = time; |
|
|
392 | } |
|
|
393 | |
386 | # we compress multiple jingles of the same type |
394 | # we compress multiple jingles of the same type |
387 | shift @MUSIC_JINGLE |
395 | shift @MUSIC_JINGLE |
388 | while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0]; |
396 | while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0]; |
389 | |
397 | |
390 | $MUSIC_PLAYING_WIDGET->clear; |
398 | $MUSIC_PLAYING_WIDGET->clear; |
… | |
… | |
984 | $hb->add (my $hg = new CFPlus::UI::Gauge type => 'hp', tooltip => "#stat_health"); |
992 | $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"); |
993 | $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"); |
994 | $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"); |
995 | $hb->add (my $fg = new CFPlus::UI::Gauge type => 'food', tooltip => "#stat_food"); |
988 | |
996 | |
989 | $vbox->add (my $exp = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp"); |
997 | $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 $prg = new CFPlus::UI::ExperienceProgress); |
|
|
999 | $vbox->add (my $sklprg = new CFPlus::UI::ExperienceProgress); |
990 | $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged"); |
1000 | $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged"); |
991 | |
1001 | |
992 | $GAUGES = { |
1002 | $GAUGES = { |
|
|
1003 | exp => $exp, prg => $prg, sklprg => $sklprg, |
993 | exp => $exp, win => $win, range => $rng, |
1004 | win => $win, range => $rng, |
994 | food => $fg, mana => $mg, hp => $hg, grace => $gg |
1005 | hp => $hg, mana => $mg, grace => $gg, food => $fg, |
995 | }; |
1006 | }; |
996 | |
1007 | |
997 | &set_gauge_window_fontsize; |
1008 | &set_gauge_window_fontsize; |
998 | |
1009 | |
999 | $win |
1010 | $win |
… | |
… | |
1200 | $r |
1211 | $r |
1201 | } |
1212 | } |
1202 | |
1213 | |
1203 | sub skill_window { |
1214 | sub skill_window { |
1204 | my $sw = new CFPlus::UI::ScrolledWindow (expand => 1); |
1215 | my $sw = new CFPlus::UI::ScrolledWindow (expand => 1); |
|
|
1216 | |
1205 | $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, 0, 0, 1]); |
1217 | $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, .1, 0, 0, 1, .1]); |
|
|
1218 | |
1206 | $sw |
1219 | $sw |
1207 | } |
1220 | } |
1208 | |
1221 | |
1209 | sub formsep($) { |
1222 | sub formsep($) { |
1210 | scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1 |
1223 | scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1 |
… | |
… | |
1719 | $ntb->add_tab ( |
1732 | $ntb->add_tab ( |
1720 | "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, |
1733 | "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, |
1721 | "Toggles the inventory window, where you can manage your loot (or treasures :). " |
1734 | "Toggles the inventory window, where you can manage your loot (or treasures :). " |
1722 | . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." |
1735 | . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." |
1723 | ); |
1736 | ); |
1724 | $ntb->add_tab (Pickup => autopickup_setup, |
1737 | $ntb->add_tab (Pickup => $PICKUP_PAGE = autopickup_setup, |
1725 | "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); |
1738 | "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); |
1726 | |
1739 | |
1727 | $ntb->add_tab (Media => media_window, |
1740 | $ntb->add_tab (Media => media_window, |
1728 | "License, Author and Source info for media sent by the server."); |
1741 | "License, Author and Source info for media sent by the server."); |
1729 | |
1742 | |
… | |
… | |
1970 | |
1983 | |
1971 | $SDL_ACTIVE = 1; |
1984 | $SDL_ACTIVE = 1; |
1972 | $LAST_REFRESH = time - 0.01; |
1985 | $LAST_REFRESH = time - 0.01; |
1973 | |
1986 | |
1974 | CFPlus::OpenGL::init; |
1987 | CFPlus::OpenGL::init; |
|
|
1988 | CFPlus::Macro::init; |
1975 | |
1989 | |
1976 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
1990 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
1977 | |
1991 | |
1978 | $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# |
1992 | $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# |
1979 | |
1993 | |
1980 | ############################################################################# |
1994 | ############################################################################# |
1981 | |
1995 | |
1982 | if ($DEBUG_STATUS) { |
1996 | if ($DEBUG_STATUS) { |
1983 | CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h; |
1997 | CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h; |
1984 | } else { |
1998 | } else { |
1985 | # create the widgets |
1999 | # create/configure the widgets |
|
|
2000 | |
|
|
2001 | $CFPlus::UI::ROOT->connect (key_down => sub { |
|
|
2002 | my (undef, $ev) = @_; |
|
|
2003 | |
|
|
2004 | if (my @macros = CFPlus::Macro::find $ev) { |
|
|
2005 | CFPlus::Macro::execute $_ for @macros; |
|
|
2006 | |
|
|
2007 | return 1; |
|
|
2008 | } |
|
|
2009 | |
|
|
2010 | 0 |
|
|
2011 | }); |
1986 | |
2012 | |
1987 | $DEBUG_STATUS = new CFPlus::UI::Label |
2013 | $DEBUG_STATUS = new CFPlus::UI::Label |
1988 | padding => 0, |
2014 | padding => 0, |
1989 | z => 100, |
2015 | z => 100, |
1990 | force_x => "max", |
2016 | force_x => "max", |
… | |
… | |
2020 | $MESSAGE_WINDOW->activate_console ($preset) |
2046 | $MESSAGE_WINDOW->activate_console ($preset) |
2021 | if $MESSAGE_WINDOW; |
2047 | if $MESSAGE_WINDOW; |
2022 | }); |
2048 | }); |
2023 | $MAPWIDGET->show; |
2049 | $MAPWIDGET->show; |
2024 | $MAPWIDGET->grab_focus; |
2050 | $MAPWIDGET->grab_focus; |
|
|
2051 | |
|
|
2052 | $COMPLETER = new CFPlus::MapWidget::Command:: |
|
|
2053 | command => { }, |
|
|
2054 | tooltip => "#completer_help", |
|
|
2055 | ; |
2025 | |
2056 | |
2026 | $SETUP_DIALOG = new CFPlus::UI::Toplevel |
2057 | $SETUP_DIALOG = new CFPlus::UI::Toplevel |
2027 | title => "Setup", |
2058 | title => "Setup", |
2028 | name => "setup_dialog", |
2059 | name => "setup_dialog", |
2029 | x => 'center', |
2060 | x => 'center', |
… | |
… | |
2154 | delete $animate_object{$widget}; |
2185 | delete $animate_object{$widget}; |
2155 | } |
2186 | } |
2156 | |
2187 | |
2157 | %SDL_CB = ( |
2188 | %SDL_CB = ( |
2158 | CFPlus::SDL_QUIT => sub { |
2189 | CFPlus::SDL_QUIT => sub { |
2159 | exit; |
2190 | Event::unloop_all; |
2160 | }, |
2191 | }, |
2161 | CFPlus::SDL_VIDEORESIZE => sub { |
2192 | CFPlus::SDL_VIDEORESIZE => sub { |
2162 | }, |
2193 | }, |
2163 | CFPlus::SDL_VIDEOEXPOSE => sub { |
2194 | CFPlus::SDL_VIDEOEXPOSE => sub { |
2164 | CFPlus::UI::full_refresh; |
2195 | CFPlus::UI::full_refresh; |
… | |
… | |
2297 | # } |
2328 | # } |
2298 | # my $t2 = Time::HiRes::time; |
2329 | # my $t2 = Time::HiRes::time; |
2299 | # warn $t2-$t1; |
2330 | # warn $t2-$t1; |
2300 | # } |
2331 | # } |
2301 | |
2332 | |
2302 | $startup_done->(); |
|
|
2303 | |
|
|
2304 | video_init; |
2333 | video_init; |
2305 | audio_init; |
2334 | audio_init; |
2306 | } |
2335 | } |
2307 | |
2336 | |
2308 | show_tip_of_the_day if $CFG->{show_tips}; |
2337 | show_tip_of_the_day if $CFG->{show_tips}; |
|
|
2338 | |
|
|
2339 | Event->idle (cb => sub { |
|
|
2340 | $_[0]->w->cancel; |
|
|
2341 | $startup_done->(); |
|
|
2342 | }); |
2309 | |
2343 | |
2310 | Event::loop; |
2344 | Event::loop; |
2311 | |
2345 | |
2312 | #video_shutdown; |
2346 | #video_shutdown; |
2313 | #audio_shutdown; |
2347 | #audio_shutdown; |