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.99 by root, Fri Apr 14 02:03:11 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;
53 57
54sub status { 58sub status {
55 $STATUS_LINE->set_text ($_[0]); 59 $STATUS_LINE->set_text ($_[0]);
56 my ($w, $h) = $STATUS_LINE->size_request; 60 my ($w, $h) = $STATUS_LINE->size_request;
57 $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);
64} 68}
65 69
66sub start_game { 70sub start_game {
67 status "logging in..."; 71 status "logging in...";
68 72
69 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;
70 74
71 $MAP = new CFClient::Map $mapsize, $mapsize; 75 $MAP = new CFClient::Map $mapsize, $mapsize;
76
77 my ($host, $port) = split /:/, $CFG->{host};
72 78
73 $CONN = new conn 79 $CONN = new conn
74 host => $CFG->{host}, 80 host => $host,
75 port => $CFG->{port}, 81 port => $port || 13327,
76 user => $CFG->{user}, 82 user => $CFG->{user},
77 pass => $CFG->{password}, 83 pass => $CFG->{password},
78 mapw => $mapsize, 84 mapw => $mapsize,
79 maph => $mapsize, 85 maph => $mapsize,
80 ; 86 ;
86 92
87sub stop_game { 93sub stop_game {
88 undef $CONN; 94 undef $CONN;
89} 95}
90 96
91sub config_dialog { 97sub client_setup {
92 my $dialog = new CFClient::UI::FancyFrame 98 my $dialog = new CFClient::UI::FancyFrame
93 child => (my $vbox = new CFClient::UI::VBox); 99 child => (my $vbox = new CFClient::UI::VBox);
94 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); 100 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup");
95 $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]);
96 102
136 $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 {
137 my ($self, $value) = @_; 143 my ($self, $value) = @_;
138 $CFG->{fow_smooth} = $value; 144 $CFG->{fow_smooth} = $value;
139 }); 145 });
140 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
141 $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 {
142 destroy_screen (); 154 destroy_screen ();
143 init_screen (); 155 init_screen ();
144 }); 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);
145 194
146 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup"); 195 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup");
147 $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]);
148 $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");
149 $table->add (1, 2, my $host = new CFClient::UI::Entry text => $CFG->{host}); 198
150 199 {
151 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Port"); 200 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
152 $table->add (1, 3, my $port = new CFClient::UI::Entry text => $CFG->{port}); 201
202 $vbox->add (new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub {
203 my ($self, $value) = @_;
204 $CFG->{host} = $value;
205 });
206
207 $METASERVER = metaserver_dialog;
208
209 $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub {
210 update_metaserver;
211 });
212 }
153 213
154 $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");
155 $table->add (1, 4, my $user = new CFClient::UI::Entry text => $CFG->{user}); 215 $table->add (1, 4, my $user = new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub {
216 my ($self, $value) = @_;
217 $CFG->{user} = $value;
218 });
156 219
157 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); 220 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password");
158 $table->add (1, 5, my $pass = new CFClient::UI::Entry text => $CFG->{password}, hidden => 1); 221 $table->add (1, 5, my $pass = new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub {
222 my ($self, $value) = @_;
223 $CFG->{password} = $value;
224 });
159 225
226 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Def. say cmd");
227 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub {
228 my ($self, $value) = @_;
229 $CFG->{say_command} = $value;
230 });
231
160 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Map Size"); 232 $table->add (0, 7, new CFClient::UI::Label align => 1, text => "Map Size");
161 $table->add (1, 6, new CFClient::UI::Slider 233 $table->add (1, 7, new CFClient::UI::Slider
162 req_w => 100, 234 req_w => 100,
163 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 235 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
164 connect_changed => sub { 236 connect_changed => sub {
165 my ($self, $value) = @_; 237 my ($self, $value) = @_;
166 238
167 $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 239 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
168 }, 240 },
169 ); 241 );
170 242
171 $table->add (1, 7, 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 {
172 start_game; 244 start_game;
173 }); 245 });
174 246
175 $vbox->add (my $hbox = new CFClient::UI::HBox);
176
177 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub {
178 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
179 status "Configuration Saved";
180 });
181
182 $dialog 247 $dialog
183} 248}
184 249
185sub console_window { 250sub message_window {
186 my $window = new CFClient::UI::FancyFrame 251 my $window = new CFClient::UI::FancyFrame
187 border_bg => [1, 1, 1, 0.5], 252 border_bg => [1, 1, 1, 0.5],
188 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,
189 child => (my $vbox = new CFClient::UI::VBox); 256 child => (my $vbox = new CFClient::UI::VBox);
190 257
191 $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
192 $vbox->add (my $input = new CFClient::UI::Entry); 263 $vbox->add (my $input = new CFClient::UI::LineEntry);
264 $input->connect (activate => sub {
265 my ($input, $text) = @_;
266 $input->set_text ('');
267
268 if ($text =~ /^\/(.*)/) {
269 $::CONN->user_send ("command $1");
270 } else {
271 my $say_cmd = $::CFG->{say_command} || 'say';
272 $::CONN->user_send ("command $say_cmd $text");
273 }
274 1
275 });
276 $input->connect (escape => sub {
277 $MAPWIDGET->focus_in
278 });
279 $input->focus_in;
280
281 $CONSOLE = {
282 window => $window,
283 input => $input
284 };
193 285
194 $window 286 $window
195} 287}
196 288
197sub sdl_init { 289sub sdl_init {
290 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE
198 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO 291 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
199 and die "SDL::Init failed!\n"; 292 and die "SDL::Init failed!\n";
200} 293}
201 294
202sub init_screen { 295sub init_screen {
239 $FONTSIZE = int $HEIGHT / 40; 332 $FONTSIZE = int $HEIGHT / 40;
240 333
241 ############################################################################# 334 #############################################################################
242 335
243 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 336 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
244 $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS); 337 $CFClient::UI::ROOT->add ($DEBUG_STATUS);
245 338
246 $STATUS_LINE = new CFClient::UI::Label 339 $STATUS_LINE = new CFClient::UI::Label
247 padding => 0, 340 padding => 0,
248 y => $HEIGHT * 44 / 45 - $FONTSIZE; 341 y => $HEIGHT * 44 / 45 - $FONTSIZE;
249 $CFClient::UI::TOPLEVEL->add ($STATUS_LINE); 342 $CFClient::UI::ROOT->add ($STATUS_LINE);
250 343
251 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 344 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
252 padding => 0, 345 padding => 0,
253 y => $HEIGHT * 44 / 45, 346 y => $HEIGHT * 44 / 45,
254 height => $HEIGHT / 45, 347 height => $HEIGHT / 45,
255 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 348 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
256 $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE); 349 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE);
257 350
258 $CFClient::UI::TOPLEVEL->add ($MAPWIDGET = new CFClient::UI::MapWidget); 351 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget);
259 $MAPWIDGET->focus_in; 352 $MAPWIDGET->focus_in;
353 $MAPWIDGET->connect (activate_console => sub {
354 my ($mapwidget, $preset) = @_;
260 355
356 if ($CONSOLE) {
357 $CONSOLE->{input}->focus_in;
358
359 if ($preset && $CONSOLE->{input}->get_text eq '') {
360 $CONSOLE->{input}->set_text ($preset);
361 }
362 }
363 });
364
261 $CFClient::UI::TOPLEVEL->add ($BUTTONBAR = new CFClient::UI::HBox); 365 $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox);
262 366
263 $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);
264 $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");
265} 377}
266 378
267sub destroy_screen { 379sub destroy_screen {
268 $CFClient::UI::TOPLEVEL->{children} = []; 380 $CFClient::UI::ROOT->{children} = [];
269 undef $SDL_ACTIVE; 381 undef $SDL_ACTIVE;
270 undef $SDL_EV; 382 undef $SDL_EV;
271 SDL::Quit; 383 SDL::Quit;
272} 384}
273 385
284 debug sprintf "%3.2f", $fps; 396 debug sprintf "%3.2f", $fps;
285 397
286 $want_refresh = 0; 398 $want_refresh = 0;
287 $can_refresh = 0; 399 $can_refresh = 0;
288 400
289 glViewport 0, 0, $WIDTH, $HEIGHT;
290
291 glMatrixMode GL_PROJECTION;
292 glLoadIdentity;
293 glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000;
294 glMatrixMode GL_MODELVIEW;
295 glLoadIdentity;
296
297 glClearColor +($CFG->{fow_intensity}) x 3, 1;
298 glClear GL_COLOR_BUFFER_BIT;
299
300 $CFClient::UI::TOPLEVEL->draw; 401 $CFClient::UI::ROOT->draw;
301 402
302 SDL::GLSwapBuffers; 403 SDL::GLSwapBuffers;
303 404
304 $LAST_REFRESH = $NOW; 405 $LAST_REFRESH = $NOW;
305} 406}
378sub conn::face_update { 479sub conn::face_update {
379 my ($self, $facenum, $face) = @_; 480 my ($self, $facenum, $face) = @_;
380 481
381 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; 482 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image};
382 483
383 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;
384 487
385 $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}});
386 $MAPWIDGET->update; 489 $MAPWIDGET->update;
387} 490}
388 491
389sub conn::query { 492sub conn::query {
390 my ($self, $flags, $prompt) = @_; 493 my ($self, $flags, $prompt) = @_;
454############################################################################# 557#############################################################################
455 558
456CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 559CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
457 560
458my %DEF_CFG = ( 561my %DEF_CFG = (
562 sdl_mode => 0,
459 width => 640, 563 width => 640,
460 height => 480, 564 height => 480,
565 fullscreen => 0,
461 fast => 0, 566 fast => 0,
462 fow_enable => 1, 567 fow_enable => 1,
463 fow_intensity => 0.45, 568 fow_intensity => 0.45,
464 fow_smooth => 0, 569 fow_smooth => 0,
465 fullscreen => 0, 570 log_fontsize => 14,
466 sdl_mode => 0,
467 mapsize => 100, 571 mapsize => 100,
468 host => "crossfire.schmorp.de", 572 host => "crossfire.schmorp.de",
469 port => 13327, 573 say_command => 'say',
470); 574);
471 575
472while (my ($k, $v) = each %DEF_CFG) { 576while (my ($k, $v) = each %DEF_CFG) {
473 $CFG->{$k} = $v unless exists $CFG->{$k}; 577 $CFG->{$k} = $v unless exists $CFG->{$k};
474} 578}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines