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.181 by root, Tue Apr 25 10:39:45 2006 UTC vs.
Revision 1.209 by root, Thu May 11 23:54:31 2006 UTC

37use CFClient; 37use CFClient;
38use CFClient::UI; 38use CFClient::UI;
39use CFClient::MapWidget; 39use CFClient::MapWidget;
40 40
41$Event::DIED = sub { 41$Event::DIED = sub {
42 # TODO: display dialog box or so
42 CFClient::error $_[1]; 43 CFClient::error $_[1];
43}; 44};
44 45
45#$SIG{__WARN__} = sub { Carp::cluck $_[0] };#d# 46#$SIG{__WARN__} = sub { Carp::cluck $_[0] };#d#
46 47
59our $NOW; 60our $NOW;
60 61
61our $CFG; 62our $CFG;
62our $CONN; 63our $CONN;
63our $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;
64 68
65our @SDL_MODES; 69our @SDL_MODES;
66our $WIDTH; 70our $WIDTH;
67our $HEIGHT; 71our $HEIGHT;
68our $FULLSCREEN; 72our $FULLSCREEN;
70 74
71our $FONT_PROP; 75our $FONT_PROP;
72our $FONT_FIXED; 76our $FONT_FIXED;
73 77
74our $MAP; 78our $MAP;
79our $MAPMAP;
75our $MAPWIDGET; 80our $MAPWIDGET;
76our $BUTTONBAR; 81our $BUTTONBAR;
77our $LOGVIEW; 82our $LOGVIEW;
78our $CONSOLE; 83our $CONSOLE;
79our $METASERVER; 84our $METASERVER;
85our $LOGIN_BUTTON;
80 86
81our $FLOORBOX; 87our $FLOORBOX;
82our $GAUGES; 88our $GAUGES;
83our $STATWIDS; 89our $STATWIDS;
84 90
91 97
92our $ALT_ENTER_MESSAGE; 98our $ALT_ENTER_MESSAGE;
93our $STATUS_LINE; 99our $STATUS_LINE;
94our $DEBUG_STATUS; 100our $DEBUG_STATUS;
95 101
102our $INVWIN;
103our $INV;
104
96sub status { 105sub status {
97 $STATUS_LINE->set_text ($_[0]); 106 $STATUS_LINE->add ($_[0], group => "status", timeout => 60);
98 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h}); 107 $CFClient::UI::ROOT->on_refresh ($STATUS_LINE => sub {
108 $STATUS_LINE->move (0, $HEIGHT - $STATUS_LINE->{h});#d# to in toplevel
109 });
99} 110}
100 111
101sub debug { 112sub debug {
102 $DEBUG_STATUS->set_text ($_[0]); 113 $DEBUG_STATUS->set_text ($_[0]);
103 $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);
104} 116}
105 117
106sub start_game { 118sub start_game {
107 status "logging in..."; 119 status "logging in...";
108 120
109 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;
110 122
111 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}"; 123 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}";
112
113 $MAP = new CFClient::Map $mapsize, $mapsize; 124 $MAP = new CFClient::Map $mapsize, $mapsize;
114 125
115 my ($host, $port) = split /:/, $CFG->{host}; 126 my ($host, $port) = split /:/, $CFG->{host};
116 127
117 $CONN = new conn 128 $CONN = eval {
129 new conn
118 host => $host, 130 host => $host,
119 port => $port || 13327, 131 port => $port || 13327,
120 user => $CFG->{user}, 132 user => $CFG->{user},
121 pass => $CFG->{password}, 133 pass => $CFG->{password},
122 mapw => $mapsize, 134 mapw => $mapsize,
123 maph => $mapsize, 135 maph => $mapsize,
136 ;
124 ; 137 };
125 138
139 if ($CONN) {
140 $LOGIN_BUTTON->set_text ("Logout");
141
126 status "login successful"; 142 status "login successful";
127 143
128 CFClient::lowdelay fileno $CONN->{fh}; 144 CFClient::lowdelay fileno $CONN->{fh};
145 } else {
146 status "unable to connect";
147 stop_game();
148 }
129} 149}
130 150
131sub 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;
132 undef $CONN; 160 undef $MAP;
133} 161}
134 162
135sub client_setup { 163sub client_setup {
136 my $dialog = new CFClient::UI::FancyFrame 164 my $dialog = new CFClient::UI::FancyFrame
137 title => "Client Setup", 165 title => "Client Setup",
313 audio_shutdown (); 341 audio_shutdown ();
314 audio_init (); 342 audio_init ();
315 } 343 }
316 ); 344 );
317 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
318 $dialog 358 $dialog
319} 359}
320 360
321sub set_stats_window_fontsize { 361sub set_stats_window_fontsize {
322 for (values %{$STATWIDS}) { 362 for (values %{$STATWIDS}) {
364 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."); 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.");
365 $hb->add (my $fg = new CFClient::UI::Gauge type => 'food', 405 $hb->add (my $fg = new CFClient::UI::Gauge type => 'food',
366 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."); 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.");
367 407
368 $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,
369 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 dieing. 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."); 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.");
370 $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,
371 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.)");
372 412
373 $GAUGES = { 413 $GAUGES = {
374 exp => $exp, win => $win, range => $rng, 414 exp => $exp, win => $win, range => $rng,
379 419
380 $win 420 $win
381} 421}
382 422
383sub make_stats_window { 423sub make_stats_window {
384 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";
385 425
386 $tgw->add (my $vb = new CFClient::UI::VBox); 426 $tgw->add (new CFClient::UI::Window child => my $vb = new CFClient::UI::VBox);
387 $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);
388 $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);
389 429
390 $vb->add (my $hb = new CFClient::UI::HBox expand => 1); 430 $vb->add (my $hb = new CFClient::UI::HBox expand => 1);
391 431
410 [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."], 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."],
411 ) { 451 ) {
412 my ($col, $row, $id, $label, $template, $tooltip) = @$_; 452 my ($col, $row, $id, $label, $template, $tooltip) = @$_;
413 453
414 $tbl->add ($col , $row, $STATWIDS->{$id} = new CFClient::UI::Label 454 $tbl->add ($col , $row, $STATWIDS->{$id} = new CFClient::UI::Label
415 can_hover => 1, can_events => 1, valign => 0, align => +1, template => $template, tooltip => $tooltip); 455 font => $FONT_FIXED, can_hover => 1, can_events => 1, valign => 0, align => +1, template => $template, tooltip => $tooltip);
416 $tbl->add ($col + 1, $row, $STATWIDS->{"$id\_lbl"} = new CFClient::UI::Label 456 $tbl->add ($col + 1, $row, $STATWIDS->{"$id\_lbl"} = new CFClient::UI::Label
417 can_hover => 1, can_events => 1, fg => $black, valign => 0, align => -1, text => $label, tooltip => $tooltip); 457 font => $FONT_FIXED, can_hover => 1, can_events => 1, fg => $black, valign => 0, align => -1, text => $label, tooltip => $tooltip);
418 } 458 }
419 459
420 $hb->add (my $tbl2 = new CFClient::UI::Table expand => 1); 460 $hb->add (my $tbl2 = new CFClient::UI::Table expand => 1);
421 461
422 my $row = 0; 462 my $row = 0;
423 my $col = 0; 463 my $col = 0;
424 464
425 my %resist_names = ( 465 my %resist_names = (
426 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.)",
427 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.)",
428 conf => "Confusion", 468 conf => "Confusion (If you are hit by confusion you will move into random directions, and likely into monsters.)",
429 fire => "Fire", 469 fire => "Fire (just your resistance to fire spells like burning hands, dragonbreath, meteor swarm fire, ...)",
430 depl => "Depletion (some monsters and other effects can cause stats depletion)", 470 depl => "Depletion (some monsters and other effects can cause stats depletion)",
431 magic => "Magic", 471 magic => "Magic (resistance to magic spells like magic missile or similar)",
432 drain => "Draining (some monsters (e.g. vampires) and other effects can steal experience)", 472 drain => "Draining (some monsters (e.g. vampires) and other effects can steal experience)",
433 acid => "Acid", 473 acid => "Acid (resistance to acid, acid hurts pretty much and also corrodes your weapons)",
434 pois => "Poison", 474 pois => "Poison (resistance to getting poisoned)",
435 para => "Paralysation", 475 para => "Paralysation (this resistance affects the chance you get paralysed)",
436 deat => "Death (resistance against death spells)", 476 deat => "Death (resistance against death spells)",
437 phys => "Physical", 477 phys => "Physical (this is the resistance against physical attacks, like when a monster hit you in melee combat)",
438 blind => "Blind", 478 blind => "Blind (blind resistance affects the chance of a successful blinding attack)",
439 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)",
440 tund => "Turn undead", 480 tund => "Turn undead",
441 elec => "Electricity", 481 elec => "Electricity (resistance againt electricity, spells like large lightning, small lightning, ...)",
442 cold => "Cold", 482 cold => "Cold (this is your resistance against cold spells like icestorm, snowstorm, ...)",
443 ghit => "Ghost hit (special attack used by ghosts and ghost-like beings)", 483 ghit => "Ghost hit (special attack used by ghosts and ghost-like beings)",
444 ); 484 );
445 for (qw/slow holyw conf fire depl magic 485 for (qw/slow holyw conf fire depl magic
446 drain acid pois para deat phys 486 drain acid pois para deat phys
447 blind fear tund elec cold ghit/) 487 blind fear tund elec cold ghit/)
448 { 488 {
449 $tbl2->add ($col, $row, 489 $tbl2->add ($col, $row,
450 $STATWIDS->{"res_$_"} = 490 $STATWIDS->{"res_$_"} =
451 new CFClient::UI::Label 491 new CFClient::UI::Label
492 font => $FONT_FIXED,
452 template => "-100%", 493 template => "-100%",
453 align => +1, 494 align => +1,
454 valign => 0, 495 valign => 0,
455 can_events => 1, 496 can_events => 1,
456 can_hover => 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 );
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
659 701
660 $METASERVER = metaserver_dialog; 702 $METASERVER = metaserver_dialog;
661 703
662 $vbox->add (new CFClient::UI::Flopper 704 $vbox->add (new CFClient::UI::Flopper
663 expand => 1, 705 expand => 1,
664 text => "Metaserver", 706 text => "Server List",
665 other => $METASERVER, 707 other => $METASERVER,
666 tooltip => "Show a list of avaible crossfire servers", 708 tooltip => "Show a list of available crossfire servers",
667 connect_open => sub { 709 connect_open => sub {
668 update_metaserver $HOST; 710 update_metaserver $HOST;
669 } 711 }
670 ); 712 );
671 } 713 }
686 hidden => 1, 728 hidden => 1,
687 tooltip => "The password for your character", 729 tooltip => "The password for your character",
688 connect_changed => sub { 730 connect_changed => sub {
689 my ($self, $value) = @_; 731 my ($self, $value) = @_;
690 $CFG->{password} = $value; 732 $CFG->{password} = $value;
691 }
692 );
693
694 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd");
695 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry
696 text => $CFG->{say_command},
697 tooltip => "This is the command that will be used if you write a line in the message window entry. "
698 ."Usually you want to enter something like 'say' or 'shout' or 'gsay' here. "
699 ."But you could also set it to 'tell <playername>' to only chat with that user.",
700 connect_changed => sub {
701 my ($self, $value) = @_;
702 $CFG->{say_command} = $value;
703 } 733 }
704 ); 734 );
705 735
706 $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");
707 $table->add (1, 7, new CFClient::UI::Slider 737 $table->add (1, 7, new CFClient::UI::Slider
714 744
715 $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 745 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
716 }, 746 },
717 ); 747 );
718 748
719 $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
720 start_game; 755 : start_game;
756 },
721 }); 757 );
722 758
723 $dialog 759 $dialog
724} 760}
725 761
726sub message_window { 762sub message_window {
727 my $window = new CFClient::UI::FancyFrame 763 my $window = new CFClient::UI::FancyFrame
728 title => "Messages", 764 title => "Messages",
729 border_bg => [1, 1, 1, 0.5], 765 border_bg => [1, 1, 1, 1],
730 bg => [0.3, 0.3, 0.3, 0.8], 766 bg => [0, 0, 0, 0.5],
731 user_w => int $::WIDTH / 3, 767 user_w => int $::WIDTH / 3,
732 user_h => int $::HEIGHT / 5, 768 user_h => int $::HEIGHT / 5,
733 child => (my $vbox = new CFClient::UI::VBox); 769 child => (my $vbox = new CFClient::UI::VBox);
734 770
735 $vbox->add ($LOGVIEW = new CFClient::UI::TextView 771 $vbox->add ($LOGVIEW = new CFClient::UI::TextView
775 }; 811 };
776 812
777 $window 813 $window
778} 814}
779 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
780sub sdl_init { 822sub sdl_init {
781 CFClient::SDL_Init 823 CFClient::SDL_Init
782 and die "SDL::Init failed!\n"; 824 and die "SDL::Init failed!\n";
783} 825}
784 826
785sub video_init { 827sub video_init {
786 sdl_init; 828 sdl_init;
787 829
830 $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} >= @SDL_MODES;
831
788 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 832 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
789 $FULLSCREEN = $CFG->{fullscreen}; 833 $FULLSCREEN = $CFG->{fullscreen};
790 $FAST = $CFG->{fast}; 834 $FAST = $CFG->{fast};
791 835
792 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN 836 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
793 or die "SDL_SetVideoMode failed!\n"; 837 or die "SDL_SetVideoMode failed!\n";
794 838
795 $SDL_ACTIVE = 1; 839 $SDL_ACTIVE = 1;
796
797 $LAST_REFRESH = time - 0.01; 840 $LAST_REFRESH = time - 0.01;
798 841
799 CFClient::gl_init; 842 CFClient::gl_init;
800 843
801 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; 844 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
802 845
846 $CFClient::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d#
847
803 ############################################################################# 848 #############################################################################
804 849
850 if ($DEBUG_STATUS) {
851 # reconfigure all widgets
852 $CFClient::UI::ROOT->reconfigure;
853
854 } else {
855 # create the widgets
856
805 $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#
806 $DEBUG_STATUS->show; 858 $DEBUG_STATUS->show;
807 859
808 $STATUS_LINE = new CFClient::UI::Label 860 $STATUS_LINE = new CFClient::UI::Statusbox;
809 padding => 0, 861 $STATUS_LINE->add ("Use <b>Alt-Enter</b> to toggle fullscreen mode", pri => 0, size => 0.8, color => [1, 1, 1]);
810 y => $HEIGHT - $FONTSIZE * 1.8;
811 $STATUS_LINE->show; 862 $STATUS_LINE->show;
812 863
813 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 864 CFClient::UI::FancyFrame->new (
814 padding => 0, 865 border_bg => [1, 1, 1, 192/255],
815 fontsize => 0.8, 866 bg => [1, 1, 1, 0],
816 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 867 child => ($MAPMAP = new CFClient::MapWidget::MapMap),
817 $ALT_ENTER_MESSAGE->show; 868 )->show;
818 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
819 869
820 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget); 870 $MAPWIDGET = new CFClient::MapWidget;
821 $MAPWIDGET->focus_in;
822 $MAPWIDGET->connect (activate_console => sub { 871 $MAPWIDGET->connect (activate_console => sub {
823 my ($mapwidget, $preset) = @_; 872 my ($mapwidget, $preset) = @_;
824 873
825 if ($CONSOLE) { 874 if ($CONSOLE) {
826 $CONSOLE->{input}->{auto_activated} = 1; 875 $CONSOLE->{input}->{auto_activated} = 1;
827 $CONSOLE->{input}->focus_in; 876 $CONSOLE->{input}->focus_in;
828 877
829 if ($preset && $CONSOLE->{input}->get_text eq '') { 878 if ($preset && $CONSOLE->{input}->get_text eq '') {
830 $CONSOLE->{input}->set_text ($preset); 879 $CONSOLE->{input}->set_text ($preset);
880 }
831 } 881 }
832 } 882 });
833 }); 883 $MAPWIDGET->show;
884 $MAPWIDGET->focus_in;
834 885
835 $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox); 886 $BUTTONBAR = new CFClient::UI::HBox;
836 887
837 $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);
838 $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);
839 $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);
840 891
841 $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
842 $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);
843 896
844 $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 {
845 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 898 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
846 status "Configuration Saved"; 899 status "Configuration Saved";
847 }); 900 });
848 901
902 $BUTTONBAR->show;
903
904 # delay till geometry is constant
905 $CFClient::UI::ROOT->on_refresh (startup => sub {
849 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 906 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
907 });
908 force_refresh ();
909 }
850} 910}
851 911
852sub video_shutdown { 912sub video_shutdown {
853 $CFClient::UI::ROOT->{children} = [];
854 undef $CFClient::UI::GRAB;
855 undef $CFClient::UI::HOVER;
856 undef $SDL_ACTIVE; 913 undef $SDL_ACTIVE;
857} 914}
858 915
859my @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#
860my $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}
861 924
862sub audio_music_finished { 925sub audio_music_finished {
863 return unless $CFG->{bgm_enable}; 926 return unless $CFG->{bgm_enable};
864 927
865 # TODO: hack, do play loop and mood music 928 # TODO: hack, do play loop and mood music
869 push @bgmusic, shift @bgmusic; 932 push @bgmusic, shift @bgmusic;
870} 933}
871 934
872sub audio_init { 935sub audio_init {
873 if ($CFG->{audio_enable}) { 936 if ($CFG->{audio_enable}) {
874 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { 937 if (open my $fh, "<", CFClient::find_rcfile "sounds/config") {
875 $SDL_MIXER = !CFClient::Mix_OpenAudio; 938 $SDL_MIXER = !CFClient::Mix_OpenAudio;
876 CFClient::Mix_AllocateChannels 8; 939 CFClient::Mix_AllocateChannels 8;
877 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; 940 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
878 941
879 audio_music_finished; 942 audio_music_finished;
906} 969}
907 970
908my %animate_object; 971my %animate_object;
909my $animate_timer; 972my $animate_timer;
910 973
911my $want_refresh;
912my $can_refresh;
913
914my $fps = 9; 974my $fps = 9;
915 975
916sub force_refresh { 976sub force_refresh {
917 $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05; 977 $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05;
918 debug sprintf "%3.2f", $fps; 978 debug sprintf "%3.2f", $fps;
919 979
920 $want_refresh = 0;
921 $can_refresh = 0;
922
923 $CFClient::UI::ROOT->draw; 980 $CFClient::UI::ROOT->draw;
924
925 CFClient::SDL_GL_SwapBuffers; 981 CFClient::SDL_GL_SwapBuffers;
926 982
983 $WANT_REFRESH = 0;
984 $CAN_REFRESH = 0;
927 $LAST_REFRESH = $NOW; 985 $LAST_REFRESH = $NOW;
928} 986}
929 987
930my $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 {
931 $NOW = time; 989 $NOW = time;
933 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) 991 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
934 for CFClient::SDL_PollEvent; 992 for CFClient::SDL_PollEvent;
935 993
936 if (%animate_object) { 994 if (%animate_object) {
937 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 995 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
938 $want_refresh++; 996 $WANT_REFRESH++;
939 } 997 }
940 998
941 if ($want_refresh) { 999 if ($WANT_REFRESH) {
942 force_refresh; 1000 force_refresh;
943 } else { 1001 } else {
944 $can_refresh = 1; 1002 $CAN_REFRESH = 1;
945 } 1003 }
946}); 1004});
947
948sub refresh {
949 $want_refresh++;
950}
951 1005
952sub animation_start { 1006sub animation_start {
953 my ($widget) = @_; 1007 my ($widget) = @_;
954 $animate_object{$widget} = $widget; 1008 $animate_object{$widget} = $widget;
955} 1009}
1034# at worst. 1088# at worst.
1035sub conn::flood_fill { 1089sub conn::flood_fill {
1036 my ($self, $gx, $gy, $path, $hash, $flags) = @_; 1090 my ($self, $gx, $gy, $path, $hash, $flags) = @_;
1037 1091
1038 # the server does not allow map paths > 6 1092 # the server does not allow map paths > 6
1039 return if 6 <= length $path; 1093 return if 7 <= length $path;
1040 1094
1041 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}}; 1095 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}};
1042 1096
1043 for ( 1097 for (
1044 [1, 0, -1], 1098 [1, 0, -1],
1087 1141
1088 $self->flush_map; 1142 $self->flush_map;
1089 1143
1090 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 1144 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
1091 1145
1092 my $mapmapw = 250; 1146 my $mapmapw = $MAPMAP->{w};
1093 my $mapmaph = 250; 1147 my $mapmaph = $MAPMAP->{h};
1094 1148
1095 $self->{neigh_rect} = [ 1149 $self->{neigh_rect} = [
1096 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, 1150 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
1097 $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h, 1151 $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h,
1098 ]; 1152 ];
1267 [0.55, 0.41, 0.13], 1321 [0.55, 0.41, 0.13],
1268 [0.99, 0.77, 0.26], 1322 [0.99, 0.77, 0.26],
1269 [0.74, 0.65, 0.41], 1323 [0.74, 0.65, 0.41],
1270 ); 1324 );
1271 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
1272 $LOGVIEW->add_paragraph ($color[$color], $text); 1332 $LOGVIEW->add_paragraph ($color[$color],
1333 join "\n", map "$time $_", split /\n/, $text);
1334 $STATUS_LINE->add ($text, color => $color[$color], timeout => 60);
1335}
1336
1337sub conn::drawextinfo {
1338 my ($self, $color, $type, $subtype, $message) = @_;
1339
1340 $self->drawinfo ($color, $message);
1273} 1341}
1274 1342
1275sub conn::spell_add { 1343sub conn::spell_add {
1276 my ($self, $spell) = @_; 1344 my ($self, $spell) = @_;
1277 1345
1290 1358
1291 for my $skill (values %{$self->{skill_info}}) { 1359 for my $skill (values %{$self->{skill_info}}) {
1292 $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'"); 1360 $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'");
1293 $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'"); 1361 $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'");
1294 } 1362 }
1363
1364 $MAPWIDGET->add_command ("pet\\_mode defend", "Tell pets to stay close to you and defend you");
1365 $MAPWIDGET->add_command ("pet\\_mode arena", "Same as petmode attack, but also attack other players");
1366 $MAPWIDGET->add_command ("pet\\_mode sad", "Search &amp; Destroy - tell pets to roam about and attack enemies");
1367 $MAPWIDGET->add_command ("kill\\_pets", "kill your pets");
1368}
1369
1370sub conn::eof {
1371 stop_game;
1295} 1372}
1296 1373
1297sub update_floorbox { 1374sub update_floorbox {
1298 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { 1375 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub {
1376 return unless $CONN;
1377
1299 $FLOORBOX->clear; 1378 $FLOORBOX->clear;
1300 $FLOORBOX->add (new CFClient::UI::Empty expand => 1); 1379 $FLOORBOX->add (new CFClient::UI::Empty expand => 1);
1301 1380
1302 my @items = values %{ $CONN->{container}{0} }; 1381 my $count = 4;
1303 1382 for (@{ $CONN->{container}{0} }) {
1304 # we basically have to use the same sorting as everybody else 1383 if (--$count) {
1305 @items = sort { $a->{type} <=> $b->{type} } @items; 1384 $FLOORBOX->add (new CFClient::UI::InventoryItem item => $_);
1306 1385 } else {
1307 for my $item (reverse @items) { 1386 $FLOORBOX->add (new CFClient::UI::Label text => "More...");
1308 my $desc = $item->{nrof} < 2
1309 ? $item->{name}
1310 : "$item->{nrof} $item->{name_pl}";
1311 # todo: animation widget, face widget, weight(?) etc.
1312 $FLOORBOX->add (my $hbox = new CFClient::UI::HBox
1313 tooltip => (CFClient::UI::Label->escape ($desc)
1314 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"),
1315 can_hover => 1,
1316 can_events => 1,
1317 connect_button_down => sub {
1318 my ($self, $ev, $x, $y) = @_;
1319
1320 # todo: maybe put examine on 1? but should just be a tooltip :(
1321 if ($ev->{button} == 1) {
1322 $CONN->send ("move $CONN->{player}{tag} $item->{tag} 0");
1323 } elsif ($ev->{button} == 2) {
1324 $CONN->send ("apply $item->{tag}");
1325 } elsif ($ev->{button} == 3) {
1326 # examine, lock, mark, maybe other things
1327 warn "MENU not implemented yet\n";
1328 }
1329
1330 1
1331 }, 1387 last;
1332 );
1333
1334 $hbox->add (new CFClient::UI::Face
1335 can_events => 0,
1336 face => $item->{face},
1337 anim => $item->{anim},
1338 animspeed => $item->{animspeed},
1339 );
1340 1388 }
1341 $hbox->add (new CFClient::UI::Label
1342 can_events => 0,
1343 text => $desc,
1344 );
1345 } 1389 }
1346 }); 1390 });
1347 refresh; 1391
1392 $WANT_REFRESH++;
1348} 1393}
1349 1394
1350sub conn::container_add { 1395sub conn::container_add {
1351 my ($self, $id, $items) = @_; 1396 my ($self, $tag, $items) = @_;
1352 1397
1353 update_floorbox if $id == 0; 1398 update_floorbox if $tag == 0;
1399
1400 $INV->set_items ($self->{container}{$self->{player}{tag}})
1401 if $tag == $self->{player}{tag};
1402
1354 # $self-<{player}{tag} => player inv 1403 # $self-<{player}{tag} => player inv
1355 #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; 1404 #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}};
1356} 1405}
1357 1406
1358sub conn::container_clear { 1407sub conn::container_clear {
1359 my ($self, $id) = @_; 1408 my ($self, $tag) = @_;
1360 1409
1361 update_floorbox if $id == 0; 1410 update_floorbox if $tag == 0;
1411
1412 $INV->set_items ($self->{container}{$tag})
1413 if $tag == $self->{player}{tag};
1414
1362# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; 1415# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0};
1363} 1416}
1364 1417
1365sub conn::item_delete { 1418sub conn::item_delete {
1366 my ($self, @items) = @_; 1419 my ($self, @items) = @_;
1367 1420
1368 for (@items) { 1421 for (@items) {
1369 update_floorbox if $_->{container} == 0; 1422 update_floorbox if $_->{container} == 0;
1423
1424 $INV->set_items ($self->{container}{$_->{container}})
1425 if $_->{container} == $self->{player}{tag};
1370 } 1426 }
1371} 1427}
1372 1428
1373sub conn::item_update { 1429sub conn::item_update {
1374 my ($self, $item) = @_; 1430 my ($self, $item) = @_;
1375 1431
1376 update_floorbox if $item->{container} == 0; 1432 update_floorbox if $item->{container} == 0;
1433
1434 $INV->set_items ($self->{container}{$item->{container}})
1435 if $item->{container} == $self->{player}{tag};
1377} 1436}
1378 1437
1379%SDL_CB = ( 1438%SDL_CB = (
1380 CFClient::SDL_QUIT => sub { 1439 CFClient::SDL_QUIT => sub {
1381 Event::unloop -1; 1440 Event::unloop -1;
1382 }, 1441 },
1383 CFClient::SDL_VIDEORESIZE => sub { 1442 CFClient::SDL_VIDEORESIZE => sub {
1384 }, 1443 },
1385 CFClient::SDL_VIDEOEXPOSE => \&refresh, 1444 CFClient::SDL_VIDEOEXPOSE => sub {
1445 $WANT_REFRESH++;
1446 },
1386 CFClient::SDL_ACTIVEEVENT => sub { 1447 CFClient::SDL_ACTIVEEVENT => sub {
1387# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# 1448# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
1388 }, 1449 },
1389 CFClient::SDL_KEYDOWN => sub { 1450 CFClient::SDL_KEYDOWN => sub {
1390 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { 1451 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
1394 video_init; 1455 video_init;
1395 } else { 1456 } else {
1396 CFClient::UI::feed_sdl_key_down_event ($_[0]); 1457 CFClient::UI::feed_sdl_key_down_event ($_[0]);
1397 } 1458 }
1398 }, 1459 },
1399 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, 1460 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
1400 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, 1461 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
1401 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, 1462 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
1402 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, 1463 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
1403 CFClient::SDL_USEREVENT => \&audio_music_finished, 1464 CFClient::SDL_USEREVENT => sub {
1465 if ($_[0]{code} == 1) {
1466 audio_channel_finished $_[0]{data1};
1467 } elsif ($_[0]{code} == 0) {
1468 audio_music_finished;
1469 }
1470 },
1404); 1471);
1405 1472
1406############################################################################# 1473#############################################################################
1407 1474
1408$SIG{INT} = $SIG{TERM} = sub { exit }; 1475$SIG{INT} = $SIG{TERM} = sub { exit };
1409 1476
1410$TILECACHE = CFClient::db_table "tilecache";
1411$FACEMAP = CFClient::db_table "facemap";
1412
1413CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1414
1415my %DEF_CFG = (
1416 sdl_mode => 0,
1417 width => 640,
1418 height => 480,
1419 fullscreen => 0,
1420 fast => 0,
1421 map_scale => 0.5,
1422 fow_enable => 1,
1423 fow_intensity => 0.45,
1424 fow_smooth => 0,
1425 gui_fontsize => 1,
1426 log_fontsize => 1,
1427 gauge_fontsize => 1,
1428 gauge_size => 0.35,
1429 stat_fontsize => 1,
1430 mapsize => 100,
1431 host => "crossfire.schmorp.de",
1432 say_command => 'say',
1433 audio_enable => 1,
1434 bgm_enable => 1,
1435 bgm_volume => 0.25,
1436);
1437
1438while (my ($k, $v) = each %DEF_CFG) {
1439 $CFG->{$k} = $v unless exists $CFG->{$k};
1440}
1441
1442sdl_init;
1443
1444@SDL_MODES = reverse
1445 grep $_->[0] >= 640 && $_->[1] >= 480,
1446 CFClient::SDL_ListModes;
1447
1448@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
1449
1450$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
1451
1452{ 1477{
1478 local $SIG{__DIE__} = sub { CFClient::fatal $_[0] };
1479
1480 CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1481
1482 $TILECACHE = CFClient::db_table "tilecache";
1483 $FACEMAP = CFClient::db_table "facemap";
1484
1485 my %DEF_CFG = (
1486 sdl_mode => 0,
1487 width => 640,
1488 height => 480,
1489 fullscreen => 0,
1490 fast => 0,
1491 map_scale => 0.5,
1492 fow_enable => 1,
1493 fow_intensity => 0.45,
1494 fow_smooth => 0,
1495 gui_fontsize => 1,
1496 log_fontsize => 1,
1497 gauge_fontsize=> 1,
1498 gauge_size => 0.35,
1499 stat_fontsize => 1,
1500 mapsize => 100,
1501 host => "crossfire.schmorp.de",
1502 say_command => 'say',
1503 audio_enable => 1,
1504 bgm_enable => 1,
1505 bgm_volume => 0.25,
1506 );
1507
1508 while (my ($k, $v) = each %DEF_CFG) {
1509 $CFG->{$k} = $v unless exists $CFG->{$k};
1510 }
1511
1512 sdl_init;
1513
1514 @SDL_MODES = reverse
1515 grep $_->[0] >= 640 && $_->[1] >= 480,
1516 CFClient::SDL_ListModes;
1517
1518 @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
1519
1520 $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
1521
1522 {
1453 my @fonts = map CFClient::find_rcfile "fonts/$_", qw( 1523 my @fonts = map CFClient::find_rcfile "fonts/$_", qw(
1454 DejaVuSans.ttf 1524 DejaVuSans.ttf
1455 DejaVuSansMono.ttf 1525 DejaVuSansMono.ttf
1456 DejaVuSans-Bold.ttf 1526 DejaVuSans-Bold.ttf
1457 DejaVuSansMono-Bold.ttf 1527 DejaVuSansMono-Bold.ttf
1458 DejaVuSans-Oblique.ttf 1528 DejaVuSans-Oblique.ttf
1459 DejaVuSansMono-Oblique.ttf 1529 DejaVuSansMono-Oblique.ttf
1460 DejaVuSans-BoldOblique.ttf 1530 DejaVuSans-BoldOblique.ttf
1461 DejaVuSansMono-BoldOblique.ttf 1531 DejaVuSansMono-BoldOblique.ttf
1462 ); 1532 );
1463 1533
1464 CFClient::add_font $_ for @fonts; 1534 CFClient::add_font $_ for @fonts;
1465 1535
1466 $FONT_PROP = new_from_file CFClient::Font $fonts[0]; 1536 $FONT_PROP = new_from_file CFClient::Font $fonts[0];
1467 $FONT_FIXED = new_from_file CFClient::Font $fonts[1]; 1537 $FONT_FIXED = new_from_file CFClient::Font $fonts[1];
1468 1538
1469 $FONT_PROP->make_default; 1539 $FONT_PROP->make_default;
1470} 1540 }
1471 1541
1472video_init; 1542 video_init;
1473audio_init; 1543 audio_init;
1544}
1474 1545
1475Event::loop; 1546Event::loop;
1476 1547
1477END { CFClient::SDL_Quit } 1548END { CFClient::SDL_Quit }
1478 1549

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines