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.94 by root, Thu Apr 13 01:55:39 2006 UTC vs.
Revision 1.102 by elmex, Fri Apr 14 11:43:51 2006 UTC

34 34
35our @SDL_MODES; 35our @SDL_MODES;
36our $WIDTH; 36our $WIDTH;
37our $HEIGHT; 37our $HEIGHT;
38our $FULLSCREEN; 38our $FULLSCREEN;
39our $FONTSIZE;
39 40
41our $MAP;
40our $MAPWIDGET; 42our $MAPWIDGET;
41our $FONTSIZE;
42 43
43our $SDL_ACTIVE; 44our $SDL_ACTIVE;
44our $SDL_EV; 45our $SDL_EV;
45our %SDL_CB; 46our %SDL_CB;
46 47
47our $ALT_ENTER_MESSAGE; 48our $ALT_ENTER_MESSAGE;
48our $STATUS_LINE; 49our $STATUS_LINE;
49our $DEBUG_STATUS; 50our $DEBUG_STATUS;
51our $BUTTONBAR;
52our $LOGVIEW;
53our $CONSOLE;
50 54
51sub status { 55sub status {
52 $STATUS_LINE->set_text ($_[0]); 56 $STATUS_LINE->set_text ($_[0]);
53 my ($w, $h) = $STATUS_LINE->size_request; 57 my ($w, $h) = $STATUS_LINE->size_request;
54 $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h); 58 $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h);
63sub start_game { 67sub start_game {
64 status "logging in..."; 68 status "logging in...";
65 69
66 my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 70 my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
67 71
72 $MAP = new CFClient::Map $mapsize, $mapsize;
73
68 $CONN = new conn 74 $CONN = new conn
69 host => $CFG->{host}, 75 host => $CFG->{host},
70 port => $CFG->{port}, 76 port => $CFG->{port},
71 user => $CFG->{user}, 77 user => $CFG->{user},
72 pass => $CFG->{password}, 78 pass => $CFG->{password},
82sub stop_game { 88sub stop_game {
83 undef $CONN; 89 undef $CONN;
84} 90}
85 91
86sub config_dialog { 92sub config_dialog {
87 my $dialog = new CFClient::UI::FancyFrame x => 300, y => 100, 93 my $dialog = new CFClient::UI::FancyFrame
88 child => (my $vbox = new CFClient::UI::VBox); 94 child => (my $vbox = new CFClient::UI::VBox);
89 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); 95 $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]); 96 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
91 97
92 $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); 98 $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode");
114 my ($self, $value) = @_; 120 my ($self, $value) = @_;
115 $CFG->{fast} = $value; 121 $CFG->{fast} = $value;
116 }); 122 });
117 123
118 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Fog of War"); 124 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Fog of War");
125 $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub {
126 my ($self, $value) = @_;
127 $CFG->{fow_enable} = $value;
128 });
129
130 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "FoW Intensity");
119 $table->add (1, 3, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub { 131 $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub {
120 my ($self, $value) = @_; 132 my ($self, $value) = @_;
121 $CFG->{fow_intensity} = $value; 133 $CFG->{fow_intensity} = $value;
122 }); 134 });
123 135
124 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Smooth FoW"); 136 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth");
125 $table->add (1, 4, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { 137 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub {
126 my ($self, $value) = @_; 138 my ($self, $value) = @_;
127 $CFG->{fow_smooth} = $value; 139 $CFG->{fow_smooth} = $value;
128 }); 140 });
129 141
130 $table->add (1, 5, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 142 $table->add (1, 6, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
131 destroy_screen (); 143 destroy_screen ();
132 init_screen (); 144 init_screen ();
133 }); 145 });
134 146
135 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup"); 147 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup");
136 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 148 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
137 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host"); 149 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host");
138 $table->add (1, 2, my $host = new CFClient::UI::Entry text => $CFG->{host}); 150 $table->add (1, 2, my $host = new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub {
139 151 my ($self, $value) = @_;
152 $CFG->{host} = $value;
153 });
154
140 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Port"); 155 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Port");
141 $table->add (1, 3, my $port = new CFClient::UI::Entry text => $CFG->{port}); 156 $table->add (1, 3, my $port = new CFClient::UI::Entry text => $CFG->{port}, connect_changed => sub {
157 my ($self, $value) = @_;
158 $CFG->{port} = $value;
159 });
142 160
143 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); 161 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username");
144 $table->add (1, 4, my $user = new CFClient::UI::Entry text => $CFG->{user}); 162 $table->add (1, 4, my $user = new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub {
163 my ($self, $value) = @_;
164 $CFG->{user} = $value;
165 });
145 166
146 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); 167 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password");
147 $table->add (1, 5, my $pass = new CFClient::UI::Entry text => $CFG->{password}, hidden => 1); 168 $table->add (1, 5, my $pass = new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub {
169 my ($self, $value) = @_;
170 $CFG->{password} = $value;
171 });
148 172
173 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Def. say cmd");
174 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub {
175 my ($self, $value) = @_;
176 $CFG->{say_command} = $value;
177 });
178
149 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Map Size"); 179 $table->add (0, 7, new CFClient::UI::Label align => 1, text => "Map Size");
150 $table->add (1, 6, new CFClient::UI::Slider 180 $table->add (1, 7, new CFClient::UI::Slider
151 req_w => 100, 181 req_w => 100,
152 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 182 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
153 connect_changed => sub { 183 connect_changed => sub {
154 my ($self, $value) = @_; 184 my ($self, $value) = @_;
155 185
156 $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 186 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
157 }, 187 },
158 ); 188 );
159 189
160 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { 190 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub {
161 start_game; 191 start_game;
162 }); 192 });
163 193
164 $vbox->add (my $hbox = new CFClient::UI::HBox); 194 $vbox->add (my $hbox = new CFClient::UI::HBox);
165 195
166 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub { 196 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub {
167 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 197 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
168 status "Configuration Saved"; 198 status "Configuration Saved";
169 }); 199 });
170 $CFClient::UI::TOPLEVEL->add ($dialog); 200
201 $dialog
202}
203
204sub console_window {
205 my $window = new CFClient::UI::FancyFrame
206 border_bg => [1, 1, 1, 0.5],
207 bg => [0.3, 0.3, 0.3, 0.8],
208 child => (my $vbox = new CFClient::UI::VBox);
209
210 $vbox->add ($LOGVIEW = new CFClient::UI::TextView expand => 1);
211 $vbox->add (my $input = new CFClient::UI::LineEntry);
212 $input->connect (activate => sub {
213 my ($input, $text) = @_;
214 $input->set_text ('');
215
216 if ($text =~ /^\/(.*)/) {
217 $::CONN->user_send ("command $1");
218 } else {
219 my $say_cmd = $::CFG->{say_command} || 'say';
220 $::CONN->user_send ("command $say_cmd $text");
221 }
222 1
223 });
224 $input->connect (escape => sub {
225 $MAPWIDGET->focus_in
226 });
227 $input->focus_in;
228
229 $CONSOLE = {
230 window => $window,
231 input => $input
232 };
233
234 $window
171} 235}
172 236
173sub sdl_init { 237sub sdl_init {
174 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO 238 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
175 and die "SDL::Init failed!\n"; 239 and die "SDL::Init failed!\n";
214 278
215 $FONTSIZE = int $HEIGHT / 40; 279 $FONTSIZE = int $HEIGHT / 40;
216 280
217 ############################################################################# 281 #############################################################################
218 282
219 $DEBUG_STATUS = new CFClient::UI::Label padding => 0; 283 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
220 $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS); 284 $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS);
221 285
222 $STATUS_LINE = new CFClient::UI::Label 286 $STATUS_LINE = new CFClient::UI::Label
223 padding => 0, 287 padding => 0,
224 y => $HEIGHT * 49 / 50 - $FONTSIZE; 288 y => $HEIGHT * 44 / 45 - $FONTSIZE;
225 $CFClient::UI::TOPLEVEL->add ($STATUS_LINE); 289 $CFClient::UI::TOPLEVEL->add ($STATUS_LINE);
226 290
227 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 291 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
228 padding => 0, 292 padding => 0,
229 y => $HEIGHT * 49 / 50, 293 y => $HEIGHT * 44 / 45,
230 height => $HEIGHT / 50, 294 height => $HEIGHT / 45,
231 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 295 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
232 $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE); 296 $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE);
233 297
234 $MAPWIDGET = new CFClient::UI::MapWidget;
235 $CFClient::UI::TOPLEVEL->add ($MAPWIDGET); 298 $CFClient::UI::TOPLEVEL->add ($MAPWIDGET = new CFClient::UI::MapWidget);
236 $MAPWIDGET->focus_in; 299 $MAPWIDGET->focus_in;
300 $MAPWIDGET->connect (activate_console => sub {
301 if ($CONSOLE) {
302 $CONSOLE->{input}->focus_in;
303 }
304 });
237 305
238 config_dialog; 306 $CFClient::UI::TOPLEVEL->add ($BUTTONBAR = new CFClient::UI::HBox);
307
308 $BUTTONBAR->add (my $setup = new CFClient::UI::Flopper x => 0, y => 0, text => "Setup", other => config_dialog, state => 1);
309 $BUTTONBAR->add (my $setup = new CFClient::UI::Flopper x => 0, y => 0, text => "Console", other => console_window);
239} 310}
240 311
241sub destroy_screen { 312sub destroy_screen {
242 $CFClient::UI::TOPLEVEL->{children} = []; 313 $CFClient::UI::TOPLEVEL->{children} = [];
243 undef $SDL_ACTIVE; 314 undef $SDL_ACTIVE;
317 388
318 $self->send ($command); 389 $self->send ($command);
319 status $command; 390 status $command;
320} 391}
321 392
322my $MAP = new CFClient::Map 63, 63;#d#
323
324sub conn::feed_map1a { 393sub conn::feed_map1a {
325 my ($self, $data) = @_; 394 my ($self, $data) = @_;
326 395
327 $self->Crossfire::Protocol::feed_map1a ($data); 396# $self->Crossfire::Protocol::feed_map1a ($data);
328 397
329 #$MAP->scroll (delete $self->{_dx}, delete $self->{_dy}); 398 $MAP->scroll (delete $self->{delayed_scroll_x}, delete $self->{delayed_scroll_y});
330 #$MAP->map1a_update ($data); 399 $MAP->map1a_update ($data);
331}
332
333sub conn::map_update {
334 my ($self, $dirty) = @_;
335
336 $MAPWIDGET->update; 400 $MAPWIDGET->update;
337} 401}
338 402
339sub conn::map_scroll { 403#sub conn::map_update {
340 my ($self, $dx, $dy) = @_; 404# my ($self, $dirty) = @_;
341 405#
342 $self->{_dx} += $dx; 406# $MAPWIDGET->update;
343 $self->{_dy} += $dy; 407#}
344
345# refresh;
346}
347 408
348sub conn::map_clear { 409sub conn::map_clear {
349 my ($self) = @_; 410 my ($self) = @_;
350 411
412 $MAP->clear;
413
351# refresh; 414# refresh;
352} 415}
353 416
354sub conn::face_find { 417sub conn::face_find {
355 my ($self, $face) = @_; 418 my ($self, $face) = @_;
356 419
357 $FACECACHE->{"$face->{chksum},$face->{name}"} 420 $FACECACHE->{"$face->{chksum},$face->{name}"}
358} 421}
359 422
360sub conn::face_update { 423sub conn::face_update {
361 my ($self, $face) = @_; 424 my ($self, $facenum, $face) = @_;
362 425
363 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; 426 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image};
364 427
365 $face->{texture} = new_from_image CFClient::Texture delete $face->{image}; 428 my $tex = $face->{texture} = new_from_image CFClient::Texture delete $face->{image};
429
430 $MAP->set_texture ($facenum, @$tex{qw(name w h s t)});
431 $MAPWIDGET->update;
366} 432}
367 433
368sub conn::query { 434sub conn::query {
369 my ($self, $flags, $prompt) = @_; 435 my ($self, $flags, $prompt) = @_;
370 436
437 #TODO
371 warn "<<<<QUERY:$flags:$prompt>>>\n";#d# 438 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
439}
440
441sub conn::drawinfo {
442 my ($self, $color, $text) = @_;
443
444 my @color = (
445 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
446 [1.00, 1.00, 1.00],
447 [0.00, 0.00, 0.55],
448 [1.00, 0.00, 0.00],
449 [1.00, 0.54, 0.00],
450 [0.11, 0.56, 1.00],
451 [0.93, 0.46, 0.00],
452 [0.18, 0.54, 0.34],
453 [0.56, 0.73, 0.56],
454 [0.80, 0.80, 0.80],
455 [0.55, 0.41, 0.13],
456 [0.99, 0.77, 0.26],
457 [0.74, 0.65, 0.41],
458 );
459
460 $LOGVIEW->add_paragraph ($color[$color], $text);
372} 461}
373 462
374%SDL_CB = ( 463%SDL_CB = (
375 SDL_QUIT() => sub { 464 SDL_QUIT() => sub {
376 Event::unloop -1; 465 Event::unloop -1;
381 refresh; 470 refresh;
382 }, 471 },
383 SDL_KEYDOWN() => sub { 472 SDL_KEYDOWN() => sub {
384 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 473 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
385 # alt-enter 474 # alt-enter
386 $FULLSCREEN = !$FULLSCREEN;
387 destroy_screen; 475 destroy_screen;
476 $CFG->{fullscreen} = !$CFG->{fullscreen};
388 init_screen; 477 init_screen;
389 } else { 478 } else {
390 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 479 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
391 } 480 }
392 }, 481 },
413 502
414my %DEF_CFG = ( 503my %DEF_CFG = (
415 width => 640, 504 width => 640,
416 height => 480, 505 height => 480,
417 fast => 0, 506 fast => 0,
507 fow_enable => 1,
418 fow_intensity => 0.45, 508 fow_intensity => 0.45,
419 fow_smooth => 0, 509 fow_smooth => 0,
420 fullscreen => 0, 510 fullscreen => 0,
421 sdl_mode => 0, 511 sdl_mode => 0,
422 mapsize => 100, 512 mapsize => 100,
423 host => "crossfire.schmorp.de", 513 host => "crossfire.schmorp.de",
424 port => 13327, 514 port => 13327,
515 say_command => 'say',
425); 516);
426 517
427while (my ($k, $v) = each %DEF_CFG) { 518while (my ($k, $v) = each %DEF_CFG) {
428 $CFG->{$k} = $v unless exists $CFG->{$k}; 519 $CFG->{$k} = $v unless exists $CFG->{$k};
429} 520}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines