… | |
… | |
113 | our $CONN; |
113 | our $CONN; |
114 | our $PROFILE; # current profile |
114 | our $PROFILE; # current profile |
115 | our $FAST; # fast, low-quality mode, possibly useful for software-rendering |
115 | our $FAST; # fast, low-quality mode, possibly useful for software-rendering |
116 | |
116 | |
117 | our $WANT_REFRESH; |
117 | our $WANT_REFRESH; |
118 | our $CAN_REFRESH; |
|
|
119 | |
118 | |
120 | our @SDL_MODES; |
119 | our @SDL_MODES; |
121 | our $WIDTH; |
120 | our $WIDTH; |
122 | our $HEIGHT; |
121 | our $HEIGHT; |
123 | our $FULLSCREEN; |
122 | our $FULLSCREEN; |
… | |
… | |
127 | our $FONT_FIXED; |
126 | our $FONT_FIXED; |
128 | |
127 | |
129 | our $MAP; |
128 | our $MAP; |
130 | our $MAPMAP; |
129 | our $MAPMAP; |
131 | our $MAPWIDGET; |
130 | our $MAPWIDGET; |
|
|
131 | our $COMPLETER; |
132 | our $BUTTONBAR; |
132 | our $BUTTONBAR; |
133 | our $METASERVER; |
133 | our $METASERVER; |
134 | our $LOGIN_BUTTON; |
134 | our $LOGIN_BUTTON; |
135 | our $QUIT_DIALOG; |
135 | our $QUIT_DIALOG; |
136 | our $HOST_ENTRY; |
136 | our $HOST_ENTRY; |
… | |
… | |
147 | our $PL_WINDOW; |
147 | our $PL_WINDOW; |
148 | |
148 | |
149 | our $MUSIC_PLAYING_WIDGET; |
149 | our $MUSIC_PLAYING_WIDGET; |
150 | our $LICENSE_WIDGET; |
150 | our $LICENSE_WIDGET; |
151 | |
151 | |
|
|
152 | our $PICKUP_PAGE; |
152 | our $INVENTORY_PAGE; |
153 | our $INVENTORY_PAGE; |
153 | our $STATS_PAGE; |
154 | our $STATS_PAGE; |
154 | our $SKILL_PAGE; |
155 | our $SKILL_PAGE; |
155 | our $SPELL_PAGE; |
156 | our $SPELL_PAGE; |
156 | our $SPELL_LIST; |
157 | our $SPELL_LIST; |
… | |
… | |
168 | our $STATUSBOX; |
169 | our $STATUSBOX; |
169 | our $DEBUG_STATUS; |
170 | our $DEBUG_STATUS; |
170 | |
171 | |
171 | our $INV; |
172 | our $INV; |
172 | our $INVR; |
173 | our $INVR; |
173 | our $INV_RIGHT_HB; |
174 | our $INVR_HB; |
174 | |
|
|
175 | our $PICKUP_CFG; |
|
|
176 | |
175 | |
177 | ############################################################################# |
176 | ############################################################################# |
178 | |
177 | |
179 | sub status { |
178 | sub status { |
180 | $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); |
179 | $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); |
… | |
… | |
231 | $channel->set_position_r ($dx, $dy, 20); |
230 | $channel->set_position_r ($dx, $dy, 20); |
232 | $chunk->play ($channel); |
231 | $chunk->play ($channel); |
233 | } |
232 | } |
234 | } else { |
233 | } else { |
235 | # sound_meta not set means data is in flight either way |
234 | # sound_meta not set means data is in flight either way |
236 | my $meta = $CONN->{sound_meta}{$face} |
235 | my $meta = $CONN->{face}[$face] |
237 | or return; |
236 | or return; |
238 | |
237 | |
|
|
238 | $meta->{data} |
|
|
239 | or return; |
|
|
240 | |
239 | # if its a jingle, play it as ambient music |
241 | # if its a jingle, play it as ambient music |
240 | if ($meta->{meta}{jingle}) { |
242 | if ($meta->{data}{jingle}) { |
241 | 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 |
242 | push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue |
244 | push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue |
243 | &audio_music_push ($face); |
245 | &audio_music_push ($face); |
244 | } |
246 | } |
245 | } else { |
247 | } else { |
246 | # fetch from database |
248 | # fetch from database |
247 | CFPlus::DB::get res_data => $meta->{name}, sub { |
249 | CFPlus::DB::get res_data => $meta->{name}, sub { |
248 | my $rwops = new CFPlus::RW $_[0]; |
250 | my $rwops = new CFPlus::RW $_[0]; |
249 | my $chunk = new CFPlus::MixChunk $rwops |
251 | my $chunk = new CFPlus::MixChunk $rwops |
250 | 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; |
251 | $chunk->volume (($meta->{meta}{volume} || 1) * 128); |
253 | $chunk->volume (($meta->{data}{volume} || 1) * 128); |
252 | $AUDIO_CHUNK{$face} = $chunk; |
254 | $AUDIO_CHUNK{$face} = $chunk; |
253 | |
255 | |
254 | audio_sound_push ($face); |
256 | audio_sound_push ($face); |
255 | }; |
257 | }; |
256 | } |
258 | } |
… | |
… | |
264 | or return; |
266 | or return; |
265 | $CFG->{effects_enable} |
267 | $CFG->{effects_enable} |
266 | or return; |
268 | or return; |
267 | |
269 | |
268 | my $queue = $AUDIO_PLAY{$face} ||= []; |
270 | my $queue = $AUDIO_PLAY{$face} ||= []; |
269 | push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s |
271 | push @$queue, [Event::time + 0.6, $dx, $dy, $vol]; # do not play sound for outdated events |
270 | audio_sound_push $face |
272 | audio_sound_push $face |
271 | unless @$queue > 1; |
273 | unless @$queue > 1; |
272 | } |
274 | } |
273 | |
275 | |
274 | sub audio_music_set_meta { |
276 | sub audio_music_set_meta { |
275 | my ($meta) = @_; |
277 | my ($meta) = @_; |
276 | |
278 | |
277 | $MUSIC_PLAYING_META = $meta; |
279 | $MUSIC_PLAYING_META = $meta; |
278 | $MUSIC_PLAYING_WIDGET->set_markup ( |
280 | $MUSIC_PLAYING_WIDGET->set_markup ( |
279 | "<b>Name</b>: " . (CFPlus::asxml $meta->{meta}{name}) . "\n" |
281 | "<b>Name</b>: " . (CFPlus::asxml $meta->{data}{name}) . "\n" |
280 | . "<b>Author</b>: " . (CFPlus::asxml $meta->{meta}{author}) . "\n" |
282 | . "<b>Author</b>: " . (CFPlus::asxml $meta->{data}{author}) . "\n" |
281 | . "<b>Source</b>: " . (CFPlus::asxml $meta->{meta}{source}) . "\n" |
283 | . "<b>Source</b>: " . (CFPlus::asxml $meta->{data}{source}) . "\n" |
282 | . "<b>License</b>: " . (CFPlus::asxml $meta->{meta}{license}) |
284 | . "<b>License</b>: " . (CFPlus::asxml $meta->{data}{license}) |
283 | ); |
285 | ); |
284 | } |
286 | } |
285 | |
287 | |
286 | sub audio_music_update_volume { |
288 | sub audio_music_update_volume { |
287 | return unless $MUSIC_PLAYING_META; |
289 | return unless $MUSIC_PLAYING_META; |
288 | my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1; |
290 | my $volume = $MUSIC_PLAYING_META->{data}{volume} || 1; |
289 | my $base = $MUSIC_PLAYING_META->{meta}{jingle} ? 1 : $CFG->{bgm_volume}; |
291 | my $base = $MUSIC_PLAYING_META->{data}{jingle} ? 1 : $CFG->{bgm_volume}; |
290 | CFPlus::MixMusic::volume $base * $volume * 128; |
292 | CFPlus::MixMusic::volume $base * $volume * 128; |
291 | } |
293 | } |
292 | |
294 | |
293 | sub audio_music_start { |
295 | sub audio_music_start { |
294 | my $meta = $MUSIC_PLAYING_META; |
296 | my $meta = $MUSIC_PLAYING_META; |
… | |
… | |
337 | $fade_out = 333; |
339 | $fade_out = 333; |
338 | } else { |
340 | } else { |
339 | return unless $CFG->{bgm_enable}; |
341 | return unless $CFG->{bgm_enable}; |
340 | |
342 | |
341 | my @have = |
343 | my @have = |
342 | grep $_, |
344 | grep $_ && $_->{data}, |
343 | map $CONN->{music_meta}{$_}, |
345 | map $CONN->{face}[$_], |
344 | @$MUSIC_WANT; |
346 | @$MUSIC_WANT; |
345 | |
347 | |
346 | @MUSIC_HAVE = @have |
348 | @MUSIC_HAVE = @have |
347 | if @have; |
349 | if @have; |
348 | |
350 | |
… | |
… | |
770 | state => $CFG->{fullscreen}, |
772 | state => $CFG->{fullscreen}, |
771 | tooltip => "Bring the client into fullscreen mode.", |
773 | tooltip => "Bring the client into fullscreen mode.", |
772 | on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 } |
774 | on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 } |
773 | ); |
775 | ); |
774 | |
776 | |
|
|
777 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Force OpenGL 1.1"); |
|
|
778 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
|
|
779 | state => $CFG->{force_opengl11}, |
|
|
780 | tooltip => "Limit CFPlus to use OpenGL 1.1 features only. This will normally result in " |
|
|
781 | . "higher memory usage and slower performance. It will, however, help tremendously on " |
|
|
782 | . "cards that claim to support a feature but fall back to software rendering. " |
|
|
783 | . "Nvidia Geforce FX cards are known to claim features the hardware doesn't support, " |
|
|
784 | . "but cards and drivers from other vendors (ATI) are often just as bad. <b>If you " |
|
|
785 | . "experience extremely low framerates and your card should do better, try this option.</b>", |
|
|
786 | on_changed => sub { my ($self, $value) = @_; $CFG->{force_opengl11} = $value; 0 } |
|
|
787 | ); |
|
|
788 | |
|
|
789 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Compress Textures"); |
|
|
790 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
|
|
791 | state => $CFG->{texture_compression}, |
|
|
792 | tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but " |
|
|
793 | . "will save a lot of memory and increase performance. The compression algorithm " |
|
|
794 | . "can differ form card to card, so your mileage may vary. This setting is ignored in " |
|
|
795 | . "forced OpenGL 1.1 mode.", |
|
|
796 | on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 } |
|
|
797 | ); |
|
|
798 | |
775 | $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"); |
776 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
800 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
777 | state => $CFG->{fast}, |
801 | state => $CFG->{fast}, |
778 | tooltip => "Lower the visual quality considerably to speed up rendering.", |
802 | tooltip => "Lower the visual quality considerably to speed up rendering.", |
779 | on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 } |
803 | on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 } |
… | |
… | |
805 | |
829 | |
806 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing"); |
830 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing"); |
807 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
831 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
808 | state => $CFG->{map_smoothing}, |
832 | state => $CFG->{map_smoothing}, |
809 | tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. " |
833 | tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. " |
810 | . "This increases load on the graphics subsystem and works only with 2.x servers. " |
834 | . "This increases load on the graphics subsystem and works only with TRT servers. " |
811 | . "Changes take effect at next connection only.", |
835 | . "Changes take effect at next login only.", |
812 | on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 } |
836 | on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 } |
813 | ); |
837 | ); |
814 | |
838 | |
815 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War"); |
839 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War"); |
816 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
840 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
… | |
… | |
827 | ); |
851 | ); |
828 | |
852 | |
829 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize"); |
853 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize"); |
830 | $table->add_at (1, $row++, new CFPlus::UI::Slider |
854 | $table->add_at (1, $row++, new CFPlus::UI::Slider |
831 | range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], |
855 | range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], |
832 | tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant.", |
856 | tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant, " |
|
|
857 | . "but you still need to press apply to correctly re-layout the widget.", |
833 | on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 }, |
858 | on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 }, |
834 | ); |
859 | ); |
835 | |
860 | |
836 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); |
861 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); |
837 | $table->add_at (1, $row++, new CFPlus::UI::Slider |
862 | $table->add_at (1, $row++, new CFPlus::UI::Slider |
… | |
… | |
898 | expand => 1, state => $CFG->{bgm_enable}, |
923 | expand => 1, state => $CFG->{bgm_enable}, |
899 | 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.", |
900 | on_changed => sub { |
925 | on_changed => sub { |
901 | $CFG->{bgm_enable} = $_[1]; |
926 | $CFG->{bgm_enable} = $_[1]; |
902 | $CONN->update_fx_want if $CONN; |
927 | $CONN->update_fx_want if $CONN; |
|
|
928 | audio_music_push; |
903 | 0 |
929 | 0 |
904 | } |
930 | } |
905 | ); |
931 | ); |
906 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
932 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
907 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], |
933 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], |
… | |
… | |
960 | $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"); |
961 | $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"); |
962 | $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"); |
963 | $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"); |
964 | |
990 | |
965 | $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); |
966 | $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"); |
967 | |
995 | |
968 | $GAUGES = { |
996 | $GAUGES = { |
|
|
997 | exp => $exp, prg => $prg, sklprg => $sklprg, |
969 | exp => $exp, win => $win, range => $rng, |
998 | win => $win, range => $rng, |
970 | food => $fg, mana => $mg, hp => $hg, grace => $gg |
999 | hp => $hg, mana => $mg, grace => $gg, food => $fg, |
971 | }; |
1000 | }; |
972 | |
1001 | |
973 | &set_gauge_window_fontsize; |
1002 | &set_gauge_window_fontsize; |
974 | |
1003 | |
975 | $win |
1004 | $win |
… | |
… | |
1176 | $r |
1205 | $r |
1177 | } |
1206 | } |
1178 | |
1207 | |
1179 | sub skill_window { |
1208 | sub skill_window { |
1180 | my $sw = new CFPlus::UI::ScrolledWindow (expand => 1); |
1209 | my $sw = new CFPlus::UI::ScrolledWindow (expand => 1); |
|
|
1210 | |
1181 | $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 | |
1182 | $sw |
1213 | $sw |
1183 | } |
1214 | } |
1184 | |
1215 | |
1185 | sub formsep($) { |
1216 | sub formsep($) { |
1186 | scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1 |
1217 | scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1 |
… | |
… | |
1598 | $sw1->add ($INV = new CFPlus::UI::Inventory); |
1629 | $sw1->add ($INV = new CFPlus::UI::Inventory); |
1599 | $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}}); |
1630 | $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}}); |
1600 | |
1631 | |
1601 | $hb->add (my $vb2 = new CFPlus::UI::VBox); |
1632 | $hb->add (my $vb2 = new CFPlus::UI::VBox); |
1602 | |
1633 | |
1603 | $vb2->add ($INV_RIGHT_HB = new CFPlus::UI::HBox); |
1634 | $vb2->add ($INVR_HB = new CFPlus::UI::HBox); |
1604 | |
1635 | |
1605 | $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); |
1636 | $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); |
1606 | $sw2->add ($INVR = new CFPlus::UI::Inventory); |
1637 | $sw2->add ($INVR = new CFPlus::UI::Inventory); |
1607 | |
1638 | |
1608 | # XXX: Call after $INVR = ... because set_opencont sets the items |
1639 | # XXX: Call after $INVR = ... because set_opencont sets the items |
… | |
… | |
1631 | } |
1662 | } |
1632 | |
1663 | |
1633 | sub add_license { |
1664 | sub add_license { |
1634 | my ($meta) = @_; |
1665 | my ($meta) = @_; |
1635 | |
1666 | |
1636 | $meta = $meta->{meta} |
1667 | $meta = $meta->{data} |
1637 | or return; |
1668 | or return; |
1638 | |
1669 | |
1639 | $meta->{license} || $meta->{author} || $meta->{source} |
1670 | $meta->{license} || $meta->{author} || $meta->{source} |
1640 | or return; |
1671 | or return; |
1641 | |
1672 | |
… | |
… | |
1695 | $ntb->add_tab ( |
1726 | $ntb->add_tab ( |
1696 | "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, |
1727 | "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, |
1697 | "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 :). " |
1698 | . "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." |
1699 | ); |
1730 | ); |
1700 | $ntb->add_tab (Pickup => autopickup_setup, |
1731 | $ntb->add_tab (Pickup => $PICKUP_PAGE = autopickup_setup, |
1701 | "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."); |
1702 | |
1733 | |
1703 | $ntb->add_tab (Media => media_window, |
1734 | $ntb->add_tab (Media => media_window, |
1704 | "License, Author and Source info for media sent by the server."); |
1735 | "License, Author and Source info for media sent by the server."); |
1705 | |
1736 | |
… | |
… | |
1863 | on_activate => sub { $QUIT_DIALOG->hide; 0 }, |
1894 | on_activate => sub { $QUIT_DIALOG->hide; 0 }, |
1864 | ); |
1895 | ); |
1865 | $hb->add (new CFPlus::UI::Button |
1896 | $hb->add (new CFPlus::UI::Button |
1866 | text => "Quit anyway", |
1897 | text => "Quit anyway", |
1867 | expand => 1, |
1898 | expand => 1, |
1868 | on_activate => sub { exit }, |
1899 | on_activate => sub { Event::unloop_all }, |
1869 | ); |
1900 | ); |
1870 | } |
1901 | } |
1871 | |
1902 | |
1872 | $QUIT_DIALOG->show; |
1903 | $QUIT_DIALOG->show; |
1873 | $QUIT_DIALOG->grab_focus; |
1904 | $QUIT_DIALOG->grab_focus; |
… | |
… | |
1946 | |
1977 | |
1947 | $SDL_ACTIVE = 1; |
1978 | $SDL_ACTIVE = 1; |
1948 | $LAST_REFRESH = time - 0.01; |
1979 | $LAST_REFRESH = time - 0.01; |
1949 | |
1980 | |
1950 | CFPlus::OpenGL::init; |
1981 | CFPlus::OpenGL::init; |
|
|
1982 | CFPlus::Macro::init; |
1951 | |
1983 | |
1952 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
1984 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
1953 | |
1985 | |
1954 | $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# |
1986 | $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# |
1955 | |
1987 | |
1956 | ############################################################################# |
1988 | ############################################################################# |
1957 | |
1989 | |
1958 | if ($DEBUG_STATUS) { |
1990 | if ($DEBUG_STATUS) { |
1959 | CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h; |
1991 | CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h; |
1960 | } else { |
1992 | } else { |
1961 | # 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 | }); |
1962 | |
2006 | |
1963 | $DEBUG_STATUS = new CFPlus::UI::Label |
2007 | $DEBUG_STATUS = new CFPlus::UI::Label |
1964 | padding => 0, |
2008 | padding => 0, |
1965 | z => 100, |
2009 | z => 100, |
1966 | force_x => "max", |
2010 | force_x => "max", |
… | |
… | |
1996 | $MESSAGE_WINDOW->activate_console ($preset) |
2040 | $MESSAGE_WINDOW->activate_console ($preset) |
1997 | if $MESSAGE_WINDOW; |
2041 | if $MESSAGE_WINDOW; |
1998 | }); |
2042 | }); |
1999 | $MAPWIDGET->show; |
2043 | $MAPWIDGET->show; |
2000 | $MAPWIDGET->grab_focus; |
2044 | $MAPWIDGET->grab_focus; |
|
|
2045 | |
|
|
2046 | $COMPLETER = new CFPlus::MapWidget::Command:: |
|
|
2047 | command => { }, |
|
|
2048 | tooltip => "#completer_help", |
|
|
2049 | ; |
2001 | |
2050 | |
2002 | $SETUP_DIALOG = new CFPlus::UI::Toplevel |
2051 | $SETUP_DIALOG = new CFPlus::UI::Toplevel |
2003 | title => "Setup", |
2052 | title => "Setup", |
2004 | name => "setup_dialog", |
2053 | name => "setup_dialog", |
2005 | x => 'center', |
2054 | x => 'center', |
… | |
… | |
2067 | tooltip => "Terminates the program", |
2116 | tooltip => "Terminates the program", |
2068 | on_activate => sub { |
2117 | on_activate => sub { |
2069 | if ($CONN) { |
2118 | if ($CONN) { |
2070 | open_quit_dialog; |
2119 | open_quit_dialog; |
2071 | } else { |
2120 | } else { |
2072 | exit; |
2121 | Event::unloop_all; |
2073 | } |
2122 | } |
2074 | 0 |
2123 | 0 |
2075 | }, |
2124 | }, |
2076 | ); |
2125 | ); |
2077 | |
2126 | |
2078 | $BUTTONBAR->show; |
2127 | $BUTTONBAR->show; |
2079 | $SETUP_DIALOG->show; |
2128 | $SETUP_DIALOG->show; |
|
|
2129 | $MESSAGE_WINDOW->show; |
2080 | } |
2130 | } |
2081 | |
2131 | |
2082 | $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); |
2132 | $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); |
2083 | } |
2133 | } |
2084 | |
2134 | |
… | |
… | |
2092 | my $animate_timer; |
2142 | my $animate_timer; |
2093 | |
2143 | |
2094 | my $fps = 9; |
2144 | my $fps = 9; |
2095 | |
2145 | |
2096 | sub force_refresh { |
2146 | sub force_refresh { |
|
|
2147 | if ($ENV{CFPLUS_DEBUG} & 4) { |
2097 | $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05; |
2148 | $fps = $fps * 0.98 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.02; |
2098 | debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4; |
2149 | debug sprintf "%3.2f", $fps; |
|
|
2150 | } |
2099 | |
2151 | |
2100 | $CFPlus::UI::ROOT->draw; |
2152 | $CFPlus::UI::ROOT->draw; |
2101 | |
2153 | CFPlus::SDL_GL_SwapBuffers; |
2102 | $WANT_REFRESH = 0; |
|
|
2103 | $CAN_REFRESH = 0; |
|
|
2104 | $LAST_REFRESH = $NOW; |
2154 | $LAST_REFRESH = $NOW; |
2105 | |
2155 | $WANT_REFRESH->stop; |
2106 | CFPlus::SDL_GL_SwapBuffers; |
|
|
2107 | } |
2156 | } |
2108 | |
2157 | |
|
|
2158 | $WANT_REFRESH = Event->idle (min => 0.001, max => 0.06, parked => 1, cb => \&force_refresh); |
|
|
2159 | |
2109 | my $refresh_watcher = Event->timer (after => 0, hard => 0, interval => 1 / $MAX_FPS, cb => sub { |
2160 | my $input = Event->timer (after => 0, hard => 0, interval => 1 / 50, cb => sub { |
2110 | $NOW = time; |
2161 | $NOW = time; |
2111 | |
2162 | |
2112 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
2163 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
2113 | for CFPlus::poll_events; |
2164 | for CFPlus::poll_events; |
2114 | |
2165 | |
2115 | if (%animate_object) { |
2166 | if (%animate_object) { |
2116 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
2167 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
2117 | ++$WANT_REFRESH; |
2168 | $WANT_REFRESH->start; |
2118 | } |
|
|
2119 | |
|
|
2120 | if ($WANT_REFRESH) { |
|
|
2121 | force_refresh; |
|
|
2122 | } else { |
|
|
2123 | $CAN_REFRESH = 1; |
|
|
2124 | } |
2169 | } |
2125 | }); |
2170 | }); |
2126 | |
2171 | |
2127 | sub animation_start { |
2172 | sub animation_start { |
2128 | my ($widget) = @_; |
2173 | my ($widget) = @_; |
… | |
… | |
2134 | delete $animate_object{$widget}; |
2179 | delete $animate_object{$widget}; |
2135 | } |
2180 | } |
2136 | |
2181 | |
2137 | %SDL_CB = ( |
2182 | %SDL_CB = ( |
2138 | CFPlus::SDL_QUIT => sub { |
2183 | CFPlus::SDL_QUIT => sub { |
2139 | exit; |
2184 | Event::unloop_all; |
2140 | }, |
2185 | }, |
2141 | CFPlus::SDL_VIDEORESIZE => sub { |
2186 | CFPlus::SDL_VIDEORESIZE => sub { |
2142 | }, |
2187 | }, |
2143 | CFPlus::SDL_VIDEOEXPOSE => sub { |
2188 | CFPlus::SDL_VIDEOEXPOSE => sub { |
2144 | CFPlus::UI::full_refresh; |
2189 | CFPlus::UI::full_refresh; |
… | |
… | |
2183 | CFPlus::DB::Server::run; |
2228 | CFPlus::DB::Server::run; |
2184 | |
2229 | |
2185 | CFPlus::UI::set_layout ($::CFG->{layout}); |
2230 | CFPlus::UI::set_layout ($::CFG->{layout}); |
2186 | |
2231 | |
2187 | my %DEF_CFG = ( |
2232 | my %DEF_CFG = ( |
2188 | sdl_mode => 0, |
2233 | sdl_mode => 0, |
2189 | fullscreen => 0, |
2234 | fullscreen => 0, |
2190 | fast => 0, |
2235 | fast => 0, |
|
|
2236 | force_opengl11 => undef, |
|
|
2237 | texture_compression => 1, |
2191 | map_scale => 1, |
2238 | map_scale => 1, |
2192 | fow_enable => 1, |
2239 | fow_enable => 1, |
2193 | fow_intensity => 0, |
2240 | fow_intensity => 0, |
2194 | map_smoothing => 1, |
2241 | map_smoothing => 1, |
2195 | gui_fontsize => 1, |
2242 | gui_fontsize => 1, |
2196 | log_fontsize => 0.7, |
2243 | log_fontsize => 0.7, |
2197 | gauge_fontsize => 1, |
2244 | gauge_fontsize => 1, |
2198 | gauge_size => 0.35, |
2245 | gauge_size => 0.35, |
2199 | stat_fontsize => 0.7, |
2246 | stat_fontsize => 0.7, |
2200 | mapsize => 100, |
2247 | mapsize => 100, |
2201 | audio_enable => 1, |
2248 | audio_enable => 1, |
2202 | effects_enable => 1, |
2249 | effects_enable => 1, |
2203 | effects_volume => 1, |
2250 | effects_volume => 1, |
2204 | bgm_enable => 1, |
2251 | bgm_enable => 1, |
2205 | bgm_volume => 0.5, |
2252 | bgm_volume => 0.5, |
2206 | output_sync => 1, |
2253 | output_sync => 1, |
2207 | output_count => 1, |
2254 | output_count => 1, |
2208 | output_rate => "", |
2255 | output_rate => "", |
2209 | pickup => 0, |
2256 | pickup => 0, |
2210 | inv_sort => "mtime", |
2257 | inv_sort => "mtime", |
2211 | default => "profile", # default profile |
2258 | default => "profile", # default profile |
2212 | show_tips => 1, |
2259 | show_tips => 1, |
2213 | logview_max_par => 1000, |
2260 | logview_max_par => 1000, |
2214 | ); |
2261 | ); |
2215 | |
2262 | |
2216 | while (my ($k, $v) = each %DEF_CFG) { |
2263 | while (my ($k, $v) = each %DEF_CFG) { |
2217 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
2264 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
2218 | } |
2265 | } |
… | |
… | |
2275 | # } |
2322 | # } |
2276 | # my $t2 = Time::HiRes::time; |
2323 | # my $t2 = Time::HiRes::time; |
2277 | # warn $t2-$t1; |
2324 | # warn $t2-$t1; |
2278 | # } |
2325 | # } |
2279 | |
2326 | |
2280 | $startup_done->(); |
|
|
2281 | |
|
|
2282 | video_init; |
2327 | video_init; |
2283 | audio_init; |
2328 | audio_init; |
2284 | } |
2329 | } |
2285 | |
2330 | |
2286 | show_tip_of_the_day if $CFG->{show_tips}; |
2331 | show_tip_of_the_day if $CFG->{show_tips}; |
2287 | |
2332 | |
|
|
2333 | Event->idle (cb => sub { |
|
|
2334 | $_[0]->w->cancel; |
|
|
2335 | $startup_done->(); |
|
|
2336 | }); |
|
|
2337 | |
2288 | Event::loop; |
2338 | Event::loop; |
|
|
2339 | |
|
|
2340 | #video_shutdown; |
|
|
2341 | #audio_shutdown; |
2289 | #CFPlus::SDL_Quit; |
2342 | CFPlus::SDL_Quit; |
2290 | #CFPlus::_exit 0; |
|
|
2291 | |
|
|
2292 | END { |
|
|
2293 | video_shutdown; |
|
|
2294 | audio_shutdown; |
|
|
2295 | CFPlus::SDL_Quit; |
|
|
2296 | CFPlus::DB::Server::stop; |
2343 | CFPlus::DB::Server::stop; |
2297 | } |
|
|
2298 | |
2344 | |
2299 | =head1 NAME |
2345 | =head1 NAME |
2300 | |
2346 | |
2301 | cfplus - A Crossfire TRT and Crossfire game client |
2347 | cfplus - A Crossfire TRT and Crossfire game client |
2302 | |
2348 | |