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.190 by elmex, Thu Apr 27 08:55:35 2006 UTC vs.
Revision 1.198 by root, Fri May 5 19:10:16 2006 UTC

92 92
93our $ALT_ENTER_MESSAGE; 93our $ALT_ENTER_MESSAGE;
94our $STATUS_LINE; 94our $STATUS_LINE;
95our $DEBUG_STATUS; 95our $DEBUG_STATUS;
96 96
97our $INVWIN;
98our $INV;
99
97sub status { 100sub status {
98 $STATUS_LINE->set_text ($_[0]); 101 $STATUS_LINE->set_text ($_[0]);
99 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h}); 102 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h});
100} 103}
101 104
113 116
114 $MAP = new CFClient::Map $mapsize, $mapsize; 117 $MAP = new CFClient::Map $mapsize, $mapsize;
115 118
116 my ($host, $port) = split /:/, $CFG->{host}; 119 my ($host, $port) = split /:/, $CFG->{host};
117 120
118 $CONN = new conn 121 $CONN = eval {
122 new conn
119 host => $host, 123 host => $host,
120 port => $port || 13327, 124 port => $port || 13327,
121 user => $CFG->{user}, 125 user => $CFG->{user},
122 pass => $CFG->{password}, 126 pass => $CFG->{password},
123 mapw => $mapsize, 127 mapw => $mapsize,
124 maph => $mapsize, 128 maph => $mapsize,
129 ;
125 ; 130 };
126 131
132 if ($CONN) {
127 status "login successful"; 133 status "login successful";
128 134
129 CFClient::lowdelay fileno $CONN->{fh}; 135 CFClient::lowdelay fileno $CONN->{fh};
136 } else {
137 status "unable to connect";
138 }
130} 139}
131 140
132sub stop_game { 141sub stop_game {
133 undef $CONN; 142 undef $CONN;
134} 143}
778 }; 787 };
779 788
780 $window 789 $window
781} 790}
782 791
792sub make_inventory_window {
793 my $invwin = new CFClient::UI::FancyFrame user_w => 300, user_h => 300, title => "Inventory";
794 $invwin->add ($INV = new CFClient::UI::Inventory expand => 1);
795 $invwin
796}
797
783sub sdl_init { 798sub sdl_init {
784 CFClient::SDL_Init 799 CFClient::SDL_Init
785 and die "SDL::Init failed!\n"; 800 and die "SDL::Init failed!\n";
786} 801}
787 802
788sub video_init { 803sub video_init {
789 sdl_init; 804 sdl_init;
805
806 $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} >= @SDL_MODES;
790 807
791 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 808 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
792 $FULLSCREEN = $CFG->{fullscreen}; 809 $FULLSCREEN = $CFG->{fullscreen};
793 $FAST = $CFG->{fast}; 810 $FAST = $CFG->{fast};
794 811
846 863
847 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup); 864 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup);
848 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup); 865 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup);
849 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window); 866 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window);
850 867
851 $CFClient::UI::ROOT->add (make_gauge_window); # 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 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
869
852 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window); 870 $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);
853 872
854 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { 873 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub {
855 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 874 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
856 status "Configuration Saved"; 875 status "Configuration Saved";
857 }); 876 });
869} 888}
870 889
871my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# 890my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d#
872my $bgmusic;#TODO#hack#d# 891my $bgmusic;#TODO#hack#d#
873 892
893sub audio_channel_finished {
894 my ($channel) = @_;
895
896 warn "channel $channel finished\n";#d#
897}
898
874sub audio_music_finished { 899sub audio_music_finished {
875 return unless $CFG->{bgm_enable}; 900 return unless $CFG->{bgm_enable};
876 901
877 # TODO: hack, do play loop and mood music 902 # TODO: hack, do play loop and mood music
878 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]"; 903 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]";
881 push @bgmusic, shift @bgmusic; 906 push @bgmusic, shift @bgmusic;
882} 907}
883 908
884sub audio_init { 909sub audio_init {
885 if ($CFG->{audio_enable}) { 910 if ($CFG->{audio_enable}) {
886 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { 911 if (open my $fh, "<", CFClient::find_rcfile "sounds/config") {
887 $SDL_MIXER = !CFClient::Mix_OpenAudio; 912 $SDL_MIXER = !CFClient::Mix_OpenAudio;
888 CFClient::Mix_AllocateChannels 8; 913 CFClient::Mix_AllocateChannels 8;
889 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; 914 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
890 915
891 audio_music_finished; 916 audio_music_finished;
1309sub update_floorbox { 1334sub update_floorbox {
1310 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { 1335 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub {
1311 $FLOORBOX->clear; 1336 $FLOORBOX->clear;
1312 $FLOORBOX->add (new CFClient::UI::Empty expand => 1); 1337 $FLOORBOX->add (new CFClient::UI::Empty expand => 1);
1313 1338
1314 my @items = values %{ $CONN->{container}{0} };
1315
1316 # we basically have to use the same sorting as everybody else 1339 # we basically have to use the same sorting as everybody else
1317 @items = sort { $a->{type} <=> $b->{type} } @items; 1340 for my $item (@{ $CONN->{container}{0} }) {
1318 1341 $FLOORBOX->add (new CFClient::UI::InventoryItem item => $item);
1319 for my $item (reverse @items) {
1320 my $desc = $item->{nrof} < 2
1321 ? $item->{name}
1322 : "$item->{nrof} $item->{name_pl}";
1323 # todo: animation widget, face widget, weight(?) etc.
1324 $FLOORBOX->add (my $hbox = new CFClient::UI::HBox
1325 tooltip => (CFClient::UI::Label->escape ($desc)
1326 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"),
1327 can_hover => 1,
1328 can_events => 1,
1329 connect_button_down => sub {
1330 my ($self, $ev, $x, $y) = @_;
1331
1332 # todo: maybe put examine on 1? but should just be a tooltip :(
1333 if ($ev->{button} == 1) {
1334 $CONN->send ("move $CONN->{player}{tag} $item->{tag} 0");
1335 } elsif ($ev->{button} == 2) {
1336 $CONN->send ("apply $item->{tag}");
1337 } elsif ($ev->{button} == 3) {
1338 CFClient::UI::Menu->new (
1339 items => [
1340 ["examine", sub { $CONN->send ("examine $item->{tag}") }],
1341 [
1342 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
1343 sub { $CONN->send ("lock $item->{tag}") },
1344 ],
1345 ["mark", sub { $CONN->send ("mark $item->{tag}") }],
1346 ["apply", sub { $CONN->send ("apply $item->{tag}") }],
1347 ],
1348 )->popup ($ev);
1349 }
1350
1351 1
1352 },
1353 );
1354
1355 $hbox->add (new CFClient::UI::Face
1356 can_events => 0,
1357 face => $item->{face},
1358 anim => $item->{anim},
1359 animspeed => $item->{animspeed},
1360 );
1361
1362 $hbox->add (new CFClient::UI::Label
1363 can_events => 0,
1364 text => $desc,
1365 );
1366 } 1342 }
1367 }); 1343 });
1368 refresh; 1344 refresh;
1369} 1345}
1370 1346
1371sub conn::container_add { 1347sub conn::container_add {
1372 my ($self, $id, $items) = @_; 1348 my ($self, $id, $items) = @_;
1373 1349
1374 update_floorbox if $id == 0; 1350 update_floorbox if $id == 0;
1351 if ($self->{player}{tag} == $id) {
1352 $INV->set_items ($self->{container}{$self->{player}{tag}});
1353 }
1375 # $self-<{player}{tag} => player inv 1354 # $self-<{player}{tag} => player inv
1376 #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; 1355 #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}};
1377} 1356}
1378 1357
1379sub conn::container_clear { 1358sub conn::container_clear {
1380 my ($self, $id) = @_; 1359 my ($self, $id) = @_;
1381 1360
1382 update_floorbox if $id == 0; 1361 update_floorbox if $id == 0;
1362 if ($self->{player}{tag} == $id) {
1363 $INV->set_items ($self->{container}{$id});
1364 }
1365
1383# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; 1366# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0};
1384} 1367}
1385 1368
1386sub conn::item_delete { 1369sub conn::item_delete {
1387 my ($self, @items) = @_; 1370 my ($self, @items) = @_;
1388 1371
1389 for (@items) { 1372 for (@items) {
1390 update_floorbox if $_->{container} == 0; 1373 update_floorbox if $_->{container} == 0;
1374 if ($self->{player}{tag} == $_->{container}) {
1375 $INV->set_items ($self->{container}{$_->{container}});
1376 }
1391 } 1377 }
1392} 1378}
1393 1379
1394sub conn::item_update { 1380sub conn::item_update {
1395 my ($self, $item) = @_; 1381 my ($self, $item) = @_;
1396 1382
1397 update_floorbox if $item->{container} == 0; 1383 update_floorbox if $item->{container} == 0;
1384 if ($self->{player}{tag} == $item->{container}) {
1385 $INV->set_items ($self->{container}{$item->{container}});
1386 }
1398} 1387}
1399 1388
1400%SDL_CB = ( 1389%SDL_CB = (
1401 CFClient::SDL_QUIT => sub { 1390 CFClient::SDL_QUIT => sub {
1402 Event::unloop -1; 1391 Event::unloop -1;
1415 video_init; 1404 video_init;
1416 } else { 1405 } else {
1417 CFClient::UI::feed_sdl_key_down_event ($_[0]); 1406 CFClient::UI::feed_sdl_key_down_event ($_[0]);
1418 } 1407 }
1419 }, 1408 },
1420 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, 1409 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
1421 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, 1410 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
1422 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, 1411 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
1423 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, 1412 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
1424 CFClient::SDL_USEREVENT => \&audio_music_finished, 1413 CFClient::SDL_USEREVENT => sub {
1414 if ($_[0]{code} == 1) {
1415 audio_channel_finished $_[0]{data1};
1416 } elsif ($_[0]{code} == 0) {
1417 audio_music_finished;
1418 }
1419 },
1425); 1420);
1426 1421
1427############################################################################# 1422#############################################################################
1428 1423
1429$SIG{INT} = $SIG{TERM} = sub { exit }; 1424$SIG{INT} = $SIG{TERM} = sub { exit };
1425
1426CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1430 1427
1431$TILECACHE = CFClient::db_table "tilecache"; 1428$TILECACHE = CFClient::db_table "tilecache";
1432$FACEMAP = CFClient::db_table "facemap"; 1429$FACEMAP = CFClient::db_table "facemap";
1433
1434CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1435 1430
1436my %DEF_CFG = ( 1431my %DEF_CFG = (
1437 sdl_mode => 0, 1432 sdl_mode => 0,
1438 width => 640, 1433 width => 640,
1439 height => 480, 1434 height => 480,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines