… | |
… | |
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; |
… | |
… | |
228 | $channel->set_position_r ($dx, $dy, 20); |
230 | $channel->set_position_r ($dx, $dy, 20); |
229 | $chunk->play ($channel); |
231 | $chunk->play ($channel); |
230 | } |
232 | } |
231 | } else { |
233 | } else { |
232 | # sound_meta not set means data is in flight either way |
234 | # sound_meta not set means data is in flight either way |
233 | my $meta = $CONN->{sound_meta}{$face} |
235 | my $meta = $CONN->{face}[$face] |
234 | or return; |
236 | or return; |
235 | |
237 | |
|
|
238 | $meta->{data} |
|
|
239 | or return; |
|
|
240 | |
236 | # if its a jingle, play it as ambient music |
241 | # if its a jingle, play it as ambient music |
237 | if ($meta->{meta}{jingle}) { |
242 | if ($meta->{data}{jingle}) { |
238 | if (delete $AUDIO_PLAY{$face}) { # take the jingle out of the sound queue |
243 | if (delete $AUDIO_PLAY{$face}) { # take the jingle out of the sound queue |
239 | push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue |
244 | push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue |
240 | &audio_music_push ($face); |
245 | &audio_music_push ($face); |
241 | } |
246 | } |
242 | } else { |
247 | } else { |
243 | # fetch from database |
248 | # fetch from database |
244 | CFPlus::DB::get res_data => $meta->{name}, sub { |
249 | CFPlus::DB::get res_data => $meta->{name}, sub { |
245 | my $rwops = new CFPlus::RW $_[0]; |
250 | my $rwops = new CFPlus::RW $_[0]; |
246 | my $chunk = new CFPlus::MixChunk $rwops |
251 | my $chunk = new CFPlus::MixChunk $rwops |
247 | or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError; |
252 | or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError; |
248 | $chunk->volume (($meta->{meta}{volume} || 1) * 128); |
253 | $chunk->volume (($meta->{data}{volume} || 1) * 128); |
249 | $AUDIO_CHUNK{$face} = $chunk; |
254 | $AUDIO_CHUNK{$face} = $chunk; |
250 | |
255 | |
251 | audio_sound_push ($face); |
256 | audio_sound_push ($face); |
252 | }; |
257 | }; |
253 | } |
258 | } |
… | |
… | |
271 | sub audio_music_set_meta { |
276 | sub audio_music_set_meta { |
272 | my ($meta) = @_; |
277 | my ($meta) = @_; |
273 | |
278 | |
274 | $MUSIC_PLAYING_META = $meta; |
279 | $MUSIC_PLAYING_META = $meta; |
275 | $MUSIC_PLAYING_WIDGET->set_markup ( |
280 | $MUSIC_PLAYING_WIDGET->set_markup ( |
276 | "<b>Name</b>: " . (CFPlus::asxml $meta->{meta}{name}) . "\n" |
281 | "<b>Name</b>: " . (CFPlus::asxml $meta->{data}{name}) . "\n" |
277 | . "<b>Author</b>: " . (CFPlus::asxml $meta->{meta}{author}) . "\n" |
282 | . "<b>Author</b>: " . (CFPlus::asxml $meta->{data}{author}) . "\n" |
278 | . "<b>Source</b>: " . (CFPlus::asxml $meta->{meta}{source}) . "\n" |
283 | . "<b>Source</b>: " . (CFPlus::asxml $meta->{data}{source}) . "\n" |
279 | . "<b>License</b>: " . (CFPlus::asxml $meta->{meta}{license}) |
284 | . "<b>License</b>: " . (CFPlus::asxml $meta->{data}{license}) |
280 | ); |
285 | ); |
281 | } |
286 | } |
282 | |
287 | |
283 | sub audio_music_update_volume { |
288 | sub audio_music_update_volume { |
284 | return unless $MUSIC_PLAYING_META; |
289 | return unless $MUSIC_PLAYING_META; |
285 | my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1; |
290 | my $volume = $MUSIC_PLAYING_META->{data}{volume} || 1; |
286 | my $base = $MUSIC_PLAYING_META->{meta}{jingle} ? 1 : $CFG->{bgm_volume}; |
291 | my $base = $MUSIC_PLAYING_META->{data}{jingle} ? 1 : $CFG->{bgm_volume}; |
287 | CFPlus::MixMusic::volume $base * $volume * 128; |
292 | CFPlus::MixMusic::volume $base * $volume * 128; |
288 | } |
293 | } |
289 | |
294 | |
290 | sub audio_music_start { |
295 | sub audio_music_start { |
291 | my $meta = $MUSIC_PLAYING_META; |
296 | my $meta = $MUSIC_PLAYING_META; |
… | |
… | |
334 | $fade_out = 333; |
339 | $fade_out = 333; |
335 | } else { |
340 | } else { |
336 | return unless $CFG->{bgm_enable}; |
341 | return unless $CFG->{bgm_enable}; |
337 | |
342 | |
338 | my @have = |
343 | my @have = |
339 | grep $_, |
344 | grep $_ && $_->{data}, |
340 | map $CONN->{music_meta}{$_}, |
345 | map $CONN->{face}[$_], |
341 | @$MUSIC_WANT; |
346 | @$MUSIC_WANT; |
342 | |
347 | |
343 | @MUSIC_HAVE = @have |
348 | @MUSIC_HAVE = @have |
344 | if @have; |
349 | if @have; |
345 | |
350 | |
… | |
… | |
784 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Compress Textures"); |
789 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Compress Textures"); |
785 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
790 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
786 | state => $CFG->{texture_compression}, |
791 | state => $CFG->{texture_compression}, |
787 | tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but " |
792 | tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but " |
788 | . "will save a lot of memory and increase performance. The compression algorithm " |
793 | . "will save a lot of memory and increase performance. The compression algorithm " |
789 | . "can differ form card to card, so your mileage may vary.", |
794 | . "can differ form card to card, so your mileage may vary. This setting is ignored in " |
|
|
795 | . "forced OpenGL 1.1 mode.", |
790 | on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 } |
796 | on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 } |
791 | ); |
797 | ); |
792 | |
798 | |
793 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); |
799 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); |
794 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
800 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
… | |
… | |
917 | expand => 1, state => $CFG->{bgm_enable}, |
923 | expand => 1, state => $CFG->{bgm_enable}, |
918 | tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", |
924 | tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", |
919 | on_changed => sub { |
925 | on_changed => sub { |
920 | $CFG->{bgm_enable} = $_[1]; |
926 | $CFG->{bgm_enable} = $_[1]; |
921 | $CONN->update_fx_want if $CONN; |
927 | $CONN->update_fx_want if $CONN; |
|
|
928 | audio_music_push; |
922 | 0 |
929 | 0 |
923 | } |
930 | } |
924 | ); |
931 | ); |
925 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
932 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
926 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], |
933 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], |
… | |
… | |
979 | $hb->add (my $hg = new CFPlus::UI::Gauge type => 'hp', tooltip => "#stat_health"); |
986 | $hb->add (my $hg = new CFPlus::UI::Gauge type => 'hp', tooltip => "#stat_health"); |
980 | $hb->add (my $mg = new CFPlus::UI::Gauge type => 'mana', tooltip => "#stat_mana"); |
987 | $hb->add (my $mg = new CFPlus::UI::Gauge type => 'mana', tooltip => "#stat_mana"); |
981 | $hb->add (my $gg = new CFPlus::UI::Gauge type => 'grace', tooltip => "#stat_grace"); |
988 | $hb->add (my $gg = new CFPlus::UI::Gauge type => 'grace', tooltip => "#stat_grace"); |
982 | $hb->add (my $fg = new CFPlus::UI::Gauge type => 'food', tooltip => "#stat_food"); |
989 | $hb->add (my $fg = new CFPlus::UI::Gauge type => 'food', tooltip => "#stat_food"); |
983 | |
990 | |
984 | $vbox->add (my $exp = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp"); |
991 | $vbox->add (my $exp = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp"); |
|
|
992 | $vbox->add (my $prg = new CFPlus::UI::ExperienceProgress); |
|
|
993 | $vbox->add (my $sklprg = new CFPlus::UI::ExperienceProgress); |
985 | $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged"); |
994 | $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged"); |
986 | |
995 | |
987 | $GAUGES = { |
996 | $GAUGES = { |
|
|
997 | exp => $exp, prg => $prg, sklprg => $sklprg, |
988 | exp => $exp, win => $win, range => $rng, |
998 | win => $win, range => $rng, |
989 | food => $fg, mana => $mg, hp => $hg, grace => $gg |
999 | hp => $hg, mana => $mg, grace => $gg, food => $fg, |
990 | }; |
1000 | }; |
991 | |
1001 | |
992 | &set_gauge_window_fontsize; |
1002 | &set_gauge_window_fontsize; |
993 | |
1003 | |
994 | $win |
1004 | $win |
… | |
… | |
1195 | $r |
1205 | $r |
1196 | } |
1206 | } |
1197 | |
1207 | |
1198 | sub skill_window { |
1208 | sub skill_window { |
1199 | my $sw = new CFPlus::UI::ScrolledWindow (expand => 1); |
1209 | my $sw = new CFPlus::UI::ScrolledWindow (expand => 1); |
|
|
1210 | |
1200 | $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, 0, 0, 1]); |
1211 | $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, .1, 0, 0, 1, .1]); |
|
|
1212 | |
1201 | $sw |
1213 | $sw |
1202 | } |
1214 | } |
1203 | |
1215 | |
1204 | sub formsep($) { |
1216 | sub formsep($) { |
1205 | scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1 |
1217 | scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1 |
… | |
… | |
1650 | } |
1662 | } |
1651 | |
1663 | |
1652 | sub add_license { |
1664 | sub add_license { |
1653 | my ($meta) = @_; |
1665 | my ($meta) = @_; |
1654 | |
1666 | |
1655 | $meta = $meta->{meta} |
1667 | $meta = $meta->{data} |
1656 | or return; |
1668 | or return; |
1657 | |
1669 | |
1658 | $meta->{license} || $meta->{author} || $meta->{source} |
1670 | $meta->{license} || $meta->{author} || $meta->{source} |
1659 | or return; |
1671 | or return; |
1660 | |
1672 | |
… | |
… | |
1714 | $ntb->add_tab ( |
1726 | $ntb->add_tab ( |
1715 | "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, |
1727 | "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, |
1716 | "Toggles the inventory window, where you can manage your loot (or treasures :). " |
1728 | "Toggles the inventory window, where you can manage your loot (or treasures :). " |
1717 | . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." |
1729 | . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." |
1718 | ); |
1730 | ); |
1719 | $ntb->add_tab (Pickup => autopickup_setup, |
1731 | $ntb->add_tab (Pickup => $PICKUP_PAGE = autopickup_setup, |
1720 | "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); |
1732 | "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); |
1721 | |
1733 | |
1722 | $ntb->add_tab (Media => media_window, |
1734 | $ntb->add_tab (Media => media_window, |
1723 | "License, Author and Source info for media sent by the server."); |
1735 | "License, Author and Source info for media sent by the server."); |
1724 | |
1736 | |
… | |
… | |
1965 | |
1977 | |
1966 | $SDL_ACTIVE = 1; |
1978 | $SDL_ACTIVE = 1; |
1967 | $LAST_REFRESH = time - 0.01; |
1979 | $LAST_REFRESH = time - 0.01; |
1968 | |
1980 | |
1969 | CFPlus::OpenGL::init; |
1981 | CFPlus::OpenGL::init; |
|
|
1982 | CFPlus::Macro::init; |
1970 | |
1983 | |
1971 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
1984 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
1972 | |
1985 | |
1973 | $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# |
1986 | $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# |
1974 | |
1987 | |
1975 | ############################################################################# |
1988 | ############################################################################# |
1976 | |
1989 | |
1977 | if ($DEBUG_STATUS) { |
1990 | if ($DEBUG_STATUS) { |
1978 | CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h; |
1991 | CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h; |
1979 | } else { |
1992 | } else { |
1980 | # create the widgets |
1993 | # create/configure the widgets |
|
|
1994 | |
|
|
1995 | $CFPlus::UI::ROOT->connect (key_down => sub { |
|
|
1996 | my (undef, $ev) = @_; |
|
|
1997 | |
|
|
1998 | if (my @macros = CFPlus::Macro::find $ev) { |
|
|
1999 | CFPlus::Macro::execute $_ for @macros; |
|
|
2000 | |
|
|
2001 | return 1; |
|
|
2002 | } |
|
|
2003 | |
|
|
2004 | 0 |
|
|
2005 | }); |
1981 | |
2006 | |
1982 | $DEBUG_STATUS = new CFPlus::UI::Label |
2007 | $DEBUG_STATUS = new CFPlus::UI::Label |
1983 | padding => 0, |
2008 | padding => 0, |
1984 | z => 100, |
2009 | z => 100, |
1985 | force_x => "max", |
2010 | force_x => "max", |
… | |
… | |
2015 | $MESSAGE_WINDOW->activate_console ($preset) |
2040 | $MESSAGE_WINDOW->activate_console ($preset) |
2016 | if $MESSAGE_WINDOW; |
2041 | if $MESSAGE_WINDOW; |
2017 | }); |
2042 | }); |
2018 | $MAPWIDGET->show; |
2043 | $MAPWIDGET->show; |
2019 | $MAPWIDGET->grab_focus; |
2044 | $MAPWIDGET->grab_focus; |
|
|
2045 | |
|
|
2046 | $COMPLETER = new CFPlus::MapWidget::Command:: |
|
|
2047 | command => { }, |
|
|
2048 | tooltip => "#completer_help", |
|
|
2049 | ; |
2020 | |
2050 | |
2021 | $SETUP_DIALOG = new CFPlus::UI::Toplevel |
2051 | $SETUP_DIALOG = new CFPlus::UI::Toplevel |
2022 | title => "Setup", |
2052 | title => "Setup", |
2023 | name => "setup_dialog", |
2053 | name => "setup_dialog", |
2024 | x => 'center', |
2054 | x => 'center', |
… | |
… | |
2149 | delete $animate_object{$widget}; |
2179 | delete $animate_object{$widget}; |
2150 | } |
2180 | } |
2151 | |
2181 | |
2152 | %SDL_CB = ( |
2182 | %SDL_CB = ( |
2153 | CFPlus::SDL_QUIT => sub { |
2183 | CFPlus::SDL_QUIT => sub { |
2154 | exit; |
2184 | Event::unloop_all; |
2155 | }, |
2185 | }, |
2156 | CFPlus::SDL_VIDEORESIZE => sub { |
2186 | CFPlus::SDL_VIDEORESIZE => sub { |
2157 | }, |
2187 | }, |
2158 | CFPlus::SDL_VIDEOEXPOSE => sub { |
2188 | CFPlus::SDL_VIDEOEXPOSE => sub { |
2159 | CFPlus::UI::full_refresh; |
2189 | CFPlus::UI::full_refresh; |
… | |
… | |
2292 | # } |
2322 | # } |
2293 | # my $t2 = Time::HiRes::time; |
2323 | # my $t2 = Time::HiRes::time; |
2294 | # warn $t2-$t1; |
2324 | # warn $t2-$t1; |
2295 | # } |
2325 | # } |
2296 | |
2326 | |
2297 | $startup_done->(); |
|
|
2298 | |
|
|
2299 | video_init; |
2327 | video_init; |
2300 | audio_init; |
2328 | audio_init; |
2301 | } |
2329 | } |
2302 | |
2330 | |
2303 | show_tip_of_the_day if $CFG->{show_tips}; |
2331 | show_tip_of_the_day if $CFG->{show_tips}; |
|
|
2332 | |
|
|
2333 | Event->idle (cb => sub { |
|
|
2334 | $_[0]->w->cancel; |
|
|
2335 | $startup_done->(); |
|
|
2336 | }); |
2304 | |
2337 | |
2305 | Event::loop; |
2338 | Event::loop; |
2306 | |
2339 | |
2307 | #video_shutdown; |
2340 | #video_shutdown; |
2308 | #audio_shutdown; |
2341 | #audio_shutdown; |