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.104 by root, Fri Apr 14 14:55:28 2006 UTC vs.
Revision 1.112 by root, Sat Apr 15 13:56:26 2006 UTC

21our $VERSION = '0.1'; 21our $VERSION = '0.1';
22 22
23my $MAX_FPS = 60; 23my $MAX_FPS = 60;
24my $MIN_FPS = 5; # unused as of yet 24my $MIN_FPS = 5; # unused as of yet
25 25
26our $META_SERVER = "crossfire.real-time.com:13326";
27
26our $FACECACHE; 28our $FACECACHE;
27 29
28our $LAST_REFRESH; 30our $LAST_REFRESH;
29our $NOW; 31our $NOW;
30 32
38our $FULLSCREEN; 40our $FULLSCREEN;
39our $FONTSIZE; 41our $FONTSIZE;
40 42
41our $MAP; 43our $MAP;
42our $MAPWIDGET; 44our $MAPWIDGET;
45our $BUTTONBAR;
46our $LOGVIEW;
47our $CONSOLE;
48our $METASERVER;
43 49
44our $SDL_ACTIVE; 50our $SDL_ACTIVE;
45our $SDL_EV; 51our $SDL_EV;
46our %SDL_CB; 52our %SDL_CB;
47 53
48our $ALT_ENTER_MESSAGE; 54our $ALT_ENTER_MESSAGE;
49our $STATUS_LINE; 55our $STATUS_LINE;
50our $DEBUG_STATUS; 56our $DEBUG_STATUS;
51our $BUTTONBAR;
52our $LOGVIEW;
53our $CONSOLE;
54 57
55sub status { 58sub status {
56 $STATUS_LINE->set_text ($_[0]); 59 $STATUS_LINE->set_text ($_[0]);
57 my ($w, $h) = $STATUS_LINE->size_request; 60 my ($w, $h) = $STATUS_LINE->size_request;
58 $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h); 61 $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h);
65} 68}
66 69
67sub start_game { 70sub start_game {
68 status "logging in..."; 71 status "logging in...";
69 72
70 my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 73 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
71 74
72 $MAP = new CFClient::Map $mapsize, $mapsize; 75 $MAP = new CFClient::Map $mapsize, $mapsize;
76
77 my ($host, $port) = split /:/, $CFG->{host};
73 78
74 $CONN = new conn 79 $CONN = new conn
75 host => $CFG->{host}, 80 host => $host,
76 port => $CFG->{port}, 81 port => $port || 13327,
77 user => $CFG->{user}, 82 user => $CFG->{user},
78 pass => $CFG->{password}, 83 pass => $CFG->{password},
79 mapw => $mapsize, 84 mapw => $mapsize,
80 maph => $mapsize, 85 maph => $mapsize,
81 ; 86 ;
87 92
88sub stop_game { 93sub stop_game {
89 undef $CONN; 94 undef $CONN;
90} 95}
91 96
92sub config_dialog { 97sub client_setup {
93 my $dialog = new CFClient::UI::FancyFrame 98 my $dialog = new CFClient::UI::FancyFrame
94 child => (my $vbox = new CFClient::UI::VBox); 99 child => (my $vbox = new CFClient::UI::VBox);
95 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); 100 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup");
96 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 101 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
97 102
137 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { 142 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub {
138 my ($self, $value) = @_; 143 my ($self, $value) = @_;
139 $CFG->{fow_smooth} = $value; 144 $CFG->{fow_smooth} = $value;
140 }); 145 });
141 146
147 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize");
148 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub {
149 my ($self, $value) = @_;
150 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value);
151 });
152
142 $table->add (1, 6, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 153 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
143 destroy_screen (); 154 destroy_screen ();
144 init_screen (); 155 init_screen ();
145 }); 156 });
157
158 $dialog
159}
160
161sub metaserver_dialog {
162 my $dialog = new CFClient::UI::FancyFrame
163 child => (my $vbox = new CFClient::UI::VBox);
164
165 $vbox->add ($dialog->{table} = new CFClient::UI::Table);
166
167 $dialog
168}
169
170sub update_metaserver {
171 status "fetching metaserver list...";
172
173 my $buf;
174
175 my $fh = new IO::Socket::INET PeerHost => $META_SERVER, Blocking => 0;
176
177 Event->io (fd => $fh, poll => 'r', cb => sub {
178 my $res = sysread $fh, $buf, 8192, length $buf;
179
180 if (!defined $res) {
181 $_[0]->w->cancel;
182 status "metaserver: $!";
183 } elsif ($res == 0) {
184 $_[0]->w->cancel;
185 status "server list retrieved";
186 warn $buf;
187 }
188 });
189}
190
191sub server_setup {
192 my $dialog = new CFClient::UI::FancyFrame
193 child => (my $vbox = new CFClient::UI::VBox);
146 194
147 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup"); 195 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup");
148 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 196 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
149 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host"); 197 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host:Port");
198
199 {
200 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
201
150 $table->add (1, 2, my $host = new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub { 202 $vbox->add (new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub {
151 my ($self, $value) = @_; 203 my ($self, $value) = @_;
152 $CFG->{host} = $value; 204 $CFG->{host} = $value;
153 }); 205 });
154 206
155 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Port"); 207 $METASERVER = metaserver_dialog;
156 $table->add (1, 3, my $port = new CFClient::UI::Entry text => $CFG->{port}, connect_changed => sub { 208
157 my ($self, $value) = @_; 209 $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub {
158 $CFG->{port} = $value; 210 update_metaserver;
159 }); 211 });
212 }
160 213
161 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); 214 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username");
162 $table->add (1, 4, my $user = new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { 215 $table->add (1, 4, my $user = new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub {
163 my ($self, $value) = @_; 216 my ($self, $value) = @_;
164 $CFG->{user} = $value; 217 $CFG->{user} = $value;
189 242
190 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { 243 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub {
191 start_game; 244 start_game;
192 }); 245 });
193 246
194 $vbox->add (my $hbox = new CFClient::UI::HBox);
195
196 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub {
197 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
198 status "Configuration Saved";
199 });
200
201 $dialog 247 $dialog
202} 248}
203 249
204sub console_window { 250sub message_window {
205 my $window = new CFClient::UI::FancyFrame 251 my $window = new CFClient::UI::FancyFrame
206 border_bg => [1, 1, 1, 0.5], 252 border_bg => [1, 1, 1, 0.5],
207 bg => [0.3, 0.3, 0.3, 0.8], 253 bg => [0.3, 0.3, 0.3, 0.8],
254 user_w => $::WIDTH/4,
255 user_h => $::HEIGHT,
208 child => (my $vbox = new CFClient::UI::VBox); 256 child => (my $vbox = new CFClient::UI::VBox);
209 257
210 $vbox->add ($LOGVIEW = new CFClient::UI::TextView expand => 1); 258 $vbox->add ($LOGVIEW = new CFClient::UI::TextView
259 expand => 1,
260 fontsize => $::CFG->{log_fontsize},
261 );
262
211 $vbox->add (my $input = new CFClient::UI::LineEntry); 263 $vbox->add (my $input = new CFClient::UI::LineEntry);
212 $input->connect (activate => sub { 264 $input->connect (activate => sub {
213 my ($input, $text) = @_; 265 my ($input, $text) = @_;
214 $input->set_text (''); 266 $input->set_text ('');
215 267
233 285
234 $window 286 $window
235} 287}
236 288
237sub sdl_init { 289sub sdl_init {
290 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE
238 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO 291 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
239 and die "SDL::Init failed!\n"; 292 and die "SDL::Init failed!\n";
240} 293}
241 294
242sub init_screen { 295sub init_screen {
279 $FONTSIZE = int $HEIGHT / 40; 332 $FONTSIZE = int $HEIGHT / 40;
280 333
281 ############################################################################# 334 #############################################################################
282 335
283 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 336 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
284 $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS); 337 $CFClient::UI::ROOT->add ($DEBUG_STATUS);
285 338
286 $STATUS_LINE = new CFClient::UI::Label 339 $STATUS_LINE = new CFClient::UI::Label
287 padding => 0, 340 padding => 0,
288 y => $HEIGHT * 44 / 45 - $FONTSIZE; 341 y => $HEIGHT * 44 / 45 - $FONTSIZE;
289 $CFClient::UI::TOPLEVEL->add ($STATUS_LINE); 342 $CFClient::UI::ROOT->add ($STATUS_LINE);
290 343
291 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 344 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
292 padding => 0, 345 padding => 0,
293 y => $HEIGHT * 44 / 45, 346 y => $HEIGHT * 44 / 45,
294 height => $HEIGHT / 45, 347 height => $HEIGHT / 45,
295 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 348 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
296 $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE); 349 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE);
297 350
298 $CFClient::UI::TOPLEVEL->add ($MAPWIDGET = new CFClient::UI::MapWidget); 351 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget);
299 $MAPWIDGET->focus_in; 352 $MAPWIDGET->focus_in;
300 $MAPWIDGET->connect (activate_console => sub { 353 $MAPWIDGET->connect (activate_console => sub {
301 my ($mapwidget, $preset) = @_; 354 my ($mapwidget, $preset) = @_;
302 355
303 if ($CONSOLE) { 356 if ($CONSOLE) {
307 $CONSOLE->{input}->set_text ($preset); 360 $CONSOLE->{input}->set_text ($preset);
308 } 361 }
309 } 362 }
310 }); 363 });
311 364
312 $CFClient::UI::TOPLEVEL->add ($BUTTONBAR = new CFClient::UI::HBox); 365 $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox);
313 366
314 $BUTTONBAR->add (my $setup = new CFClient::UI::Flopper x => 0, y => 0, text => "Setup", other => config_dialog, state => 1); 367 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup);
315 $BUTTONBAR->add (my $setup = new CFClient::UI::Flopper x => 0, y => 0, text => "Console", other => console_window); 368 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup);
369 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window);
370
371 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub {
372 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
373 status "Configuration Saved";
374 });
375
376 $BUTTONBAR->{children}[0]->emit ("activate");
316} 377}
317 378
318sub destroy_screen { 379sub destroy_screen {
319 $CFClient::UI::TOPLEVEL->{children} = []; 380 $CFClient::UI::ROOT->{children} = [];
320 undef $SDL_ACTIVE; 381 undef $SDL_ACTIVE;
321 undef $SDL_EV; 382 undef $SDL_EV;
322 SDL::Quit; 383 SDL::Quit;
323} 384}
324 385
335 debug sprintf "%3.2f", $fps; 396 debug sprintf "%3.2f", $fps;
336 397
337 $want_refresh = 0; 398 $want_refresh = 0;
338 $can_refresh = 0; 399 $can_refresh = 0;
339 400
340 glViewport 0, 0, $WIDTH, $HEIGHT;
341 glClearColor +($CFG->{fow_intensity}) x 3, 1;
342 glClear GL_COLOR_BUFFER_BIT;
343
344 glMatrixMode GL_PROJECTION;
345 glLoadIdentity;
346 glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000;
347 glMatrixMode GL_MODELVIEW;
348 glLoadIdentity;
349
350 $CFClient::UI::TOPLEVEL->draw; 401 $CFClient::UI::ROOT->draw;
351 402
352 SDL::GLSwapBuffers; 403 SDL::GLSwapBuffers;
353 404
354 $LAST_REFRESH = $NOW; 405 $LAST_REFRESH = $NOW;
355} 406}
428sub conn::face_update { 479sub conn::face_update {
429 my ($self, $facenum, $face) = @_; 480 my ($self, $facenum, $face) = @_;
430 481
431 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; 482 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image};
432 483
433 my $tex = $face->{texture} = new_from_image CFClient::Texture delete $face->{image}; 484 my $tex = $face->{texture} =
485 new_from_image CFClient::Texture
486 delete $face->{image}, minify => 1;
434 487
435 $MAP->set_texture ($facenum, @$tex{qw(name w h s t)}); 488 $MAP->set_texture ($facenum, @$tex{qw(name w h s t)}, @{$tex->{minified}});
436 $MAPWIDGET->update; 489 $MAPWIDGET->update;
437} 490}
438 491
439sub conn::query { 492sub conn::query {
440 my ($self, $flags, $prompt) = @_; 493 my ($self, $flags, $prompt) = @_;
504############################################################################# 557#############################################################################
505 558
506CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 559CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
507 560
508my %DEF_CFG = ( 561my %DEF_CFG = (
562 sdl_mode => 0,
509 width => 640, 563 width => 640,
510 height => 480, 564 height => 480,
565 fullscreen => 0,
511 fast => 0, 566 fast => 0,
512 fow_enable => 1, 567 fow_enable => 1,
513 fow_intensity => 0.45, 568 fow_intensity => 0.45,
514 fow_smooth => 0, 569 fow_smooth => 0,
515 fullscreen => 0, 570 log_fontsize => 14,
516 sdl_mode => 0,
517 mapsize => 100, 571 mapsize => 100,
518 host => "crossfire.schmorp.de", 572 host => "crossfire.schmorp.de",
519 port => 13327,
520 say_command => 'say', 573 say_command => 'say',
521); 574);
522 575
523while (my ($k, $v) = each %DEF_CFG) { 576while (my ($k, $v) = each %DEF_CFG) {
524 $CFG->{$k} = $v unless exists $CFG->{$k}; 577 $CFG->{$k} = $v unless exists $CFG->{$k};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines