… | |
… | |
94 | our $SDL_MIXER; |
94 | our $SDL_MIXER; |
95 | our @SOUNDS; # event => file mapping |
95 | our @SOUNDS; # event => file mapping |
96 | our %AUDIO_CHUNKS; # audio files |
96 | our %AUDIO_CHUNKS; # audio files |
97 | |
97 | |
98 | our $ALT_ENTER_MESSAGE; |
98 | our $ALT_ENTER_MESSAGE; |
99 | our $STATUS_LINE; |
99 | our $STATUSBOX; |
100 | our $DEBUG_STATUS; |
100 | our $DEBUG_STATUS; |
101 | |
101 | |
102 | our $INVWIN; |
102 | our $INVWIN; |
103 | our $INV; |
103 | our $INV; |
104 | |
104 | |
105 | sub status { |
105 | sub status { |
106 | $STATUS_LINE->add ($_[0], group => "status", timeout => 60); |
106 | $STATUSBOX->add ($_[0], pri => -10, group => "status", timeout => 20, fg => [1, 1, 0, 1]); |
107 | $CFClient::UI::ROOT->on_refresh ($STATUS_LINE => sub { |
|
|
108 | $STATUS_LINE->move (0, $HEIGHT - $STATUS_LINE->{h});#d# to in toplevel |
|
|
109 | }); |
|
|
110 | } |
107 | } |
111 | |
108 | |
112 | sub debug { |
109 | sub debug { |
113 | $DEBUG_STATUS->set_text ($_[0]); |
110 | $DEBUG_STATUS->set_text ($_[0]); |
114 | my ($w, $h) = $DEBUG_STATUS->size_request; |
111 | my ($w, $h) = $DEBUG_STATUS->size_request; |
… | |
… | |
167 | $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]); |
168 | |
165 | |
169 | $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"); |
170 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
167 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
171 | |
168 | |
172 | $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]); |
173 | $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"); |
174 | |
171 | |
175 | $mode_slider->connect (changed => sub { |
172 | $mode_slider->connect (changed => sub { |
176 | my ($self, $value) = @_; |
173 | my ($self, $value) = @_; |
177 | |
174 | |
… | |
… | |
202 | } |
199 | } |
203 | ); |
200 | ); |
204 | |
201 | |
205 | $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"); |
206 | $table->add (1, $row++, new CFClient::UI::Slider |
203 | $table->add (1, $row++, new CFClient::UI::Slider |
207 | range => [$CFG->{map_scale}, 0.25, 2, 0.05], |
204 | range => [$CFG->{map_scale}, 0.25, 2, 0.05, 0.05], |
208 | tooltip => "Enlarge or shrink the displayed map", |
205 | tooltip => "Enlarge or shrink the displayed map", |
209 | connect_changed => sub { |
206 | connect_changed => sub { |
210 | my ($self, $value) = @_; |
207 | my ($self, $value) = @_; |
211 | $CFG->{map_scale} = 0.05 * int $value / 0.05; |
208 | $CFG->{map_scale} = $value; |
212 | } |
209 | } |
213 | ); |
210 | ); |
214 | |
211 | |
215 | $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"); |
216 | $table->add (1, $row++, new CFClient::UI::CheckBox |
213 | $table->add (1, $row++, new CFClient::UI::CheckBox |
… | |
… | |
243 | } |
240 | } |
244 | ); |
241 | ); |
245 | |
242 | |
246 | $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"); |
247 | $table->add (1, $row++, new CFClient::UI::Slider |
244 | $table->add (1, $row++, new CFClient::UI::Slider |
248 | range => [$CFG->{gui_fontsize}, 0.5, 2, 0.1], |
245 | range => [$CFG->{gui_fontsize}, 0.5, 2, 0.1, 0.1], |
249 | tooltip => "The font size used by most GUI elements", |
246 | tooltip => "The font size used by most GUI elements", |
250 | connect_changed => sub { |
247 | connect_changed => sub { $CFG->{gui_fontsize} = $_[1] }, |
251 | $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10; |
|
|
252 | # $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
|
|
253 | } |
|
|
254 | ); |
248 | ); |
255 | |
249 | |
256 | $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"); |
257 | $table->add (1, $row++, new CFClient::UI::Slider |
251 | $table->add (1, $row++, new CFClient::UI::Slider |
258 | range => [$CFG->{log_fontsize}, 0.5, 2, 0.1], |
252 | range => [$CFG->{log_fontsize}, 0.5, 2, 0.1, 0.1], |
259 | tooltip => "The font size used by the server log window only", |
253 | tooltip => "The font size used by the server log window only", |
260 | connect_changed => sub { |
254 | connect_changed => sub { $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = $_[1]) }, |
261 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10); |
|
|
262 | } |
|
|
263 | ); |
255 | ); |
264 | |
256 | |
265 | $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"); |
266 | |
258 | |
267 | $table->add (1, $row++, new CFClient::UI::Slider |
259 | $table->add (1, $row++, new CFClient::UI::Slider |
268 | range => [$CFG->{stat_fontsize}, 0.5, 2, 0.1], |
260 | range => [$CFG->{stat_fontsize}, 0.5, 2, 0.1, 0.1], |
269 | tooltip => "The font size used by the statistics window only", |
261 | tooltip => "The font size used by the statistics window only", |
270 | connect_changed => sub { |
262 | connect_changed => sub { |
271 | $CFG->{stat_fontsize} = 0.1 * int $_[1] * 10; |
263 | $CFG->{stat_fontsize} = $_[1]; |
272 | &set_stats_window_fontsize; |
264 | &set_stats_window_fontsize; |
273 | } |
265 | } |
274 | ); |
266 | ); |
275 | |
267 | |
276 | $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"); |
277 | $table->add (1, $row++, new CFClient::UI::Slider |
269 | $table->add (1, $row++, new CFClient::UI::Slider |
278 | range => [$CFG->{gauge_size}, 0.2, 0.8, 0.02], |
270 | range => [$CFG->{gauge_size}, 0.2, 0.8, 0.02], |
279 | 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", |
280 | connect_changed => sub { |
272 | connect_changed => sub { |
281 | $CFG->{gauge_size} = $_[1]; |
273 | $CFG->{gauge_size} = $_[1]; |
282 | my $h = int $HEIGHT * $CFG->{gauge_size}; |
274 | $GAUGES->{win}->set_size ($WIDTH, int $HEIGHT * $CFG->{gauge_size}); |
283 | $GAUGES->{win}->set_size ($WIDTH, $h); |
|
|
284 | $GAUGES->{win}->move (0, $HEIGHT - $h); |
|
|
285 | } |
275 | } |
286 | ); |
276 | ); |
287 | |
277 | |
288 | $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"); |
289 | $table->add (1, $row++, new CFClient::UI::Slider |
279 | $table->add (1, $row++, new CFClient::UI::Slider |
290 | range => [$CFG->{gauge_fontsize}, 0.5, 2.0, 0.1], |
280 | range => [$CFG->{gauge_fontsize}, 0.5, 2.0, 0.1, 0.1], |
291 | tooltip => "Adjusts the fontsize of the gauges at the bottom right", |
281 | tooltip => "Adjusts the fontsize of the gauges at the bottom right", |
292 | connect_changed => sub { |
282 | connect_changed => sub { |
293 | $CFG->{gauge_fontsize} = 0.1 * int $_[1] * 10; |
283 | $CFG->{gauge_fontsize} = $_[1]; |
294 | &set_gauge_window_fontsize; |
284 | &set_gauge_window_fontsize; |
295 | } |
285 | } |
296 | ); |
286 | ); |
297 | |
287 | |
298 | $table->add (1, $row++, new CFClient::UI::Button |
288 | $table->add (1, $row++, new CFClient::UI::Button |
… | |
… | |
372 | # local $GAUGES->{win}{parent};#d# |
362 | # local $GAUGES->{win}{parent};#d# |
373 | # 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; |
374 | } |
364 | } |
375 | |
365 | |
376 | sub make_gauge_window { |
366 | sub make_gauge_window { |
377 | my $gh = int ($HEIGHT * $CFG->{gauge_size}); |
367 | my $gh = int $HEIGHT * $CFG->{gauge_size}; |
378 | # my $gw = int ($WIDTH * $CFG->{gauge_w_size}); |
|
|
379 | |
368 | |
380 | my $win = new CFClient::UI::Frame ( |
369 | my $win = new CFClient::UI::Frame ( |
381 | y => $HEIGHT - $gh, x => 0, user_w => $WIDTH, user_h => $gh |
370 | req_y => -1, |
|
|
371 | user_w => $WIDTH, |
|
|
372 | user_h => $gh, |
382 | ); |
373 | ); |
|
|
374 | |
383 | $win->add (my $hbox = new CFClient::UI::HBox |
375 | $win->add (my $hbox = new CFClient::UI::HBox |
384 | children => [ |
376 | children => [ |
385 | (new CFClient::UI::HBox expand => 1), |
377 | (new CFClient::UI::HBox expand => 1), |
386 | ($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 | ]), |
387 | (my $vbox = new CFClient::UI::VBox), |
382 | (my $vbox = new CFClient::UI::VBox), |
388 | ], |
383 | ], |
389 | ); |
384 | ); |
390 | |
385 | |
391 | $vbox->add (new CFClient::UI::HBox |
386 | $vbox->add (new CFClient::UI::HBox |
… | |
… | |
734 | ); |
729 | ); |
735 | |
730 | |
736 | $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"); |
737 | $table->add (1, 7, new CFClient::UI::Slider |
732 | $table->add (1, 7, new CFClient::UI::Slider |
738 | req_w => 100, |
733 | req_w => 100, |
739 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
734 | range => [$CFG->{mapsize}, 10, 100 + 1, 1, 1], |
740 | 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. " |
741 | ."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.", |
742 | connect_changed => sub { |
737 | connect_changed => sub { |
743 | my ($self, $value) = @_; |
738 | my ($self, $value) = @_; |
744 | |
739 | |
… | |
… | |
845 | |
840 | |
846 | $CFClient::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# |
841 | $CFClient::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# |
847 | |
842 | |
848 | ############################################################################# |
843 | ############################################################################# |
849 | |
844 | |
850 | if ($DEBUG_STATUS) { |
845 | unless ($DEBUG_STATUS) { |
851 | # reconfigure all widgets |
|
|
852 | $CFClient::UI::ROOT->reconfigure; |
|
|
853 | |
|
|
854 | } else { |
|
|
855 | # create the widgets |
846 | # create the widgets |
856 | |
847 | |
857 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100, text => "hulla", x => 100;#d# |
848 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100, req_x => -1; |
858 | $DEBUG_STATUS->show; |
849 | $DEBUG_STATUS->show; |
859 | |
850 | |
860 | $STATUS_LINE = new CFClient::UI::Statusbox; |
851 | $STATUSBOX = new CFClient::UI::Statusbox; |
861 | $STATUS_LINE->add ("Use <b>Alt-Enter</b> to toggle fullscreen mode", pri => 0, size => 0.8, color => [1, 1, 1]); |
852 | $STATUSBOX->add ("Use <b>Alt-Enter</b> to toggle fullscreen mode", pri => -100, color => [1, 1, 1, 0.8]); |
862 | $STATUS_LINE->show; |
853 | |
|
|
854 | (new CFClient::UI::Frame |
|
|
855 | bg => [0, 0, 0, 0.4], |
|
|
856 | req_y => -1, |
|
|
857 | child => $STATUSBOX, |
|
|
858 | )->show; |
863 | |
859 | |
864 | CFClient::UI::FancyFrame->new ( |
860 | CFClient::UI::FancyFrame->new ( |
865 | border_bg => [1, 1, 1, 192/255], |
861 | border_bg => [1, 1, 1, 192/255], |
866 | bg => [1, 1, 1, 0], |
862 | bg => [1, 1, 1, 0], |
867 | child => ($MAPMAP = new CFClient::MapWidget::MapMap), |
863 | child => ($MAPMAP = new CFClient::MapWidget::MapMap), |
… | |
… | |
899 | status "Configuration Saved"; |
895 | status "Configuration Saved"; |
900 | }); |
896 | }); |
901 | |
897 | |
902 | $BUTTONBAR->show; |
898 | $BUTTONBAR->show; |
903 | |
899 | |
|
|
900 | $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); |
|
|
901 | |
904 | # delay till geometry is constant |
902 | # delay till geometry is constant |
905 | $CFClient::UI::ROOT->on_refresh (startup => sub { |
903 | $CFClient::UI::ROOT->on_post_alloc (startup => sub { |
906 | $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 | }); |
907 | }); |
908 | force_refresh (); |
908 | force_refresh (); |
909 | } |
909 | } |
910 | } |
910 | } |
911 | |
911 | |
… | |
… | |
972 | my $animate_timer; |
972 | my $animate_timer; |
973 | |
973 | |
974 | my $fps = 9; |
974 | my $fps = 9; |
975 | |
975 | |
976 | sub force_refresh { |
976 | sub force_refresh { |
977 | $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05; |
977 | $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05; |
978 | debug sprintf "%3.2f", $fps; |
978 | debug sprintf "%3.2f", $fps; |
979 | |
979 | |
980 | $CFClient::UI::ROOT->draw; |
980 | $CFClient::UI::ROOT->draw; |
981 | CFClient::SDL_GL_SwapBuffers; |
981 | CFClient::SDL_GL_SwapBuffers; |
982 | |
982 | |
… | |
… | |
1323 | [0.74, 0.65, 0.41], |
1323 | [0.74, 0.65, 0.41], |
1324 | ); |
1324 | ); |
1325 | |
1325 | |
1326 | my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
1326 | my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
1327 | |
1327 | |
1328 | $LOGVIEW->add_paragraph ($color[$color], |
|
|
1329 | join "\n", map "$time $_", split /\n/, $text); |
|
|
1330 | |
|
|
1331 | $text =~ s/&/&/g; $text =~ s/</</g; |
1328 | $text =~ s/&/&/g; $text =~ s/</</g; |
1332 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
1329 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
1333 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
1330 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
1334 | $STATUS_LINE->add ($text, color => $color[$color], timeout => 60); |
1331 | |
|
|
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 | ); |
1335 | } |
1341 | } |
1336 | |
1342 | |
1337 | sub conn::drawextinfo { |
1343 | sub conn::drawextinfo { |
1338 | my ($self, $color, $type, $subtype, $message) = @_; |
1344 | my ($self, $color, $type, $subtype, $message) = @_; |
1339 | |
1345 | |
… | |
… | |
1531 | DejaVuSansMono-BoldOblique.ttf |
1537 | DejaVuSansMono-BoldOblique.ttf |
1532 | ); |
1538 | ); |
1533 | |
1539 | |
1534 | CFClient::add_font $_ for @fonts; |
1540 | CFClient::add_font $_ for @fonts; |
1535 | |
1541 | |
|
|
1542 | CFClient::pango_init; |
|
|
1543 | |
1536 | $FONT_PROP = new_from_file CFClient::Font $fonts[0]; |
1544 | $FONT_PROP = new_from_file CFClient::Font $fonts[0]; |
1537 | $FONT_FIXED = new_from_file CFClient::Font $fonts[1]; |
1545 | $FONT_FIXED = new_from_file CFClient::Font $fonts[1]; |
1538 | |
1546 | |
1539 | $FONT_PROP->make_default; |
1547 | $FONT_PROP->make_default; |
1540 | } |
1548 | } |