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.98 by root, Fri Apr 14 00:15:52 2006 UTC vs.
Revision 1.103 by elmex, Fri Apr 14 14:02:52 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
40our $MAP; 41our $MAP;
41our $MAPWIDGET; 42our $MAPWIDGET;
42our $FONTSIZE;
43 43
44our $SDL_ACTIVE; 44our $SDL_ACTIVE;
45our $SDL_EV; 45our $SDL_EV;
46our %SDL_CB; 46our %SDL_CB;
47 47
48our $ALT_ENTER_MESSAGE; 48our $ALT_ENTER_MESSAGE;
49our $STATUS_LINE; 49our $STATUS_LINE;
50our $DEBUG_STATUS; 50our $DEBUG_STATUS;
51our $BUTTONBAR; 51our $BUTTONBAR;
52our $LOGVIEW;
53our $CONSOLE;
52 54
53sub status { 55sub status {
54 $STATUS_LINE->set_text ($_[0]); 56 $STATUS_LINE->set_text ($_[0]);
55 my ($w, $h) = $STATUS_LINE->size_request; 57 my ($w, $h) = $STATUS_LINE->size_request;
56 $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);
86sub stop_game { 88sub stop_game {
87 undef $CONN; 89 undef $CONN;
88} 90}
89 91
90sub config_dialog { 92sub config_dialog {
91 my $dialog = new CFClient::UI::FancyFrame x => 300, y => 100, 93 my $dialog = new CFClient::UI::FancyFrame
92 child => (my $vbox = new CFClient::UI::VBox); 94 child => (my $vbox = new CFClient::UI::VBox);
93 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); 95 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup");
94 $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]);
95 97
96 $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");
143 }); 145 });
144 146
145 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup"); 147 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup");
146 $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]);
147 $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");
148 $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 {
149 151 my ($self, $value) = @_;
152 $CFG->{host} = $value;
153 });
154
150 $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");
151 $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 });
152 160
153 $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");
154 $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 });
155 166
156 $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");
157 $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 });
158 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
159 $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");
160 $table->add (1, 6, new CFClient::UI::Slider 180 $table->add (1, 7, new CFClient::UI::Slider
161 req_w => 100, 181 req_w => 100,
162 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 182 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
163 connect_changed => sub { 183 connect_changed => sub {
164 my ($self, $value) = @_; 184 my ($self, $value) = @_;
165 185
166 $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 186 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
167 }, 187 },
168 ); 188 );
169 189
170 $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 {
171 start_game; 191 start_game;
172 }); 192 });
173 193
174 $vbox->add (my $hbox = new CFClient::UI::HBox); 194 $vbox->add (my $hbox = new CFClient::UI::HBox);
175 195
179 }); 199 });
180 200
181 $dialog 201 $dialog
182} 202}
183 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
235}
236
184sub sdl_init { 237sub sdl_init {
185 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 238 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
186 and die "SDL::Init failed!\n"; 239 and die "SDL::Init failed!\n";
187} 240}
188 241
189sub init_screen { 242sub init_screen {
190 sdl_init; 243 sdl_init;
225 278
226 $FONTSIZE = int $HEIGHT / 40; 279 $FONTSIZE = int $HEIGHT / 40;
227 280
228 ############################################################################# 281 #############################################################################
229 282
230 $DEBUG_STATUS = new CFClient::UI::Label padding => 0; 283 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
231 $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS); 284 $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS);
232 285
233 $STATUS_LINE = new CFClient::UI::Label 286 $STATUS_LINE = new CFClient::UI::Label
234 padding => 0, 287 padding => 0,
235 y => $HEIGHT * 49 / 50 - $FONTSIZE; 288 y => $HEIGHT * 44 / 45 - $FONTSIZE;
236 $CFClient::UI::TOPLEVEL->add ($STATUS_LINE); 289 $CFClient::UI::TOPLEVEL->add ($STATUS_LINE);
237 290
238 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 291 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
239 padding => 0, 292 padding => 0,
240 y => $HEIGHT * 49 / 50, 293 y => $HEIGHT * 44 / 45,
241 height => $HEIGHT / 50, 294 height => $HEIGHT / 45,
242 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 295 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
243 $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE); 296 $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE);
244 297
245 $CFClient::UI::TOPLEVEL->add ($MAPWIDGET = new CFClient::UI::MapWidget); 298 $CFClient::UI::TOPLEVEL->add ($MAPWIDGET = new CFClient::UI::MapWidget);
246 $MAPWIDGET->focus_in; 299 $MAPWIDGET->focus_in;
300 $MAPWIDGET->connect (activate_console => sub {
301 my ($mapwidget, $preset) = @_;
302
303 if ($CONSOLE) {
304 $CONSOLE->{input}->focus_in;
305
306 if ($preset && $CONSOLE->{input}->get_text eq '') {
307 $CONSOLE->{input}->set_text ($preset);
308 }
309 }
310 });
247 311
248 $CFClient::UI::TOPLEVEL->add ($BUTTONBAR = new CFClient::UI::HBox); 312 $CFClient::UI::TOPLEVEL->add ($BUTTONBAR = new CFClient::UI::HBox);
249 313
250 $BUTTONBAR->add (my $setup = new CFClient::UI::Flopper x => 0, y => 0, text => "Setup", other => config_dialog, state => 1); 314 $BUTTONBAR->add (my $setup = new CFClient::UI::Flopper x => 0, y => 0, text => "Setup", other => config_dialog, state => 1);
315 $BUTTONBAR->add (my $setup = new CFClient::UI::Flopper x => 0, y => 0, text => "Console", other => console_window);
251} 316}
252 317
253sub destroy_screen { 318sub destroy_screen {
254 $CFClient::UI::TOPLEVEL->{children} = []; 319 $CFClient::UI::TOPLEVEL->{children} = [];
255 undef $SDL_ACTIVE; 320 undef $SDL_ACTIVE;
373} 438}
374 439
375sub conn::query { 440sub conn::query {
376 my ($self, $flags, $prompt) = @_; 441 my ($self, $flags, $prompt) = @_;
377 442
443 #TODO
378 warn "<<<<QUERY:$flags:$prompt>>>\n";#d# 444 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
445}
446
447sub conn::drawinfo {
448 my ($self, $color, $text) = @_;
449
450 my @color = (
451 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
452 [1.00, 1.00, 1.00],
453 [0.00, 0.00, 0.55],
454 [1.00, 0.00, 0.00],
455 [1.00, 0.54, 0.00],
456 [0.11, 0.56, 1.00],
457 [0.93, 0.46, 0.00],
458 [0.18, 0.54, 0.34],
459 [0.56, 0.73, 0.56],
460 [0.80, 0.80, 0.80],
461 [0.55, 0.41, 0.13],
462 [0.99, 0.77, 0.26],
463 [0.74, 0.65, 0.41],
464 );
465
466 $LOGVIEW->add_paragraph ($color[$color], $text);
379} 467}
380 468
381%SDL_CB = ( 469%SDL_CB = (
382 SDL_QUIT() => sub { 470 SDL_QUIT() => sub {
383 Event::unloop -1; 471 Event::unloop -1;
388 refresh; 476 refresh;
389 }, 477 },
390 SDL_KEYDOWN() => sub { 478 SDL_KEYDOWN() => sub {
391 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 479 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
392 # alt-enter 480 # alt-enter
393 $FULLSCREEN = !$FULLSCREEN;
394 destroy_screen; 481 destroy_screen;
482 $CFG->{fullscreen} = !$CFG->{fullscreen};
395 init_screen; 483 init_screen;
396 } else { 484 } else {
397 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 485 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
398 } 486 }
399 }, 487 },
428 fullscreen => 0, 516 fullscreen => 0,
429 sdl_mode => 0, 517 sdl_mode => 0,
430 mapsize => 100, 518 mapsize => 100,
431 host => "crossfire.schmorp.de", 519 host => "crossfire.schmorp.de",
432 port => 13327, 520 port => 13327,
521 say_command => 'say',
433); 522);
434 523
435while (my ($k, $v) = each %DEF_CFG) { 524while (my ($k, $v) = each %DEF_CFG) {
436 $CFG->{$k} = $v unless exists $CFG->{$k}; 525 $CFG->{$k} = $v unless exists $CFG->{$k};
437} 526}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines