ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pclient
(Generate patch)

Comparing deliantra/Deliantra-Client/bin/pclient (file contents):
Revision 1.197 by root, Fri May 5 19:05:47 2006 UTC vs.
Revision 1.208 by root, Thu May 11 23:41:47 2006 UTC

37use CFClient; 37use CFClient;
38use CFClient::UI; 38use CFClient::UI;
39use CFClient::MapWidget; 39use CFClient::MapWidget;
40 40
41$Event::DIED = sub { 41$Event::DIED = sub {
42 # TODO: display dialog box or so
42 CFClient::error $_[1]; 43 CFClient::error $_[1];
43}; 44};
44 45
45#$SIG{__WARN__} = sub { Carp::cluck $_[0] };#d# 46#$SIG{__WARN__} = sub { Carp::cluck $_[0] };#d#
46 47
59our $NOW; 60our $NOW;
60 61
61our $CFG; 62our $CFG;
62our $CONN; 63our $CONN;
63our $FAST; # fast, low-quality mode, possibly useful for software-rendering 64our $FAST; # fast, low-quality mode, possibly useful for software-rendering
65
66our $WANT_REFRESH;
67our $CAN_REFRESH;
64 68
65our @SDL_MODES; 69our @SDL_MODES;
66our $WIDTH; 70our $WIDTH;
67our $HEIGHT; 71our $HEIGHT;
68our $FULLSCREEN; 72our $FULLSCREEN;
76our $MAPWIDGET; 80our $MAPWIDGET;
77our $BUTTONBAR; 81our $BUTTONBAR;
78our $LOGVIEW; 82our $LOGVIEW;
79our $CONSOLE; 83our $CONSOLE;
80our $METASERVER; 84our $METASERVER;
85our $LOGIN_BUTTON;
81 86
82our $FLOORBOX; 87our $FLOORBOX;
83our $GAUGES; 88our $GAUGES;
84our $STATWIDS; 89our $STATWIDS;
85 90
96 101
97our $INVWIN; 102our $INVWIN;
98our $INV; 103our $INV;
99 104
100sub status { 105sub status {
101 $STATUS_LINE->set_text ($_[0]); 106 $STATUS_LINE->add ($_[0], group => "status", timeout => 60);
102 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h}); 107 $CFClient::UI::ROOT->on_refresh ($STATUS_LINE => sub {
108 $STATUS_LINE->move (0, $HEIGHT - $STATUS_LINE->{h});#d# to in toplevel
109 });
103} 110}
104 111
105sub debug { 112sub debug {
106 $DEBUG_STATUS->set_text ($_[0]); 113 $DEBUG_STATUS->set_text ($_[0]);
107 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h}); 114 my ($w, $h) = $DEBUG_STATUS->size_request;
115 $DEBUG_STATUS->move ($WIDTH - $w, 0);
108} 116}
109 117
110sub start_game { 118sub start_game {
111 status "logging in..."; 119 status "logging in...";
112 120
113 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 121 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
114 122
115 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}"; 123 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}";
116
117 $MAP = new CFClient::Map $mapsize, $mapsize; 124 $MAP = new CFClient::Map $mapsize, $mapsize;
118 125
119 my ($host, $port) = split /:/, $CFG->{host}; 126 my ($host, $port) = split /:/, $CFG->{host};
120 127
121 $CONN = eval { 128 $CONN = eval {
128 maph => $mapsize, 135 maph => $mapsize,
129 ; 136 ;
130 }; 137 };
131 138
132 if ($CONN) { 139 if ($CONN) {
140 $LOGIN_BUTTON->set_text ("Logout");
141
133 status "login successful"; 142 status "login successful";
134 143
135 CFClient::lowdelay fileno $CONN->{fh}; 144 CFClient::lowdelay fileno $CONN->{fh};
136 } else { 145 } else {
137 status "unable to connect"; 146 status "unable to connect";
147 stop_game();
138 } 148 }
139} 149}
140 150
141sub stop_game { 151sub stop_game {
152 return unless $CONN;
153
154 status "connection closed";
155 $LOGIN_BUTTON->set_text ("Login");
156 $CONN->destroy;
157 $CONN = 0; # false, does not autovivify
158
159 undef $MAPCACHE;
142 undef $CONN; 160 undef $MAP;
143} 161}
144 162
145sub client_setup { 163sub client_setup {
146 my $dialog = new CFClient::UI::FancyFrame 164 my $dialog = new CFClient::UI::FancyFrame
147 title => "Client Setup", 165 title => "Client Setup",
571 589
572} 590}
573 591
574sub metaserver_dialog { 592sub metaserver_dialog {
575 my $dialog = new CFClient::UI::FancyFrame 593 my $dialog = new CFClient::UI::FancyFrame
576 title => "Metaserver", 594 title => "Server List",
577 child => (my $vbox = new CFClient::UI::VBox); 595 child => (my $vbox = new CFClient::UI::VBox);
578 596
579 $vbox->add ($dialog->{table} = new CFClient::UI::Table); 597 $vbox->add ($dialog->{table} = new CFClient::UI::Table);
580 598
581 $dialog 599 $dialog
683 701
684 $METASERVER = metaserver_dialog; 702 $METASERVER = metaserver_dialog;
685 703
686 $vbox->add (new CFClient::UI::Flopper 704 $vbox->add (new CFClient::UI::Flopper
687 expand => 1, 705 expand => 1,
688 text => "Metaserver", 706 text => "Server List",
689 other => $METASERVER, 707 other => $METASERVER,
690 tooltip => "Show a list of avaible crossfire servers", 708 tooltip => "Show a list of available crossfire servers",
691 connect_open => sub { 709 connect_open => sub {
692 update_metaserver $HOST; 710 update_metaserver $HOST;
693 } 711 }
694 ); 712 );
695 } 713 }
726 744
727 $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 745 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
728 }, 746 },
729 ); 747 );
730 748
731 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { 749 $table->add (1, 8, $LOGIN_BUTTON = new CFClient::UI::Button
750 expand => 1,
751 align => 0,
752 text => "Login",
753 connect_activate => sub {
754 $CONN ? stop_game
732 start_game; 755 : start_game;
756 },
733 }); 757 );
734 758
735 $dialog 759 $dialog
736} 760}
737 761
738sub message_window { 762sub message_window {
811 835
812 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN 836 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
813 or die "SDL_SetVideoMode failed!\n"; 837 or die "SDL_SetVideoMode failed!\n";
814 838
815 $SDL_ACTIVE = 1; 839 $SDL_ACTIVE = 1;
816
817 $LAST_REFRESH = time - 0.01; 840 $LAST_REFRESH = time - 0.01;
818 841
819 CFClient::gl_init; 842 CFClient::gl_init;
820 843
821 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; 844 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
822 845
846 $CFClient::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d#
847
823 ############################################################################# 848 #############################################################################
824 849
850 if ($DEBUG_STATUS) {
851 # reconfigure all widgets
852 $CFClient::UI::ROOT->reconfigure;
853
854 } else {
855 # create the widgets
856
825 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 857 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100, text => "hulla", x => 100;#d#
826 $DEBUG_STATUS->show; 858 $DEBUG_STATUS->show;
827 859
828 $STATUS_LINE = new CFClient::UI::Label 860 $STATUS_LINE = new CFClient::UI::Statusbox;
829 padding => 0, 861 $STATUS_LINE->add ("Use <b>Alt-Enter</b> to toggle fullscreen mode", pri => 0, size => 0.8, color => [1, 1, 1]);
830 y => $HEIGHT - $FONTSIZE * 1.8;
831 $STATUS_LINE->show; 862 $STATUS_LINE->show;
832 863
833 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
834 padding => 0,
835 fontsize => 0.8,
836 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
837 $ALT_ENTER_MESSAGE->show;
838 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
839
840 CFClient::UI::FancyFrame->new ( 864 CFClient::UI::FancyFrame->new (
841 border_bg => [1, 1, 1, 192/255], 865 border_bg => [1, 1, 1, 192/255],
842 bg => [1, 1, 1, 0], 866 bg => [1, 1, 1, 0],
843 child => ($MAPMAP = new CFClient::MapWidget::MapMap), 867 child => ($MAPMAP = new CFClient::MapWidget::MapMap),
844 )->show; 868 )->show;
845 869
846 $MAPWIDGET = new CFClient::MapWidget; 870 $MAPWIDGET = new CFClient::MapWidget;
847 $MAPWIDGET->connect (activate_console => sub { 871 $MAPWIDGET->connect (activate_console => sub {
848 my ($mapwidget, $preset) = @_; 872 my ($mapwidget, $preset) = @_;
849 873
850 if ($CONSOLE) { 874 if ($CONSOLE) {
851 $CONSOLE->{input}->{auto_activated} = 1; 875 $CONSOLE->{input}->{auto_activated} = 1;
852 $CONSOLE->{input}->focus_in; 876 $CONSOLE->{input}->focus_in;
853 877
854 if ($preset && $CONSOLE->{input}->get_text eq '') { 878 if ($preset && $CONSOLE->{input}->get_text eq '') {
855 $CONSOLE->{input}->set_text ($preset); 879 $CONSOLE->{input}->set_text ($preset);
880 }
856 } 881 }
857 } 882 });
858 });
859 $MAPWIDGET->show; 883 $MAPWIDGET->show;
860 $MAPWIDGET->focus_in; 884 $MAPWIDGET->focus_in;
861 885
862 $BUTTONBAR = new CFClient::UI::HBox; 886 $BUTTONBAR = new CFClient::UI::HBox;
863 887
864 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup); 888 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup);
865 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup); 889 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup);
866 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window); 890 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window);
867 891
868 make_gauge_window->show; # XXX: this has to be set before make_stats_window as make_stats_window calls update_stats_window which updated the gauges also X-D 892 make_gauge_window->show; # XXX: this has to be set before make_stats_window as make_stats_window calls update_stats_window which updated the gauges also X-D
869 893
870 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window); 894 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window);
871 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Inventory", other => make_inventory_window); 895 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Inventory", other => make_inventory_window);
872 896
873 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { 897 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub {
874 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 898 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
875 status "Configuration Saved"; 899 status "Configuration Saved";
876 }); 900 });
877 901
878 $BUTTONBAR->show; 902 $BUTTONBAR->show;
879 903
904 # delay till geometry is constant
905 $CFClient::UI::ROOT->on_refresh (startup => sub {
880 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 906 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
907 });
908 force_refresh ();
909 }
881} 910}
882 911
883sub video_shutdown { 912sub video_shutdown {
884 $CFClient::UI::ROOT->{children} = [];
885 undef $CFClient::UI::GRAB;
886 undef $CFClient::UI::HOVER;
887 undef $SDL_ACTIVE; 913 undef $SDL_ACTIVE;
888} 914}
889 915
890my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# 916my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d#
891my $bgmusic;#TODO#hack#d# 917my $bgmusic;#TODO#hack#d#
918
919sub audio_channel_finished {
920 my ($channel) = @_;
921
922 warn "channel $channel finished\n";#d#
923}
892 924
893sub audio_music_finished { 925sub audio_music_finished {
894 return unless $CFG->{bgm_enable}; 926 return unless $CFG->{bgm_enable};
895 927
896 # TODO: hack, do play loop and mood music 928 # TODO: hack, do play loop and mood music
937} 969}
938 970
939my %animate_object; 971my %animate_object;
940my $animate_timer; 972my $animate_timer;
941 973
942my $want_refresh;
943my $can_refresh;
944
945my $fps = 9; 974my $fps = 9;
946 975
947sub force_refresh { 976sub force_refresh {
948 $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05; 977 $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05;
949 debug sprintf "%3.2f", $fps; 978 debug sprintf "%3.2f", $fps;
950 979
951 $want_refresh = 0;
952 $can_refresh = 0;
953
954 $CFClient::UI::ROOT->draw; 980 $CFClient::UI::ROOT->draw;
955
956 CFClient::SDL_GL_SwapBuffers; 981 CFClient::SDL_GL_SwapBuffers;
957 982
983 $WANT_REFRESH = 0;
984 $CAN_REFRESH = 0;
958 $LAST_REFRESH = $NOW; 985 $LAST_REFRESH = $NOW;
959} 986}
960 987
961my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { 988my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub {
962 $NOW = time; 989 $NOW = time;
964 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) 991 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
965 for CFClient::SDL_PollEvent; 992 for CFClient::SDL_PollEvent;
966 993
967 if (%animate_object) { 994 if (%animate_object) {
968 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 995 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
969 $want_refresh++; 996 $WANT_REFRESH++;
970 } 997 }
971 998
972 if ($want_refresh) { 999 if ($WANT_REFRESH) {
973 force_refresh; 1000 force_refresh;
974 } else { 1001 } else {
975 $can_refresh = 1; 1002 $CAN_REFRESH = 1;
976 } 1003 }
977}); 1004});
978
979sub refresh {
980 $want_refresh++;
981}
982 1005
983sub animation_start { 1006sub animation_start {
984 my ($widget) = @_; 1007 my ($widget) = @_;
985 $animate_object{$widget} = $widget; 1008 $animate_object{$widget} = $widget;
986} 1009}
1298 [0.55, 0.41, 0.13], 1321 [0.55, 0.41, 0.13],
1299 [0.99, 0.77, 0.26], 1322 [0.99, 0.77, 0.26],
1300 [0.74, 0.65, 0.41], 1323 [0.74, 0.65, 0.41],
1301 ); 1324 );
1302 1325
1326 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
1327
1303 $LOGVIEW->add_paragraph ($color[$color], $text); 1328 $LOGVIEW->add_paragraph ($color[$color],
1329 join "\n", map "$time $_", split /\n/, $text);
1330
1331 $text =~ s/&/&amp;/g; $text =~ s/</&lt;/g;
1332 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
1333 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
1334 $STATUS_LINE->add ($text, color => $color[$color], timeout => 60);
1335}
1336
1337sub conn::drawextinfo {
1338 my ($self, $color, $type, $subtype, $message) = @_;
1339
1340 $self->drawinfo ($color, $message);
1304} 1341}
1305 1342
1306sub conn::spell_add { 1343sub conn::spell_add {
1307 my ($self, $spell) = @_; 1344 my ($self, $spell) = @_;
1308 1345
1321 1358
1322 for my $skill (values %{$self->{skill_info}}) { 1359 for my $skill (values %{$self->{skill_info}}) {
1323 $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'"); 1360 $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'");
1324 $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'"); 1361 $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'");
1325 } 1362 }
1363
1364 $MAPWIDGET->add_command ("pet\\_mode defend", "Tell pets to stay close to you and defend you");
1365 $MAPWIDGET->add_command ("pet\\_mode arena", "Same as petmode attack, but also attack other players");
1366 $MAPWIDGET->add_command ("pet\\_mode sad", "Search &amp; Destroy - tell pets to roam about and attack enemies");
1367 $MAPWIDGET->add_command ("kill\\_pets", "kill your pets");
1368}
1369
1370sub conn::eof {
1371 stop_game;
1326} 1372}
1327 1373
1328sub update_floorbox { 1374sub update_floorbox {
1329 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { 1375 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub {
1376 return unless $CONN;
1377
1330 $FLOORBOX->clear; 1378 $FLOORBOX->clear;
1331 $FLOORBOX->add (new CFClient::UI::Empty expand => 1); 1379 $FLOORBOX->add (new CFClient::UI::Empty expand => 1);
1332 1380
1333 # we basically have to use the same sorting as everybody else 1381 my $count = 4;
1334 for my $item (@{ $CONN->{container}{0} }) { 1382 for (@{ $CONN->{container}{0} }) {
1383 if (--$count) {
1335 $FLOORBOX->add (new CFClient::UI::InventoryItem item => $item); 1384 $FLOORBOX->add (new CFClient::UI::InventoryItem item => $_);
1385 } else {
1386 $FLOORBOX->add (new CFClient::UI::Label text => "More...");
1387 last;
1388 }
1336 } 1389 }
1337 }); 1390 });
1338 refresh; 1391
1392 $WANT_REFRESH++;
1339} 1393}
1340 1394
1341sub conn::container_add { 1395sub conn::container_add {
1342 my ($self, $id, $items) = @_; 1396 my ($self, $tag, $items) = @_;
1343 1397
1344 update_floorbox if $id == 0; 1398 update_floorbox if $tag == 0;
1345 if ($self->{player}{tag} == $id) { 1399
1346 $INV->set_items ($self->{container}{$self->{player}{tag}}); 1400 $INV->set_items ($self->{container}{$self->{player}{tag}})
1347 } 1401 if $tag == $self->{player}{tag};
1402
1348 # $self-<{player}{tag} => player inv 1403 # $self-<{player}{tag} => player inv
1349 #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; 1404 #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}};
1350} 1405}
1351 1406
1352sub conn::container_clear { 1407sub conn::container_clear {
1353 my ($self, $id) = @_; 1408 my ($self, $tag) = @_;
1354 1409
1355 update_floorbox if $id == 0; 1410 update_floorbox if $tag == 0;
1356 if ($self->{player}{tag} == $id) { 1411
1357 $INV->set_items ($self->{container}{$id}); 1412 $INV->set_items ($self->{container}{$tag})
1358 } 1413 if $tag == $self->{player}{tag};
1359 1414
1360# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; 1415# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0};
1361} 1416}
1362 1417
1363sub conn::item_delete { 1418sub conn::item_delete {
1364 my ($self, @items) = @_; 1419 my ($self, @items) = @_;
1365 1420
1366 for (@items) { 1421 for (@items) {
1367 update_floorbox if $_->{container} == 0; 1422 update_floorbox if $_->{container} == 0;
1368 if ($self->{player}{tag} == $_->{container}) { 1423
1369 $INV->set_items ($self->{container}{$_->{container}}); 1424 $INV->set_items ($self->{container}{$_->{container}})
1370 } 1425 if $_->{container} == $self->{player}{tag};
1371 } 1426 }
1372} 1427}
1373 1428
1374sub conn::item_update { 1429sub conn::item_update {
1375 my ($self, $item) = @_; 1430 my ($self, $item) = @_;
1376 1431
1377 update_floorbox if $item->{container} == 0; 1432 update_floorbox if $item->{container} == 0;
1378 if ($self->{player}{tag} == $item->{container}) { 1433
1379 $INV->set_items ($self->{container}{$item->{container}}); 1434 $INV->set_items ($self->{container}{$item->{container}})
1380 } 1435 if $item->{container} == $self->{player}{tag};
1381} 1436}
1382 1437
1383%SDL_CB = ( 1438%SDL_CB = (
1384 CFClient::SDL_QUIT => sub { 1439 CFClient::SDL_QUIT => sub {
1385 Event::unloop -1; 1440 Event::unloop -1;
1386 }, 1441 },
1387 CFClient::SDL_VIDEORESIZE => sub { 1442 CFClient::SDL_VIDEORESIZE => sub {
1388 }, 1443 },
1389 CFClient::SDL_VIDEOEXPOSE => \&refresh, 1444 CFClient::SDL_VIDEOEXPOSE => sub {
1445 $WANT_REFRESH++;
1446 },
1390 CFClient::SDL_ACTIVEEVENT => sub { 1447 CFClient::SDL_ACTIVEEVENT => sub {
1391# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# 1448# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
1392 }, 1449 },
1393 CFClient::SDL_KEYDOWN => sub { 1450 CFClient::SDL_KEYDOWN => sub {
1394 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { 1451 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
1398 video_init; 1455 video_init;
1399 } else { 1456 } else {
1400 CFClient::UI::feed_sdl_key_down_event ($_[0]); 1457 CFClient::UI::feed_sdl_key_down_event ($_[0]);
1401 } 1458 }
1402 }, 1459 },
1403 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, 1460 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
1404 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, 1461 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
1405 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, 1462 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
1406 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, 1463 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
1407 CFClient::SDL_USEREVENT => \&audio_music_finished, 1464 CFClient::SDL_USEREVENT => sub {
1465 if ($_[0]{code} == 1) {
1466 audio_channel_finished $_[0]{data1};
1467 } elsif ($_[0]{code} == 0) {
1468 audio_music_finished;
1469 }
1470 },
1408); 1471);
1409 1472
1410############################################################################# 1473#############################################################################
1411 1474
1412$SIG{INT} = $SIG{TERM} = sub { exit }; 1475$SIG{INT} = $SIG{TERM} = sub { exit };
1413 1476
1414CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1415
1416$TILECACHE = CFClient::db_table "tilecache";
1417$FACEMAP = CFClient::db_table "facemap";
1418
1419my %DEF_CFG = (
1420 sdl_mode => 0,
1421 width => 640,
1422 height => 480,
1423 fullscreen => 0,
1424 fast => 0,
1425 map_scale => 0.5,
1426 fow_enable => 1,
1427 fow_intensity => 0.45,
1428 fow_smooth => 0,
1429 gui_fontsize => 1,
1430 log_fontsize => 1,
1431 gauge_fontsize => 1,
1432 gauge_size => 0.35,
1433 stat_fontsize => 1,
1434 mapsize => 100,
1435 host => "crossfire.schmorp.de",
1436 say_command => 'say',
1437 audio_enable => 1,
1438 bgm_enable => 1,
1439 bgm_volume => 0.25,
1440);
1441
1442while (my ($k, $v) = each %DEF_CFG) {
1443 $CFG->{$k} = $v unless exists $CFG->{$k};
1444}
1445
1446sdl_init;
1447
1448@SDL_MODES = reverse
1449 grep $_->[0] >= 640 && $_->[1] >= 480,
1450 CFClient::SDL_ListModes;
1451
1452@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
1453
1454$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
1455
1456{ 1477{
1478 local $SIG{__DIE__} = sub { CFClient::fatal $_[0] };
1479
1480 CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1481
1482 $TILECACHE = CFClient::db_table "tilecache";
1483 $FACEMAP = CFClient::db_table "facemap";
1484
1485 my %DEF_CFG = (
1486 sdl_mode => 0,
1487 width => 640,
1488 height => 480,
1489 fullscreen => 0,
1490 fast => 0,
1491 map_scale => 0.5,
1492 fow_enable => 1,
1493 fow_intensity => 0.45,
1494 fow_smooth => 0,
1495 gui_fontsize => 1,
1496 log_fontsize => 1,
1497 gauge_fontsize=> 1,
1498 gauge_size => 0.35,
1499 stat_fontsize => 1,
1500 mapsize => 100,
1501 host => "crossfire.schmorp.de",
1502 say_command => 'say',
1503 audio_enable => 1,
1504 bgm_enable => 1,
1505 bgm_volume => 0.25,
1506 );
1507
1508 while (my ($k, $v) = each %DEF_CFG) {
1509 $CFG->{$k} = $v unless exists $CFG->{$k};
1510 }
1511
1512 sdl_init;
1513
1514 @SDL_MODES = reverse
1515 grep $_->[0] >= 640 && $_->[1] >= 480,
1516 CFClient::SDL_ListModes;
1517
1518 @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
1519
1520 $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
1521
1522 {
1457 my @fonts = map CFClient::find_rcfile "fonts/$_", qw( 1523 my @fonts = map CFClient::find_rcfile "fonts/$_", qw(
1458 DejaVuSans.ttf 1524 DejaVuSans.ttf
1459 DejaVuSansMono.ttf 1525 DejaVuSansMono.ttf
1460 DejaVuSans-Bold.ttf 1526 DejaVuSans-Bold.ttf
1461 DejaVuSansMono-Bold.ttf 1527 DejaVuSansMono-Bold.ttf
1462 DejaVuSans-Oblique.ttf 1528 DejaVuSans-Oblique.ttf
1463 DejaVuSansMono-Oblique.ttf 1529 DejaVuSansMono-Oblique.ttf
1464 DejaVuSans-BoldOblique.ttf 1530 DejaVuSans-BoldOblique.ttf
1465 DejaVuSansMono-BoldOblique.ttf 1531 DejaVuSansMono-BoldOblique.ttf
1466 ); 1532 );
1467 1533
1468 CFClient::add_font $_ for @fonts; 1534 CFClient::add_font $_ for @fonts;
1469 1535
1470 $FONT_PROP = new_from_file CFClient::Font $fonts[0]; 1536 $FONT_PROP = new_from_file CFClient::Font $fonts[0];
1471 $FONT_FIXED = new_from_file CFClient::Font $fonts[1]; 1537 $FONT_FIXED = new_from_file CFClient::Font $fonts[1];
1472 1538
1473 $FONT_PROP->make_default; 1539 $FONT_PROP->make_default;
1474} 1540 }
1475 1541
1476video_init; 1542 video_init;
1477audio_init; 1543 audio_init;
1544}
1478 1545
1479Event::loop; 1546Event::loop;
1480 1547
1481END { CFClient::SDL_Quit } 1548END { CFClient::SDL_Quit }
1482 1549

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines