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.196 by elmex, Sun Apr 30 13:10:47 2006 UTC vs.
Revision 1.203 by root, Mon May 8 20:55:49 2006 UTC

76our $MAPWIDGET; 76our $MAPWIDGET;
77our $BUTTONBAR; 77our $BUTTONBAR;
78our $LOGVIEW; 78our $LOGVIEW;
79our $CONSOLE; 79our $CONSOLE;
80our $METASERVER; 80our $METASERVER;
81our $LOGIN_BUTTON;
81 82
82our $FLOORBOX; 83our $FLOORBOX;
83our $GAUGES; 84our $GAUGES;
84our $STATWIDS; 85our $STATWIDS;
85 86
111 status "logging in..."; 112 status "logging in...";
112 113
113 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 114 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
114 115
115 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}"; 116 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}";
116
117 $MAP = new CFClient::Map $mapsize, $mapsize; 117 $MAP = new CFClient::Map $mapsize, $mapsize;
118 118
119 my ($host, $port) = split /:/, $CFG->{host}; 119 my ($host, $port) = split /:/, $CFG->{host};
120 120
121 $CONN = eval { 121 $CONN = eval {
128 maph => $mapsize, 128 maph => $mapsize,
129 ; 129 ;
130 }; 130 };
131 131
132 if ($CONN) { 132 if ($CONN) {
133 $LOGIN_BUTTON->set_text ("Logout");
134
133 status "login successful"; 135 status "login successful";
134 136
135 CFClient::lowdelay fileno $CONN->{fh}; 137 CFClient::lowdelay fileno $CONN->{fh};
136 } else { 138 } else {
137 status "unable to connect"; 139 status "unable to connect";
140 stop_game();
138 } 141 }
139} 142}
140 143
141sub stop_game { 144sub stop_game {
145 return unless $CONN;
146
147 status "connection closed";
148 $LOGIN_BUTTON->set_text ("Login");
149 $CONN->destroy;
150 $CONN = 0; # false, does not autovivify
151
152 undef $MAPCACHE;
142 undef $CONN; 153 undef $MAP;
143} 154}
144 155
145sub client_setup { 156sub client_setup {
146 my $dialog = new CFClient::UI::FancyFrame 157 my $dialog = new CFClient::UI::FancyFrame
147 title => "Client Setup", 158 title => "Client Setup",
571 582
572} 583}
573 584
574sub metaserver_dialog { 585sub metaserver_dialog {
575 my $dialog = new CFClient::UI::FancyFrame 586 my $dialog = new CFClient::UI::FancyFrame
576 title => "Metaserver", 587 title => "Server List",
577 child => (my $vbox = new CFClient::UI::VBox); 588 child => (my $vbox = new CFClient::UI::VBox);
578 589
579 $vbox->add ($dialog->{table} = new CFClient::UI::Table); 590 $vbox->add ($dialog->{table} = new CFClient::UI::Table);
580 591
581 $dialog 592 $dialog
683 694
684 $METASERVER = metaserver_dialog; 695 $METASERVER = metaserver_dialog;
685 696
686 $vbox->add (new CFClient::UI::Flopper 697 $vbox->add (new CFClient::UI::Flopper
687 expand => 1, 698 expand => 1,
688 text => "Metaserver", 699 text => "Server List",
689 other => $METASERVER, 700 other => $METASERVER,
690 tooltip => "Show a list of avaible crossfire servers", 701 tooltip => "Show a list of available crossfire servers",
691 connect_open => sub { 702 connect_open => sub {
692 update_metaserver $HOST; 703 update_metaserver $HOST;
693 } 704 }
694 ); 705 );
695 } 706 }
726 737
727 $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 738 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
728 }, 739 },
729 ); 740 );
730 741
731 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { 742 $table->add (1, 8, $LOGIN_BUTTON = new CFClient::UI::Button
743 expand => 1,
744 align => 0,
745 text => "Login",
746 connect_activate => sub {
747 $CONN ? stop_game
732 start_game; 748 : start_game;
749 },
733 }); 750 );
734 751
735 $dialog 752 $dialog
736} 753}
737 754
738sub message_window { 755sub message_window {
801} 818}
802 819
803sub video_init { 820sub video_init {
804 sdl_init; 821 sdl_init;
805 822
823 $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} >= @SDL_MODES;
824
806 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 825 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
807 $FULLSCREEN = $CFG->{fullscreen}; 826 $FULLSCREEN = $CFG->{fullscreen};
808 $FAST = $CFG->{fast}; 827 $FAST = $CFG->{fast};
809 828
810 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN 829 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
811 or die "SDL_SetVideoMode failed!\n"; 830 or die "SDL_SetVideoMode failed!\n";
812 831
813 $SDL_ACTIVE = 1; 832 $SDL_ACTIVE = 1;
814
815 $LAST_REFRESH = time - 0.01; 833 $LAST_REFRESH = time - 0.01;
816 834
817 CFClient::gl_init; 835 CFClient::gl_init;
818 836
819 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; 837 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
820 838
839 $CFClient::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d#
840
821 ############################################################################# 841 #############################################################################
822 842
843 if ($DEBUG_STATUS) {
844 # reconfigure all widgets
845 $CFClient::UI::ROOT->reconfigure;
846
847 } else {
848 # create the widgets
849
823 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 850 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
824 $DEBUG_STATUS->show; 851 $DEBUG_STATUS->show;
825 852
826 $STATUS_LINE = new CFClient::UI::Label 853 $STATUS_LINE = new CFClient::UI::Label
827 padding => 0, 854 padding => 0,
828 y => $HEIGHT - $FONTSIZE * 1.8; 855 y => $HEIGHT - $FONTSIZE * 1.8;
829 $STATUS_LINE->show; 856 $STATUS_LINE->show;
830 857
831 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 858 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
832 padding => 0, 859 padding => 0,
833 fontsize => 0.8, 860 fontsize => 0.8,
834 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 861 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
835 $ALT_ENTER_MESSAGE->show; 862 $ALT_ENTER_MESSAGE->show;
836 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); 863 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
837 864
838 CFClient::UI::FancyFrame->new ( 865 CFClient::UI::FancyFrame->new (
839 border_bg => [1, 1, 1, 192/255], 866 border_bg => [1, 1, 1, 192/255],
840 bg => [1, 1, 1, 0], 867 bg => [1, 1, 1, 0],
841 child => ($MAPMAP = new CFClient::MapWidget::MapMap), 868 child => ($MAPMAP = new CFClient::MapWidget::MapMap),
842 )->show; 869 )->show;
843 870
844 $MAPWIDGET = new CFClient::MapWidget; 871 $MAPWIDGET = new CFClient::MapWidget;
845 $MAPWIDGET->connect (activate_console => sub { 872 $MAPWIDGET->connect (activate_console => sub {
846 my ($mapwidget, $preset) = @_; 873 my ($mapwidget, $preset) = @_;
847 874
848 if ($CONSOLE) { 875 if ($CONSOLE) {
849 $CONSOLE->{input}->{auto_activated} = 1; 876 $CONSOLE->{input}->{auto_activated} = 1;
850 $CONSOLE->{input}->focus_in; 877 $CONSOLE->{input}->focus_in;
851 878
852 if ($preset && $CONSOLE->{input}->get_text eq '') { 879 if ($preset && $CONSOLE->{input}->get_text eq '') {
853 $CONSOLE->{input}->set_text ($preset); 880 $CONSOLE->{input}->set_text ($preset);
881 }
854 } 882 }
855 } 883 });
856 });
857 $MAPWIDGET->show; 884 $MAPWIDGET->show;
858 $MAPWIDGET->focus_in; 885 $MAPWIDGET->focus_in;
859 886
860 $BUTTONBAR = new CFClient::UI::HBox; 887 $BUTTONBAR = new CFClient::UI::HBox;
861 888
862 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup); 889 $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); 890 $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); 891 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window);
865 892
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 893 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 894
868 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window); 895 $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); 896 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Inventory", other => make_inventory_window);
870 897
871 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { 898 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub {
872 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 899 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
873 status "Configuration Saved"; 900 status "Configuration Saved";
874 }); 901 });
875 902
876 $BUTTONBAR->show; 903 $BUTTONBAR->show;
877 904
878 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 905 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
906 }
879} 907}
880 908
881sub video_shutdown { 909sub video_shutdown {
882 $CFClient::UI::ROOT->{children} = [];
883 undef $CFClient::UI::GRAB;
884 undef $CFClient::UI::HOVER;
885 undef $SDL_ACTIVE; 910 undef $SDL_ACTIVE;
886} 911}
887 912
888my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# 913my @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# 914my $bgmusic;#TODO#hack#d#
915
916sub audio_channel_finished {
917 my ($channel) = @_;
918
919 warn "channel $channel finished\n";#d#
920}
890 921
891sub audio_music_finished { 922sub audio_music_finished {
892 return unless $CFG->{bgm_enable}; 923 return unless $CFG->{bgm_enable};
893 924
894 # TODO: hack, do play loop and mood music 925 # TODO: hack, do play loop and mood music
1319 1350
1320 for my $skill (values %{$self->{skill_info}}) { 1351 for my $skill (values %{$self->{skill_info}}) {
1321 $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'"); 1352 $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'");
1322 $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'"); 1353 $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'");
1323 } 1354 }
1355
1356 $MAPWIDGET->add_command ("pet\\_mode defend", "Tell pets to stay close to you and defend you");
1357 $MAPWIDGET->add_command ("pet\\_mode arena", "Same as petmode attack, but also attack other players");
1358 $MAPWIDGET->add_command ("pet\\_mode sad", "Search &amp; Destroy - tell pets to roam about and attack enemies");
1359 $MAPWIDGET->add_command ("kill\\_pets", "kill your pets");
1360}
1361
1362sub conn::eof {
1363 stop_game;
1324} 1364}
1325 1365
1326sub update_floorbox { 1366sub update_floorbox {
1327 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { 1367 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub {
1368 return unless $CONN;
1369
1328 $FLOORBOX->clear; 1370 $FLOORBOX->clear;
1329 $FLOORBOX->add (new CFClient::UI::Empty expand => 1); 1371 $FLOORBOX->add (new CFClient::UI::Empty expand => 1);
1330 1372
1331 # we basically have to use the same sorting as everybody else 1373 # we basically have to use the same sorting as everybody else
1332 for my $item (@{ $CONN->{container}{0} }) { 1374 for my $item (@{ $CONN->{container}{0} }) {
1335 }); 1377 });
1336 refresh; 1378 refresh;
1337} 1379}
1338 1380
1339sub conn::container_add { 1381sub conn::container_add {
1340 my ($self, $id, $items) = @_; 1382 my ($self, $tag, $items) = @_;
1341 1383
1342 update_floorbox if $id == 0; 1384 update_floorbox if $tag == 0;
1343 if ($self->{player}{tag} == $id) { 1385
1344 $INV->set_items ($self->{container}{$self->{player}{tag}}); 1386 $INV->set_items ($self->{container}{$self->{player}{tag}})
1345 } 1387 if $tag == $self->{player}{tag};
1388
1346 # $self-<{player}{tag} => player inv 1389 # $self-<{player}{tag} => player inv
1347 #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; 1390 #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}};
1348} 1391}
1349 1392
1350sub conn::container_clear { 1393sub conn::container_clear {
1351 my ($self, $id) = @_; 1394 my ($self, $tag) = @_;
1352 1395
1353 update_floorbox if $id == 0; 1396 update_floorbox if $tag == 0;
1354 if ($self->{player}{tag} == $id) { 1397
1355 $INV->set_items ($self->{container}{$id}); 1398 $INV->set_items ($self->{container}{$tag})
1356 } 1399 if $tag == $self->{player}{tag};
1357 1400
1358# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; 1401# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0};
1359} 1402}
1360 1403
1361sub conn::item_delete { 1404sub conn::item_delete {
1362 my ($self, @items) = @_; 1405 my ($self, @items) = @_;
1363 1406
1364 for (@items) { 1407 for (@items) {
1365 update_floorbox if $_->{container} == 0; 1408 update_floorbox if $_->{container} == 0;
1366 if ($self->{player}{tag} == $_->{container}) { 1409
1367 $INV->set_items ($self->{container}{$_->{container}}); 1410 $INV->set_items ($self->{container}{$_->{container}})
1368 } 1411 if $_->{container} == $self->{player}{tag};
1369 } 1412 }
1370} 1413}
1371 1414
1372sub conn::item_update { 1415sub conn::item_update {
1373 my ($self, $item) = @_; 1416 my ($self, $item) = @_;
1374 1417
1375 update_floorbox if $item->{container} == 0; 1418 update_floorbox if $item->{container} == 0;
1376 if ($self->{player}{tag} == $item->{container}) { 1419
1377 $INV->set_items ($self->{container}{$item->{container}}); 1420 $INV->set_items ($self->{container}{$item->{container}})
1378 } 1421 if $item->{container}; == $self->{player}{tag};
1379} 1422}
1380 1423
1381%SDL_CB = ( 1424%SDL_CB = (
1382 CFClient::SDL_QUIT => sub { 1425 CFClient::SDL_QUIT => sub {
1383 Event::unloop -1; 1426 Event::unloop -1;
1396 video_init; 1439 video_init;
1397 } else { 1440 } else {
1398 CFClient::UI::feed_sdl_key_down_event ($_[0]); 1441 CFClient::UI::feed_sdl_key_down_event ($_[0]);
1399 } 1442 }
1400 }, 1443 },
1401 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, 1444 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
1402 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, 1445 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
1403 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, 1446 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
1404 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, 1447 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
1405 CFClient::SDL_USEREVENT => \&audio_music_finished, 1448 CFClient::SDL_USEREVENT => sub {
1449 if ($_[0]{code} == 1) {
1450 audio_channel_finished $_[0]{data1};
1451 } elsif ($_[0]{code} == 0) {
1452 audio_music_finished;
1453 }
1454 },
1406); 1455);
1407 1456
1408############################################################################# 1457#############################################################################
1409 1458
1410$SIG{INT} = $SIG{TERM} = sub { exit }; 1459$SIG{INT} = $SIG{TERM} = sub { exit };

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines