… | |
… | |
37 | use CFClient; |
37 | use CFClient; |
38 | use CFClient::UI; |
38 | use CFClient::UI; |
39 | use CFClient::MapWidget; |
39 | use CFClient::MapWidget; |
40 | |
40 | |
41 | $Event::DIED = sub { |
41 | $Event::DIED = sub { |
|
|
42 | # TODO: display dialog box or so |
42 | CFClient::error $_[1]; |
43 | CFClient::error $_[1]; |
43 | }; |
44 | }; |
44 | |
45 | |
45 | #$SIG{__WARN__} = sub { Carp::cluck $_[0] };#d# |
46 | #$SIG{__WARN__} = sub { Carp::cluck $_[0] };#d# |
46 | |
47 | |
… | |
… | |
59 | our $NOW; |
60 | our $NOW; |
60 | |
61 | |
61 | our $CFG; |
62 | our $CFG; |
62 | our $CONN; |
63 | our $CONN; |
63 | our $FAST; # fast, low-quality mode, possibly useful for software-rendering |
64 | our $FAST; # fast, low-quality mode, possibly useful for software-rendering |
|
|
65 | |
|
|
66 | our $WANT_REFRESH; |
|
|
67 | our $CAN_REFRESH; |
64 | |
68 | |
65 | our @SDL_MODES; |
69 | our @SDL_MODES; |
66 | our $WIDTH; |
70 | our $WIDTH; |
67 | our $HEIGHT; |
71 | our $HEIGHT; |
68 | our $FULLSCREEN; |
72 | our $FULLSCREEN; |
… | |
… | |
76 | our $MAPWIDGET; |
80 | our $MAPWIDGET; |
77 | our $BUTTONBAR; |
81 | our $BUTTONBAR; |
78 | our $LOGVIEW; |
82 | our $LOGVIEW; |
79 | our $CONSOLE; |
83 | our $CONSOLE; |
80 | our $METASERVER; |
84 | our $METASERVER; |
|
|
85 | our $LOGIN_BUTTON; |
81 | |
86 | |
82 | our $FLOORBOX; |
87 | our $FLOORBOX; |
83 | our $GAUGES; |
88 | our $GAUGES; |
84 | our $STATWIDS; |
89 | our $STATWIDS; |
85 | |
90 | |
… | |
… | |
96 | |
101 | |
97 | our $INVWIN; |
102 | our $INVWIN; |
98 | our $INV; |
103 | our $INV; |
99 | |
104 | |
100 | sub status { |
105 | sub status { |
101 | $STATUS_LINE->set_text ($_[0]); |
106 | $STATUS_LINE->add ($_[0], pri => -10, group => "status", timeout => 20, color => [1, 1, 0, 1]); |
102 | $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h}); |
107 | $CFClient::UI::ROOT->on_refresh ($STATUS_LINE => sub { |
|
|
108 | $STATUS_LINE->move (0, $HEIGHT - $STATUS_LINE->{h});#d# to in toplevel |
|
|
109 | }); |
103 | } |
110 | } |
104 | |
111 | |
105 | sub debug { |
112 | sub debug { |
106 | $DEBUG_STATUS->set_text ($_[0]); |
113 | $DEBUG_STATUS->set_text ($_[0]); |
107 | $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h}); |
114 | my ($w, $h) = $DEBUG_STATUS->size_request; |
|
|
115 | $DEBUG_STATUS->move ($WIDTH - $w, 0); |
108 | } |
116 | } |
109 | |
117 | |
110 | sub start_game { |
118 | sub start_game { |
111 | status "logging in..."; |
119 | status "logging in..."; |
112 | |
120 | |
113 | my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
121 | my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
114 | |
122 | |
115 | $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}"; |
123 | $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}"; |
116 | |
|
|
117 | $MAP = new CFClient::Map $mapsize, $mapsize; |
124 | $MAP = new CFClient::Map $mapsize, $mapsize; |
118 | |
125 | |
119 | my ($host, $port) = split /:/, $CFG->{host}; |
126 | my ($host, $port) = split /:/, $CFG->{host}; |
120 | |
127 | |
121 | $CONN = eval { |
128 | $CONN = eval { |
… | |
… | |
128 | maph => $mapsize, |
135 | maph => $mapsize, |
129 | ; |
136 | ; |
130 | }; |
137 | }; |
131 | |
138 | |
132 | if ($CONN) { |
139 | if ($CONN) { |
|
|
140 | $LOGIN_BUTTON->set_text ("Logout"); |
|
|
141 | |
133 | status "login successful"; |
142 | status "login successful"; |
134 | |
143 | |
135 | CFClient::lowdelay fileno $CONN->{fh}; |
144 | CFClient::lowdelay fileno $CONN->{fh}; |
136 | } else { |
145 | } else { |
137 | status "unable to connect"; |
146 | status "unable to connect"; |
|
|
147 | stop_game(); |
138 | } |
148 | } |
139 | } |
149 | } |
140 | |
150 | |
141 | sub stop_game { |
151 | sub stop_game { |
|
|
152 | return unless $CONN; |
|
|
153 | |
|
|
154 | status "connection closed"; |
|
|
155 | $LOGIN_BUTTON->set_text ("Login"); |
|
|
156 | $CONN->destroy; |
|
|
157 | $CONN = 0; # false, does not autovivify |
|
|
158 | |
|
|
159 | undef $MAPCACHE; |
142 | undef $CONN; |
160 | undef $MAP; |
143 | } |
161 | } |
144 | |
162 | |
145 | sub client_setup { |
163 | sub client_setup { |
146 | my $dialog = new CFClient::UI::FancyFrame |
164 | my $dialog = new CFClient::UI::FancyFrame |
147 | title => "Client Setup", |
165 | title => "Client Setup", |
… | |
… | |
571 | |
589 | |
572 | } |
590 | } |
573 | |
591 | |
574 | sub metaserver_dialog { |
592 | sub metaserver_dialog { |
575 | my $dialog = new CFClient::UI::FancyFrame |
593 | my $dialog = new CFClient::UI::FancyFrame |
576 | title => "Metaserver", |
594 | title => "Server List", |
577 | child => (my $vbox = new CFClient::UI::VBox); |
595 | child => (my $vbox = new CFClient::UI::VBox); |
578 | |
596 | |
579 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
597 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
580 | |
598 | |
581 | $dialog |
599 | $dialog |
… | |
… | |
683 | |
701 | |
684 | $METASERVER = metaserver_dialog; |
702 | $METASERVER = metaserver_dialog; |
685 | |
703 | |
686 | $vbox->add (new CFClient::UI::Flopper |
704 | $vbox->add (new CFClient::UI::Flopper |
687 | expand => 1, |
705 | expand => 1, |
688 | text => "Metaserver", |
706 | text => "Server List", |
689 | other => $METASERVER, |
707 | other => $METASERVER, |
690 | tooltip => "Show a list of avaible crossfire servers", |
708 | tooltip => "Show a list of available crossfire servers", |
691 | connect_open => sub { |
709 | connect_open => sub { |
692 | update_metaserver $HOST; |
710 | update_metaserver $HOST; |
693 | } |
711 | } |
694 | ); |
712 | ); |
695 | } |
713 | } |
… | |
… | |
726 | |
744 | |
727 | $CFG->{mapsize} = $self->{range}[0] = $value = int $value; |
745 | $CFG->{mapsize} = $self->{range}[0] = $value = int $value; |
728 | }, |
746 | }, |
729 | ); |
747 | ); |
730 | |
748 | |
731 | $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { |
749 | $table->add (1, 8, $LOGIN_BUTTON = new CFClient::UI::Button |
|
|
750 | expand => 1, |
|
|
751 | align => 0, |
|
|
752 | text => "Login", |
|
|
753 | connect_activate => sub { |
|
|
754 | $CONN ? stop_game |
732 | start_game; |
755 | : start_game; |
|
|
756 | }, |
733 | }); |
757 | ); |
734 | |
758 | |
735 | $dialog |
759 | $dialog |
736 | } |
760 | } |
737 | |
761 | |
738 | sub message_window { |
762 | sub message_window { |
… | |
… | |
801 | } |
825 | } |
802 | |
826 | |
803 | sub video_init { |
827 | sub video_init { |
804 | sdl_init; |
828 | sdl_init; |
805 | |
829 | |
|
|
830 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} >= @SDL_MODES; |
|
|
831 | |
806 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
832 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
807 | $FULLSCREEN = $CFG->{fullscreen}; |
833 | $FULLSCREEN = $CFG->{fullscreen}; |
808 | $FAST = $CFG->{fast}; |
834 | $FAST = $CFG->{fast}; |
809 | |
835 | |
810 | CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN |
836 | CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN |
811 | or die "SDL_SetVideoMode failed!\n"; |
837 | or die "SDL_SetVideoMode failed!\n"; |
812 | |
838 | |
813 | $SDL_ACTIVE = 1; |
839 | $SDL_ACTIVE = 1; |
814 | |
|
|
815 | $LAST_REFRESH = time - 0.01; |
840 | $LAST_REFRESH = time - 0.01; |
816 | |
841 | |
817 | CFClient::gl_init; |
842 | CFClient::gl_init; |
818 | |
843 | |
819 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
844 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
820 | |
845 | |
|
|
846 | $CFClient::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# |
|
|
847 | |
821 | ############################################################################# |
848 | ############################################################################# |
822 | |
849 | |
|
|
850 | if ($DEBUG_STATUS) { |
|
|
851 | # reconfigure all widgets |
|
|
852 | $CFClient::UI::ROOT->reconfigure; |
|
|
853 | |
|
|
854 | } else { |
|
|
855 | # create the widgets |
|
|
856 | |
823 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
857 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100, text => "hulla", x => 100;#d# |
824 | $DEBUG_STATUS->show; |
858 | $DEBUG_STATUS->show; |
825 | |
859 | |
826 | $STATUS_LINE = new CFClient::UI::Label |
860 | $STATUS_LINE = new CFClient::UI::Statusbox; |
827 | padding => 0, |
861 | $STATUS_LINE->add ("Use <b>Alt-Enter</b> to toggle fullscreen mode", pri => -100, size => 0.8, color => [1, 1, 1, 0.8]); |
828 | y => $HEIGHT - $FONTSIZE * 1.8; |
|
|
829 | $STATUS_LINE->show; |
862 | $STATUS_LINE->show; |
830 | |
863 | |
831 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
|
|
832 | padding => 0, |
|
|
833 | fontsize => 0.8, |
|
|
834 | markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
|
|
835 | $ALT_ENTER_MESSAGE->show; |
|
|
836 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); |
|
|
837 | |
|
|
838 | CFClient::UI::FancyFrame->new ( |
864 | CFClient::UI::FancyFrame->new ( |
839 | border_bg => [1, 1, 1, 192/255], |
865 | border_bg => [1, 1, 1, 192/255], |
840 | bg => [1, 1, 1, 0], |
866 | bg => [1, 1, 1, 0], |
841 | child => ($MAPMAP = new CFClient::MapWidget::MapMap), |
867 | child => ($MAPMAP = new CFClient::MapWidget::MapMap), |
842 | )->show; |
868 | )->show; |
843 | |
869 | |
844 | $MAPWIDGET = new CFClient::MapWidget; |
870 | $MAPWIDGET = new CFClient::MapWidget; |
845 | $MAPWIDGET->connect (activate_console => sub { |
871 | $MAPWIDGET->connect (activate_console => sub { |
846 | my ($mapwidget, $preset) = @_; |
872 | my ($mapwidget, $preset) = @_; |
847 | |
873 | |
848 | if ($CONSOLE) { |
874 | if ($CONSOLE) { |
849 | $CONSOLE->{input}->{auto_activated} = 1; |
875 | $CONSOLE->{input}->{auto_activated} = 1; |
850 | $CONSOLE->{input}->focus_in; |
876 | $CONSOLE->{input}->focus_in; |
851 | |
877 | |
852 | if ($preset && $CONSOLE->{input}->get_text eq '') { |
878 | if ($preset && $CONSOLE->{input}->get_text eq '') { |
853 | $CONSOLE->{input}->set_text ($preset); |
879 | $CONSOLE->{input}->set_text ($preset); |
|
|
880 | } |
854 | } |
881 | } |
855 | } |
882 | }); |
856 | }); |
|
|
857 | $MAPWIDGET->show; |
883 | $MAPWIDGET->show; |
858 | $MAPWIDGET->focus_in; |
884 | $MAPWIDGET->focus_in; |
859 | |
885 | |
860 | $BUTTONBAR = new CFClient::UI::HBox; |
886 | $BUTTONBAR = new CFClient::UI::HBox; |
861 | |
887 | |
862 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup); |
888 | $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); |
889 | $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); |
890 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window); |
865 | |
891 | |
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 |
892 | 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 | |
893 | |
868 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window); |
894 | $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); |
895 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Inventory", other => make_inventory_window); |
870 | |
896 | |
871 | $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { |
897 | $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { |
872 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
898 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
873 | status "Configuration Saved"; |
899 | status "Configuration Saved"; |
874 | }); |
900 | }); |
875 | |
901 | |
876 | $BUTTONBAR->show; |
902 | $BUTTONBAR->show; |
877 | |
903 | |
|
|
904 | # delay till geometry is constant |
|
|
905 | $CFClient::UI::ROOT->on_refresh (startup => sub { |
878 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
906 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
|
|
907 | }); |
|
|
908 | force_refresh (); |
|
|
909 | } |
879 | } |
910 | } |
880 | |
911 | |
881 | sub video_shutdown { |
912 | sub video_shutdown { |
882 | $CFClient::UI::ROOT->{children} = []; |
|
|
883 | undef $CFClient::UI::GRAB; |
|
|
884 | undef $CFClient::UI::HOVER; |
|
|
885 | undef $SDL_ACTIVE; |
913 | undef $SDL_ACTIVE; |
886 | } |
914 | } |
887 | |
915 | |
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# |
916 | 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# |
917 | my $bgmusic;#TODO#hack#d# |
|
|
918 | |
|
|
919 | sub audio_channel_finished { |
|
|
920 | my ($channel) = @_; |
|
|
921 | |
|
|
922 | warn "channel $channel finished\n";#d# |
|
|
923 | } |
890 | |
924 | |
891 | sub audio_music_finished { |
925 | sub audio_music_finished { |
892 | return unless $CFG->{bgm_enable}; |
926 | return unless $CFG->{bgm_enable}; |
893 | |
927 | |
894 | # TODO: hack, do play loop and mood music |
928 | # TODO: hack, do play loop and mood music |
… | |
… | |
935 | } |
969 | } |
936 | |
970 | |
937 | my %animate_object; |
971 | my %animate_object; |
938 | my $animate_timer; |
972 | my $animate_timer; |
939 | |
973 | |
940 | my $want_refresh; |
|
|
941 | my $can_refresh; |
|
|
942 | |
|
|
943 | my $fps = 9; |
974 | my $fps = 9; |
944 | |
975 | |
945 | sub force_refresh { |
976 | sub force_refresh { |
946 | $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05; |
977 | $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05; |
947 | debug sprintf "%3.2f", $fps; |
978 | debug sprintf "%3.2f", $fps; |
948 | |
979 | |
949 | $want_refresh = 0; |
|
|
950 | $can_refresh = 0; |
|
|
951 | |
|
|
952 | $CFClient::UI::ROOT->draw; |
980 | $CFClient::UI::ROOT->draw; |
953 | |
|
|
954 | CFClient::SDL_GL_SwapBuffers; |
981 | CFClient::SDL_GL_SwapBuffers; |
955 | |
982 | |
|
|
983 | $WANT_REFRESH = 0; |
|
|
984 | $CAN_REFRESH = 0; |
956 | $LAST_REFRESH = $NOW; |
985 | $LAST_REFRESH = $NOW; |
957 | } |
986 | } |
958 | |
987 | |
959 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
988 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
960 | $NOW = time; |
989 | $NOW = time; |
… | |
… | |
962 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
991 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
963 | for CFClient::SDL_PollEvent; |
992 | for CFClient::SDL_PollEvent; |
964 | |
993 | |
965 | if (%animate_object) { |
994 | if (%animate_object) { |
966 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
995 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
967 | $want_refresh++; |
996 | $WANT_REFRESH++; |
968 | } |
997 | } |
969 | |
998 | |
970 | if ($want_refresh) { |
999 | if ($WANT_REFRESH) { |
971 | force_refresh; |
1000 | force_refresh; |
972 | } else { |
1001 | } else { |
973 | $can_refresh = 1; |
1002 | $CAN_REFRESH = 1; |
974 | } |
1003 | } |
975 | }); |
1004 | }); |
976 | |
|
|
977 | sub refresh { |
|
|
978 | $want_refresh++; |
|
|
979 | } |
|
|
980 | |
1005 | |
981 | sub animation_start { |
1006 | sub animation_start { |
982 | my ($widget) = @_; |
1007 | my ($widget) = @_; |
983 | $animate_object{$widget} = $widget; |
1008 | $animate_object{$widget} = $widget; |
984 | } |
1009 | } |
… | |
… | |
1296 | [0.55, 0.41, 0.13], |
1321 | [0.55, 0.41, 0.13], |
1297 | [0.99, 0.77, 0.26], |
1322 | [0.99, 0.77, 0.26], |
1298 | [0.74, 0.65, 0.41], |
1323 | [0.74, 0.65, 0.41], |
1299 | ); |
1324 | ); |
1300 | |
1325 | |
|
|
1326 | my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
|
|
1327 | |
|
|
1328 | $text =~ s/&/&/g; $text =~ s/</</g; |
|
|
1329 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
|
|
1330 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
|
|
1331 | |
1301 | $LOGVIEW->add_paragraph ($color[$color], $text); |
1332 | $LOGVIEW->add_paragraph ($color[$color], |
|
|
1333 | join "\n", map "$time $_", split /\n/, $text); |
|
|
1334 | $STATUS_LINE->add ($text, color => $color[$color], timeout => 60); |
|
|
1335 | } |
|
|
1336 | |
|
|
1337 | sub conn::drawextinfo { |
|
|
1338 | my ($self, $color, $type, $subtype, $message) = @_; |
|
|
1339 | |
|
|
1340 | $self->drawinfo ($color, $message); |
1302 | } |
1341 | } |
1303 | |
1342 | |
1304 | sub conn::spell_add { |
1343 | sub conn::spell_add { |
1305 | my ($self, $spell) = @_; |
1344 | my ($self, $spell) = @_; |
1306 | |
1345 | |
… | |
… | |
1319 | |
1358 | |
1320 | for my $skill (values %{$self->{skill_info}}) { |
1359 | for my $skill (values %{$self->{skill_info}}) { |
1321 | $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'"); |
1360 | $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'"); |
1322 | $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'"); |
1361 | $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'"); |
1323 | } |
1362 | } |
|
|
1363 | |
|
|
1364 | $MAPWIDGET->add_command ("pet\\_mode defend", "Tell pets to stay close to you and defend you"); |
|
|
1365 | $MAPWIDGET->add_command ("pet\\_mode arena", "Same as petmode attack, but also attack other players"); |
|
|
1366 | $MAPWIDGET->add_command ("pet\\_mode sad", "Search & Destroy - tell pets to roam about and attack enemies"); |
|
|
1367 | $MAPWIDGET->add_command ("kill\\_pets", "kill your pets"); |
|
|
1368 | } |
|
|
1369 | |
|
|
1370 | sub conn::eof { |
|
|
1371 | stop_game; |
1324 | } |
1372 | } |
1325 | |
1373 | |
1326 | sub update_floorbox { |
1374 | sub update_floorbox { |
1327 | $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { |
1375 | $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { |
|
|
1376 | return unless $CONN; |
|
|
1377 | |
1328 | $FLOORBOX->clear; |
1378 | $FLOORBOX->clear; |
1329 | $FLOORBOX->add (new CFClient::UI::Empty expand => 1); |
1379 | $FLOORBOX->add (new CFClient::UI::Empty expand => 1); |
1330 | |
1380 | |
1331 | # we basically have to use the same sorting as everybody else |
1381 | my $count = 4; |
1332 | for my $item (@{ $CONN->{container}{0} }) { |
1382 | for (@{ $CONN->{container}{0} }) { |
1333 | my $desc = $item->{nrof} < 2 |
1383 | if (--$count) { |
1334 | ? $item->{name} |
1384 | $FLOORBOX->add (new CFClient::UI::InventoryItem item => $_); |
1335 | : "$item->{nrof} $item->{name_pl}"; |
1385 | } else { |
1336 | # todo: animation widget, face widget, weight(?) etc. |
1386 | $FLOORBOX->add (new CFClient::UI::Label text => "More..."); |
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 | }, |
1387 | last; |
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 | |
1388 | } |
1375 | $hbox->add (new CFClient::UI::Label |
|
|
1376 | can_events => 0, |
|
|
1377 | text => $desc, |
|
|
1378 | ); |
|
|
1379 | } |
1389 | } |
1380 | }); |
1390 | }); |
1381 | refresh; |
1391 | |
|
|
1392 | $WANT_REFRESH++; |
1382 | } |
1393 | } |
1383 | |
1394 | |
1384 | sub conn::container_add { |
1395 | sub conn::container_add { |
1385 | my ($self, $id, $items) = @_; |
1396 | my ($self, $tag, $items) = @_; |
1386 | |
1397 | |
1387 | update_floorbox if $id == 0; |
1398 | update_floorbox if $tag == 0; |
1388 | if ($self->{player}{tag} == $id) { |
1399 | |
1389 | $INV->set_items ($self->{container}{$self->{player}{tag}}); |
1400 | $INV->set_items ($self->{container}{$self->{player}{tag}}) |
1390 | } |
1401 | if $tag == $self->{player}{tag}; |
|
|
1402 | |
1391 | # $self-<{player}{tag} => player inv |
1403 | # $self-<{player}{tag} => player inv |
1392 | #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; |
1404 | #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; |
1393 | } |
1405 | } |
1394 | |
1406 | |
1395 | sub conn::container_clear { |
1407 | sub conn::container_clear { |
1396 | my ($self, $id) = @_; |
1408 | my ($self, $tag) = @_; |
1397 | |
1409 | |
1398 | update_floorbox if $id == 0; |
1410 | update_floorbox if $tag == 0; |
1399 | if ($self->{player}{tag} == $id) { |
1411 | |
1400 | $INV->set_items ($self->{container}{$id}); |
1412 | $INV->set_items ($self->{container}{$tag}) |
1401 | } |
1413 | if $tag == $self->{player}{tag}; |
1402 | |
1414 | |
1403 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
1415 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
1404 | } |
1416 | } |
1405 | |
1417 | |
1406 | sub conn::item_delete { |
1418 | sub conn::item_delete { |
1407 | my ($self, @items) = @_; |
1419 | my ($self, @items) = @_; |
1408 | |
1420 | |
1409 | for (@items) { |
1421 | for (@items) { |
1410 | update_floorbox if $_->{container} == 0; |
1422 | update_floorbox if $_->{container} == 0; |
1411 | if ($self->{player}{tag} == $_->{container}) { |
1423 | |
1412 | $INV->set_items ($self->{container}{$_->{container}}); |
1424 | $INV->set_items ($self->{container}{$_->{container}}) |
1413 | } |
1425 | if $_->{container} == $self->{player}{tag}; |
1414 | } |
1426 | } |
1415 | } |
1427 | } |
1416 | |
1428 | |
1417 | sub conn::item_update { |
1429 | sub conn::item_update { |
1418 | my ($self, $item) = @_; |
1430 | my ($self, $item) = @_; |
1419 | |
1431 | |
1420 | update_floorbox if $item->{container} == 0; |
1432 | update_floorbox if $item->{container} == 0; |
1421 | if ($self->{player}{tag} == $item->{container}) { |
1433 | |
1422 | $INV->set_items ($self->{container}{$item->{container}}); |
1434 | $INV->set_items ($self->{container}{$item->{container}}) |
1423 | } |
1435 | if $item->{container} == $self->{player}{tag}; |
1424 | } |
1436 | } |
1425 | |
1437 | |
1426 | %SDL_CB = ( |
1438 | %SDL_CB = ( |
1427 | CFClient::SDL_QUIT => sub { |
1439 | CFClient::SDL_QUIT => sub { |
1428 | Event::unloop -1; |
1440 | Event::unloop -1; |
1429 | }, |
1441 | }, |
1430 | CFClient::SDL_VIDEORESIZE => sub { |
1442 | CFClient::SDL_VIDEORESIZE => sub { |
1431 | }, |
1443 | }, |
1432 | CFClient::SDL_VIDEOEXPOSE => \&refresh, |
1444 | CFClient::SDL_VIDEOEXPOSE => sub { |
|
|
1445 | $WANT_REFRESH++; |
|
|
1446 | }, |
1433 | CFClient::SDL_ACTIVEEVENT => sub { |
1447 | CFClient::SDL_ACTIVEEVENT => sub { |
1434 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
1448 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
1435 | }, |
1449 | }, |
1436 | CFClient::SDL_KEYDOWN => sub { |
1450 | CFClient::SDL_KEYDOWN => sub { |
1437 | if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { |
1451 | if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { |
… | |
… | |
1441 | video_init; |
1455 | video_init; |
1442 | } else { |
1456 | } else { |
1443 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
1457 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
1444 | } |
1458 | } |
1445 | }, |
1459 | }, |
1446 | CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, |
1460 | CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, |
1447 | CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, |
1461 | CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, |
1448 | CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, |
1462 | CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, |
1449 | CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, |
1463 | CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, |
1450 | CFClient::SDL_USEREVENT => \&audio_music_finished, |
1464 | CFClient::SDL_USEREVENT => sub { |
|
|
1465 | if ($_[0]{code} == 1) { |
|
|
1466 | audio_channel_finished $_[0]{data1}; |
|
|
1467 | } elsif ($_[0]{code} == 0) { |
|
|
1468 | audio_music_finished; |
|
|
1469 | } |
|
|
1470 | }, |
1451 | ); |
1471 | ); |
1452 | |
1472 | |
1453 | ############################################################################# |
1473 | ############################################################################# |
1454 | |
1474 | |
1455 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
1475 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
1456 | |
1476 | |
1457 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
|
|
1458 | |
|
|
1459 | $TILECACHE = CFClient::db_table "tilecache"; |
|
|
1460 | $FACEMAP = CFClient::db_table "facemap"; |
|
|
1461 | |
|
|
1462 | my %DEF_CFG = ( |
|
|
1463 | sdl_mode => 0, |
|
|
1464 | width => 640, |
|
|
1465 | height => 480, |
|
|
1466 | fullscreen => 0, |
|
|
1467 | fast => 0, |
|
|
1468 | map_scale => 0.5, |
|
|
1469 | fow_enable => 1, |
|
|
1470 | fow_intensity => 0.45, |
|
|
1471 | fow_smooth => 0, |
|
|
1472 | gui_fontsize => 1, |
|
|
1473 | log_fontsize => 1, |
|
|
1474 | gauge_fontsize => 1, |
|
|
1475 | gauge_size => 0.35, |
|
|
1476 | stat_fontsize => 1, |
|
|
1477 | mapsize => 100, |
|
|
1478 | host => "crossfire.schmorp.de", |
|
|
1479 | say_command => 'say', |
|
|
1480 | audio_enable => 1, |
|
|
1481 | bgm_enable => 1, |
|
|
1482 | bgm_volume => 0.25, |
|
|
1483 | ); |
|
|
1484 | |
|
|
1485 | while (my ($k, $v) = each %DEF_CFG) { |
|
|
1486 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
|
|
1487 | } |
|
|
1488 | |
|
|
1489 | sdl_init; |
|
|
1490 | |
|
|
1491 | @SDL_MODES = reverse |
|
|
1492 | grep $_->[0] >= 640 && $_->[1] >= 480, |
|
|
1493 | CFClient::SDL_ListModes; |
|
|
1494 | |
|
|
1495 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
|
|
1496 | |
|
|
1497 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
|
|
1498 | |
|
|
1499 | { |
1477 | { |
|
|
1478 | local $SIG{__DIE__} = sub { CFClient::fatal $_[0] }; |
|
|
1479 | |
|
|
1480 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
|
|
1481 | |
|
|
1482 | $TILECACHE = CFClient::db_table "tilecache"; |
|
|
1483 | $FACEMAP = CFClient::db_table "facemap"; |
|
|
1484 | |
|
|
1485 | my %DEF_CFG = ( |
|
|
1486 | sdl_mode => 0, |
|
|
1487 | width => 640, |
|
|
1488 | height => 480, |
|
|
1489 | fullscreen => 0, |
|
|
1490 | fast => 0, |
|
|
1491 | map_scale => 0.5, |
|
|
1492 | fow_enable => 1, |
|
|
1493 | fow_intensity => 0.45, |
|
|
1494 | fow_smooth => 0, |
|
|
1495 | gui_fontsize => 1, |
|
|
1496 | log_fontsize => 1, |
|
|
1497 | gauge_fontsize=> 1, |
|
|
1498 | gauge_size => 0.35, |
|
|
1499 | stat_fontsize => 1, |
|
|
1500 | mapsize => 100, |
|
|
1501 | host => "crossfire.schmorp.de", |
|
|
1502 | say_command => 'say', |
|
|
1503 | audio_enable => 1, |
|
|
1504 | bgm_enable => 1, |
|
|
1505 | bgm_volume => 0.25, |
|
|
1506 | ); |
|
|
1507 | |
|
|
1508 | while (my ($k, $v) = each %DEF_CFG) { |
|
|
1509 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
|
|
1510 | } |
|
|
1511 | |
|
|
1512 | sdl_init; |
|
|
1513 | |
|
|
1514 | @SDL_MODES = reverse |
|
|
1515 | grep $_->[0] >= 640 && $_->[1] >= 480, |
|
|
1516 | CFClient::SDL_ListModes; |
|
|
1517 | |
|
|
1518 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
|
|
1519 | |
|
|
1520 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
|
|
1521 | |
|
|
1522 | { |
1500 | my @fonts = map CFClient::find_rcfile "fonts/$_", qw( |
1523 | my @fonts = map CFClient::find_rcfile "fonts/$_", qw( |
1501 | DejaVuSans.ttf |
1524 | DejaVuSans.ttf |
1502 | DejaVuSansMono.ttf |
1525 | DejaVuSansMono.ttf |
1503 | DejaVuSans-Bold.ttf |
1526 | DejaVuSans-Bold.ttf |
1504 | DejaVuSansMono-Bold.ttf |
1527 | DejaVuSansMono-Bold.ttf |
1505 | DejaVuSans-Oblique.ttf |
1528 | DejaVuSans-Oblique.ttf |
1506 | DejaVuSansMono-Oblique.ttf |
1529 | DejaVuSansMono-Oblique.ttf |
1507 | DejaVuSans-BoldOblique.ttf |
1530 | DejaVuSans-BoldOblique.ttf |
1508 | DejaVuSansMono-BoldOblique.ttf |
1531 | DejaVuSansMono-BoldOblique.ttf |
1509 | ); |
1532 | ); |
1510 | |
1533 | |
1511 | CFClient::add_font $_ for @fonts; |
1534 | CFClient::add_font $_ for @fonts; |
1512 | |
1535 | |
1513 | $FONT_PROP = new_from_file CFClient::Font $fonts[0]; |
1536 | $FONT_PROP = new_from_file CFClient::Font $fonts[0]; |
1514 | $FONT_FIXED = new_from_file CFClient::Font $fonts[1]; |
1537 | $FONT_FIXED = new_from_file CFClient::Font $fonts[1]; |
1515 | |
1538 | |
1516 | $FONT_PROP->make_default; |
1539 | $FONT_PROP->make_default; |
1517 | } |
1540 | } |
1518 | |
1541 | |
1519 | video_init; |
1542 | video_init; |
1520 | audio_init; |
1543 | audio_init; |
|
|
1544 | } |
1521 | |
1545 | |
1522 | Event::loop; |
1546 | Event::loop; |
1523 | |
1547 | |
1524 | END { CFClient::SDL_Quit } |
1548 | END { CFClient::SDL_Quit } |
1525 | |
1549 | |