… | |
… | |
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 | |
… | |
… | |
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 | |
141 | sub stop_game { |
144 | sub 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 | |
145 | sub client_setup { |
156 | sub 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 | |
574 | sub metaserver_dialog { |
585 | sub 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 | |
738 | sub message_window { |
755 | sub message_window { |
… | |
… | |
801 | } |
818 | } |
802 | |
819 | |
803 | sub video_init { |
820 | sub 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 | |
881 | sub video_shutdown { |
909 | sub 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 | |
888 | my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# |
913 | my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# |
889 | my $bgmusic;#TODO#hack#d# |
914 | my $bgmusic;#TODO#hack#d# |
|
|
915 | |
|
|
916 | sub audio_channel_finished { |
|
|
917 | my ($channel) = @_; |
|
|
918 | |
|
|
919 | warn "channel $channel finished\n";#d# |
|
|
920 | } |
890 | |
921 | |
891 | sub audio_music_finished { |
922 | sub 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 & Destroy - tell pets to roam about and attack enemies"); |
|
|
1359 | $MAPWIDGET->add_command ("kill\\_pets", "kill your pets"); |
|
|
1360 | } |
|
|
1361 | |
|
|
1362 | sub conn::eof { |
|
|
1363 | stop_game; |
1324 | } |
1364 | } |
1325 | |
1365 | |
1326 | sub update_floorbox { |
1366 | sub 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} }) { |
1333 | my $desc = $item->{nrof} < 2 |
1375 | $FLOORBOX->add (new CFClient::UI::InventoryItem item => $item); |
1334 | ? $item->{name} |
|
|
1335 | : "$item->{nrof} $item->{name_pl}"; |
|
|
1336 | # todo: animation widget, face widget, weight(?) etc. |
|
|
1337 | $FLOORBOX->add (my $hbox = new CFClient::UI::HBox |
|
|
1338 | tooltip => (CFClient::UI::Label->escape ($desc) |
|
|
1339 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
|
|
1340 | can_hover => 1, |
|
|
1341 | can_events => 1, |
|
|
1342 | connect_button_down => sub { |
|
|
1343 | my ($self, $ev, $x, $y) = @_; |
|
|
1344 | |
|
|
1345 | # todo: maybe put examine on 1? but should just be a tooltip :( |
|
|
1346 | if ($ev->{button} == 1) { |
|
|
1347 | $CONN->send ("move $CONN->{player}{tag} $item->{tag} 0"); |
|
|
1348 | } elsif ($ev->{button} == 2) { |
|
|
1349 | $CONN->send ("apply $item->{tag}"); |
|
|
1350 | } elsif ($ev->{button} == 3) { |
|
|
1351 | CFClient::UI::Menu->new ( |
|
|
1352 | items => [ |
|
|
1353 | ["examine", sub { $CONN->send ("examine $item->{tag}") }], |
|
|
1354 | [ |
|
|
1355 | $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", |
|
|
1356 | sub { $CONN->send ("lock $item->{tag}") }, |
|
|
1357 | ], |
|
|
1358 | ["mark", sub { $CONN->send ("mark $item->{tag}") }], |
|
|
1359 | ["apply", sub { $CONN->send ("apply $item->{tag}") }], |
|
|
1360 | ], |
|
|
1361 | )->popup ($ev); |
|
|
1362 | } |
|
|
1363 | |
|
|
1364 | 1 |
|
|
1365 | }, |
|
|
1366 | ); |
|
|
1367 | |
|
|
1368 | $hbox->add (new CFClient::UI::Face |
|
|
1369 | can_events => 0, |
|
|
1370 | face => $item->{face}, |
|
|
1371 | anim => $item->{anim}, |
|
|
1372 | animspeed => $item->{animspeed}, |
|
|
1373 | ); |
|
|
1374 | |
|
|
1375 | $hbox->add (new CFClient::UI::Label |
|
|
1376 | can_events => 0, |
|
|
1377 | text => $desc, |
|
|
1378 | ); |
|
|
1379 | } |
1376 | } |
1380 | }); |
1377 | }); |
1381 | refresh; |
1378 | refresh; |
1382 | } |
1379 | } |
1383 | |
1380 | |
… | |
… | |
1441 | video_init; |
1438 | video_init; |
1442 | } else { |
1439 | } else { |
1443 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
1440 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
1444 | } |
1441 | } |
1445 | }, |
1442 | }, |
1446 | CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, |
1443 | CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, |
1447 | CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, |
1444 | CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, |
1448 | CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, |
1445 | CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, |
1449 | CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, |
1446 | CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, |
1450 | CFClient::SDL_USEREVENT => \&audio_music_finished, |
1447 | CFClient::SDL_USEREVENT => sub { |
|
|
1448 | if ($_[0]{code} == 1) { |
|
|
1449 | audio_channel_finished $_[0]{data1}; |
|
|
1450 | } elsif ($_[0]{code} == 0) { |
|
|
1451 | audio_music_finished; |
|
|
1452 | } |
|
|
1453 | }, |
1451 | ); |
1454 | ); |
1452 | |
1455 | |
1453 | ############################################################################# |
1456 | ############################################################################# |
1454 | |
1457 | |
1455 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
1458 | $SIG{INT} = $SIG{TERM} = sub { exit }; |