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.195 by root, Sun Apr 30 11:17:09 2006 UTC vs.
Revision 1.216 by root, Mon May 15 17:45:31 2006 UTC

37use CFClient; 37use CFClient;
38use CFClient::UI; 38use CFClient::UI;
39use CFClient::MapWidget; 39use 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
59our $NOW; 60our $NOW;
60 61
61our $CFG; 62our $CFG;
62our $CONN; 63our $CONN;
63our $FAST; # fast, low-quality mode, possibly useful for software-rendering 64our $FAST; # fast, low-quality mode, possibly useful for software-rendering
65
66our $WANT_REFRESH;
67our $CAN_REFRESH;
64 68
65our @SDL_MODES; 69our @SDL_MODES;
66our $WIDTH; 70our $WIDTH;
67our $HEIGHT; 71our $HEIGHT;
68our $FULLSCREEN; 72our $FULLSCREEN;
76our $MAPWIDGET; 80our $MAPWIDGET;
77our $BUTTONBAR; 81our $BUTTONBAR;
78our $LOGVIEW; 82our $LOGVIEW;
79our $CONSOLE; 83our $CONSOLE;
80our $METASERVER; 84our $METASERVER;
85our $LOGIN_BUTTON;
81 86
82our $FLOORBOX; 87our $FLOORBOX;
83our $GAUGES; 88our $GAUGES;
84our $STATWIDS; 89our $STATWIDS;
85 90
89our $SDL_MIXER; 94our $SDL_MIXER;
90our @SOUNDS; # event => file mapping 95our @SOUNDS; # event => file mapping
91our %AUDIO_CHUNKS; # audio files 96our %AUDIO_CHUNKS; # audio files
92 97
93our $ALT_ENTER_MESSAGE; 98our $ALT_ENTER_MESSAGE;
94our $STATUS_LINE; 99our $STATUSBOX;
95our $DEBUG_STATUS; 100our $DEBUG_STATUS;
96 101
97our $INVWIN; 102our $INVWIN;
98our $INV; 103our $INV;
99 104
100sub status { 105sub status {
101 $STATUS_LINE->set_text ($_[0]); 106 $STATUSBOX->add ($_[0], pri => -10, group => "status", timeout => 20, fg => [1, 1, 0, 1]);
102 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h});
103} 107}
104 108
105sub debug { 109sub debug {
106 $DEBUG_STATUS->set_text ($_[0]); 110 $DEBUG_STATUS->set_text ($_[0]);
107 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h}); 111 my ($w, $h) = $DEBUG_STATUS->size_request;
112 $DEBUG_STATUS->move ($WIDTH - $w, 0);
108} 113}
109 114
110sub start_game { 115sub start_game {
111 status "logging in..."; 116 status "logging in...";
112 117
113 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 118 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
114 119
115 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}"; 120 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}";
116
117 $MAP = new CFClient::Map $mapsize, $mapsize; 121 $MAP = new CFClient::Map $mapsize, $mapsize;
118 122
119 my ($host, $port) = split /:/, $CFG->{host}; 123 my ($host, $port) = split /:/, $CFG->{host};
120 124
121 $CONN = eval { 125 $CONN = eval {
128 maph => $mapsize, 132 maph => $mapsize,
129 ; 133 ;
130 }; 134 };
131 135
132 if ($CONN) { 136 if ($CONN) {
137 $LOGIN_BUTTON->set_text ("Logout");
138
133 status "login successful"; 139 status "login successful";
134 140
135 CFClient::lowdelay fileno $CONN->{fh}; 141 CFClient::lowdelay fileno $CONN->{fh};
136 } else { 142 } else {
137 status "unable to connect"; 143 status "unable to connect";
144 stop_game();
138 } 145 }
139} 146}
140 147
141sub stop_game { 148sub stop_game {
149 return unless $CONN;
150
151 status "connection closed";
152 $LOGIN_BUTTON->set_text ("Login");
153 $CONN->destroy;
154 $CONN = 0; # false, does not autovivify
155
156 undef $MAPCACHE;
142 undef $CONN; 157 undef $MAP;
143} 158}
144 159
145sub client_setup { 160sub client_setup {
146 my $dialog = new CFClient::UI::FancyFrame 161 my $dialog = new CFClient::UI::FancyFrame
147 title => "Client Setup", 162 title => "Client Setup",
149 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 164 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
150 165
151 $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode"); 166 $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode");
152 $table->add (1, 0, my $hbox = new CFClient::UI::HBox); 167 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
153 168
154 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); 169 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, $#SDL_MODES, 1, 1]);
155 $hbox->add (my $mode_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999"); 170 $hbox->add (my $mode_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999");
156 171
157 $mode_slider->connect (changed => sub { 172 $mode_slider->connect (changed => sub {
158 my ($self, $value) = @_; 173 my ($self, $value) = @_;
159 174
184 } 199 }
185 ); 200 );
186 201
187 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Map Scale"); 202 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Map Scale");
188 $table->add (1, $row++, new CFClient::UI::Slider 203 $table->add (1, $row++, new CFClient::UI::Slider
189 range => [$CFG->{map_scale}, 0.25, 2, 0.05], 204 range => [$CFG->{map_scale}, 0.25, 2, 0.05, 0.05],
190 tooltip => "Enlarge or shrink the displayed map", 205 tooltip => "Enlarge or shrink the displayed map",
191 connect_changed => sub { 206 connect_changed => sub {
192 my ($self, $value) = @_; 207 my ($self, $value) = @_;
193 $CFG->{map_scale} = 0.05 * int $value / 0.05; 208 $CFG->{map_scale} = $value;
194 } 209 }
195 ); 210 );
196 211
197 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War"); 212 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War");
198 $table->add (1, $row++, new CFClient::UI::CheckBox 213 $table->add (1, $row++, new CFClient::UI::CheckBox
225 } 240 }
226 ); 241 );
227 242
228 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize"); 243 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize");
229 $table->add (1, $row++, new CFClient::UI::Slider 244 $table->add (1, $row++, new CFClient::UI::Slider
230 range => [$CFG->{gui_fontsize}, 0.5, 2, 0.1], 245 range => [$CFG->{gui_fontsize}, 0.5, 2, 0.1, 0.1],
231 tooltip => "The font size used by most GUI elements", 246 tooltip => "The font size used by most GUI elements",
232 connect_changed => sub { 247 connect_changed => sub { $CFG->{gui_fontsize} = $_[1] },
233 $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10;
234# $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
235 }
236 ); 248 );
237 249
238 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize"); 250 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize");
239 $table->add (1, $row++, new CFClient::UI::Slider 251 $table->add (1, $row++, new CFClient::UI::Slider
240 range => [$CFG->{log_fontsize}, 0.5, 2, 0.1], 252 range => [$CFG->{log_fontsize}, 0.5, 2, 0.1, 0.1],
241 tooltip => "The font size used by the server log window only", 253 tooltip => "The font size used by the server log window only",
242 connect_changed => sub { 254 connect_changed => sub { $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = $_[1]) },
243 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10);
244 }
245 ); 255 );
246 256
247 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Stats Fontsize"); 257 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Stats Fontsize");
248 258
249 $table->add (1, $row++, new CFClient::UI::Slider 259 $table->add (1, $row++, new CFClient::UI::Slider
250 range => [$CFG->{stat_fontsize}, 0.5, 2, 0.1], 260 range => [$CFG->{stat_fontsize}, 0.5, 2, 0.1, 0.1],
251 tooltip => "The font size used by the statistics window only", 261 tooltip => "The font size used by the statistics window only",
252 connect_changed => sub { 262 connect_changed => sub {
253 $CFG->{stat_fontsize} = 0.1 * int $_[1] * 10; 263 $CFG->{stat_fontsize} = $_[1];
254 &set_stats_window_fontsize; 264 &set_stats_window_fontsize;
255 } 265 }
256 ); 266 );
257 267
258 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge size"); 268 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge size");
259 $table->add (1, $row++, new CFClient::UI::Slider 269 $table->add (1, $row++, new CFClient::UI::Slider
260 range => [$CFG->{gauge_size}, 0.2, 0.8, 0.02], 270 range => [$CFG->{gauge_size}, 0.2, 0.8, 0.02],
261 tooltip => "Adjust the size of the stats gauges at the bottom right", 271 tooltip => "Adjust the size of the stats gauges at the bottom right",
262 connect_changed => sub { 272 connect_changed => sub {
263 $CFG->{gauge_size} = $_[1]; 273 $CFG->{gauge_size} = $_[1];
264 my $h = int $HEIGHT * $CFG->{gauge_size}; 274 $GAUGES->{win}->set_size ($WIDTH, int $HEIGHT * $CFG->{gauge_size});
265 $GAUGES->{win}->set_size ($WIDTH, $h);
266 $GAUGES->{win}->move (0, $HEIGHT - $h);
267 } 275 }
268 ); 276 );
269 277
270 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); 278 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge fontsize");
271 $table->add (1, $row++, new CFClient::UI::Slider 279 $table->add (1, $row++, new CFClient::UI::Slider
272 range => [$CFG->{gauge_fontsize}, 0.5, 2.0, 0.1], 280 range => [$CFG->{gauge_fontsize}, 0.5, 2.0, 0.1, 0.1],
273 tooltip => "Adjusts the fontsize of the gauges at the bottom right", 281 tooltip => "Adjusts the fontsize of the gauges at the bottom right",
274 connect_changed => sub { 282 connect_changed => sub {
275 $CFG->{gauge_fontsize} = 0.1 * int $_[1] * 10; 283 $CFG->{gauge_fontsize} = $_[1];
276 &set_gauge_window_fontsize; 284 &set_gauge_window_fontsize;
277 } 285 }
278 ); 286 );
279 287
280 $table->add (1, $row++, new CFClient::UI::Button 288 $table->add (1, $row++, new CFClient::UI::Button
354# local $GAUGES->{win}{parent};#d# 362# local $GAUGES->{win}{parent};#d#
355# use PApp::Util; open D, ">:utf8", "d"; print D PApp::Util::dumpval $GAUGES->{win}; close D; 363# use PApp::Util; open D, ">:utf8", "d"; print D PApp::Util::dumpval $GAUGES->{win}; close D;
356} 364}
357 365
358sub make_gauge_window { 366sub make_gauge_window {
359 my $gh = int ($HEIGHT * $CFG->{gauge_size}); 367 my $gh = int $HEIGHT * $CFG->{gauge_size};
360# my $gw = int ($WIDTH * $CFG->{gauge_w_size});
361 368
362 my $win = new CFClient::UI::Frame ( 369 my $win = new CFClient::UI::Frame (
363 y => $HEIGHT - $gh, x => 0, user_w => $WIDTH, user_h => $gh 370 req_y => -1,
371 user_w => $WIDTH,
372 user_h => $gh,
364 ); 373 );
374
365 $win->add (my $hbox = new CFClient::UI::HBox 375 $win->add (my $hbox = new CFClient::UI::HBox
366 children => [ 376 children => [
367 (new CFClient::UI::HBox expand => 1), 377 (new CFClient::UI::HBox expand => 1),
368 ($FLOORBOX = new CFClient::UI::VBox), 378 (new CFClient::UI::VBox children => [
379 (new CFClient::UI::Empty expand => 1),
380 (new CFClient::UI::Frame bg => [0, 0, 0, 0.4], child => ($FLOORBOX = new CFClient::UI::VBox)),
381 ]),
369 (my $vbox = new CFClient::UI::VBox), 382 (my $vbox = new CFClient::UI::VBox),
370 ], 383 ],
371 ); 384 );
372 385
373 $vbox->add (new CFClient::UI::HBox 386 $vbox->add (new CFClient::UI::HBox
571 584
572} 585}
573 586
574sub metaserver_dialog { 587sub metaserver_dialog {
575 my $dialog = new CFClient::UI::FancyFrame 588 my $dialog = new CFClient::UI::FancyFrame
576 title => "Metaserver", 589 title => "Server List",
577 child => (my $vbox = new CFClient::UI::VBox); 590 child => (my $vbox = new CFClient::UI::VBox);
578 591
579 $vbox->add ($dialog->{table} = new CFClient::UI::Table); 592 $vbox->add ($dialog->{table} = new CFClient::UI::Table);
580 593
581 $dialog 594 $dialog
683 696
684 $METASERVER = metaserver_dialog; 697 $METASERVER = metaserver_dialog;
685 698
686 $vbox->add (new CFClient::UI::Flopper 699 $vbox->add (new CFClient::UI::Flopper
687 expand => 1, 700 expand => 1,
688 text => "Metaserver", 701 text => "Server List",
689 other => $METASERVER, 702 other => $METASERVER,
690 tooltip => "Show a list of avaible crossfire servers", 703 tooltip => "Show a list of available crossfire servers",
691 connect_open => sub { 704 connect_open => sub {
692 update_metaserver $HOST; 705 update_metaserver $HOST;
693 } 706 }
694 ); 707 );
695 } 708 }
716 ); 729 );
717 730
718 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size"); 731 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size");
719 $table->add (1, 7, new CFClient::UI::Slider 732 $table->add (1, 7, new CFClient::UI::Slider
720 req_w => 100, 733 req_w => 100,
721 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 734 range => [$CFG->{mapsize}, 10, 100 + 1, 1, 1],
722 tooltip => "This is the size of the portion of the map update the server sends you. " 735 tooltip => "This is the size of the portion of the map update the server sends you. "
723 ."If you set this to a high value you will be able to see further for example.", 736 ."If you set this to a high value you will be able to see further for example.",
724 connect_changed => sub { 737 connect_changed => sub {
725 my ($self, $value) = @_; 738 my ($self, $value) = @_;
726 739
727 $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 740 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
728 }, 741 },
729 ); 742 );
730 743
731 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { 744 $table->add (1, 8, $LOGIN_BUTTON = new CFClient::UI::Button
745 expand => 1,
746 align => 0,
747 text => "Login",
748 connect_activate => sub {
749 $CONN ? stop_game
732 start_game; 750 : start_game;
751 },
733 }); 752 );
734 753
735 $dialog 754 $dialog
736} 755}
737 756
738sub message_window { 757sub message_window {
801} 820}
802 821
803sub video_init { 822sub video_init {
804 sdl_init; 823 sdl_init;
805 824
825 $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} >= @SDL_MODES;
826
806 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 827 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
807 $FULLSCREEN = $CFG->{fullscreen}; 828 $FULLSCREEN = $CFG->{fullscreen};
808 $FAST = $CFG->{fast}; 829 $FAST = $CFG->{fast};
809 830
810 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN 831 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
811 or die "SDL_SetVideoMode failed!\n"; 832 or die "SDL_SetVideoMode failed!\n";
812 833
813 $SDL_ACTIVE = 1; 834 $SDL_ACTIVE = 1;
814
815 $LAST_REFRESH = time - 0.01; 835 $LAST_REFRESH = time - 0.01;
816 836
817 CFClient::gl_init; 837 CFClient::gl_init;
818 838
819 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; 839 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
820 840
841 $CFClient::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d#
842
821 ############################################################################# 843 #############################################################################
822 844
845 unless ($DEBUG_STATUS) {
846 # create the widgets
847
823 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 848 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100, req_x => -1;
824 $DEBUG_STATUS->show; 849 $DEBUG_STATUS->show;
825 850
826 $STATUS_LINE = new CFClient::UI::Label 851 $STATUSBOX = new CFClient::UI::Statusbox;
827 padding => 0, 852 $STATUSBOX->add ("Use <b>Alt-Enter</b> to toggle fullscreen mode", pri => -100, color => [1, 1, 1, 0.8]);
828 y => $HEIGHT - $FONTSIZE * 1.8;
829 $STATUS_LINE->show;
830 853
831 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 854 (new CFClient::UI::Frame
832 padding => 0, 855 bg => [0, 0, 0, 0.4],
833 fontsize => 0.8, 856 req_y => -1,
834 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 857 child => $STATUSBOX,
835 $ALT_ENTER_MESSAGE->show; 858 )->show;
836 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
837 859
838 CFClient::UI::FancyFrame->new ( 860 CFClient::UI::FancyFrame->new (
839 border_bg => [1, 1, 1, 192/255], 861 border_bg => [1, 1, 1, 192/255],
840 bg => [1, 1, 1, 0], 862 bg => [1, 1, 1, 0],
841 child => ($MAPMAP = new CFClient::MapWidget::MapMap), 863 child => ($MAPMAP = new CFClient::MapWidget::MapMap),
842 )->show; 864 )->show;
843 865
844 $MAPWIDGET = new CFClient::MapWidget; 866 $MAPWIDGET = new CFClient::MapWidget;
845 $MAPWIDGET->connect (activate_console => sub { 867 $MAPWIDGET->connect (activate_console => sub {
846 my ($mapwidget, $preset) = @_; 868 my ($mapwidget, $preset) = @_;
847 869
848 if ($CONSOLE) { 870 if ($CONSOLE) {
849 $CONSOLE->{input}->{auto_activated} = 1; 871 $CONSOLE->{input}->{auto_activated} = 1;
850 $CONSOLE->{input}->focus_in; 872 $CONSOLE->{input}->focus_in;
851 873
852 if ($preset && $CONSOLE->{input}->get_text eq '') { 874 if ($preset && $CONSOLE->{input}->get_text eq '') {
853 $CONSOLE->{input}->set_text ($preset); 875 $CONSOLE->{input}->set_text ($preset);
876 }
854 } 877 }
855 } 878 });
856 });
857 $MAPWIDGET->show; 879 $MAPWIDGET->show;
858 $MAPWIDGET->focus_in; 880 $MAPWIDGET->focus_in;
859 881
860 $BUTTONBAR = new CFClient::UI::HBox; 882 $BUTTONBAR = new CFClient::UI::HBox;
861 883
862 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup); 884 $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); 885 $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); 886 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window);
865 887
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 888 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 889
868 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window); 890 $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); 891 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Inventory", other => make_inventory_window);
870 892
871 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { 893 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub {
872 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 894 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
873 status "Configuration Saved"; 895 status "Configuration Saved";
874 }); 896 });
875 897
876 $BUTTONBAR->show; 898 $BUTTONBAR->show;
877 899
900 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]);
901
902 # delay till geometry is constant
903 $CFClient::UI::ROOT->on_post_alloc (startup => sub {
878 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 904 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
905 my $widget = $GAUGES->{win};
906 $widget->move (0, $HEIGHT - $widget->{h});#d# to in toplevel
907 });
908 force_refresh ();
909 }
879} 910}
880 911
881sub video_shutdown { 912sub 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
888my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# 916my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d#
889my $bgmusic;#TODO#hack#d# 917my $bgmusic;#TODO#hack#d#
918
919sub audio_channel_finished {
920 my ($channel) = @_;
921
922 warn "channel $channel finished\n";#d#
923}
890 924
891sub audio_music_finished { 925sub 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
937my %animate_object; 971my %animate_object;
938my $animate_timer; 972my $animate_timer;
939 973
940my $want_refresh;
941my $can_refresh;
942
943my $fps = 9; 974my $fps = 9;
944 975
945sub force_refresh { 976sub force_refresh {
946 $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05; 977 $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 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
959my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { 988my $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
977sub refresh {
978 $want_refresh++;
979}
980 1005
981sub animation_start { 1006sub 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/&/&amp;/g; $text =~ s/</&lt;/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
1335 $STATUSBOX->add ($text,
1336 group => $text,
1337 fg => $color[$color],
1338 timeout => 60,
1339 tooltip_font => $::FONT_FIXED,
1340 );
1341}
1342
1343sub conn::drawextinfo {
1344 my ($self, $color, $type, $subtype, $message) = @_;
1345
1346 $self->drawinfo ($color, $message);
1302} 1347}
1303 1348
1304sub conn::spell_add { 1349sub conn::spell_add {
1305 my ($self, $spell) = @_; 1350 my ($self, $spell) = @_;
1306 1351
1319 1364
1320 for my $skill (values %{$self->{skill_info}}) { 1365 for my $skill (values %{$self->{skill_info}}) {
1321 $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'"); 1366 $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'");
1322 $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'"); 1367 $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'");
1323 } 1368 }
1369
1370 $MAPWIDGET->add_command ("pet\\_mode defend", "Tell pets to stay close to you and defend you");
1371 $MAPWIDGET->add_command ("pet\\_mode arena", "Same as petmode attack, but also attack other players");
1372 $MAPWIDGET->add_command ("pet\\_mode sad", "Search &amp; Destroy - tell pets to roam about and attack enemies");
1373 $MAPWIDGET->add_command ("kill\\_pets", "kill your pets");
1374}
1375
1376sub conn::eof {
1377 stop_game;
1324} 1378}
1325 1379
1326sub update_floorbox { 1380sub update_floorbox {
1327 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { 1381 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub {
1382 return unless $CONN;
1383
1328 $FLOORBOX->clear; 1384 $FLOORBOX->clear;
1329 $FLOORBOX->add (new CFClient::UI::Empty expand => 1); 1385 $FLOORBOX->add (new CFClient::UI::Empty expand => 1);
1330 1386
1331 # we basically have to use the same sorting as everybody else 1387 my $count = 4;
1332 for my $item (@{ $CONN->{container}{0} }) { 1388 for (@{ $CONN->{container}{0} }) {
1333 my $desc = $item->{nrof} < 2 1389 if (--$count) {
1334 ? $item->{name} 1390 $FLOORBOX->add (new CFClient::UI::InventoryItem item => $_);
1335 : "$item->{nrof} $item->{name_pl}"; 1391 } else {
1336 # todo: animation widget, face widget, weight(?) etc. 1392 $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 }, 1393 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 1394 }
1375 $hbox->add (new CFClient::UI::Label
1376 can_events => 0,
1377 text => $desc,
1378 );
1379 } 1395 }
1380 }); 1396 });
1381 refresh; 1397
1398 $WANT_REFRESH++;
1382} 1399}
1383 1400
1384sub conn::container_add { 1401sub conn::container_add {
1385 my ($self, $id, $items) = @_; 1402 my ($self, $tag, $items) = @_;
1386 1403
1387 update_floorbox if $id == 0; 1404 update_floorbox if $tag == 0;
1388 if ($self->{player}{tag} == $id) { 1405
1389 $INV->set_items ($self->{container}{$self->{player}{tag}}); 1406 $INV->set_items ($self->{container}{$self->{player}{tag}})
1390 } 1407 if $tag == $self->{player}{tag};
1408
1391 # $self-<{player}{tag} => player inv 1409 # $self-<{player}{tag} => player inv
1392 #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; 1410 #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}};
1393} 1411}
1394 1412
1395sub conn::container_clear { 1413sub conn::container_clear {
1396 my ($self, $id) = @_; 1414 my ($self, $tag) = @_;
1397 1415
1398 update_floorbox if $id == 0; 1416 update_floorbox if $tag == 0;
1399 if ($self->{player}{tag} == $id) { 1417
1400 $INV->set_items ($self->{container}{$id}); 1418 $INV->set_items ($self->{container}{$tag})
1401 } 1419 if $tag == $self->{player}{tag};
1402 1420
1403# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; 1421# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0};
1404} 1422}
1405 1423
1406sub conn::item_delete { 1424sub conn::item_delete {
1407 my ($self, @items) = @_; 1425 my ($self, @items) = @_;
1408 1426
1409 for (@items) { 1427 for (@items) {
1410 update_floorbox if $_->{container} == 0; 1428 update_floorbox if $_->{container} == 0;
1411 if ($self->{player}{tag} == $_->{container}) { 1429
1412 $INV->set_items ($self->{container}{$_->{container}}); 1430 $INV->set_items ($self->{container}{$_->{container}})
1413 } 1431 if $_->{container} == $self->{player}{tag};
1414 } 1432 }
1415} 1433}
1416 1434
1417sub conn::item_update { 1435sub conn::item_update {
1418 my ($self, $item) = @_; 1436 my ($self, $item) = @_;
1419 1437
1420 update_floorbox if $item->{container} == 0; 1438 update_floorbox if $item->{container} == 0;
1421 if ($self->{player}{tag} == $item->{container}) { 1439
1422 $INV->set_items ($self->{container}{$item->{container}}); 1440 $INV->set_items ($self->{container}{$item->{container}})
1423 } 1441 if $item->{container} == $self->{player}{tag};
1424} 1442}
1425 1443
1426%SDL_CB = ( 1444%SDL_CB = (
1427 CFClient::SDL_QUIT => sub { 1445 CFClient::SDL_QUIT => sub {
1428 Event::unloop -1; 1446 Event::unloop -1;
1429 }, 1447 },
1430 CFClient::SDL_VIDEORESIZE => sub { 1448 CFClient::SDL_VIDEORESIZE => sub {
1431 }, 1449 },
1432 CFClient::SDL_VIDEOEXPOSE => \&refresh, 1450 CFClient::SDL_VIDEOEXPOSE => sub {
1451 $WANT_REFRESH++;
1452 },
1433 CFClient::SDL_ACTIVEEVENT => sub { 1453 CFClient::SDL_ACTIVEEVENT => sub {
1434# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# 1454# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
1435 }, 1455 },
1436 CFClient::SDL_KEYDOWN => sub { 1456 CFClient::SDL_KEYDOWN => sub {
1437 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { 1457 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
1441 video_init; 1461 video_init;
1442 } else { 1462 } else {
1443 CFClient::UI::feed_sdl_key_down_event ($_[0]); 1463 CFClient::UI::feed_sdl_key_down_event ($_[0]);
1444 } 1464 }
1445 }, 1465 },
1446 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, 1466 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
1447 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, 1467 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
1448 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, 1468 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
1449 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, 1469 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
1450 CFClient::SDL_USEREVENT => \&audio_music_finished, 1470 CFClient::SDL_USEREVENT => sub {
1471 if ($_[0]{code} == 1) {
1472 audio_channel_finished $_[0]{data1};
1473 } elsif ($_[0]{code} == 0) {
1474 audio_music_finished;
1475 }
1476 },
1451); 1477);
1452 1478
1453############################################################################# 1479#############################################################################
1454 1480
1455$SIG{INT} = $SIG{TERM} = sub { exit }; 1481$SIG{INT} = $SIG{TERM} = sub { exit };
1456 1482
1457CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1458
1459$TILECACHE = CFClient::db_table "tilecache";
1460$FACEMAP = CFClient::db_table "facemap";
1461
1462my %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
1485while (my ($k, $v) = each %DEF_CFG) {
1486 $CFG->{$k} = $v unless exists $CFG->{$k};
1487}
1488
1489sdl_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{ 1483{
1484 local $SIG{__DIE__} = sub { CFClient::fatal $_[0] };
1485
1486 CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1487
1488 $TILECACHE = CFClient::db_table "tilecache";
1489 $FACEMAP = CFClient::db_table "facemap";
1490
1491 my %DEF_CFG = (
1492 sdl_mode => 0,
1493 width => 640,
1494 height => 480,
1495 fullscreen => 0,
1496 fast => 0,
1497 map_scale => 0.5,
1498 fow_enable => 1,
1499 fow_intensity => 0.45,
1500 fow_smooth => 0,
1501 gui_fontsize => 1,
1502 log_fontsize => 1,
1503 gauge_fontsize=> 1,
1504 gauge_size => 0.35,
1505 stat_fontsize => 1,
1506 mapsize => 100,
1507 host => "crossfire.schmorp.de",
1508 say_command => 'say',
1509 audio_enable => 1,
1510 bgm_enable => 1,
1511 bgm_volume => 0.25,
1512 );
1513
1514 while (my ($k, $v) = each %DEF_CFG) {
1515 $CFG->{$k} = $v unless exists $CFG->{$k};
1516 }
1517
1518 sdl_init;
1519
1520 @SDL_MODES = reverse
1521 grep $_->[0] >= 640 && $_->[1] >= 480,
1522 CFClient::SDL_ListModes;
1523
1524 @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
1525
1526 $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
1527
1528 {
1500 my @fonts = map CFClient::find_rcfile "fonts/$_", qw( 1529 my @fonts = map CFClient::find_rcfile "fonts/$_", qw(
1501 DejaVuSans.ttf 1530 DejaVuSans.ttf
1502 DejaVuSansMono.ttf 1531 DejaVuSansMono.ttf
1503 DejaVuSans-Bold.ttf 1532 DejaVuSans-Bold.ttf
1504 DejaVuSansMono-Bold.ttf 1533 DejaVuSansMono-Bold.ttf
1505 DejaVuSans-Oblique.ttf 1534 DejaVuSans-Oblique.ttf
1506 DejaVuSansMono-Oblique.ttf 1535 DejaVuSansMono-Oblique.ttf
1507 DejaVuSans-BoldOblique.ttf 1536 DejaVuSans-BoldOblique.ttf
1508 DejaVuSansMono-BoldOblique.ttf 1537 DejaVuSansMono-BoldOblique.ttf
1509 ); 1538 );
1510 1539
1511 CFClient::add_font $_ for @fonts; 1540 CFClient::add_font $_ for @fonts;
1512 1541
1542 CFClient::pango_init;
1543
1513 $FONT_PROP = new_from_file CFClient::Font $fonts[0]; 1544 $FONT_PROP = new_from_file CFClient::Font $fonts[0];
1514 $FONT_FIXED = new_from_file CFClient::Font $fonts[1]; 1545 $FONT_FIXED = new_from_file CFClient::Font $fonts[1];
1515 1546
1516 $FONT_PROP->make_default; 1547 $FONT_PROP->make_default;
1517} 1548 }
1518 1549
1519video_init; 1550 video_init;
1520audio_init; 1551 audio_init;
1552}
1521 1553
1522Event::loop; 1554Event::loop;
1523 1555
1524END { CFClient::SDL_Quit } 1556END { CFClient::SDL_Quit }
1525 1557

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines