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.195 by root, Sun Apr 30 11:17:09 2006 UTC vs.
Revision 1.206 by root, Tue May 9 22:27:55 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines