… | |
… | |
167 | our $STATUSBOX; |
167 | our $STATUSBOX; |
168 | our $DEBUG_STATUS; |
168 | our $DEBUG_STATUS; |
169 | |
169 | |
170 | our $INV; |
170 | our $INV; |
171 | our $INVR; |
171 | our $INVR; |
172 | our $INV_RIGHT_HB; |
172 | our $INVR_HB; |
173 | |
|
|
174 | our $PICKUP_CFG; |
|
|
175 | |
173 | |
176 | ############################################################################# |
174 | ############################################################################# |
177 | |
175 | |
178 | sub status { |
176 | sub status { |
179 | $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); |
177 | $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); |
… | |
… | |
230 | $channel->set_position_r ($dx, $dy, 20); |
228 | $channel->set_position_r ($dx, $dy, 20); |
231 | $chunk->play ($channel); |
229 | $chunk->play ($channel); |
232 | } |
230 | } |
233 | } else { |
231 | } else { |
234 | # sound_meta not set means data is in flight either way |
232 | # sound_meta not set means data is in flight either way |
235 | my $meta = $CONN->{sound_meta}{$face} |
233 | my $meta = $CONN->{face}[$face] |
236 | or return; |
234 | or return; |
237 | |
235 | |
|
|
236 | $meta->{data} |
|
|
237 | or return; |
|
|
238 | |
238 | # if its a jingle, play it as ambient music |
239 | # if its a jingle, play it as ambient music |
239 | if ($meta->{meta}{jingle}) { |
240 | if ($meta->{data}{jingle}) { |
240 | if (delete $AUDIO_PLAY{$face}) { # take the jingle out of the sound queue |
241 | if (delete $AUDIO_PLAY{$face}) { # take the jingle out of the sound queue |
241 | push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue |
242 | push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue |
242 | &audio_music_push ($face); |
243 | &audio_music_push ($face); |
243 | } |
244 | } |
244 | } else { |
245 | } else { |
245 | # fetch from database |
246 | # fetch from database |
246 | CFPlus::DB::get res_data => $meta->{name}, sub { |
247 | CFPlus::DB::get res_data => $meta->{name}, sub { |
247 | my $rwops = new CFPlus::RW $_[0]; |
248 | my $rwops = new CFPlus::RW $_[0]; |
248 | my $chunk = new CFPlus::MixChunk $rwops |
249 | my $chunk = new CFPlus::MixChunk $rwops |
249 | or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError; |
250 | or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError; |
250 | $chunk->volume (($meta->{meta}{volume} || 1) * 128); |
251 | $chunk->volume (($meta->{data}{volume} || 1) * 128); |
251 | $AUDIO_CHUNK{$face} = $chunk; |
252 | $AUDIO_CHUNK{$face} = $chunk; |
252 | |
253 | |
253 | audio_sound_push ($face); |
254 | audio_sound_push ($face); |
254 | }; |
255 | }; |
255 | } |
256 | } |
… | |
… | |
273 | sub audio_music_set_meta { |
274 | sub audio_music_set_meta { |
274 | my ($meta) = @_; |
275 | my ($meta) = @_; |
275 | |
276 | |
276 | $MUSIC_PLAYING_META = $meta; |
277 | $MUSIC_PLAYING_META = $meta; |
277 | $MUSIC_PLAYING_WIDGET->set_markup ( |
278 | $MUSIC_PLAYING_WIDGET->set_markup ( |
278 | "<b>Name</b>: " . (CFPlus::asxml $meta->{meta}{name}) . "\n" |
279 | "<b>Name</b>: " . (CFPlus::asxml $meta->{data}{name}) . "\n" |
279 | . "<b>Author</b>: " . (CFPlus::asxml $meta->{meta}{author}) . "\n" |
280 | . "<b>Author</b>: " . (CFPlus::asxml $meta->{data}{author}) . "\n" |
280 | . "<b>Source</b>: " . (CFPlus::asxml $meta->{meta}{source}) . "\n" |
281 | . "<b>Source</b>: " . (CFPlus::asxml $meta->{data}{source}) . "\n" |
281 | . "<b>License</b>: " . (CFPlus::asxml $meta->{meta}{license}) |
282 | . "<b>License</b>: " . (CFPlus::asxml $meta->{data}{license}) |
282 | ); |
283 | ); |
283 | } |
284 | } |
284 | |
285 | |
285 | sub audio_music_update_volume { |
286 | sub audio_music_update_volume { |
286 | return unless $MUSIC_PLAYING_META; |
287 | return unless $MUSIC_PLAYING_META; |
287 | my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1; |
288 | my $volume = $MUSIC_PLAYING_META->{data}{volume} || 1; |
288 | my $base = $MUSIC_PLAYING_META->{meta}{jingle} ? 1 : $CFG->{bgm_volume}; |
289 | my $base = $MUSIC_PLAYING_META->{data}{jingle} ? 1 : $CFG->{bgm_volume}; |
289 | CFPlus::MixMusic::volume $base * $volume * 128; |
290 | CFPlus::MixMusic::volume $base * $volume * 128; |
290 | } |
291 | } |
291 | |
292 | |
292 | sub audio_music_start { |
293 | sub audio_music_start { |
293 | my $meta = $MUSIC_PLAYING_META; |
294 | my $meta = $MUSIC_PLAYING_META; |
… | |
… | |
336 | $fade_out = 333; |
337 | $fade_out = 333; |
337 | } else { |
338 | } else { |
338 | return unless $CFG->{bgm_enable}; |
339 | return unless $CFG->{bgm_enable}; |
339 | |
340 | |
340 | my @have = |
341 | my @have = |
341 | grep $_, |
342 | grep $_ && $_->{data}, |
342 | map $CONN->{music_meta}{$_}, |
343 | map $CONN->{face}[$_], |
343 | @$MUSIC_WANT; |
344 | @$MUSIC_WANT; |
344 | |
345 | |
345 | @MUSIC_HAVE = @have |
346 | @MUSIC_HAVE = @have |
346 | if @have; |
347 | if @have; |
347 | |
348 | |
… | |
… | |
771 | on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 } |
772 | on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 } |
772 | ); |
773 | ); |
773 | |
774 | |
774 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Force OpenGL 1.1"); |
775 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Force OpenGL 1.1"); |
775 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
776 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
776 | state => $CFG->{opengl11}, |
777 | state => $CFG->{force_opengl11}, |
777 | tooltip => "Limit CFPlus to use OpenGL 1.1 features only. This will normally result in " |
778 | tooltip => "Limit CFPlus to use OpenGL 1.1 features only. This will normally result in " |
778 | . "higher memory usage and slower performance. It will, however, help tremendously on " |
779 | . "higher memory usage and slower performance. It will, however, help tremendously on " |
779 | . "cards that claim to support a feature but fall back to software rendering. " |
780 | . "cards that claim to support a feature but fall back to software rendering. " |
780 | . "Nvidia Geforce FX cards are known to claim features the hardware doesn't support, " |
781 | . "Nvidia Geforce FX cards are known to claim features the hardware doesn't support, " |
781 | . "but cards and drivers from other vendors (ATI) are often just as bad. <b>If you " |
782 | . "but cards and drivers from other vendors (ATI) are often just as bad. <b>If you " |
782 | . "experience extremely low framerates and your card should do better, try this option.</b>", |
783 | . "experience extremely low framerates and your card should do better, try this option.</b>", |
783 | on_changed => sub { my ($self, $value) = @_; $CFG->{opengl11} = $value; 0 } |
784 | on_changed => sub { my ($self, $value) = @_; $CFG->{force_opengl11} = $value; 0 } |
|
|
785 | ); |
|
|
786 | |
|
|
787 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Compress Textures"); |
|
|
788 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
|
|
789 | state => $CFG->{texture_compression}, |
|
|
790 | tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but " |
|
|
791 | . "will save a lot of memory and increase performance. The compression algorithm " |
|
|
792 | . "can differ form card to card, so your mileage may vary. This setting is ignored in " |
|
|
793 | . "forced OpenGL 1.1 mode.", |
|
|
794 | on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 } |
784 | ); |
795 | ); |
785 | |
796 | |
786 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); |
797 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); |
787 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
798 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
788 | state => $CFG->{fast}, |
799 | state => $CFG->{fast}, |
… | |
… | |
910 | expand => 1, state => $CFG->{bgm_enable}, |
921 | expand => 1, state => $CFG->{bgm_enable}, |
911 | tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", |
922 | tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", |
912 | on_changed => sub { |
923 | on_changed => sub { |
913 | $CFG->{bgm_enable} = $_[1]; |
924 | $CFG->{bgm_enable} = $_[1]; |
914 | $CONN->update_fx_want if $CONN; |
925 | $CONN->update_fx_want if $CONN; |
|
|
926 | audio_music_push; |
915 | 0 |
927 | 0 |
916 | } |
928 | } |
917 | ); |
929 | ); |
918 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
930 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
919 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], |
931 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], |
… | |
… | |
1610 | $sw1->add ($INV = new CFPlus::UI::Inventory); |
1622 | $sw1->add ($INV = new CFPlus::UI::Inventory); |
1611 | $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}}); |
1623 | $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}}); |
1612 | |
1624 | |
1613 | $hb->add (my $vb2 = new CFPlus::UI::VBox); |
1625 | $hb->add (my $vb2 = new CFPlus::UI::VBox); |
1614 | |
1626 | |
1615 | $vb2->add ($INV_RIGHT_HB = new CFPlus::UI::HBox); |
1627 | $vb2->add ($INVR_HB = new CFPlus::UI::HBox); |
1616 | |
1628 | |
1617 | $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); |
1629 | $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); |
1618 | $sw2->add ($INVR = new CFPlus::UI::Inventory); |
1630 | $sw2->add ($INVR = new CFPlus::UI::Inventory); |
1619 | |
1631 | |
1620 | # XXX: Call after $INVR = ... because set_opencont sets the items |
1632 | # XXX: Call after $INVR = ... because set_opencont sets the items |
… | |
… | |
1643 | } |
1655 | } |
1644 | |
1656 | |
1645 | sub add_license { |
1657 | sub add_license { |
1646 | my ($meta) = @_; |
1658 | my ($meta) = @_; |
1647 | |
1659 | |
1648 | $meta = $meta->{meta} |
1660 | $meta = $meta->{data} |
1649 | or return; |
1661 | or return; |
1650 | |
1662 | |
1651 | $meta->{license} || $meta->{author} || $meta->{source} |
1663 | $meta->{license} || $meta->{author} || $meta->{source} |
1652 | or return; |
1664 | or return; |
1653 | |
1665 | |
… | |
… | |
1875 | on_activate => sub { $QUIT_DIALOG->hide; 0 }, |
1887 | on_activate => sub { $QUIT_DIALOG->hide; 0 }, |
1876 | ); |
1888 | ); |
1877 | $hb->add (new CFPlus::UI::Button |
1889 | $hb->add (new CFPlus::UI::Button |
1878 | text => "Quit anyway", |
1890 | text => "Quit anyway", |
1879 | expand => 1, |
1891 | expand => 1, |
1880 | on_activate => sub { exit }, |
1892 | on_activate => sub { Event::unloop_all }, |
1881 | ); |
1893 | ); |
1882 | } |
1894 | } |
1883 | |
1895 | |
1884 | $QUIT_DIALOG->show; |
1896 | $QUIT_DIALOG->show; |
1885 | $QUIT_DIALOG->grab_focus; |
1897 | $QUIT_DIALOG->grab_focus; |
… | |
… | |
2079 | tooltip => "Terminates the program", |
2091 | tooltip => "Terminates the program", |
2080 | on_activate => sub { |
2092 | on_activate => sub { |
2081 | if ($CONN) { |
2093 | if ($CONN) { |
2082 | open_quit_dialog; |
2094 | open_quit_dialog; |
2083 | } else { |
2095 | } else { |
2084 | exit; |
2096 | Event::unloop_all; |
2085 | } |
2097 | } |
2086 | 0 |
2098 | 0 |
2087 | }, |
2099 | }, |
2088 | ); |
2100 | ); |
2089 | |
2101 | |
2090 | $BUTTONBAR->show; |
2102 | $BUTTONBAR->show; |
2091 | $SETUP_DIALOG->show; |
2103 | $SETUP_DIALOG->show; |
|
|
2104 | $MESSAGE_WINDOW->show; |
2092 | } |
2105 | } |
2093 | |
2106 | |
2094 | $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); |
2107 | $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); |
2095 | } |
2108 | } |
2096 | |
2109 | |
… | |
… | |
2190 | CFPlus::DB::Server::run; |
2203 | CFPlus::DB::Server::run; |
2191 | |
2204 | |
2192 | CFPlus::UI::set_layout ($::CFG->{layout}); |
2205 | CFPlus::UI::set_layout ($::CFG->{layout}); |
2193 | |
2206 | |
2194 | my %DEF_CFG = ( |
2207 | my %DEF_CFG = ( |
2195 | sdl_mode => 0, |
2208 | sdl_mode => 0, |
2196 | fullscreen => 0, |
2209 | fullscreen => 0, |
2197 | fast => 0, |
2210 | fast => 0, |
2198 | opengl11 => 0, |
2211 | force_opengl11 => undef, |
|
|
2212 | texture_compression => 1, |
2199 | map_scale => 1, |
2213 | map_scale => 1, |
2200 | fow_enable => 1, |
2214 | fow_enable => 1, |
2201 | fow_intensity => 0, |
2215 | fow_intensity => 0, |
2202 | map_smoothing => 1, |
2216 | map_smoothing => 1, |
2203 | gui_fontsize => 1, |
2217 | gui_fontsize => 1, |
2204 | log_fontsize => 0.7, |
2218 | log_fontsize => 0.7, |
2205 | gauge_fontsize => 1, |
2219 | gauge_fontsize => 1, |
2206 | gauge_size => 0.35, |
2220 | gauge_size => 0.35, |
2207 | stat_fontsize => 0.7, |
2221 | stat_fontsize => 0.7, |
2208 | mapsize => 100, |
2222 | mapsize => 100, |
2209 | audio_enable => 1, |
2223 | audio_enable => 1, |
2210 | effects_enable => 1, |
2224 | effects_enable => 1, |
2211 | effects_volume => 1, |
2225 | effects_volume => 1, |
2212 | bgm_enable => 1, |
2226 | bgm_enable => 1, |
2213 | bgm_volume => 0.5, |
2227 | bgm_volume => 0.5, |
2214 | output_sync => 1, |
2228 | output_sync => 1, |
2215 | output_count => 1, |
2229 | output_count => 1, |
2216 | output_rate => "", |
2230 | output_rate => "", |
2217 | pickup => 0, |
2231 | pickup => 0, |
2218 | inv_sort => "mtime", |
2232 | inv_sort => "mtime", |
2219 | default => "profile", # default profile |
2233 | default => "profile", # default profile |
2220 | show_tips => 1, |
2234 | show_tips => 1, |
2221 | logview_max_par => 1000, |
2235 | logview_max_par => 1000, |
2222 | ); |
2236 | ); |
2223 | |
2237 | |
2224 | while (my ($k, $v) = each %DEF_CFG) { |
2238 | while (my ($k, $v) = each %DEF_CFG) { |
2225 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
2239 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
2226 | } |
2240 | } |
… | |
… | |
2292 | } |
2306 | } |
2293 | |
2307 | |
2294 | show_tip_of_the_day if $CFG->{show_tips}; |
2308 | show_tip_of_the_day if $CFG->{show_tips}; |
2295 | |
2309 | |
2296 | Event::loop; |
2310 | Event::loop; |
|
|
2311 | |
|
|
2312 | #video_shutdown; |
|
|
2313 | #audio_shutdown; |
2297 | #CFPlus::SDL_Quit; |
2314 | CFPlus::SDL_Quit; |
2298 | #CFPlus::_exit 0; |
|
|
2299 | |
|
|
2300 | END { |
|
|
2301 | video_shutdown; |
|
|
2302 | audio_shutdown; |
|
|
2303 | CFPlus::SDL_Quit; |
|
|
2304 | CFPlus::DB::Server::stop; |
2315 | CFPlus::DB::Server::stop; |
2305 | } |
|
|
2306 | |
2316 | |
2307 | =head1 NAME |
2317 | =head1 NAME |
2308 | |
2318 | |
2309 | cfplus - A Crossfire TRT and Crossfire game client |
2319 | cfplus - A Crossfire TRT and Crossfire game client |
2310 | |
2320 | |