… | |
… | |
19 | use CFClient::UI; |
19 | use CFClient::UI; |
20 | |
20 | |
21 | our $VERSION = '0.1'; |
21 | our $VERSION = '0.1'; |
22 | |
22 | |
23 | my $MAX_FPS = 60; |
23 | my $MAX_FPS = 60; |
24 | my $MIN_FPS = 5; # unused |
24 | my $MIN_FPS = 5; # unused as of yet |
25 | |
25 | |
26 | our $FACECACHE; |
26 | our $FACECACHE; |
27 | |
27 | |
28 | our $LAST_REFRESH; |
28 | our $LAST_REFRESH; |
29 | our $NOW; |
29 | our $NOW; |
… | |
… | |
34 | |
34 | |
35 | our @SDL_MODES; |
35 | our @SDL_MODES; |
36 | our $WIDTH; |
36 | our $WIDTH; |
37 | our $HEIGHT; |
37 | our $HEIGHT; |
38 | our $FULLSCREEN; |
38 | our $FULLSCREEN; |
|
|
39 | our $FONTSIZE; |
39 | |
40 | |
|
|
41 | our $MAP; |
40 | our $MAPWIDGET; |
42 | our $MAPWIDGET; |
41 | our $FONTSIZE; |
|
|
42 | |
43 | |
43 | our $SDL_ACTIVE; |
44 | our $SDL_ACTIVE; |
44 | our $SDL_EV; |
45 | our $SDL_EV; |
45 | our %SDL_CB; |
46 | our %SDL_CB; |
46 | |
47 | |
47 | our $ALT_ENTER_MESSAGE; |
48 | our $ALT_ENTER_MESSAGE; |
48 | our $STATUS_LINE; |
49 | our $STATUS_LINE; |
49 | our $DEBUG_STATUS; |
50 | our $DEBUG_STATUS; |
|
|
51 | our $BUTTONBAR; |
|
|
52 | our $LOGVIEW; |
50 | |
53 | |
51 | sub status { |
54 | sub status { |
52 | $STATUS_LINE->set_text ($_[0]); |
55 | $STATUS_LINE->set_text ($_[0]); |
53 | my ($w, $h) = $STATUS_LINE->size_request; |
56 | my ($w, $h) = $STATUS_LINE->size_request; |
54 | $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h); |
57 | $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h); |
… | |
… | |
63 | sub start_game { |
66 | sub start_game { |
64 | status "logging in..."; |
67 | status "logging in..."; |
65 | |
68 | |
66 | my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
69 | my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
67 | |
70 | |
|
|
71 | $MAP = new CFClient::Map $mapsize, $mapsize; |
|
|
72 | |
68 | $CONN = new conn |
73 | $CONN = new conn |
69 | host => $CFG->{host}, |
74 | host => $CFG->{host}, |
70 | port => $CFG->{port}, |
75 | port => $CFG->{port}, |
71 | user => $CFG->{user}, |
76 | user => $CFG->{user}, |
72 | pass => $CFG->{password}, |
77 | pass => $CFG->{password}, |
… | |
… | |
82 | sub stop_game { |
87 | sub stop_game { |
83 | undef $CONN; |
88 | undef $CONN; |
84 | } |
89 | } |
85 | |
90 | |
86 | sub config_dialog { |
91 | sub config_dialog { |
87 | my $dialog = new CFClient::UI::FancyFrame x => 300, y => 100, |
92 | my $dialog = new CFClient::UI::FancyFrame |
88 | child => (my $vbox = new CFClient::UI::VBox); |
93 | child => (my $vbox = new CFClient::UI::VBox); |
89 | $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); |
94 | $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); |
90 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
95 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
91 | |
96 | |
92 | $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); |
97 | $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); |
… | |
… | |
113 | $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub { |
118 | $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub { |
114 | my ($self, $value) = @_; |
119 | my ($self, $value) = @_; |
115 | $CFG->{fast} = $value; |
120 | $CFG->{fast} = $value; |
116 | }); |
121 | }); |
117 | |
122 | |
|
|
123 | $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Fog of War"); |
|
|
124 | $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub { |
|
|
125 | my ($self, $value) = @_; |
|
|
126 | $CFG->{fow_enable} = $value; |
|
|
127 | }); |
|
|
128 | |
|
|
129 | $table->add (0, 4, new CFClient::UI::Label align => 1, text => "FoW Intensity"); |
|
|
130 | $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub { |
|
|
131 | my ($self, $value) = @_; |
|
|
132 | $CFG->{fow_intensity} = $value; |
|
|
133 | }); |
|
|
134 | |
|
|
135 | $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); |
|
|
136 | $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { |
|
|
137 | my ($self, $value) = @_; |
|
|
138 | $CFG->{fow_smooth} = $value; |
|
|
139 | }); |
|
|
140 | |
118 | $table->add (1, 3, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
141 | $table->add (1, 6, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
119 | destroy_screen (); |
142 | destroy_screen (); |
120 | init_screen (); |
143 | init_screen (); |
121 | }); |
144 | }); |
122 | |
145 | |
123 | $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup"); |
146 | $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup"); |
… | |
… | |
153 | |
176 | |
154 | $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub { |
177 | $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub { |
155 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
178 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
156 | status "Configuration Saved"; |
179 | status "Configuration Saved"; |
157 | }); |
180 | }); |
158 | $CFClient::UI::TOPLEVEL->add ($dialog); |
181 | |
|
|
182 | $dialog |
|
|
183 | } |
|
|
184 | |
|
|
185 | sub console_window { |
|
|
186 | my $window = new CFClient::UI::FancyFrame |
|
|
187 | border_bg => [1, 1, 1, 0.5], |
|
|
188 | bg => [0.3, 0.3, 0.3, 0.8], |
|
|
189 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
190 | |
|
|
191 | $vbox->add ($LOGVIEW = new CFClient::UI::TextView expand => 1); |
|
|
192 | $vbox->add (my $input = new CFClient::UI::LineEntry); |
|
|
193 | $input->connect (activate => sub { |
|
|
194 | my ($input, $text) = @_; |
|
|
195 | $input->set_text (''); |
|
|
196 | |
|
|
197 | if ($text =~ /^\/(.*)/) { |
|
|
198 | $::CONN->user_send ("command $1"); |
|
|
199 | } else { |
|
|
200 | $::CONN->user_send ("command say $text"); |
|
|
201 | } |
|
|
202 | 1 |
|
|
203 | }); |
|
|
204 | |
|
|
205 | $window |
159 | } |
206 | } |
160 | |
207 | |
161 | sub sdl_init { |
208 | sub sdl_init { |
162 | SDL::Init SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO |
209 | SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO |
163 | and die "SDL::Init failed!\n"; |
210 | and die "SDL::Init failed!\n"; |
164 | } |
211 | } |
165 | |
212 | |
166 | sub init_screen { |
213 | sub init_screen { |
167 | sdl_init; |
214 | sdl_init; |
… | |
… | |
202 | |
249 | |
203 | $FONTSIZE = int $HEIGHT / 40; |
250 | $FONTSIZE = int $HEIGHT / 40; |
204 | |
251 | |
205 | ############################################################################# |
252 | ############################################################################# |
206 | |
253 | |
207 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0; |
254 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
208 | $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS); |
255 | $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS); |
209 | |
256 | |
210 | $STATUS_LINE = new CFClient::UI::Label |
257 | $STATUS_LINE = new CFClient::UI::Label |
211 | padding => 0, |
258 | padding => 0, |
212 | y => $HEIGHT * 49 / 50 - $FONTSIZE; |
259 | y => $HEIGHT * 44 / 45 - $FONTSIZE; |
213 | $CFClient::UI::TOPLEVEL->add ($STATUS_LINE); |
260 | $CFClient::UI::TOPLEVEL->add ($STATUS_LINE); |
214 | |
261 | |
215 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
262 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
216 | padding => 0, |
263 | padding => 0, |
217 | y => $HEIGHT * 49 / 50, |
264 | y => $HEIGHT * 44 / 45, |
218 | height => $HEIGHT / 50, |
265 | height => $HEIGHT / 45, |
219 | text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
266 | text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
220 | $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
267 | $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
221 | |
268 | |
222 | $MAPWIDGET = new CFClient::UI::MapWidget; |
|
|
223 | $CFClient::UI::TOPLEVEL->add ($MAPWIDGET); |
269 | $CFClient::UI::TOPLEVEL->add ($MAPWIDGET = new CFClient::UI::MapWidget); |
224 | $MAPWIDGET->focus_in; |
270 | $MAPWIDGET->focus_in; |
225 | |
271 | |
226 | config_dialog; |
272 | $CFClient::UI::TOPLEVEL->add ($BUTTONBAR = new CFClient::UI::HBox); |
|
|
273 | |
|
|
274 | $BUTTONBAR->add (my $setup = new CFClient::UI::Flopper x => 0, y => 0, text => "Setup", other => config_dialog, state => 1); |
|
|
275 | $BUTTONBAR->add (my $setup = new CFClient::UI::Flopper x => 0, y => 0, text => "Console", other => console_window); |
227 | } |
276 | } |
228 | |
277 | |
229 | sub destroy_screen { |
278 | sub destroy_screen { |
230 | $CFClient::UI::TOPLEVEL->{children} = []; |
279 | $CFClient::UI::TOPLEVEL->{children} = []; |
231 | undef $SDL_ACTIVE; |
280 | undef $SDL_ACTIVE; |
… | |
… | |
254 | glLoadIdentity; |
303 | glLoadIdentity; |
255 | glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000; |
304 | glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000; |
256 | glMatrixMode GL_MODELVIEW; |
305 | glMatrixMode GL_MODELVIEW; |
257 | glLoadIdentity; |
306 | glLoadIdentity; |
258 | |
307 | |
|
|
308 | glClearColor +($CFG->{fow_intensity}) x 3, 1; |
259 | glClear GL_COLOR_BUFFER_BIT; |
309 | glClear GL_COLOR_BUFFER_BIT; |
260 | |
310 | |
261 | $CFClient::UI::TOPLEVEL->draw; |
311 | $CFClient::UI::TOPLEVEL->draw; |
262 | |
312 | |
263 | SDL::GLSwapBuffers; |
313 | SDL::GLSwapBuffers; |
… | |
… | |
304 | |
354 | |
305 | $self->send ($command); |
355 | $self->send ($command); |
306 | status $command; |
356 | status $command; |
307 | } |
357 | } |
308 | |
358 | |
309 | sub conn::map_update { |
359 | sub conn::feed_map1a { |
310 | my ($self, $dirty) = @_; |
360 | my ($self, $data) = @_; |
311 | |
361 | |
|
|
362 | # $self->Crossfire::Protocol::feed_map1a ($data); |
|
|
363 | |
|
|
364 | $MAP->scroll (delete $self->{delayed_scroll_x}, delete $self->{delayed_scroll_y}); |
|
|
365 | $MAP->map1a_update ($data); |
312 | $MAPWIDGET->update; |
366 | $MAPWIDGET->update; |
313 | } |
367 | } |
314 | |
368 | |
315 | sub conn::map_scroll { |
369 | #sub conn::map_update { |
316 | my ($self, $dx, $dy) = @_; |
370 | # my ($self, $dirty) = @_; |
317 | |
371 | # |
318 | # refresh; |
372 | # $MAPWIDGET->update; |
319 | } |
373 | #} |
320 | |
374 | |
321 | sub conn::map_clear { |
375 | sub conn::map_clear { |
322 | my ($self) = @_; |
376 | my ($self) = @_; |
323 | |
377 | |
|
|
378 | $MAP->clear; |
|
|
379 | |
324 | # refresh; |
380 | # refresh; |
325 | } |
381 | } |
326 | |
382 | |
327 | sub conn::face_find { |
383 | sub conn::face_find { |
328 | my ($self, $face) = @_; |
384 | my ($self, $face) = @_; |
329 | |
385 | |
330 | $FACECACHE->{"$face->{chksum},$face->{name}"} |
386 | $FACECACHE->{"$face->{chksum},$face->{name}"} |
331 | } |
387 | } |
332 | |
388 | |
333 | sub conn::face_update { |
389 | sub conn::face_update { |
334 | my ($self, $face) = @_; |
390 | my ($self, $facenum, $face) = @_; |
335 | |
391 | |
336 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
392 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
337 | |
393 | |
338 | $face->{texture} = new_from_image CFClient::Texture delete $face->{image}; |
394 | my $tex = $face->{texture} = new_from_image CFClient::Texture delete $face->{image}; |
|
|
395 | |
|
|
396 | $MAP->set_texture ($facenum, @$tex{qw(name w h s t)}); |
|
|
397 | $MAPWIDGET->update; |
339 | } |
398 | } |
340 | |
399 | |
341 | sub conn::query { |
400 | sub conn::query { |
342 | my ($self, $flags, $prompt) = @_; |
401 | my ($self, $flags, $prompt) = @_; |
343 | |
402 | |
|
|
403 | #TODO |
344 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
404 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
|
|
405 | } |
|
|
406 | |
|
|
407 | sub conn::drawinfo { |
|
|
408 | my ($self, $color, $text) = @_; |
|
|
409 | |
|
|
410 | my @color = ( |
|
|
411 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
|
|
412 | [1.00, 1.00, 1.00], |
|
|
413 | [0.00, 0.00, 0.55], |
|
|
414 | [1.00, 0.00, 0.00], |
|
|
415 | [1.00, 0.54, 0.00], |
|
|
416 | [0.11, 0.56, 1.00], |
|
|
417 | [0.93, 0.46, 0.00], |
|
|
418 | [0.18, 0.54, 0.34], |
|
|
419 | [0.56, 0.73, 0.56], |
|
|
420 | [0.80, 0.80, 0.80], |
|
|
421 | [0.55, 0.41, 0.13], |
|
|
422 | [0.99, 0.77, 0.26], |
|
|
423 | [0.74, 0.65, 0.41], |
|
|
424 | ); |
|
|
425 | |
|
|
426 | $LOGVIEW->add_paragraph ($color[$color], $text); |
345 | } |
427 | } |
346 | |
428 | |
347 | %SDL_CB = ( |
429 | %SDL_CB = ( |
348 | SDL_QUIT() => sub { |
430 | SDL_QUIT() => sub { |
349 | Event::unloop -1; |
431 | Event::unloop -1; |
… | |
… | |
354 | refresh; |
436 | refresh; |
355 | }, |
437 | }, |
356 | SDL_KEYDOWN() => sub { |
438 | SDL_KEYDOWN() => sub { |
357 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
439 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
358 | # alt-enter |
440 | # alt-enter |
359 | $FULLSCREEN = !$FULLSCREEN; |
|
|
360 | destroy_screen; |
441 | destroy_screen; |
|
|
442 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
361 | init_screen; |
443 | init_screen; |
362 | } else { |
444 | } else { |
363 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
445 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
364 | } |
446 | } |
365 | }, |
447 | }, |
… | |
… | |
382 | |
464 | |
383 | ############################################################################# |
465 | ############################################################################# |
384 | |
466 | |
385 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
467 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
386 | |
468 | |
387 | $CFG ||= { |
469 | my %DEF_CFG = ( |
388 | width => 640, |
470 | width => 640, |
389 | height => 480, |
471 | height => 480, |
390 | fast => 0, |
472 | fast => 0, |
|
|
473 | fow_enable => 1, |
|
|
474 | fow_intensity => 0.45, |
|
|
475 | fow_smooth => 0, |
391 | fullscreen => 0, |
476 | fullscreen => 0, |
392 | sdl_mode => 0, |
477 | sdl_mode => 0, |
393 | mapsize => 100, |
478 | mapsize => 100, |
394 | host => "crossfire.schmorp.de", |
479 | host => "crossfire.schmorp.de", |
395 | port => 13327, |
480 | port => 13327, |
396 | }; |
481 | ); |
|
|
482 | |
|
|
483 | while (my ($k, $v) = each %DEF_CFG) { |
|
|
484 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
|
|
485 | } |
397 | |
486 | |
398 | sdl_init; |
487 | sdl_init; |
399 | |
488 | |
400 | @SDL_MODES = reverse map [SDL::RectW ($_), SDL::RectH ($_)], |
489 | @SDL_MODES = reverse |
|
|
490 | grep $_->[0] >= 640 && $_->[1] >= 480, |
|
|
491 | map [SDL::RectW ($_), SDL::RectH ($_)], |
401 | @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL }; |
492 | @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL }; |
402 | |
493 | |
403 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
494 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
404 | |
495 | |
405 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
496 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
406 | |
497 | |