… | |
… | |
70 | |
70 | |
71 | our $FONT_PROP; |
71 | our $FONT_PROP; |
72 | our $FONT_FIXED; |
72 | our $FONT_FIXED; |
73 | |
73 | |
74 | our $MAP; |
74 | our $MAP; |
|
|
75 | our $MAPMAP; |
75 | our $MAPWIDGET; |
76 | our $MAPWIDGET; |
76 | our $BUTTONBAR; |
77 | our $BUTTONBAR; |
77 | our $LOGVIEW; |
78 | our $LOGVIEW; |
78 | our $CONSOLE; |
79 | our $CONSOLE; |
79 | our $METASERVER; |
80 | our $METASERVER; |
|
|
81 | our $LOGIN_BUTTON; |
80 | |
82 | |
81 | our $FLOORBOX; |
83 | our $FLOORBOX; |
82 | our $GAUGES; |
84 | our $GAUGES; |
83 | our $STATWIDS; |
85 | our $STATWIDS; |
84 | |
86 | |
… | |
… | |
91 | |
93 | |
92 | our $ALT_ENTER_MESSAGE; |
94 | our $ALT_ENTER_MESSAGE; |
93 | our $STATUS_LINE; |
95 | our $STATUS_LINE; |
94 | our $DEBUG_STATUS; |
96 | our $DEBUG_STATUS; |
95 | |
97 | |
|
|
98 | our $INVWIN; |
|
|
99 | our $INV; |
|
|
100 | |
96 | sub status { |
101 | sub status { |
97 | $STATUS_LINE->set_text ($_[0]); |
102 | $STATUS_LINE->set_text ($_[0]); |
98 | $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}); |
99 | } |
104 | } |
100 | |
105 | |
… | |
… | |
107 | status "logging in..."; |
112 | status "logging in..."; |
108 | |
113 | |
109 | my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
114 | my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
110 | |
115 | |
111 | $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}"; |
116 | $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}"; |
112 | |
|
|
113 | $MAP = new CFClient::Map $mapsize, $mapsize; |
117 | $MAP = new CFClient::Map $mapsize, $mapsize; |
114 | |
118 | |
115 | my ($host, $port) = split /:/, $CFG->{host}; |
119 | my ($host, $port) = split /:/, $CFG->{host}; |
116 | |
120 | |
117 | $CONN = new conn |
121 | $CONN = eval { |
|
|
122 | new conn |
118 | host => $host, |
123 | host => $host, |
119 | port => $port || 13327, |
124 | port => $port || 13327, |
120 | user => $CFG->{user}, |
125 | user => $CFG->{user}, |
121 | pass => $CFG->{password}, |
126 | pass => $CFG->{password}, |
122 | mapw => $mapsize, |
127 | mapw => $mapsize, |
123 | maph => $mapsize, |
128 | maph => $mapsize, |
|
|
129 | ; |
124 | ; |
130 | }; |
125 | |
131 | |
|
|
132 | if ($CONN) { |
|
|
133 | $LOGIN_BUTTON->set_text ("Logout"); |
|
|
134 | |
126 | status "login successful"; |
135 | status "login successful"; |
127 | |
136 | |
128 | CFClient::lowdelay fileno $CONN->{fh}; |
137 | CFClient::lowdelay fileno $CONN->{fh}; |
|
|
138 | } else { |
|
|
139 | status "unable to connect"; |
|
|
140 | stop_game(); |
|
|
141 | } |
129 | } |
142 | } |
130 | |
143 | |
131 | sub stop_game { |
144 | sub stop_game { |
|
|
145 | return unless $CONN; |
|
|
146 | |
|
|
147 | status "connection closed"; |
|
|
148 | $LOGIN_BUTTON->set_text ("Login"); |
|
|
149 | $CONN->destroy; |
|
|
150 | $CONN = 0; # false, does not autovivify |
|
|
151 | |
|
|
152 | undef $MAPCACHE; |
132 | undef $CONN; |
153 | undef $MAP; |
133 | } |
154 | } |
134 | |
155 | |
135 | sub client_setup { |
156 | sub client_setup { |
136 | my $dialog = new CFClient::UI::FancyFrame |
157 | my $dialog = new CFClient::UI::FancyFrame |
137 | title => "Client Setup", |
158 | title => "Client Setup", |
… | |
… | |
313 | audio_shutdown (); |
334 | audio_shutdown (); |
314 | audio_init (); |
335 | audio_init (); |
315 | } |
336 | } |
316 | ); |
337 | ); |
317 | |
338 | |
|
|
339 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Communication cmd"); |
|
|
340 | $table->add (1, $row++, my $saycmd = new CFClient::UI::Entry |
|
|
341 | text => $CFG->{say_command}, |
|
|
342 | tooltip => "This is the command that will be used if you write a line in the message window entry. " |
|
|
343 | ."Usually you want to enter something like 'say' or 'shout' or 'gsay' here. " |
|
|
344 | ."But you could also set it to 'tell <playername>' to only chat with that user.", |
|
|
345 | connect_changed => sub { |
|
|
346 | my ($self, $value) = @_; |
|
|
347 | $CFG->{say_command} = $value; |
|
|
348 | } |
|
|
349 | ); |
|
|
350 | |
318 | $dialog |
351 | $dialog |
319 | } |
352 | } |
320 | |
353 | |
321 | sub set_stats_window_fontsize { |
354 | sub set_stats_window_fontsize { |
322 | for (values %{$STATWIDS}) { |
355 | for (values %{$STATWIDS}) { |
… | |
… | |
355 | (my $hb = new CFClient::UI::HBox), |
388 | (my $hb = new CFClient::UI::HBox), |
356 | ], |
389 | ], |
357 | ); |
390 | ); |
358 | |
391 | |
359 | $hb->add (my $hg = new CFClient::UI::Gauge type => 'hp', |
392 | $hb->add (my $hg = new CFClient::UI::Gauge type => 'hp', |
360 | tooltip => "Health points - depletes when you get wounded, refills when you heal or idle"); |
393 | 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."); |
361 | $hb->add (my $mg = new CFClient::UI::Gauge type => 'mana', |
394 | $hb->add (my $mg = new CFClient::UI::Gauge type => 'mana', |
362 | tooltip => "Spell points - deplete when you cast wizard spells, refills when you idle"); |
395 | 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."); |
363 | $hb->add (my $gg = new CFClient::UI::Gauge type => 'grace', |
396 | $hb->add (my $gg = new CFClient::UI::Gauge type => 'grace', |
364 | tooltip => "Grace points - deplete when you cast priest spells, refills when you pray"); |
397 | 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', |
398 | $hb->add (my $fg = new CFClient::UI::Gauge type => 'food', |
366 | tooltip => "Food - depletes with time, faster when you heal or build mana, refills when you eat healthy food"); |
399 | 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 | |
400 | |
368 | $vbox->add (my $exp = new CFClient::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, |
401 | $vbox->add (my $exp = new CFClient::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, |
369 | tooltip => "Experience points and level - increases when you kill monsters or successfully use skills"); |
402 | 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, |
403 | $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.)"); |
404 | tooltip => "Ranged attack - how you attack when you press shift-cursor (spell, skill, weapon etc.)"); |
372 | |
405 | |
373 | $GAUGES = { |
406 | $GAUGES = { |
374 | exp => $exp, win => $win, range => $rng, |
407 | exp => $exp, win => $win, range => $rng, |
… | |
… | |
379 | |
412 | |
380 | $win |
413 | $win |
381 | } |
414 | } |
382 | |
415 | |
383 | sub make_stats_window { |
416 | sub make_stats_window { |
384 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/5, y => 0, title => "Stats"); |
417 | my $tgw = new CFClient::UI::FancyFrame x => $WIDTH * 2/5, y => 0, title => "Stats"; |
385 | |
418 | |
386 | $tgw->add (my $vb = new CFClient::UI::VBox); |
419 | $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); |
420 | $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); |
421 | $vb->add ($STATWIDS->{map} = new CFClient::UI::Label valign => 0, align => -1, text => "Map:", expand => 1); |
389 | |
422 | |
390 | $vb->add (my $hb = new CFClient::UI::HBox expand => 1); |
423 | $vb->add (my $hb = new CFClient::UI::HBox expand => 1); |
391 | |
424 | |
… | |
… | |
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."], |
443 | [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 | ) { |
444 | ) { |
412 | my ($col, $row, $id, $label, $template, $tooltip) = @$_; |
445 | my ($col, $row, $id, $label, $template, $tooltip) = @$_; |
413 | |
446 | |
414 | $tbl->add ($col , $row, $STATWIDS->{$id} = new CFClient::UI::Label |
447 | $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); |
448 | 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 |
449 | $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); |
450 | font => $FONT_FIXED, can_hover => 1, can_events => 1, fg => $black, valign => 0, align => -1, text => $label, tooltip => $tooltip); |
418 | } |
451 | } |
419 | |
452 | |
420 | $hb->add (my $tbl2 = new CFClient::UI::Table expand => 1); |
453 | $hb->add (my $tbl2 = new CFClient::UI::Table expand => 1); |
421 | |
454 | |
422 | my $row = 0; |
455 | my $row = 0; |
423 | my $col = 0; |
456 | my $col = 0; |
424 | |
457 | |
425 | my %resist_names = ( |
458 | my %resist_names = ( |
426 | slow => "Slow", |
459 | 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", |
460 | 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", |
461 | conf => "Confusion (If you are hit by confusion you will move into random directions, and likely into monsters.)", |
429 | fire => "Fire", |
462 | 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)", |
463 | depl => "Depletion (some monsters and other effects can cause stats depletion)", |
431 | magic => "Magic", |
464 | 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)", |
465 | drain => "Draining (some monsters (e.g. vampires) and other effects can steal experience)", |
433 | acid => "Acid", |
466 | acid => "Acid (resistance to acid, acid hurts pretty much and also corrodes your weapons)", |
434 | pois => "Poison", |
467 | pois => "Poison (resistance to getting poisoned)", |
435 | para => "Paralysation", |
468 | para => "Paralysation (this resistance affects the chance you get paralysed)", |
436 | deat => "Death (resistance against death spells)", |
469 | deat => "Death (resistance against death spells)", |
437 | phys => "Physical", |
470 | phys => "Physical (this is the resistance against physical attacks, like when a monster hit you in melee combat)", |
438 | blind => "Blind", |
471 | blind => "Blind (blind resistance affects the chance of a successful blinding attack)", |
439 | fear => "Fear", |
472 | 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", |
473 | tund => "Turn undead", |
441 | elec => "Electricity", |
474 | elec => "Electricity (resistance againt electricity, spells like large lightning, small lightning, ...)", |
442 | cold => "Cold", |
475 | 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)", |
476 | ghit => "Ghost hit (special attack used by ghosts and ghost-like beings)", |
444 | ); |
477 | ); |
445 | for (qw/slow holyw conf fire depl magic |
478 | for (qw/slow holyw conf fire depl magic |
446 | drain acid pois para deat phys |
479 | drain acid pois para deat phys |
447 | blind fear tund elec cold ghit/) |
480 | blind fear tund elec cold ghit/) |
448 | { |
481 | { |
449 | $tbl2->add ($col, $row, |
482 | $tbl2->add ($col, $row, |
450 | $STATWIDS->{"res_$_"} = |
483 | $STATWIDS->{"res_$_"} = |
451 | new CFClient::UI::Label |
484 | new CFClient::UI::Label |
|
|
485 | font => $FONT_FIXED, |
452 | template => "-100%", |
486 | template => "-100%", |
453 | align => +1, |
487 | align => +1, |
454 | valign => 0, |
488 | valign => 0, |
455 | can_events => 1, |
489 | can_events => 1, |
456 | can_hover => 1, |
490 | can_hover => 1, |
457 | tooltip => $resist_names{$_}, |
491 | tooltip => $resist_names{$_}, |
458 | ); |
492 | ); |
459 | $tbl2->add ($col + 1, $row, new CFClient::UI::Image |
493 | $tbl2->add ($col + 1, $row, new CFClient::UI::Image |
|
|
494 | font => $FONT_FIXED, |
460 | can_hover => 1, |
495 | can_hover => 1, |
461 | can_events => 1, |
496 | can_events => 1, |
462 | image => "ui/resist/resist_$_.png", |
497 | image => "ui/resist/resist_$_.png", |
463 | tooltip => $resist_names{$_}, |
498 | tooltip => $resist_names{$_}, |
464 | ); |
499 | ); |
… | |
… | |
547 | |
582 | |
548 | } |
583 | } |
549 | |
584 | |
550 | sub metaserver_dialog { |
585 | sub metaserver_dialog { |
551 | my $dialog = new CFClient::UI::FancyFrame |
586 | my $dialog = new CFClient::UI::FancyFrame |
552 | title => "Metaserver", |
587 | title => "Server List", |
553 | child => (my $vbox = new CFClient::UI::VBox); |
588 | child => (my $vbox = new CFClient::UI::VBox); |
554 | |
589 | |
555 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
590 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
556 | |
591 | |
557 | $dialog |
592 | $dialog |
… | |
… | |
659 | |
694 | |
660 | $METASERVER = metaserver_dialog; |
695 | $METASERVER = metaserver_dialog; |
661 | |
696 | |
662 | $vbox->add (new CFClient::UI::Flopper |
697 | $vbox->add (new CFClient::UI::Flopper |
663 | expand => 1, |
698 | expand => 1, |
664 | text => "Metaserver", |
699 | text => "Server List", |
665 | other => $METASERVER, |
700 | other => $METASERVER, |
666 | tooltip => "Show a list of avaible crossfire servers", |
701 | tooltip => "Show a list of available crossfire servers", |
667 | connect_open => sub { |
702 | connect_open => sub { |
668 | update_metaserver $HOST; |
703 | update_metaserver $HOST; |
669 | } |
704 | } |
670 | ); |
705 | ); |
671 | } |
706 | } |
… | |
… | |
686 | hidden => 1, |
721 | hidden => 1, |
687 | tooltip => "The password for your character", |
722 | tooltip => "The password for your character", |
688 | connect_changed => sub { |
723 | connect_changed => sub { |
689 | my ($self, $value) = @_; |
724 | my ($self, $value) = @_; |
690 | $CFG->{password} = $value; |
725 | $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 | } |
726 | } |
704 | ); |
727 | ); |
705 | |
728 | |
706 | $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size"); |
729 | $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size"); |
707 | $table->add (1, 7, new CFClient::UI::Slider |
730 | $table->add (1, 7, new CFClient::UI::Slider |
… | |
… | |
714 | |
737 | |
715 | $CFG->{mapsize} = $self->{range}[0] = $value = int $value; |
738 | $CFG->{mapsize} = $self->{range}[0] = $value = int $value; |
716 | }, |
739 | }, |
717 | ); |
740 | ); |
718 | |
741 | |
719 | $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { |
742 | $table->add (1, 8, $LOGIN_BUTTON = new CFClient::UI::Button |
|
|
743 | expand => 1, |
|
|
744 | align => 0, |
|
|
745 | text => "Login", |
|
|
746 | connect_activate => sub { |
|
|
747 | $CONN ? stop_game |
720 | start_game; |
748 | : start_game; |
|
|
749 | }, |
721 | }); |
750 | ); |
722 | |
751 | |
723 | $dialog |
752 | $dialog |
724 | } |
753 | } |
725 | |
754 | |
726 | sub message_window { |
755 | sub message_window { |
727 | my $window = new CFClient::UI::FancyFrame |
756 | my $window = new CFClient::UI::FancyFrame |
728 | title => "Messages", |
757 | title => "Messages", |
729 | border_bg => [1, 1, 1, 0.5], |
758 | border_bg => [1, 1, 1, 1], |
730 | bg => [0.3, 0.3, 0.3, 0.8], |
759 | bg => [0, 0, 0, 0.5], |
731 | user_w => int $::WIDTH / 3, |
760 | user_w => int $::WIDTH / 3, |
732 | user_h => int $::HEIGHT / 5, |
761 | user_h => int $::HEIGHT / 5, |
733 | child => (my $vbox = new CFClient::UI::VBox); |
762 | child => (my $vbox = new CFClient::UI::VBox); |
734 | |
763 | |
735 | $vbox->add ($LOGVIEW = new CFClient::UI::TextView |
764 | $vbox->add ($LOGVIEW = new CFClient::UI::TextView |
… | |
… | |
775 | }; |
804 | }; |
776 | |
805 | |
777 | $window |
806 | $window |
778 | } |
807 | } |
779 | |
808 | |
|
|
809 | sub make_inventory_window { |
|
|
810 | my $invwin = new CFClient::UI::FancyFrame user_w => 300, user_h => 300, title => "Inventory"; |
|
|
811 | $invwin->add ($INV = new CFClient::UI::Inventory expand => 1); |
|
|
812 | $invwin |
|
|
813 | } |
|
|
814 | |
780 | sub sdl_init { |
815 | sub sdl_init { |
781 | CFClient::SDL_Init |
816 | CFClient::SDL_Init |
782 | and die "SDL::Init failed!\n"; |
817 | and die "SDL::Init failed!\n"; |
783 | } |
818 | } |
784 | |
819 | |
785 | sub video_init { |
820 | sub video_init { |
786 | sdl_init; |
821 | sdl_init; |
|
|
822 | |
|
|
823 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} >= @SDL_MODES; |
787 | |
824 | |
788 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
825 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
789 | $FULLSCREEN = $CFG->{fullscreen}; |
826 | $FULLSCREEN = $CFG->{fullscreen}; |
790 | $FAST = $CFG->{fast}; |
827 | $FAST = $CFG->{fast}; |
791 | |
828 | |
… | |
… | |
815 | fontsize => 0.8, |
852 | fontsize => 0.8, |
816 | markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
853 | markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
817 | $ALT_ENTER_MESSAGE->show; |
854 | $ALT_ENTER_MESSAGE->show; |
818 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); |
855 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); |
819 | |
856 | |
820 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget); |
857 | CFClient::UI::FancyFrame->new ( |
821 | $MAPWIDGET->focus_in; |
858 | border_bg => [1, 1, 1, 192/255], |
|
|
859 | bg => [1, 1, 1, 0], |
|
|
860 | child => ($MAPMAP = new CFClient::MapWidget::MapMap), |
|
|
861 | )->show; |
|
|
862 | |
|
|
863 | $MAPWIDGET = new CFClient::MapWidget; |
822 | $MAPWIDGET->connect (activate_console => sub { |
864 | $MAPWIDGET->connect (activate_console => sub { |
823 | my ($mapwidget, $preset) = @_; |
865 | my ($mapwidget, $preset) = @_; |
824 | |
866 | |
825 | if ($CONSOLE) { |
867 | if ($CONSOLE) { |
826 | $CONSOLE->{input}->{auto_activated} = 1; |
868 | $CONSOLE->{input}->{auto_activated} = 1; |
… | |
… | |
829 | if ($preset && $CONSOLE->{input}->get_text eq '') { |
871 | if ($preset && $CONSOLE->{input}->get_text eq '') { |
830 | $CONSOLE->{input}->set_text ($preset); |
872 | $CONSOLE->{input}->set_text ($preset); |
831 | } |
873 | } |
832 | } |
874 | } |
833 | }); |
875 | }); |
|
|
876 | $MAPWIDGET->show; |
|
|
877 | $MAPWIDGET->focus_in; |
834 | |
878 | |
835 | $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox); |
879 | $BUTTONBAR = new CFClient::UI::HBox; |
836 | |
880 | |
837 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup); |
881 | $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); |
882 | $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); |
883 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window); |
840 | |
884 | |
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 |
885 | 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 |
|
|
886 | |
842 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window); |
887 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window); |
|
|
888 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Inventory", other => make_inventory_window); |
843 | |
889 | |
844 | $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { |
890 | $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { |
845 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
891 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
846 | status "Configuration Saved"; |
892 | status "Configuration Saved"; |
847 | }); |
893 | }); |
|
|
894 | |
|
|
895 | $BUTTONBAR->show; |
848 | |
896 | |
849 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
897 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
850 | } |
898 | } |
851 | |
899 | |
852 | sub video_shutdown { |
900 | sub video_shutdown { |
… | |
… | |
857 | } |
905 | } |
858 | |
906 | |
859 | my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# |
907 | my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# |
860 | my $bgmusic;#TODO#hack#d# |
908 | my $bgmusic;#TODO#hack#d# |
861 | |
909 | |
|
|
910 | sub audio_channel_finished { |
|
|
911 | my ($channel) = @_; |
|
|
912 | |
|
|
913 | warn "channel $channel finished\n";#d# |
|
|
914 | } |
|
|
915 | |
862 | sub audio_music_finished { |
916 | sub audio_music_finished { |
863 | return unless $CFG->{bgm_enable}; |
917 | return unless $CFG->{bgm_enable}; |
864 | |
918 | |
865 | # TODO: hack, do play loop and mood music |
919 | # TODO: hack, do play loop and mood music |
866 | $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]"; |
920 | $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]"; |
… | |
… | |
869 | push @bgmusic, shift @bgmusic; |
923 | push @bgmusic, shift @bgmusic; |
870 | } |
924 | } |
871 | |
925 | |
872 | sub audio_init { |
926 | sub audio_init { |
873 | if ($CFG->{audio_enable}) { |
927 | if ($CFG->{audio_enable}) { |
874 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
928 | if (open my $fh, "<", CFClient::find_rcfile "sounds/config") { |
875 | $SDL_MIXER = !CFClient::Mix_OpenAudio; |
929 | $SDL_MIXER = !CFClient::Mix_OpenAudio; |
876 | CFClient::Mix_AllocateChannels 8; |
930 | CFClient::Mix_AllocateChannels 8; |
877 | CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; |
931 | CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; |
878 | |
932 | |
879 | audio_music_finished; |
933 | audio_music_finished; |
… | |
… | |
1034 | # at worst. |
1088 | # at worst. |
1035 | sub conn::flood_fill { |
1089 | sub 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 | ]; |
… | |
… | |
1141 | } |
1195 | } |
1142 | |
1196 | |
1143 | gotid: |
1197 | gotid: |
1144 | $face->{id} = $id; |
1198 | $face->{id} = $id; |
1145 | $MAP->set_face ($facenum => $id); |
1199 | $MAP->set_face ($facenum => $id); |
1146 | $self->{faceid}[$facenum] = $id;#d# |
|
|
1147 | $TILECACHE->get ($id) |
1200 | $TILECACHE->get ($id) |
1148 | } |
1201 | } |
1149 | |
1202 | |
1150 | sub conn::face_update { |
1203 | sub conn::face_update { |
1151 | my ($self, $facenum, $face) = @_; |
1204 | my ($self, $facenum, $face) = @_; |
… | |
… | |
1290 | |
1343 | |
1291 | for my $skill (values %{$self->{skill_info}}) { |
1344 | for my $skill (values %{$self->{skill_info}}) { |
1292 | $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'"); |
1345 | $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'"); |
1293 | $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'"); |
1346 | $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'"); |
1294 | } |
1347 | } |
|
|
1348 | |
|
|
1349 | $MAPWIDGET->add_command ("pet\\_mode defend", "Tell pets to stay close to you and defend you"); |
|
|
1350 | $MAPWIDGET->add_command ("pet\\_mode arena", "Same as petmode attack, but also attack other players"); |
|
|
1351 | $MAPWIDGET->add_command ("pet\\_mode sad", "Search & Destroy - tell pets to roam about and attack enemies"); |
|
|
1352 | $MAPWIDGET->add_command ("kill\\_pets", "kill your pets"); |
|
|
1353 | } |
|
|
1354 | |
|
|
1355 | sub conn::eof { |
|
|
1356 | stop_game; |
1295 | } |
1357 | } |
1296 | |
1358 | |
1297 | sub update_floorbox { |
1359 | sub update_floorbox { |
1298 | $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { |
1360 | $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { |
|
|
1361 | return unless $CONN; |
|
|
1362 | |
1299 | $FLOORBOX->clear; |
1363 | $FLOORBOX->clear; |
1300 | $FLOORBOX->add (new CFClient::UI::Empty expand => 1); |
1364 | $FLOORBOX->add (new CFClient::UI::Empty expand => 1); |
1301 | |
1365 | |
1302 | my @items = values %{ $CONN->{container}{0} }; |
|
|
1303 | |
|
|
1304 | # we basically have to use the same sorting as everybody else |
1366 | # we basically have to use the same sorting as everybody else |
1305 | @items = sort { $a->{type} <=> $b->{type} } @items; |
1367 | for my $item (@{ $CONN->{container}{0} }) { |
1306 | |
1368 | $FLOORBOX->add (new CFClient::UI::InventoryItem item => $item); |
1307 | for my $item (reverse @items) { |
|
|
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 | }, |
|
|
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 | |
|
|
1341 | $hbox->add (new CFClient::UI::Label |
|
|
1342 | can_events => 0, |
|
|
1343 | text => $desc, |
|
|
1344 | ); |
|
|
1345 | } |
1369 | } |
1346 | }); |
1370 | }); |
1347 | refresh; |
1371 | refresh; |
1348 | } |
1372 | } |
1349 | |
1373 | |
1350 | sub conn::container_add { |
1374 | sub conn::container_add { |
1351 | my ($self, $id, $items) = @_; |
1375 | my ($self, $id, $items) = @_; |
1352 | |
1376 | |
1353 | update_floorbox if $id == 0; |
1377 | update_floorbox if $id == 0; |
|
|
1378 | if ($self->{player}{tag} == $id) { |
|
|
1379 | $INV->set_items ($self->{container}{$self->{player}{tag}}); |
|
|
1380 | } |
1354 | # $self-<{player}{tag} => player inv |
1381 | # $self-<{player}{tag} => player inv |
1355 | #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; |
1382 | #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; |
1356 | } |
1383 | } |
1357 | |
1384 | |
1358 | sub conn::container_clear { |
1385 | sub conn::container_clear { |
1359 | my ($self, $id) = @_; |
1386 | my ($self, $id) = @_; |
1360 | |
1387 | |
1361 | update_floorbox if $id == 0; |
1388 | update_floorbox if $id == 0; |
|
|
1389 | if ($self->{player}{tag} == $id) { |
|
|
1390 | $INV->set_items ($self->{container}{$id}); |
|
|
1391 | } |
|
|
1392 | |
1362 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
1393 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
1363 | } |
1394 | } |
1364 | |
1395 | |
1365 | sub conn::item_delete { |
1396 | sub conn::item_delete { |
1366 | my ($self, @items) = @_; |
1397 | my ($self, @items) = @_; |
1367 | |
1398 | |
1368 | for (@items) { |
1399 | for (@items) { |
1369 | update_floorbox if $_->{container} == 0; |
1400 | update_floorbox if $_->{container} == 0; |
|
|
1401 | if ($self->{player}{tag} == $_->{container}) { |
|
|
1402 | $INV->set_items ($self->{container}{$_->{container}}); |
|
|
1403 | } |
1370 | } |
1404 | } |
1371 | } |
1405 | } |
1372 | |
1406 | |
1373 | sub conn::item_update { |
1407 | sub conn::item_update { |
1374 | my ($self, $item) = @_; |
1408 | my ($self, $item) = @_; |
1375 | |
1409 | |
1376 | update_floorbox if $item->{container} == 0; |
1410 | update_floorbox if $item->{container} == 0; |
|
|
1411 | if ($self->{player}{tag} == $item->{container}) { |
|
|
1412 | $INV->set_items ($self->{container}{$item->{container}}); |
|
|
1413 | } |
1377 | } |
1414 | } |
1378 | |
1415 | |
1379 | %SDL_CB = ( |
1416 | %SDL_CB = ( |
1380 | CFClient::SDL_QUIT => sub { |
1417 | CFClient::SDL_QUIT => sub { |
1381 | Event::unloop -1; |
1418 | Event::unloop -1; |
… | |
… | |
1394 | video_init; |
1431 | video_init; |
1395 | } else { |
1432 | } else { |
1396 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
1433 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
1397 | } |
1434 | } |
1398 | }, |
1435 | }, |
1399 | CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, |
1436 | CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, |
1400 | CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, |
1437 | CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, |
1401 | CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, |
1438 | CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, |
1402 | CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, |
1439 | CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, |
1403 | CFClient::SDL_USEREVENT => \&audio_music_finished, |
1440 | CFClient::SDL_USEREVENT => sub { |
|
|
1441 | if ($_[0]{code} == 1) { |
|
|
1442 | audio_channel_finished $_[0]{data1}; |
|
|
1443 | } elsif ($_[0]{code} == 0) { |
|
|
1444 | audio_music_finished; |
|
|
1445 | } |
|
|
1446 | }, |
1404 | ); |
1447 | ); |
1405 | |
1448 | |
1406 | ############################################################################# |
1449 | ############################################################################# |
1407 | |
1450 | |
1408 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
1451 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
|
|
1452 | |
|
|
1453 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
1409 | |
1454 | |
1410 | $TILECACHE = CFClient::db_table "tilecache"; |
1455 | $TILECACHE = CFClient::db_table "tilecache"; |
1411 | $FACEMAP = CFClient::db_table "facemap"; |
1456 | $FACEMAP = CFClient::db_table "facemap"; |
1412 | |
|
|
1413 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
|
|
1414 | |
1457 | |
1415 | my %DEF_CFG = ( |
1458 | my %DEF_CFG = ( |
1416 | sdl_mode => 0, |
1459 | sdl_mode => 0, |
1417 | width => 640, |
1460 | width => 640, |
1418 | height => 480, |
1461 | height => 480, |