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.176 by root, Mon Apr 24 10:19:40 2006 UTC vs.
Revision 1.199 by root, Mon May 8 15:12:39 2006 UTC

36 36
37use CFClient; 37use CFClient;
38use CFClient::UI; 38use CFClient::UI;
39use CFClient::MapWidget; 39use CFClient::MapWidget;
40 40
41$SIG{__DIE__} = sub { CFClient::fatal "$_[0]"; exit 1 }; 41$Event::DIED = sub {
42 CFClient::error $_[1];
43};
44
45#$SIG{__WARN__} = sub { Carp::cluck $_[0] };#d#
42 46
43our $VERSION = '0.1'; 47our $VERSION = '0.1';
44 48
45my $MAX_FPS = 60; 49my $MAX_FPS = 60;
46my $MIN_FPS = 5; # unused as of yet 50my $MIN_FPS = 5; # unused as of yet
66 70
67our $FONT_PROP; 71our $FONT_PROP;
68our $FONT_FIXED; 72our $FONT_FIXED;
69 73
70our $MAP; 74our $MAP;
75our $MAPMAP;
71our $MAPWIDGET; 76our $MAPWIDGET;
72our $BUTTONBAR; 77our $BUTTONBAR;
73our $LOGVIEW; 78our $LOGVIEW;
74our $CONSOLE; 79our $CONSOLE;
75our $METASERVER; 80our $METASERVER;
81our $LOGIN_BUTTON;
76 82
77our $FLOORBOX; 83our $FLOORBOX;
78our $GAUGES; 84our $GAUGES;
79our $STATWIDS; 85our $STATWIDS;
80 86
87 93
88our $ALT_ENTER_MESSAGE; 94our $ALT_ENTER_MESSAGE;
89our $STATUS_LINE; 95our $STATUS_LINE;
90our $DEBUG_STATUS; 96our $DEBUG_STATUS;
91 97
98our $INVWIN;
99our $INV;
100
92sub status { 101sub status {
93 $STATUS_LINE->set_text ($_[0]); 102 $STATUS_LINE->set_text ($_[0]);
94 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h}); 103 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h});
95} 104}
96 105
98 $DEBUG_STATUS->set_text ($_[0]); 107 $DEBUG_STATUS->set_text ($_[0]);
99 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h}); 108 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h});
100} 109}
101 110
102sub start_game { 111sub start_game {
112 $LOGIN_BUTTON->set_text ("Logout");
113
103 status "logging in..."; 114 status "logging in...";
104 115
105 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 116 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
106 117
107 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}"; 118 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}";
108 119
109 $MAP = new CFClient::Map $mapsize, $mapsize; 120 $MAP = new CFClient::Map $mapsize, $mapsize;
110 121
111 my ($host, $port) = split /:/, $CFG->{host}; 122 my ($host, $port) = split /:/, $CFG->{host};
112 123
113 $CONN = new conn 124 $CONN = eval {
125 new conn
114 host => $host, 126 host => $host,
115 port => $port || 13327, 127 port => $port || 13327,
116 user => $CFG->{user}, 128 user => $CFG->{user},
117 pass => $CFG->{password}, 129 pass => $CFG->{password},
118 mapw => $mapsize, 130 mapw => $mapsize,
119 maph => $mapsize, 131 maph => $mapsize,
132 ;
120 ; 133 };
121 134
135 if ($CONN) {
122 status "login successful"; 136 status "login successful";
123 137
124 CFClient::lowdelay fileno $CONN->{fh}; 138 CFClient::lowdelay fileno $CONN->{fh};
139 } else {
140 status "unable to connect";
141 stop_game();
142 }
125} 143}
126 144
127sub stop_game { 145sub stop_game {
146 status "connection closed";
147 $LOGIN_BUTTON->set_text ("Login");
128 undef $CONN; 148 undef $CONN;
129} 149}
130 150
131sub client_setup { 151sub client_setup {
132 my $dialog = new CFClient::UI::FancyFrame 152 my $dialog = new CFClient::UI::FancyFrame
309 audio_shutdown (); 329 audio_shutdown ();
310 audio_init (); 330 audio_init ();
311 } 331 }
312 ); 332 );
313 333
334 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Communication cmd");
335 $table->add (1, $row++, my $saycmd = new CFClient::UI::Entry
336 text => $CFG->{say_command},
337 tooltip => "This is the command that will be used if you write a line in the message window entry. "
338 ."Usually you want to enter something like 'say' or 'shout' or 'gsay' here. "
339 ."But you could also set it to 'tell <playername>' to only chat with that user.",
340 connect_changed => sub {
341 my ($self, $value) = @_;
342 $CFG->{say_command} = $value;
343 }
344 );
345
314 $dialog 346 $dialog
315} 347}
316 348
317sub set_stats_window_fontsize { 349sub set_stats_window_fontsize {
318 for (values %{$STATWIDS}) { 350 for (values %{$STATWIDS}) {
351 (my $hb = new CFClient::UI::HBox), 383 (my $hb = new CFClient::UI::HBox),
352 ], 384 ],
353 ); 385 );
354 386
355 $hb->add (my $hg = new CFClient::UI::Gauge type => 'hp', 387 $hb->add (my $hg = new CFClient::UI::Gauge type => 'hp',
356 tooltip => "Health points - depletes when you get wounded, refills when you heal or idle"); 388 tooltip => "Health points. Measures of how much damage you can take before dying. Hit points are determined from your level and are influenced by the value of your Con. Hp value may range between 1 to beyond 500 and higher values indicate a greater ability to withstand punishment.");
357 $hb->add (my $mg = new CFClient::UI::Gauge type => 'mana', 389 $hb->add (my $mg = new CFClient::UI::Gauge type => 'mana',
358 tooltip => "Spell points - deplete when you cast wizard spells, refills when you idle"); 390 tooltip => "Spell points. Measures of how much \"fuel\" you have for casting spells and incantations. Mana is calculated from your level and your Pow. Mana values can range between 1 to beyond 500 (glowing crystals can increase the current spell points beyond your normal maximum). Higher values indicate greater amounts of mana.");
359 $hb->add (my $gg = new CFClient::UI::Gauge type => 'grace', 391 $hb->add (my $gg = new CFClient::UI::Gauge type => 'grace',
360 tooltip => "Grace points - deplete when you cast priest spells, refills when you pray"); 392 tooltip => "Grace points - how favored you are by your god. In game terms, how much divine magic you can cast. Your level, Wis and Pow effect what the value of grace is. Prayong on an altar of your god can increase this value beyond your normal maximum. Grace can take on large positive and negative values. Positive values indicate favor by the gods.");
361 $hb->add (my $fg = new CFClient::UI::Gauge type => 'food', 393 $hb->add (my $fg = new CFClient::UI::Gauge type => 'food',
362 tooltip => "Food - depletes with time, faster when you heal or build mana, refills when you eat healthy food"); 394 tooltip => "Food. Ranges between 0 (starving) and 999 (satiated). At a value of 0 the character begins to die. Some magic can speed up or slow down the character digestion. Healing wounds will speed up digestion too.");
363 395
364 $vbox->add (my $exp = new CFClient::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, 396 $vbox->add (my $exp = new CFClient::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1,
365 tooltip => "Experience points and level - increases when you kill monsters or successfully use skills"); 397 tooltip => "Experience points and overall level - experience is increased as a reward for appropriate action (such as killing monsters) and may decrease as a result of a magical attack or dying. Level is directly derived from the experience value. As the level of the character increases, the character becomes able to succeed at more difficult tasks. A character's level starts at a value of 0 and may range up beyond 100.");
366 $vbox->add (my $rng = new CFClient::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, 398 $vbox->add (my $rng = new CFClient::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1,
367 tooltip => "Ranged attack - how you attack when you press shift-cursor (spell, skill, weapon etc.)"); 399 tooltip => "Ranged attack - how you attack when you press shift-cursor (spell, skill, weapon etc.)");
368 400
369 $GAUGES = { 401 $GAUGES = {
370 exp => $exp, win => $win, range => $rng, 402 exp => $exp, win => $win, range => $rng,
375 407
376 $win 408 $win
377} 409}
378 410
379sub make_stats_window { 411sub make_stats_window {
380 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/5, y => 0, title => "Stats"); 412 my $tgw = new CFClient::UI::FancyFrame x => $WIDTH * 2/5, y => 0, title => "Stats";
381 413
382 $tgw->add (my $vb = new CFClient::UI::VBox); 414 $tgw->add (new CFClient::UI::Window child => my $vb = new CFClient::UI::VBox);
383 $vb->add ($STATWIDS->{title} = new CFClient::UI::Label valign => 0, align => -1, text => "Title:", expand => 1); 415 $vb->add ($STATWIDS->{title} = new CFClient::UI::Label valign => 0, align => -1, text => "Title:", expand => 1);
384 $vb->add ($STATWIDS->{map} = new CFClient::UI::Label valign => 0, align => -1, text => "Map:", expand => 1); 416 $vb->add ($STATWIDS->{map} = new CFClient::UI::Label valign => 0, align => -1, text => "Map:", expand => 1);
385 417
386 $vb->add (my $hb = new CFClient::UI::HBox expand => 1); 418 $vb->add (my $hb = new CFClient::UI::HBox expand => 1);
387 419
388 $hb->add (my $tbl = new CFClient::UI::Table expand => 1); 420 $hb->add (my $tbl = new CFClient::UI::Table expand => 1);
389 421
390 my $black = [0, 0, 0]; 422 my $black = [0, 0, 0];
391 423
392 $tbl->add (0, 0, $STATWIDS->{st_str} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); 424 for (
393 $tbl->add (0, 1, $STATWIDS->{st_dex} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); 425 [0, 0, st_str => "Str", 30, "Physical Strength, determines damage dealt with weapons, how much you can carry, and how often you can attack"],
394 $tbl->add (0, 2, $STATWIDS->{st_con} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); 426 [0, 1, st_dex => "Dex", 30, "Dexterity, your physical agility. Determines chance of being hit and affects armor class and speed"],
395 $tbl->add (0, 3, $STATWIDS->{st_int} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); 427 [0, 2, st_con => "Con", 30, "Constitution, physical health and toughness. Determines how many healthpoints you can have"],
396 $tbl->add (0, 4, $STATWIDS->{st_wis} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); 428 [0, 3, st_int => "Int", 30, "Intelligence, your ability to learn and use skills and incantations (both prayers and magic) and determines how much spell points you can have"],
397 $tbl->add (0, 5, $STATWIDS->{st_pow} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); 429 [0, 4, st_wis => "Wis", 30, "Wisdom, the ability to learn and use divine magic (prayers). Determines how many grace points you can have"],
398 $tbl->add (0, 6, $STATWIDS->{st_cha} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); 430 [0, 5, st_pow => "Pow", 30, "Power, your magical potential. Influences the strength of spell effects, and also how much your spell and grace points increase when leveling up"],
431 [0, 6, st_cha => "Cha", 30, "Charisma, how well you are received by NPCs. Affects buying and selling prices in shops."],
399 432
400 $tbl->add (1, 0, $STATWIDS->{st_str_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Str"); 433 [2, 0, st_wc => "Wc", -120, "Weapon Class, effectiveness of melee/missile attacks. Lower is more potent. Current weapon, level and Str are some things which effect the value of Wc. The value of Wc may range between 25 and -72."],
401 $tbl->add (1, 1, $STATWIDS->{st_dex_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Dex"); 434 [2, 1, st_ac => "Ac", -120, "Armour Class, how protected you are from being hit by any attack. Lower values are better. Ac is based on your race and is modified by the Dex and current armour worn. For characters that cannot wear armour, Ac improves as their level increases."],
402 $tbl->add (1, 2, $STATWIDS->{st_con_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Con"); 435 [2, 2, st_dam => "Dam", 120, "Damage, how much damage your melee/missile attack inflicts. Higher values indicate a greater amount of damage will be inflicted with each attack."],
403 $tbl->add (1, 3, $STATWIDS->{st_int_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Int"); 436 [2, 3, st_arm => "Arm", 120, "Armour, how much damage (from physical attacks) will be subtracted from successful hits made upon you. This value ranges between 0 to 99%. Current armour worn primarily determines Arm value."],
404 $tbl->add (1, 4, $STATWIDS->{st_wis_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Wis"); 437 [2, 4, st_spd => "Spd", 10.54, "Speed, how fast you can move. The value of speed may range between nearly 0 (\"very slow\") to higher than 5 (\"lightning fast\"). Base speed is determined from the Dex and modified downward proportionally by the amount of weight carried which exceeds the Max Carry limit. The armour worn also sets the upper limit on speed."],
405 $tbl->add (1, 5, $STATWIDS->{st_pow_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Pow"); 438 [2, 5, st_wspd => "WSp", 10.54, "Weapon Speed, how many attacks you may make per unit of time (0.120s). Higher values indicate faster attack speed. Current weapon and Dex effect the value of weapon speed."],
406 $tbl->add (1, 6, $STATWIDS->{st_cha_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Cha"); 439 ) {
440 my ($col, $row, $id, $label, $template, $tooltip) = @$_;
407 441
408 $tbl->add (2, 0, $STATWIDS->{st_wc} = new CFClient::UI::Label valign => 0, align => +1, template => "-120"); 442 $tbl->add ($col , $row, $STATWIDS->{$id} = new CFClient::UI::Label
409 $tbl->add (2, 1, $STATWIDS->{st_ac} = new CFClient::UI::Label valign => 0, align => +1, template => "-120"); 443 font => $FONT_FIXED, can_hover => 1, can_events => 1, valign => 0, align => +1, template => $template, tooltip => $tooltip);
410 $tbl->add (2, 2, $STATWIDS->{st_dam} = new CFClient::UI::Label valign => 0, align => +1, template => "120"); 444 $tbl->add ($col + 1, $row, $STATWIDS->{"$id\_lbl"} = new CFClient::UI::Label
411 $tbl->add (2, 3, $STATWIDS->{st_arm} = new CFClient::UI::Label valign => 0, align => +1, template => "120"); 445 font => $FONT_FIXED, can_hover => 1, can_events => 1, fg => $black, valign => 0, align => -1, text => $label, tooltip => $tooltip);
412 $tbl->add (2, 4, $STATWIDS->{st_spd} = new CFClient::UI::Label valign => 0, align => +1, template => "10.54"); 446 }
413 $tbl->add (2, 5, $STATWIDS->{st_wspd} = new CFClient::UI::Label valign => 0, align => +1, template => "9");
414
415 $tbl->add (3, 0, $STATWIDS->{st_wc_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Wc");
416 $tbl->add (3, 1, $STATWIDS->{st_ac_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Ac");
417 $tbl->add (3, 2, $STATWIDS->{st_dam_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Dam");
418 $tbl->add (3, 3, $STATWIDS->{st_arm_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Arm");
419 $tbl->add (3, 4, $STATWIDS->{st_spd_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Sp");
420 $tbl->add (3, 5, $STATWIDS->{st_wspd_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "WSp");
421 447
422 $hb->add (my $tbl2 = new CFClient::UI::Table expand => 1); 448 $hb->add (my $tbl2 = new CFClient::UI::Table expand => 1);
423 449
424 my $row = 0; 450 my $row = 0;
425 my $col = 0; 451 my $col = 0;
426 452
427 my %resist_names = ( 453 my %resist_names = (
428 slow => "Slow", 454 slow => "Slow (slows you down when you are hit by the spell. Monsters will have an opportunity to come near you faster and hit you more often.)",
429 holyw => "Holy Word", 455 holyw => "Holy Word (resistance you against getting the fear when someone whose god doesn't like you spells the holy word on you.)",
430 conf => "Confusion", 456 conf => "Confusion (If you are hit by confusion you will move into random directions, and likely into monsters.)",
431 fire => "Fire", 457 fire => "Fire (just your resistance to fire spells like burning hands, dragonbreath, meteor swarm fire, ...)",
432 depl => "Depletion", 458 depl => "Depletion (some monsters and other effects can cause stats depletion)",
433 magic => "Magic", 459 magic => "Magic (resistance to magic spells like magic missile or similar)",
434 drain => "Draining", 460 drain => "Draining (some monsters (e.g. vampires) and other effects can steal experience)",
435 acid => "Acid", 461 acid => "Acid (resistance to acid, acid hurts pretty much and also corrodes your weapons)",
436 pois => "Poison", 462 pois => "Poison (resistance to getting poisoned)",
437 para => "Paralysation", 463 para => "Paralysation (this resistance affects the chance you get paralysed)",
438 deat => "Death", 464 deat => "Death (resistance against death spells)",
439 phys => "Physical", 465 phys => "Physical (this is the resistance against physical attacks, like when a monster hit you in melee combat)",
440 blind => "Blind", 466 blind => "Blind (blind resistance affects the chance of a successful blinding attack)",
441 fear => "Fear", 467 fear => "Fear (this attack will drive you away from monsters who cast this and hit you successfully, being resistant to this helps a lot when fighting those monsters)",
442 tund => "Turn undead", 468 tund => "Turn undead",
443 elec => "Electricity", 469 elec => "Electricity (resistance againt electricity, spells like large lightning, small lightning, ...)",
444 cold => "Cold", 470 cold => "Cold (this is your resistance against cold spells like icestorm, snowstorm, ...)",
445 ghit => "Ghost hit", 471 ghit => "Ghost hit (special attack used by ghosts and ghost-like beings)",
446 ); 472 );
447 for (qw/slow holyw conf fire depl magic 473 for (qw/slow holyw conf fire depl magic
448 drain acid pois para deat phys 474 drain acid pois para deat phys
449 blind fear tund elec cold ghit/) 475 blind fear tund elec cold ghit/)
450 { 476 {
451 $tbl2->add ($col, $row, 477 $tbl2->add ($col, $row,
452 $STATWIDS->{"res_$_"} = 478 $STATWIDS->{"res_$_"} =
453 new CFClient::UI::Label 479 new CFClient::UI::Label
480 font => $FONT_FIXED,
454 template => "-100%", 481 template => "-100%",
455 align => +1, 482 align => +1,
456 valign => 0, 483 valign => 0,
484 can_events => 1,
485 can_hover => 1,
457 tooltip => $resist_names{$_} 486 tooltip => $resist_names{$_},
458 ); 487 );
459 $tbl2->add ($col + 1, $row, new CFClient::UI::Image 488 $tbl2->add ($col + 1, $row, new CFClient::UI::Image
489 font => $FONT_FIXED,
460 can_hover => 1, 490 can_hover => 1,
461 can_events => 1, 491 can_events => 1,
462 image => "ui/resist/resist_$_.png", 492 image => "ui/resist/resist_$_.png",
463 tooltip => $resist_names{$_} 493 tooltip => $resist_names{$_},
464 ); 494 );
465 495
466 $row++; 496 $row++;
467 if ($row % 6 == 0) { 497 if ($row % 6 == 0) {
468 $col += 2; 498 $col += 2;
547 577
548} 578}
549 579
550sub metaserver_dialog { 580sub metaserver_dialog {
551 my $dialog = new CFClient::UI::FancyFrame 581 my $dialog = new CFClient::UI::FancyFrame
552 title => "Metaserver", 582 title => "Server List",
553 child => (my $vbox = new CFClient::UI::VBox); 583 child => (my $vbox = new CFClient::UI::VBox);
554 584
555 $vbox->add ($dialog->{table} = new CFClient::UI::Table); 585 $vbox->add ($dialog->{table} = new CFClient::UI::Table);
556 586
557 $dialog 587 $dialog
558} 588}
589
590my $METASERVER_ATIME;
559 591
560sub update_metaserver { 592sub update_metaserver {
561 my ($HOST) = @_; 593 my ($HOST) = @_;
562 594
563 status "fetching metaserver list..."; 595 return if $METASERVER_ATIME > time;
596 $METASERVER_ATIME = time + 60;
597
598 my $table = $METASERVER->{table};
599 $table->clear;
600 $table->add (0, 0, my $label = new CFClient::UI::Label max_w => $WIDTH * 0.8, text => "fetching server list...");
564 601
565 my $buf; 602 my $buf;
566 603
567 my $fh = new IO::Socket::INET PeerHost => $META_SERVER, Blocking => 0; 604 my $fh = new IO::Socket::INET PeerHost => $META_SERVER, Blocking => 0;
605
606 unless ($fh) {
607 $label->set_text ("unable to contact metaserver: $!");
608 return;
609 }
568 610
569 Event->io (fd => $fh, poll => 'r', cb => sub { 611 Event->io (fd => $fh, poll => 'r', cb => sub {
570 my $res = sysread $fh, $buf, 8192, length $buf; 612 my $res = sysread $fh, $buf, 8192, length $buf;
571 613
572 if (!defined $res) { 614 if (!defined $res) {
573 $_[0]->w->cancel; 615 $_[0]->w->cancel;
574 status "metaserver: $!"; 616 $label->set_text ("error while retrieving server list: $!");
575 } elsif ($res == 0) { 617 } elsif ($res == 0) {
576 $_[0]->w->cancel; 618 $_[0]->w->cancel;
577 status "server list retrieved"; 619 status "server list retrieved";
578 620
579 my $table = $METASERVER->{table}; 621 utf8::decode $buf if utf8::valid $buf;
580 622
581 $table->clear; 623 $table->clear;
582 624
583 my @col = qw(Use #Users Host Uptime Version Description); 625 my @col = qw(Use #Users Host Uptime Version Description);
584 $table->add ($_, 0, new CFClient::UI::Label align => 0, fg => [1, 1, 0], text => $col[$_]) 626 $table->add ($_, 0, new CFClient::UI::Label align => 0, fg => [1, 1, 0], text => $col[$_])
608 $m = [$users, $host, $uptime, $version, $desc]; 650 $m = [$users, $host, $uptime, $version, $desc];
609 651
610 $y++; 652 $y++;
611 653
612 $table->add (0, $y, new CFClient::UI::VBox children => [ 654 $table->add (0, $y, new CFClient::UI::VBox children => [
613 (new CFClient::UI::Button text => " ", connect_activate => sub { 655 (new CFClient::UI::Button text => "Use", connect_activate => sub {
614 $HOST->set_text ($CFG->{host} = $host); 656 $HOST->set_text ($CFG->{host} = $host);
615 }), 657 }),
616 (new CFClient::UI::Empty expand => 1), 658 (new CFClient::UI::Empty expand => 1),
617 ]); 659 ]);
618 660
677 my ($self, $value) = @_; 719 my ($self, $value) = @_;
678 $CFG->{password} = $value; 720 $CFG->{password} = $value;
679 } 721 }
680 ); 722 );
681 723
682 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd");
683 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry
684 text => $CFG->{say_command},
685 tooltip => "This is the command that will be used if you write a line in the message window entry. "
686 ."Usually you want to enter something like 'say' or 'shout' or 'gsay' here. "
687 ."But you could also set it to 'tell <playername>' to only chat with that user.",
688 connect_changed => sub {
689 my ($self, $value) = @_;
690 $CFG->{say_command} = $value;
691 }
692 );
693
694 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size"); 724 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size");
695 $table->add (1, 7, new CFClient::UI::Slider 725 $table->add (1, 7, new CFClient::UI::Slider
696 req_w => 100, 726 req_w => 100,
697 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 727 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
698 tooltip => "This is the size of the portion of the map update the server sends you. " 728 tooltip => "This is the size of the portion of the map update the server sends you. "
702 732
703 $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 733 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
704 }, 734 },
705 ); 735 );
706 736
707 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { 737 $table->add (1, 8, $LOGIN_BUTTON = new CFClient::UI::Button
738 expand => 1,
739 align => 0,
740 text => "Login",
741 connect_activate => sub {
742 $CONN ? stop_game
708 start_game; 743 : start_game;
744 },
709 }); 745 );
710 746
711 $dialog 747 $dialog
712} 748}
713 749
714sub message_window { 750sub message_window {
715 my $window = new CFClient::UI::FancyFrame 751 my $window = new CFClient::UI::FancyFrame
716 title => "Messages", 752 title => "Messages",
717 border_bg => [1, 1, 1, 0.5], 753 border_bg => [1, 1, 1, 1],
718 bg => [0.3, 0.3, 0.3, 0.8], 754 bg => [0, 0, 0, 0.5],
719 user_w => int $::WIDTH / 3, 755 user_w => int $::WIDTH / 3,
720 user_h => int $::HEIGHT / 5, 756 user_h => int $::HEIGHT / 5,
721 child => (my $vbox = new CFClient::UI::VBox); 757 child => (my $vbox = new CFClient::UI::VBox);
722 758
723 $vbox->add ($LOGVIEW = new CFClient::UI::TextView 759 $vbox->add ($LOGVIEW = new CFClient::UI::TextView
763 }; 799 };
764 800
765 $window 801 $window
766} 802}
767 803
804sub make_inventory_window {
805 my $invwin = new CFClient::UI::FancyFrame user_w => 300, user_h => 300, title => "Inventory";
806 $invwin->add ($INV = new CFClient::UI::Inventory expand => 1);
807 $invwin
808}
809
768sub sdl_init { 810sub sdl_init {
769 CFClient::SDL_Init 811 CFClient::SDL_Init
770 and die "SDL::Init failed!\n"; 812 and die "SDL::Init failed!\n";
771} 813}
772 814
773sub video_init { 815sub video_init {
774 sdl_init; 816 sdl_init;
817
818 $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} >= @SDL_MODES;
775 819
776 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 820 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
777 $FULLSCREEN = $CFG->{fullscreen}; 821 $FULLSCREEN = $CFG->{fullscreen};
778 $FAST = $CFG->{fast}; 822 $FAST = $CFG->{fast};
779 823
803 fontsize => 0.8, 847 fontsize => 0.8,
804 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 848 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
805 $ALT_ENTER_MESSAGE->show; 849 $ALT_ENTER_MESSAGE->show;
806 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); 850 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
807 851
808 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget); 852 CFClient::UI::FancyFrame->new (
809 $MAPWIDGET->focus_in; 853 border_bg => [1, 1, 1, 192/255],
854 bg => [1, 1, 1, 0],
855 child => ($MAPMAP = new CFClient::MapWidget::MapMap),
856 )->show;
857
858 $MAPWIDGET = new CFClient::MapWidget;
810 $MAPWIDGET->connect (activate_console => sub { 859 $MAPWIDGET->connect (activate_console => sub {
811 my ($mapwidget, $preset) = @_; 860 my ($mapwidget, $preset) = @_;
812 861
813 if ($CONSOLE) { 862 if ($CONSOLE) {
814 $CONSOLE->{input}->{auto_activated} = 1; 863 $CONSOLE->{input}->{auto_activated} = 1;
817 if ($preset && $CONSOLE->{input}->get_text eq '') { 866 if ($preset && $CONSOLE->{input}->get_text eq '') {
818 $CONSOLE->{input}->set_text ($preset); 867 $CONSOLE->{input}->set_text ($preset);
819 } 868 }
820 } 869 }
821 }); 870 });
871 $MAPWIDGET->show;
872 $MAPWIDGET->focus_in;
822 873
823 $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox); 874 $BUTTONBAR = new CFClient::UI::HBox;
824 875
825 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup); 876 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup);
826 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup); 877 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup);
827 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window); 878 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window);
828 879
829 $CFClient::UI::ROOT->add (make_gauge_window); # XXX: this has to be set before make_stats_window as make_stats_window calls update_stats_window which updated the gauges also X-D 880 make_gauge_window->show; # XXX: this has to be set before make_stats_window as make_stats_window calls update_stats_window which updated the gauges also X-D
881
830 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window); 882 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window);
883 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Inventory", other => make_inventory_window);
831 884
832 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { 885 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub {
833 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 886 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
834 status "Configuration Saved"; 887 status "Configuration Saved";
835 }); 888 });
836 889
890 $BUTTONBAR->show;
891
837 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 892 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
838} 893}
839 894
840sub video_shutdown { 895sub video_shutdown {
841 $CFClient::UI::ROOT->{children} = []; 896 $CFClient::UI::ROOT->{children} = [];
897 undef $CFClient::UI::GRAB;
898 undef $CFClient::UI::HOVER;
842 undef $SDL_ACTIVE; 899 undef $SDL_ACTIVE;
843} 900}
844 901
845my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# 902my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d#
846my $bgmusic;#TODO#hack#d# 903my $bgmusic;#TODO#hack#d#
904
905sub audio_channel_finished {
906 my ($channel) = @_;
907
908 warn "channel $channel finished\n";#d#
909}
847 910
848sub audio_music_finished { 911sub audio_music_finished {
849 return unless $CFG->{bgm_enable}; 912 return unless $CFG->{bgm_enable};
850 913
851 # TODO: hack, do play loop and mood music 914 # TODO: hack, do play loop and mood music
855 push @bgmusic, shift @bgmusic; 918 push @bgmusic, shift @bgmusic;
856} 919}
857 920
858sub audio_init { 921sub audio_init {
859 if ($CFG->{audio_enable}) { 922 if ($CFG->{audio_enable}) {
860 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { 923 if (open my $fh, "<", CFClient::find_rcfile "sounds/config") {
861 $SDL_MIXER = !CFClient::Mix_OpenAudio; 924 $SDL_MIXER = !CFClient::Mix_OpenAudio;
862 CFClient::Mix_AllocateChannels 8; 925 CFClient::Mix_AllocateChannels 8;
863 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; 926 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
864 927
865 audio_music_finished; 928 audio_music_finished;
1020# at worst. 1083# at worst.
1021sub conn::flood_fill { 1084sub conn::flood_fill {
1022 my ($self, $gx, $gy, $path, $hash, $flags) = @_; 1085 my ($self, $gx, $gy, $path, $hash, $flags) = @_;
1023 1086
1024 # the server does not allow map paths > 6 1087 # the server does not allow map paths > 6
1025 return if 6 <= length $path; 1088 return if 7 <= length $path;
1026 1089
1027 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}}; 1090 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}};
1028 1091
1029 for ( 1092 for (
1030 [1, 0, -1], 1093 [1, 0, -1],
1073 1136
1074 $self->flush_map; 1137 $self->flush_map;
1075 1138
1076 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 1139 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
1077 1140
1078 my $mapmapw = 250; 1141 my $mapmapw = $MAPMAP->{w};
1079 my $mapmaph = 250; 1142 my $mapmaph = $MAPMAP->{h};
1080 1143
1081 $self->{neigh_rect} = [ 1144 $self->{neigh_rect} = [
1082 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, 1145 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
1083 $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h, 1146 $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h,
1084 ]; 1147 ];
1283sub update_floorbox { 1346sub update_floorbox {
1284 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { 1347 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub {
1285 $FLOORBOX->clear; 1348 $FLOORBOX->clear;
1286 $FLOORBOX->add (new CFClient::UI::Empty expand => 1); 1349 $FLOORBOX->add (new CFClient::UI::Empty expand => 1);
1287 1350
1288 my @items = values %{ $CONN->{container}{0} };
1289
1290 # we basically have to use the same sorting as everybody else 1351 # we basically have to use the same sorting as everybody else
1291 @items = sort { $a->{type} <=> $b->{type} } @items; 1352 for my $item (@{ $CONN->{container}{0} }) {
1292 1353 $FLOORBOX->add (new CFClient::UI::InventoryItem item => $item);
1293 for my $item (reverse @items) {
1294 my $desc = $item->{nrof} < 2
1295 ? $item->{name}
1296 : "$item->{nrof} $item->{name_pl}";
1297 # todo: animation widget, face widget, weight(?) etc.
1298 $FLOORBOX->add (my $hbox = new CFClient::UI::HBox
1299 tooltip => (CFClient::UI::Label->escape ($desc)
1300 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"),
1301 can_hover => 1,
1302 can_events => 1,
1303 connect_button_down => sub {
1304 my ($self, $ev, $x, $y) = @_;
1305
1306 # todo: maybe put examine on 1? but should just be a tooltip :(
1307 if ($ev->{button} == 1) {
1308 $CONN->send ("move $CONN->{player}{tag} $item->{tag} 0");
1309 } elsif ($ev->{button} == 2) {
1310 $CONN->send ("apply $item->{tag}");
1311 } elsif ($ev->{button} == 3) {
1312 # examine, lock, mark, maybe other things
1313 warn "MENU not implemented yet\n";
1314 }
1315
1316 1
1317 },
1318 );
1319
1320 $hbox->add (new CFClient::UI::Face
1321 can_events => 0,
1322 face => $item->{face},
1323 anim => $item->{anim},
1324 animspeed => $item->{animspeed},
1325 );
1326
1327 $hbox->add (new CFClient::UI::Label
1328 can_events => 0,
1329 text => $desc,
1330 );
1331 } 1354 }
1332 }); 1355 });
1333 refresh; 1356 refresh;
1334} 1357}
1335 1358
1336sub conn::container_add { 1359sub conn::container_add {
1337 my ($self, $id, $items) = @_; 1360 my ($self, $id, $items) = @_;
1338 1361
1339 update_floorbox if $id == 0; 1362 update_floorbox if $id == 0;
1363 if ($self->{player}{tag} == $id) {
1364 $INV->set_items ($self->{container}{$self->{player}{tag}});
1365 }
1340 # $self-<{player}{tag} => player inv 1366 # $self-<{player}{tag} => player inv
1341 #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; 1367 #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}};
1342} 1368}
1343 1369
1344sub conn::container_clear { 1370sub conn::container_clear {
1345 my ($self, $id) = @_; 1371 my ($self, $id) = @_;
1346 1372
1347 update_floorbox if $id == 0; 1373 update_floorbox if $id == 0;
1374 if ($self->{player}{tag} == $id) {
1375 $INV->set_items ($self->{container}{$id});
1376 }
1377
1348# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; 1378# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0};
1349} 1379}
1350 1380
1351sub conn::item_delete { 1381sub conn::item_delete {
1352 my ($self, @items) = @_; 1382 my ($self, @items) = @_;
1353 1383
1354 for (@items) { 1384 for (@items) {
1355 update_floorbox if $_->{container} == 0; 1385 update_floorbox if $_->{container} == 0;
1386 if ($self->{player}{tag} == $_->{container}) {
1387 $INV->set_items ($self->{container}{$_->{container}});
1388 }
1356 } 1389 }
1357} 1390}
1358 1391
1359sub conn::item_update { 1392sub conn::item_update {
1360 my ($self, $item) = @_; 1393 my ($self, $item) = @_;
1361 1394
1362 update_floorbox if $item->{container} == 0; 1395 update_floorbox if $item->{container} == 0;
1396 if ($self->{player}{tag} == $item->{container}) {
1397 $INV->set_items ($self->{container}{$item->{container}});
1398 }
1363} 1399}
1364 1400
1365%SDL_CB = ( 1401%SDL_CB = (
1366 CFClient::SDL_QUIT => sub { 1402 CFClient::SDL_QUIT => sub {
1367 Event::unloop -1; 1403 Event::unloop -1;
1380 video_init; 1416 video_init;
1381 } else { 1417 } else {
1382 CFClient::UI::feed_sdl_key_down_event ($_[0]); 1418 CFClient::UI::feed_sdl_key_down_event ($_[0]);
1383 } 1419 }
1384 }, 1420 },
1385 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, 1421 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
1386 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, 1422 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
1387 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, 1423 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
1388 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, 1424 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
1389 CFClient::SDL_USEREVENT => \&audio_music_finished, 1425 CFClient::SDL_USEREVENT => sub {
1426 if ($_[0]{code} == 1) {
1427 audio_channel_finished $_[0]{data1};
1428 } elsif ($_[0]{code} == 0) {
1429 audio_music_finished;
1430 }
1431 },
1390); 1432);
1391 1433
1392############################################################################# 1434#############################################################################
1393 1435
1394$SIG{INT} = $SIG{TERM} = sub { exit }; 1436$SIG{INT} = $SIG{TERM} = sub { exit };
1437
1438CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1395 1439
1396$TILECACHE = CFClient::db_table "tilecache"; 1440$TILECACHE = CFClient::db_table "tilecache";
1397$FACEMAP = CFClient::db_table "facemap"; 1441$FACEMAP = CFClient::db_table "facemap";
1398
1399CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1400 1442
1401my %DEF_CFG = ( 1443my %DEF_CFG = (
1402 sdl_mode => 0, 1444 sdl_mode => 0,
1403 width => 640, 1445 width => 640,
1404 height => 480, 1446 height => 480,
1460 1502
1461Event::loop; 1503Event::loop;
1462 1504
1463END { CFClient::SDL_Quit } 1505END { CFClient::SDL_Quit }
1464 1506
1507=head1 pclient - Crossfire+ and Crossfire game client
1465 1508
1509Pclient is a Crossfire+ and Crossfire game client.
1510
1511=head2 Features
1512
1513=over 4
1514
1515=item Fullscreen Map
1516
1517PClient can uses a fullscreen map, which greatly enhances how much of the
1518game world you can see.
1519
1520=item Persistent Map Cache (Crossfire+ only)
1521
1522PClient can persistently cache all map data it received from the
1523server. This not only allows it to display an overview map, but also
1524ensures that once-explored areas will be available the next time you want
1525to explore more.
1526
1527=item Hardware acceleration
1528
1529Unlike most Crossfire clients, PClient take advantage of OpenGL hardware
1530acceleration. Most modern graphics cards have difficulties with 2D
1531acceleration, while 3D graphics is accelerated well.
1532
1533=item No arbitrary limits
1534
1535Unlike other Crossfire clients, pclient does not suffer from arbitrary
1536limits (like a fixed amount of face numbers). There are still limits, but
1537they are not arbitrarily low :)
1538
1539=back
1540
1541=head1 USAGE
1542
1543=head2 The Map
1544
1545The map is always displayed in the background, behind all other windows and UI elements.
1546
1547#TODO# middle-click scrolls
1548#
1549# keys:
1550#
1551# a apply
1552# keypad moves, kp_5 applies ranged attack to self
1553
1554Starting to type enters the I<completion mode>. In that mode, you can type
1555abbreviations or commands and have them executed as soon as they match a
1556valid command. This is best explained by a few examples:
1557
1558Typing B<climb> will display a list of commands with I<climb> in their
1559name, such as I<ready_skill climbing> and I<use_skill climbing>.
1560
1561You can abbreviate commands by typing only the first character of every
1562word. For example, typing I<iwor> will likely select I<invoke word of
1563recall>, while I<ccfo> will select I<cast create food>. Likewise, I<rscli>
1564will likely select I<ready_skill climbing> and I<usl> will give you
1565I<use_skill levitation>.
1566
1567=head2 The map overview
1568
1569#TODO#
1570
1571=head2 The Status area in the lower right corner
1572
1573#TODO#
1574
1575=head2 The I<Statistics>/I>Stats> window
1576
1577#TODO#
1578
1579=head1 FAQ
1580
1581=over 4
1582
1583=item The client is very sluggish and slow, what can I do about this?
1584
1585Most likely, you don't have accelerated OpenGL support. Try to find a
1586newer driver, or a driver from your hardware vendor, that features OpenGL
1587support.
1588
1589If this is not an option, the following Setup options reduce the load and
1590will likely make the client playable with sofwtare rendering (it will
1591still be slow, though):
1592
1593=over 4
1594
1595=item B<Video Mode> should be set as low as possible (e.g. 640x480)
1596
1597=item Enable B<Fast & Ugly> mode
1598
1599=item Disable B<Fog of War>
1600
1601=item Increase B<Map Scale>
1602
1603=back
1604
1605=back
1606
1607=head1 AUTHOR
1608
1609Marc Lehmann <crossfire@schmorp.de>, Robin Redeker <elmex@ta-sa.org>
1610
1611
1612

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines