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.194 by root, Sun Apr 30 09:21:48 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 {
789 $window 810 $window
790} 811}
791 812
792sub make_inventory_window { 813sub make_inventory_window {
793 my $invwin = new CFClient::UI::FancyFrame user_w => 300, user_h => 300, title => "Inventory"; 814 my $invwin = new CFClient::UI::FancyFrame user_w => 300, user_h => 300, title => "Inventory";
794 $invwin->add (my $hb = new CFClient::UI::HBox);
795 $hb->add ($INV = new CFClient::UI::Inventory expand => 1); 815 $invwin->add ($INV = new CFClient::UI::Inventory expand => 1);
796 $hb->add (my $rng = new CFClient::UI::Slider vertical => 1);
797 $INV->set_range ($rng);
798 $invwin 816 $invwin
799} 817}
800 818
801sub sdl_init { 819sub sdl_init {
802 CFClient::SDL_Init 820 CFClient::SDL_Init
804} 822}
805 823
806sub video_init { 824sub video_init {
807 sdl_init; 825 sdl_init;
808 826
827 $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} >= @SDL_MODES;
828
809 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 829 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
810 $FULLSCREEN = $CFG->{fullscreen}; 830 $FULLSCREEN = $CFG->{fullscreen};
811 $FAST = $CFG->{fast}; 831 $FAST = $CFG->{fast};
812 832
813 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN 833 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
814 or die "SDL_SetVideoMode failed!\n"; 834 or die "SDL_SetVideoMode failed!\n";
815 835
816 $SDL_ACTIVE = 1; 836 $SDL_ACTIVE = 1;
817
818 $LAST_REFRESH = time - 0.01; 837 $LAST_REFRESH = time - 0.01;
819 838
820 CFClient::gl_init; 839 CFClient::gl_init;
821 840
822 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; 841 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
823 842
843 $CFClient::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d#
844
824 ############################################################################# 845 #############################################################################
825 846
847 if ($DEBUG_STATUS) {
848 # reconfigure all widgets
849 $CFClient::UI::ROOT->reconfigure;
850
851 } else {
852 # create the widgets
853
826 $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#
827 $DEBUG_STATUS->show; 855 $DEBUG_STATUS->show;
828 856
829 $STATUS_LINE = new CFClient::UI::Label 857 $STATUS_LINE = new CFClient::UI::Label
830 padding => 0, 858 padding => 0,
831 y => $HEIGHT - $FONTSIZE * 1.8; 859 y => $HEIGHT - $FONTSIZE * 1.8;
832 $STATUS_LINE->show; 860 $STATUS_LINE->show;
833 861
834 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 862 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
835 padding => 0, 863 padding => 0,
836 fontsize => 0.8, 864 fontsize => 0.8,
837 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 865 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
838 $ALT_ENTER_MESSAGE->show; 866 $ALT_ENTER_MESSAGE->show;
839 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); 867 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
840 868
841 CFClient::UI::FancyFrame->new ( 869 CFClient::UI::FancyFrame->new (
842 border_bg => [1, 1, 1, 192/255], 870 border_bg => [1, 1, 1, 192/255],
843 bg => [1, 1, 1, 0], 871 bg => [1, 1, 1, 0],
844 child => ($MAPMAP = new CFClient::MapWidget::MapMap), 872 child => ($MAPMAP = new CFClient::MapWidget::MapMap),
845 )->show; 873 )->show;
846 874
847 $MAPWIDGET = new CFClient::MapWidget; 875 $MAPWIDGET = new CFClient::MapWidget;
848 $MAPWIDGET->connect (activate_console => sub { 876 $MAPWIDGET->connect (activate_console => sub {
849 my ($mapwidget, $preset) = @_; 877 my ($mapwidget, $preset) = @_;
850 878
851 if ($CONSOLE) { 879 if ($CONSOLE) {
852 $CONSOLE->{input}->{auto_activated} = 1; 880 $CONSOLE->{input}->{auto_activated} = 1;
853 $CONSOLE->{input}->focus_in; 881 $CONSOLE->{input}->focus_in;
854 882
855 if ($preset && $CONSOLE->{input}->get_text eq '') { 883 if ($preset && $CONSOLE->{input}->get_text eq '') {
856 $CONSOLE->{input}->set_text ($preset); 884 $CONSOLE->{input}->set_text ($preset);
885 }
857 } 886 }
858 } 887 });
859 });
860 $MAPWIDGET->show; 888 $MAPWIDGET->show;
861 $MAPWIDGET->focus_in; 889 $MAPWIDGET->focus_in;
862 890
863 $BUTTONBAR = new CFClient::UI::HBox; 891 $BUTTONBAR = new CFClient::UI::HBox;
864 892
865 $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);
866 $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);
867 $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);
868 896
869 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
870 898
871 $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);
872 $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);
873 901
874 $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 {
875 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 903 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
876 status "Configuration Saved"; 904 status "Configuration Saved";
877 }); 905 });
878 906
879 $BUTTONBAR->show; 907 $BUTTONBAR->show;
880 908
909 # delay till geometry is constant
910 $CFClient::UI::ROOT->on_refresh (startup => sub {
881 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 911 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
912 });
913 force_refresh ();
914 }
882} 915}
883 916
884sub video_shutdown { 917sub video_shutdown {
885 $CFClient::UI::ROOT->{children} = [];
886 undef $CFClient::UI::GRAB;
887 undef $CFClient::UI::HOVER;
888 undef $SDL_ACTIVE; 918 undef $SDL_ACTIVE;
889} 919}
890 920
891my @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#
892my $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}
893 929
894sub audio_music_finished { 930sub audio_music_finished {
895 return unless $CFG->{bgm_enable}; 931 return unless $CFG->{bgm_enable};
896 932
897 # TODO: hack, do play loop and mood music 933 # TODO: hack, do play loop and mood music
901 push @bgmusic, shift @bgmusic; 937 push @bgmusic, shift @bgmusic;
902} 938}
903 939
904sub audio_init { 940sub audio_init {
905 if ($CFG->{audio_enable}) { 941 if ($CFG->{audio_enable}) {
906 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { 942 if (open my $fh, "<", CFClient::find_rcfile "sounds/config") {
907 $SDL_MIXER = !CFClient::Mix_OpenAudio; 943 $SDL_MIXER = !CFClient::Mix_OpenAudio;
908 CFClient::Mix_AllocateChannels 8; 944 CFClient::Mix_AllocateChannels 8;
909 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; 945 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
910 946
911 audio_music_finished; 947 audio_music_finished;
938} 974}
939 975
940my %animate_object; 976my %animate_object;
941my $animate_timer; 977my $animate_timer;
942 978
943my $want_refresh;
944my $can_refresh;
945
946my $fps = 9; 979my $fps = 9;
947 980
948sub force_refresh { 981sub force_refresh {
949 $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05; 982 $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05;
950 debug sprintf "%3.2f", $fps; 983 debug sprintf "%3.2f", $fps;
951 984
952 $want_refresh = 0;
953 $can_refresh = 0;
954
955 $CFClient::UI::ROOT->draw; 985 $CFClient::UI::ROOT->draw;
956
957 CFClient::SDL_GL_SwapBuffers; 986 CFClient::SDL_GL_SwapBuffers;
958 987
988 $WANT_REFRESH = 0;
989 $CAN_REFRESH = 0;
959 $LAST_REFRESH = $NOW; 990 $LAST_REFRESH = $NOW;
960} 991}
961 992
962my $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 {
963 $NOW = time; 994 $NOW = time;
965 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) 996 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
966 for CFClient::SDL_PollEvent; 997 for CFClient::SDL_PollEvent;
967 998
968 if (%animate_object) { 999 if (%animate_object) {
969 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 1000 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
970 $want_refresh++; 1001 $WANT_REFRESH++;
971 } 1002 }
972 1003
973 if ($want_refresh) { 1004 if ($WANT_REFRESH) {
974 force_refresh; 1005 force_refresh;
975 } else { 1006 } else {
976 $can_refresh = 1; 1007 $CAN_REFRESH = 1;
977 } 1008 }
978}); 1009});
979
980sub refresh {
981 $want_refresh++;
982}
983 1010
984sub animation_start { 1011sub animation_start {
985 my ($widget) = @_; 1012 my ($widget) = @_;
986 $animate_object{$widget} = $widget; 1013 $animate_object{$widget} = $widget;
987} 1014}
1322 1349
1323 for my $skill (values %{$self->{skill_info}}) { 1350 for my $skill (values %{$self->{skill_info}}) {
1324 $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'"); 1351 $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'");
1325 $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'"); 1352 $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'");
1326 } 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;
1327} 1363}
1328 1364
1329sub update_floorbox { 1365sub update_floorbox {
1330 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { 1366 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub {
1367 return unless $CONN;
1368
1331 $FLOORBOX->clear; 1369 $FLOORBOX->clear;
1332 $FLOORBOX->add (new CFClient::UI::Empty expand => 1); 1370 $FLOORBOX->add (new CFClient::UI::Empty expand => 1);
1333 1371
1334 # we basically have to use the same sorting as everybody else 1372 # we basically have to use the same sorting as everybody else
1335 for my $item (@{ $CONN->{container}{0} }) { 1373 $FLOORBOX->add (
1336 my $desc = $item->{nrof} < 2 1374 map +(new CFClient::UI::InventoryItem item => $_),
1337 ? $item->{name} 1375 @{ $CONN->{container}{0} }
1338 : "$item->{nrof} $item->{name_pl}";
1339 # todo: animation widget, face widget, weight(?) etc.
1340 $FLOORBOX->add (my $hbox = new CFClient::UI::HBox
1341 tooltip => (CFClient::UI::Label->escape ($desc)
1342 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"),
1343 can_hover => 1,
1344 can_events => 1,
1345 connect_button_down => sub {
1346 my ($self, $ev, $x, $y) = @_;
1347
1348 # todo: maybe put examine on 1? but should just be a tooltip :(
1349 if ($ev->{button} == 1) {
1350 $CONN->send ("move $CONN->{player}{tag} $item->{tag} 0");
1351 } elsif ($ev->{button} == 2) {
1352 $CONN->send ("apply $item->{tag}");
1353 } elsif ($ev->{button} == 3) {
1354 CFClient::UI::Menu->new (
1355 items => [
1356 ["examine", sub { $CONN->send ("examine $item->{tag}") }],
1357 [
1358 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
1359 sub { $CONN->send ("lock $item->{tag}") },
1360 ],
1361 ["mark", sub { $CONN->send ("mark $item->{tag}") }],
1362 ["apply", sub { $CONN->send ("apply $item->{tag}") }],
1363 ],
1364 )->popup ($ev);
1365 }
1366
1367 1
1368 },
1369 ); 1376 );
1370
1371 $hbox->add (new CFClient::UI::Face
1372 can_events => 0,
1373 face => $item->{face},
1374 anim => $item->{anim},
1375 animspeed => $item->{animspeed},
1376 );
1377
1378 $hbox->add (new CFClient::UI::Label
1379 can_events => 0,
1380 text => $desc,
1381 );
1382 }
1383 }); 1377 });
1384 refresh; 1378
1379 $WANT_REFRESH++;
1385} 1380}
1386 1381
1387sub conn::container_add { 1382sub conn::container_add {
1388 my ($self, $id, $items) = @_; 1383 my ($self, $tag, $items) = @_;
1389 1384
1390 update_floorbox if $id == 0; 1385 update_floorbox if $tag == 0;
1391 if ($self->{player}{tag} == $id) { 1386
1392 $INV->set_items ($self->{container}{$self->{player}{tag}}); 1387 $INV->set_items ($self->{container}{$self->{player}{tag}})
1393 } 1388 if $tag == $self->{player}{tag};
1389
1394 # $self-<{player}{tag} => player inv 1390 # $self-<{player}{tag} => player inv
1395 #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}};
1396} 1392}
1397 1393
1398sub conn::container_clear { 1394sub conn::container_clear {
1399 my ($self, $id) = @_; 1395 my ($self, $tag) = @_;
1400 1396
1401 update_floorbox if $id == 0; 1397 update_floorbox if $tag == 0;
1402 if ($self->{player}{tag} == $id) { 1398
1403 $INV->set_items ($self->{container}{$id}); 1399 $INV->set_items ($self->{container}{$tag})
1404 } 1400 if $tag == $self->{player}{tag};
1405 1401
1406# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; 1402# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0};
1407} 1403}
1408 1404
1409sub conn::item_delete { 1405sub conn::item_delete {
1410 my ($self, @items) = @_; 1406 my ($self, @items) = @_;
1411 1407
1412 for (@items) { 1408 for (@items) {
1413 update_floorbox if $_->{container} == 0; 1409 update_floorbox if $_->{container} == 0;
1414 if ($self->{player}{tag} == $_->{container}) { 1410
1415 $INV->set_items ($self->{container}{$_->{container}}); 1411 $INV->set_items ($self->{container}{$_->{container}})
1416 } 1412 if $_->{container} == $self->{player}{tag};
1417 } 1413 }
1418} 1414}
1419 1415
1420sub conn::item_update { 1416sub conn::item_update {
1421 my ($self, $item) = @_; 1417 my ($self, $item) = @_;
1422 1418
1423 update_floorbox if $item->{container} == 0; 1419 update_floorbox if $item->{container} == 0;
1424 if ($self->{player}{tag} == $item->{container}) { 1420
1425 $INV->set_items ($self->{container}{$item->{container}}); 1421 $INV->set_items ($self->{container}{$item->{container}})
1426 } 1422 if $item->{container} == $self->{player}{tag};
1427} 1423}
1428 1424
1429%SDL_CB = ( 1425%SDL_CB = (
1430 CFClient::SDL_QUIT => sub { 1426 CFClient::SDL_QUIT => sub {
1431 Event::unloop -1; 1427 Event::unloop -1;
1432 }, 1428 },
1433 CFClient::SDL_VIDEORESIZE => sub { 1429 CFClient::SDL_VIDEORESIZE => sub {
1434 }, 1430 },
1435 CFClient::SDL_VIDEOEXPOSE => \&refresh, 1431 CFClient::SDL_VIDEOEXPOSE => sub {
1432 $WANT_REFRESH++;
1433 },
1436 CFClient::SDL_ACTIVEEVENT => sub { 1434 CFClient::SDL_ACTIVEEVENT => sub {
1437# 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#
1438 }, 1436 },
1439 CFClient::SDL_KEYDOWN => sub { 1437 CFClient::SDL_KEYDOWN => sub {
1440 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { 1438 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
1444 video_init; 1442 video_init;
1445 } else { 1443 } else {
1446 CFClient::UI::feed_sdl_key_down_event ($_[0]); 1444 CFClient::UI::feed_sdl_key_down_event ($_[0]);
1447 } 1445 }
1448 }, 1446 },
1449 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, 1447 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
1450 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, 1448 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
1451 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, 1449 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
1452 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, 1450 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
1453 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 },
1454); 1458);
1455 1459
1456############################################################################# 1460#############################################################################
1457 1461
1458$SIG{INT} = $SIG{TERM} = sub { exit }; 1462$SIG{INT} = $SIG{TERM} = sub { exit };
1459 1463
1460CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1461
1462$TILECACHE = CFClient::db_table "tilecache";
1463$FACEMAP = CFClient::db_table "facemap";
1464
1465my %DEF_CFG = (
1466 sdl_mode => 0,
1467 width => 640,
1468 height => 480,
1469 fullscreen => 0,
1470 fast => 0,
1471 map_scale => 0.5,
1472 fow_enable => 1,
1473 fow_intensity => 0.45,
1474 fow_smooth => 0,
1475 gui_fontsize => 1,
1476 log_fontsize => 1,
1477 gauge_fontsize => 1,
1478 gauge_size => 0.35,
1479 stat_fontsize => 1,
1480 mapsize => 100,
1481 host => "crossfire.schmorp.de",
1482 say_command => 'say',
1483 audio_enable => 1,
1484 bgm_enable => 1,
1485 bgm_volume => 0.25,
1486);
1487
1488while (my ($k, $v) = each %DEF_CFG) {
1489 $CFG->{$k} = $v unless exists $CFG->{$k};
1490}
1491
1492sdl_init;
1493
1494@SDL_MODES = reverse
1495 grep $_->[0] >= 640 && $_->[1] >= 480,
1496 CFClient::SDL_ListModes;
1497
1498@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
1499
1500$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
1501
1502{ 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 {
1503 my @fonts = map CFClient::find_rcfile "fonts/$_", qw( 1510 my @fonts = map CFClient::find_rcfile "fonts/$_", qw(
1504 DejaVuSans.ttf 1511 DejaVuSans.ttf
1505 DejaVuSansMono.ttf 1512 DejaVuSansMono.ttf
1506 DejaVuSans-Bold.ttf 1513 DejaVuSans-Bold.ttf
1507 DejaVuSansMono-Bold.ttf 1514 DejaVuSansMono-Bold.ttf
1508 DejaVuSans-Oblique.ttf 1515 DejaVuSans-Oblique.ttf
1509 DejaVuSansMono-Oblique.ttf 1516 DejaVuSansMono-Oblique.ttf
1510 DejaVuSans-BoldOblique.ttf 1517 DejaVuSans-BoldOblique.ttf
1511 DejaVuSansMono-BoldOblique.ttf 1518 DejaVuSansMono-BoldOblique.ttf
1512 ); 1519 );
1513 1520
1514 CFClient::add_font $_ for @fonts; 1521 CFClient::add_font $_ for @fonts;
1515 1522
1516 $FONT_PROP = new_from_file CFClient::Font $fonts[0]; 1523 $FONT_PROP = new_from_file CFClient::Font $fonts[0];
1517 $FONT_FIXED = new_from_file CFClient::Font $fonts[1]; 1524 $FONT_FIXED = new_from_file CFClient::Font $fonts[1];
1518 1525
1519 $FONT_PROP->make_default; 1526 $FONT_PROP->make_default;
1520} 1527 }
1521 1528
1522video_init; 1529 video_init;
1523audio_init; 1530 audio_init;
1531}
1524 1532
1525Event::loop; 1533Event::loop;
1526 1534
1527END { CFClient::SDL_Quit } 1535END { CFClient::SDL_Quit }
1528 1536

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines