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.211 by root, Fri May 12 02:08:52 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 # TODO: display dialog box or so
43 CFClient::error $_[1];
44};
45
46#$SIG{__WARN__} = sub { Carp::cluck $_[0] };#d#
42 47
43our $VERSION = '0.1'; 48our $VERSION = '0.1';
44 49
45my $MAX_FPS = 60; 50my $MAX_FPS = 60;
46my $MIN_FPS = 5; # unused as of yet 51my $MIN_FPS = 5; # unused as of yet
55our $NOW; 60our $NOW;
56 61
57our $CFG; 62our $CFG;
58our $CONN; 63our $CONN;
59our $FAST; # fast, low-quality mode, possibly useful for software-rendering 64our $FAST; # fast, low-quality mode, possibly useful for software-rendering
65
66our $WANT_REFRESH;
67our $CAN_REFRESH;
60 68
61our @SDL_MODES; 69our @SDL_MODES;
62our $WIDTH; 70our $WIDTH;
63our $HEIGHT; 71our $HEIGHT;
64our $FULLSCREEN; 72our $FULLSCREEN;
66 74
67our $FONT_PROP; 75our $FONT_PROP;
68our $FONT_FIXED; 76our $FONT_FIXED;
69 77
70our $MAP; 78our $MAP;
79our $MAPMAP;
71our $MAPWIDGET; 80our $MAPWIDGET;
72our $BUTTONBAR; 81our $BUTTONBAR;
73our $LOGVIEW; 82our $LOGVIEW;
74our $CONSOLE; 83our $CONSOLE;
75our $METASERVER; 84our $METASERVER;
85our $LOGIN_BUTTON;
76 86
77our $FLOORBOX; 87our $FLOORBOX;
78our $GAUGES; 88our $GAUGES;
79our $STATWIDS; 89our $STATWIDS;
80 90
87 97
88our $ALT_ENTER_MESSAGE; 98our $ALT_ENTER_MESSAGE;
89our $STATUS_LINE; 99our $STATUS_LINE;
90our $DEBUG_STATUS; 100our $DEBUG_STATUS;
91 101
102our $INVWIN;
103our $INV;
104
92sub status { 105sub status {
93 $STATUS_LINE->set_text ($_[0]); 106 $STATUS_LINE->add ($_[0], pri => -10, group => "status", timeout => 20, color => [1, 1, 0, 1]);
94 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h}); 107 $CFClient::UI::ROOT->on_post_alloc ($STATUS_LINE => sub {
108 $STATUS_LINE->move (0, $HEIGHT - $STATUS_LINE->{h});#d# to in toplevel
109 });
95} 110}
96 111
97sub debug { 112sub debug {
98 $DEBUG_STATUS->set_text ($_[0]); 113 $DEBUG_STATUS->set_text ($_[0]);
99 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h}); 114 my ($w, $h) = $DEBUG_STATUS->size_request;
115 $DEBUG_STATUS->move ($WIDTH - $w, 0);
100} 116}
101 117
102sub start_game { 118sub start_game {
103 status "logging in..."; 119 status "logging in...";
104 120
105 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 121 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
106 122
107 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}"; 123 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}";
108
109 $MAP = new CFClient::Map $mapsize, $mapsize; 124 $MAP = new CFClient::Map $mapsize, $mapsize;
110 125
111 my ($host, $port) = split /:/, $CFG->{host}; 126 my ($host, $port) = split /:/, $CFG->{host};
112 127
113 $CONN = new conn 128 $CONN = eval {
129 new conn
114 host => $host, 130 host => $host,
115 port => $port || 13327, 131 port => $port || 13327,
116 user => $CFG->{user}, 132 user => $CFG->{user},
117 pass => $CFG->{password}, 133 pass => $CFG->{password},
118 mapw => $mapsize, 134 mapw => $mapsize,
119 maph => $mapsize, 135 maph => $mapsize,
136 ;
120 ; 137 };
121 138
139 if ($CONN) {
140 $LOGIN_BUTTON->set_text ("Logout");
141
122 status "login successful"; 142 status "login successful";
123 143
124 CFClient::lowdelay fileno $CONN->{fh}; 144 CFClient::lowdelay fileno $CONN->{fh};
145 } else {
146 status "unable to connect";
147 stop_game();
148 }
125} 149}
126 150
127sub stop_game { 151sub stop_game {
152 return unless $CONN;
153
154 status "connection closed";
155 $LOGIN_BUTTON->set_text ("Login");
156 $CONN->destroy;
157 $CONN = 0; # false, does not autovivify
158
159 undef $MAPCACHE;
128 undef $CONN; 160 undef $MAP;
129} 161}
130 162
131sub client_setup { 163sub client_setup {
132 my $dialog = new CFClient::UI::FancyFrame 164 my $dialog = new CFClient::UI::FancyFrame
133 title => "Client Setup", 165 title => "Client Setup",
309 audio_shutdown (); 341 audio_shutdown ();
310 audio_init (); 342 audio_init ();
311 } 343 }
312 ); 344 );
313 345
346 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Communication cmd");
347 $table->add (1, $row++, my $saycmd = new CFClient::UI::Entry
348 text => $CFG->{say_command},
349 tooltip => "This is the command that will be used if you write a line in the message window entry. "
350 ."Usually you want to enter something like 'say' or 'shout' or 'gsay' here. "
351 ."But you could also set it to 'tell <playername>' to only chat with that user.",
352 connect_changed => sub {
353 my ($self, $value) = @_;
354 $CFG->{say_command} = $value;
355 }
356 );
357
314 $dialog 358 $dialog
315} 359}
316 360
317sub set_stats_window_fontsize { 361sub set_stats_window_fontsize {
318 for (values %{$STATWIDS}) { 362 for (values %{$STATWIDS}) {
351 (my $hb = new CFClient::UI::HBox), 395 (my $hb = new CFClient::UI::HBox),
352 ], 396 ],
353 ); 397 );
354 398
355 $hb->add (my $hg = new CFClient::UI::Gauge type => 'hp', 399 $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"); 400 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', 401 $hb->add (my $mg = new CFClient::UI::Gauge type => 'mana',
358 tooltip => "Spell points - deplete when you cast wizard spells, refills when you idle"); 402 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', 403 $hb->add (my $gg = new CFClient::UI::Gauge type => 'grace',
360 tooltip => "Grace points - deplete when you cast priest spells, refills when you pray"); 404 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', 405 $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"); 406 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 407
364 $vbox->add (my $exp = new CFClient::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, 408 $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"); 409 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, 410 $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.)"); 411 tooltip => "Ranged attack - how you attack when you press shift-cursor (spell, skill, weapon etc.)");
368 412
369 $GAUGES = { 413 $GAUGES = {
370 exp => $exp, win => $win, range => $rng, 414 exp => $exp, win => $win, range => $rng,
375 419
376 $win 420 $win
377} 421}
378 422
379sub make_stats_window { 423sub make_stats_window {
380 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/5, y => 0, title => "Stats"); 424 my $tgw = new CFClient::UI::FancyFrame x => $WIDTH * 2/5, y => 0, title => "Stats";
381 425
382 $tgw->add (my $vb = new CFClient::UI::VBox); 426 $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); 427 $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); 428 $vb->add ($STATWIDS->{map} = new CFClient::UI::Label valign => 0, align => -1, text => "Map:", expand => 1);
385 429
386 $vb->add (my $hb = new CFClient::UI::HBox expand => 1); 430 $vb->add (my $hb = new CFClient::UI::HBox expand => 1);
387 431
388 $hb->add (my $tbl = new CFClient::UI::Table expand => 1); 432 $hb->add (my $tbl = new CFClient::UI::Table expand => 1);
389 433
390 my $black = [0, 0, 0]; 434 my $black = [0, 0, 0];
391 435
392 $tbl->add (0, 0, $STATWIDS->{st_str} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); 436 for (
393 $tbl->add (0, 1, $STATWIDS->{st_dex} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); 437 [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"); 438 [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"); 439 [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"); 440 [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"); 441 [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"); 442 [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"],
443 [0, 6, st_cha => "Cha", 30, "Charisma, how well you are received by NPCs. Affects buying and selling prices in shops."],
399 444
400 $tbl->add (1, 0, $STATWIDS->{st_str_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Str"); 445 [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"); 446 [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"); 447 [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"); 448 [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"); 449 [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"); 450 [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"); 451 ) {
452 my ($col, $row, $id, $label, $template, $tooltip) = @$_;
407 453
408 $tbl->add (2, 0, $STATWIDS->{st_wc} = new CFClient::UI::Label valign => 0, align => +1, template => "-120"); 454 $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"); 455 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"); 456 $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"); 457 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"); 458 }
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 459
422 $hb->add (my $tbl2 = new CFClient::UI::Table expand => 1); 460 $hb->add (my $tbl2 = new CFClient::UI::Table expand => 1);
423 461
424 my $row = 0; 462 my $row = 0;
425 my $col = 0; 463 my $col = 0;
426 464
427 my %resist_names = ( 465 my %resist_names = (
428 slow => "Slow", 466 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", 467 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", 468 conf => "Confusion (If you are hit by confusion you will move into random directions, and likely into monsters.)",
431 fire => "Fire", 469 fire => "Fire (just your resistance to fire spells like burning hands, dragonbreath, meteor swarm fire, ...)",
432 depl => "Depletion", 470 depl => "Depletion (some monsters and other effects can cause stats depletion)",
433 magic => "Magic", 471 magic => "Magic (resistance to magic spells like magic missile or similar)",
434 drain => "Draining", 472 drain => "Draining (some monsters (e.g. vampires) and other effects can steal experience)",
435 acid => "Acid", 473 acid => "Acid (resistance to acid, acid hurts pretty much and also corrodes your weapons)",
436 pois => "Poison", 474 pois => "Poison (resistance to getting poisoned)",
437 para => "Paralysation", 475 para => "Paralysation (this resistance affects the chance you get paralysed)",
438 deat => "Death", 476 deat => "Death (resistance against death spells)",
439 phys => "Physical", 477 phys => "Physical (this is the resistance against physical attacks, like when a monster hit you in melee combat)",
440 blind => "Blind", 478 blind => "Blind (blind resistance affects the chance of a successful blinding attack)",
441 fear => "Fear", 479 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", 480 tund => "Turn undead",
443 elec => "Electricity", 481 elec => "Electricity (resistance againt electricity, spells like large lightning, small lightning, ...)",
444 cold => "Cold", 482 cold => "Cold (this is your resistance against cold spells like icestorm, snowstorm, ...)",
445 ghit => "Ghost hit", 483 ghit => "Ghost hit (special attack used by ghosts and ghost-like beings)",
446 ); 484 );
447 for (qw/slow holyw conf fire depl magic 485 for (qw/slow holyw conf fire depl magic
448 drain acid pois para deat phys 486 drain acid pois para deat phys
449 blind fear tund elec cold ghit/) 487 blind fear tund elec cold ghit/)
450 { 488 {
451 $tbl2->add ($col, $row, 489 $tbl2->add ($col, $row,
452 $STATWIDS->{"res_$_"} = 490 $STATWIDS->{"res_$_"} =
453 new CFClient::UI::Label 491 new CFClient::UI::Label
492 font => $FONT_FIXED,
454 template => "-100%", 493 template => "-100%",
455 align => +1, 494 align => +1,
456 valign => 0, 495 valign => 0,
496 can_events => 1,
497 can_hover => 1,
457 tooltip => $resist_names{$_} 498 tooltip => $resist_names{$_},
458 ); 499 );
459 $tbl2->add ($col + 1, $row, new CFClient::UI::Image 500 $tbl2->add ($col + 1, $row, new CFClient::UI::Image
501 font => $FONT_FIXED,
460 can_hover => 1, 502 can_hover => 1,
461 can_events => 1, 503 can_events => 1,
462 image => "ui/resist/resist_$_.png", 504 image => "ui/resist/resist_$_.png",
463 tooltip => $resist_names{$_} 505 tooltip => $resist_names{$_},
464 ); 506 );
465 507
466 $row++; 508 $row++;
467 if ($row % 6 == 0) { 509 if ($row % 6 == 0) {
468 $col += 2; 510 $col += 2;
547 589
548} 590}
549 591
550sub metaserver_dialog { 592sub metaserver_dialog {
551 my $dialog = new CFClient::UI::FancyFrame 593 my $dialog = new CFClient::UI::FancyFrame
552 title => "Metaserver", 594 title => "Server List",
553 child => (my $vbox = new CFClient::UI::VBox); 595 child => (my $vbox = new CFClient::UI::VBox);
554 596
555 $vbox->add ($dialog->{table} = new CFClient::UI::Table); 597 $vbox->add ($dialog->{table} = new CFClient::UI::Table);
556 598
557 $dialog 599 $dialog
558} 600}
601
602my $METASERVER_ATIME;
559 603
560sub update_metaserver { 604sub update_metaserver {
561 my ($HOST) = @_; 605 my ($HOST) = @_;
562 606
563 status "fetching metaserver list..."; 607 return if $METASERVER_ATIME > time;
608 $METASERVER_ATIME = time + 60;
609
610 my $table = $METASERVER->{table};
611 $table->clear;
612 $table->add (0, 0, my $label = new CFClient::UI::Label max_w => $WIDTH * 0.8, text => "fetching server list...");
564 613
565 my $buf; 614 my $buf;
566 615
567 my $fh = new IO::Socket::INET PeerHost => $META_SERVER, Blocking => 0; 616 my $fh = new IO::Socket::INET PeerHost => $META_SERVER, Blocking => 0;
617
618 unless ($fh) {
619 $label->set_text ("unable to contact metaserver: $!");
620 return;
621 }
568 622
569 Event->io (fd => $fh, poll => 'r', cb => sub { 623 Event->io (fd => $fh, poll => 'r', cb => sub {
570 my $res = sysread $fh, $buf, 8192, length $buf; 624 my $res = sysread $fh, $buf, 8192, length $buf;
571 625
572 if (!defined $res) { 626 if (!defined $res) {
573 $_[0]->w->cancel; 627 $_[0]->w->cancel;
574 status "metaserver: $!"; 628 $label->set_text ("error while retrieving server list: $!");
575 } elsif ($res == 0) { 629 } elsif ($res == 0) {
576 $_[0]->w->cancel; 630 $_[0]->w->cancel;
577 status "server list retrieved"; 631 status "server list retrieved";
578 632
579 my $table = $METASERVER->{table}; 633 utf8::decode $buf if utf8::valid $buf;
580 634
581 $table->clear; 635 $table->clear;
582 636
583 my @col = qw(Use #Users Host Uptime Version Description); 637 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[$_]) 638 $table->add ($_, 0, new CFClient::UI::Label align => 0, fg => [1, 1, 0], text => $col[$_])
608 $m = [$users, $host, $uptime, $version, $desc]; 662 $m = [$users, $host, $uptime, $version, $desc];
609 663
610 $y++; 664 $y++;
611 665
612 $table->add (0, $y, new CFClient::UI::VBox children => [ 666 $table->add (0, $y, new CFClient::UI::VBox children => [
613 (new CFClient::UI::Button text => " ", connect_activate => sub { 667 (new CFClient::UI::Button text => "Use", connect_activate => sub {
614 $HOST->set_text ($CFG->{host} = $host); 668 $HOST->set_text ($CFG->{host} = $host);
615 }), 669 }),
616 (new CFClient::UI::Empty expand => 1), 670 (new CFClient::UI::Empty expand => 1),
617 ]); 671 ]);
618 672
647 701
648 $METASERVER = metaserver_dialog; 702 $METASERVER = metaserver_dialog;
649 703
650 $vbox->add (new CFClient::UI::Flopper 704 $vbox->add (new CFClient::UI::Flopper
651 expand => 1, 705 expand => 1,
652 text => "Metaserver", 706 text => "Server List",
653 other => $METASERVER, 707 other => $METASERVER,
654 tooltip => "Show a list of avaible crossfire servers", 708 tooltip => "Show a list of available crossfire servers",
655 connect_open => sub { 709 connect_open => sub {
656 update_metaserver $HOST; 710 update_metaserver $HOST;
657 } 711 }
658 ); 712 );
659 } 713 }
674 hidden => 1, 728 hidden => 1,
675 tooltip => "The password for your character", 729 tooltip => "The password for your character",
676 connect_changed => sub { 730 connect_changed => sub {
677 my ($self, $value) = @_; 731 my ($self, $value) = @_;
678 $CFG->{password} = $value; 732 $CFG->{password} = $value;
679 }
680 );
681
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 } 733 }
692 ); 734 );
693 735
694 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size"); 736 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size");
695 $table->add (1, 7, new CFClient::UI::Slider 737 $table->add (1, 7, new CFClient::UI::Slider
702 744
703 $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 745 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
704 }, 746 },
705 ); 747 );
706 748
707 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { 749 $table->add (1, 8, $LOGIN_BUTTON = new CFClient::UI::Button
750 expand => 1,
751 align => 0,
752 text => "Login",
753 connect_activate => sub {
754 $CONN ? stop_game
708 start_game; 755 : start_game;
756 },
709 }); 757 );
710 758
711 $dialog 759 $dialog
712} 760}
713 761
714sub message_window { 762sub message_window {
715 my $window = new CFClient::UI::FancyFrame 763 my $window = new CFClient::UI::FancyFrame
716 title => "Messages", 764 title => "Messages",
717 border_bg => [1, 1, 1, 0.5], 765 border_bg => [1, 1, 1, 1],
718 bg => [0.3, 0.3, 0.3, 0.8], 766 bg => [0, 0, 0, 0.5],
719 user_w => int $::WIDTH / 3, 767 user_w => int $::WIDTH / 3,
720 user_h => int $::HEIGHT / 5, 768 user_h => int $::HEIGHT / 5,
721 child => (my $vbox = new CFClient::UI::VBox); 769 child => (my $vbox = new CFClient::UI::VBox);
722 770
723 $vbox->add ($LOGVIEW = new CFClient::UI::TextView 771 $vbox->add ($LOGVIEW = new CFClient::UI::TextView
763 }; 811 };
764 812
765 $window 813 $window
766} 814}
767 815
816sub make_inventory_window {
817 my $invwin = new CFClient::UI::FancyFrame user_w => 300, user_h => 300, title => "Inventory";
818 $invwin->add ($INV = new CFClient::UI::Inventory expand => 1);
819 $invwin
820}
821
768sub sdl_init { 822sub sdl_init {
769 CFClient::SDL_Init 823 CFClient::SDL_Init
770 and die "SDL::Init failed!\n"; 824 and die "SDL::Init failed!\n";
771} 825}
772 826
773sub video_init { 827sub video_init {
774 sdl_init; 828 sdl_init;
775 829
830 $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} >= @SDL_MODES;
831
776 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 832 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
777 $FULLSCREEN = $CFG->{fullscreen}; 833 $FULLSCREEN = $CFG->{fullscreen};
778 $FAST = $CFG->{fast}; 834 $FAST = $CFG->{fast};
779 835
780 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN 836 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
781 or die "SDL_SetVideoMode failed!\n"; 837 or die "SDL_SetVideoMode failed!\n";
782 838
783 $SDL_ACTIVE = 1; 839 $SDL_ACTIVE = 1;
784
785 $LAST_REFRESH = time - 0.01; 840 $LAST_REFRESH = time - 0.01;
786 841
787 CFClient::gl_init; 842 CFClient::gl_init;
788 843
789 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; 844 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
790 845
846 $CFClient::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d#
847
791 ############################################################################# 848 #############################################################################
792 849
850 if ($DEBUG_STATUS) {
851 # reconfigure all widgets
852 $CFClient::UI::ROOT->reconfigure;
853
854 } else {
855 # create the widgets
856
793 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 857 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100, text => "hulla", x => 100;#d#
794 $DEBUG_STATUS->show; 858 $DEBUG_STATUS->show;
795 859
796 $STATUS_LINE = new CFClient::UI::Label 860 $STATUS_LINE = new CFClient::UI::Statusbox;
797 padding => 0, 861 $STATUS_LINE->add ("Use <b>Alt-Enter</b> to toggle fullscreen mode", pri => -100, size => 0.8, color => [1, 1, 1, 0.8]);
798 y => $HEIGHT - $FONTSIZE * 1.8;
799 $STATUS_LINE->show; 862 $STATUS_LINE->show;
800 863
801 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 864 CFClient::UI::FancyFrame->new (
802 padding => 0, 865 border_bg => [1, 1, 1, 192/255],
803 fontsize => 0.8, 866 bg => [1, 1, 1, 0],
804 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 867 child => ($MAPMAP = new CFClient::MapWidget::MapMap),
805 $ALT_ENTER_MESSAGE->show; 868 )->show;
806 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
807 869
808 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget); 870 $MAPWIDGET = new CFClient::MapWidget;
809 $MAPWIDGET->focus_in;
810 $MAPWIDGET->connect (activate_console => sub { 871 $MAPWIDGET->connect (activate_console => sub {
811 my ($mapwidget, $preset) = @_; 872 my ($mapwidget, $preset) = @_;
812 873
813 if ($CONSOLE) { 874 if ($CONSOLE) {
814 $CONSOLE->{input}->{auto_activated} = 1; 875 $CONSOLE->{input}->{auto_activated} = 1;
815 $CONSOLE->{input}->focus_in; 876 $CONSOLE->{input}->focus_in;
816 877
817 if ($preset && $CONSOLE->{input}->get_text eq '') { 878 if ($preset && $CONSOLE->{input}->get_text eq '') {
818 $CONSOLE->{input}->set_text ($preset); 879 $CONSOLE->{input}->set_text ($preset);
880 }
819 } 881 }
820 } 882 });
821 }); 883 $MAPWIDGET->show;
884 $MAPWIDGET->focus_in;
822 885
823 $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox); 886 $BUTTONBAR = new CFClient::UI::HBox;
824 887
825 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup); 888 $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); 889 $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); 890 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window);
828 891
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 892 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
893
830 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window); 894 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window);
895 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Inventory", other => make_inventory_window);
831 896
832 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { 897 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub {
833 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 898 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
834 status "Configuration Saved"; 899 status "Configuration Saved";
835 }); 900 });
836 901
902 $BUTTONBAR->show;
903
904 # delay till geometry is constant
905 $CFClient::UI::ROOT->on_post_alloc (startup => sub {
837 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 906 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
907 });
908 force_refresh ();
909 }
838} 910}
839 911
840sub video_shutdown { 912sub video_shutdown {
841 $CFClient::UI::ROOT->{children} = [];
842 undef $SDL_ACTIVE; 913 undef $SDL_ACTIVE;
843} 914}
844 915
845my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# 916my @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# 917my $bgmusic;#TODO#hack#d#
918
919sub audio_channel_finished {
920 my ($channel) = @_;
921
922 warn "channel $channel finished\n";#d#
923}
847 924
848sub audio_music_finished { 925sub audio_music_finished {
849 return unless $CFG->{bgm_enable}; 926 return unless $CFG->{bgm_enable};
850 927
851 # TODO: hack, do play loop and mood music 928 # TODO: hack, do play loop and mood music
855 push @bgmusic, shift @bgmusic; 932 push @bgmusic, shift @bgmusic;
856} 933}
857 934
858sub audio_init { 935sub audio_init {
859 if ($CFG->{audio_enable}) { 936 if ($CFG->{audio_enable}) {
860 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { 937 if (open my $fh, "<", CFClient::find_rcfile "sounds/config") {
861 $SDL_MIXER = !CFClient::Mix_OpenAudio; 938 $SDL_MIXER = !CFClient::Mix_OpenAudio;
862 CFClient::Mix_AllocateChannels 8; 939 CFClient::Mix_AllocateChannels 8;
863 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; 940 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
864 941
865 audio_music_finished; 942 audio_music_finished;
892} 969}
893 970
894my %animate_object; 971my %animate_object;
895my $animate_timer; 972my $animate_timer;
896 973
897my $want_refresh;
898my $can_refresh;
899
900my $fps = 9; 974my $fps = 9;
901 975
902sub force_refresh { 976sub force_refresh {
903 $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05; 977 $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05;
904 debug sprintf "%3.2f", $fps; 978 debug sprintf "%3.2f", $fps;
905 979
906 $want_refresh = 0;
907 $can_refresh = 0;
908
909 $CFClient::UI::ROOT->draw; 980 $CFClient::UI::ROOT->draw;
910
911 CFClient::SDL_GL_SwapBuffers; 981 CFClient::SDL_GL_SwapBuffers;
912 982
983 $WANT_REFRESH = 0;
984 $CAN_REFRESH = 0;
913 $LAST_REFRESH = $NOW; 985 $LAST_REFRESH = $NOW;
914} 986}
915 987
916my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { 988my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub {
917 $NOW = time; 989 $NOW = time;
919 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) 991 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
920 for CFClient::SDL_PollEvent; 992 for CFClient::SDL_PollEvent;
921 993
922 if (%animate_object) { 994 if (%animate_object) {
923 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 995 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
924 $want_refresh++; 996 $WANT_REFRESH++;
925 } 997 }
926 998
927 if ($want_refresh) { 999 if ($WANT_REFRESH) {
928 force_refresh; 1000 force_refresh;
929 } else { 1001 } else {
930 $can_refresh = 1; 1002 $CAN_REFRESH = 1;
931 } 1003 }
932}); 1004});
933
934sub refresh {
935 $want_refresh++;
936}
937 1005
938sub animation_start { 1006sub animation_start {
939 my ($widget) = @_; 1007 my ($widget) = @_;
940 $animate_object{$widget} = $widget; 1008 $animate_object{$widget} = $widget;
941} 1009}
1020# at worst. 1088# at worst.
1021sub conn::flood_fill { 1089sub conn::flood_fill {
1022 my ($self, $gx, $gy, $path, $hash, $flags) = @_; 1090 my ($self, $gx, $gy, $path, $hash, $flags) = @_;
1023 1091
1024 # the server does not allow map paths > 6 1092 # the server does not allow map paths > 6
1025 return if 6 <= length $path; 1093 return if 7 <= length $path;
1026 1094
1027 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}}; 1095 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}};
1028 1096
1029 for ( 1097 for (
1030 [1, 0, -1], 1098 [1, 0, -1],
1073 1141
1074 $self->flush_map; 1142 $self->flush_map;
1075 1143
1076 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 1144 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
1077 1145
1078 my $mapmapw = 250; 1146 my $mapmapw = $MAPMAP->{w};
1079 my $mapmaph = 250; 1147 my $mapmaph = $MAPMAP->{h};
1080 1148
1081 $self->{neigh_rect} = [ 1149 $self->{neigh_rect} = [
1082 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, 1150 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
1083 $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h, 1151 $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h,
1084 ]; 1152 ];
1253 [0.55, 0.41, 0.13], 1321 [0.55, 0.41, 0.13],
1254 [0.99, 0.77, 0.26], 1322 [0.99, 0.77, 0.26],
1255 [0.74, 0.65, 0.41], 1323 [0.74, 0.65, 0.41],
1256 ); 1324 );
1257 1325
1326 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
1327
1328 $text =~ s/&/&amp;/g; $text =~ s/</&lt;/g;
1329 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
1330 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
1331
1258 $LOGVIEW->add_paragraph ($color[$color], $text); 1332 $LOGVIEW->add_paragraph ($color[$color],
1333 join "\n", map "$time $_", split /\n/, $text);
1334
1335 $STATUS_LINE->add ($text,
1336 group => $text,
1337 color => $color[$color],
1338 timeout => 60,
1339 tooltip_font => $::FONT_FIXED,
1340 );
1341}
1342
1343sub conn::drawextinfo {
1344 my ($self, $color, $type, $subtype, $message) = @_;
1345
1346 $self->drawinfo ($color, $message);
1259} 1347}
1260 1348
1261sub conn::spell_add { 1349sub conn::spell_add {
1262 my ($self, $spell) = @_; 1350 my ($self, $spell) = @_;
1263 1351
1276 1364
1277 for my $skill (values %{$self->{skill_info}}) { 1365 for my $skill (values %{$self->{skill_info}}) {
1278 $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'"); 1366 $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'");
1279 $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'"); 1367 $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'");
1280 } 1368 }
1369
1370 $MAPWIDGET->add_command ("pet\\_mode defend", "Tell pets to stay close to you and defend you");
1371 $MAPWIDGET->add_command ("pet\\_mode arena", "Same as petmode attack, but also attack other players");
1372 $MAPWIDGET->add_command ("pet\\_mode sad", "Search &amp; Destroy - tell pets to roam about and attack enemies");
1373 $MAPWIDGET->add_command ("kill\\_pets", "kill your pets");
1374}
1375
1376sub conn::eof {
1377 stop_game;
1281} 1378}
1282 1379
1283sub update_floorbox { 1380sub update_floorbox {
1284 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { 1381 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub {
1382 return unless $CONN;
1383
1285 $FLOORBOX->clear; 1384 $FLOORBOX->clear;
1286 $FLOORBOX->add (new CFClient::UI::Empty expand => 1); 1385 $FLOORBOX->add (new CFClient::UI::Empty expand => 1);
1287 1386
1288 my @items = values %{ $CONN->{container}{0} }; 1387 my $count = 4;
1289 1388 for (@{ $CONN->{container}{0} }) {
1290 # we basically have to use the same sorting as everybody else 1389 if (--$count) {
1291 @items = sort { $a->{type} <=> $b->{type} } @items; 1390 $FLOORBOX->add (new CFClient::UI::InventoryItem item => $_);
1292 1391 } else {
1293 for my $item (reverse @items) { 1392 $FLOORBOX->add (new CFClient::UI::Label text => "More...");
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 }, 1393 last;
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 1394 }
1327 $hbox->add (new CFClient::UI::Label
1328 can_events => 0,
1329 text => $desc,
1330 );
1331 } 1395 }
1332 }); 1396 });
1333 refresh; 1397
1398 $WANT_REFRESH++;
1334} 1399}
1335 1400
1336sub conn::container_add { 1401sub conn::container_add {
1337 my ($self, $id, $items) = @_; 1402 my ($self, $tag, $items) = @_;
1338 1403
1339 update_floorbox if $id == 0; 1404 update_floorbox if $tag == 0;
1405
1406 $INV->set_items ($self->{container}{$self->{player}{tag}})
1407 if $tag == $self->{player}{tag};
1408
1340 # $self-<{player}{tag} => player inv 1409 # $self-<{player}{tag} => player inv
1341 #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; 1410 #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}};
1342} 1411}
1343 1412
1344sub conn::container_clear { 1413sub conn::container_clear {
1345 my ($self, $id) = @_; 1414 my ($self, $tag) = @_;
1346 1415
1347 update_floorbox if $id == 0; 1416 update_floorbox if $tag == 0;
1417
1418 $INV->set_items ($self->{container}{$tag})
1419 if $tag == $self->{player}{tag};
1420
1348# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; 1421# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0};
1349} 1422}
1350 1423
1351sub conn::item_delete { 1424sub conn::item_delete {
1352 my ($self, @items) = @_; 1425 my ($self, @items) = @_;
1353 1426
1354 for (@items) { 1427 for (@items) {
1355 update_floorbox if $_->{container} == 0; 1428 update_floorbox if $_->{container} == 0;
1429
1430 $INV->set_items ($self->{container}{$_->{container}})
1431 if $_->{container} == $self->{player}{tag};
1356 } 1432 }
1357} 1433}
1358 1434
1359sub conn::item_update { 1435sub conn::item_update {
1360 my ($self, $item) = @_; 1436 my ($self, $item) = @_;
1361 1437
1362 update_floorbox if $item->{container} == 0; 1438 update_floorbox if $item->{container} == 0;
1439
1440 $INV->set_items ($self->{container}{$item->{container}})
1441 if $item->{container} == $self->{player}{tag};
1363} 1442}
1364 1443
1365%SDL_CB = ( 1444%SDL_CB = (
1366 CFClient::SDL_QUIT => sub { 1445 CFClient::SDL_QUIT => sub {
1367 Event::unloop -1; 1446 Event::unloop -1;
1368 }, 1447 },
1369 CFClient::SDL_VIDEORESIZE => sub { 1448 CFClient::SDL_VIDEORESIZE => sub {
1370 }, 1449 },
1371 CFClient::SDL_VIDEOEXPOSE => \&refresh, 1450 CFClient::SDL_VIDEOEXPOSE => sub {
1451 $WANT_REFRESH++;
1452 },
1372 CFClient::SDL_ACTIVEEVENT => sub { 1453 CFClient::SDL_ACTIVEEVENT => sub {
1373# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# 1454# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
1374 }, 1455 },
1375 CFClient::SDL_KEYDOWN => sub { 1456 CFClient::SDL_KEYDOWN => sub {
1376 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { 1457 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
1380 video_init; 1461 video_init;
1381 } else { 1462 } else {
1382 CFClient::UI::feed_sdl_key_down_event ($_[0]); 1463 CFClient::UI::feed_sdl_key_down_event ($_[0]);
1383 } 1464 }
1384 }, 1465 },
1385 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, 1466 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
1386 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, 1467 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
1387 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, 1468 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
1388 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, 1469 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
1389 CFClient::SDL_USEREVENT => \&audio_music_finished, 1470 CFClient::SDL_USEREVENT => sub {
1471 if ($_[0]{code} == 1) {
1472 audio_channel_finished $_[0]{data1};
1473 } elsif ($_[0]{code} == 0) {
1474 audio_music_finished;
1475 }
1476 },
1390); 1477);
1391 1478
1392############################################################################# 1479#############################################################################
1393 1480
1394$SIG{INT} = $SIG{TERM} = sub { exit }; 1481$SIG{INT} = $SIG{TERM} = sub { exit };
1395 1482
1396$TILECACHE = CFClient::db_table "tilecache";
1397$FACEMAP = CFClient::db_table "facemap";
1398
1399CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1400
1401my %DEF_CFG = (
1402 sdl_mode => 0,
1403 width => 640,
1404 height => 480,
1405 fullscreen => 0,
1406 fast => 0,
1407 map_scale => 0.5,
1408 fow_enable => 1,
1409 fow_intensity => 0.45,
1410 fow_smooth => 0,
1411 gui_fontsize => 1,
1412 log_fontsize => 1,
1413 gauge_fontsize => 1,
1414 gauge_size => 0.35,
1415 stat_fontsize => 1,
1416 mapsize => 100,
1417 host => "crossfire.schmorp.de",
1418 say_command => 'say',
1419 audio_enable => 1,
1420 bgm_enable => 1,
1421 bgm_volume => 0.25,
1422);
1423
1424while (my ($k, $v) = each %DEF_CFG) {
1425 $CFG->{$k} = $v unless exists $CFG->{$k};
1426}
1427
1428sdl_init;
1429
1430@SDL_MODES = reverse
1431 grep $_->[0] >= 640 && $_->[1] >= 480,
1432 CFClient::SDL_ListModes;
1433
1434@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
1435
1436$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
1437
1438{ 1483{
1484 local $SIG{__DIE__} = sub { CFClient::fatal $_[0] };
1485
1486 CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1487
1488 $TILECACHE = CFClient::db_table "tilecache";
1489 $FACEMAP = CFClient::db_table "facemap";
1490
1491 my %DEF_CFG = (
1492 sdl_mode => 0,
1493 width => 640,
1494 height => 480,
1495 fullscreen => 0,
1496 fast => 0,
1497 map_scale => 0.5,
1498 fow_enable => 1,
1499 fow_intensity => 0.45,
1500 fow_smooth => 0,
1501 gui_fontsize => 1,
1502 log_fontsize => 1,
1503 gauge_fontsize=> 1,
1504 gauge_size => 0.35,
1505 stat_fontsize => 1,
1506 mapsize => 100,
1507 host => "crossfire.schmorp.de",
1508 say_command => 'say',
1509 audio_enable => 1,
1510 bgm_enable => 1,
1511 bgm_volume => 0.25,
1512 );
1513
1514 while (my ($k, $v) = each %DEF_CFG) {
1515 $CFG->{$k} = $v unless exists $CFG->{$k};
1516 }
1517
1518 sdl_init;
1519
1520 @SDL_MODES = reverse
1521 grep $_->[0] >= 640 && $_->[1] >= 480,
1522 CFClient::SDL_ListModes;
1523
1524 @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
1525
1526 $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
1527
1528 {
1439 my @fonts = map CFClient::find_rcfile "fonts/$_", qw( 1529 my @fonts = map CFClient::find_rcfile "fonts/$_", qw(
1440 DejaVuSans.ttf 1530 DejaVuSans.ttf
1441 DejaVuSansMono.ttf 1531 DejaVuSansMono.ttf
1442 DejaVuSans-Bold.ttf 1532 DejaVuSans-Bold.ttf
1443 DejaVuSansMono-Bold.ttf 1533 DejaVuSansMono-Bold.ttf
1444 DejaVuSans-Oblique.ttf 1534 DejaVuSans-Oblique.ttf
1445 DejaVuSansMono-Oblique.ttf 1535 DejaVuSansMono-Oblique.ttf
1446 DejaVuSans-BoldOblique.ttf 1536 DejaVuSans-BoldOblique.ttf
1447 DejaVuSansMono-BoldOblique.ttf 1537 DejaVuSansMono-BoldOblique.ttf
1448 ); 1538 );
1449 1539
1450 CFClient::add_font $_ for @fonts; 1540 CFClient::add_font $_ for @fonts;
1451 1541
1452 $FONT_PROP = new_from_file CFClient::Font $fonts[0]; 1542 $FONT_PROP = new_from_file CFClient::Font $fonts[0];
1453 $FONT_FIXED = new_from_file CFClient::Font $fonts[1]; 1543 $FONT_FIXED = new_from_file CFClient::Font $fonts[1];
1454 1544
1455 $FONT_PROP->make_default; 1545 $FONT_PROP->make_default;
1456} 1546 }
1457 1547
1458video_init; 1548 video_init;
1459audio_init; 1549 audio_init;
1550}
1460 1551
1461Event::loop; 1552Event::loop;
1462 1553
1463END { CFClient::SDL_Quit } 1554END { CFClient::SDL_Quit }
1464 1555
1556=head1 pclient - Crossfire+ and Crossfire game client
1465 1557
1558Pclient is a Crossfire+ and Crossfire game client.
1559
1560=head2 Features
1561
1562=over 4
1563
1564=item Fullscreen Map
1565
1566PClient can uses a fullscreen map, which greatly enhances how much of the
1567game world you can see.
1568
1569=item Persistent Map Cache (Crossfire+ only)
1570
1571PClient can persistently cache all map data it received from the
1572server. This not only allows it to display an overview map, but also
1573ensures that once-explored areas will be available the next time you want
1574to explore more.
1575
1576=item Hardware acceleration
1577
1578Unlike most Crossfire clients, PClient take advantage of OpenGL hardware
1579acceleration. Most modern graphics cards have difficulties with 2D
1580acceleration, while 3D graphics is accelerated well.
1581
1582=item No arbitrary limits
1583
1584Unlike other Crossfire clients, pclient does not suffer from arbitrary
1585limits (like a fixed amount of face numbers). There are still limits, but
1586they are not arbitrarily low :)
1587
1588=back
1589
1590=head1 USAGE
1591
1592=head2 The Map
1593
1594The map is always displayed in the background, behind all other windows and UI elements.
1595
1596#TODO# middle-click scrolls
1597#
1598# keys:
1599#
1600# a apply
1601# keypad moves, kp_5 applies ranged attack to self
1602
1603Starting to type enters the I<completion mode>. In that mode, you can type
1604abbreviations or commands and have them executed as soon as they match a
1605valid command. This is best explained by a few examples:
1606
1607Typing B<climb> will display a list of commands with I<climb> in their
1608name, such as I<ready_skill climbing> and I<use_skill climbing>.
1609
1610You can abbreviate commands by typing only the first character of every
1611word. For example, typing I<iwor> will likely select I<invoke word of
1612recall>, while I<ccfo> will select I<cast create food>. Likewise, I<rscli>
1613will likely select I<ready_skill climbing> and I<usl> will give you
1614I<use_skill levitation>.
1615
1616=head2 The map overview
1617
1618#TODO#
1619
1620=head2 The Status area in the lower right corner
1621
1622#TODO#
1623
1624=head2 The I<Statistics>/I>Stats> window
1625
1626#TODO#
1627
1628=head1 FAQ
1629
1630=over 4
1631
1632=item The client is very sluggish and slow, what can I do about this?
1633
1634Most likely, you don't have accelerated OpenGL support. Try to find a
1635newer driver, or a driver from your hardware vendor, that features OpenGL
1636support.
1637
1638If this is not an option, the following Setup options reduce the load and
1639will likely make the client playable with sofwtare rendering (it will
1640still be slow, though):
1641
1642=over 4
1643
1644=item B<Video Mode> should be set as low as possible (e.g. 640x480)
1645
1646=item Enable B<Fast & Ugly> mode
1647
1648=item Disable B<Fog of War>
1649
1650=item Increase B<Map Scale>
1651
1652=back
1653
1654=back
1655
1656=head1 AUTHOR
1657
1658Marc Lehmann <crossfire@schmorp.de>, Robin Redeker <elmex@ta-sa.org>
1659
1660
1661

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines