… | |
… | |
76 | our $MAPWIDGET; |
76 | our $MAPWIDGET; |
77 | our $BUTTONBAR; |
77 | our $BUTTONBAR; |
78 | our $LOGVIEW; |
78 | our $LOGVIEW; |
79 | our $CONSOLE; |
79 | our $CONSOLE; |
80 | our $METASERVER; |
80 | our $METASERVER; |
|
|
81 | our $LOGIN_BUTTON; |
81 | |
82 | |
82 | our $FLOORBOX; |
83 | our $FLOORBOX; |
83 | our $GAUGES; |
84 | our $GAUGES; |
84 | our $STATWIDS; |
85 | our $STATWIDS; |
85 | |
86 | |
… | |
… | |
106 | $DEBUG_STATUS->set_text ($_[0]); |
107 | $DEBUG_STATUS->set_text ($_[0]); |
107 | $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h}); |
108 | $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h}); |
108 | } |
109 | } |
109 | |
110 | |
110 | sub start_game { |
111 | sub start_game { |
|
|
112 | $LOGIN_BUTTON->set_text ("Logout"); |
|
|
113 | |
111 | status "logging in..."; |
114 | status "logging in..."; |
112 | |
115 | |
113 | my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
116 | my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
114 | |
117 | |
115 | $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}"; |
118 | $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}"; |
116 | |
119 | |
117 | $MAP = new CFClient::Map $mapsize, $mapsize; |
120 | $MAP = new CFClient::Map $mapsize, $mapsize; |
118 | |
121 | |
119 | my ($host, $port) = split /:/, $CFG->{host}; |
122 | my ($host, $port) = split /:/, $CFG->{host}; |
120 | |
123 | |
121 | $CONN = new conn |
124 | $CONN = eval { |
|
|
125 | new conn |
122 | host => $host, |
126 | host => $host, |
123 | port => $port || 13327, |
127 | port => $port || 13327, |
124 | user => $CFG->{user}, |
128 | user => $CFG->{user}, |
125 | pass => $CFG->{password}, |
129 | pass => $CFG->{password}, |
126 | mapw => $mapsize, |
130 | mapw => $mapsize, |
127 | maph => $mapsize, |
131 | maph => $mapsize, |
|
|
132 | ; |
128 | ; |
133 | }; |
129 | |
134 | |
|
|
135 | if ($CONN) { |
130 | status "login successful"; |
136 | status "login successful"; |
131 | |
137 | |
132 | CFClient::lowdelay fileno $CONN->{fh}; |
138 | CFClient::lowdelay fileno $CONN->{fh}; |
|
|
139 | } else { |
|
|
140 | status "unable to connect"; |
|
|
141 | stop_game(); |
|
|
142 | } |
133 | } |
143 | } |
134 | |
144 | |
135 | sub stop_game { |
145 | sub stop_game { |
|
|
146 | status "connection closed"; |
|
|
147 | $LOGIN_BUTTON->set_text ("Login"); |
136 | undef $CONN; |
148 | undef $CONN; |
137 | } |
149 | } |
138 | |
150 | |
139 | sub client_setup { |
151 | sub client_setup { |
140 | my $dialog = new CFClient::UI::FancyFrame |
152 | my $dialog = new CFClient::UI::FancyFrame |
… | |
… | |
565 | |
577 | |
566 | } |
578 | } |
567 | |
579 | |
568 | sub metaserver_dialog { |
580 | sub metaserver_dialog { |
569 | my $dialog = new CFClient::UI::FancyFrame |
581 | my $dialog = new CFClient::UI::FancyFrame |
570 | title => "Metaserver", |
582 | title => "Server List", |
571 | child => (my $vbox = new CFClient::UI::VBox); |
583 | child => (my $vbox = new CFClient::UI::VBox); |
572 | |
584 | |
573 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
585 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
574 | |
586 | |
575 | $dialog |
587 | $dialog |
… | |
… | |
720 | |
732 | |
721 | $CFG->{mapsize} = $self->{range}[0] = $value = int $value; |
733 | $CFG->{mapsize} = $self->{range}[0] = $value = int $value; |
722 | }, |
734 | }, |
723 | ); |
735 | ); |
724 | |
736 | |
725 | $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { |
737 | $table->add (1, 8, $LOGIN_BUTTON = new CFClient::UI::Button |
|
|
738 | expand => 1, |
|
|
739 | align => 0, |
|
|
740 | text => "Login", |
|
|
741 | connect_activate => sub { |
|
|
742 | $CONN ? stop_game |
726 | start_game; |
743 | : start_game; |
|
|
744 | }, |
727 | }); |
745 | ); |
728 | |
746 | |
729 | $dialog |
747 | $dialog |
730 | } |
748 | } |
731 | |
749 | |
732 | sub message_window { |
750 | sub message_window { |
… | |
… | |
783 | $window |
801 | $window |
784 | } |
802 | } |
785 | |
803 | |
786 | sub make_inventory_window { |
804 | sub make_inventory_window { |
787 | my $invwin = new CFClient::UI::FancyFrame user_w => 300, user_h => 300, title => "Inventory"; |
805 | my $invwin = new CFClient::UI::FancyFrame user_w => 300, user_h => 300, title => "Inventory"; |
788 | $invwin->add (my $hb = new CFClient::UI::HBox); |
|
|
789 | $hb->add ($INV = new CFClient::UI::Inventory expand => 1); |
806 | $invwin->add ($INV = new CFClient::UI::Inventory expand => 1); |
790 | $hb->add (my $rng = new CFClient::UI::Slider vertical => 1); |
|
|
791 | $INV->set_range ($rng); |
|
|
792 | $invwin |
807 | $invwin |
793 | } |
808 | } |
794 | |
809 | |
795 | sub sdl_init { |
810 | sub sdl_init { |
796 | CFClient::SDL_Init |
811 | CFClient::SDL_Init |
797 | and die "SDL::Init failed!\n"; |
812 | and die "SDL::Init failed!\n"; |
798 | } |
813 | } |
799 | |
814 | |
800 | sub video_init { |
815 | sub video_init { |
801 | sdl_init; |
816 | sdl_init; |
|
|
817 | |
|
|
818 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} >= @SDL_MODES; |
802 | |
819 | |
803 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
820 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
804 | $FULLSCREEN = $CFG->{fullscreen}; |
821 | $FULLSCREEN = $CFG->{fullscreen}; |
805 | $FAST = $CFG->{fast}; |
822 | $FAST = $CFG->{fast}; |
806 | |
823 | |
… | |
… | |
883 | } |
900 | } |
884 | |
901 | |
885 | my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# |
902 | my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# |
886 | my $bgmusic;#TODO#hack#d# |
903 | my $bgmusic;#TODO#hack#d# |
887 | |
904 | |
|
|
905 | sub audio_channel_finished { |
|
|
906 | my ($channel) = @_; |
|
|
907 | |
|
|
908 | warn "channel $channel finished\n";#d# |
|
|
909 | } |
|
|
910 | |
888 | sub audio_music_finished { |
911 | sub audio_music_finished { |
889 | return unless $CFG->{bgm_enable}; |
912 | return unless $CFG->{bgm_enable}; |
890 | |
913 | |
891 | # TODO: hack, do play loop and mood music |
914 | # TODO: hack, do play loop and mood music |
892 | $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]"; |
915 | $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]"; |
… | |
… | |
895 | push @bgmusic, shift @bgmusic; |
918 | push @bgmusic, shift @bgmusic; |
896 | } |
919 | } |
897 | |
920 | |
898 | sub audio_init { |
921 | sub audio_init { |
899 | if ($CFG->{audio_enable}) { |
922 | if ($CFG->{audio_enable}) { |
900 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
923 | if (open my $fh, "<", CFClient::find_rcfile "sounds/config") { |
901 | $SDL_MIXER = !CFClient::Mix_OpenAudio; |
924 | $SDL_MIXER = !CFClient::Mix_OpenAudio; |
902 | CFClient::Mix_AllocateChannels 8; |
925 | CFClient::Mix_AllocateChannels 8; |
903 | CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; |
926 | CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; |
904 | |
927 | |
905 | audio_music_finished; |
928 | audio_music_finished; |
… | |
… | |
1323 | sub update_floorbox { |
1346 | sub update_floorbox { |
1324 | $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { |
1347 | $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { |
1325 | $FLOORBOX->clear; |
1348 | $FLOORBOX->clear; |
1326 | $FLOORBOX->add (new CFClient::UI::Empty expand => 1); |
1349 | $FLOORBOX->add (new CFClient::UI::Empty expand => 1); |
1327 | |
1350 | |
1328 | my @items = values %{ $CONN->{container}{0} }; |
|
|
1329 | |
|
|
1330 | # we basically have to use the same sorting as everybody else |
1351 | # we basically have to use the same sorting as everybody else |
1331 | @items = sort { $a->{type} <=> $b->{type} } @items; |
1352 | for my $item (@{ $CONN->{container}{0} }) { |
1332 | |
1353 | $FLOORBOX->add (new CFClient::UI::InventoryItem item => $item); |
1333 | for my $item (reverse @items) { |
|
|
1334 | my $desc = $item->{nrof} < 2 |
|
|
1335 | ? $item->{name} |
|
|
1336 | : "$item->{nrof} $item->{name_pl}"; |
|
|
1337 | # todo: animation widget, face widget, weight(?) etc. |
|
|
1338 | $FLOORBOX->add (my $hbox = new CFClient::UI::HBox |
|
|
1339 | tooltip => (CFClient::UI::Label->escape ($desc) |
|
|
1340 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
|
|
1341 | can_hover => 1, |
|
|
1342 | can_events => 1, |
|
|
1343 | connect_button_down => sub { |
|
|
1344 | my ($self, $ev, $x, $y) = @_; |
|
|
1345 | |
|
|
1346 | # todo: maybe put examine on 1? but should just be a tooltip :( |
|
|
1347 | if ($ev->{button} == 1) { |
|
|
1348 | $CONN->send ("move $CONN->{player}{tag} $item->{tag} 0"); |
|
|
1349 | } elsif ($ev->{button} == 2) { |
|
|
1350 | $CONN->send ("apply $item->{tag}"); |
|
|
1351 | } elsif ($ev->{button} == 3) { |
|
|
1352 | CFClient::UI::Menu->new ( |
|
|
1353 | items => [ |
|
|
1354 | ["examine", sub { $CONN->send ("examine $item->{tag}") }], |
|
|
1355 | [ |
|
|
1356 | $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", |
|
|
1357 | sub { $CONN->send ("lock $item->{tag}") }, |
|
|
1358 | ], |
|
|
1359 | ["mark", sub { $CONN->send ("mark $item->{tag}") }], |
|
|
1360 | ["apply", sub { $CONN->send ("apply $item->{tag}") }], |
|
|
1361 | ], |
|
|
1362 | )->popup ($ev); |
|
|
1363 | } |
|
|
1364 | |
|
|
1365 | 1 |
|
|
1366 | }, |
|
|
1367 | ); |
|
|
1368 | |
|
|
1369 | $hbox->add (new CFClient::UI::Face |
|
|
1370 | can_events => 0, |
|
|
1371 | face => $item->{face}, |
|
|
1372 | anim => $item->{anim}, |
|
|
1373 | animspeed => $item->{animspeed}, |
|
|
1374 | ); |
|
|
1375 | |
|
|
1376 | $hbox->add (new CFClient::UI::Label |
|
|
1377 | can_events => 0, |
|
|
1378 | text => $desc, |
|
|
1379 | ); |
|
|
1380 | } |
1354 | } |
1381 | }); |
1355 | }); |
1382 | refresh; |
1356 | refresh; |
1383 | } |
1357 | } |
1384 | |
1358 | |
… | |
… | |
1442 | video_init; |
1416 | video_init; |
1443 | } else { |
1417 | } else { |
1444 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
1418 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
1445 | } |
1419 | } |
1446 | }, |
1420 | }, |
1447 | CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, |
1421 | CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, |
1448 | CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, |
1422 | CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, |
1449 | CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, |
1423 | CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, |
1450 | CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, |
1424 | CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, |
1451 | CFClient::SDL_USEREVENT => \&audio_music_finished, |
1425 | CFClient::SDL_USEREVENT => sub { |
|
|
1426 | if ($_[0]{code} == 1) { |
|
|
1427 | audio_channel_finished $_[0]{data1}; |
|
|
1428 | } elsif ($_[0]{code} == 0) { |
|
|
1429 | audio_music_finished; |
|
|
1430 | } |
|
|
1431 | }, |
1452 | ); |
1432 | ); |
1453 | |
1433 | |
1454 | ############################################################################# |
1434 | ############################################################################# |
1455 | |
1435 | |
1456 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
1436 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
|
|
1437 | |
|
|
1438 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
1457 | |
1439 | |
1458 | $TILECACHE = CFClient::db_table "tilecache"; |
1440 | $TILECACHE = CFClient::db_table "tilecache"; |
1459 | $FACEMAP = CFClient::db_table "facemap"; |
1441 | $FACEMAP = CFClient::db_table "facemap"; |
1460 | |
|
|
1461 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
|
|
1462 | |
1442 | |
1463 | my %DEF_CFG = ( |
1443 | my %DEF_CFG = ( |
1464 | sdl_mode => 0, |
1444 | sdl_mode => 0, |
1465 | width => 640, |
1445 | width => 640, |
1466 | height => 480, |
1446 | height => 480, |