… | |
… | |
34 | use Crossfire::Protocol; |
34 | use Crossfire::Protocol; |
35 | |
35 | |
36 | use Compress::LZF; |
36 | use Compress::LZF; |
37 | |
37 | |
38 | use CFClient; |
38 | use CFClient; |
|
|
39 | use CFClient::OpenGL (); |
39 | use CFClient::UI; |
40 | use CFClient::UI; |
40 | use CFClient::MapWidget; |
41 | use CFClient::MapWidget; |
41 | |
42 | |
42 | $Event::DIED = sub { |
43 | $Event::DIED = sub { |
43 | # TODO: display dialog box or so |
44 | # TODO: display dialog box or so |
… | |
… | |
103 | |
104 | |
104 | our $INVWIN; |
105 | our $INVWIN; |
105 | our $INV; |
106 | our $INV; |
106 | our $INVR; |
107 | our $INVR; |
107 | our $INVR_LBL; |
108 | our $INVR_LBL; |
108 | our $OPENCONT; |
|
|
109 | |
109 | |
110 | sub status { |
110 | sub status { |
111 | $STATUSBOX->add (CFClient::UI::Label::escape $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); |
111 | $STATUSBOX->add (CFClient::UI::Label::escape $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); |
112 | } |
112 | } |
113 | |
113 | |
… | |
… | |
383 | $win->add (my $hbox = new CFClient::UI::HBox |
383 | $win->add (my $hbox = new CFClient::UI::HBox |
384 | children => [ |
384 | children => [ |
385 | (new CFClient::UI::HBox expand => 1), |
385 | (new CFClient::UI::HBox expand => 1), |
386 | (new CFClient::UI::VBox children => [ |
386 | (new CFClient::UI::VBox children => [ |
387 | (new CFClient::UI::Empty expand => 1), |
387 | (new CFClient::UI::Empty expand => 1), |
388 | (new CFClient::UI::Frame bg => [0, 0, 0, 0.4], child => ($FLOORBOX = new CFClient::UI::VBox)), |
388 | (new CFClient::UI::Frame bg => [0, 0, 0, 0.4], child => ($FLOORBOX = new CFClient::UI::Table)), |
389 | ]), |
389 | ]), |
390 | (my $vbox = new CFClient::UI::VBox), |
390 | (my $vbox = new CFClient::UI::VBox), |
391 | ], |
391 | ], |
392 | ); |
392 | ); |
393 | |
393 | |
… | |
… | |
431 | can_hover => 1, can_events => 1, |
431 | can_hover => 1, can_events => 1, |
432 | tooltip => "Your name and title. You can change your title by using the <b>title</b> command, if supported by the server."); |
432 | tooltip => "Your name and title. You can change your title by using the <b>title</b> command, if supported by the server."); |
433 | $vb->add ($STATWIDS->{map} = new CFClient::UI::Label valign => 0, align => -1, text => "Map:", expand => 1, |
433 | $vb->add ($STATWIDS->{map} = new CFClient::UI::Label valign => 0, align => -1, text => "Map:", expand => 1, |
434 | can_hover => 1, can_events => 1, |
434 | can_hover => 1, can_events => 1, |
435 | tooltip => "The map you are currently on (if supported by the server)."); |
435 | tooltip => "The map you are currently on (if supported by the server)."); |
|
|
436 | |
|
|
437 | $vb->add (my $hb0 = new CFClient::UI::HBox); |
|
|
438 | $hb0->add ($STATWIDS->{weight} = new CFClient::UI::Label valign => 0, align => -1, text => "Weight:", expand => 1, |
|
|
439 | can_hover => 1, can_events => 1, |
|
|
440 | tooltip => "This is the amount the Player weights."); |
|
|
441 | $hb0->add ($STATWIDS->{m_weight} = new CFClient::UI::Label valign => 0, align => -1, text => "Max weight:", expand => 1, |
|
|
442 | can_hover => 1, can_events => 1, |
|
|
443 | tooltip => "The weight limit, you can't carry more than this."); |
|
|
444 | |
436 | |
445 | |
437 | $vb->add (my $hb = new CFClient::UI::HBox expand => 1); |
446 | $vb->add (my $hb = new CFClient::UI::HBox expand => 1); |
438 | $hb->add (my $tbl = new CFClient::UI::Table expand => 1); |
447 | $hb->add (my $tbl = new CFClient::UI::Table expand => 1); |
439 | |
448 | |
440 | my $color2 = [1, 1, 0]; |
449 | my $color2 = [1, 1, 0]; |
… | |
… | |
566 | $STATWIDS->{st_dam} ->set_text (sprintf "%d", $stats->{15}); |
575 | $STATWIDS->{st_dam} ->set_text (sprintf "%d", $stats->{15}); |
567 | $STATWIDS->{st_arm} ->set_text (sprintf "%d", $stats->{16}); |
576 | $STATWIDS->{st_arm} ->set_text (sprintf "%d", $stats->{16}); |
568 | $STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{Crossfire::Protocol::CS_STAT_SPEED}); |
577 | $STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{Crossfire::Protocol::CS_STAT_SPEED}); |
569 | $STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{Crossfire::Protocol::CS_STAT_WEAP_SP}); |
578 | $STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{Crossfire::Protocol::CS_STAT_WEAP_SP}); |
570 | |
579 | |
|
|
580 | $STATWIDS->{m_weight}->set_text (sprintf "Max weight: %.1fkg", $stats->{Crossfire::Protocol::CS_STAT_WEIGHT_LIM} / 1000); |
|
|
581 | |
571 | my %tbl = ( |
582 | my %tbl = ( |
572 | phys => 100, |
583 | phys => 100, |
573 | magic => 101, |
584 | magic => 101, |
574 | fire => 102, |
585 | fire => 102, |
575 | elec => 103, |
586 | elec => 103, |
… | |
… | |
884 | user_w => $WIDTH * (7/8), user_h => $HEIGHT * (7/8), title => "Inventory"; |
895 | user_w => $WIDTH * (7/8), user_h => $HEIGHT * (7/8), title => "Inventory"; |
885 | |
896 | |
886 | $invwin->add (my $hb = new CFClient::UI::HBox expand => 1); |
897 | $invwin->add (my $hb = new CFClient::UI::HBox expand => 1); |
887 | |
898 | |
888 | $hb->add (my $vb1 = new CFClient::UI::VBox expand => 1); |
899 | $hb->add (my $vb1 = new CFClient::UI::VBox expand => 1); |
889 | $vb1->add (my $lbl = new CFClient::UI::Label); |
900 | $vb1->add (my $lbl = new CFClient::UI::Label xalign => 0.5); |
890 | $lbl->set_text ("Player"); |
901 | $lbl->set_text ("Player"); |
891 | $vb1->add ($INV = new CFClient::UI::Inventory expand => 1); |
902 | $vb1->add ($INV = new CFClient::UI::Inventory expand => 1); |
892 | |
903 | |
893 | $hb->add (my $vb2 = new CFClient::UI::VBox expand => 1); |
904 | $hb->add (my $vb2 = new CFClient::UI::VBox expand => 1); |
894 | $vb2->add ($INVR_LBL = new CFClient::UI::Label); |
905 | $vb2->add ($INVR_LBL = new CFClient::UI::Label xalign => 0.5); |
895 | $INVR_LBL->set_text ("Floor"); |
906 | $INVR_LBL->set_text ("Floor"); |
896 | $vb2->add ($INVR = new CFClient::UI::Inventory expand => 1); |
907 | $vb2->add ($INVR = new CFClient::UI::Inventory expand => 1); |
897 | |
908 | |
898 | $invwin |
909 | $invwin |
899 | } |
910 | } |
… | |
… | |
956 | or die "SDL_SetVideoMode failed: " . (CFClient::SDL_GetError) . "\n"; |
967 | or die "SDL_SetVideoMode failed: " . (CFClient::SDL_GetError) . "\n"; |
957 | |
968 | |
958 | $SDL_ACTIVE = 1; |
969 | $SDL_ACTIVE = 1; |
959 | $LAST_REFRESH = time - 0.01; |
970 | $LAST_REFRESH = time - 0.01; |
960 | |
971 | |
961 | CFClient::gl_init; |
972 | CFClient::OpenGL::init; |
962 | |
973 | |
963 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
974 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
964 | |
975 | |
965 | $CFClient::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# |
976 | $CFClient::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# |
966 | |
977 | |
… | |
… | |
1247 | $MAPWIDGET->clr_commands; |
1258 | $MAPWIDGET->clr_commands; |
1248 | |
1259 | |
1249 | my $parser = new Pod::POM; |
1260 | my $parser = new Pod::POM; |
1250 | my $pod = $parser->parse_file (CFClient::find_rcfile "pod/command_help.pod"); |
1261 | my $pod = $parser->parse_file (CFClient::find_rcfile "pod/command_help.pod"); |
1251 | |
1262 | |
1252 | for my $head2 ($pod->head2) { |
1263 | for my $head2 ($pod->head1->[-2]->head2) { |
1253 | $head2->title =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
1264 | $head2->title =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
1254 | or next; |
1265 | or next; |
1255 | |
1266 | |
1256 | my $cmd = $1; |
1267 | my $cmd = $1; |
1257 | my @args = split /\|/, $2; |
1268 | my @args = split /\|/, $2; |
… | |
… | |
1266 | } |
1277 | } |
1267 | } |
1278 | } |
1268 | |
1279 | |
1269 | $self->{noface} = new_from_file CFClient::Texture |
1280 | $self->{noface} = new_from_file CFClient::Texture |
1270 | CFClient::find_rcfile "noface.png", minify => 1, mipmap => 1; |
1281 | CFClient::find_rcfile "noface.png", minify => 1, mipmap => 1; |
|
|
1282 | |
|
|
1283 | $self->{open_container} = 0; |
1271 | |
1284 | |
1272 | $self |
1285 | $self |
1273 | } |
1286 | } |
1274 | |
1287 | |
1275 | sub conn::stats_update { |
1288 | sub conn::stats_update { |
… | |
… | |
1675 | my $parser = new Pod::POM; |
1688 | my $parser = new Pod::POM; |
1676 | my $pod = $parser->parse_file (CFClient::find_rcfile "pod/skill_help.pod"); |
1689 | my $pod = $parser->parse_file (CFClient::find_rcfile "pod/skill_help.pod"); |
1677 | |
1690 | |
1678 | my %skill_tooltip; |
1691 | my %skill_tooltip; |
1679 | |
1692 | |
1680 | for my $head2 ($pod->head2) { |
1693 | for my $head2 ($pod->head1->[-2]->head2) { |
1681 | $skill_tooltip{$head2->title} = CFClient::pod_to_pango $head2->content; |
1694 | $skill_tooltip{$head2->title} = CFClient::pod_to_pango $head2->content; |
1682 | } |
1695 | } |
1683 | |
1696 | |
1684 | for my $skill (values %{$self->{skill_info}}) { |
1697 | for my $skill (values %{$self->{skill_info}}) { |
1685 | $MAPWIDGET->add_command ("ready_skill $skill", |
1698 | $MAPWIDGET->add_command ("ready_skill $skill", |
… | |
… | |
1743 | sub update_floorbox { |
1756 | sub update_floorbox { |
1744 | $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { |
1757 | $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { |
1745 | return unless $CONN; |
1758 | return unless $CONN; |
1746 | |
1759 | |
1747 | $FLOORBOX->clear; |
1760 | $FLOORBOX->clear; |
1748 | $FLOORBOX->add (new CFClient::UI::Empty expand => 1); |
|
|
1749 | |
1761 | |
1750 | my $count = 7; |
1762 | my $row; |
1751 | for (@{ $CONN->{container}{0} }) { |
1763 | for (@{ $CONN->{container}{0} }) { |
1752 | if (--$count) { |
1764 | if ($row < 7) { |
1753 | $FLOORBOX->add (new CFClient::UI::InventoryItem item => $_); |
1765 | local $_->{face_widget}; # hack to force recreation of widget |
|
|
1766 | local $_->{desc_widget}; # hack to force recreation of widget |
|
|
1767 | CFClient::Item::update_widgets $_; |
|
|
1768 | |
|
|
1769 | $FLOORBOX->add (0, $row, $_->{face_widget}); |
|
|
1770 | $FLOORBOX->add (1, $row, $_->{desc_widget}); |
|
|
1771 | |
|
|
1772 | $row++; |
1754 | } else { |
1773 | } else { |
1755 | $FLOORBOX->add (new CFClient::UI::Label text => "More..."); |
1774 | $FLOORBOX->add (1, $row, new CFClient::UI::Label text => "More..."); |
1756 | last; |
1775 | last; |
1757 | } |
1776 | } |
1758 | } |
1777 | } |
1759 | }); |
1778 | }); |
1760 | |
1779 | |
1761 | $WANT_REFRESH++; |
1780 | $WANT_REFRESH++; |
1762 | } |
1781 | } |
1763 | |
1782 | |
|
|
1783 | sub set_opencont { |
|
|
1784 | my ($conn, $tag, $name) = @_; |
|
|
1785 | $conn->{open_container} = $tag; |
|
|
1786 | $INVR_LBL->set_text ($name); |
|
|
1787 | $INVR->set_items ($conn->{container}{$tag}); |
|
|
1788 | } |
|
|
1789 | |
|
|
1790 | sub update_container { |
|
|
1791 | my ($tag) = @_; |
|
|
1792 | $INVR->set_items ($::CONN->{container}{$CONN->{open_container}}) |
|
|
1793 | if $tag == $CONN->{open_container}; |
|
|
1794 | } |
|
|
1795 | |
1764 | sub conn::container_add { |
1796 | sub conn::container_add { |
1765 | my ($self, $tag, $items) = @_; |
1797 | my ($self, $tag, $items) = @_; |
1766 | |
1798 | |
1767 | #d# print "container_add: container $tag ($self->{player}{tag})\n"; |
1799 | #d# print "container_add: container $tag ($self->{player}{tag})\n"; |
1768 | |
1800 | |
1769 | if ($tag == 0) { |
1801 | if ($tag == 0) { |
1770 | update_floorbox; |
1802 | update_floorbox; |
1771 | $OPENCONT = 0; |
1803 | update_container (0); |
1772 | $INVR_LBL->set_text ("Floor"); |
|
|
1773 | $INVR->set_items ($self->{container}{0}); |
|
|
1774 | } elsif ($tag == $self->{player}{tag}) { |
1804 | } elsif ($tag == $self->{player}{tag}) { |
1775 | $INVR_LBL->set_text ("Player"); |
|
|
1776 | $INV->set_items ($self->{container}{$self->{player}{tag}}) |
1805 | $INV->set_items ($self->{container}{$self->{player}{tag}}) |
1777 | } else { |
1806 | } else { |
1778 | $OPENCONT = $tag; |
1807 | update_container ($tag); |
1779 | $INVR_LBL->set_text (CFClient::UI::InventoryItem::_item_to_desc ($self->{item}->{$OPENCONT})); |
|
|
1780 | $INVR->set_items ($self->{container}{$tag}); |
|
|
1781 | } |
1808 | } |
1782 | |
1809 | |
1783 | # $self-<{player}{tag} => player inv |
1810 | # $self-<{player}{tag} => player inv |
1784 | #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; |
1811 | #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; |
1785 | } |
1812 | } |
… | |
… | |
1789 | |
1816 | |
1790 | #d# print "container_clear: container $tag ($self->{player}{tag})\n"; |
1817 | #d# print "container_clear: container $tag ($self->{player}{tag})\n"; |
1791 | |
1818 | |
1792 | if ($tag == 0) { |
1819 | if ($tag == 0) { |
1793 | update_floorbox; |
1820 | update_floorbox; |
1794 | $OPENCONT = 0; |
1821 | update_container (0); |
1795 | $INVR_LBL->set_text ("Floor"); |
|
|
1796 | $INVR->set_items ($self->{container}{0}); |
|
|
1797 | } elsif ($tag == $self->{player}{tag}) { |
1822 | } elsif ($tag == $self->{player}{tag}) { |
1798 | $INVR_LBL->set_text ("Player"); |
|
|
1799 | $INV->set_items ($self->{container}{$tag}) |
1823 | $INV->set_items ($self->{container}{$tag}) |
1800 | } else { |
|
|
1801 | $OPENCONT = $tag; |
|
|
1802 | $INVR_LBL->set_text (CFClient::UI::InventoryItem::_item_to_desc ($self->{item}->{$OPENCONT})); |
|
|
1803 | $INVR->set_items ($self->{container}{$tag}); |
|
|
1804 | } |
1824 | } |
1805 | |
1825 | |
1806 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
1826 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
1807 | } |
1827 | } |
1808 | |
1828 | |
… | |
… | |
1812 | for (@items) { |
1832 | for (@items) { |
1813 | #d# print "item_delete: $_->{tag} from $_->{container} ($self->{player}{tag})\n"; |
1833 | #d# print "item_delete: $_->{tag} from $_->{container} ($self->{player}{tag})\n"; |
1814 | |
1834 | |
1815 | if ($_->{container} == 0) { |
1835 | if ($_->{container} == 0) { |
1816 | update_floorbox; |
1836 | update_floorbox; |
1817 | $OPENCONT = 0; |
1837 | update_container ($_->{tag}); |
1818 | $INVR_LBL->set_text ("Floor"); |
|
|
1819 | $INVR->set_items ($self->{container}{0}); |
|
|
1820 | } elsif ($_->{container} == $self->{player}{tag}) { |
1838 | } elsif ($_->{container} == $self->{player}{tag}) { |
1821 | $INVR_LBL->set_text ("Player"); |
|
|
1822 | $INV->set_items ($self->{container}{$self->{player}{tag}}) |
1839 | $INV->set_items ($self->{container}{$self->{player}{tag}}) |
1823 | } else { |
1840 | } else { |
1824 | $OPENCONT = $_->{container}; |
1841 | update_container ($_->{tag}); |
1825 | $INVR_LBL->set_text (CFClient::UI::InventoryItem::_item_to_desc ($self->{item}->{$OPENCONT})); |
|
|
1826 | $INVR->set_items ($self->{container}{$_->{container}}); |
|
|
1827 | } |
1842 | } |
1828 | } |
1843 | } |
1829 | } |
1844 | } |
1830 | |
1845 | |
1831 | sub conn::item_update { |
1846 | sub conn::item_update { |
1832 | my ($self, $item) = @_; |
1847 | my ($self, $item) = @_; |
1833 | |
1848 | |
1834 | #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($OPENCONT)\n"; |
1849 | #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($CONN->{open_container})\n"; |
1835 | |
1850 | |
|
|
1851 | if ($item->{tag} == $self->{player}{tag}) { |
|
|
1852 | $STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $item->{weight} / 1000); |
|
|
1853 | return |
|
|
1854 | } |
|
|
1855 | |
|
|
1856 | CFClient::Item::update_widgets $item; |
|
|
1857 | |
1836 | if ($item->{tag} == $OPENCONT && not ($item->{flags} & Crossfire::Protocol::F_OPEN)) { |
1858 | if ($item->{tag} == $CONN->{open_container} && not ($item->{flags} & Crossfire::Protocol::F_OPEN)) { |
1837 | $OPENCONT = 0; |
1859 | set_opencont ($CONN, 0, "Floor"); |
1838 | $INVR_LBL->set_text ("Floor"); |
|
|
1839 | $INVR->set_items ($self->{container}{0}); |
|
|
1840 | |
1860 | |
1841 | $item->{widget}->update_item |
1861 | } elsif ($item->{flags} & Crossfire::Protocol::F_OPEN) { |
1842 | if $item->{widget}; |
1862 | set_opencont ($CONN, $item->{tag}, CFClient::Item::desc_string $item); |
1843 | } else { |
1863 | } else { |
1844 | if ($item->{container} == 0) { |
1864 | if ($item->{container} == 0) { |
1845 | update_floorbox; |
1865 | update_floorbox; |
1846 | $OPENCONT = 0; |
1866 | update_container (0); |
1847 | $INVR_LBL->set_text ("Floor"); |
|
|
1848 | $INVR->set_items ($self->{container}{0}); |
|
|
1849 | } elsif ($item->{container} == $self->{player}{tag}) { |
1867 | } elsif ($item->{container} == $self->{player}{tag}) { |
1850 | $INV->set_items ($self->{container}{$item->{container}}) |
1868 | $INV->set_items ($self->{container}{$item->{container}}) |
1851 | } |
1869 | } |
1852 | } |
1870 | } |
1853 | } |
1871 | } |