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.198 by root, Fri May 5 19:10:16 2006 UTC vs.
Revision 1.204 by root, Mon May 8 21:16:10 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 {
811 828
812 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN 829 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
813 or die "SDL_SetVideoMode failed!\n"; 830 or die "SDL_SetVideoMode failed!\n";
814 831
815 $SDL_ACTIVE = 1; 832 $SDL_ACTIVE = 1;
816
817 $LAST_REFRESH = time - 0.01; 833 $LAST_REFRESH = time - 0.01;
818 834
819 CFClient::gl_init; 835 CFClient::gl_init;
820 836
821 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; 837 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
822 838
839 $CFClient::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d#
840
823 ############################################################################# 841 #############################################################################
824 842
843 if ($DEBUG_STATUS) {
844 # reconfigure all widgets
845 $CFClient::UI::ROOT->reconfigure;
846
847 } else {
848 # create the widgets
849
825 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 850 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
826 $DEBUG_STATUS->show; 851 $DEBUG_STATUS->show;
827 852
828 $STATUS_LINE = new CFClient::UI::Label 853 $STATUS_LINE = new CFClient::UI::Label
829 padding => 0, 854 padding => 0,
830 y => $HEIGHT - $FONTSIZE * 1.8; 855 y => $HEIGHT - $FONTSIZE * 1.8;
831 $STATUS_LINE->show; 856 $STATUS_LINE->show;
832 857
833 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 858 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
834 padding => 0, 859 padding => 0,
835 fontsize => 0.8, 860 fontsize => 0.8,
836 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 861 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
837 $ALT_ENTER_MESSAGE->show; 862 $ALT_ENTER_MESSAGE->show;
838 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); 863 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
839 864
840 CFClient::UI::FancyFrame->new ( 865 CFClient::UI::FancyFrame->new (
841 border_bg => [1, 1, 1, 192/255], 866 border_bg => [1, 1, 1, 192/255],
842 bg => [1, 1, 1, 0], 867 bg => [1, 1, 1, 0],
843 child => ($MAPMAP = new CFClient::MapWidget::MapMap), 868 child => ($MAPMAP = new CFClient::MapWidget::MapMap),
844 )->show; 869 )->show;
845 870
846 $MAPWIDGET = new CFClient::MapWidget; 871 $MAPWIDGET = new CFClient::MapWidget;
847 $MAPWIDGET->connect (activate_console => sub { 872 $MAPWIDGET->connect (activate_console => sub {
848 my ($mapwidget, $preset) = @_; 873 my ($mapwidget, $preset) = @_;
849 874
850 if ($CONSOLE) { 875 if ($CONSOLE) {
851 $CONSOLE->{input}->{auto_activated} = 1; 876 $CONSOLE->{input}->{auto_activated} = 1;
852 $CONSOLE->{input}->focus_in; 877 $CONSOLE->{input}->focus_in;
853 878
854 if ($preset && $CONSOLE->{input}->get_text eq '') { 879 if ($preset && $CONSOLE->{input}->get_text eq '') {
855 $CONSOLE->{input}->set_text ($preset); 880 $CONSOLE->{input}->set_text ($preset);
881 }
856 } 882 }
857 } 883 });
858 });
859 $MAPWIDGET->show; 884 $MAPWIDGET->show;
860 $MAPWIDGET->focus_in; 885 $MAPWIDGET->focus_in;
861 886
862 $BUTTONBAR = new CFClient::UI::HBox; 887 $BUTTONBAR = new CFClient::UI::HBox;
863 888
864 $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);
865 $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);
866 $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);
867 892
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 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
869 894
870 $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);
871 $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);
872 897
873 $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 {
874 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 899 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
875 status "Configuration Saved"; 900 status "Configuration Saved";
876 }); 901 });
877 902
878 $BUTTONBAR->show; 903 $BUTTONBAR->show;
879 904
880 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 905 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
906 }
881} 907}
882 908
883sub video_shutdown { 909sub video_shutdown {
884 $CFClient::UI::ROOT->{children} = [];
885 undef $CFClient::UI::GRAB;
886 undef $CFClient::UI::HOVER;
887 undef $SDL_ACTIVE; 910 undef $SDL_ACTIVE;
888} 911}
889 912
890my @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#
891my $bgmusic;#TODO#hack#d# 914my $bgmusic;#TODO#hack#d#
1327 1350
1328 for my $skill (values %{$self->{skill_info}}) { 1351 for my $skill (values %{$self->{skill_info}}) {
1329 $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'"); 1352 $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'");
1330 $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'"); 1353 $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'");
1331 } 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;
1332} 1364}
1333 1365
1334sub update_floorbox { 1366sub update_floorbox {
1335 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { 1367 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub {
1368 return unless $CONN;
1369
1336 $FLOORBOX->clear; 1370 $FLOORBOX->clear;
1337 $FLOORBOX->add (new CFClient::UI::Empty expand => 1); 1371 $FLOORBOX->add (new CFClient::UI::Empty expand => 1);
1338 1372
1339 # we basically have to use the same sorting as everybody else 1373 # we basically have to use the same sorting as everybody else
1340 for my $item (@{ $CONN->{container}{0} }) { 1374 $FLOORBOX->add (
1341 $FLOORBOX->add (new CFClient::UI::InventoryItem item => $item); 1375 map +(new CFClient::UI::InventoryItem item => $_),
1376 @{ $CONN->{container}{0} }
1342 } 1377 );
1343 }); 1378 });
1344 refresh; 1379 refresh;
1345} 1380}
1346 1381
1347sub conn::container_add { 1382sub conn::container_add {
1348 my ($self, $id, $items) = @_; 1383 my ($self, $tag, $items) = @_;
1349 1384
1350 update_floorbox if $id == 0; 1385 update_floorbox if $tag == 0;
1351 if ($self->{player}{tag} == $id) { 1386
1352 $INV->set_items ($self->{container}{$self->{player}{tag}}); 1387 $INV->set_items ($self->{container}{$self->{player}{tag}})
1353 } 1388 if $tag == $self->{player}{tag};
1389
1354 # $self-<{player}{tag} => player inv 1390 # $self-<{player}{tag} => player inv
1355 #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}};
1356} 1392}
1357 1393
1358sub conn::container_clear { 1394sub conn::container_clear {
1359 my ($self, $id) = @_; 1395 my ($self, $tag) = @_;
1360 1396
1361 update_floorbox if $id == 0; 1397 update_floorbox if $tag == 0;
1362 if ($self->{player}{tag} == $id) { 1398
1363 $INV->set_items ($self->{container}{$id}); 1399 $INV->set_items ($self->{container}{$tag})
1364 } 1400 if $tag == $self->{player}{tag};
1365 1401
1366# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; 1402# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0};
1367} 1403}
1368 1404
1369sub conn::item_delete { 1405sub conn::item_delete {
1370 my ($self, @items) = @_; 1406 my ($self, @items) = @_;
1371 1407
1372 for (@items) { 1408 for (@items) {
1373 update_floorbox if $_->{container} == 0; 1409 update_floorbox if $_->{container} == 0;
1374 if ($self->{player}{tag} == $_->{container}) { 1410
1375 $INV->set_items ($self->{container}{$_->{container}}); 1411 $INV->set_items ($self->{container}{$_->{container}})
1376 } 1412 if $_->{container} == $self->{player}{tag};
1377 } 1413 }
1378} 1414}
1379 1415
1380sub conn::item_update { 1416sub conn::item_update {
1381 my ($self, $item) = @_; 1417 my ($self, $item) = @_;
1382 1418
1383 update_floorbox if $item->{container} == 0; 1419 update_floorbox if $item->{container} == 0;
1384 if ($self->{player}{tag} == $item->{container}) { 1420
1385 $INV->set_items ($self->{container}{$item->{container}}); 1421 $INV->set_items ($self->{container}{$item->{container}})
1386 } 1422 if $item->{container} == $self->{player}{tag};
1387} 1423}
1388 1424
1389%SDL_CB = ( 1425%SDL_CB = (
1390 CFClient::SDL_QUIT => sub { 1426 CFClient::SDL_QUIT => sub {
1391 Event::unloop -1; 1427 Event::unloop -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines